/* =============================================================================
   Suite Design System  —  v1.0
   A premium, cohesive design foundation shared across all apps in this suite.
   Crafted to feel like Linear / Stripe / Raycast: calm, precise, tactile.

   How to theme per app:
     :root { --accent: <hsl>; --accent-ink: <hsl>; ... } in the app's own css.
   Everything below reads from CSS custom properties, so a single accent swap
   re-themes buttons, focus rings, links, charts, etc.
   ========================================================================== */

/* ----------------------------------------------------------------------------
   0. Reset (modern, minimal)
   ------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { line-height: 1.6; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
img, picture, svg, video, canvas { display: block; max-width: 100%; }
/* Inline icons are bare <svg viewBox="0 0 24 24"> with no width/height. With the
   reset above (display:block; max-width:100%) such an icon balloons to fill its
   block container. Give attribute-less SVGs a text-sized default so they sit
   inline with copy. Icons sized by attribute (icon(name,{size}) → width="24") or
   by a later class rule (.btn svg, .empty-icon svg, charts with width="100%")
   are excluded / override this via source order. */
svg:not([width]) { display: inline-block; width: 1.15em; height: 1.15em; vertical-align: -0.18em; flex: none; }
input, button, textarea, select { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }
:where(h1, h2, h3, h4, h5, h6) { line-height: 1.2; font-weight: 650; letter-spacing: -0.018em; }
p { text-wrap: pretty; }
:where(h1, h2, h3) { text-wrap: balance; }

/* ----------------------------------------------------------------------------
   1. Design tokens
   ------------------------------------------------------------------------- */
:root {
  /* Type scale (fluid-ish, rem based) */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", "Hiragino Kaku Gothic ProN", "Hiragino Sans",
               "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace,
               "Cascadia Code", Menlo, Consolas, monospace;
  --font-serif: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;

  --text-2xs: 0.6875rem;  /* 11 */
  --text-xs:  0.75rem;    /* 12 */
  --text-sm:  0.8125rem;  /* 13 */
  --text-md:  0.875rem;   /* 14 */
  --text-base:0.9375rem;  /* 15 */
  --text-lg:  1.0625rem;  /* 17 */
  --text-xl:  1.25rem;    /* 20 */
  --text-2xl: 1.5rem;     /* 24 */
  --text-3xl: 1.875rem;   /* 30 */
  --text-4xl: 2.375rem;   /* 38 */
  --text-5xl: 3rem;       /* 48 */
  --text-6xl: 3.75rem;    /* 60 */

  /* Spacing scale (4px base) */
  --s-1: 0.25rem; --s-2: 0.5rem; --s-3: 0.75rem; --s-4: 1rem;
  --s-5: 1.25rem; --s-6: 1.5rem; --s-7: 1.75rem; --s-8: 2rem;
  --s-10: 2.5rem; --s-12: 3rem; --s-16: 4rem; --s-20: 5rem; --s-24: 6rem;

  /* Radii */
  --r-xs: 5px; --r-sm: 7px; --r-md: 10px; --r-lg: 14px; --r-xl: 20px;
  --r-2xl: 28px; --r-full: 999px;

  /* Z-index */
  --z-base: 1; --z-sticky: 50; --z-overlay: 100; --z-modal: 200; --z-toast: 300;

  /* Motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --dur-1: 0.12s; --dur-2: 0.2s; --dur-3: 0.32s; --dur-4: 0.5s;

  /* Default accent (apps override). A confident indigo. */
  --accent: 243 75% 59%;
  --accent-strong: 243 76% 52%;
  --accent-soft: 243 90% 97%;
  --accent-ink: 0 0% 100%;            /* text on accent */
  --accent-ring: 243 75% 59% / 0.35;

  /* Semantic colors (hsl triplets, used via hsl(var(--x))) */
  --green: 152 60% 40%;  --green-soft: 152 70% 96%;
  --amber: 38 92% 50%;   --amber-soft: 40 96% 95%;
  --red: 0 72% 51%;      --red-soft: 0 86% 97%;
  --blue: 211 90% 52%;   --blue-soft: 211 96% 96%;
  --violet: 262 72% 58%; --violet-soft: 262 90% 97%;

  color-scheme: light;
}

