/* ─────────────────────────────────────────────────────────────────
   Arrange — v3 · Tisch
   The plane and the object. Rams + Bauhaus product design.
   White is a physical shape. Components are things resting on it.
   Single-source workshop light from upper-left, short directional shadows.
   ───────────────────────────────────────────────────────────────── */

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

/* ─────────────────────────────────────────────────────────────────
   A. TOKENS
   ───────────────────────────────────────────────────────────────── */
@layer tokens {
  :root {
    /* The plane — warm white, owned as a physical surface */
    --plane:        #f7f4ed;
    --plane-2:      #efece4;
    --plane-3:      #e6e2d8;
    --plane-edge:   rgba(34, 28, 22, 0.07);

    /* Ink — warm graphite, never pure black (Rams' Braun never used pure black) */
    --ink:          #221c16;
    --ink-2:        #4a4138;
    --ink-3:        #8a8175;

    /* Compatibility aliases (so primitive class names match across versions) */
    --paper:        var(--plane);
    --paper-2:      var(--plane-2);
    --paper-3:      var(--plane-3);

    --rule:         rgba(34, 28, 22, 0.18);
    --rule-soft:    rgba(34, 28, 22, 0.08);

    /* Single accent — Rams' burnt sienna. The indicator light on a Braun hi-fi. */
    --accent:       #b8651c;
    --accent-ink:   #f7f4ed;
    --accent-wash:  rgba(184, 101, 28, 0.10);
    --accent-line:  rgba(184, 101, 28, 0.45);

    /* Status — matte ceramic colors, not pure CMYK */
    --status-positive:      #3d6e3a;
    --status-positive-wash: rgba(61, 110, 58, 0.10);
    --status-warning:       #ab7a14;
    --status-warning-wash:  rgba(171, 122, 20, 0.12);
    --status-negative:      #9a3a2a;
    --status-negative-wash: rgba(154, 58, 42, 0.10);
    --status-info:          var(--accent);
    --status-info-wash:     var(--accent-wash);

    /* Type — confident, label-like. Sentence case, Braun product nomenclature. */
    --font-sans:    "Inter", "Helvetica Neue", Helvetica, system-ui, sans-serif;
    --font-mono:    "JetBrains Mono", "IBM Plex Mono", ui-monospace, Menlo, monospace;

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

    --t-xs:  11px;
    --t-sm:  13px;
    --t-md:  15px;
    --t-lg:  18px;
    --t-xl:  26px;
    --t-2xl: 40px;
    --t-3xl: 56px;

    --lh-tight: 1.12;
    --lh-base:  1.5;

    --tracking-eyebrow: 0.10em;
    --tracking-display: -0.012em;
    --tracking-label:   0.02em;

    /* 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 — physical objects have slight rounding from manufacturing */
    --r-sm:  3px;
    --r-md:  6px;
    --r-lg:  10px;
    --r-pill: 999px;

    /* Motion — gravity-aware */
    --m-quick: 140ms;
    --m-base:  220ms;
    --ease:      cubic-bezier(0.2, 0, 0, 1);
    --ease-lift: cubic-bezier(0.2, 0.7, 0.3, 1);

    /* Elevation — the visual language of v3.
       Single-source light from upper-left. Shadows are short and real. */
    --e0: 0 0 0 0 transparent;
    --e1: 0 1px 0 rgba(34, 28, 22, 0.06),
          0 2px 4px rgba(34, 28, 22, 0.05);
    --e2: 0 1px 0 rgba(34, 28, 22, 0.05),
          0 6px 14px rgba(34, 28, 22, 0.09);
    --e3: 0 1px 0 rgba(34, 28, 22, 0.04),
          0 4px 10px rgba(34, 28, 22, 0.07),
          0 18px 40px rgba(34, 28, 22, 0.12);
    --inset-cut: inset 0 1px 2px rgba(34, 28, 22, 0.08),
                 inset 0 0 0 1px rgba(34, 28, 22, 0.05);

    /* Control metrics */
    --control-h-sm: 28px;
    --control-h-md: 36px;
    --control-h-lg: 46px;
  }

  [data-theme="ink"] {
    /* Workshop at night, lit by a task lamp from above */
    --plane:    #1a1815;
    --plane-2:  #221f1a;
    --plane-3:  #2b2722;
    --plane-edge: rgba(255, 248, 235, 0.07);

    --paper:    var(--plane);
    --paper-2:  var(--plane-2);
    --paper-3:  var(--plane-3);

    --ink:      #ede6d8;
    --ink-2:    #b8af9d;
    --ink-3:    #807868;

    --rule:       rgba(255, 248, 235, 0.18);
    --rule-soft:  rgba(255, 248, 235, 0.08);

    --accent:       #e08555;
    --accent-ink:   #1a1815;
    --accent-wash:  rgba(224, 133, 85, 0.14);
    --accent-line:  rgba(224, 133, 85, 0.45);

    --status-positive: #6fa56a;
    --status-warning:  #d4a040;
    --status-negative: #d27068;

    /* Shadows on dark: less ambient, more contrast under the lamp */
    --e1: 0 1px 0 rgba(0, 0, 0, 0.55),
          0 2px 6px rgba(0, 0, 0, 0.45);
    --e2: 0 1px 0 rgba(0, 0, 0, 0.55),
          0 8px 18px rgba(0, 0, 0, 0.55);
    --e3: 0 1px 0 rgba(0, 0, 0, 0.4),
          0 6px 12px rgba(0, 0, 0, 0.5),
          0 24px 48px rgba(0, 0, 0, 0.65);
    --inset-cut: inset 0 1px 2px rgba(0, 0, 0, 0.55),
                 inset 0 0 0 1px rgba(255, 248, 235, 0.05);
  }
}

