/* Naturgazz Payroll: design tokens, base styles, layout and shared components.
 *
 * Page stylesheets (css/pages/*.css) build on these tokens and classes. Prefix page-only
 * classes with the page's short name (att-, pay-, emp-, dash-, hist-, tg-, set-) so the
 * parallel page styles never collide.
 */

/* ==========================================================================
   1. Tokens
   ========================================================================== */

:root {
  color-scheme: light;

  /* type */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Inter, Roboto,
    "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Cascadia Mono", "Liberation Mono", monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-base: 14px;
  --fs-md: 15px;
  --fs-lg: 16px;
  --fs-xl: 18px;
  --fs-2xl: 22px;
  --fs-3xl: 28px;
  --lh-tight: 1.25;
  --lh-snug: 1.35;
  --lh: 1.5;
  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* 4px spacing scale */
  --space-0-5: 2px;
  --space-1: 4px;
  --space-1-5: 6px;
  --space-2: 8px;
  --space-2-5: 10px;
  --space-3: 12px;
  --space-3-5: 14px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* shape */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 999px;

  /* layout */
  --sidebar-w: 240px;
  --content-max: 1240px;
  --topbar-h: 56px;
  --page-pad-x: 40px;
  --page-pad-y: 32px;
  --control-h: 36px;
  --control-h-sm: 30px;
  --control-h-lg: 40px;

  /* layers */
  --z-sticky: 10;
  --z-topbar: 30;
  --z-nav-drawer: 40;
  --z-menu: 70;
  --z-overlay: 50;
  --z-toast: 80;

  /* motion */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --ease-in: cubic-bezier(.4, 0, 1, 1);
  --dur-fast: 120ms;
  --dur: 180ms;
  --dur-slow: 260ms;

  /* brand scale (fixed in both themes) */
  --green-50: #ecf8f2;
  --green-100: #d3efe0;
  --green-200: #a8dec3;
  --green-300: #71c59f;
  --green-400: #3ea97b;
  --green-500: #1f8f60;
  --green-600: #157a4f;
  --green-700: #106341;
  --green-800: #0d4f35;
  --green-900: #0a3d29;
  --lime-400: #a9da73;
  --lime-500: #92d050;
  --lime-600: #77b33a;

  /* ---- semantic colours: light ---- */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;      /* insets, table headers, card footers */
  --surface-3: #f1f4f8;      /* hover fills */
  --surface-raised: #ffffff; /* modals, menus, toasts */
  --sidebar-bg: #ffffff;
  --border: #e3e8ef;
  --border-subtle: #edf0f4;
  --border-strong: #cfd6e0;
  --border-input: #8a94a3;   /* 3:1 against white: identifies form controls */
  --text: #0f1722;
  --text-muted: #556070;
  --text-subtle: #636d7d;
  --text-placeholder: #6b7586;
  --text-inverse: #ffffff;

  --primary: #157a4f;
  --primary-hover: #106341;
  --primary-active: #0d5637;
  --on-primary: #ffffff;
  --primary-text: #13724a;   /* links, active nav text */
  --primary-soft: #e8f5ee;
  --primary-soft-hover: #d9efe3;
  --primary-soft-text: #0f6440;
  --primary-border: #a8dec3;
  --primary-ring: rgba(21, 122, 79, .22);

  --accent: #92d050;         /* Excel "Total Gaji" lime: totals only, sparingly */
  --on-accent: #1e3a07;
  --accent-soft: #eef8e1;
  --accent-soft-text: #3b6312;
  --accent-border: #c7e7a3;

  --success: #17834f;
  --success-soft: #e6f4ec;
  --success-text: #0d6139;
  --success-border: #b5dfc7;
  --warning: #b45309;
  --warning-soft: #fdf3e1;
  --warning-text: #8a4106;
  --warning-border: #f2d29a;
  --danger: #c42b2b;
  --danger-hover: #a92222;
  --danger-soft: #fdecec;
  --danger-text: #a51f1f;
  --danger-border: #f3c0c0;
  --danger-ring: rgba(196, 43, 43, .2);
  --info: #2563c9;
  --info-soft: #e9f0fc;
  --info-text: #1d4fa3;
  --info-border: #bcd0f3;
  --neutral-soft: #eef1f5;
  --neutral-text: #475263;
  --neutral-border: #d8dee6;

  --focus: #157a4f;
  --overlay: rgba(15, 23, 34, .45);
  --skeleton: #e9edf2;
  --skeleton-shine: #f5f7fa;
  --row-hover: #f6f8fb;
  --row-selected: #eef7f2;

  --shadow-xs: 0 1px 2px rgba(15, 23, 34, .05);
  --shadow-sm: 0 1px 2px rgba(15, 23, 34, .05), 0 1px 3px rgba(15, 23, 34, .06);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 34, .08), 0 2px 4px -2px rgba(15, 23, 34, .05);
  --shadow-lg: 0 16px 40px -8px rgba(15, 23, 34, .18), 0 4px 12px -4px rgba(15, 23, 34, .08);

  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23556070' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9.5 6 6 6-6'/%3E%3C/svg%3E");

  /* "Sign in with Microsoft / Google": the providers' own button colours (their branding guidelines) */
  --ms-btn-bg: #ffffff;
  --ms-btn-fg: #5e5e5e;
  --ms-btn-border: #8c8c8c;
  --ms-btn-hover: #f3f3f3;
  --google-btn-bg: #ffffff;
  --google-btn-fg: #1f1f1f;
  --google-btn-border: #747775;
  --google-btn-hover: #eeeeee;
}

/* ---- semantic colours: dark (system preference unless overridden, or forced) ---- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0f14;
    --surface: #12171e;
    --surface-2: #161c24;
    --surface-3: #1c232c;
    --surface-raised: #171d25;
    --sidebar-bg: #0e1319;
    --border: #252d38;
    --border-subtle: #1e252f;
    --border-strong: #344050;
    --border-input: #5f6b7b;
    --text: #e7ebf0;
    --text-muted: #a0aab7;
    --text-subtle: #8a94a2;
    --text-placeholder: #7d8797;
    --text-inverse: #0b0f14;
    --primary: #157a4f;
    --primary-hover: #198553;
    --primary-active: #126e47;
    --on-primary: #ffffff;
    --primary-text: #5ccf98;
    --primary-soft: #12291f;
    --primary-soft-hover: #173426;
    --primary-soft-text: #6fd3a2;
    --primary-border: #1f5a3e;
    --primary-ring: rgba(92, 207, 152, .25);
    --accent: #92d050;
    --on-accent: #1a3306;
    --accent-soft: #1d2a12;
    --accent-soft-text: #b4e283;
    --accent-border: #3d5a1f;
    --success: #4cc38a;
    --success-soft: #11281d;
    --success-text: #6dd3a0;
    --success-border: #1f5a3e;
    --warning: #f0a73a;
    --warning-soft: #2e2210;
    --warning-text: #f3b65b;
    --warning-border: #5c4114;
    --danger: #c42b2b;
    --danger-hover: #d23a3a;
    --danger-soft: #331718;
    --danger-text: #ff8a85;
    --danger-border: #6a2a2a;
    --danger-ring: rgba(255, 138, 133, .25);
    --info: #6aa1ff;
    --info-soft: #14223a;
    --info-text: #8cb4ff;
    --info-border: #2a4677;
    --neutral-soft: #1f2630;
    --neutral-text: #b4bdc9;
    --neutral-border: #343e4b;
    --focus: #5ccf98;
    --overlay: rgba(0, 0, 0, .6);
    --skeleton: #1c232c;
    --skeleton-shine: #252e39;
    --row-hover: #171d25;
    --row-selected: #13261d;
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3), 0 1px 3px rgba(0, 0, 0, .25);
    --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, .45), 0 2px 4px -2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, .6), 0 4px 12px -4px rgba(0, 0, 0, .4);
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a0aab7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9.5 6 6 6-6'/%3E%3C/svg%3E");
    --ms-btn-bg: #2f2f2f;
    --ms-btn-fg: #ffffff;
    --ms-btn-border: #2f2f2f;
    --ms-btn-hover: #3b3b3b;
    --google-btn-bg: #131314;
    --google-btn-fg: #e3e3e3;
    --google-btn-border: #8e918f;
    --google-btn-hover: #252527;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f14;
  --surface: #12171e;
  --surface-2: #161c24;
  --surface-3: #1c232c;
  --surface-raised: #171d25;
  --sidebar-bg: #0e1319;
  --border: #252d38;
  --border-subtle: #1e252f;
  --border-strong: #344050;
  --border-input: #5f6b7b;
  --text: #e7ebf0;
  --text-muted: #a0aab7;
  --text-subtle: #8a94a2;
  --text-placeholder: #7d8797;
  --text-inverse: #0b0f14;
  --primary: #157a4f;
  --primary-hover: #198553;
  --primary-active: #126e47;
  --on-primary: #ffffff;
  --primary-text: #5ccf98;
  --primary-soft: #12291f;
  --primary-soft-hover: #173426;
  --primary-soft-text: #6fd3a2;
  --primary-border: #1f5a3e;
  --primary-ring: rgba(92, 207, 152, .25);
  --accent: #92d050;
  --on-accent: #1a3306;
  --accent-soft: #1d2a12;
  --accent-soft-text: #b4e283;
  --accent-border: #3d5a1f;
  --success: #4cc38a;
  --success-soft: #11281d;
  --success-text: #6dd3a0;
  --success-border: #1f5a3e;
  --warning: #f0a73a;
  --warning-soft: #2e2210;
  --warning-text: #f3b65b;
  --warning-border: #5c4114;
  --danger: #c42b2b;
  --danger-hover: #d23a3a;
  --danger-soft: #331718;
  --danger-text: #ff8a85;
  --danger-border: #6a2a2a;
  --danger-ring: rgba(255, 138, 133, .25);
  --info: #6aa1ff;
  --info-soft: #14223a;
  --info-text: #8cb4ff;
  --info-border: #2a4677;
  --neutral-soft: #1f2630;
  --neutral-text: #b4bdc9;
  --neutral-border: #343e4b;
  --focus: #5ccf98;
  --overlay: rgba(0, 0, 0, .6);
  --skeleton: #1c232c;
  --skeleton-shine: #252e39;
  --row-hover: #171d25;
  --row-selected: #13261d;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3), 0 1px 3px rgba(0, 0, 0, .25);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, .45), 0 2px 4px -2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, .6), 0 4px 12px -4px rgba(0, 0, 0, .4);
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a0aab7' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9.5 6 6 6-6'/%3E%3C/svg%3E");
  --ms-btn-bg: #2f2f2f;
  --ms-btn-fg: #ffffff;
  --ms-btn-border: #2f2f2f;
  --ms-btn-hover: #3b3b3b;
  --google-btn-bg: #131314;
  --google-btn-fg: #e3e3e3;
  --google-btn-border: #8e918f;
  --google-btn-hover: #252527;
}

/* ==========================================================================
   2. Base
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-gutter: stable;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: var(--fw-semibold); line-height: var(--lh-tight); color: var(--text); }
h1 { font-size: var(--fs-2xl); letter-spacing: -0.015em; }
h2 { font-size: var(--fs-lg); letter-spacing: -0.005em; }
h3 { font-size: var(--fs-md); }
h4 { font-size: var(--fs-base); }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
img, svg { display: inline-block; vertical-align: middle; }
svg.icon { flex: none; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
small { font-size: var(--fs-sm); }
strong, b { font-weight: var(--fw-semibold); }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-4) 0; }
code, kbd, samp { font-family: var(--font-mono); font-size: .92em; }
code { padding: 1px 5px; border-radius: var(--radius-xs); background: var(--surface-3); border: 1px solid var(--border-subtle); }
kbd, .kbd {
  display: inline-block; min-width: 20px; padding: 0 5px; border-radius: var(--radius-xs);
  font-family: var(--font-mono); font-size: 11px; line-height: 18px; text-align: center;
  color: var(--text-muted); background: var(--surface); border: 1px solid var(--border-strong);
  box-shadow: inset 0 -1px 0 var(--border-strong);
}
::selection { background: var(--primary-soft-hover); color: var(--text); }

a { color: var(--primary-text); text-decoration: none; text-underline-offset: 2px; }
a:hover { text-decoration: underline; }
/* a plain link inside a sentence is underlined: its colour alone does not set it apart from the text */
:is(p, span, li) > a:not([class]) { text-decoration: underline; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius-xs); }
[tabindex="-1"]:focus-visible:not(.focus-ring) { outline: none; }