/* ---- Light theme surface palette (default) ---- */
:root, [data-theme="light"] {
  --bg: 240 20% 99%;
  --bg-subtle: 240 20% 97%;
  --bg-muted: 240 16% 95%;
  --surface: 0 0% 100%;
  --surface-2: 240 24% 99%;
  --elevated: 0 0% 100%;

  --border: 240 14% 91%;
  --border-strong: 240 12% 84%;
  --ring: var(--accent-ring);

  --ink: 240 18% 12%;        /* primary text */
  --ink-2: 240 8% 32%;       /* secondary */
  --ink-3: 240 6% 48%;       /* tertiary / muted */
  --ink-4: 240 6% 64%;       /* placeholder */

  --shadow-color: 240 30% 20%;
  --shadow-xs: 0 1px 2px hsl(var(--shadow-color) / 0.06);
  --shadow-sm: 0 1px 2px hsl(var(--shadow-color) / 0.06), 0 2px 6px hsl(var(--shadow-color) / 0.05);
  --shadow-md: 0 2px 4px hsl(var(--shadow-color) / 0.05), 0 6px 16px hsl(var(--shadow-color) / 0.08);
  --shadow-lg: 0 4px 8px hsl(var(--shadow-color) / 0.05), 0 12px 32px hsl(var(--shadow-color) / 0.12);
  --shadow-xl: 0 8px 16px hsl(var(--shadow-color) / 0.06), 0 24px 56px hsl(var(--shadow-color) / 0.16);
}

/* ---- Dark theme ---- */
[data-theme="dark"] {
  color-scheme: dark;
  --bg: 240 14% 8%;
  --bg-subtle: 240 13% 10%;
  --bg-muted: 240 12% 14%;
  --surface: 240 13% 11%;
  --surface-2: 240 12% 13%;
  --elevated: 240 12% 15%;

  --border: 240 10% 20%;
  --border-strong: 240 8% 28%;

  --ink: 240 18% 96%;
  --ink-2: 240 10% 76%;
  --ink-3: 240 8% 60%;
  --ink-4: 240 8% 46%;

  --accent-soft: 243 60% 18%;

  --shadow-color: 240 60% 2%;
  --shadow-xs: 0 1px 2px hsl(var(--shadow-color) / 0.4);
  --shadow-sm: 0 1px 2px hsl(var(--shadow-color) / 0.4), 0 2px 6px hsl(var(--shadow-color) / 0.4);
  --shadow-md: 0 2px 4px hsl(var(--shadow-color) / 0.4), 0 6px 16px hsl(var(--shadow-color) / 0.5);
  --shadow-lg: 0 4px 8px hsl(var(--shadow-color) / 0.4), 0 12px 32px hsl(var(--shadow-color) / 0.6);
  --shadow-xl: 0 8px 16px hsl(var(--shadow-color) / 0.5), 0 24px 56px hsl(var(--shadow-color) / 0.7);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: 240 14% 8%; --bg-subtle: 240 13% 10%; --bg-muted: 240 12% 14%;
    --surface: 240 13% 11%; --surface-2: 240 12% 13%; --elevated: 240 12% 15%;
    --border: 240 10% 20%; --border-strong: 240 8% 28%;
    --ink: 240 18% 96%; --ink-2: 240 10% 76%; --ink-3: 240 8% 60%; --ink-4: 240 8% 46%;
    --accent-soft: 243 60% 18%;
    --shadow-color: 240 60% 2%;
    --shadow-xs: 0 1px 2px hsl(var(--shadow-color) / 0.4);
    --shadow-sm: 0 1px 2px hsl(var(--shadow-color) / 0.4), 0 2px 6px hsl(var(--shadow-color) / 0.4);
    --shadow-md: 0 2px 4px hsl(var(--shadow-color) / 0.4), 0 6px 16px hsl(var(--shadow-color) / 0.5);
    --shadow-lg: 0 4px 8px hsl(var(--shadow-color) / 0.4), 0 12px 32px hsl(var(--shadow-color) / 0.6);
    --shadow-xl: 0 8px 16px hsl(var(--shadow-color) / 0.5), 0 24px 56px hsl(var(--shadow-color) / 0.7);
  }
}

