/* =============================================================================
   STR4TUM DESIGN SYSTEM — TOKENS
   Unified design tokens for a suite of operational dashboards.
   Aesthetic: refined terminal minimalism, dark, monospace, semantic colors.
   ============================================================================= */

:root {
  /* ---------------------------------------------------------------------------
     COLOR — BACKGROUNDS & SURFACES
     Philosophy: near-black base, subtle panel elevation via hue-shift not lightness.
     --------------------------------------------------------------------------- */
  --bg-base:            #0a0a0b;   /* page background */
  --bg-panel:           #111113;   /* card / panel */
  --bg-panel-elevated:  #17171a;   /* hover state, nested panel */
  --bg-input:           #0d0d0f;   /* form controls */
  --bg-code:            #0f0f11;   /* inline code, tag chips */

  /* ---------------------------------------------------------------------------
     COLOR — BORDERS & DIVIDERS
     --------------------------------------------------------------------------- */
  --border-subtle:      rgba(255, 255, 255, 0.06);   /* barely visible */
  --border-default:     rgba(255, 255, 255, 0.10);   /* card borders */
  --border-strong:      rgba(255, 255, 255, 0.18);   /* emphasis */
  --border-focus:       var(--accent-info);          /* input focus ring */

  /* ---------------------------------------------------------------------------
     COLOR — TEXT
     --------------------------------------------------------------------------- */
  --text-primary:       #e8e8ea;   /* body, headings */
  --text-secondary:     #a8a8ad;   /* subtitles, metadata */
  --text-muted:         #6b6b72;   /* labels, captions */
  --text-dim:           #45454b;   /* placeholder, disabled */

  /* ---------------------------------------------------------------------------
     COLOR — SEMANTIC ACCENTS
     Used consistently across all 3 apps. Semantic meaning is fixed.
     --------------------------------------------------------------------------- */
  --accent-info:        #06b6d4;   /* cyan — labels, numbers, info, "LETTURA" */
  --accent-success:     #10b981;   /* green — VA, success, live, gain */
  --accent-danger:      #ef4444;   /* red — NON VA, error, loss */
  --accent-warning:     #f59e0b;   /* amber — RISCHIO, caution */
  --accent-header:      #a855f7;   /* purple — section headers, "Stato Progetto" */
  --accent-secondary:   #f97316;   /* orange — secondary highlight, legends */

  /* Dim variants for subtle backgrounds (10% opacity overlays) */
  --accent-info-dim:       rgba(6, 182, 212, 0.10);
  --accent-success-dim:    rgba(16, 185, 129, 0.10);
  --accent-danger-dim:     rgba(239, 68, 68, 0.10);
  --accent-warning-dim:    rgba(245, 158, 11, 0.10);
  --accent-header-dim:     rgba(168, 85, 247, 0.08);
  --accent-secondary-dim:  rgba(249, 115, 22, 0.10);

  /* ---------------------------------------------------------------------------
     TYPOGRAPHY
     Single monospace family, weight + case for hierarchy.
     Swap --font-mono to match your preferred typeface if needed.
     --------------------------------------------------------------------------- */
  --font-mono: 'JetBrains Mono', 'IBM Plex Mono', 'Berkeley Mono', ui-monospace,
               'SF Mono', Menlo, Consolas, monospace;

  /* Font sizes — modular scale, 4px-based */
  --fs-xs:   0.6875rem;   /* 11px — tag chips, micro-labels */
  --fs-sm:   0.75rem;     /* 12px — section labels UPPERCASE, captions */
  --fs-base: 0.875rem;    /* 14px — body, tables */
  --fs-md:   1rem;        /* 16px — emphasized body */
  --fs-lg:   1.25rem;     /* 20px — subtitle, card value secondary */
  --fs-xl:   1.75rem;     /* 28px — KPI value */
  --fs-2xl:  2.25rem;     /* 36px — hero number */
  --fs-3xl:  3rem;        /* 48px — optional display */

  /* Line heights */
  --lh-tight:  1.2;
  --lh-snug:   1.4;
  --lh-normal: 1.6;

  /* Font weights */
  --fw-regular:  400;
  --fw-medium:   500;
  --fw-semibold: 600;
  --fw-bold:     700;

  /* Letter spacing for UPPERCASE labels (critical for monospace readability) */
  --tracking-tight:  -0.01em;
  --tracking-normal: 0;
  --tracking-wide:   0.05em;
  --tracking-wider:  0.1em;    /* UPPERCASE labels */
  --tracking-widest: 0.15em;   /* hero uppercase */

  /* ---------------------------------------------------------------------------
     SPACING — 4px base scale
     --------------------------------------------------------------------------- */
  --space-0:    0;
  --space-1:    0.25rem;   /* 4px */
  --space-2:    0.5rem;    /* 8px */
  --space-3:    0.75rem;   /* 12px */
  --space-4:    1rem;      /* 16px */
  --space-5:    1.25rem;   /* 20px */
  --space-6:    1.5rem;    /* 24px */
  --space-8:    2rem;      /* 32px */
  --space-10:   2.5rem;    /* 40px */
  --space-12:   3rem;      /* 48px */
  --space-16:   4rem;      /* 64px */
  --space-20:   5rem;      /* 80px */

  /* ---------------------------------------------------------------------------
     RADIUS — Restrained. Terminal aesthetic = minimal rounding.
     --------------------------------------------------------------------------- */
  --radius-none:  0;
  --radius-sm:    2px;     /* inputs, tags */
  --radius-md:    4px;     /* small cards */
  --radius-lg:    6px;     /* panels, KPI cards */
  --radius-xl:    8px;     /* major panels, modals */

  /* ---------------------------------------------------------------------------
     SHADOWS — Use sparingly. Dark UI benefits more from border contrast.
     --------------------------------------------------------------------------- */
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md:  0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg:  0 12px 32px rgba(0, 0, 0, 0.5);

  /* Glow effects for accents (use rarely) */
  --glow-info:    0 0 20px rgba(6, 182, 212, 0.15);
  --glow-success: 0 0 20px rgba(16, 185, 129, 0.15);

  /* ---------------------------------------------------------------------------
     TRANSITIONS
     --------------------------------------------------------------------------- */
  --ease-out:     cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out:  cubic-bezier(0.65, 0, 0.35, 1);
  --duration-fast:    120ms;
  --duration-normal:  200ms;
  --duration-slow:    320ms;

  /* ---------------------------------------------------------------------------
     LAYOUT
     --------------------------------------------------------------------------- */
  --container-max:     1400px;
  --container-padding: var(--space-6);
  --panel-padding:     var(--space-6);
  --panel-padding-sm:  var(--space-4);

  /* ---------------------------------------------------------------------------
     Z-INDEX SCALE
     --------------------------------------------------------------------------- */
  --z-base:      0;
  --z-elevated:  10;
  --z-sticky:    100;
  --z-overlay:   1000;
  --z-modal:     2000;
  --z-toast:     3000;
}

