/* ─────────────────────────────────────────────────────────────────
   Arrange — Design System (alternate)
   Reference implementation of STYLE.md
   Paper and ink. Drafting blue. Two radii. Three weights.
   ───────────────────────────────────────────────────────────────── */

@layer tokens, base, primitives, components, utilities;

/* ─────────────────────────────────────────────────────────────────
   A. TOKENS — the only source of truth
   ───────────────────────────────────────────────────────────────── */
@layer tokens {
  :root {
    /* Surface — warm paper */
    --paper:    #f5f2eb;
    --paper-2:  #ebe8e0;
    --paper-3:  #e1ddd3;

    /* Text — graphite ink */
    --ink:      #1a1816;
    --ink-2:    #3a3733;
    --ink-3:    #6b6660;

    /* Divider */
    --rule:       #d8d4c8;
    --rule-soft:  #e8e4d8;

    /* Accent — drafting blue, used sparingly */
    --accent:       #2d5278;
    --accent-ink:   #ffffff;
    --accent-wash:  rgba(45, 82, 120, 0.08);
    --accent-line:  rgba(45, 82, 120, 0.35);

    /* Status — functional only */
    --status-positive:      #4a7a3a;
    --status-positive-wash: rgba(74, 122, 58, 0.10);
    --status-warning:       #a36b1a;
    --status-warning-wash:  rgba(163, 107, 26, 0.10);
    --status-negative:      #8b2a2a;
    --status-negative-wash: rgba(139, 42, 42, 0.10);
    --status-info:          var(--accent);
    --status-info-wash:     var(--accent-wash);

    /* Type */
    --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, Menlo, monospace;

    --w-regular: 400;
    --w-medium:  500;
    --w-bold:    700;

    --t-xs:  11px;
    --t-sm:  13px;
    --t-md:  15px;
    --t-lg:  18px;
    --t-xl:  24px;
    --t-2xl: 32px;

    --lh-tight: 1.2;
    --lh-base:  1.5;

    --tracking-eyebrow: 0.06em;
    --tracking-tight:   -0.01em;

    /* Space (4px scale) */
    --s-1:  4px;
    --s-2:  8px;
    --s-3: 12px;
    --s-4: 16px;
    --s-5: 24px;
    --s-6: 32px;
    --s-7: 48px;
    --s-8: 64px;

    /* Radius — two only */
    --r-sm: 2px;
    --r-md: 6px;

    /* Motion */
    --m-quick: 120ms;
    --m-base:  180ms;
    --ease:    cubic-bezier(0.2, 0, 0, 1);

    /* Elevation — used only when something floats */
    --shadow-float:
      0 8px 24px rgba(26, 24, 22, 0.10),
      0 1px 2px  rgba(26, 24, 22, 0.06);

    /* Control metrics */
    --control-h-sm: 24px;
    --control-h-md: 32px;
    --control-h-lg: 40px;
  }

  [data-theme="ink"] {
    --paper:    #16140f;
    --paper-2:  #1f1d18;
    --paper-3:  #28251f;

    --ink:      #f0ede5;
    --ink-2:    #c9c4b8;
    --ink-3:    #8a857a;

    --rule:       #2d2a23;
    --rule-soft:  #221f1a;

    --accent:       #6ea1d1;
    --accent-ink:   #16140f;
    --accent-wash:  rgba(110, 161, 209, 0.12);
    --accent-line:  rgba(110, 161, 209, 0.40);

    --status-positive:      #7ab070;
    --status-positive-wash: rgba(122, 176, 112, 0.14);
    --status-warning:       #d49a4a;
    --status-warning-wash:  rgba(212, 154, 74, 0.14);
    --status-negative:      #c46b6b;
    --status-negative-wash: rgba(196, 107, 107, 0.14);

    --shadow-float:
      0 8px 24px rgba(0, 0, 0, 0.50),
      0 1px 2px  rgba(0, 0, 0, 0.30);
  }
}

/* ─────────────────────────────────────────────────────────────────
   B. BASE — reset, document defaults
   ───────────────────────────────────────────────────────────────── */