/* ----------------------------------------------------------------------------
   2. Base
   ------------------------------------------------------------------------- */
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: hsl(var(--ink));
  background: hsl(var(--bg));
  font-feature-settings: "cv11", "ss01";
  font-variant-numeric: tabular-nums;
}
::selection { background: hsl(var(--accent) / 0.22); }

:where(a):not([class]) { color: hsl(var(--accent-strong)); }
:where(a):not([class]):hover { text-decoration: underline; text-underline-offset: 2px; }

/* Accessible focus */
:focus-visible {
  outline: 2px solid hsl(var(--accent));
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
:focus:not(:focus-visible) { outline: none; }

code, kbd, samp, pre { font-family: var(--font-mono); font-size: 0.9em; }
kbd {
  font-size: var(--text-2xs); padding: 2px 6px; border-radius: var(--r-xs);
  background: hsl(var(--bg-muted)); border: 1px solid hsl(var(--border));
  box-shadow: 0 1px 0 hsl(var(--border-strong)); font-variant-numeric: normal;
}
hr { border: none; border-top: 1px solid hsl(var(--border)); margin: var(--s-6) 0; }

/* ----------------------------------------------------------------------------
   3. Layout primitives
   ------------------------------------------------------------------------- */
.container { width: 100%; max-width: 1200px; margin-inline: auto; padding-inline: var(--s-6); }
.container-narrow { max-width: 760px; }
.container-wide { max-width: 1400px; }

.stack { display: flex; flex-direction: column; gap: var(--s-4); }
.stack-sm { gap: var(--s-2); } .stack-lg { gap: var(--s-6); } .stack-xl { gap: var(--s-8); }
.row { display: flex; align-items: center; gap: var(--s-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.center { display: grid; place-items: center; }
.grid { display: grid; gap: var(--s-4); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
@media (max-width: 768px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .container { padding-inline: var(--s-4); }
}

.muted { color: hsl(var(--ink-3)); }
.dim { color: hsl(var(--ink-2)); }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tabular { font-variant-numeric: tabular-nums; }
.text-center { text-align: center; }
.divider { height: 1px; background: hsl(var(--border)); border: 0; }

/* ----------------------------------------------------------------------------
   4. Typography helpers
   ------------------------------------------------------------------------- */
.eyebrow {
  font-size: var(--text-xs); font-weight: 650; letter-spacing: 0.08em;
  text-transform: uppercase; color: hsl(var(--accent-strong));
}
.display { font-size: var(--text-5xl); font-weight: 720; letter-spacing: -0.03em; line-height: 1.05; }
.title { font-size: var(--text-2xl); font-weight: 680; letter-spacing: -0.02em; }
.subtitle { font-size: var(--text-lg); color: hsl(var(--ink-2)); font-weight: 450; }
.lead { font-size: var(--text-lg); color: hsl(var(--ink-2)); line-height: 1.6; }
.label { font-size: var(--text-md); font-weight: 600; color: hsl(var(--ink)); }
.hint { font-size: var(--text-sm); color: hsl(var(--ink-3)); }
@media (max-width: 640px) { .display { font-size: var(--text-4xl); } }

/* ----------------------------------------------------------------------------
   5. Buttons
   ------------------------------------------------------------------------- */
.btn {
  --_bg: hsl(var(--surface));
  --_fg: hsl(var(--ink));
  --_bd: hsl(var(--border-strong));
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  font-size: var(--text-md); font-weight: 560; line-height: 1;
  padding: 0 var(--s-4); height: 38px; border-radius: var(--r-md);
  background: var(--_bg); color: var(--_fg);
  border: 1px solid var(--_bd);
  box-shadow: var(--shadow-xs);
  white-space: nowrap; user-select: none;
  transition: transform var(--dur-1) var(--ease), box-shadow var(--dur-2) var(--ease),
              background var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease), filter var(--dur-2) var(--ease);
}
.btn:hover { background: hsl(var(--bg-subtle)); }
.btn:active { transform: translateY(0.5px) scale(0.99); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
.btn svg { width: 1.05em; height: 1.05em; flex: none; }

.btn-primary {
  --_bg: hsl(var(--accent)); --_fg: hsl(var(--accent-ink)); --_bd: hsl(var(--accent-strong));
  box-shadow: var(--shadow-sm), inset 0 1px 0 hsl(0 0% 100% / 0.18);
}
.btn-primary:hover { background: hsl(var(--accent-strong)); filter: brightness(1.04); }
.btn-ghost { --_bg: transparent; --_bd: transparent; box-shadow: none; }
.btn-ghost:hover { background: hsl(var(--bg-muted)); }
.btn-soft { --_bg: hsl(var(--accent-soft)); --_fg: hsl(var(--accent-strong)); --_bd: transparent; box-shadow: none; }
.btn-soft:hover { filter: brightness(0.97); background: hsl(var(--accent-soft)); }
.btn-danger { --_bg: hsl(var(--red)); --_fg: #fff; --_bd: hsl(var(--red)); }
.btn-danger:hover { filter: brightness(1.05); background: hsl(var(--red)); }
.btn-danger-soft { --_bg: hsl(var(--red-soft)); --_fg: hsl(var(--red)); --_bd: transparent; box-shadow:none; }

.btn-lg { height: 46px; padding: 0 var(--s-6); font-size: var(--text-base); border-radius: var(--r-lg); }
.btn-sm { height: 32px; padding: 0 var(--s-3); font-size: var(--text-sm); border-radius: var(--r-sm); }
.btn-xs { height: 27px; padding: 0 var(--s-2); font-size: var(--text-xs); border-radius: var(--r-sm); }
.btn-icon { width: 38px; padding: 0; }
.btn-icon.btn-sm { width: 32px; } .btn-icon.btn-xs { width: 27px; }
.btn-block { width: 100%; }

/* ----------------------------------------------------------------------------
   6. Cards & surfaces
   ------------------------------------------------------------------------- */
.card {
  background: hsl(var(--surface));
  border: 1px solid hsl(var(--border));
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
}
.card-pad { padding: var(--s-6); }
.card-pad-sm { padding: var(--s-4); }
.card-hover { transition: box-shadow var(--dur-2) var(--ease), transform var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease); }
.card-hover:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: hsl(var(--border-strong)); }
.card-header { padding: var(--s-5) var(--s-6); border-bottom: 1px solid hsl(var(--border)); }
.card-body { padding: var(--s-6); }
.card-footer { padding: var(--s-4) var(--s-6); border-top: 1px solid hsl(var(--border)); background: hsl(var(--surface-2)); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.panel { background: hsl(var(--bg-subtle)); border: 1px solid hsl(var(--border)); border-radius: var(--r-md); padding: var(--s-4); }
.glass { background: hsl(var(--surface) / 0.72); backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px); }

/* ----------------------------------------------------------------------------
   7. Forms
   ------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field > .label { display: flex; align-items: center; gap: var(--s-2); }
.req { color: hsl(var(--red)); font-size: 0.85em; }

.input, .textarea, .select {
  width: 100%; font-size: var(--text-base);
  padding: 0 var(--s-3); height: 40px;
  color: hsl(var(--ink));
  background: hsl(var(--surface));
  border: 1px solid hsl(var(--border-strong));
  border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease), background var(--dur-2) var(--ease);
}
.textarea { height: auto; min-height: 96px; padding: var(--s-3); resize: vertical; line-height: 1.6; }
.input::placeholder, .textarea::placeholder { color: hsl(var(--ink-4)); }
.input:hover, .textarea:hover, .select:hover { border-color: hsl(var(--ink-4)); }
.input:focus, .textarea:focus, .select:focus {
  outline: none; border-color: hsl(var(--accent));
  box-shadow: 0 0 0 3.5px hsl(var(--accent) / 0.16);
}
.input:disabled, .textarea:disabled { background: hsl(var(--bg-muted)); color: hsl(var(--ink-3)); cursor: not-allowed; }
.input-lg { height: 48px; font-size: var(--text-lg); }
.input-error { border-color: hsl(var(--red)) !important; }
.input-error:focus { box-shadow: 0 0 0 3.5px hsl(var(--red) / 0.16); }
.field-error { color: hsl(var(--red)); font-size: var(--text-sm); }

.select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right var(--s-3) center; padding-right: var(--s-8);
}

/* Checkbox / radio */
.check { display: inline-flex; align-items: flex-start; gap: var(--s-3); cursor: pointer; font-size: var(--text-md); }
.check input { appearance: none; -webkit-appearance: none; flex: none; width: 19px; height: 19px; margin-top: 1px;
  border: 1.5px solid hsl(var(--border-strong)); border-radius: 6px; background: hsl(var(--surface));
  transition: all var(--dur-2) var(--ease); display: grid; place-content: center; }
.check input[type="radio"] { border-radius: 50%; }
.check input:hover { border-color: hsl(var(--accent)); }
.check input:checked { background: hsl(var(--accent)); border-color: hsl(var(--accent)); }
.check input:checked::after { content: ""; width: 11px; height: 11px;
  background: hsl(var(--accent-ink)); clip-path: polygon(14% 52%, 9% 60%, 40% 88%, 92% 24%, 84% 17%, 38% 70%);
}
.check input[type="radio"]:checked::after { clip-path: none; border-radius: 50%; width: 8px; height: 8px; }
.check input:focus-visible { outline: 2px solid hsl(var(--accent)); outline-offset: 2px; }

/* Switch */
.switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch .track { width: 40px; height: 23px; border-radius: var(--r-full); background: hsl(var(--border-strong)); transition: background var(--dur-2) var(--ease); }
.switch .thumb { position: absolute; left: 2px; top: 2px; width: 19px; height: 19px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--dur-2) var(--ease); }
.switch input:checked + .track { background: hsl(var(--accent)); }
.switch input:checked + .track + .thumb { transform: translateX(17px); }
.switch input:focus-visible + .track { outline: 2px solid hsl(var(--accent)); outline-offset: 2px; }

/* Segmented control */
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: hsl(var(--bg-muted)); border-radius: var(--r-md); border: 1px solid hsl(var(--border)); }
.segmented button { padding: 6px var(--s-3); font-size: var(--text-sm); font-weight: 550; border-radius: var(--r-sm); color: hsl(var(--ink-3)); transition: all var(--dur-2) var(--ease); }
.segmented button[aria-pressed="true"], .segmented button.active { background: hsl(var(--surface)); color: hsl(var(--ink)); box-shadow: var(--shadow-xs); }
.segmented button:hover:not([aria-pressed="true"]):not(.active) { color: hsl(var(--ink)); }

/* ----------------------------------------------------------------------------
   8. Badges, chips, pills
   ------------------------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-xs); font-weight: 600; line-height: 1;
  padding: 4px 9px; border-radius: var(--r-full);
  background: hsl(var(--bg-muted)); color: hsl(var(--ink-2));
  border: 1px solid hsl(var(--border));
  white-space: nowrap; /* keep short status labels (下書き/共有済) on one line in narrow flex slots */
}
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-accent { background: hsl(var(--accent-soft)); color: hsl(var(--accent-strong)); border-color: transparent; }
.badge-green { background: hsl(var(--green-soft)); color: hsl(var(--green)); border-color: transparent; }
.badge-amber { background: hsl(var(--amber-soft)); color: hsl(38 80% 38%); border-color: transparent; }
.badge-red { background: hsl(var(--red-soft)); color: hsl(var(--red)); border-color: transparent; }
.badge-blue { background: hsl(var(--blue-soft)); color: hsl(var(--blue)); border-color: transparent; }
.badge-violet { background: hsl(var(--violet-soft)); color: hsl(var(--violet)); border-color: transparent; }
[data-theme="dark"] .badge-amber { color: hsl(40 90% 60%); }

