/* ============================================================
   Meridian — design tokens, themes, primitives
   ============================================================ */

:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable", "Segoe UI", Roboto, Inter, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --font-reading: Georgia, "Iowan Old Style", "Times New Roman", Times, serif;

  --ease: cubic-bezier(.22, .68, .32, 1);
  --ease-in-out: cubic-bezier(.45, 0, .15, 1);
  --t-fast: 120ms;
  --t-med: 200ms;
  --t-slow: 300ms;
  --t-lazy: 460ms;

  --r-xs: 5px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-pill: 999px;

  --rail-w: 76px;
  --folder-w: 264px;
  --topbar-h: 56px;
  --mail-row-min: 74px;
  --mail-row-gap: 0px;
  --omni-w: 560px;

  --cat-blue: #3b6ef5;
  --cat-violet: #7c5cff;
  --cat-indigo: #5b5bd6;
  --cat-teal: #0e9f9f;
  --cat-green: #13a05a;
  --cat-orange: #ed7127;
  --cat-red: #e04848;
  --cat-pink: #e84393;
  --cat-gold: #b98900;

  --cat-blue-ink: #2c55c4;
  --cat-violet-ink: #6039ea;
  --cat-teal-ink: #0a7b7b;
  --cat-green-ink: #0d7a45;
  --cat-orange-ink: #b5531a;
  --cat-red-ink: #b23434;
  --cat-pink-ink: #bc2e78;
  --cat-gold-ink: #8f6a00;
}

