@layer reset, base, tokens, components, modules, utilities;

/* ═══════════════════════════════════════════════════════════ */
/* RESET */
/* ═══════════════════════════════════════════════════════════ */
@layer reset {
  *, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  html, body {
    height: 100%;
  }

  img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
  }

  input, button, textarea, select {
    font: inherit;
    color: inherit;
  }

  p, h1, h2, h3, h4, h5, h6 {
    overflow-wrap: break-word;
  }

  a {
    text-decoration: none;
    color: inherit;
  }

  ul, ol {
    list-style: none;
  }
}

/* ═══════════════════════════════════════════════════════════ */
/* BASE */
/* ═══════════════════════════════════════════════════════════ */
@layer base {
  :root {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    letter-spacing: var(--tracking-normal);
  }

  ::selection {
    background: var(--accent-light);
    color: var(--tangerine-50);
  }
}

/* ═══════════════════════════════════════════════════════════ */
/* TOKENS */
/* ═══════════════════════════════════════════════════════════ */
@layer tokens {
  :root {
    /* ── LC2026 Palette ── */
    --bone-50:  #F7F6F3;
    --bone-100: #EEEDE9;
    --bone-200: #DDDCD6;
    --ash-200:  #BFBFB9;
    --pitch-900: #050505;
    --pitch-850: #0C0C0B;
    --pitch-800: #141413;
    --pitch-700: #1F1F1D;
    --pitch-500: #5C5C58;
    --pitch-300: #9A9A95;

    --tangerine-50:  #FFE9D6;
    --tangerine-400: #FF8A4D;
    --tangerine-500: #FF6A1A;
    --tangerine-600: #E45200;

    --success: #6A8F5E;
    --warning: #C9A24A;
    --danger:  #B4513A;
    --info:    #5A7D9A;

    --success-light: rgba(106,143,94,.15);
    --warning-light: rgba(201,162,74,.15);
    --danger-light:  rgba(180,81,58,.15);
    --info-light:    rgba(90,125,154,.15);
    --accent-light:  rgba(255,106,26,.1);

    /* ── Semantic (Dark Mode Default) ── */
    --bg: var(--pitch-900);
    --surface: var(--pitch-800);
    --surface-2: var(--pitch-700);
    --border: var(--pitch-700);
    --text: var(--bone-50);
    --text-muted: var(--pitch-300);

    /* ── Focus Ring ── */
    --focus-ring-color: var(--tangerine-500);
    --focus-ring-offset: 2px;
    --focus-ring-size: 2px;

    /* ── Font Stack ── */
    --font-serif: "Fraunces", Georgia, serif;
    --font-sans: "Inter", system-ui, -apple-system, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, monospace;

    /* ── Type Scale ── */
    --text-xs: 12px;
    --text-sm: 14px;
    --text-base: 15px;
    --text-lg: 17px;
    --text-xl: 20px;
    --text-2xl: 24px;
    --text-3xl: 32px;
    --text-4xl: 44px;
    --text-5xl: 60px;

    /* ── Line Height ── */
    --leading-tight: 1.15;
    --leading-snug: 1.3;
    --leading-normal: 1.5;
    --leading-relaxed: 1.65;

    /* ── Letter Spacing ── */
    --tracking-tight: -0.02em;
    --tracking-normal: -0.01em;
    --tracking-wide: 0.02em;
    --tracking-caps: 0.08em;

    /* ── Spacing ── */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;

    /* ── Container widths ── */
    --container-sm: 40rem;
    --container-md: 56rem;
    --container-lg: 72rem;
    --container-xl: 84rem;
    --gutter: clamp(var(--space-4), 4vw, var(--space-8));

    /* ── Shadows ── */
    --shadow-sm: 0 1px 2px rgba(0,0,0,.18);
    --shadow-md: 0 2px 10px rgba(0,0,0,.25);
    --shadow-lg: 0 16px 40px rgba(0,0,0,.45);

    /* ── Border Radius ── */
    --radius-xs: 6px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 999px;

    /* ── Animation ── */
    --ease: cubic-bezier(.2,.8,.2,1);
    --duration-instant: 100ms;
    --duration-fast: 120ms;
    --duration-normal: 200ms;
    --duration-slow: 320ms;
  }
}