/* thin, quiet scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ==========================================================================
   3. Utilities
   ========================================================================== */

.sr-only, .visually-hidden {
  position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important;
  margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important; border: 0 !important;
}
.hidden { display: none !important; }

.stack { display: flex; flex-direction: column; gap: var(--stack-gap, var(--space-4)); min-width: 0; }
.stack-xs { --stack-gap: var(--space-1); }
.stack-sm { --stack-gap: var(--space-2); }
.stack-md { --stack-gap: var(--space-3); }
.stack-lg { --stack-gap: var(--space-6); }
.stack-xl { --stack-gap: var(--space-8); }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--cluster-gap, var(--space-2)); min-width: 0; }
.cluster-xs { --cluster-gap: var(--space-1); }
.cluster-md { --cluster-gap: var(--space-3); }
.cluster-lg { --cluster-gap: var(--space-4); }
.row { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.between { justify-content: space-between; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-end { justify-content: flex-end; }
.nowrap-flex { flex-wrap: nowrap; }
.spacer, .grow { flex: 1 1 auto; min-width: 0; }
.shrink-0 { flex-shrink: 0; }

.grid { display: grid; gap: var(--grid-gap, var(--space-4)); }
.grid-2 { display: grid; gap: var(--grid-gap, var(--space-4)); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: var(--grid-gap, var(--space-4)); grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: var(--grid-gap, var(--space-4)); grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { display: grid; gap: var(--grid-gap, var(--space-4)); grid-template-columns: repeat(auto-fill, minmax(var(--grid-min, 240px), 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

.text-xs { font-size: var(--fs-xs); }
.text-sm { font-size: var(--fs-sm); }
.text-base { font-size: var(--fs-base); }
.text-md { font-size: var(--fs-md); }
.text-lg { font-size: var(--fs-lg); }
.text-xl { font-size: var(--fs-xl); }
.muted { color: var(--text-muted); }
.subtle { color: var(--text-subtle); }
.text-primary { color: var(--primary-text); }
.text-success { color: var(--success-text); }
.text-warning { color: var(--warning-text); }
.text-danger { color: var(--danger-text); }
.text-info { color: var(--info-text); }
.medium { font-weight: var(--fw-medium); }
.strong, .semibold { font-weight: var(--fw-semibold); }
.bold { font-weight: var(--fw-bold); }
.mono { font-family: var(--font-mono); font-size: .92em; }
.tabular { font-variant-numeric: tabular-nums; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-left { text-align: left; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.break-words { overflow-wrap: anywhere; }
.eyebrow { font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: .06em; text-transform: uppercase; color: var(--text-subtle); }
.max-w-prose { max-width: 68ch; }
.w-full { width: 100%; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: var(--space-1); } .mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); } .mt-4 { margin-top: var(--space-4); } .mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: var(--space-1); } .mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); } .mb-4 { margin-bottom: var(--space-4); } .mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.ml-auto { margin-left: auto; }
.p-0 { padding: 0 !important; }
.divider { height: 1px; background: var(--border); border: 0; margin: 0; }
.divider-v { width: 1px; align-self: stretch; background: var(--border); }

/* status dot */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--text-subtle); flex: none; }
.dot-success { background: var(--success); }
.dot-warning { background: var(--warning); }
.dot-danger { background: var(--danger-text); }
.dot-info { background: var(--info); }
.dot-primary { background: var(--primary-text); }
.dot-neutral { background: var(--text-subtle); }
.dot-pulse { position: relative; }
.dot-pulse::after {
  content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 2px solid currentColor;
  color: inherit; opacity: 0; animation: dot-pulse 2s var(--ease) infinite;
}
.dot-success.dot-pulse::after { color: var(--success); }
@keyframes dot-pulse { 0% { transform: scale(.6); opacity: .6; } 80%, 100% { transform: scale(1.6); opacity: 0; } }

/* the "Total Gaji" highlight, echoing the lime cell of the Excel payslip */
.total-pill {
  display: inline-flex; align-items: center; gap: var(--space-1); padding: 2px var(--space-2);
  border-radius: var(--radius-sm); background: var(--accent); color: var(--on-accent);
  font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.total-soft {
  background: var(--accent-soft); color: var(--accent-soft-text); font-weight: var(--fw-semibold);
}
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money-negative, .is-negative { color: var(--danger-text); }

/* responsive visibility */
@media (max-width: 900px) { .hide-md { display: none !important; } }
@media (min-width: 901px) { .show-md { display: none !important; } }
@media (max-width: 640px) { .hide-sm { display: none !important; } }
@media (min-width: 641px) { .show-sm { display: none !important; } }

/* ==========================================================================
   4. App layout: sidebar, top bar, page
   ========================================================================== */

.skip-link {
  position: fixed; top: var(--space-2); left: var(--space-2); z-index: 100; padding: var(--space-2) var(--space-4);
  background: var(--surface-raised); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-md); transform: translateY(-160%); transition: transform var(--dur) var(--ease);
}
.skip-link:focus, .skip-link:focus-visible { transform: none; text-decoration: none; }

.app-shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
/* the sidebar is sticky (one screen tall); this paints its column down the whole page behind it */
.app-shell::before {
  content: ""; grid-column: 1; grid-row: 1; background: var(--sidebar-bg); border-right: 1px solid var(--border);
}
.app-shell > .sidebar { grid-column: 1; grid-row: 1; align-self: start; }
.app-shell > .main-area { grid-column: 2; grid-row: 1; }

.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column;
  background: var(--sidebar-bg); border-right: 1px solid var(--border); z-index: var(--z-nav-drawer);
  overflow: hidden;
}
.sidebar-head {
  display: flex; align-items: center; gap: var(--space-3); height: 64px; padding: 0 var(--space-4) 0 var(--space-5);
  flex: none;
}
.brand { display: flex; align-items: center; gap: var(--space-3); color: var(--text); min-width: 0; border-radius: var(--radius); }
.brand:hover { text-decoration: none; }
.brand .logo-mark, .brand img { width: 30px; height: 30px; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-name { font-size: var(--fs-md); font-weight: var(--fw-bold); letter-spacing: -0.01em; }
.brand-sub { font-size: var(--fs-xs); color: var(--text-muted); font-weight: var(--fw-medium); }
.sidebar-close { margin-left: auto; }

.sidebar-scroll { flex: 1 1 auto; overflow-y: auto; padding: var(--space-2) var(--space-3) var(--space-4); }
.nav-label {
  padding: var(--space-3) var(--space-3) var(--space-1-5); font-size: 11px; font-weight: var(--fw-semibold);
  letter-spacing: .06em; text-transform: uppercase; color: var(--text-subtle);
}
.nav-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: var(--space-3); height: 36px; padding: 0 var(--space-3);
  border-radius: var(--radius); color: var(--text-muted); font-weight: var(--fw-medium);
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.nav-link .icon { color: var(--text-subtle); transition: color var(--dur-fast) var(--ease); }
.nav-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-link:hover .icon { color: var(--text-muted); }
.nav-link[aria-current="page"] { background: var(--primary-soft); color: var(--primary-soft-text); font-weight: var(--fw-semibold); }
.nav-link[aria-current="page"] .icon { color: var(--primary-text); }
.nav-link[aria-current="page"]::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 0 2px 2px 0;
  background: var(--primary-text);
}
.nav-link:focus-visible { outline-offset: -2px; border-radius: var(--radius); }
.nav-badge { margin-left: auto; }