.chip {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-size: var(--text-sm); font-weight: 500;
  padding: 5px 11px; border-radius: var(--r-full);
  background: hsl(var(--surface)); color: hsl(var(--ink-2));
  border: 1px solid hsl(var(--border-strong)); cursor: pointer;
  transition: all var(--dur-2) var(--ease);
}
.chip:hover { border-color: hsl(var(--accent)); color: hsl(var(--ink)); }
.chip[aria-pressed="true"], .chip.active { background: hsl(var(--accent-soft)); color: hsl(var(--accent-strong)); border-color: hsl(var(--accent) / 0.4); }

/* ----------------------------------------------------------------------------
   9. Stars / rating
   ------------------------------------------------------------------------- */
.stars { display: inline-flex; gap: 2px; color: hsl(var(--amber)); }
.stars svg { width: 1.1em; height: 1.1em; }
.stars .empty { color: hsl(var(--border-strong)); }
.rating-input { display: inline-flex; gap: 4px; direction: rtl; }
.rating-input button { color: hsl(var(--border-strong)); transition: transform var(--dur-1) var(--ease), color var(--dur-1) var(--ease); }
.rating-input button svg { width: 28px; height: 28px; }
.rating-input button:hover, .rating-input button:hover ~ button,
.rating-input button.on, .rating-input button.on ~ button { color: hsl(var(--amber)); }
.rating-input button:hover { transform: scale(1.12); }