/* ═══════════════════════════════════════════════════════════ */
/* COMPONENTS */
/* ═══════════════════════════════════════════════════════════ */
@layer components {

  /* ── Buttons ── */
  .btn {
    --btn-bg: var(--surface);
    --btn-border: var(--border);
    --btn-color: var(--text);
    --btn-padding: 10px 16px;
    --btn-radius: var(--radius-md);
    --btn-weight: 500;
    --btn-height: 2.5rem;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5em;
    height: var(--btn-height);
    padding: var(--btn-padding);
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    border-radius: var(--btn-radius);
    color: var(--btn-color);
    font-size: var(--text-sm);
    font-weight: var(--btn-weight);
    line-height: 1;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: var(--duration-fast) var(--ease);
    transition-property: background-color, border-color, box-shadow, opacity;
  }

  .btn:focus-visible {
    outline: var(--focus-ring-size) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
  }

  .btn:disabled { opacity: 0.4; cursor: not-allowed; }

  .btn--primary {
    --btn-bg: var(--tangerine-500);
    --btn-border: var(--tangerine-500);
    --btn-color: #fff;
  }
  .btn--primary:hover { --btn-bg: var(--tangerine-600); --btn-border: var(--tangerine-600); }

  .btn--ghost {
    --btn-bg: transparent;
    --btn-border: transparent;
  }
  .btn--ghost:hover { --btn-bg: var(--pitch-800); }

  .btn--destructive {
    --btn-bg: var(--danger-light);
    --btn-border: var(--danger);
    --btn-color: var(--danger);
  }
  .btn--destructive:hover { --btn-bg: var(--danger); --btn-color: #fff; }

  .btn--sm { --btn-height: 1.75rem; --btn-padding: 6px 12px; font-size: var(--text-xs); }
  .btn--lg { --btn-height: 2.75rem; --btn-padding: 12px 24px; font-size: var(--text-base); }
  .btn--icon { width: var(--btn-height); padding: 0; }

  /* ── Inputs ── */
  .input {
    --input-bg: var(--pitch-850);
    --input-border: var(--pitch-700);
    --input-color: var(--text);
    --input-radius: var(--radius-md);
    --input-padding: 0.5em 0.75em;
    --input-height: 2.75rem;

    display: block;
    width: 100%;
    height: var(--input-height);
    padding: var(--input-padding);
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--input-radius);
    color: var(--input-color);
    font-size: var(--text-sm);
    font-family: inherit;
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
  }

  .input::placeholder { color: var(--pitch-500); }

  .input:focus {
    outline: none;
    border-color: var(--tangerine-500);
    box-shadow: 0 0 0 3px var(--accent-light);
  }

  /* ── Field ── */
  .field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
  }

  .field__label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--pitch-300);
    letter-spacing: var(--tracking-wide);
  }

  .field__error {
    font-size: var(--text-xs);
    color: var(--danger);
  }

  /* ── Badges ── */
  .badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 500;
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    white-space: nowrap;
    border: 1px solid transparent;
  }

  .badge::before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
  }

  .badge--positive {
    color: var(--success);
    background: var(--success-light);
    border-color: var(--success);
  }

  .badge--warning {
    color: var(--warning);
    background: var(--warning-light);
    border-color: var(--warning);
  }

  .badge--negative {
    color: var(--danger);
    background: var(--danger-light);
    border-color: var(--danger);
  }

  .badge--info {
    color: var(--info);
    background: var(--info-light);
    border-color: var(--info);
  }

  .badge--neutral {
    color: var(--pitch-300);
    background: var(--pitch-800);
    border-color: var(--pitch-700);
  }

  .badge--live::before {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  }

  @keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
  }

  /* ── Cards ── */
  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
  }

  .card:hover {
    border-color: var(--pitch-500);
    box-shadow: var(--shadow-md);
  }

  .card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--pitch-700);
    margin-bottom: var(--space-4);
  }

  .card__title {
    font-family: var(--font-serif);
    font-size: var(--text-lg);
    font-weight: 500;
    color: var(--text);
    letter-spacing: var(--tracking-tight);
  }

  .card__description {
    font-size: var(--text-sm);
    color: var(--text-muted);
    line-height: var(--leading-relaxed);
  }

  /* ── Panel ── */
  .panel {
    max-width: var(--container-sm);
    padding: var(--space-6) var(--space-8);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
  }

  .panel--centered { margin-inline: auto; }

  /* ── Avatar ── */
  .avatar {
    --avatar-size: 2rem;
    display: grid;
    place-items: center;
    width: var(--avatar-size);
    height: var(--avatar-size);
    border-radius: 50%;
    overflow: hidden;
    background: var(--accent-light);
    color: var(--tangerine-500);
    font-size: calc(var(--avatar-size) * 0.4);
    font-weight: 600;
    flex-shrink: 0;
  }

  .avatar--sm { --avatar-size: 1.5rem; }
  .avatar--lg { --avatar-size: 2.5rem; }
}