.sidebar-foot { flex: none; padding: var(--space-3); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: var(--space-2); }
.bot-status {
  display: flex; align-items: center; gap: var(--space-2-5); padding: var(--space-2) var(--space-3);
  border-radius: var(--radius); color: var(--text-muted); font-size: var(--fs-sm);
  background: var(--surface-2); border: 1px solid var(--border-subtle);
}
.bot-status:hover { text-decoration: none; background: var(--surface-3); color: var(--text); }
.bot-status-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.bot-status-title { color: var(--text); font-weight: var(--fw-medium); }
.bot-status-sub { font-size: var(--fs-xs); color: var(--text-muted); }
.sidebar-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
/* who is signed in (main.js renderUser): initials, name, e-mail and how they signed in */
.sidebar-user { display: flex; align-items: center; gap: var(--space-2-5); min-width: 0; padding: var(--space-1) var(--space-1) 0; }
.sidebar-user-avatar .icon { width: 16px; height: 16px; }
.sidebar-user-text { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; min-width: 0; flex: 1 1 auto; line-height: 1.3; }
.sidebar-user-name, .sidebar-user-email { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-name { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text); }
.sidebar-user-email { font-size: var(--fs-xs); color: var(--text-muted); }
.sidebar-user-method { display: inline-flex; margin-top: 3px; }
.sidebar-user-badge { gap: 5px; background: var(--surface); }
.sidebar-user-badge .provider-logo { flex: none; }

.topbar {
  display: none; position: sticky; top: 0; z-index: var(--z-topbar); height: var(--topbar-h);
  align-items: center; gap: var(--space-2); padding: 0 var(--space-3);
  background: var(--surface);
  -webkit-backdrop-filter: saturate(1.4) blur(8px); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
/* (a color-mix() with var() inside is not dropped by older browsers but turns transparent, so feature-test it) */
@supports (background: color-mix(in srgb, red 50%, transparent)) {
  .topbar { background: color-mix(in srgb, var(--surface) 92%, transparent); }
}
.topbar .brand .logo-mark { width: 26px; height: 26px; }
.topbar-end { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

.main-area { min-width: 0; display: flex; flex-direction: column; }
.main { flex: 1 1 auto; min-width: 0; outline: none; }
.main-inner {
  width: 100%; max-width: calc(var(--content-max) + 2 * var(--page-pad-x)); margin: 0 auto;
  padding: var(--page-pad-y) var(--page-pad-x) var(--space-16);
}
.page { display: flex; flex-direction: column; gap: var(--space-6); min-width: 0; animation: page-in var(--dur) var(--ease); }
@keyframes page-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.nav-backdrop {
  position: fixed; inset: 0; background: var(--overlay); z-index: calc(var(--z-nav-drawer) - 1);
  opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease);
}

/* where a link opens a page part-way down (the router scrolls to [data-scroll-to]): a little room above it, and
   on small screens room for the sticky top bar */
[data-scroll-to] { scroll-margin-top: var(--space-4); }

@media (max-width: 900px) {
  :root { --page-pad-x: 24px; --page-pad-y: 24px; }
  [data-scroll-to] { scroll-margin-top: calc(var(--topbar-h) + var(--space-3)); }
  .app-shell { grid-template-columns: minmax(0, 1fr); }
  .app-shell::before { display: none; }
  .app-shell > .main-area { grid-column: 1; }
  .topbar { display: flex; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); height: 100%;
    transform: translateX(-100%); visibility: hidden; box-shadow: var(--shadow-lg);
    transition: transform var(--dur-slow) var(--ease), visibility 0s linear var(--dur-slow);
  }
  .app-shell.nav-open .sidebar { transform: none; visibility: visible; transition: transform var(--dur-slow) var(--ease); }
  .app-shell.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
}
@media (min-width: 901px) {
  .sidebar-close, .nav-backdrop { display: none !important; }
}
@media (max-width: 640px) {
  :root { --page-pad-x: 16px; --page-pad-y: 20px; }
  .page { gap: var(--space-5); }
}

/* page header */
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4) var(--space-6); flex-wrap: wrap; }
.page-header-text { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; flex: 1 1 320px; }
.page-title { font-size: var(--fs-2xl); font-weight: var(--fw-semibold); letter-spacing: -0.015em; line-height: 1.2; }
.page-title:focus { outline: none; }
.page-subtitle { color: var(--text-muted); font-size: var(--fs-base); display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2); min-height: 22px; }
.page-back {
  display: inline-flex; align-items: center; gap: var(--space-1); color: var(--text-muted); font-size: var(--fs-sm);
  font-weight: var(--fw-medium); margin-bottom: var(--space-1); width: fit-content;
}
.page-back:hover { color: var(--text); text-decoration: none; }
.page-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; flex: 0 1 auto; }
@media (max-width: 640px) {
  .page-title { font-size: var(--fs-xl); }
  .page-actions { width: 100%; }
}

.section { display: flex; flex-direction: column; gap: var(--space-3); min-width: 0; }
.section-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; }
.section-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.section-sub { color: var(--text-muted); font-size: var(--fs-sm); }

/* the login / setup screens (auth-…) are styled in css/pages/login.css */

/* full-screen boot / fatal states */
.boot { min-height: 100vh; display: grid; place-items: center; padding: var(--space-6); }
.boot-inner { display: flex; flex-direction: column; align-items: center; gap: var(--space-4); color: var(--text-muted); text-align: center; }
/* theme-init.js: the app could not start (old browser, script not loaded) */
.boot-problem { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); max-width: 400px; }
.boot-problem-title { color: var(--text); font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.boot-problem .btn { margin-top: var(--space-2); }

/* ==========================================================================
   5. Buttons
   ========================================================================== */

.btn {
  --btn-h: var(--control-h);
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  height: var(--btn-h); min-width: 0; padding: 0 var(--space-3-5); border: 1px solid transparent; border-radius: var(--radius);
  font-size: var(--fs-base); font-weight: var(--fw-medium); line-height: 1; white-space: nowrap; text-decoration: none;
  cursor: pointer; user-select: none; -webkit-user-select: none; vertical-align: middle;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-xs);
}
.btn:hover { text-decoration: none; }
.btn .icon { width: 18px; height: 18px; margin-left: -2px; }
.btn-icon .icon { margin: 0; }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius); }

.btn-primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255, 255, 255, .08); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-primary:active { background: var(--primary-active); border-color: var(--primary-active); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-3); }
.btn-secondary:active { background: var(--surface-2); }

.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-ghost:active { background: var(--border-subtle); }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-danger-ghost { background: transparent; color: var(--danger-text); border-color: transparent; box-shadow: none; }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-soft { background: var(--primary-soft); color: var(--primary-soft-text); border-color: transparent; box-shadow: none; }
.btn-soft:hover { background: var(--primary-soft-hover); }

.btn-link {
  height: auto; padding: 0; border: 0; background: none; box-shadow: none; color: var(--primary-text);
  font-weight: var(--fw-medium); border-radius: var(--radius-xs);
}
.btn-link:hover { text-decoration: underline; background: none; }

.btn-sm { --btn-h: var(--control-h-sm); padding: 0 var(--space-2-5); font-size: var(--fs-sm); gap: var(--space-1-5); border-radius: var(--radius-sm); }
.btn-sm .icon { width: 16px; height: 16px; }
.btn-lg { --btn-h: var(--control-h-lg); padding: 0 var(--space-5); font-size: var(--fs-md); }
.btn-icon { width: var(--btn-h); padding: 0; flex: none; }
.btn-block { width: 100%; }

.btn:disabled, .btn[aria-disabled="true"] { cursor: not-allowed; opacity: .55; box-shadow: none; }
.btn-primary:disabled:hover { background: var(--primary); border-color: var(--primary); }
.btn-secondary:disabled:hover, .btn:not([class*="btn-"]):disabled:hover { background: var(--surface); }
.btn-ghost:disabled:hover, .btn-danger-ghost:disabled:hover { background: transparent; }
.btn-danger:disabled:hover { background: var(--danger); border-color: var(--danger); }
.btn-soft:disabled:hover { background: var(--primary-soft); }
.btn.is-loading { cursor: progress; opacity: 1; }
.btn.is-loading > .icon { display: none; }
.btn.is-loading:disabled { opacity: .85; }
.btn .spinner { width: 16px; height: 16px; border-width: 2px; }
.btn-primary .spinner, .btn-danger .spinner { color: currentColor; }

.btn-group { display: inline-flex; }
.btn-group > .btn { border-radius: 0; }
.btn-group > .btn + .btn { margin-left: -1px; }
.btn-group > .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.btn-group > .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.btn-group > .btn:focus-visible { z-index: 1; }

/* "Sign in with Microsoft" / "Sign in with Google" (login page, the "session ended" dialog): the providers' own
   logo, wording and colours, full width. <a class="btn-provider btn-provider-google" href="/auth/google?next=…"> */