/* ----------------------------------------------------------------------------
   10. Tabs
   ------------------------------------------------------------------------- */
.tabs { display: flex; gap: var(--s-1); border-bottom: 1px solid hsl(var(--border)); }
.tabs button { position: relative; padding: var(--s-3) var(--s-3); font-size: var(--text-md); font-weight: 550; color: hsl(var(--ink-3)); transition: color var(--dur-2) var(--ease); }
.tabs button::after { content: ""; position: absolute; left: var(--s-2); right: var(--s-2); bottom: -1px; height: 2px; background: hsl(var(--accent)); border-radius: 2px 2px 0 0; transform: scaleX(0); transition: transform var(--dur-2) var(--ease); }
.tabs button:hover { color: hsl(var(--ink)); }
.tabs button[aria-selected="true"], .tabs button.active { color: hsl(var(--ink)); }
.tabs button[aria-selected="true"]::after, .tabs button.active::after { transform: scaleX(1); }

/* ----------------------------------------------------------------------------
   11. Tables
   ------------------------------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--text-md); }
.table th { text-align: left; font-weight: 600; color: hsl(var(--ink-3)); font-size: var(--text-sm); padding: var(--s-3) var(--s-4); border-bottom: 1px solid hsl(var(--border)); white-space: nowrap; }
.table td { padding: var(--s-3) var(--s-4); border-bottom: 1px solid hsl(var(--border)); }
.table tbody tr { transition: background var(--dur-2) var(--ease); }
.table tbody tr:hover { background: hsl(var(--bg-subtle)); }
.table tbody tr:last-child td { border-bottom: none; }

/* ----------------------------------------------------------------------------
   12. Stats
   ------------------------------------------------------------------------- */
