/*
 * Giorgio Design System — giorgio.css
 * Single source of truth for all interfaces.
 *
 * Tokens derived from project fingerprint (giorgio.json):
 *   - 29 audits, Inter font, indigo accent, dark palette
 *   - Self-improving: tokens reflect learned preferences
 */

/* ── Reset ───────────────────────────────────────── */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

/* ── Tokens ──────────────────────────────────────── */

:root {
    /* Surface */
    --g-bg: #06060c;
    --g-surface: #0e0e18;
    --g-surface-2: #16162a;
    --g-surface-3: #1e1e30;
    --g-elevated: #24243a;

    /* Border */
    --g-border: #262640;
    --g-border-hover: #3a3a58;
    --g-border-focus: #6366f1;

    /* Text */
    --g-text: #eaeaf2;
    --g-text-muted: #8080a4;
    --g-text-dim: #505070;

    /* Accent — Indigo */
    --g-accent: #6366f1;
    --g-accent-light: #818cf8;
    --g-accent-dim: rgba(99, 102, 241, 0.12);
    --g-accent-glow: rgba(99, 102, 241, 0.15);
    --g-accent-glow-strong: rgba(99, 102, 241, 0.35);

    /* Semantic */
    --g-green: #22c55e;
    --g-green-dim: rgba(34, 197, 94, 0.12);
    --g-red: #ef4444;
    --g-red-dim: rgba(239, 68, 68, 0.12);
    --g-amber: #f59e0b;
    --g-amber-dim: rgba(245, 158, 11, 0.12);
    --g-cyan: #06b6d4;
    --g-cyan-dim: rgba(6, 182, 212, 0.12);
    --g-purple: #a855f7;
    --g-purple-dim: rgba(168, 85, 247, 0.12);

    /* Glass */
    --g-glass: rgba(14, 14, 24, 0.7);
    --g-glass-border: rgba(255, 255, 255, 0.06);
    --g-glass-hover: rgba(255, 255, 255, 0.03);

    /* Typography */
    --g-font: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    --g-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

    /* Radii */
    --g-radius: 16px;
    --g-radius-sm: 10px;
    --g-radius-xs: 6px;
    --g-radius-pill: 100px;

    /* Shadows */
    --g-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --g-shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
    --g-glow: 0 4px 20px var(--g-accent-glow);
    --g-glow-lg: 0 8px 30px var(--g-accent-glow-strong);

    /* Transitions */
    --g-transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --g-transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);

    /* Spacing Scale */
    --g-space-xs: 4px;
    --g-space-sm: 8px;
    --g-space-md: 16px;
    --g-space-lg: 24px;
    --g-space-xl: 32px;
    --g-space-2xl: 48px;
}

/* ── Light Theme Override ────────────────────────── */

.g-light {
    --g-bg: #FAFBFC;
    --g-surface: #FFFFFF;
    --g-surface-2: #F3F4F6;
    --g-surface-3: #E5E7EB;
    --g-elevated: #FFFFFF;

    --g-border: #E5E7EB;
    --g-border-hover: #D1D5DB;
    --g-border-focus: #6366f1;

    --g-text: #1a1a2e;
    --g-text-muted: #6b7280;
    --g-text-dim: #9ca3af;

    --g-accent: #6366f1;
    --g-accent-light: #4f46e5;
    --g-accent-dim: rgba(99, 102, 241, 0.08);
    --g-accent-glow: rgba(99, 102, 241, 0.1);
    --g-accent-glow-strong: rgba(99, 102, 241, 0.2);

    --g-green: #16a34a;
    --g-green-dim: rgba(22, 163, 74, 0.08);
    --g-red: #dc2626;
    --g-red-dim: rgba(220, 38, 38, 0.08);
    --g-amber: #d97706;
    --g-amber-dim: rgba(217, 119, 6, 0.08);
    --g-cyan: #0891b2;
    --g-cyan-dim: rgba(8, 145, 178, 0.08);
    --g-purple: #9333ea;
    --g-purple-dim: rgba(147, 51, 234, 0.08);

    --g-glass: rgba(255, 255, 255, 0.8);
    --g-glass-border: rgba(0, 0, 0, 0.06);
    --g-glass-hover: rgba(0, 0, 0, 0.02);

    --g-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    --g-shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.08);
    --g-glow: 0 2px 12px var(--g-accent-glow);
    --g-glow-lg: 0 4px 20px var(--g-accent-glow-strong);
}

/* ── Base ────────────────────────────────────────── */