.btn-provider {
  --pb-bg: var(--surface); --pb-fg: var(--text); --pb-border: var(--border-strong); --pb-hover: var(--surface-3);
  position: relative; display: flex; align-items: center; justify-content: center; gap: var(--space-3);
  width: 100%; min-height: 44px; padding: 0 var(--space-4); border: 1px solid var(--pb-border); border-radius: var(--radius);
  background: var(--pb-bg); color: var(--pb-fg); box-shadow: var(--shadow-xs); cursor: pointer;
  font-size: var(--fs-md); font-weight: var(--fw-semibold); line-height: 1.2; text-align: center; text-decoration: none;
  user-select: none; -webkit-user-select: none;
  transition: background-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}
.btn-provider:hover { background: var(--pb-hover); color: var(--pb-fg); text-decoration: none; }
.btn-provider:active { box-shadow: none; }
.btn-provider:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--radius); }
.btn-provider .provider-logo { flex: none; }
.btn-provider-microsoft {
  --pb-bg: var(--ms-btn-bg); --pb-fg: var(--ms-btn-fg); --pb-border: var(--ms-btn-border); --pb-hover: var(--ms-btn-hover);
  font-family: "Segoe UI", "Segoe UI Variable Text", var(--font-sans); font-size: 15px; font-weight: var(--fw-semibold);
}
.btn-provider-google {
  --pb-bg: var(--google-btn-bg); --pb-fg: var(--google-btn-fg); --pb-border: var(--google-btn-border); --pb-hover: var(--google-btn-hover);
  font-family: Roboto, "Segoe UI", Arial, var(--font-sans); font-size: 14px; font-weight: var(--fw-medium); letter-spacing: .25px;
}
.btn-provider .spinner { width: 18px; height: 18px; border-width: 2px; color: currentColor; }
.btn-provider.is-loading { cursor: progress; }
.btn-provider[aria-disabled="true"] { pointer-events: none; }
.btn-provider[aria-disabled="true"]:not(.is-loading) { opacity: .5; box-shadow: none; }
.provider-stack { display: flex; flex-direction: column; gap: var(--space-3); }

/* ==========================================================================
   6. Forms
   ========================================================================== */

.field { display: flex; flex-direction: column; gap: var(--space-1-5); min-width: 0; }
.field-label { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); display: flex; align-items: baseline; gap: var(--space-1-5); }
.field-optional { font-weight: var(--fw-regular); color: var(--text-subtle); font-size: var(--fs-xs); }
.field-required { color: var(--danger-text); }
.field-hint { font-size: var(--fs-xs); color: var(--text-muted); line-height: 1.45; }
.field-error { font-size: var(--fs-xs); color: var(--danger-text); display: flex; align-items: flex-start; gap: var(--space-1); font-weight: var(--fw-medium); line-height: 1.45; }
.field-error .icon { width: 14px; height: 14px; margin-top: 1px; }
.field-inline { flex-direction: row; align-items: center; gap: var(--space-3); }
.fieldset { border: 0; padding: 0; margin: 0; min-width: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.fieldset > legend { padding: 0; margin-bottom: var(--space-2); font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.form-grid { display: grid; gap: var(--space-4) var(--space-5); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid > .span-all { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }

.input, .select, .textarea {
  display: block; width: 100%; min-width: 0; height: var(--control-h); padding: 0 var(--space-3);
  background: var(--surface); color: var(--text); border: 1px solid var(--border-input); border-radius: var(--radius);
  font-size: var(--fs-base); line-height: 1.4; box-shadow: var(--shadow-xs);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
  appearance: none; -webkit-appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--text-placeholder); opacity: 1; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-subtle); }
.input:focus, .select:focus, .textarea:focus,
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  outline: none; border-color: var(--primary-text); box-shadow: 0 0 0 3px var(--primary-ring);
}
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger-text); }
.input[aria-invalid="true"]:focus, .select[aria-invalid="true"]:focus, .textarea[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--danger-ring); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); border-color: var(--border-strong); color: var(--text-subtle); cursor: not-allowed; box-shadow: none; }
.input[readonly] { background: var(--surface-2); }
.input-sm, .select.input-sm { height: var(--control-h-sm); font-size: var(--fs-sm); padding: 0 var(--space-2-5); border-radius: var(--radius-sm); }
.input-lg { height: var(--control-h-lg); font-size: var(--fs-md); }
.input.num, .input-num { text-align: right; font-variant-numeric: tabular-nums; }
.input-mono { font-family: var(--font-mono); font-size: var(--fs-sm); }
.textarea { height: auto; min-height: 88px; padding: var(--space-2) var(--space-3); resize: vertical; line-height: var(--lh); }
.select {
  padding-right: 34px; cursor: pointer; background-image: var(--chevron); background-repeat: no-repeat;
  background-position: right 10px center; background-size: 16px 16px; text-overflow: ellipsis;
}
.select.input-sm { padding-right: 28px; background-position: right 7px center; background-size: 14px 14px; }
.select::-ms-expand { display: none; }
input[type="search"].input::-webkit-search-cancel-button { cursor: pointer; }
input[type="number"].input { -moz-appearance: textfield; }
input[type="number"].input::-webkit-inner-spin-button, input[type="number"].input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* input with addons ("Rp", icons, buttons) */
.input-group {
  display: flex; align-items: stretch; width: 100%; min-width: 0; height: var(--control-h);
  background: var(--surface); border: 1px solid var(--border-input); border-radius: var(--radius);
  box-shadow: var(--shadow-xs); transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input-group:hover { border-color: var(--text-subtle); }
.input-group:focus-within { border-color: var(--primary-text); box-shadow: 0 0 0 3px var(--primary-ring); }
/* (:has() never shares a selector list with its fallback: browsers without :has() drop the whole rule) */
.input-group.is-invalid { border-color: var(--danger-text); }
.input-group:has(> .input[aria-invalid="true"]) { border-color: var(--danger-text); }
.input-group.is-invalid:focus-within { box-shadow: 0 0 0 3px var(--danger-ring); }
.input-group:has(> .input[aria-invalid="true"]):focus-within { box-shadow: 0 0 0 3px var(--danger-ring); }
.input-group.is-disabled { background: var(--surface-2); box-shadow: none; }
.input-group > .input {
  flex: 1 1 auto; height: 100%; border: 0; background: transparent; box-shadow: none; border-radius: 0; min-width: 0;
}
.input-group > .input:focus { box-shadow: none; }
.input-group > .input:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.input-group > .input:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.input-addon {
  display: flex; align-items: center; padding: 0 var(--space-3); color: var(--text-muted); font-size: var(--fs-sm);
  font-weight: var(--fw-medium); white-space: nowrap; flex: none; user-select: none; -webkit-user-select: none;
}
.input-addon:first-child { padding-right: 0; }
.input-addon:last-child { padding-left: 0; }
.input-addon.is-boxed { background: var(--surface-2); border-right: 1px solid var(--border); padding: 0 var(--space-3); border-radius: var(--radius) 0 0 var(--radius); }
.input-addon .icon { width: 16px; height: 16px; color: var(--text-subtle); }
.input-group > .btn { height: auto; margin: 3px; border-radius: var(--radius-sm); --btn-h: calc(var(--control-h) - 8px); }
.input-group > .btn-icon { width: calc(var(--control-h) - 8px); }
.input-group-sm { height: var(--control-h-sm); border-radius: var(--radius-sm); }
.input-group-sm > .input { font-size: var(--fs-sm); padding: 0 var(--space-2); }
.input-group-sm > .input-addon { font-size: var(--fs-xs); padding-left: var(--space-2); }
.input-rp > .input { font-variant-numeric: tabular-nums; }
.input-rp.is-right > .input { text-align: right; }

/* checkbox & radio (custom, keyboard-native) */
.checkbox, .radio {
  appearance: none; -webkit-appearance: none; flex: none; width: 16px; height: 16px; margin: 0; cursor: pointer;
  background: var(--surface); border: 1.5px solid var(--border-input); display: inline-grid; place-content: center;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
  vertical-align: middle;
}
.checkbox { border-radius: var(--radius-xs); }
.radio { border-radius: 50%; }
.checkbox:hover, .radio:hover { border-color: var(--primary-text); }
.checkbox:checked, .checkbox:indeterminate { background-color: var(--primary); border-color: var(--primary); }
.checkbox:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m3.5 8.5 3 3 6-7'/%3E%3C/svg%3E");
  background-size: 12px 12px; background-position: center; background-repeat: no-repeat;
}
.checkbox:indeterminate {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' stroke='white' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M4 8h8'/%3E%3C/svg%3E");
  background-size: 12px 12px; background-position: center; background-repeat: no-repeat;
}
.radio:checked { border-color: var(--primary); border-width: 5px; background: #fff; }
.checkbox:focus-visible, .radio:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.checkbox:disabled, .radio:disabled { opacity: .5; cursor: not-allowed; }
.check-row { display: inline-flex; align-items: flex-start; gap: var(--space-2-5); cursor: pointer; line-height: 1.4; }
.check-row > .checkbox, .check-row > .radio { margin-top: 1px; }
.check-text { display: flex; flex-direction: column; gap: 2px; }
.check-label { font-weight: var(--fw-medium); }
.check-desc { font-size: var(--fs-sm); color: var(--text-muted); }

/* switch: <label class="switch"><input class="switch-input" type="checkbox" role="switch"><span class="switch-track"></span>…</label> */
.switch { display: inline-flex; align-items: flex-start; gap: var(--space-3); cursor: pointer; position: relative; line-height: 1.4; }
.switch-input { position: absolute; opacity: 0; width: 36px; height: 20px; margin: 0; cursor: pointer; }
.switch-track {
  position: relative; flex: none; width: 36px; height: 20px; border-radius: var(--radius-full);
  background: var(--border-input); transition: background-color var(--dur) var(--ease);
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); transition: transform var(--dur) var(--ease);
}
.switch-input:checked + .switch-track { background: var(--primary); }
.switch-input:checked + .switch-track::after { transform: translateX(16px); }
.switch-input:focus-visible + .switch-track { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch-input:disabled + .switch-track { opacity: .5; }
.switch:has(.switch-input:disabled) { cursor: not-allowed; }

/* radio cards */
.radio-cards { display: grid; gap: var(--space-3); grid-template-columns: repeat(var(--radio-cols, 2), minmax(0, 1fr)); border: 0; padding: 0; margin: 0; min-width: 0; }
.radio-cards > legend { padding: 0; margin-bottom: var(--space-2); font-size: var(--fs-sm); font-weight: var(--fw-medium); }
@media (max-width: 640px) { .radio-cards { grid-template-columns: minmax(0, 1fr); } }
.radio-card {
  position: relative; display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3-5) var(--space-4);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.radio-card:hover { border-color: var(--border-input); }
.radio-card.is-checked {
  border-color: var(--primary-text); background: var(--primary-soft); box-shadow: 0 0 0 1px var(--primary-text) inset;
}
.radio-card:has(.radio:checked) {
  border-color: var(--primary-text); background: var(--primary-soft); box-shadow: 0 0 0 1px var(--primary-text) inset;
}
.radio-card .radio { margin-top: 2px; }
.radio-card-icon { flex: none; width: 32px; height: 32px; border-radius: var(--radius); display: grid; place-items: center; background: var(--surface-3); color: var(--text-muted); }
.radio-card.is-checked .radio-card-icon { background: var(--surface); color: var(--primary-text); }
.radio-card:has(.radio:checked) .radio-card-icon { background: var(--surface); color: var(--primary-text); }
.radio-card-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.radio-card-title { font-weight: var(--fw-semibold); display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.radio-card-desc { font-size: var(--fs-sm); color: var(--text-muted); }
.radio-card:has(.radio:disabled) { opacity: .6; cursor: not-allowed; }

/* segmented control (native radios) */
.segmented {
  display: inline-flex; align-items: stretch; gap: 2px; padding: 3px; border-radius: var(--radius);
  background: var(--surface-3); border: 1px solid var(--border); max-width: 100%; overflow-x: auto;
}
.segmented-item { position: relative; display: flex; }
.segmented-item input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented-item span {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-1-5); min-height: 28px;
  padding: 0 var(--space-3); border-radius: var(--radius-sm); color: var(--text-muted); font-size: var(--fs-sm);
  font-weight: var(--fw-medium); white-space: nowrap; cursor: pointer; transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.segmented-item span .icon { width: 16px; height: 16px; }
.segmented-item:hover span { color: var(--text); }
.segmented-item input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm), inset 0 0 0 1px var(--primary-text); }
.segmented-item input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }
.segmented-item input:disabled + span { opacity: .5; cursor: not-allowed; }
.segmented-sm { padding: 2px; }
.segmented-sm .segmented-item span { min-height: 24px; padding: 0 var(--space-2); font-size: var(--fs-xs); }
.segmented-icons .segmented-item span { padding: 0 var(--space-2); }
.segmented-block { display: flex; width: 100%; }
.segmented-block .segmented-item { flex: 1; }
.segmented-block .segmented-item span { flex: 1; }

