/* ─────────────────────────────────────────────────────────────────
   Arrange — v2 · Werkstatt
   Bauhaus-skewed. Primary triad, lowercase display, sharp corners,
   heavy black rules. The Dessau workshop as interface.
   ───────────────────────────────────────────────────────────────── */

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

/* ─────────────────────────────────────────────────────────────────
   A. TOKENS
   ───────────────────────────────────────────────────────────────── */
@layer tokens {
  :root {
    /* Surface — pure white, no warm cast */
    --paper:    #ffffff;
    --paper-2:  #f3f3f1;
    --paper-3:  #e6e6e2;

    /* Text — pure ink, full contrast */
    --ink:      #0a0a0a;
    --ink-2:    #2a2a2a;
    --ink-3:    #6e6e6e;

    /* Rules — black is the divider, not a pale gray */
    --rule:       #0a0a0a;
    --rule-soft:  #d4d4d0;

    /* Bauhaus primary triad
       Kandinsky's color-form: red = square, yellow = triangle, blue = circle */
    --bh-red:    #e3261b;
    --bh-yellow: #f2b21a;
    --bh-blue:   #2c5fa0;

    /* Roles bind to triad */
    --accent:       var(--bh-blue);
    --accent-ink:   #ffffff;
    --accent-wash:  rgba(44, 95, 160, 0.10);
    --accent-line:  rgba(44, 95, 160, 0.40);

    --status-positive:      #1f7a3a;
    --status-positive-wash: rgba(31, 122, 58, 0.10);
    --status-warning:       var(--bh-yellow);
    --status-warning-wash:  rgba(242, 178, 26, 0.18);
    --status-negative:      var(--bh-red);
    --status-negative-wash: rgba(227, 38, 27, 0.10);
    --status-info:          var(--bh-blue);
    --status-info-wash:     var(--accent-wash);

    /* Typography
       Display: geometric grotesque (Futura family) for poster moments
       Sans: Inter for UI text
       Mono: JetBrains Mono for codes and numerals */
    --font-display: "Futura PT", Futura, "ITC Avant Garde Gothic Std", "Avenir Next", "Century Gothic", Inter, system-ui, sans-serif;
    --font-sans:    "Inter", "Helvetica Neue", system-ui, -apple-system, 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:  20px;
    --t-xl:  32px;
    --t-2xl: 48px;
    --t-3xl: 80px;   /* poster moments */

    --lh-tight: 0.95;
    --lh-snug:  1.15;
    --lh-base:  1.5;

    --tracking-eyebrow: 0.14em;
    --tracking-caps:    0.06em;
    --tracking-display: -0.025em;

    /* 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;
    --s-9: 96px;

    /* Radius — zero, by design */
    --r-sm: 0;
    --r-md: 0;

    /* Motion — fast and final */
    --m-quick: 100ms;
    --m-base:  150ms;
    --ease:    cubic-bezier(0.2, 0, 0, 1);

    /* Rule weights — Bauhaus loved thick black bars */
    --rule-thin:  1px;
    --rule-mid:   2px;
    --rule-heavy: 4px;

    /* No elevation. Buildings do not float. */
    --shadow-float: none;

    --control-h-sm: 26px;
    --control-h-md: 36px;
    --control-h-lg: 48px;
  }

  [data-theme="ink"] {
    --paper:    #0a0a0a;
    --paper-2:  #181818;
    --paper-3:  #262626;

    --ink:      #ffffff;
    --ink-2:    #dcdcdc;
    --ink-3:    #8a8a8a;

    --rule:       #ffffff;
    --rule-soft:  #2e2e2e;

    /* Triad slightly desaturated for dark — same identity, less glare */
    --bh-red:    #ff4538;
    --bh-yellow: #f5c742;
    --bh-blue:   #5b8fcc;

    --accent:       var(--bh-blue);
    --accent-ink:   #0a0a0a;
    --accent-wash:  rgba(91, 143, 204, 0.16);
    --accent-line:  rgba(91, 143, 204, 0.45);

    --status-positive:      #5dd07b;
    --status-positive-wash: rgba(93, 208, 123, 0.14);
    --status-warning:       var(--bh-yellow);
    --status-warning-wash:  rgba(245, 199, 66, 0.18);
    --status-negative:      var(--bh-red);
    --status-negative-wash: rgba(255, 69, 56, 0.14);
  }
}

/* ─────────────────────────────────────────────────────────────────
   B. BASE
   ───────────────────────────────────────────────────────────────── */
@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); }

  /* Display type — lowercase, Bayer's principle. */
  h1, h2, h3, h4, h5, h6 {
    margin: 0;
    font-family: var(--font-display);
    font-weight: var(--w-bold);
    line-height: var(--lh-tight);
    color: var(--ink);
    text-transform: lowercase;
  }
  h1 { font-size: var(--t-3xl); letter-spacing: var(--tracking-display); }
  h2 { font-size: var(--t-2xl); letter-spacing: var(--tracking-display); }
  h3 { font-size: var(--t-xl);  letter-spacing: var(--tracking-display); line-height: var(--lh-snug); }
  h4 { font-size: var(--t-lg); font-weight: var(--w-medium); line-height: var(--lh-snug); }

  p { margin: 0; }

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

  ::selection { background: var(--bh-yellow); color: var(--ink); }

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

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

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