@layer base {
  *, *::before, *::after { box-sizing: border-box; }

  html {
    font-family: var(--font-sans);
    font-size: var(--t-md);
    line-height: var(--lh-base);
    color: var(--ink);
    background: var(--paper);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
  }

  h1, h2, h3, h4, h5, h6 {
    margin: 0;
    font-weight: var(--w-bold);
    line-height: var(--lh-tight);
    color: var(--ink);
  }

  h1 { font-size: var(--t-2xl); letter-spacing: var(--tracking-tight); }
  h2 { font-size: var(--t-xl);  letter-spacing: var(--tracking-tight); }
  h3 { font-size: var(--t-lg); }
  h4 { font-size: var(--t-md); font-weight: var(--w-medium); }

  p { margin: 0; }

  a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px solid var(--accent-line);
    transition: color var(--m-quick) var(--ease), border-color var(--m-quick) var(--ease);
  }
  a:hover { color: var(--ink); border-bottom-color: var(--ink); }

  hr {
    border: 0;
    height: 1px;
    background: var(--rule);
    margin: var(--s-5) 0;
  }

  ::selection { background: var(--accent-wash); color: var(--ink); }

  code, kbd, samp {
    font-family: var(--font-mono);
    font-size: 0.92em;
  }

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

/* ─────────────────────────────────────────────────────────────────
   C. PRIMITIVES — the small alphabet
   ───────────────────────────────────────────────────────────────── */