.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .stat-value { font-size: var(--text-3xl); font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .stat-label { font-size: var(--text-sm); color: hsl(var(--ink-3)); font-weight: 500; }
.stat .stat-delta { font-size: var(--text-xs); font-weight: 600; }
.stat-delta.up { color: hsl(var(--green)); } .stat-delta.down { color: hsl(var(--red)); }

/* ----------------------------------------------------------------------------
   13. Progress
   ------------------------------------------------------------------------- */
.progress { height: 8px; background: hsl(var(--bg-muted)); border-radius: var(--r-full); overflow: hidden; }
.progress > i { display: block; height: 100%; background: hsl(var(--accent)); border-radius: inherit; transition: width var(--dur-4) var(--ease); }
.progress-ring { transform: rotate(-90deg); }
.progress-ring circle { fill: none; stroke-width: 8; }
.progress-ring .bg { stroke: hsl(var(--bg-muted)); }
.progress-ring .fg { stroke: hsl(var(--accent)); stroke-linecap: round; transition: stroke-dashoffset var(--dur-4) var(--ease); }

/* ----------------------------------------------------------------------------
   14. Avatars
   ------------------------------------------------------------------------- */
.avatar { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: hsl(var(--accent-soft)); color: hsl(var(--accent-strong)); font-weight: 650; font-size: var(--text-md); flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar-lg { width: 52px; height: 52px; font-size: var(--text-lg); }

/* ----------------------------------------------------------------------------
   15. Modal / dialog
   ------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: hsl(240 30% 8% / 0.5); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: var(--s-4);
  opacity: 0; transition: opacity var(--dur-2) var(--ease);
}
.modal-backdrop.open { opacity: 1; }
.modal {
  width: 100%; max-width: 520px; max-height: 90vh; overflow: auto;
  background: hsl(var(--elevated)); border: 1px solid hsl(var(--border));
  border-radius: var(--r-xl); box-shadow: var(--shadow-xl);
  transform: translateY(8px) scale(0.98); opacity: 0;
  transition: transform var(--dur-3) var(--ease), opacity var(--dur-3) var(--ease);
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); opacity: 1; }
.modal-header { padding: var(--s-5) var(--s-6); display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); border-bottom: 1px solid hsl(var(--border)); }
.modal-body { padding: var(--s-6); }
.modal-footer { padding: var(--s-4) var(--s-6); border-top: 1px solid hsl(var(--border)); display: flex; justify-content: flex-end; gap: var(--s-3); }

/* ----------------------------------------------------------------------------
   16. Toasts
   ------------------------------------------------------------------------- */
.toast-host { position: fixed; bottom: var(--s-6); left: 50%; transform: translateX(-50%); z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--s-2); align-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4); border-radius: var(--r-md);
  background: hsl(var(--ink)); color: hsl(var(--bg));
  box-shadow: var(--shadow-lg); font-size: var(--text-md); font-weight: 500;
  pointer-events: auto; max-width: min(92vw, 440px);
  animation: toast-in var(--dur-3) var(--ease);
}
.toast.out { animation: toast-out var(--dur-2) var(--ease) forwards; }
.toast .ico { display: grid; place-items: center; width: 18px; height: 18px; flex: none; }
.toast.success .ico { color: hsl(152 70% 64%); } .toast.error .ico { color: hsl(0 80% 70%); }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(0.96); } }