/* ─────────────────────────────────────────────────────────────────
   C. PRIMITIVES
   ───────────────────────────────────────────────────────────────── */
@layer primitives {

  .eyebrow {
    font-family: var(--font-sans);
    font-size: var(--t-xs);
    font-weight: var(--w-bold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-eyebrow);
    color: var(--ink);
  }
  .eyebrow--muted { color: var(--ink-3); }

  /* — Button — heavy borders, uppercase tracking, no radius */
  .btn {
    --_bg: transparent;
    --_fg: var(--ink);
    --_border: var(--ink);
    --_bg-hover: var(--ink);
    --_fg-hover: var(--paper);
    --_border-hover: var(--ink);

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    height: var(--control-h-md);
    padding: 0 var(--s-4);
    font-family: var(--font-sans);
    font-size: var(--t-sm);
    font-weight: var(--w-bold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-caps);
    line-height: 1;
    color: var(--_fg);
    background: var(--_bg);
    border: var(--rule-mid) solid var(--_border);
    border-radius: 0;
    cursor: pointer;
    user-select: none;
    transition:
      background-color var(--m-quick) var(--ease),
      color           var(--m-quick) var(--ease),
      border-color    var(--m-quick) var(--ease);
  }
  .btn:hover {
    background: var(--_bg-hover);
    color: var(--_fg-hover);
    border-color: var(--_border-hover);
  }
  .btn:focus-visible {
    outline: 2px solid var(--bh-yellow);
    outline-offset: 2px;
  }
  .btn[disabled],
  .btn[aria-disabled="true"] {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
  }

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

  .btn--ghost {
    --_border: transparent;
    --_border-hover: transparent;
    --_bg-hover: var(--paper-2);
    --_fg-hover: var(--ink);
  }

  .btn--danger {
    --_fg: var(--bh-red);
    --_border: var(--bh-red);
    --_bg-hover: var(--bh-red);
    --_fg-hover: var(--paper);
    --_border-hover: var(--bh-red);
  }

  .btn--sm { height: var(--control-h-sm); padding: 0 var(--s-3); font-size: var(--t-xs); }
  .btn--lg { height: var(--control-h-lg); padding: 0 var(--s-5); 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 — drafting underline, not a full enclosure */
  .input,
  .select,
  .textarea {
    display: block;
    width: 100%;
    height: var(--control-h-md);
    padding: 0 var(--s-2);
    font-family: var(--font-sans);
    font-size: var(--t-md);
    color: var(--ink);
    background: transparent;
    border: 0;
    border-bottom: var(--rule-mid) solid var(--ink);
    border-radius: 0;
    transition: border-color var(--m-quick) var(--ease), background-color var(--m-quick) var(--ease);
  }
  .input::placeholder,
  .textarea::placeholder { color: var(--ink-3); }
  .input:hover, .select:hover, .textarea:hover { border-color: var(--accent); }
  .input:focus, .select:focus, .textarea:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--accent-wash);
  }

  .textarea {
    height: auto;
    padding: var(--s-2);
    line-height: var(--lh-base);
    border: var(--rule-mid) solid var(--ink);
    resize: vertical;
  }

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

  .checkbox,
  .radio {
    appearance: none;
    width: 18px;
    height: 18px;
    margin: 0;
    background: var(--paper);
    border: var(--rule-mid) solid var(--ink);
    border-radius: 0;
    cursor: pointer;
    display: inline-grid;
    place-content: center;
    vertical-align: middle;
    transition: background-color var(--m-quick) var(--ease);
  }
  .radio { border-radius: 999px; }
  .checkbox:checked,
  .radio:checked {
    background: var(--accent);
    border-color: var(--accent);
  }
  .checkbox:checked::after {
    content: "";
    width: 10px;
    height: 5px;
    border-left: 2px solid var(--accent-ink);
    border-bottom: 2px solid var(--accent-ink);
    transform: rotate(-45deg) translate(1px, -1px);
  }
  .radio:checked::after {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--accent-ink);
  }

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

  /* — Card — sharp, full enclosure with thick border */
  .card {
    background: var(--paper);
    border: var(--rule-mid) solid var(--ink);
    border-radius: 0;
    padding: var(--s-5);
  }
  .card--panel  { background: var(--paper-2); border-color: var(--rule-soft); border-width: var(--rule-thin); }
  .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: var(--rule-mid) solid var(--ink);
  }
  .card__title {
    font-family: var(--font-display);
    font-size: var(--t-lg);
    font-weight: var(--w-bold);
    text-transform: lowercase;
  }
  .card__meta { font-size: var(--t-sm); color: var(--ink-3); }

  /* — Table — heavy header rule, no row alternation */
  .table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--t-sm);
    color: var(--ink);
  }
  .table th {
    text-align: left;
    font-family: var(--font-sans);
    font-weight: var(--w-bold);
    font-size: var(--t-xs);
    text-transform: uppercase;
    letter-spacing: var(--tracking-eyebrow);
    color: var(--ink);
    padding: var(--s-3);
    border-bottom: var(--rule-mid) solid var(--ink);
    white-space: nowrap;
  }
  .table td {
    padding: var(--s-3);
    border-bottom: var(--rule-thin) 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 — sharp, uppercase, color-coded */
  .tag {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    height: 22px;
    padding: 0 var(--s-2);
    font-family: var(--font-sans);
    font-size: var(--t-xs);
    font-weight: var(--w-bold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-caps);
    line-height: 1;
    color: var(--ink);
    background: transparent;
    border: var(--rule-thin) solid var(--ink);
    border-radius: 0;
    white-space: nowrap;
  }
  .tag--accent   { color: var(--accent);          border-color: var(--accent);          background: var(--accent-wash); }
  .tag--positive { color: var(--status-positive); border-color: var(--status-positive); background: var(--status-positive-wash); }
  .tag--warning  { color: var(--ink);             border-color: var(--ink);             background: var(--bh-yellow); }
  .tag--negative { color: var(--paper);           border-color: var(--bh-red);          background: var(--bh-red); }

  /* — Status mark — square, the Bauhaus building block */
  .dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 0;
    background: var(--ink-3);
    flex-shrink: 0;
  }
  .dot--positive { background: var(--status-positive); }
  .dot--warning  { background: var(--bh-yellow); }
  .dot--negative { background: var(--bh-red); }
  .dot--info     { background: var(--bh-blue); }

  /* — Tabs / Segmented — black/white block toggles */
  .tabs {
    display: inline-flex;
    border: var(--rule-mid) solid var(--ink);
    border-radius: 0;
    background: var(--paper);
  }
  .tabs__tab {
    appearance: none;
    border: 0;
    background: transparent;
    font-family: var(--font-sans);
    font-size: var(--t-xs);
    font-weight: var(--w-bold);
    text-transform: uppercase;
    letter-spacing: var(--tracking-caps);
    color: var(--ink);
    padding: 0 var(--s-3);
    height: 28px;
    cursor: pointer;
    border-radius: 0;
    border-right: var(--rule-thin) solid var(--ink);
    transition: background-color var(--m-quick) var(--ease), color var(--m-quick) var(--ease);
  }
  .tabs__tab:last-child { border-right: 0; }
  .tabs__tab:hover { background: var(--paper-2); }
  .tabs__tab[aria-selected="true"] {
    background: var(--ink);
    color: var(--paper);
  }

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

  /* — Divider */
  .divider        { height: var(--rule-thin); background: var(--ink); margin: var(--s-4) 0; }
  .divider--heavy { height: var(--rule-heavy); }

  /* — Bauhaus marks — Kandinsky color-form pairings
       red = square, yellow = triangle, blue = circle */
  .mark {
    display: inline-block;
    flex-shrink: 0;
    width: 22px;
    height: 22px;
  }
  .mark--square   { background: var(--bh-red); }
  .mark--circle   { background: var(--bh-blue); border-radius: 999px; }
  .mark--triangle {
    width: 0;
    height: 0;
    background: transparent;
    border-left: 11px solid transparent;
    border-right: 11px solid transparent;
    border-bottom: 20px solid var(--bh-yellow);
  }
  .mark--outline.mark--square   { background: transparent; box-shadow: inset 0 0 0 2px var(--ink); }
  .mark--outline.mark--circle   { background: transparent; box-shadow: inset 0 0 0 2px var(--ink); }
}