@layer primitives {

  /* — Eyebrow ─────────────────────────────────────────────────── */
  .eyebrow {
    font-size: var(--t-xs);
    font-weight: var(--w-medium);
    text-transform: uppercase;
    letter-spacing: var(--tracking-eyebrow);
    color: var(--ink-3);
  }

  /* — Button ─────────────────────────────────────────────────── */
  .btn {
    --_bg: transparent;
    --_fg: var(--ink);
    --_border: var(--rule);
    --_bg-hover: var(--paper-2);
    --_border-hover: var(--ink-3);

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    height: var(--control-h-md);
    padding: 0 var(--s-3);
    font: inherit;
    font-size: var(--t-sm);
    font-weight: var(--w-medium);
    line-height: 1;
    color: var(--_fg);
    background: var(--_bg);
    border: 1px solid var(--_border);
    border-radius: var(--r-sm);
    cursor: pointer;
    user-select: none;
    transition:
      background-color var(--m-quick) var(--ease),
      border-color    var(--m-quick) var(--ease),
      color           var(--m-quick) var(--ease);
  }
  .btn:hover   { background: var(--_bg-hover); border-color: var(--_border-hover); }
  .btn:active  { background: var(--paper-3); }
  .btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  .btn[disabled],
  .btn[aria-disabled="true"] {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
  }

  .btn--primary {
    --_bg: var(--accent);
    --_fg: var(--accent-ink);
    --_border: var(--accent);
    --_bg-hover: var(--ink);
    --_border-hover: var(--ink);
  }

  .btn--ghost {
    --_border: transparent;
    --_border-hover: transparent;
  }

  .btn--danger {
    --_fg: var(--status-negative);
    --_border: var(--rule);
    --_bg-hover: var(--status-negative);
    --_border-hover: var(--status-negative);
  }
  .btn--danger:hover { color: var(--paper); }

  .btn--sm { height: var(--control-h-sm); padding: 0 var(--s-2); font-size: var(--t-xs); }
  .btn--lg { height: var(--control-h-lg); padding: 0 var(--s-4); font-size: var(--t-md); }

  .btn--icon { width: var(--control-h-md); padding: 0; }
  .btn--icon.btn--sm { width: var(--control-h-sm); }
  .btn--icon.btn--lg { width: var(--control-h-lg); }

  /* — Inputs ────────────────────────────────────────────────── */
  .input,
  .select,
  .textarea {
    display: block;
    width: 100%;
    height: var(--control-h-md);
    padding: 0 var(--s-3);
    font: inherit;
    font-size: var(--t-sm);
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: var(--r-sm);
    transition: border-color var(--m-quick) var(--ease);
  }
  .input::placeholder,
  .textarea::placeholder { color: var(--ink-3); }

  .input:hover,
  .select:hover,
  .textarea:hover { border-color: var(--ink-3); }

  .input:focus,
  .select:focus,
  .textarea:focus {
    outline: none;
    border-color: var(--accent);
  }

  .textarea {
    height: auto;
    padding: var(--s-2) var(--s-3);
    line-height: var(--lh-base);
    resize: vertical;
  }

  .select {
    appearance: none;
    background-image:
      linear-gradient(45deg, transparent 50%, var(--ink-2) 50%),
      linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
    background-position:
      calc(100% - 16px) center,
      calc(100% - 11px) center;
    background-size: 5px 5px;
    background-repeat: no-repeat;
    padding-right: var(--s-6);
  }

  /* Checkbox / Radio */
  .checkbox,
  .radio {
    appearance: none;
    width: 16px;
    height: 16px;
    margin: 0;
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: var(--r-sm);
    cursor: pointer;
    display: inline-grid;
    place-content: center;
    vertical-align: middle;
    transition: border-color var(--m-quick) var(--ease), background-color var(--m-quick) var(--ease);
  }
  .radio { border-radius: 999px; }
  .checkbox:hover,
  .radio:hover { border-color: var(--ink-3); }
  .checkbox:checked,
  .radio:checked {
    background: var(--accent);
    border-color: var(--accent);
  }
  .checkbox:checked::after {
    content: "";
    width: 8px;
    height: 4px;
    border-left: 1.5px solid var(--accent-ink);
    border-bottom: 1.5px solid var(--accent-ink);
    transform: rotate(-45deg) translate(1px, -1px);
  }
  .radio:checked::after {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--accent-ink);
  }

  /* Field anatomy */
  .field { display: flex; flex-direction: column; gap: var(--s-1); }
  .field__label {
    font-size: var(--t-xs);
    font-weight: var(--w-medium);
    color: var(--ink-2);
    text-transform: uppercase;
    letter-spacing: var(--tracking-eyebrow);
  }
  .field__hint { font-size: var(--t-xs); color: var(--ink-3); }

  /* — Card / Panel ─────────────────────────────────────────── */
  .card {
    background: var(--paper);
    border: 1px solid var(--rule);
    border-radius: var(--r-md);
    padding: var(--s-5);
  }
  .card--panel { background: var(--paper-2); border-color: var(--rule-soft); }
  .card--flush { padding: 0; }
  .card__head {
    display: flex; align-items: baseline; justify-content: space-between;
    padding-bottom: var(--s-3);
    margin-bottom: var(--s-3);
    border-bottom: 1px solid var(--rule-soft);
  }
  .card__title { font-size: var(--t-md); font-weight: var(--w-bold); }
  .card__meta  { font-size: var(--t-sm); color: var(--ink-3); }

  /* — Table ─────────────────────────────────────────────────── */
  .table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--t-sm);
    color: var(--ink);
  }
  .table th {
    text-align: left;
    font-weight: var(--w-medium);
    font-size: var(--t-xs);
    text-transform: uppercase;
    letter-spacing: var(--tracking-eyebrow);
    color: var(--ink-3);
    padding: var(--s-2) var(--s-3);
    border-bottom: 1px solid var(--ink);
    white-space: nowrap;
  }
  .table td {
    padding: var(--s-3);
    border-bottom: 1px solid var(--rule-soft);
    vertical-align: top;
  }
  .table td.num,
  .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
  .table td.mono { font-family: var(--font-mono); font-size: 0.92em; color: var(--ink-2); }
  .table tbody tr:hover td { background: var(--paper-2); }
  .table tbody tr[aria-selected="true"] td { background: var(--accent-wash); }

  /* — Tag / Pill ────────────────────────────────────────────── */
  .tag {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    height: 20px;
    padding: 0 var(--s-2);
    font-size: var(--t-xs);
    font-weight: var(--w-medium);
    line-height: 1;
    color: var(--ink-2);
    background: var(--paper-2);
    border: 1px solid var(--rule);
    border-radius: var(--r-sm);
    white-space: nowrap;
  }
  .tag--accent   { color: var(--accent);          border-color: var(--accent-line);  background: var(--accent-wash); }
  .tag--positive { color: var(--status-positive); border-color: var(--status-positive); background: var(--status-positive-wash); }
  .tag--warning  { color: var(--status-warning);  border-color: var(--status-warning);  background: var(--status-warning-wash); }
  .tag--negative { color: var(--status-negative); border-color: var(--status-negative); background: var(--status-negative-wash); }

  /* — Status dot ────────────────────────────────────────────── */
  .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--ink-3);
    flex-shrink: 0;
  }
  .dot--positive { background: var(--status-positive); }
  .dot--warning  { background: var(--status-warning); }
  .dot--negative { background: var(--status-negative); }
  .dot--info     { background: var(--status-info); }

  /* — Tabs / Segmented ───────────────────────────────────────── */
  .tabs {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    background: var(--paper-2);
    border: 1px solid var(--rule);
    border-radius: var(--r-sm);
  }
  .tabs__tab {
    appearance: none;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: var(--t-sm);
    font-weight: var(--w-medium);
    color: var(--ink-2);
    padding: 0 var(--s-3);
    height: 26px;
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: background-color var(--m-quick) var(--ease), color var(--m-quick) var(--ease);
  }
  .tabs__tab:hover { color: var(--ink); }
  .tabs__tab[aria-selected="true"] {
    background: var(--paper);
    color: var(--ink);
    box-shadow: inset 0 0 0 1px var(--rule);
  }

  /* — Kbd ────────────────────────────────────────────────────── */
  .kbd {
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    padding: 1px 6px;
    border: 1px solid var(--rule);
    border-bottom-width: 2px;
    border-radius: var(--r-sm);
    color: var(--ink-2);
    background: var(--paper);
  }

  /* — Divider ─────────────────────────────────────────────────── */
  .divider { height: 1px; background: var(--rule); margin: var(--s-4) 0; }
  .divider--strong { background: var(--ink); }
}