body {
    font-family: var(--g-font);
    background: var(--g-bg);
    color: var(--g-text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    min-height: 100vh;
}

a { color: var(--g-accent-light); text-decoration: none; transition: color var(--g-transition); }
a:hover { color: var(--g-text); }

::selection { background: var(--g-accent-dim); color: var(--g-text); }

/* ── Typography ──────────────────────────────────── */

.g-h1 {
    font-size: clamp(2.5rem, 6vw, 4rem);
    font-weight: 800;
    letter-spacing: -0.04em;
    line-height: 1.1;
}

.g-h2 {
    font-size: clamp(1.8rem, 4vw, 2.4rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

.g-h3 {
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.g-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--g-text-dim);
}

.g-mono { font-family: var(--g-mono); }

.g-gradient-text {
    background: linear-gradient(135deg, var(--g-accent-light) 0%, var(--g-cyan) 50%, var(--g-green) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.g-logo-text {
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    background: linear-gradient(135deg, var(--g-accent-light), var(--g-cyan));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* ── Cards ───────────────────────────────────────── */

.g-card {
    background: var(--g-surface);
    border: 1px solid var(--g-border);
    border-radius: var(--g-radius);
    padding: var(--g-space-lg);
    transition: border-color var(--g-transition), box-shadow var(--g-transition), transform var(--g-transition);
}

.g-card:hover {
    border-color: var(--g-border-hover);
}

.g-card-interactive:hover {
    border-color: var(--g-accent);
    box-shadow: var(--g-glow);
    transform: translateY(-2px);
}

.g-glass {
    background: var(--g-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--g-glass-border);
    border-radius: var(--g-radius);
}

/* ── Buttons ─────────────────────────────────────── */

.g-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--g-radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: var(--g-font);
    cursor: pointer;
    border: none;
    transition: all var(--g-transition);
    text-decoration: none;
    line-height: 1;
}

.g-btn-primary {
    background: linear-gradient(135deg, var(--g-accent), #4f46e5);
    color: white;
    box-shadow: var(--g-glow), inset 0 1px 0 rgba(255,255,255,0.1);
}
.g-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--g-glow-lg), inset 0 1px 0 rgba(255,255,255,0.15);
    color: white;
}

.g-btn-secondary {
    background: var(--g-surface-2);
    color: var(--g-text);
    border: 1px solid var(--g-border);
}
.g-btn-secondary:hover {
    border-color: var(--g-border-hover);
    background: var(--g-surface-3);
    transform: translateY(-1px);
    color: var(--g-text);
}

.g-btn-ghost {
    background: transparent;
    color: var(--g-text-muted);
    border: 1px solid var(--g-border);
}
.g-btn-ghost:hover {
    border-color: var(--g-accent);
    color: var(--g-text);
}

.g-btn-sm {
    padding: 8px 16px;
    font-size: 0.82rem;
    border-radius: var(--g-radius-xs);
}

.g-btn-lg {
    padding: 16px 32px;
    font-size: 1rem;
}

.g-btn-danger {
    background: var(--g-red-dim);
    color: var(--g-red);
    border: 1px solid rgba(239, 68, 68, 0.2);
}
.g-btn-danger:hover {
    background: rgba(239, 68, 68, 0.2);
    color: var(--g-red);
}

/* ── Inputs ──────────────────────────────────────── */

.g-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--g-surface);
    border: 1px solid var(--g-border);
    border-radius: var(--g-radius-sm);
    color: var(--g-text);
    font-family: var(--g-font);
    font-size: 0.9rem;
    outline: none;
    transition: border-color var(--g-transition), box-shadow var(--g-transition);
}
.g-input:focus {
    border-color: var(--g-accent);
    box-shadow: 0 0 0 3px var(--g-accent-dim);
}
.g-input::placeholder { color: var(--g-text-dim); }

/* ── Stat Cards ──────────────────────────────────── */

.g-stat {
    background: var(--g-surface);
    border: 1px solid var(--g-border);
    border-radius: var(--g-radius);
    padding: var(--g-space-md);
}

.g-stat-label {
    font-size: 0.72rem;
    color: var(--g-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.g-stat-value {
    font-size: 1.8rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-top: 4px;
    line-height: 1;
}

/* ── Badges ──────────────────────────────────────── */

.g-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: var(--g-radius-pill);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.g-badge-accent { background: var(--g-accent-dim); color: var(--g-accent-light); }
.g-badge-green  { background: var(--g-green-dim); color: var(--g-green); }
.g-badge-amber  { background: var(--g-amber-dim); color: var(--g-amber); }
.g-badge-red    { background: var(--g-red-dim); color: var(--g-red); }
.g-badge-cyan   { background: var(--g-cyan-dim); color: var(--g-cyan); }

/* ── Navigation ──────────────────────────────────── */

.g-nav {
    display: flex;
    gap: 4px;
    align-items: center;
}

.g-nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: var(--g-radius-xs);
    color: var(--g-text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--g-transition);
    cursor: pointer;
}
.g-nav-item:hover {
    background: var(--g-surface-2);
    color: var(--g-text);
}
.g-nav-item.active {
    background: var(--g-accent-dim);
    color: var(--g-accent-light);
}

/* ── Status ──────────────────────────────────────── */

.g-pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--g-green);
    animation: g-pulse 2s ease-in-out infinite;
}

@keyframes g-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34,197,94,0.4); }
    50% { opacity: 0.7; box-shadow: 0 0 0 6px rgba(34,197,94,0); }
}

/* ── Ambient Background ──────────────────────────── */