/* ----------------------------------------------------------------------------
   17. Empty / skeleton / spinner
   ------------------------------------------------------------------------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--s-3); padding: var(--s-12) var(--s-6); color: hsl(var(--ink-3)); }
.empty .empty-icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: var(--r-lg); background: hsl(var(--bg-muted)); color: hsl(var(--ink-3)); margin-bottom: var(--s-2); }
.empty h3 { color: hsl(var(--ink)); font-size: var(--text-lg); }

.skeleton { background: linear-gradient(90deg, hsl(var(--bg-muted)) 25%, hsl(var(--bg-subtle)) 50%, hsl(var(--bg-muted)) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--r-sm); }
@keyframes shimmer { to { background-position: -200% 0; } }

.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid hsl(var(--accent) / 0.25); border-top-color: hsl(var(--accent)); animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------------------
   18. Tooltip (CSS-only, data-tip)
   ------------------------------------------------------------------------- */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%) translateY(4px);
  background: hsl(var(--ink)); color: hsl(var(--bg)); font-size: var(--text-xs); font-weight: 500; white-space: nowrap;
  padding: 5px 9px; border-radius: var(--r-sm); box-shadow: var(--shadow-md);
  opacity: 0; pointer-events: none; transition: opacity var(--dur-2) var(--ease), transform var(--dur-2) var(--ease); z-index: var(--z-toast);
}
[data-tip]:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ----------------------------------------------------------------------------
   19. App shell (sidebar + topbar)
   ------------------------------------------------------------------------- */