/* ═══════════════════════════════════════════════════════════ */
/* MODULES */
/* ═══════════════════════════════════════════════════════════ */
@layer modules {

  /* ── Login View ── */
  .login-view {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    padding: var(--space-6);
    background: var(--bg);
  }

  .login-card {
    width: 100%;
    max-width: 420px;
    padding: var(--space-10) var(--space-6);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
  }

  .login-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-8);
    text-align: center;
  }

  .brand-icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
  }

  .brand-icon--sm { width: 32px; height: 32px; }

  .brand-title {
    font-family: var(--font-serif);
    font-size: var(--text-2xl);
    font-weight: 500;
    letter-spacing: var(--tracking-tight);
    line-height: var(--leading-tight);
    color: var(--text);
  }

  .brand-subtitle {
    font-size: var(--text-sm);
    color: var(--pitch-500);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
  }

  .login-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }

  .login-hint {
    margin-top: var(--space-6);
    text-align: center;
    font-size: var(--text-xs);
    color: var(--pitch-500);
  }

  /* ── Dashboard Layout ── */
  .dashboard-view {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: auto 1fr;
    min-height: 100dvh;
    background: var(--bg);
  }

  /* ── Sidebar ── */
  .sidebar {
    grid-row: 1 / -1;
    display: flex;
    flex-direction: column;
    padding: var(--space-4);
    gap: var(--space-2);
    background: var(--pitch-850);
    border-right: 1px solid var(--pitch-700);
    overflow-y: auto;
  }

  .sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-2);
    margin-bottom: var(--space-4);
  }

  .sidebar__brand-text {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text);
    letter-spacing: var(--tracking-tight);
  }

  .sidebar__brand img {
    height: 52px;
    width: auto;
    max-width: 200px;
    object-fit: contain;
    filter: brightness(1.1);
  }

  .sidebar__section-label {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--pitch-500);
    text-transform: uppercase;
    letter-spacing: var(--tracking-caps);
  }

  .sidebar__nav {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    flex: 1;
  }

  .nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    color: var(--pitch-300);
    font-size: var(--text-sm);
    font-weight: 500;
    transition: background var(--duration-fast), color var(--duration-fast);
  }

  .nav-item:hover {
    background: var(--pitch-800);
    color: var(--text);
  }

  .nav-item--active {
    background: var(--accent-light);
    color: var(--tangerine-500);
    font-weight: 600;
  }

  .sidebar__footer {
    margin-top: auto;
    padding-top: var(--space-4);
    border-top: 1px solid var(--pitch-700);
  }

  .user-widget {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2);
  }

  .user-widget__name {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text);
  }

  .user-widget__role {
    font-size: var(--text-xs);
    color: var(--pitch-500);
  }

  /* ── Main Content ── */
  .main {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: 0 var(--space-6);
    height: 56px;
    background: var(--pitch-850);
    border-bottom: 1px solid var(--pitch-700);
    flex-shrink: 0;
  }

  .topbar__title {
    font-family: var(--font-serif);
    font-size: var(--text-lg);
    font-weight: 500;
    color: var(--text);
    letter-spacing: var(--tracking-tight);
  }

  .topbar__actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }

  .page {
    padding: var(--space-6) var(--space-8);
    overflow-y: auto;
    flex: 1;
  }

  .page__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-8);
  }

  .page__title {
    font-family: var(--font-serif);
    font-size: var(--text-2xl);
    font-weight: 500;
    letter-spacing: var(--tracking-tight);
    line-height: var(--leading-tight);
    color: var(--text);
  }

  .page__subtitle {
    font-size: var(--text-sm);
    color: var(--pitch-500);
    margin-top: var(--space-1);
  }

  /* ── Tools Grid ── */
  .tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-4);
  }

  .tool-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }

  .tool-card:hover {
    border-color: var(--pitch-500);
    box-shadow: var(--shadow-md);
  }

  .tool-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
  }

  .tool-card__icon {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    background: var(--accent-light);
    border-radius: var(--radius-md);
    color: var(--tangerine-500);
    flex-shrink: 0;
  }

  .tool-card__title {
    font-family: var(--font-serif);
    font-size: var(--text-lg);
    font-weight: 500;
    color: var(--text);
    letter-spacing: var(--tracking-tight);
  }

  .tool-card__description {
    font-size: var(--text-sm);
    color: var(--text-muted);
    line-height: var(--leading-relaxed);
    flex: 1;
  }

  .tool-card__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: var(--space-4);
    border-top: 1px solid var(--pitch-700);
  }

  /* ── Responsive ── */
  @media (max-width: 768px) {
    .dashboard-view {
      grid-template-columns: 1fr;
      grid-template-rows: auto auto 1fr;
    }

    .sidebar {
      grid-row: auto;
      flex-direction: row;
      align-items: center;
      padding: var(--space-3) var(--space-4);
      border-right: none;
      border-bottom: 1px solid var(--pitch-700);
    }

    .sidebar__brand { margin-bottom: 0; }
    .sidebar__nav { flex-direction: row; }
    .sidebar__footer { display: none; }
    .nav-item span { display: none; }

    .page {
      padding: var(--space-4);
    }

    .tools-grid {
      grid-template-columns: 1fr;
    }
  }
}

/* ═══════════════════════════════════════════════════════════ */
/* UTILITIES */
/* ═══════════════════════════════════════════════════════════ */
@layer utilities {
  .visually-hidden {
    clip-path: inset(50%);
    overflow: hidden;
    position: absolute;
    width: 1px;
    height: 1px;
    white-space: nowrap;
  }

  :focus-visible {
    outline: var(--focus-ring-size) solid var(--focus-ring-color);
    outline-offset: var(--focus-ring-offset);
    border-radius: var(--radius-xs);
  }

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