/* chips input */
.chips-input {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1-5); min-height: var(--control-h); padding: 4px 6px;
  background: var(--surface); border: 1px solid var(--border-input); border-radius: var(--radius); cursor: text;
  box-shadow: var(--shadow-xs); transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.chips-input:hover { border-color: var(--text-subtle); }
.chips-input:focus-within { border-color: var(--primary-text); box-shadow: 0 0 0 3px var(--primary-ring); }
.chips-input.is-invalid { border-color: var(--danger-text); }
.chips-input > input { flex: 1 0 120px; min-width: 80px; height: 26px; border: 0; outline: none; background: transparent; padding: 0 4px; }
.chips-input > input::placeholder { color: var(--text-placeholder); }
.chip {
  display: inline-flex; align-items: center; gap: 2px; height: 26px; padding: 0 2px 0 var(--space-2); max-width: 100%;
  border-radius: var(--radius-sm); background: var(--surface-3); border: 1px solid var(--border); font-size: var(--fs-sm);
  font-weight: var(--fw-medium); color: var(--text);
}
.chip-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-remove {
  display: grid; place-items: center; width: 20px; height: 20px; padding: 0; border: 0; border-radius: var(--radius-xs);
  background: transparent; color: var(--text-muted);
}
.chip-remove:hover { background: var(--border); color: var(--text); }
.chip-remove .icon { width: 14px; height: 14px; }
.chip.is-invalid { background: var(--danger-soft); border-color: var(--danger-border); color: var(--danger-text); }
.chip.is-invalid .chip-remove { color: inherit; }
/* always on the list (e.g. set on the server): a lock instead of the remove button */
.chip.is-locked { background: var(--surface-2); border-style: dashed; border-color: var(--border-strong); }
.chip-lock { display: grid; place-items: center; width: 20px; height: 20px; color: var(--text-subtle); }
.chip.is-invalid .chip-lock { color: inherit; }

/* ==========================================================================
   7. Badges, avatars
   ========================================================================== */

.badge {
  display: inline-flex; align-items: center; gap: var(--space-1-5); height: 22px; padding: 0 var(--space-2);
  border-radius: var(--radius-full); font-size: var(--fs-xs); font-weight: var(--fw-medium); line-height: 1;
  white-space: nowrap; vertical-align: middle; border: 1px solid var(--neutral-border);
  background: var(--neutral-soft); color: var(--neutral-text);
}
.badge .icon { width: 13px; height: 13px; margin: 0 -1px; }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.badge-success { background: var(--success-soft); color: var(--success-text); border-color: var(--success-border); }
.badge-warning { background: var(--warning-soft); color: var(--warning-text); border-color: var(--warning-border); }
.badge-danger { background: var(--danger-soft); color: var(--danger-text); border-color: var(--danger-border); }
.badge-info { background: var(--info-soft); color: var(--info-text); border-color: var(--info-border); }
.badge-primary { background: var(--primary-soft); color: var(--primary-soft-text); border-color: var(--primary-border); }
.badge-accent { background: var(--accent-soft); color: var(--accent-soft-text); border-color: var(--accent-border); }
.badge-solid { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.badge-sm { height: 18px; padding: 0 6px; font-size: 11px; }
.badge-lg { height: 26px; padding: 0 var(--space-2-5); font-size: var(--fs-sm); }
.count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--radius-full);
  background: var(--surface-3); color: var(--text-muted); font-size: 11px; font-weight: var(--fw-semibold); font-variant-numeric: tabular-nums;
}

.avatar {
  --avatar: 32px;
  display: inline-grid; place-items: center; flex: none; width: var(--avatar); height: var(--avatar); border-radius: 50%;
  font-size: calc(var(--avatar) * .38); font-weight: var(--fw-semibold); letter-spacing: .02em; user-select: none;
  background: var(--avatar-bg, var(--primary-soft)); color: var(--avatar-fg, var(--primary-soft-text));
}
.avatar-sm { --avatar: 24px; }
.avatar-lg { --avatar: 40px; }
.avatar[data-tone="1"] { --avatar-bg: var(--info-soft); --avatar-fg: var(--info-text); }
.avatar[data-tone="2"] { --avatar-bg: var(--accent-soft); --avatar-fg: var(--accent-soft-text); }
.avatar[data-tone="3"] { --avatar-bg: var(--warning-soft); --avatar-fg: var(--warning-text); }
.avatar[data-tone="4"] { --avatar-bg: var(--neutral-soft); --avatar-fg: var(--neutral-text); }
.person { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.person-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.person-name { font-weight: var(--fw-medium); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-sub { font-size: var(--fs-xs); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ==========================================================================
   8. Cards & stat tiles
   ========================================================================== */

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs); min-width: 0; display: flex; flex-direction: column;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap;
  padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border);
}
.card-header.is-plain { border-bottom: 0; padding-bottom: 0; }
.card-heading { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); line-height: var(--lh-snug); display: flex; align-items: center; gap: var(--space-2); }
.card-subtitle { font-size: var(--fs-sm); color: var(--text-muted); }
.card-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.card-body { padding: var(--space-5); min-width: 0; flex: 1 1 auto; }
.card-body.is-flush, .card-flush > .card-body { padding: 0; }
.card-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap;
  padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border); background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.card-footer.is-between { justify-content: space-between; }
.card-muted { background: var(--surface-2); box-shadow: none; }
.card-interactive { transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
.card-interactive:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
a.card { color: inherit; text-decoration: none; }
.card > .table-wrap { border: 0; border-radius: 0 0 var(--radius-lg) var(--radius-lg); box-shadow: none; }
.card > .card-header + .table-wrap { border-top: 0; }
.card > .table-wrap:first-child { border-radius: var(--radius-lg); }

.tiles { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.tile {
  position: relative; display: flex; flex-direction: column; gap: var(--space-1-5); padding: var(--space-4) var(--space-5) var(--space-5);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs);
  min-width: 0; overflow: hidden; color: inherit;
}
a.tile:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.tile-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-height: 32px; }
.tile-label { font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text-muted); }
.tile-icon {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius); flex: none;
  background: var(--surface-3); color: var(--text-muted);
}
.tile-icon .icon { width: 18px; height: 18px; }
.tile-value {
  font-size: 26px; font-weight: var(--fw-semibold); letter-spacing: -0.02em; line-height: 1.15;
  font-variant-numeric: tabular-nums; color: var(--text); overflow-wrap: anywhere;
}
.tile-value small { font-size: var(--fs-base); font-weight: var(--fw-medium); color: var(--text-muted); letter-spacing: 0; }
.tile-meta { font-size: var(--fs-sm); color: var(--text-muted); display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-1-5); }
.tile-trend { display: inline-flex; align-items: center; gap: 2px; font-weight: var(--fw-medium); }
.tile-trend .icon { width: 14px; height: 14px; }
.tile-trend.is-up { color: var(--success-text); }
.tile-trend.is-down { color: var(--danger-text); }
.tile-trend.is-flat { color: var(--text-muted); }
.tile-trend.tone-neutral { color: var(--text-muted); }
.tile-trend.tone-success { color: var(--success-text); }
.tile-trend.tone-danger { color: var(--danger-text); }
.tile-trend.tone-warning { color: var(--warning-text); }
.tile-primary .tile-icon { background: var(--primary-soft); color: var(--primary-text); }
.tile-info .tile-icon { background: var(--info-soft); color: var(--info-text); }
.tile-warning .tile-icon { background: var(--warning-soft); color: var(--warning-text); }
.tile-danger .tile-icon { background: var(--danger-soft); color: var(--danger-text); }
.tile-accent::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); }
.tile-accent .tile-icon { background: var(--accent-soft); color: var(--accent-soft-text); }