/* =============================================================================
   LIGHT THEME — Override via [data-theme="light"] on <html> or <body>
   Keeps accent colors identical (brand consistency), shifts only neutrals.
   ============================================================================= */
:root[data-theme="light"],
:root[data-theme="light"] body {
  /* Backgrounds — inverted neutral scale */
  --bg-base:            #fafafa;
  --bg-panel:           #ffffff;
  --bg-panel-elevated:  #f4f4f6;
  --bg-input:           #ffffff;
  --bg-code:            #f4f4f6;

  /* Borders — black-alpha instead of white-alpha */
  --border-subtle:  rgba(0, 0, 0, 0.06);
  --border-default: rgba(0, 0, 0, 0.10);
  --border-strong:  rgba(0, 0, 0, 0.16);

  /* Text — dark on light */
  --text-primary:   #18181b;
  --text-secondary: #52525b;
  --text-muted:     #71717a;
  --text-dim:       #a1a1aa;

  /* Dim accent variants — slightly stronger for visibility on white */
  --accent-info-dim:       rgba(6, 182, 212, 0.12);
  --accent-success-dim:    rgba(16, 185, 129, 0.12);
  --accent-danger-dim:     rgba(239, 68, 68, 0.10);
  --accent-warning-dim:    rgba(245, 158, 11, 0.14);
  --accent-header-dim:     rgba(168, 85, 247, 0.10);
  --accent-secondary-dim:  rgba(249, 115, 22, 0.12);

  /* Shadows — stronger contrast on light */
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-md:  0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg:  0 12px 32px rgba(0, 0, 0, 0.12);
}

/* Auto-detect system preference on first load (no data-theme set yet) */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]),
  :root:not([data-theme]) body {
    --bg-base:            #fafafa;
    --bg-panel:           #ffffff;
    --bg-panel-elevated:  #f4f4f6;
    --bg-input:           #ffffff;
    --bg-code:            #f4f4f6;
    --border-subtle:  rgba(0, 0, 0, 0.06);
    --border-default: rgba(0, 0, 0, 0.10);
    --border-strong:  rgba(0, 0, 0, 0.16);
    --text-primary:   #18181b;
    --text-secondary: #52525b;
    --text-muted:     #71717a;
    --text-dim:       #a1a1aa;
    --accent-info-dim:       rgba(6, 182, 212, 0.12);
    --accent-success-dim:    rgba(16, 185, 129, 0.12);
    --accent-danger-dim:     rgba(239, 68, 68, 0.10);
    --accent-warning-dim:    rgba(245, 158, 11, 0.14);
    --accent-header-dim:     rgba(168, 85, 247, 0.10);
    --accent-secondary-dim:  rgba(249, 115, 22, 0.12);
  }
}

/* Smooth transition when toggling theme */
html, body, .page, .panel, .kpi, .stato-progetto,
.nav-section, .btn, .table, .input, .tag, .toggle-group {
  transition:
    background-color var(--duration-normal) var(--ease-out),
    border-color var(--duration-normal) var(--ease-out),
    color var(--duration-normal) var(--ease-out);
}

/* =============================================================================
   BASE RESET — Minimal, opinionated
   ============================================================================= */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
  font-feature-settings: 'ss01', 'cv01'; /* stylistic alternates in JetBrains Mono */
}

/* Typographic rhythm */
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
}

p { margin: 0; }

/* Links — subtle, inherit color by default, underline on hover */
a {
  color: var(--accent-info);
  text-decoration: none;
  transition: opacity var(--duration-fast) var(--ease-out);
}
a:hover { opacity: 0.8; }

/* Code */
code, pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}
