/* Shared design system for all services. Light theme by default, dark via <html data-theme> (ui/theme.js); left sidebar, card layout. */
:root {
  color-scheme: light;
  --bg: #f3f5fb;
  --sidebar-c: #ffffff;
  --panel-c: #ffffff;
  --panel-2: #f7f8fc;
  --line: #e4e7f0;
  --text: #1d2233;
  --text-2: #4d5469;
  --muted: #7a8197;
  --accent: #2a78d6;          /* Single-series chart color (dataviz-checked, >=3:1 on light) */
  --accent-strong: #1f64b8;
  --accent-soft: #e8f1fc;
  --good: #0ca30c;
  --good-ink: #0a7a0a;
  --good-soft: #e7f6e7;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --warn-soft: #fff4dc;
  --crit: #d03b3b;
  --crit-soft: #fdeceb;
  --good-solid: #0a7a0a;
  --line-strong: #b9c2d8;
  --line-dashed: #cfd4e2;
  --hover: #eceff6;
  --sunken: #e9ecf5;
  --faint: #b3b8c7;
  --weekend: #b44a4a;
  --crit-line: #f3c7c5;
  --good-line: #a9d8a9;
  --warn-line: #f1d9a6;
  --warn-faint: #fffaf0;
  --accent-line: #cfe0f7;
  --glow-1: #dfe8fb;
  --glow-2: #e6ecfa;
  --tooltip: #1d2233;
  --shadow-rgb: 29 34 51;
  --shadow: 0 1px 2px rgb(var(--shadow-rgb) / 5%), 0 6px 20px rgb(var(--shadow-rgb) / 6%);
  --radius: 14px;
  /* Motion: 120ms feedback, 200ms state changes, 320ms dialogs/layout; decelerating enter, faster exit. --rise is the enter lift (0 under reduced motion). */
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-in: cubic-bezier(.4, 0, 1, 1);
  --dur-fast: 120ms;
  --dur: 200ms;
  --dur-slow: 320ms;
  --rise: 8px;
  --intro-blur: 12px;
  --pop: .97;
  /* Default themes for custom backgrounds (ui/theme.js sets <html data-bg>) */
  --serif: "Noto Serif TC", "Noto Serif CJK TC", "Source Han Serif TC", "Songti TC", "PMingLiU", serif;
  /* Style thumbnails (appearance settings); fixed so they stay distinguishable under any data-style */
  --stp-default: linear-gradient(#2a78d6, #2a78d6) 46% 30% / 36% 8px no-repeat, linear-gradient(#ffffff, #ffffff) 50% 70% / 50% 26px no-repeat, linear-gradient(90deg, #ffffff 0 26%, #e4e7f0 26% calc(26% + 1px), #f3f5fb 0);
  --stp-japandi: linear-gradient(#8a5a3c, #8a5a3c) 46% 30% / 36% 8px no-repeat, linear-gradient(#fbf8f3, #fbf8f3) 50% 70% / 50% 26px no-repeat, linear-gradient(90deg, #f8f4ee 0 26%, #e3dace 26% calc(26% + 1px), #f3eee6 0);
  --stp-glass: linear-gradient(#ffffff, #ffffff) 46% 30% / 36% 8px no-repeat, linear-gradient(rgb(255 255 255 / 55%), rgb(255 255 255 / 55%)) 50% 70% / 50% 26px no-repeat, linear-gradient(180deg, #7a5638 0 16%, #e4d8c9 16% 76%, #b88a62 76%);
  --stp-industry: linear-gradient(#1d5fbf, #1d5fbf) 46% 30% / 36% 8px no-repeat, linear-gradient(#ffffff, #ffffff) 50% 70% / 50% 26px no-repeat, linear-gradient(180deg, #1d3557 0 16%, #edf2f8 16% 76%, #b8c6d8 76%);
  --bgp-aurora: radial-gradient(at 12% 18%, #c6efe0 0, transparent 48%), radial-gradient(at 88% 8%, #d6d8ff 0, transparent 44%), radial-gradient(at 62% 92%, #f1d9ff 0, transparent 50%), #eef3fb;
  --bgp-sunset: linear-gradient(160deg, #ffe0c4 0%, #ffd0d9 48%, #e4dcff 100%);
  --bgp-ocean: linear-gradient(180deg, #dcf1ff 0%, #cde3fb 55%, #e6efff 100%);
  --bgp-forest: linear-gradient(160deg, #e1f3df 0%, #d2eadb 50%, #eef6e6 100%);
  --bgp-sakura: radial-gradient(at 18% 14%, #ffd6e4 0, transparent 48%), radial-gradient(at 82% 82%, #ffe6ee 0, transparent 55%), #fff5f8;
  --bgp-starry: radial-gradient(at 50% 0%, #e3e1fb 0, transparent 60%), linear-gradient(180deg, #e6e9f7 0%, #f1eff9 100%);
}

/* Dark: blue-grey, not pure black; accent lightened to keep >=3:1 on dark and >=4:1 with white text */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #12161f;
  --sidebar-c: #171c27;
  --panel-c: #1b2130;
  --panel-2: #222939;
  --line: #2e3648;
  --text: #e5e8f0;
  --text-2: #b6bccb;
  --muted: #8b92a6;
  --accent: #3b84de;
  --accent-strong: #7fb2f0;
  --accent-soft: #1d304d;
  --good: #3cb93c;
  --good-ink: #72d072;
  --good-soft: #193323;
  --warn: #fab219;
  --warn-ink: #f0c561;
  --warn-soft: #3a2f16;
  --crit: #ec6461;
  --crit-soft: #3d2024;
  --good-solid: #1f8a2a;
  --line-strong: #4a5570;
  --line-dashed: #44506a;
  --hover: #283043;
  --sunken: #151a25;
  --faint: #576078;
  --weekend: #e98585;
  --crit-line: #6b3236;
  --good-line: #2f6b3a;
  --warn-line: #6e5626;
  --warn-faint: #2a2618;
  --accent-line: #2c4a75;
  --glow-1: #1b2742;
  --glow-2: #19223a;
  --tooltip: #39425a;
  --shadow-rgb: 0 0 0;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 20px rgb(0 0 0 / 25%);
  --stp-default: linear-gradient(#3b84de, #3b84de) 46% 30% / 36% 8px no-repeat, linear-gradient(#1b2130, #1b2130) 50% 70% / 50% 26px no-repeat, linear-gradient(90deg, #171c27 0 26%, #2e3648 26% calc(26% + 1px), #12161f 0);
  --stp-japandi: linear-gradient(#9a6a49, #9a6a49) 46% 30% / 36% 8px no-repeat, linear-gradient(#272420, #272420) 50% 70% / 50% 26px no-repeat, linear-gradient(90deg, #22201c 0 26%, #3b3630 26% calc(26% + 1px), #1d1b18 0);
  --stp-glass: linear-gradient(#ece4da, #ece4da) 46% 30% / 36% 8px no-repeat, linear-gradient(rgb(255 255 255 / 16%), rgb(255 255 255 / 16%)) 50% 70% / 50% 26px no-repeat, linear-gradient(180deg, #2e2018 0 16%, #4a3c31 16% 76%, #5e4231 76%);
  --stp-industry: linear-gradient(#2f74d6, #2f74d6) 46% 30% / 36% 8px no-repeat, linear-gradient(#18222f, #18222f) 50% 70% / 50% 26px no-repeat, linear-gradient(180deg, #0a111b 0 16%, #131c28 16% 76%, #24344a 76%);
  --bgp-aurora: radial-gradient(at 12% 18%, #0f3a33 0, transparent 50%), radial-gradient(at 88% 8%, #232867 0, transparent 46%), radial-gradient(at 62% 92%, #3a1b52 0, transparent 52%), #0f1420;
  --bgp-sunset: linear-gradient(160deg, #3d2028 0%, #2b1c3e 50%, #131a32 100%);
  --bgp-ocean: linear-gradient(180deg, #0a2539 0%, #0d1d35 55%, #0a1322 100%);
  --bgp-forest: linear-gradient(160deg, #11281d 0%, #12231d 50%, #0e1613 100%);
  --bgp-sakura: radial-gradient(at 18% 14%, #3d1a2b 0, transparent 50%), radial-gradient(at 82% 82%, #2c1726 0, transparent 55%), #171218;
  --bgp-starry: radial-gradient(1.5px 1.5px at 12% 22%, #fff9 50%, transparent 51%), radial-gradient(1px 1px at 34% 68%, #fff8 50%, transparent 51%), radial-gradient(1.5px 1.5px at 58% 14%, #fffa 50%, transparent 51%), radial-gradient(1px 1px at 76% 46%, #fff8 50%, transparent 51%), radial-gradient(1.5px 1.5px at 90% 80%, #fff9 50%, transparent 51%), radial-gradient(1px 1px at 22% 88%, #fff7 50%, transparent 51%), radial-gradient(at 50% 0%, #1c2350 0, transparent 60%), linear-gradient(180deg, #0b1024 0%, #0e1328 100%);
}

/* Japandi style (chosen in me's appearance settings; ui/theme.js sets <html data-style="japandi">): linen + walnut + charcoal + moss, minimal shadows, thin borders, small radii */
:root[data-style="japandi"] {
  --bg: #f3eee6;
  --sidebar-c: #f8f4ee;
  --panel-c: #fbf8f3;
  --panel-2: #f2ece3;
  --line: #e3dace;
  --text: #2b2723;
  --text-2: #57504a;
  --muted: #8a8177;
  --accent: #8a5a3c;
  --accent-strong: #6f4529;
  --accent-soft: #f0e4d7;
  --good: #5f7f45;
  --good-ink: #4a6833;
  --good-soft: #e9eee1;
  --warn: #c9952e;
  --warn-ink: #7a5414;
  --warn-soft: #f6ecd8;
  --crit: #b0453a;
  --crit-soft: #f6e5e1;
  --good-solid: #4a6833;
  --line-strong: #c9bba8;
  --line-dashed: #d6cab9;
  --hover: #efe8de;
  --sunken: #ebe4d9;
  --faint: #b9aea1;
  --weekend: #a8493c;
  --crit-line: #e5bdb5;
  --good-line: #c5d3b4;
  --warn-line: #e6d2a8;
  --warn-faint: #faf5ea;
  --accent-line: #ddc8b3;
  --glow-1: #efe7dc;
  --glow-2: #f0eadf;
  --tooltip: #3b3631;
  --shadow-rgb: 60 48 36;
  --shadow: 0 1px 0 rgb(var(--shadow-rgb) / 4%);
  --radius: 10px;
  --rise: 4px;
  --intro-blur: 6px;
}
:root[data-style="japandi"][data-theme="dark"] {
  --bg: #1d1b18;
  --sidebar-c: #22201c;
  --panel-c: #272420;
  --panel-2: #2f2b26;
  --line: #3b3630;
  --text: #ebe5db;
  --text-2: #c2b9ac;
  --muted: #958b7e;
  --accent: #9a6a49;
  --accent-strong: #d6a982;
  --accent-soft: #3a2d23;
  --good: #7fa25f;
  --good-ink: #9cbf7c;
  --good-soft: #2a3122;
  --warn: #d6a645;
  --warn-ink: #e3bf73;
  --warn-soft: #3a301c;
  --crit: #d77a6c;
  --crit-soft: #3a2622;
  --good-solid: #5a7a3e;
  --line-strong: #5a5248;
  --line-dashed: #4e473f;
  --hover: #322e28;
  --sunken: #34302a;
  --faint: #645c52;
  --weekend: #d98f80;
  --crit-line: #63352d;
  --good-line: #3e5230;
  --warn-line: #66512a;
  --warn-faint: #2a251b;
  --accent-line: #5c4535;
  --glow-1: #26221d;
  --glow-2: #231f1b;
  --tooltip: #3e3832;
  --shadow-rgb: 0 0 0;
  --shadow: 0 1px 0 rgb(0 0 0 / 18%);
}
:root[data-style="japandi"] :is(h1, h2) { font-family: var(--serif); font-weight: 600; letter-spacing: .02em; }

/* Glass style: blurred warm interior photo as background, one big frosted panel, brighter translucent cards, dark pill primary buttons */
:root[data-style="glass"] {
  --bg: #d8ccbd;
  --sidebar-c: rgb(250 246 240 / 55%);
  --panel-c: rgb(255 253 250 / 66%);
  --panel-2: rgb(255 255 255 / 38%);
  --line: rgb(70 52 36 / 13%);
  --line-strong: rgb(70 52 36 / 26%);
  --line-dashed: rgb(70 52 36 / 20%);
  --text: #1c1916;
  --text-2: #4a423b;
  --muted: #7b7067;
  --faint: #b3a89c;
  --accent: #1f1c1a;
  --accent-strong: #1f1c1a;
  --accent-soft: rgb(255 255 255 / 88%);
  --accent-line: rgb(255 255 255 / 70%);
  --hover: rgb(255 255 255 / 45%);
  --sunken: rgb(60 45 30 / 8%);
  --glow-1: rgb(255 255 255 / 30%);
  --glow-2: rgb(255 240 222 / 24%);
  --tooltip: #1f1c1a;
  --shadow-rgb: 60 40 20;
  --shadow: 0 1px 0 rgb(255 255 255 / 55%) inset, 0 10px 30px rgb(60 40 20 / 10%);
  --radius: 20px;
  --glass-sheet-c: rgb(255 250 244 / 32%);
  --glass-bar-c: rgb(255 250 244 / 52%);
  --glass-btn-c: rgb(255 255 255 / 85%);
  --glass-edge: rgb(255 255 255 / 55%);
  --glass-blur-c: 28px;
}
:root[data-style="glass"][data-theme="dark"] {
  --bg: #2a221c;
  --sidebar-c: rgb(30 25 21 / 55%);
  --panel-c: rgb(36 30 26 / 70%);
  --panel-2: rgb(255 255 255 / 7%);
  --line: rgb(255 240 225 / 12%);
  --line-strong: rgb(255 240 225 / 24%);
  --line-dashed: rgb(255 240 225 / 18%);
  --text: #f1ebe4;
  --text-2: #cfc5ba;
  --muted: #9d9287;
  --faint: #6a6058;
  --accent: #6b5646;
  --accent-strong: #f1ebe4;
  --accent-soft: rgb(255 255 255 / 16%);
  --accent-line: rgb(255 255 255 / 22%);
  --hover: rgb(255 255 255 / 8%);
  --sunken: rgb(0 0 0 / 22%);
  --glow-1: rgb(255 220 180 / 6%);
  --glow-2: rgb(255 200 150 / 4%);
  --tooltip: #3e352e;
  --shadow-rgb: 0 0 0;
  --shadow: 0 1px 0 rgb(255 255 255 / 6%) inset, 0 10px 30px rgb(0 0 0 / 30%);
  --glass-sheet-c: rgb(28 22 18 / 38%);
  --glass-bar-c: rgb(32 26 22 / 55%);
  --glass-btn-c: rgb(255 255 255 / 12%);
  --glass-edge: rgb(255 255 255 / 12%);
}
/* Background: gradients composing a blurred warm room; a user custom background (data-bg) replaces it */
:root[data-style="glass"]:not([data-bg])::before {
  content: ""; position: fixed; inset: -60px; z-index: -1; pointer-events: none; filter: blur(18px);
  background:
    radial-gradient(12% 20% at 4% 88%, #3a2c22 0, transparent 72%),
    linear-gradient(#6b4630, #4e3222) 10% 0 / 22% 13% no-repeat,
    linear-gradient(#6b4630, #4e3222) 86% 0 / 24% 13% no-repeat,
    radial-gradient(38% 34% at 60% 36%, rgb(255 238 210 / 90%) 0, transparent 70%),
    radial-gradient(16% 46% at 97% 42%, #f6f0e7 0, transparent 72%),
    linear-gradient(90deg, #4a3e36 0 4%, transparent 9%),
    linear-gradient(180deg, transparent 78%, #b8875e 80%, #94643f 100%),
    linear-gradient(180deg, #e8ddd0, #d9cbba);
}
:root[data-style="glass"][data-theme="dark"]:not([data-bg])::before {
  background:
    radial-gradient(12% 20% at 4% 88%, #110c09 0, transparent 72%),
    linear-gradient(#2e1f15, #20150e) 10% 0 / 22% 13% no-repeat,
    linear-gradient(#2e1f15, #20150e) 86% 0 / 24% 13% no-repeat,
    radial-gradient(38% 34% at 60% 36%, rgb(255 176 104 / 32%) 0, transparent 70%),
    radial-gradient(16% 46% at 97% 42%, #4a3a2e 0, transparent 72%),
    linear-gradient(90deg, #17110d 0 4%, transparent 9%),
    linear-gradient(180deg, transparent 78%, #4a3222 80%, #33221a 100%),
    linear-gradient(180deg, #3a2f27, #29211b);
}

/* Industry style: glass layout in blue-white steel, blueprint grid background, steel-blue accent, tighter radii, square pills (ui/theme.js sets data-style="glass" + a flag) */
:root[data-style="glass"][data-glass="industry"] {
  --bg: #e4eaf2;
  --sidebar-c: rgb(255 255 255 / 72%);
  --panel-c: rgb(255 255 255 / 86%);
  --panel-2: rgb(240 245 251 / 80%);
  --line: rgb(30 55 90 / 12%);
  --line-strong: rgb(30 55 90 / 26%);
  --line-dashed: rgb(30 55 90 / 20%);
  --text: #0f1b2d;
  --text-2: #3a4a60;
  --muted: #5b6a80;
  --faint: #a9b5c5;
  --accent: #1d5fbf;
  --accent-strong: #154a99;
  --accent-soft: #e2ecfa;
  --accent-line: #bcd2f1;
  --hover: rgb(29 95 191 / 7%);
  --sunken: rgb(30 55 90 / 7%);
  --glow-1: rgb(255 255 255 / 40%);
  --glow-2: rgb(190 215 250 / 24%);
  --tooltip: #0f1b2d;
  --shadow-rgb: 20 40 70;
  --shadow: 0 1px 0 rgb(255 255 255 / 70%) inset, 0 8px 24px rgb(20 40 70 / 9%);
  --radius: 10px;
  --glass-sheet-c: rgb(248 251 255 / 46%);
  --glass-bar-c: rgb(255 255 255 / 70%);
  --glass-btn-c: #ffffff;
  --glass-edge: rgb(255 255 255 / 80%);
  --glass-blur-c: 22px;
}
:root[data-style="glass"][data-glass="industry"][data-theme="dark"] {
  --bg: #0d141e;
  --sidebar-c: rgb(17 25 36 / 70%);
  --panel-c: rgb(22 32 46 / 78%);
  --panel-2: rgb(255 255 255 / 5%);
  --line: rgb(170 200 240 / 12%);
  --line-strong: rgb(170 200 240 / 24%);
  --line-dashed: rgb(170 200 240 / 18%);
  --text: #e6edf6;
  --text-2: #b4c1d2;
  --muted: #8494aa;
  --faint: #536177;
  --accent: #2a6cc9;
  --accent-strong: #9cc3f5;
  --accent-soft: rgb(80 140 230 / 20%);
  --accent-line: rgb(120 170 240 / 30%);
  --hover: rgb(150 190 240 / 8%);
  --sunken: rgb(0 0 0 / 25%);
  --glow-1: rgb(80 140 230 / 8%);
  --glow-2: rgb(60 110 200 / 6%);
  --tooltip: #24344a;
  --shadow-rgb: 0 0 0;
  --shadow: 0 1px 0 rgb(255 255 255 / 5%) inset, 0 8px 24px rgb(0 0 0 / 35%);
  --glass-sheet-c: rgb(14 22 33 / 42%);
  --glass-bar-c: rgb(18 27 39 / 66%);
  --glass-btn-c: rgb(255 255 255 / 9%);
  --glass-edge: rgb(170 200 240 / 14%);
}
/* Blueprint grid background (32px fine, 160px coarse); no blur so the grid stays crisp */
:root[data-style="glass"][data-glass="industry"]:not([data-bg])::before {
  inset: 0; filter: none;
  background:
    linear-gradient(rgb(29 95 191 / 9%) 1px, transparent 1px) 0 0 / 160px 160px,
    linear-gradient(90deg, rgb(29 95 191 / 9%) 1px, transparent 1px) 0 0 / 160px 160px,
    linear-gradient(rgb(29 95 191 / 5%) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, rgb(29 95 191 / 5%) 1px, transparent 1px) 0 0 / 32px 32px,
    radial-gradient(45% 40% at 22% 12%, rgb(255 255 255 / 95%) 0, transparent 70%),
    radial-gradient(40% 45% at 92% 96%, rgb(120 160 225 / 38%) 0, transparent 70%),
    linear-gradient(160deg, #f1f5fa, #dce5f0);
}
:root[data-style="glass"][data-glass="industry"][data-theme="dark"]:not([data-bg])::before {
  background:
    linear-gradient(rgb(120 170 240 / 8%) 1px, transparent 1px) 0 0 / 160px 160px,
    linear-gradient(90deg, rgb(120 170 240 / 8%) 1px, transparent 1px) 0 0 / 160px 160px,
    linear-gradient(rgb(120 170 240 / 4%) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, rgb(120 170 240 / 4%) 1px, transparent 1px) 0 0 / 32px 32px,
    radial-gradient(45% 40% at 22% 12%, rgb(60 110 190 / 22%) 0, transparent 70%),
    radial-gradient(40% 45% at 92% 96%, rgb(40 80 150 / 26%) 0, transparent 70%),
    linear-gradient(160deg, #111a26, #0a1018);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14.5px/1.55 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; }
h1 { font-size: 22px; margin: 0 0 2px; letter-spacing: -.01em; }
h2 { font-size: 15.5px; margin: 0 0 2px; }
p { margin: 0; }
a { color: var(--accent-strong); }
svg { fill: currentColor; }

/* Sidebar width: --side-open = user-dragged width (theme.js applies it from localStorage before first paint), --side-w = actual width */
:root { --side-w: var(--side-open, 248px); }
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
/* Grid children default to min-width:auto and get stretched by content (nav bar, long URLs), overflowing on mobile */
.shell > * { min-width: 0; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  padding: 20px 14px; background: var(--sidebar); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
/* Sidebar logo: dark-text brand-logo.png on light, white-text brand-logo-dark.png on dark; square brand-mark on narrow screens */
.brand-logo { display: block; padding: 0 2px; text-decoration: none; }
.brand-logo img { display: block; width: 100%; height: auto; }
.brand-logo .logo-mark, .brand-logo .logo-dark { display: none; }
:root[data-theme="dark"] .brand-logo .logo-wide.logo-dark { display: block; }
:root[data-theme="dark"] .brand-logo .logo-light { display: none; }
.logo {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #4f6ef7, #2a78d6); color: #fff; font-weight: 800; font-size: 18px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
/* Only the nav scrolls when there are many links; logo, cards and user row stay fixed */
.sidebar > .nav {
  flex: 1 1 auto; min-height: 140px; overflow-y: auto; overscroll-behavior: contain;
  margin: 0 -6px; padding: 0 6px; scrollbar-width: none;
}
/* No scrollbar; wheel/touch still scroll, the edge fade below hints it */
.sidebar > .nav::-webkit-scrollbar { display: none; }
.sidebar > :not(.nav) { flex-shrink: 0; }
/* Edge fade hints more content above/below (ui/sidebar.js toggles .more-above / .more-below) */
.sidebar > .nav.more-below { mask-image: linear-gradient(to bottom, #000 calc(100% - 32px), transparent); }
.sidebar > .nav.more-above { mask-image: linear-gradient(to top, #000 calc(100% - 32px), transparent); }
.sidebar > .nav.more-above.more-below { mask-image: linear-gradient(to bottom, transparent, #000 32px, #000 calc(100% - 32px), transparent); }
/* On very short windows the whole sidebar scrolls */
.sidebar { overflow-y: auto; scrollbar-width: none; }
.sidebar::-webkit-scrollbar { display: none; }

/* Custom background: ui/theme.js sets <html data-bg> from cookie nbbg, with --ubg-image / --ubg-dim / --ubg-blur */
:root[data-bg]::before, :root[data-bg]::after { content: ""; position: fixed; z-index: -1; pointer-events: none; }
:root[data-bg]::before {
  inset: calc(var(--ubg-blur, 0px) * -2);    /* Drawn oversized so blur doesn't reveal the edge color */
  background: var(--ubg-image, none) center / cover no-repeat; filter: blur(var(--ubg-blur, 0px));
}
:root[data-bg]::after { inset: 0; background: var(--bg); opacity: var(--ubg-dim, 0); }
:root[data-bg="aurora"] { --ubg-image: var(--bgp-aurora); }
:root[data-bg="sunset"] { --ubg-image: var(--bgp-sunset); }
:root[data-bg="ocean"] { --ubg-image: var(--bgp-ocean); }
:root[data-bg="forest"] { --ubg-image: var(--bgp-forest); }
:root[data-bg="sakura"] { --ubg-image: var(--bgp-sakura); }
:root[data-bg="starry"] { --ubg-image: var(--bgp-starry); }
/* Halo behind header text placed directly on the background so it stays readable at low dim */
:root[data-bg] .page-head { text-shadow: 0 0 2px var(--bg), 0 0 8px var(--bg), 0 0 14px var(--bg); }
/* Translucent sidebar on desktop; the mobile drawer covers content and stays opaque */
@media (min-width: 861px) { :root[data-bg] .sidebar { background: color-mix(in srgb, var(--sidebar) 86%, transparent); } }
/* UI opacity: ui/theme.js sets <html data-op>, --ui-op (e.g. 70%) and --ui-op-f (0-1) from cookie nbop */
:root {
  --panel: var(--panel-c); --sidebar: var(--sidebar-c);
  --glass-sheet: var(--glass-sheet-c); --glass-bar: var(--glass-bar-c); --glass-btn: var(--glass-btn-c); --glass-blur: var(--glass-blur-c);
}
:root[data-op] {
  --panel: color-mix(in srgb, var(--panel-c) var(--ui-op, 100%), transparent);
  --sidebar: color-mix(in srgb, var(--sidebar-c) var(--ui-op, 100%), transparent);
  --glass-sheet: color-mix(in srgb, var(--glass-sheet-c) var(--ui-op, 100%), transparent);
  --glass-bar: color-mix(in srgb, var(--glass-bar-c) var(--ui-op, 100%), transparent);
  --glass-btn: color-mix(in srgb, var(--glass-btn-c) var(--ui-op, 100%), transparent);
  --glass-blur: calc(var(--glass-blur-c, 0px) * var(--ui-op-f, 1));
}
@media (max-width: 860px) {
  :root[data-op]:not([data-style="glass"]) .sidebar { background: var(--sidebar-c); }
}
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px;
  color: var(--text-2); text-decoration: none; font-weight: 500;
}
.nav a svg { width: 19px; height: 19px; opacity: .75; }
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-strong); }
.nav a.active svg { opacity: 1; }
/* Sidebar category (e.g. casino): a group of links under a small heading */
.nav-cat { display: flex; flex-direction: column; gap: 2px; margin: 6px 0; padding: 6px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
/* Adjacent categories share one divider with the same spacing as a single one (offsets margin 6px + nav gap 2px) */
.nav-cat + .nav-cat { margin-top: -8px; border-top: 0; }
.nav-cat-label { padding: 2px 12px 4px; font-size: 11.5px; font-weight: 700; letter-spacing: .08em; color: var(--muted); }
/* Collapsible (ui/sidebar.js turns the heading into a button and wraps links in .nav-cat-items) */
button.nav-cat-label {
  display: flex; align-items: center; justify-content: space-between; width: 100%; margin: 0;
  padding: 4px 8px 4px 12px; border: 0; border-radius: 8px; background: none; font-family: inherit; cursor: pointer; text-align: left;
}
button.nav-cat-label:hover { background: var(--panel-2); color: var(--text-2); }
button.nav-cat-label:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.nav-cat-chev { width: 18px; height: 18px; flex: none; }
.nav-cat.collapsed .nav-cat-chev { transform: rotate(-90deg); }
.nav-cat-items { display: grid; grid-template-rows: 1fr; }
.nav-cat-inner { display: flex; flex-direction: column; gap: 2px; min-height: 0; overflow: hidden; }
.nav-cat.collapsed .nav-cat-items { grid-template-rows: 0fr; }
.nav-cat.collapsed .nav-cat-inner { visibility: hidden; }   /* Collapsed links must not be tabbable */
.nav-cat.collapsed { padding-bottom: 2px; }
.nav-ready .nav-cat-items { transition: grid-template-rows .2s ease; }
.nav-ready .nav-cat-inner { transition: visibility 0s; }
.nav-ready .nav-cat.collapsed .nav-cat-inner { transition: visibility 0s .2s; }
.nav-ready .nav-cat-chev { transition: transform .2s ease; }
@media (prefers-reduced-motion: reduce) {
  .nav-ready .nav-cat-items, .nav-ready .nav-cat-chev { transition: none; }
}
.count {
  margin-left: auto; min-width: 22px; padding: 0 7px; border-radius: 999px;
  background: var(--crit); color: #fff; font-size: 12px; font-weight: 700; text-align: center;
}
.side-card { margin-top: auto; padding: 12px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); }
.side-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px 8px 0; border-top: 1px solid var(--line); }
.me-text { min-width: 0; flex: 1; }
.me-text strong, .me-text small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text small { color: var(--muted); font-size: 12px; }
.icon-btn { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; color: var(--muted); }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn svg { width: 19px; height: 19px; }
button.icon-btn { border: 0; background: transparent; padding: 0; cursor: pointer; }
/* Pages without a sidebar (e.g. logged-out home) put the theme button top right */
.theme-corner { position: fixed; top: 14px; right: 14px; z-index: 20; }

/* Content fills all width right of the sidebar; components needing a reading width set their own max-width */
.content { padding: 28px 32px 48px; width: 100%; }
.page { display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 10px; }
.head-actions input { width: 260px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.panel.flush { padding: 0; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.link { font-size: 13px; text-decoration: none; }
.grid-2 { display: grid; grid-template-columns: 3fr 2fr; gap: 18px; }

.notice { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--crit); border-radius: var(--radius); padding: 20px 24px; box-shadow: var(--shadow); }
.notice h2 { font-size: 18px; margin-bottom: 8px; }
.notice p + p { margin-top: 12px; }

.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12.5px; color: var(--text-2); }
.kpi.alert { border-color: var(--crit-line); background: linear-gradient(0deg, var(--panel), var(--crit-soft)); }

.chart svg { display: block; width: 100%; height: auto; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--accent); }
.chart .bar.dim { opacity: .45; }
.chart .hit { fill: transparent; cursor: crosshair; }
.hbars { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.hbar { display: grid; grid-template-columns: minmax(80px, 34%) 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.hbar .track { height: 10px; border-radius: 0 4px 4px 0; background: var(--panel-2); }
.hbar .fill { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--accent); min-width: 3px; }
.hbar .num { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.spark { display: block; width: 100%; height: 34px; }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark .area { fill: var(--accent-soft); }
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; padding: 6px 10px; border-radius: 8px;
  background: var(--tooltip); color: #fff; font-size: 12.5px; box-shadow: 0 6px 20px rgb(0 0 0 / 18%); white-space: nowrap;
}

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.card {
  display: flex; flex-direction: column; gap: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.card.inactive { background: var(--panel-2); }
.card.inactive .card-top, .card.inactive .stats, .card.inactive .spark-wrap { opacity: .6; }
.card.inactive .stat { background: var(--sunken); }
.card-top { display: flex; align-items: center; gap: 12px; }
.card-top .who { min-width: 0; flex: 1; }
.card-top .who strong { display: block; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-top .who span { color: var(--muted); font-size: 13px; }
.avatar {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  color: #fff; font-weight: 700; font-size: 16px; background: #6a7bd8;
}
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
/* Custom avatar: image over the initials; JS removes it on load failure to reveal them */
.avatar { position: relative; }
.avatar > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.fields { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; overflow-wrap: anywhere; }
.note { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text-2); border-left: 3px solid var(--line); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; }
.stat .label { font-size: 11.5px; color: var(--muted); }
.stat .value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .value.small-text { font-size: 13px; font-weight: 600; line-height: 1.9; }
.spark-wrap .label { font-size: 11.5px; color: var(--muted); margin-bottom: 2px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.card-actions .spacer { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px dashed var(--line-dashed); background: transparent; color: var(--muted);
  border-radius: 999px; padding: 2px 10px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.chip.on { border-style: solid; border-color: transparent; background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.chip.static { cursor: default; }
.tag { display: inline-block; border-radius: 6px; padding: 1px 8px; background: var(--panel-2); color: var(--text-2); font-size: 12px; }

.badge { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 2px 10px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.badge::before { font-size: 11px; }
.badge.good { color: var(--good-ink); background: var(--good-soft); }
.badge.good::before { content: "✓"; }
.badge.warn { color: var(--warn-ink); background: var(--warn-soft); }
.badge.warn::before { content: "●"; color: var(--warn); }
.badge.crit { color: var(--crit); background: var(--crit-soft); }
.badge.crit::before { content: "✕"; }
.badge.off { color: var(--muted); background: var(--panel-2); }
.badge.off::before { content: "–"; }
.badge.info { color: var(--accent-strong); background: var(--accent-soft); }
.badge.info::before { content: "…"; }

.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.list-row:first-child { border-top: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .grow small { color: var(--muted); }

.segmented { display: inline-flex; gap: 2px; padding: 3px; background: var(--sunken); border-radius: 10px; align-self: flex-start; }
.segmented button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; font: inherit; color: var(--text-2); cursor: pointer; }
.segmented button.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgb(0 0 0 / 10%); }
.empty { padding: 40px; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }

input, button, textarea { font: inherit; }
input[type=search], input:not([type]), input[type=email], textarea, dialog input {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel); color: var(--text);
}
textarea { resize: vertical; }
input:focus-visible, button:focus-visible, textarea:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; font-weight: 500;
}
.btn:hover { border-color: var(--line-strong); background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.good { background: var(--good-solid); border-color: var(--good-solid); color: #fff; }
.btn.danger { color: var(--crit); }
.btn.danger:hover { border-color: var(--crit); background: var(--crit-soft); }
dialog .btn.danger { background: var(--crit); border-color: var(--crit); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12.5px; font-weight: 600; color: var(--muted); background: var(--panel-2); }
tr:last-child td { border-bottom: 0; }

dialog {
  width: min(480px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 16px;
  background: var(--panel); color: var(--text); padding: 22px 24px; box-shadow: 0 24px 60px rgb(var(--shadow-rgb) / 22%);
}
dialog::backdrop { background: rgb(var(--shadow-rgb) / 35%); }
dialog h2 { font-size: 18px; margin-bottom: 14px; }
dialog label { display: block; margin-bottom: 12px; font-size: 13.5px; color: var(--text-2); }
dialog label input, dialog label textarea { margin-top: 4px; }
fieldset { border: 0; padding: 0; margin: 0 0 12px; }
legend { font-size: 13.5px; color: var(--text-2); margin-bottom: 6px; }
.checks { display: flex; gap: 16px; flex-wrap: wrap; }
.check { display: flex; align-items: center; gap: 6px; color: var(--text) !important; margin: 0 !important; font-size: 13.5px; }
.check input { width: auto; margin: 0; }
.hint { font-size: 13px; color: var(--muted); }
.error { color: var(--crit); font-size: 13.5px; min-height: 1em; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.linkbox { display: flex; gap: 8px; }
.linkbox input { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.sessions { list-style: none; padding: 0; margin: 0; max-height: 300px; overflow: auto; }
.sessions li { padding: 10px 0; border-bottom: 1px solid var(--line); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 60;
  padding: 10px 18px; border-radius: 10px; color: #fff; background: var(--tooltip);
  box-shadow: 0 8px 30px rgb(0 0 0 / 20%); max-width: calc(100vw - 32px);
}
.toast.err { background: var(--crit); }

/* Motion (shared): feedback on press, continuity of dialogs/toasts, and state changes only */
.btn, .chip, .segmented button, .icon-btn, .nav a, button.nav-cat-label, .topbar-btn {
  transition: background-color var(--dur) ease, border-color var(--dur) ease, color var(--dur) ease,
    box-shadow var(--dur) ease, transform var(--dur-fast) var(--ease-out);
}
.btn:active:not(:disabled), .chip:active, .segmented button:active { transform: scale(var(--pop)); }
input, textarea, select { transition: border-color var(--dur) ease, box-shadow var(--dur) ease; }

dialog:not(.sheet) {
  opacity: 0; transform: translateY(var(--rise)) scale(.98);
  transition: opacity 140ms var(--ease-in), transform 140ms var(--ease-in);
  transition: opacity 140ms var(--ease-in), transform 140ms var(--ease-in), overlay 140ms allow-discrete, display 140ms allow-discrete;
}
dialog:not(.sheet)[open] { opacity: 1; transform: none; transition-duration: var(--dur-slow); transition-timing-function: var(--ease-out); }
dialog:not(.sheet)::backdrop {
  opacity: 0;
  transition: opacity 140ms ease;
  transition: opacity 140ms ease, overlay 140ms allow-discrete, display 140ms allow-discrete;
}
dialog:not(.sheet)[open]::backdrop { opacity: 1; transition-duration: var(--dur-slow); }
@starting-style {
  dialog:not(.sheet)[open] { opacity: 0; transform: translateY(var(--rise)) scale(.98); }
  dialog:not(.sheet)[open]::backdrop { opacity: 0; }
}

.toast {
  transition: opacity var(--dur) var(--ease-out), transform var(--dur-slow) var(--ease-out);
  transition: opacity var(--dur) var(--ease-out), transform var(--dur-slow) var(--ease-out), display var(--dur) allow-discrete;
}
.toast.hidden { opacity: 0; transform: translate(-50%, var(--rise)); transition-duration: 160ms; transition-timing-function: var(--ease-in); }
@starting-style { .toast:not(.hidden) { opacity: 0; transform: translate(-50%, calc(var(--rise) * 2)); } }

/* Enter animation for view/tab switches and new items (JS adds the class or calls element.animate) */
@keyframes nb-enter { from { opacity: 0; transform: translateY(var(--rise)); } }
.nb-enter { animation: nb-enter var(--dur-slow) var(--ease-out) backwards; }   /* No `both` fill: it would keep holding transform after the end (hover/press scale) */

/* Page-load entrance (same as pidash's reel): main blocks fade in from blur in sequence; only active when theme.js sets the class on <html> */
@keyframes nb-intro { from { opacity: 0; filter: blur(var(--intro-blur)); transform: translateY(calc(var(--rise) * 2)) scale(.985); } }
.nb-intro .shell:not(.hidden) :is(.content > :not(.page), .content > .page > *) { animation: nb-intro 700ms var(--ease-out) backwards; }
.nb-intro .shell:not(.hidden) :is(.content > :not(.page), .content > .page > *):nth-child(2) { animation-delay: 70ms; }
.nb-intro .shell:not(.hidden) :is(.content > :not(.page), .content > .page > *):nth-child(3) { animation-delay: 140ms; }
.nb-intro .shell:not(.hidden) :is(.content > :not(.page), .content > .page > *):nth-child(4) { animation-delay: 210ms; }
.nb-intro .shell:not(.hidden) :is(.content > :not(.page), .content > .page > *):nth-child(n+5) { animation-delay: 280ms; }

/* Circular reveal for theme switch and sidebar navigation across pages: theme.js animates clip-path */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-new(root) { z-index: 1; }

@media (prefers-reduced-motion: reduce) {
  :root { --rise: 0px; --pop: 1; --intro-blur: 0px; }
  @view-transition { navigation: none; }
  dialog:not(.sheet), dialog:not(.sheet)[open] { transform: none; }
}

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
/* Mobile top bar (made by ui/sidebar.js): menu/close, logo, page name, avatar; hidden on desktop */
.topbar, .nav-scrim, .nb-dock { display: none; }
@media (max-width: 860px) {
  :root { --topbar-h: 56px; }
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .topbar {
    display: flex; align-items: center; gap: 6px; position: sticky; top: 0; z-index: 46;
    height: var(--topbar-h); padding: 0 10px 0 6px; border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--sidebar) 90%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(calc(12px * var(--ui-op-f, 1))); backdrop-filter: saturate(1.4) blur(calc(12px * var(--ui-op-f, 1)));
  }
  .topbar-btn {
    position: relative; flex: none; display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
    border: 0; border-radius: 12px; background: none; color: var(--text); cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .topbar-btn:active { background: var(--panel-2); }
  .burger { position: relative; width: 20px; height: 14px; }
  .burger i { position: absolute; left: 0; width: 100%; height: 2px; border-radius: 2px; background: currentColor; transition: transform .25s ease, opacity .15s ease; }
  .burger i:nth-child(1) { top: 0; }
  .burger i:nth-child(2) { top: 6px; }
  .burger i:nth-child(3) { top: 12px; }
  .nav-open .burger i:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .nav-open .burger i:nth-child(2) { opacity: 0; transform: scaleX(.3); }
  .nav-open .burger i:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
  /* Red dot on the menu button when the sidebar has pending counts (e.g. signup review) */
  .nav-dot { position: absolute; top: 9px; right: 8px; width: 9px; height: 9px; border-radius: 50%; background: var(--crit); box-shadow: 0 0 0 2px var(--sidebar); }
  .nav-open .nav-dot { display: none; }
  .topbar .brand-logo { flex: none; padding: 0; }
  .topbar .brand-logo img { width: 30px; height: 30px; }
  :root:not([data-theme="dark"]) .topbar .brand-logo .logo-mark.logo-light,
  :root[data-theme="dark"] .topbar .brand-logo .logo-mark.logo-dark { display: block; }
  .topbar-title { flex: 1; min-width: 0; margin-left: 4px; font-size: 16.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-me { width: 40px; height: 40px; border-radius: 50%; }
  .topbar-me:empty { visibility: hidden; }

  /* Sidebar becomes a drawer sliding in from the left below the top bar, same content as desktop */
  .sidebar {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0; z-index: 45; width: min(300px, 86vw); height: auto;
    padding: 14px 14px max(14px, env(safe-area-inset-bottom)); gap: 14px;
    border-right: 1px solid var(--line); overscroll-behavior: contain;
    transform: translateX(-100%); visibility: hidden;
    transition: transform .28s cubic-bezier(.2, .8, .2, 1), visibility 0s .28s;
  }
  .nav-open .sidebar { transform: none; visibility: visible; transition: transform .28s cubic-bezier(.2, .8, .2, 1); box-shadow: 8px 0 32px rgb(var(--shadow-rgb) / 18%); }
  .sidebar > .brand { display: none; }   /* The top bar already has the logo */
  .nav a { padding: 11px 12px; }          /* Larger touch targets */
  .nav-scrim {
    display: block; position: fixed; inset: var(--topbar-h) 0 0; z-index: 44; background: rgb(var(--shadow-rgb) / 38%);
    opacity: 0; pointer-events: none; transition: opacity .28s ease;
  }
  .nav-open .nav-scrim { opacity: 1; pointer-events: auto; }
  html.nav-lock { overflow: hidden; }
  .content { padding: 20px 16px 40px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .head-actions { width: 100%; }
  .head-actions input { width: auto; flex: 1; }
  .cards { grid-template-columns: 1fr; }
}
@media (max-width: 860px) and (prefers-reduced-motion: reduce) {
  .sidebar, .nav-open .sidebar, .nav-scrim, .burger i { transition: none; }
}

/* Glass style layout. Placed last so it beats same-specificity rules above. Never put backdrop-filter on .sidebar or .content (it would break fixed-position descendants) */
:root[data-style="glass"] .content { position: relative; width: auto; }
:root[data-style="glass"] .content::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; border-radius: inherit;
  background: var(--glass-sheet); border: 1px solid var(--glass-edge); box-shadow: 0 30px 80px rgb(var(--shadow-rgb) / 16%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.2); backdrop-filter: blur(var(--glass-blur)) saturate(1.2);
}
:root[data-style="glass"] :is(.panel, .kpi, .card, .notice) { border-color: var(--glass-edge); }
:root[data-style="glass"] .kpi.alert { border-color: var(--crit-line); }
:root[data-style="glass"] .notice { border-left-color: var(--crit); }
:root[data-style="glass"] dialog {
  border-color: var(--glass-edge); -webkit-backdrop-filter: blur(calc(24px * var(--ui-op-f, 1))) saturate(1.2); backdrop-filter: blur(calc(24px * var(--ui-op-f, 1))) saturate(1.2);
}
:root[data-style="glass"] .btn { border-radius: 999px; }
/* --accent-strong is light text in dark mode, so white hover text vanishes: lift on hover instead */
:root[data-style="glass"] .btn.primary:hover { background: var(--accent); box-shadow: 0 4px 14px rgb(var(--shadow-rgb) / 25%); }
:root[data-style="glass"] .segmented, :root[data-style="glass"] .segmented button { border-radius: 999px; }
:root[data-style="glass"] .segmented button.active { background: var(--accent-soft); color: var(--accent-strong); }

/* Bottom menu (ui/nav.js): links of the current category; current page is a white pill */
:root[data-style="glass"] .nb-dock {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 42;
  display: flex; gap: 4px; max-width: calc(100vw - 32px); padding: 6px; overflow-x: auto; scrollbar-width: none;
  border: 1px solid var(--glass-edge); border-radius: 999px; background: var(--glass-bar); box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.3); backdrop-filter: blur(var(--glass-blur)) saturate(1.3);
}
:root[data-style="glass"] .nb-dock::-webkit-scrollbar { display: none; }
:root[data-style="glass"] .nb-dock a {
  flex: none; padding: 8px 16px; border-radius: 999px; color: var(--text-2); font-size: 13.5px; font-weight: 500;
  text-decoration: none; white-space: nowrap; transition: background-color var(--dur) ease, color var(--dur) ease;
}
:root[data-style="glass"] .nb-dock a:hover { background: var(--hover); color: var(--text); }
:root[data-style="glass"] .nb-dock a.active { background: var(--accent-soft); color: var(--accent-strong); box-shadow: 0 2px 8px rgb(var(--shadow-rgb) / 12%); }

@media (min-width: 861px) {
  :root[data-style="glass"] .shell { display: block; }
  /* Left icon-only sidebar, same height as the big glass panel, never expands */
  :root[data-style="glass"] .sidebar {
    /* Aligned with the big panel (.content: 88px top, 96px bottom); nav scrolls itself when links overflow */
    position: fixed; left: 20px; top: 88px; bottom: 96px; z-index: 40;
    width: 60px; height: auto; max-height: none; margin-block: 0; padding: 10px 8px; gap: 6px;
    border: 0; border-radius: 30px; background: var(--sidebar); box-shadow: inset 0 0 0 1px var(--glass-edge), var(--shadow);
    overflow-x: hidden; overflow-y: auto;
  }
  :root[data-style="glass"] .sidebar > .nav { margin: 0; padding: 0; }
  :root[data-style="glass"] .sidebar > .nav a {
    position: relative; flex: none; justify-content: flex-start; gap: 14px; padding: 10px 12px; border-radius: 999px;
    white-space: nowrap; overflow: hidden; font-size: 0;   /* Hide text (text nodes have no class); icons are px so unaffected; flex: none because overflow would let flex squash links */
  }
  :root[data-style="glass"] .sidebar > .nav a svg { flex: none; width: 20px; height: 20px; }
  :root[data-style="glass"] .sidebar > .nav a.active { box-shadow: 0 2px 8px rgb(var(--shadow-rgb) / 12%); }
  :root[data-style="glass"] .sidebar .nav-cat { margin: 0; padding: 0; border: 0; }
  :root[data-style="glass"] .sidebar :is(.nav-cat-label, .side-card) { display: none; }
  /* Category headings are hidden so collapse can't be undone: this style always expands all (collapse state stays in nbnav for other styles) */
  :root[data-style="glass"] .sidebar .nav-cat.collapsed .nav-cat-items { grid-template-rows: 1fr; }
  :root[data-style="glass"] .sidebar .nav-cat.collapsed .nav-cat-inner { visibility: visible; }
  /* Pending count becomes a red dot at the top right */
  :root[data-style="glass"] .sidebar > .nav a .count { position: absolute; top: 7px; right: 7px; width: 9px; min-width: 0; height: 9px; padding: 0; }
  /* Logo: glass square top left, square logo only */
  :root[data-style="glass"] .sidebar > .brand {
    position: fixed; top: 16px; left: 20px; display: grid; place-items: center; width: 60px; height: 56px; padding: 0;
    border: 1px solid var(--glass-edge); border-radius: 28px; background: var(--glass-bar); box-shadow: var(--shadow);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.3); backdrop-filter: blur(var(--glass-blur)) saturate(1.3);
  }
  :root[data-style="glass"] .sidebar > .brand .logo-wide { display: none; }
  :root[data-style="glass"]:not([data-theme="dark"]) .sidebar > .brand .logo-mark.logo-light,
  :root[data-style="glass"][data-theme="dark"] .sidebar > .brand .logo-mark.logo-dark { display: block; }
  :root[data-style="glass"] .sidebar > .brand img { width: 34px; height: 34px; }
  /* Top pill bar: user row (avatar, welcome, theme / old-new / logout buttons) moved to the top */
  :root[data-style="glass"] .sidebar > .me {
    position: fixed; top: 16px; left: 92px; right: 20px; z-index: 41; height: 56px; padding: 6px 8px 6px 6px;
    border: 1px solid var(--glass-edge); border-radius: 28px; background: var(--glass-bar); box-shadow: var(--shadow);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.3); backdrop-filter: blur(var(--glass-blur)) saturate(1.3);
  }
  :root[data-style="glass"] .me-text { display: flex; align-items: baseline; gap: 8px; }
  :root[data-style="glass"] .me-text strong::before { content: "歡迎回來，"; font-weight: 500; }
  :root[data-style="glass"] .me .icon-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--glass-btn); color: var(--text); }
  :root[data-style="glass"] .me .icon-btn:hover { box-shadow: 0 2px 10px rgb(var(--shadow-rgb) / 18%); }
  /* Big glass panel: top reserved for the pill bar, left for the sidebar, bottom for the bottom menu */
  :root[data-style="glass"] .content {
    min-height: calc(100vh - 184px); margin: 88px 20px 96px 96px; padding: 32px 36px; border-radius: 32px;
  }
  :root[data-style="glass"] .content:is(.chat-content, .vc-content) { height: calc(100vh - 184px); }
  :root[data-style="glass"] .content h1 { font-size: 30px; font-weight: 600; letter-spacing: -.02em; }
}
@media (max-width: 860px) {
  /* Mobile keeps the top bar + drawer; the drawer sits over content with an opaque --bg layer */
  :root[data-style="glass"] .topbar { border-bottom-color: var(--glass-edge); background: var(--glass-bar); }
  :root[data-style="glass"] .sidebar { background: linear-gradient(var(--sidebar), var(--sidebar)), var(--bg); }
  :root[data-style="glass"] .content { margin: 12px 12px 84px; padding: 20px 16px; border-radius: 24px; }
  :root[data-style="glass"] .content:is(.chat-content, .vc-content) { height: calc(100dvh - var(--topbar-h) - 96px); }
  :root[data-style="glass"] .nb-dock { bottom: max(12px, env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) {
  :root[data-style="glass"] .sidebar { transition: none; }
}

/* Industry style: round the glass layout down (pills -> small-radius rectangles) */
:root[data-glass="industry"] :is(.btn, .segmented, .segmented button, .nb-dock, .nb-dock a) { border-radius: 8px; }
:root[data-glass="industry"] .nb-dock { padding: 5px; }
:root[data-glass="industry"] :is(h1, h2, .kpi) { font-variant-numeric: tabular-nums; }
@media (min-width: 861px) {
  :root[data-glass="industry"] .sidebar { border-radius: 14px; }
  :root[data-glass="industry"] .sidebar > .nav a { border-radius: 8px; }
  :root[data-glass="industry"] :is(.sidebar > .brand, .sidebar > .me) { border-radius: 14px; }
  :root[data-glass="industry"] .me .icon-btn { border-radius: 8px; }
  :root[data-glass="industry"] .content { border-radius: 16px; }
  :root[data-glass="industry"] .content h1 { font-weight: 650; letter-spacing: -.01em; }
}
@media (max-width: 860px) {
  :root[data-glass="industry"] .content { border-radius: 12px; }
}

/* Sidebar collapse / drag-resize (ui/sidebar.js adds the button and handle; theme.js applies state at the start) */
.side-toggle, .side-resize { display: none; }
@media (min-width: 861px) {
  :root:not([data-style="glass"]) .side-resize {
    display: block; position: fixed; top: 0; bottom: 0; left: calc(var(--side-w) - 4px); z-index: 30;
    width: 8px; cursor: col-resize; touch-action: none; outline: none;
  }
  .side-resize::after {
    content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px;
    background: var(--accent); opacity: 0; transition: opacity var(--dur-fast, .15s);
  }
  .side-resize:hover::after, .side-resize:focus-visible::after, .side-drag .side-resize::after { opacity: .6; }
  :root:not([data-style="glass"]) .side-toggle {
    display: grid; place-items: center; position: fixed; top: 26px; left: calc(var(--side-w) - 13px); z-index: 31;
    width: 26px; height: 26px; padding: 0; border-radius: 50%; cursor: pointer;
    background: var(--panel); color: var(--muted); border: 1px solid var(--line); box-shadow: 0 1px 4px rgb(var(--shadow-rgb, 15 23 42) / 12%);
    opacity: 0; transition: opacity var(--dur-fast, .15s), color var(--dur-fast, .15s);
  }
  .side-toggle svg { width: 16px; height: 16px; transition: transform var(--dur, .2s) var(--ease-out, ease); }
  :root[data-side="rail"] .side-toggle svg { transform: rotate(180deg); }
  /* Faint at rest, clear on sidebar hover, button hover or keyboard focus; always visible when collapsed */
  .shell:has(> .sidebar:hover) .side-toggle, .side-toggle:hover, .side-toggle:focus-visible,
  :root[data-side="rail"] .side-toggle, .side-resize:hover + .side-toggle { opacity: 1; }
  .side-toggle:hover { color: var(--text); }
  .side-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .side-anim .shell { transition: grid-template-columns var(--dur, .2s) var(--ease-out, ease); }
  .side-anim :is(.side-resize, .side-toggle) { transition: left var(--dur, .2s) var(--ease-out, ease), opacity var(--dur-fast, .15s); }
  .side-drag, .side-drag * { cursor: col-resize !important; user-select: none; }
  .side-drag .shell, .side-drag :is(.side-resize, .side-toggle) { transition: none !important; }

  /* Logo does not scale when widened (its height is proportional to width and would push the nav down) */
  .sidebar > .brand-logo .logo-wide { max-width: 216px; }
  :root[data-side="rail"]:not([data-style="glass"]) { --side-w: 72px; }
  :root[data-side="rail"]:not([data-style="glass"]) .sidebar { padding-inline: 10px; }
  :root[data-side="rail"]:not([data-style="glass"]) .sidebar .nav a {
    position: relative; justify-content: center; gap: 0; padding: 10px 0; font-size: 0;
  }
  :root[data-side="rail"]:not([data-style="glass"]) .sidebar .nav a .count {
    position: absolute; top: 6px; right: 8px; width: 9px; min-width: 0; height: 9px; padding: 0; font-size: 0;
  }
  :root[data-side="rail"]:not([data-style="glass"]) .sidebar :is(.nav-cat-label, .side-card, .me-text) { display: none; }
  :root[data-side="rail"]:not([data-style="glass"]) .sidebar .nav-cat { margin: 4px 0; padding: 4px 0; }
  :root[data-side="rail"]:not([data-style="glass"]) .sidebar .nav-cat.collapsed .nav-cat-items { grid-template-rows: 1fr; }
  :root[data-side="rail"]:not([data-style="glass"]) .sidebar .nav-cat.collapsed .nav-cat-inner { visibility: visible; }
  :root[data-side="rail"]:not([data-style="glass"]) .sidebar > .brand { padding: 0; justify-content: center; }
  :root[data-side="rail"]:not([data-style="glass"]) .sidebar > .brand .logo-wide { display: none; }
  :root[data-side="rail"]:not([data-style="glass"]):not([data-theme="dark"]) .sidebar > .brand .logo-mark.logo-light,
  :root[data-side="rail"]:not([data-style="glass"])[data-theme="dark"] .sidebar > .brand .logo-mark.logo-dark { display: block; width: 40px; height: 40px; margin-inline: auto; }
  :root[data-side="rail"]:not([data-style="glass"]) .sidebar > .me { flex-direction: column; gap: 8px; padding-inline: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .side-anim .shell, .side-anim :is(.side-resize, .side-toggle), .side-toggle svg { transition: none; }
}