/* ==========================================================================
   9. Tables
   ========================================================================== */

.table-wrap {
  position: relative; width: 100%; overflow: auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs);
  -webkit-overflow-scrolling: touch;
}
.table-wrap.is-scroll { max-height: var(--table-max-h, min(70vh, 640px)); }
.table-wrap.is-plain { border: 0; border-radius: 0; box-shadow: none; background: transparent; }

.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-base); }
.table caption { text-align: left; }
.table th, .table td { padding: var(--space-2-5) var(--space-4); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border-subtle); }
.table thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); color: var(--text-muted);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); letter-spacing: .02em; white-space: nowrap;
  border-bottom: 1px solid var(--border); height: 38px; padding-top: 0; padding-bottom: 0;
}
.table tbody tr:last-child > * { border-bottom: 0; }
.table tbody tr { transition: background-color var(--dur-fast) var(--ease); }
.table tbody tr:hover > * { background: var(--row-hover); }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table th.center, .table td.center { text-align: center; }
.table td.nowrap { white-space: nowrap; }
.table th.shrink, .table td.shrink { width: 1%; white-space: nowrap; }
.table td.muted { color: var(--text-muted); }
.table td.actions { width: 1%; white-space: nowrap; text-align: right; padding-top: 0; padding-bottom: 0; }
.table td.actions .btn { vertical-align: middle; }
.table tr.is-clickable { cursor: pointer; }
.table tr.is-clickable:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.table tr.is-selected > * { background: var(--row-selected); }
.table tr.is-muted > * { color: var(--text-subtle); }
.table tr.is-error > * { background: var(--danger-soft); }
.table tr.is-warning > * { background: var(--warning-soft); }
.table tfoot td, .table tfoot th {
  position: sticky; bottom: 0; z-index: 1; background: var(--surface-2); font-weight: var(--fw-semibold);
  border-top: 1px solid var(--border); border-bottom: 0; color: var(--text);
}
.table td.cell-total, .table th.cell-total { background: var(--accent-soft); color: var(--accent-soft-text); font-weight: var(--fw-semibold); }
.table tbody tr:hover > td.cell-total { background: var(--accent-soft); }
.table tfoot td.cell-total { background: var(--accent); color: var(--on-accent); }
.table .table-empty td, .table td.table-empty {
  padding: var(--space-10) var(--space-4); text-align: center; color: var(--text-muted); background: var(--surface);
}
.table tbody tr.table-empty:hover > * { background: var(--surface); }
.table-compact th, .table-compact td { padding: var(--space-1-5) var(--space-3); }
.table-compact thead th { height: 32px; }
.table-compact { font-size: var(--fs-sm); }
.table-sticky-first th:first-child, .table-sticky-first td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.table-sticky-first thead th:first-child { z-index: 3; background: var(--surface-2); }
.table-sticky-first tbody tr:hover td:first-child { background: var(--row-hover); }
.table-sticky-first tr.is-selected > td:first-child { background: var(--row-selected); }
.table-sticky-first tr.is-error > td:first-child { background: var(--danger-soft); }
.table-sticky-first tr.is-warning > td:first-child { background: var(--warning-soft); }
/* the row's focus outline would be painted under the sticky cell: draw that cell's part on top */
.table-sticky-first tr.is-clickable:focus-visible > td:first-child::after {
  content: ""; position: absolute; inset: 0 0 -1px 0; pointer-events: none;
  border: 2px solid var(--focus); border-right: 0;
}
.table-sticky-first tbody tr.is-clickable:last-child:focus-visible > td:first-child::after { bottom: 0; }

/* sortable header */
.th-sort {
  display: inline-flex; align-items: center; gap: 4px; padding: 0; margin: 0; border: 0; background: none;
  font: inherit; color: inherit; letter-spacing: inherit; cursor: pointer; border-radius: var(--radius-xs);
}
.th-sort:hover { color: var(--text); }
.th-sort .icon { width: 14px; height: 14px; opacity: .45; }
th[aria-sort="ascending"] .th-sort, th[aria-sort="descending"] .th-sort { color: var(--text); }
th[aria-sort="ascending"] .th-sort .icon, th[aria-sort="descending"] .th-sort .icon { opacity: 1; }
th.num .th-sort { flex-direction: row-reverse; }
.table thead .th-sort { vertical-align: top; }

/* description list (key / value) */
.dl { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: var(--space-2) var(--space-6); margin: 0; }
.dl dt { color: var(--text-muted); font-size: var(--fs-sm); }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) { .dl { grid-template-columns: minmax(0, 1fr); gap: 2px; } .dl dd { margin-bottom: var(--space-2); } }

/* ==========================================================================
   10. Tabs
   ========================================================================== */

.tabs { display: flex; align-items: flex-end; gap: var(--space-6); border-bottom: 1px solid var(--border); overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: var(--space-2); height: 42px; padding: 0 2px;
  margin: 0; border: 0; background: none; color: var(--text-muted); font-weight: var(--fw-medium); font-size: var(--fs-base);
  white-space: nowrap; cursor: pointer; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color var(--dur-fast) var(--ease);
}
.tab .icon { width: 18px; height: 18px; color: var(--text-subtle); }
.tab::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; border-radius: 2px 2px 0 0;
  background: transparent; transition: background-color var(--dur-fast) var(--ease);
}
.tab:hover { color: var(--text); }
.tab:hover::after { background: var(--border-strong); }
.tab[aria-selected="true"] { color: var(--text); }
.tab[aria-selected="true"] .icon { color: var(--primary-text); }
.tab[aria-selected="true"]::after { background: var(--primary-text); }
.tab:focus-visible { outline-offset: -2px; }
.tab .count { height: 18px; min-width: 18px; }
.tab[aria-selected="true"] .count { background: var(--primary-soft); color: var(--primary-soft-text); }
.tab-panel:focus-visible { outline: none; }
.tab-panel { min-width: 0; }

/* ==========================================================================
   11. Overlays: modal, drawer, menu
   ========================================================================== */

html.has-overlay, html.has-overlay body { overflow: hidden; }
/* html keeps its scrollbar gutter (no jump when a dialog opens); paint it like the backdrop / drawer beside it */
html.has-overlay { background: linear-gradient(var(--overlay), var(--overlay)), var(--bg); }
html.has-drawer { background: var(--surface-raised); }

.overlay {
  position: fixed; inset: 0; z-index: var(--z-overlay); display: flex; align-items: center; justify-content: center;
  padding: var(--space-6) var(--space-4);
}
.overlay-backdrop {
  position: absolute; inset: 0; background: var(--overlay);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  animation: fade-in var(--dur) var(--ease);
}
.modal {
  --modal-w: 560px;
  position: relative; display: flex; flex-direction: column; width: 100%; max-width: var(--modal-w);
  max-height: calc(100vh - 48px); max-height: calc(100dvh - 48px);
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg); animation: modal-in var(--dur) var(--ease); outline: none; overflow: hidden;
}
.modal-sm { --modal-w: 420px; }
.modal-md { --modal-w: 560px; }
.modal-lg { --modal-w: 760px; }
.modal-xl { --modal-w: 1040px; }
.modal-form { display: contents; }
.modal-header { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-5) var(--space-5) 0 var(--space-6); flex: none; }
.modal-heading { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--space-1); padding-top: 4px; }
.modal-title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); line-height: 1.3; }
.modal-description { color: var(--text-muted); font-size: var(--fs-base); }
.modal-close { margin: 0 -6px 0 0; }
.modal-icon {
  flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary-text);
}
.modal-icon.is-danger { background: var(--danger-soft); color: var(--danger-text); }
.modal-icon.is-warning { background: var(--warning-soft); color: var(--warning-text); }
.modal-icon.is-info { background: var(--info-soft); color: var(--info-text); }
.modal-body { padding: var(--space-4) var(--space-6) var(--space-6); overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-body > .callout + * { margin-top: var(--space-4); }
.modal-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); flex-wrap: wrap; flex: none;
  padding: var(--space-3) var(--space-6); border-top: 1px solid var(--border); background: var(--surface-2);
}
.modal-footer .footer-start { margin-right: auto; }
.modal.is-closing, .drawer.is-closing { animation: modal-out var(--dur-fast) var(--ease-in) forwards; }
.overlay.is-closing .overlay-backdrop { animation: fade-out var(--dur-fast) var(--ease-in) forwards; }
.modal-error { margin-bottom: var(--space-4); }
/* "Your session ended" for someone who signed in with Microsoft / Google (main.js externalRelogin) */
.relogin-wait:not(:empty) { display: flex; align-items: flex-start; gap: var(--space-2); margin-top: var(--space-3); font-size: var(--fs-sm); color: var(--text-muted); }
.relogin-wait .spinner { margin-top: 2px; }
.relogin-password { margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--border); }