/* ─────────────────────────────────────────────────────────────────
   D. COMPONENTS — composed patterns (kept minimal here)
   ───────────────────────────────────────────────────────────────── */
@layer components {
  /* Mode bar / page header */
  .page-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    padding: var(--s-5) 0 var(--s-4);
    border-bottom: 1px solid var(--ink);
    margin-bottom: var(--s-5);
  }
  .page-head__title  { font-size: var(--t-2xl); letter-spacing: var(--tracking-tight); }
  .page-head__meta   { font-size: var(--t-sm); color: var(--ink-3); font-variant-numeric: tabular-nums; }

  /* List/detail shell */
  .shell {
    display: grid;
    grid-template-columns: 340px 1fr;
    min-height: 480px;
    border: 1px solid var(--rule);
    border-radius: var(--r-md);
    overflow: hidden;
  }
  .shell__rail {
    border-right: 1px solid var(--rule);
    background: var(--paper-2);
    overflow-y: auto;
  }
  .shell__main {
    background: var(--paper);
    overflow-y: auto;
    padding: var(--s-5);
  }

  /* Empty state */
  .empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: var(--s-2);
    padding: var(--s-7) var(--s-5);
    color: var(--ink-3);
  }
  .empty__mark { color: var(--ink-3); margin-bottom: var(--s-2); }
  .empty__title { font-size: var(--t-md); font-weight: var(--w-bold); color: var(--ink-2); }
}

/* ─────────────────────────────────────────────────────────────────
   E. UTILITIES — sparse helpers
   ───────────────────────────────────────────────────────────────── */
@layer utilities {
  .stack       { display: flex; flex-direction: column; gap: var(--s-3); }
  .stack--lg   { gap: var(--s-5); }
  .row         { display: flex; align-items: center; gap: var(--s-3); }
  .row--baseline { align-items: baseline; }
  .row--between  { justify-content: space-between; }

  .muted   { color: var(--ink-3); }
  .mono    { font-family: var(--font-mono); }
  .tabular { font-variant-numeric: tabular-nums; }
  .nowrap  { white-space: nowrap; }

  .grow    { flex: 1 1 0; min-width: 0; }
}