/* ─────────────────────────────────────────────────────────────────
   D. COMPONENTS
   ───────────────────────────────────────────────────────────────── */
@layer components {

  .page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--s-5);
    padding: var(--s-7) 0 var(--s-4);
    border-bottom: var(--rule-heavy) solid var(--ink);
    margin-bottom: var(--s-7);
  }
  .page-head__title {
    font-size: var(--t-3xl);
    letter-spacing: var(--tracking-display);
    line-height: var(--lh-tight);
  }
  .page-head__meta {
    font-family: var(--font-mono);
    font-size: var(--t-sm);
    color: var(--ink-3);
    text-transform: uppercase;
    letter-spacing: var(--tracking-caps);
    white-space: nowrap;
  }

  /* List + detail shell */
  .shell {
    display: grid;
    grid-template-columns: 320px 1fr;
    min-height: 480px;
    border: var(--rule-mid) solid var(--ink);
  }
  .shell__rail {
    border-right: var(--rule-mid) solid var(--ink);
    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-3);
    padding: var(--s-8) var(--s-5);
    color: var(--ink-3);
  }
  .empty__title {
    font-family: var(--font-display);
    font-size: var(--t-lg);
    font-weight: var(--w-bold);
    text-transform: lowercase;
    color: var(--ink-2);
  }
}

/* ─────────────────────────────────────────────────────────────────
   E. UTILITIES
   ───────────────────────────────────────────────────────────────── */
@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; }
  .caps    { text-transform: uppercase; letter-spacing: var(--tracking-caps); font-weight: var(--w-bold); }

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