@media (max-width: 640px) {
  .overlay { padding: var(--space-3); align-items: flex-end; }
  .modal { max-height: calc(100dvh - 24px); border-radius: var(--radius-lg); }
  .modal-header { padding: var(--space-4) var(--space-4) 0 var(--space-5); }
  .modal-body { padding: var(--space-4) var(--space-5) var(--space-5); }
  .modal-footer { padding: var(--space-3) var(--space-5); }
  .modal-footer .btn { flex: 1 1 auto; }
}

/* side drawer */
.overlay.is-drawer { justify-content: flex-end; align-items: stretch; padding: 0; }
.drawer {
  --drawer-w: 520px;
  position: relative; display: flex; flex-direction: column; width: 100%; max-width: var(--drawer-w); height: 100%;
  background: var(--surface-raised); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: drawer-in var(--dur-slow) var(--ease); outline: none;
}
.drawer-sm { --drawer-w: 400px; }
.drawer-md { --drawer-w: 520px; }
.drawer-lg { --drawer-w: 720px; }
.drawer-xl { --drawer-w: 960px; }
.drawer .modal-header { padding: var(--space-5) var(--space-5) var(--space-4) var(--space-6); border-bottom: 1px solid var(--border); }
.drawer .modal-body { padding: var(--space-5) var(--space-6); }
.drawer.is-closing { animation: drawer-out var(--dur) var(--ease-in) forwards; }
@media (max-width: 640px) {
  .drawer { max-width: 100%; }
  .drawer .modal-header { padding: var(--space-4) var(--space-4) var(--space-3) var(--space-5); }
  .drawer .modal-body { padding: var(--space-4) var(--space-5); }
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes modal-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(4px) scale(.99); } }
@keyframes drawer-in { from { transform: translateX(32px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes drawer-out { from { transform: none; opacity: 1; } to { transform: translateX(32px); opacity: 0; } }

/* dropdown menu */
.menu {
  position: fixed; z-index: var(--z-menu); min-width: 200px; max-width: min(320px, calc(100vw - 16px));
  padding: var(--space-1); background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); animation: menu-in var(--dur-fast) var(--ease);
  max-height: min(420px, calc(100vh - 16px)); overflow-y: auto;
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.menu-item {
  display: flex; align-items: center; gap: var(--space-2-5); width: 100%; min-height: 34px; padding: 0 var(--space-2-5);
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--text); font-size: var(--fs-base);
  text-align: left; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.menu-item .icon { width: 16px; height: 16px; color: var(--text-muted); }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-3); text-decoration: none; outline: none; }
.menu-item:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.menu-item.is-danger { color: var(--danger-text); }
.menu-item.is-danger .icon { color: var(--danger-text); }
.menu-item:disabled, .menu-item[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.menu-item-hint { margin-left: auto; padding-left: var(--space-4); font-size: var(--fs-xs); color: var(--text-subtle); }
/* long labels (names, file names) wrap instead of running out of the menu */
.menu-item { white-space: normal; padding-top: var(--space-1-5); padding-bottom: var(--space-1-5); line-height: var(--lh-snug); }
.menu-item > .icon { flex: none; }
.menu-item > span:not(.menu-item-hint) { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.menu-item-hint { flex: 0 1 auto; max-width: 45%; text-align: right; overflow-wrap: anywhere; }
.menu-sep { height: 1px; margin: var(--space-1) calc(-1 * var(--space-1)); background: var(--border); }
.menu-label { padding: var(--space-1-5) var(--space-2-5) var(--space-1); font-size: var(--fs-xs); font-weight: var(--fw-semibold); color: var(--text-subtle); }

/* ==========================================================================
   12. Toasts
   ========================================================================== */

.toast-region {
  position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: var(--z-toast);
  display: flex; flex-direction: column-reverse; gap: var(--space-2); width: min(400px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  background: var(--surface-raised); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); animation: toast-in var(--dur-slow) var(--ease); position: relative; overflow: hidden;
}
.toast::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--toast-c, var(--info)); }
.toast-icon { flex: none; color: var(--toast-c, var(--info)); margin-top: 1px; }
.toast-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding-top: 1px; }
.toast-title { font-weight: var(--fw-semibold); }
.toast-message { color: var(--text); overflow-wrap: anywhere; }
.toast-title + .toast-message { color: var(--text-muted); font-size: var(--fs-sm); }
.toast-actions { display: flex; gap: var(--space-2); margin-top: var(--space-2); }
.toast-close { margin: -4px -4px -4px 0; }
.toast-success { --toast-c: var(--success); }
.toast-error { --toast-c: var(--danger-text); }
.toast-warning { --toast-c: var(--warning); }
.toast-info { --toast-c: var(--info); }
.toast.is-leaving { animation: toast-out var(--dur) var(--ease-in) forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }
/* while a modal/drawer is open, toasts move to the top so they never cover its buttons */
html.has-overlay .toast-region { top: var(--space-4); bottom: auto; left: 50%; right: auto; transform: translateX(-50%); flex-direction: column; }
@media (min-width: 901px) {
  /* beside an open modal: bottom-left, in the space left of a centred 560px dialog */
  html.has-overlay .toast-region {
    top: auto; bottom: var(--space-5); left: var(--space-5); right: auto; transform: none; flex-direction: column-reverse;
    width: clamp(260px, calc((100vw - 560px) / 2 - 40px), 400px);
  }
  /* beside an open drawer: bottom-left, clear of the drawer's header and footer */
  html.has-drawer .toast-region { top: auto; bottom: var(--space-5); left: var(--space-5); transform: none; flex-direction: column-reverse; width: min(400px, calc(100vw - 600px)); }
}
@media (max-width: 640px) {
  .toast-region, html.has-overlay .toast-region {
    top: var(--space-2); bottom: auto; left: var(--space-3); right: var(--space-3); width: auto; transform: none; flex-direction: column;
  }
  .toast { animation-name: toast-in-top; }
  /* on a phone, toasts sit over the content: show only the newest two (one while a dialog is open) */
  .toast-region > .toast:nth-child(n+3), html.has-overlay .toast-region > .toast:nth-child(n+2) { display: none; }
}
@keyframes toast-in-top { from { opacity: 0; transform: translateY(-12px) scale(.98); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   13. Callouts, issue lists, empty states
   ========================================================================== */

.callout {
  --c-bg: var(--info-soft); --c-fg: var(--info-text); --c-bd: var(--info-border);
  display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4);
  background: var(--c-bg); border: 1px solid var(--c-bd); border-radius: var(--radius); color: var(--text);
}
.callout-icon { flex: none; color: var(--c-fg); margin-top: 1px; }
.callout-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.callout-title { font-weight: var(--fw-semibold); color: var(--c-fg); }
.callout-text { color: var(--text); overflow-wrap: anywhere; }
.callout-text a { color: inherit; text-decoration: underline; }
.callout-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
.callout-aside { flex: none; align-self: center; display: flex; gap: var(--space-2); }
.callout-close { margin: -4px -6px -4px 0; }
.callout-success { --c-bg: var(--success-soft); --c-fg: var(--success-text); --c-bd: var(--success-border); }
.callout-warning { --c-bg: var(--warning-soft); --c-fg: var(--warning-text); --c-bd: var(--warning-border); }
.callout-danger { --c-bg: var(--danger-soft); --c-fg: var(--danger-text); --c-bd: var(--danger-border); }
.callout-neutral { --c-bg: var(--surface-2); --c-fg: var(--text-muted); --c-bd: var(--border); }
.callout-primary { --c-bg: var(--primary-soft); --c-fg: var(--primary-soft-text); --c-bd: var(--primary-border); }
@media (max-width: 640px) { .callout { flex-wrap: wrap; } .callout-aside { width: 100%; padding-left: 32px; } }

.issue-box { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden; }
.issue-box.has-errors { border-color: var(--danger-border); }
.issue-head {
  display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; padding: var(--space-3) var(--space-4);
  background: var(--surface-2); border-bottom: 1px solid var(--border); font-weight: var(--fw-semibold);
}
.issue-box.has-errors .issue-head { background: var(--danger-soft); border-bottom-color: var(--danger-border); color: var(--danger-text); }
.issue-box.has-warnings:not(.has-errors) { border-color: var(--warning-border); }
.issue-box.has-warnings:not(.has-errors) .issue-head { background: var(--warning-soft); border-bottom-color: var(--warning-border); color: var(--warning-text); }
.issue-head .badge { margin-left: auto; }
.issue-list { list-style: none; margin: 0; padding: 0; max-height: var(--issue-max-h, 320px); overflow-y: auto; }
.issue {
  display: flex; align-items: flex-start; gap: var(--space-2-5); width: 100%; padding: var(--space-2-5) var(--space-4);
  border: 0; border-bottom: 1px solid var(--border-subtle); background: none; text-align: left; color: var(--text);
  font-size: var(--fs-base); line-height: 1.45;
}
.issue-list > li:last-child > .issue { border-bottom: 0; }
.issue-icon { flex: none; margin-top: 1px; width: 18px; height: 18px; }
.issue.is-error .issue-icon { color: var(--danger-text); }
.issue.is-warning .issue-icon { color: var(--warning); }
.issue.is-info .issue-icon { color: var(--info); }
.issue-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.issue-where {
  flex: none; font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--text-muted); background: var(--surface-3);
  border-radius: var(--radius-xs); padding: 1px 6px; margin-top: 1px; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.issue-go { flex: none; color: var(--text-subtle); margin-top: 1px; width: 16px; height: 16px; }
button.issue { cursor: pointer; }
button.issue:hover { background: var(--surface-3); }
button.issue:hover .issue-go { color: var(--text); }
button.issue:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; border-radius: 0; }
.issue-more { padding: var(--space-2) var(--space-4); font-size: var(--fs-sm); color: var(--text-muted); border-top: 1px solid var(--border-subtle); }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  gap: var(--space-2); padding: var(--space-12) var(--space-6); color: var(--text-muted);
}
.empty-icon {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: var(--radius-lg); margin-bottom: var(--space-2);
  background: var(--surface-3); color: var(--text-muted); border: 1px solid var(--border-subtle);
}
.empty-icon .icon { width: 24px; height: 24px; }
.empty-state.is-primary .empty-icon { background: var(--primary-soft); color: var(--primary-text); border-color: var(--primary-border); }
.empty-state.is-danger .empty-icon { background: var(--danger-soft); color: var(--danger-text); border-color: var(--danger-border); }
.empty-state.is-warning .empty-icon { background: var(--warning-soft); color: var(--warning-text); border-color: var(--warning-border); }
.empty-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text); }
.empty-text { max-width: 44ch; }
.empty-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; justify-content: center; margin-top: var(--space-3); }
.empty-state.is-compact { padding: var(--space-8) var(--space-4); }
.empty-state.is-compact .empty-icon { width: 40px; height: 40px; }
.card > .empty-state, .card-body > .empty-state:only-child { padding-top: var(--space-10); padding-bottom: var(--space-10); }