:root[data-accent="indigo"]  { --accent: #4661e8; --accent-strong: #3a52d4; --accent-ink: #fff; }
:root[data-accent="blue"]    { --accent: #0f79d8; --accent-strong: #0b63b4; --accent-ink: #fff; }
:root[data-accent="teal"]    { --accent: #0d9488; --accent-strong: #0a756c; --accent-ink: #fff; }
:root[data-accent="plum"]    { --accent: #9457d6; --accent-strong: #7a41bb; --accent-ink: #fff; }
:root[data-accent="copper"]  { --accent: #c2572b; --accent-strong: #a3441e; --accent-ink: #fff; }

/* ---------- Light theme ---------- */
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eceef4;
  --bg-deep: #e4e7f0;
  --surface-0: #f7f8fc;      /* navigation panes */
  --surface-1: #ffffff;      /* raised surfaces, list rows */
  --surface-2: #ffffff;      /* floating chrome */
  --surface-3: #ffffff;      /* modals */
  --surface-sunken: #f0f2f8;
  --surface-hover: #f3f5fb;
  --surface-active: #eaedf9;
  --surface-spill: rgba(38, 50, 86, .045);

  --ink-1: #1b1e2b;
  --ink-2: #555c72;
  --ink-3: #8b91a6;
  --ink-4: #b3b8c9;

  --line: #e4e7f0;
  --line-strong: #d5d9e6;
  --line-soft: #edeff6;

  --accent-soft: color-mix(in srgb, var(--accent) 11%, transparent);
  --accent-softer: color-mix(in srgb, var(--accent) 6%, transparent);
  --accent-line: color-mix(in srgb, var(--accent) 32%, transparent);
  --on-accent-soft: color-mix(in srgb, var(--accent) 78%, #14183f);

  --danger: #d13438;
  --danger-soft: rgba(209, 52, 56, .1);
  --success: #0f7b41;
  --success-soft: rgba(15, 123, 65, .1);
  --warning: #966b00;
  --warning-soft: rgba(150, 107, 0, .12);

  --shadow-1: 0 1px 2px rgba(24, 28, 48, .05), 0 2px 10px rgba(24, 28, 48, .06);
  --shadow-2: 0 2px 6px rgba(24, 28, 48, .07), 0 10px 28px rgba(24, 28, 48, .1);
  --shadow-3: 0 6px 16px rgba(24, 28, 48, .1), 0 24px 56px rgba(24, 28, 48, .16);
  --shadow-pop: 0 2px 8px rgba(24, 28, 48, .08), 0 16px 44px rgba(24, 28, 48, .14);
  --focus-ring: 0 0 0 2px var(--surface-1), 0 0 0 4px color-mix(in srgb, var(--accent) 55%, transparent);
  --glass: rgba(255, 255, 255, .82);
  --glass-border: rgba(255, 255, 255, .6);
  --scrim: rgba(28, 32, 54, .4);
  --skeleton-a: #eef0f7;
  --skeleton-b: #f8f9fd;
  --pin-glow: rgba(240, 184, 46, .35);
}

/* ---------- Dark theme (designed, not inverted) ---------- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1117;
  --bg-deep: #0b0d12;
  --surface-0: #151823;
  --surface-1: #1b1f2d;
  --surface-2: #222739;
  --surface-3: #262b3f;
  --surface-sunken: #12141d;
  --surface-hover: #232941;
  --surface-active: #2a3050;
  --surface-spill: rgba(120, 140, 220, .06);

  --ink-1: #e9ebf5;
  --ink-2: #a6adc7;
  --ink-3: #787f9c;
  --ink-4: #565c75;

  --line: #272d40;
  --line-strong: #333a52;
  --line-soft: #1f2434;

  --accent-soft: color-mix(in srgb, var(--accent) 22%, transparent);
  --accent-softer: color-mix(in srgb, var(--accent) 12%, transparent);
  --accent-line: color-mix(in srgb, var(--accent) 45%, transparent);
  --on-accent-soft: color-mix(in srgb, var(--accent) 40%, #dfe4ff);

  --danger: #ff6b6e;
  --danger-soft: rgba(255, 107, 110, .14);
  --success: #43c988;
  --success-soft: rgba(67, 201, 136, .14);
  --warning: #e3b341;
  --warning-soft: rgba(227, 179, 65, .14);

  --shadow-1: 0 1px 2px rgba(4, 6, 12, .4);
  --shadow-2: 0 2px 8px rgba(4, 6, 12, .45), 0 10px 28px rgba(4, 6, 12, .5);
  --shadow-3: 0 6px 18px rgba(4, 6, 12, .5), 0 28px 60px rgba(4, 6, 12, .6);
  --shadow-pop: 0 4px 14px rgba(4, 6, 12, .5), 0 18px 48px rgba(4, 6, 12, .55);
  --focus-ring: 0 0 0 2px var(--surface-1), 0 0 0 4px color-mix(in srgb, var(--accent) 70%, transparent);
  --glass: rgba(21, 24, 35, .86);
  --glass-border: rgba(255, 255, 255, .07);
  --scrim: rgba(5, 7, 14, .58);
  --skeleton-a: #1d2233;
  --skeleton-b: #242a3f;
  --pin-glow: rgba(240, 184, 46, .3);

  --cat-blue: #6f94ff;  --cat-blue-ink: #9db8ff;
  --cat-violet: #a18bff; --cat-violet-ink: #c0adff;
  --cat-teal: #37c4c4; --cat-teal-ink: #64d8d8;
  --cat-green: #3ecf8b; --cat-green-ink: #74ddb0;
  --cat-orange: #ff9257; --cat-orange-ink: #ffb185;
  --cat-red: #ff7070; --cat-red-ink: #ff9c9c;
  --cat-pink: #ff74b4; --cat-pink-ink: #ff9ecb;
  --cat-gold: #e3b341; --cat-gold-ink: #f0c96b;
}

/* ---------- Density ---------- */
:root[data-density="compact"] {
  --mail-row-min: 42px;
}

/* ============================================================
   Base
   ============================================================ */
* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink-1);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  transition: background var(--t-slow) var(--ease), color var(--t-slow) var(--ease);
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
svg { display: block; }
::selection { background: color-mix(in srgb, var(--accent) 25%, transparent); }

:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--r-xs); }
.icon-btn:focus-visible, .rail-btn:focus-visible { border-radius: var(--r-sm); }

.skip-link {
  position: fixed; left: 12px; top: -48px; z-index: 200;
  background: var(--accent); color: #fff; padding: 8px 14px; border-radius: var(--r-sm);
  font-weight: 600; transition: top var(--t-med) var(--ease);
}
.skip-link:focus { top: 12px; }

.noscript { padding: 48px; text-align: center; font-size: 16px; color: var(--ink-2); }

/* ---------- Scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--line-strong); border-radius: 8px;
  border: 3px solid transparent; background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { border-width: 2px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-corner { background: transparent; }

/* ---------- Icon system ---------- */
.icon { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon.lg { width: 22px; height: 22px; }
.icon.xl { width: 26px; height: 26px; }
.icon.sm { width: 15px; height: 15px; }
.icon.xs { width: 13px; height: 13px; stroke-width: 2; }
.icon.fill { fill: currentColor; stroke: none; }

/* ============================================================
   Shared primitives
   ============================================================ */
.icon-btn {
  width: 34px; height: 34px; border-radius: var(--r-sm);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-2); position: relative;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--ink-1); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.is-on { color: var(--accent); background: var(--accent-softer); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 14px; border-radius: var(--r-sm);
  font-weight: 560; font-size: 13.5px; color: var(--ink-1);
  border: 1px solid var(--line); background: var(--surface-1);
  box-shadow: 0 1px 1px rgba(20, 24, 44, .04);
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; box-shadow: 0 1px 2px rgba(20, 24, 44, .18); }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: transparent; }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-hover); }
.btn.subtle { background: var(--surface-sunken); border-color: transparent; box-shadow: none; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px; border-radius: var(--r-pill);
  font-size: 11.5px; font-weight: 620; letter-spacing: .01em;
  background: var(--surface-sunken); color: var(--ink-2);
}
.chip.accent { background: var(--accent-soft); color: var(--on-accent-soft); }
.chip .icon { width: 12px; height: 12px; stroke-width: 2.2; }