.g-bg-grid {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(var(--g-border) 1px, transparent 1px),
        linear-gradient(90deg, var(--g-border) 1px, transparent 1px);
    background-size: 60px 60px;
    opacity: 0.06;
    pointer-events: none;
    z-index: 0;
}

.g-bg-orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    pointer-events: none;
    z-index: 0;
    animation: g-float 20s ease-in-out infinite;
}
.g-bg-orb-1 {
    width: 600px; height: 600px;
    top: -200px; left: -100px;
    background: var(--g-accent-glow-strong);
}
.g-bg-orb-2 {
    width: 500px; height: 500px;
    bottom: -150px; right: -100px;
    background: rgba(6, 182, 212, 0.12);
    animation-delay: -10s;
}

@keyframes g-float {
    0%, 100% { transform: translate(0, 0) rotate(0deg); }
    33% { transform: translate(30px, -30px) rotate(5deg); }
    66% { transform: translate(-20px, 20px) rotate(-3deg); }
}

/* ── Layout Utilities ────────────────────────────── */

.g-container { max-width: 1200px; margin: 0 auto; padding: 0 24px; position: relative; z-index: 1; }
.g-container-sm { max-width: 800px; margin: 0 auto; padding: 0 24px; position: relative; z-index: 1; }

.g-flex { display: flex; }
.g-flex-col { display: flex; flex-direction: column; }
.g-flex-center { display: flex; align-items: center; justify-content: center; }
.g-flex-between { display: flex; align-items: center; justify-content: space-between; }

.g-grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--g-space-md); }
.g-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--g-space-md); }
.g-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--g-space-md); }
.g-grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: var(--g-space-md); }
.g-grid-auto-sm { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }

.g-gap-xs { gap: var(--g-space-xs); }
.g-gap-sm { gap: var(--g-space-sm); }
.g-gap-md { gap: var(--g-space-md); }
.g-gap-lg { gap: var(--g-space-lg); }

/* ── Divider ─────────────────────────────────────── */

.g-divider {
    border: none;
    border-top: 1px solid var(--g-border);
    margin: var(--g-space-lg) 0;
}

/* ── Code Block ──────────────────────────────────── */

.g-code {
    background: var(--g-surface);
    border: 1px solid var(--g-border);
    border-radius: var(--g-radius);
    overflow: hidden;
}

.g-code-header {
    padding: 10px 16px;
    background: var(--g-surface-2);
    border-bottom: 1px solid var(--g-border);
    font-family: var(--g-mono);
    font-size: 0.78rem;
    color: var(--g-text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.g-code-body {
    padding: 20px;
    font-family: var(--g-mono);
    font-size: 0.85rem;
    line-height: 1.8;
    overflow-x: auto;
}

.g-code-dots {
    display: flex; gap: 6px;
}
.g-code-dot {
    width: 10px; height: 10px; border-radius: 50%;
}
.g-code-dot:nth-child(1) { background: #ff5f57; }
.g-code-dot:nth-child(2) { background: #febc2e; }
.g-code-dot:nth-child(3) { background: #28c840; }

/* ── Slide-in Animation ──────────────────────────── */

.g-animate-in {
    animation: g-slideIn 0.3s ease-out;
}

@keyframes g-slideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.g-fade-in {
    animation: g-fadeIn 0.4s ease;
}

@keyframes g-fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ── Scrollbar ───────────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--g-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--g-border-hover); }

/* ── Mobile Foundation ───────────────────────────── */

/* Safe area insets for notched devices */
body {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Prevent iOS input zoom (font-size < 16px triggers zoom) */
input, select, textarea { font-size: 16px; }

/* Touch tap feedback */
a, button, [role="button"], .g-btn, .g-nav-item, .g-card-interactive {
    -webkit-tap-highlight-color: rgba(99, 102, 241, 0.15);
}

/* Focus-visible for keyboard/switch navigation */
:focus-visible {
    outline: 2px solid var(--g-accent);
    outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

/* Reduce motion when requested */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Sticky CTA utility */
.g-sticky-cta {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--g-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--g-glass-border);
    z-index: 100;
    display: none;
}

/* Mobile hamburger nav */
.g-mobile-nav-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--g-text);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 8px;
    -webkit-tap-highlight-color: rgba(99, 102, 241, 0.15);
}

.g-mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 999;
    opacity: 0;
    transition: opacity var(--g-transition);
}
.g-mobile-overlay.open { opacity: 1; }

/* ── Responsive ──────────────────────────────────── */

@media (max-width: 768px) {
    .g-grid-2 { grid-template-columns: 1fr; }
    .g-grid-3 { grid-template-columns: 1fr; }
    .g-grid-4 { grid-template-columns: repeat(2, 1fr); }
    .g-container { padding: 0 16px; }
    :root {
        --g-radius: 14px;
        --g-radius-sm: 8px;
        --g-space-lg: 20px;
        --g-space-xl: 24px;
    }
    .g-mobile-nav-toggle { display: flex; }
    .g-sticky-cta { display: block; }
}

@media (max-width: 480px) {
    .g-grid-4 { grid-template-columns: 1fr; }
}