/* ─────────────────────────────────────────────────────────────────
   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(--plane);
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "cv11", "ss01", "ss03";
  }

  /* The plane is lit. A faint directional wash suggests an upper-left key light. */
  body {
    margin: 0;
    color: var(--ink);
    background:
      radial-gradient(1200px 800px at -10% -20%,
        color-mix(in srgb, var(--plane) 85%, #ffffff 15%) 0%,
        var(--plane) 55%);
    min-height: 100vh;
  }

  [data-theme="ink"] body {
    background:
      radial-gradient(1200px 800px at 50% -30%,
        color-mix(in srgb, var(--plane) 70%, #ffffff 6%) 0%,
        var(--plane) 60%);
  }

  h1, h2, h3, h4, h5, h6 {
    margin: 0;
    font-family: var(--font-sans);
    font-weight: var(--w-bold);
    line-height: var(--lh-tight);
    color: var(--ink);
    letter-spacing: var(--tracking-display);
  }
  h1 { font-size: var(--t-3xl); }
  h2 { font-size: var(--t-2xl); }
  h3 { font-size: var(--t-xl); }
  h4 { font-size: var(--t-lg); 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); }

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

  hr {
    border: 0;
    height: 1px;
    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 — each is a physical object
   ───────────────────────────────────────────────────────────────── */
@layer primitives {

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

  /* — Button — the KEY.
     Sits on the plane (e1). On hover it lifts (e2). On press it presses back down. */
  .btn {
    --_bg: var(--plane);
    --_fg: var(--ink);
    --_border: var(--rule);
    --_shadow: var(--e1);
    --_shadow-hover: var(--e2);

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s-2);
    height: var(--control-h-md);
    padding: 0 var(--s-4);
    font: inherit;
    font-family: var(--font-sans);
    font-size: var(--t-sm);
    font-weight: var(--w-medium);
    letter-spacing: var(--tracking-label);
    line-height: 1;
    color: var(--_fg);
    background: var(--_bg);
    border: 1px solid var(--_border);
    border-radius: var(--r-sm);
    box-shadow: var(--_shadow);
    cursor: pointer;
    user-select: none;
    transform: translateY(0);
    transition:
      box-shadow  var(--m-quick) var(--ease-lift),
      transform   var(--m-quick) var(--ease-lift),
      background-color var(--m-quick) var(--ease),
      border-color var(--m-quick) var(--ease),
      color       var(--m-quick) var(--ease);
  }
  .btn:hover {
    box-shadow: var(--_shadow-hover);
    transform: translateY(-1px);
  }
  .btn:active {
    box-shadow: var(--e0), inset 0 1px 2px rgba(34, 28, 22, 0.10);
    transform: translateY(0);
  }
  .btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }
  .btn[disabled],
  .btn[aria-disabled="true"] {
    opacity: 0.45;
    box-shadow: var(--e0);
    cursor: not-allowed;
    pointer-events: none;
    transform: none;
  }

  .btn--primary {
    --_bg: var(--ink);
    --_fg: var(--plane);
    --_border: var(--ink);
  }
  .btn--primary:active {
    box-shadow: var(--e0), inset 0 1px 2px rgba(0, 0, 0, 0.4);
  }

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

  .btn--ghost {
    --_bg: transparent;
    --_border: transparent;
    --_shadow: var(--e0);
    --_shadow-hover: var(--e0);
  }
  .btn--ghost:hover { background: var(--plane-2); transform: none; }

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

  .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); }

  /* — Input — a SLOT cut into the plane.
     Inset shadow makes the field feel recessed; the plane is intact above it. */
  .input,
  .select,
  .textarea {
    display: block;
    width: 100%;
    height: var(--control-h-md);
    padding: 0 var(--s-3);
    font: inherit;
    font-family: var(--font-sans);
    font-size: var(--t-sm);
    color: var(--ink);
    background: var(--plane);
    border: 0;
    border-radius: var(--r-sm);
    box-shadow: var(--inset-cut);
    transition:
      box-shadow 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 {
    box-shadow: var(--inset-cut), 0 0 0 1px var(--rule);
  }

  .input:focus,
  .select:focus,
  .textarea:focus {
    outline: none;
    box-shadow:
      var(--inset-cut),
      0 0 0 2px var(--accent-wash),
      0 0 0 1px 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 {
    appearance: none;
    width: 18px;
    height: 18px;
    margin: 0;
    background: var(--plane);
    border-radius: var(--r-sm);
    box-shadow: var(--inset-cut);
    cursor: pointer;
    display: inline-grid;
    place-content: center;
    vertical-align: middle;
    transition: background-color var(--m-quick) var(--ease), box-shadow var(--m-quick) var(--ease);
  }
  .radio { border-radius: var(--r-pill); }
  .checkbox:hover, .radio:hover { box-shadow: var(--inset-cut), 0 0 0 1px var(--rule); }
  .checkbox:checked, .radio:checked {
    background: var(--ink);
    box-shadow: var(--e1);
  }
  .checkbox:checked::after {
    content: "";
    width: 9px;
    height: 5px;
    border-left: 1.5px solid var(--plane);
    border-bottom: 1.5px solid var(--plane);
    transform: rotate(-45deg) translate(1px, -1px);
  }
  .radio:checked::after {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: var(--r-pill);
    background: var(--plane);
  }

  .field { display: flex; flex-direction: column; gap: var(--s-2); }
  .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 — a SHEET resting on the plane.
     e1 by default, no border (the shadow does the work). */
  .card {
    background: var(--plane);
    border-radius: var(--r-md);
    box-shadow: var(--e1);
    padding: var(--s-5);
  }
  .card--panel  {
    background: var(--plane-2);
    box-shadow: var(--e0);
    border: 1px solid var(--plane-edge);
  }
  .card--lifted { box-shadow: var(--e2); }
  .card--floating { box-shadow: var(--e3); }
  .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 — PRINT on the plane. No card, no shadow. The page itself. */
  .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-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(--plane-2); }
  .table tbody tr[aria-selected="true"] td { background: var(--accent-wash); }

  /* — Tag — a CHIP. Pill-shaped, slightly elevated. A ceramic disc. */
  .tag {
    display: inline-flex;
    align-items: center;
    gap: var(--s-1);
    height: 22px;
    padding: 0 var(--s-3);
    font-size: var(--t-xs);
    font-weight: var(--w-medium);
    line-height: 1;
    letter-spacing: var(--tracking-label);
    color: var(--ink-2);
    background: var(--plane);
    border-radius: var(--r-pill);
    box-shadow: var(--e1);
    white-space: nowrap;
  }
  .tag--accent   { color: var(--accent);          background: var(--accent-wash);           box-shadow: var(--e1); }
  .tag--positive { color: var(--status-positive); background: var(--status-positive-wash);  box-shadow: var(--e1); }
  .tag--warning  { color: var(--status-warning);  background: var(--status-warning-wash);   box-shadow: var(--e1); }
  .tag--negative { color: var(--status-negative); background: var(--status-negative-wash);  box-shadow: var(--e1); }

  /* — Status indicator — an LED on a product face */
  .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: var(--r-pill);
    background: var(--ink-3);
    flex-shrink: 0;
    box-shadow: inset 0 0 0 0.5px rgba(0,0,0,0.08);
  }
  .dot--positive { background: var(--status-positive); }
  .dot--warning  { background: var(--status-warning); }
  .dot--negative { background: var(--status-negative); }
  .dot--info     { background: var(--accent); }
  .dot--lit {
    box-shadow:
      inset 0 0 0 0.5px rgba(0,0,0,0.10),
      0 0 0 2px color-mix(in srgb, currentColor 20%, transparent);
  }

  /* — Tabs — a row of physical KEYS, the active one depressed */
  .tabs {
    display: inline-flex;
    padding: 3px;
    background: var(--plane);
    border-radius: var(--r-md);
    box-shadow: var(--inset-cut);
    gap: 2px;
  }
  .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: 28px;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color var(--m-quick) var(--ease), color var(--m-quick) var(--ease), box-shadow var(--m-quick) var(--ease);
  }
  .tabs__tab:hover { color: var(--ink); }
  .tabs__tab[aria-selected="true"] {
    background: var(--plane);
    color: var(--ink);
    box-shadow: var(--e1);
  }

  /* — Kbd — a physical key */
  .kbd {
    font-family: var(--font-mono);
    font-size: var(--t-xs);
    padding: 1px 6px;
    color: var(--ink-2);
    background: var(--plane);
    border-radius: var(--r-sm);
    box-shadow: var(--e1), inset 0 -1.5px 0 rgba(34,28,22,0.10);
  }

  .divider { height: 1px; background: var(--rule-soft); margin: var(--s-4) 0; }
  .divider--strong { background: var(--ink); }
}