/* ==========================================================================
   14. Loading: skeletons, spinner, progress
   ========================================================================== */

.skeleton {
  display: block; border-radius: var(--radius-sm); min-height: 12px;
  background: linear-gradient(90deg, var(--skeleton) 0%, var(--skeleton) 40%, var(--skeleton-shine) 50%, var(--skeleton) 60%, var(--skeleton) 100%);
  background-size: 300% 100%; animation: shimmer 1.6s linear infinite;
}
.skeleton-text { height: 12px; margin: 4px 0; }
.skeleton-title { height: 20px; width: 40%; }
.skeleton-circle { border-radius: 50%; }
.skeleton-pill { border-radius: var(--radius-full); height: 22px; width: 120px; }
.skeleton-lines { display: flex; flex-direction: column; gap: var(--space-2); }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -50% 0; } }

.spinner {
  display: inline-block; flex: none; width: 20px; height: 20px; border-radius: 50%; vertical-align: middle;
  border: 2px solid currentColor; border-right-color: transparent; color: var(--primary-text);
  animation: spin .7s linear infinite; opacity: .9;
}
.spinner-sm { width: 14px; height: 14px; border-width: 2px; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }
.spinner-muted { color: var(--text-subtle); }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--text-muted); font-size: var(--fs-sm); }
.loading-block { display: flex; align-items: center; justify-content: center; gap: var(--space-3); padding: var(--space-12) var(--space-4); color: var(--text-muted); }

.progress { position: relative; height: 6px; border-radius: var(--radius-full); background: var(--surface-3); overflow: hidden; }
.progress-bar { position: absolute; inset: 0 auto 0 0; width: var(--value, 0%); border-radius: inherit; background: var(--primary); transition: width var(--dur-slow) var(--ease); }
.progress.is-indeterminate .progress-bar { width: 35%; animation: indeterminate 1.3s var(--ease) infinite; }
.progress-accent .progress-bar { background: var(--accent); }
@keyframes indeterminate { from { left: -35%; } to { left: 100%; } }

/* ==========================================================================
   15. Dropzone, period picker
   ========================================================================== */

.dropzone {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-2);
  padding: var(--space-8) var(--space-6); text-align: center; cursor: pointer;
  border: 1.5px dashed var(--border-input); border-radius: var(--radius-lg); background: var(--surface-2);
  color: var(--text-muted); transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.dropzone:hover { border-color: var(--primary-text); background: var(--surface); }
.dropzone:has(.dropzone-input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
@supports not selector(:has(a)) {
  .dropzone:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
}
.dropzone.is-dragover { border-color: var(--primary-text); border-style: solid; background: var(--primary-soft); }
.dropzone.is-busy { cursor: progress; }
.dropzone.is-disabled { cursor: not-allowed; opacity: .6; }
.dropzone.is-invalid { border-color: var(--danger-text); }
.dropzone-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: inherit; }
.dropzone-input::-webkit-file-upload-button { cursor: pointer; }
.dropzone-icon {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; margin-bottom: var(--space-1);
  background: var(--surface); color: var(--primary-text); border: 1px solid var(--border); box-shadow: var(--shadow-xs);
}
.dropzone.is-dragover .dropzone-icon { border-color: var(--primary-border); }
.dropzone-label { color: var(--text); font-weight: var(--fw-medium); }
.dropzone-label .dropzone-browse { color: var(--primary-text); text-decoration: underline; text-underline-offset: 2px; }
.dropzone-hint { font-size: var(--fs-sm); }
.dropzone-error { font-size: var(--fs-sm); color: var(--danger-text); font-weight: var(--fw-medium); }
.dropzone-compact { flex-direction: row; padding: var(--space-4) var(--space-5); gap: var(--space-3); text-align: left; justify-content: flex-start; }
.dropzone-compact .dropzone-icon { margin: 0; width: 36px; height: 36px; }
.dropzone-compact .dropzone-text { display: flex; flex-direction: column; gap: 2px; }

.period-picker {
  display: inline-flex; align-items: stretch; align-self: flex-start; width: max-content; height: var(--control-h); border: 1px solid var(--border-strong);
  border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-xs); max-width: 100%;
}
.period-picker > .btn {
  height: 100%; --btn-h: calc(var(--control-h) - 2px); width: 34px; border: 0; border-radius: 0; box-shadow: none; background: transparent;
  color: var(--text-muted);
}
.period-picker > .btn:hover { background: var(--surface-3); color: var(--text); }
.period-picker > .btn:first-child { border-radius: calc(var(--radius) - 1px) 0 0 calc(var(--radius) - 1px); border-right: 1px solid var(--border); }
.period-picker > .btn:last-child { border-radius: 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0; border-left: 1px solid var(--border); }
.period-picker > .btn:focus-visible { outline-offset: -2px; z-index: 1; }
.period-picker .select {
  height: 100%; border: 0; border-radius: 0; box-shadow: none; background-color: transparent; font-weight: var(--fw-medium);
  padding-left: var(--space-3); width: auto; min-width: 0;
}
.period-picker .select:hover { background-color: var(--surface-3); }
.period-picker .select:focus { box-shadow: none; }
.period-picker .select:focus-visible { box-shadow: inset 0 0 0 2px var(--focus); }
.period-picker .pp-month { min-width: 128px; }
.period-picker .pp-year { min-width: 84px; border-left: 1px solid var(--border); }
.period-picker-sm { height: var(--control-h-sm); }
.period-picker-sm .select { font-size: var(--fs-sm); }
.period-picker-sm > .btn { width: 28px; }
.period-picker-sm .pp-month { min-width: 112px; }

/* ==========================================================================
   15b. Forced colours (Windows contrast themes): the system replaces backgrounds and drops shadows,
        so states drawn with them get system colours, borders or outlines here
   ========================================================================== */

@media (forced-colors: active) {
  /* native boxes draw the tick / dot in system colours */
  .checkbox, .radio { appearance: auto; -webkit-appearance: auto; }

  .switch-track { border: 1px solid CanvasText; }
  .switch-track::after { forced-color-adjust: none; background: CanvasText; box-shadow: none; top: 1px; left: 1px; }
  .switch-input:checked + .switch-track { forced-color-adjust: none; background: Highlight; border-color: Highlight; }
  .switch-input:checked + .switch-track::after { background: HighlightText; }
  .switch-input:disabled + .switch-track { border-color: GrayText; }

  .segmented-item input:checked + span { forced-color-adjust: none; background: Highlight; color: HighlightText; }
  .nav-link[aria-current="page"] { forced-color-adjust: none; background: Highlight; color: HighlightText; }
  .nav-link[aria-current="page"] .icon { color: HighlightText; }
  .radio-card.is-checked { outline: 2px solid Highlight; outline-offset: -2px; }
  .radio-card:has(.radio:checked) { outline: 2px solid Highlight; outline-offset: -2px; }

  /* focus drawn with box-shadow elsewhere */
  .input:focus-visible, .select:focus-visible, .textarea:focus-visible,
  .input-group:focus-within, .chips-input:focus-within { outline: 2px solid Highlight; outline-offset: 1px; }
  .input-group > .input:focus-visible { outline: none; }
  .menu .menu-item:focus-visible, .period-picker .select:focus-visible { outline: 2px solid Highlight; outline-offset: -2px; }
  .btn-provider { border-color: ButtonText; }
}

/* ==========================================================================
   16. Print: hide the app chrome
   ========================================================================== */

@media print {
  :root { --bg: #fff; --surface: #fff; }
  html, body { background: #fff !important; }
  .sidebar, .topbar, .nav-backdrop, .toast-region, .overlay, .menu, .skip-link,
  .page-actions, .no-print, .btn, .tabs { display: none !important; }
  .app-shell { display: block; }
  .app-shell::before { display: none; }
  .main-inner { padding: 0; max-width: none; }
  .card, .tile, .table-wrap { box-shadow: none; break-inside: avoid; }
  .table-wrap { overflow: visible; max-height: none; }
  .table thead th { position: static; }
  a { color: inherit; text-decoration: none; }
}

/* ==========================================================================
   17. Motion preferences
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important; animation-iteration-count: 1 !important;
    transition-duration: 1ms !important; scroll-behavior: auto !important;
  }
  .skeleton { animation: none; background: var(--skeleton); }
  .spinner { animation: spin 1.2s linear infinite !important; animation-iteration-count: infinite !important; animation-duration: 1.2s !important; }
  .dot-pulse::after { display: none; }
}