.badge-count {
  min-width: 19px; height: 19px; padding: 0 6px; border-radius: var(--r-pill);
  font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
}
.badge-count.soft { background: var(--ink-4); }

.kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 6px;
  font-family: var(--font-ui); font-size: 11px; font-weight: 650;
  color: var(--ink-3); background: var(--surface-sunken);
  border: 1px solid var(--line); border-bottom-width: 2px;
}

/* ---------- Avatars ---------- */
.avatar {
  width: 36px; height: 36px; border-radius: var(--r-pill);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; letter-spacing: .02em;
  color: #fff; flex: none; position: relative; user-select: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .18), inset 0 -6px 12px rgba(0, 0, 0, .08);
}
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.xs { width: 22px; height: 22px; font-size: 9.5px; }
.avatar.lg { width: 48px; height: 48px; font-size: 17px; }
.avatar.ring { box-shadow: 0 0 0 2px var(--surface-1), 0 0 0 3.5px var(--line); }

/* ---------- Inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12.5px; font-weight: 620; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%; background: var(--surface-sunken);
  border: 1px solid transparent; border-radius: var(--r-sm);
  padding: 8px 12px; font-size: 13.5px; color: var(--ink-1);
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-4); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--line-strong); }
.input:focus, .textarea:focus, .select:focus {
  outline: none; background: var(--surface-1); border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-softer);
}
.textarea { resize: none; min-height: 76px; }
.select {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b91a6' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}

.switch {
  width: 40px; height: 22px; border-radius: var(--r-pill);
  background: var(--line-strong); position: relative; flex: none;
  transition: background var(--t-med) var(--ease); cursor: pointer;
  border: 0; padding: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform var(--t-med) var(--ease), width var(--t-fast) var(--ease), height var(--t-fast) var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.switch:active::after { width: 18px; }

.seg {
  display: inline-flex; padding: 2px; gap: 2px; border-radius: var(--r-sm);
  background: var(--surface-sunken); border: 1px solid var(--line);
}
.seg button {
  height: 26px; padding: 0 12px; border-radius: 6px; font-size: 12.5px; font-weight: 600;
  color: var(--ink-2); transition: all var(--t-fast) var(--ease); white-space: nowrap;
}
.seg button:hover { color: var(--ink-1); }
.seg button.is-on { background: var(--surface-1); color: var(--ink-1); box-shadow: var(--shadow-1); }

/* ---------- Empty & skeleton states ---------- */
.empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 40px 24px; text-align: center; animation: fadeIn var(--t-slow) var(--ease);
}
.empty-art { width: 132px; height: 112px; margin-bottom: 12px; color: var(--ink-3); }
.empty-art svg { width: 100%; height: 100%; }
.empty-title { font-size: 15.5px; font-weight: 680; color: var(--ink-1); }
.empty-sub { font-size: 13px; color: var(--ink-3); max-width: 320px; line-height: 1.55; }
.empty .btn { margin-top: 14px; }

.skel {
  border-radius: var(--r-xs);
  background: linear-gradient(100deg, var(--skeleton-a) 40%, var(--skeleton-b) 50%, var(--skeleton-a) 60%);
  background-size: 220% 100%;
  animation: shimmer 1.3s linear infinite;
}

@keyframes shimmer { to { background-position: -120% 0; } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes riseIn {
  from { opacity: 0; transform: translateY(7px); }
}
@keyframes popIn {
  from { opacity: 0; transform: scale(.96) translateY(4px); }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
}
@keyframes checkPop {
  0% { transform: scale(1); }
  45% { transform: scale(1.35); }
  100% { transform: scale(1); }
}
@keyframes ping {
  from { transform: scale(1); opacity: .8; }
  to { transform: scale(2.1); opacity: 0; }
}
@keyframes confettiFall {
  from { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001s !important;
    scroll-behavior: auto !important;
  }
}
:root.no-motion *, :root.no-motion *::before, :root.no-motion *::after {
  animation-duration: .001s !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001s !important;
}

/* ---------- Screen-reader helper ---------- */
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