.app-shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--s-1); padding: var(--s-4); background: hsl(var(--surface)); border-right: 1px solid hsl(var(--border)); overflow-y: auto; }
.sidebar .brand { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) var(--s-2) var(--s-5); }
.nav-item { display: flex; align-items: center; gap: var(--s-3); padding: 9px var(--s-3); border-radius: var(--r-md); color: hsl(var(--ink-2)); font-weight: 520; font-size: var(--text-md); transition: all var(--dur-2) var(--ease); }
.nav-item svg { width: 18px; height: 18px; flex: none; color: hsl(var(--ink-3)); transition: color var(--dur-2) var(--ease); }
.nav-item:hover { background: hsl(var(--bg-muted)); color: hsl(var(--ink)); }
.nav-item.active { background: hsl(var(--accent-soft)); color: hsl(var(--accent-strong)); }
.nav-item.active svg { color: hsl(var(--accent-strong)); }
.nav-section { font-size: var(--text-2xs); font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: hsl(var(--ink-4)); padding: var(--s-4) var(--s-3) var(--s-2); }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: var(--z-sticky); display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); padding: var(--s-4) var(--s-6); border-bottom: 1px solid hsl(var(--border)); background: hsl(var(--surface) / 0.8); backdrop-filter: saturate(180%) blur(12px); -webkit-backdrop-filter: saturate(180%) blur(12px); }
.content { padding: var(--s-6); flex: 1; }
/* Scrim is desktop-hidden by default so it never becomes a stray grid item
   inside .app-shell (which would steal a column). Only shown as a mobile overlay. */
.sidebar-scrim { display: none; }
@media (max-width: 880px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: var(--z-overlay); width: 248px; transform: translateX(-100%); transition: transform var(--dur-3) var(--ease); box-shadow: var(--shadow-xl); }
  .sidebar.open { transform: none; }
  .sidebar-scrim { display: block; position: fixed; inset: 0; background: hsl(240 30% 8% / 0.4); z-index: 99; opacity: 0; pointer-events: none; transition: opacity var(--dur-2) var(--ease); }
  .sidebar-scrim.open { opacity: 1; pointer-events: auto; }
}

/* ----------------------------------------------------------------------------
   20. Brand mark helper
   ------------------------------------------------------------------------- */
.logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: hsl(var(--accent)); color: hsl(var(--accent-ink)); font-weight: 750; box-shadow: var(--shadow-sm), inset 0 1px 0 hsl(0 0% 100% / 0.2); flex: none; }
.brand-name { font-weight: 680; font-size: var(--text-lg); letter-spacing: -0.02em; }

/* ----------------------------------------------------------------------------
   21. Utilities
   ------------------------------------------------------------------------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.hidden { display: none !important; }
.pointer { cursor: pointer; }
.gap-1{gap:var(--s-1)} .gap-2{gap:var(--s-2)} .gap-3{gap:var(--s-3)} .gap-4{gap:var(--s-4)} .gap-6{gap:var(--s-6)}
.mt-2{margin-top:var(--s-2)} .mt-4{margin-top:var(--s-4)} .mt-6{margin-top:var(--s-6)} .mt-8{margin-top:var(--s-8)}
.mb-2{margin-bottom:var(--s-2)} .mb-4{margin-bottom:var(--s-4)} .mb-6{margin-bottom:var(--s-6)}
.w-full{width:100%} .full-h{min-height:100vh}
.rounded{border-radius:var(--r-md)} .rounded-lg{border-radius:var(--r-lg)}
.shadow-sm{box-shadow:var(--shadow-sm)} .shadow-md{box-shadow:var(--shadow-md)} .shadow-lg{box-shadow:var(--shadow-lg)}
.fade-in { animation: fade-in var(--dur-3) var(--ease); }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.pop-in { animation: pop-in var(--dur-3) var(--ease); }
@keyframes pop-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }

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

/* Print (useful for PDF-style exports) */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
}