/* ─────────────────────────────────────────────────────────────────
   D. COMPONENTS
   ───────────────────────────────────────────────────────────────── */
@layer components {
  .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-3xl); letter-spacing: var(--tracking-display); }
  .page-head__meta {
    font-family: var(--font-mono);
    font-size: var(--t-sm);
    color: var(--ink-3);
    font-variant-numeric: tabular-nums;
  }

  .shell {
    display: grid;
    grid-template-columns: 340px 1fr;
    min-height: 480px;
    background: var(--plane);
    border-radius: var(--r-lg);
    box-shadow: var(--e2);
    overflow: hidden;
  }
  .shell__rail {
    border-right: 1px solid var(--rule-soft);
    background: var(--plane-2);
    overflow-y: auto;
  }
  .shell__main {
    background: var(--plane);
    overflow-y: auto;
    padding: var(--s-5);
  }

  .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__title { font-size: var(--t-md); font-weight: var(--w-bold); 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; }
  .grow    { flex: 1 1 0; min-width: 0; }

  /* Object-style helpers — make any element behave like the elevation system */
  .obj-resting  { box-shadow: var(--e1); }
  .obj-lifted   { box-shadow: var(--e2); }
  .obj-floating { box-shadow: var(--e3); }
  .obj-cut      { box-shadow: var(--inset-cut); background: var(--plane); }
}
