/* 短剧库 — design tokens, app chrome and shared components.
   Short-video style: dark #161823 page with #252632 surfaces (light: #f8f8f8
   page, white surfaces), accent #FE2C55 for primary actions, selection and
   played progress; cyan #25F4EE only as a small highlight. Semantic colours
   (success / danger / warning) are separate from the accent. */

:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  --background: #f8f8f8;
  --page-surface: #ffffff;
  --foreground: #161823;
  --muted: rgba(22, 24, 35, 0.6);
  --faint: rgba(22, 24, 35, 0.34);
  --fill: rgba(22, 24, 35, 0.05);
  --fill-strong: rgba(22, 24, 35, 0.09);
  --divider: rgba(22, 24, 35, 0.08);
  --border: rgba(22, 24, 35, 0.12);
  --accent: #FE2C55;
  --accent-hover: #FF4772;
  --accent-soft: rgba(254, 44, 85, 0.1);
  --accent-cyan: #25F4EE;
  --success: #12B76A;
  --danger: #D92D20;
  --warning: #DC6803;
  --radius-sm: 4px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-pill: 999px;
  --shadow-pop: 0 10px 36px rgba(22, 24, 35, 0.14);
  --scrim: rgba(0, 0, 0, 0.45);
  --chrome-bg: rgba(248, 248, 248, 0.86);
  --sidebar-width: 168px;
  --topbar-height: 64px;
  --tabbar-height: 52px;
  --icon-button: 36px;
  --selector-height: 32px;
  --z-chrome: 20;
  --z-player: 50;
  --z-modal: 70;
  --z-popover: 100;
  --z-toast: 120;
  background: var(--background);
  color: var(--foreground);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #161823;
  --page-surface: #252632;
  --foreground: rgba(255, 255, 255, 0.9);
  --muted: rgba(255, 255, 255, 0.5);
  --faint: rgba(255, 255, 255, 0.3);
  --fill: rgba(255, 255, 255, 0.06);
  --fill-strong: rgba(255, 255, 255, 0.1);
  --divider: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.12);
  --accent-soft: rgba(254, 44, 85, 0.16);
  --success: #32D583;
  --danger: #F97066;
  --warning: #FDB022;
  --shadow-pop: 0 12px 40px rgba(0, 0, 0, 0.5);
  --scrim: rgba(0, 0, 0, 0.6);
  --chrome-bg: rgba(22, 24, 35, 0.86);
}

* { box-sizing: border-box; border-color: var(--border); }
html { min-height: 100%; background: var(--background); }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--background); color: var(--foreground); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; overflow-x: hidden; }
body.has-modal, body.has-player { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; opacity: .45; }
a { color: inherit; }
h1, h2, h3, h4, p { margin: 0; }
svg { display: block; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent); outline-offset: 2px; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { margin: 0; -webkit-appearance: none; appearance: none; }
* { scrollbar-width: thin; scrollbar-color: var(--fill-strong) transparent; }
mark { background: transparent; color: var(--accent); }

/* ------------------------------------------------------------------ app chrome */
.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: var(--topbar-height) minmax(0, 1fr);
}
.sidebar {
  grid-row: 1 / -1;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  z-index: var(--z-chrome);
  display: flex;
  flex-direction: column;
  gap: 18px;
  /* landscape iPhones: keep the rail clear of the notch */
  padding: 18px 12px calc(18px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  overflow-y: auto;
  border-right: 1px solid var(--divider);
  background: var(--background);
}
.brand { display: inline-flex; align-items: center; gap: 9px; min-width: 0; color: inherit; text-decoration: none; font-size: 18px; font-weight: 600; letter-spacing: .02em; }
.brand__logo { width: 32px; height: 32px; flex: 0 0 32px; display: inline-flex; align-items: center; justify-content: center; border-radius: 9px; background: var(--accent); color: #fff; box-shadow: -2px -2px 0 var(--accent-cyan); }
.brand__logo .icon { width: 18px; height: 18px; }
.brand__name { white-space: nowrap; }
.brand--side { padding: 2px 8px 6px; }
.brand--top { display: none; }
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-nav__item {
  position: relative;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
  transition: color 150ms ease, background-color 150ms ease;
}
.side-nav__item .icon { width: 22px; height: 22px; }
.side-nav__item[aria-current="page"] { background: var(--fill-strong); color: var(--foreground); font-weight: 600; }
.side-nav__item[aria-current="page"] .icon { color: var(--accent); }
@media (hover: hover) and (pointer: fine) { .side-nav__item:hover:not([aria-current="page"]) { background: var(--fill); color: var(--foreground); } }
.sidebar__stats { margin-top: auto; display: grid; gap: 2px; padding: 12px 6px 0; border-top: 1px solid var(--divider); }

.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-chrome);
  display: grid;
  /* the right column is never narrower than its buttons, so the search box cannot slide under them */
  grid-template-columns: minmax(0, 1fr) minmax(0, 520px) minmax(max-content, 1fr);
  align-items: center;
  gap: 16px;
  min-width: 0;
  padding: env(safe-area-inset-top) max(24px, env(safe-area-inset-right)) 0 24px;
  background: var(--chrome-bg);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  backdrop-filter: saturate(1.4) blur(16px);
}
.topbar__search { grid-column: 2; min-width: 0; display: flex; justify-content: center; }
.topbar > .nav-actions { grid-column: 3; justify-self: end; }
.nav-actions { display: inline-flex; flex: none; align-items: center; gap: 8px; }
.page-host { min-width: 0; display: flex; flex-direction: column; gap: 16px; padding: 8px 24px 40px; outline: none; }
.page { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.mobile-stats { display: none; }

.icon-btn {
  position: relative;
  width: var(--icon-button);
  height: var(--icon-button);
  flex: 0 0 var(--icon-button);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--fill);
  color: var(--foreground);
  transition: color 150ms ease, background-color 150ms ease;
}
.icon-btn .icon { width: 18px; height: 18px; }
.icon-btn[aria-pressed="true"], .icon-btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); }
@media (hover: hover) and (pointer: fine) { .icon-btn:hover:not(:disabled) { background: var(--fill-strong); } }
.activity-dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--background); }
.login-link {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 160px;
  padding: 0 14px 0 6px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--fill);
  color: var(--foreground);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.login-link .icon { width: 24px; height: 24px; padding: 4px; border-radius: 50%; background: var(--accent); color: #fff; }
.login-link__name { overflow: hidden; text-overflow: ellipsis; }
@media (hover: hover) and (pointer: fine) { .login-link:hover { background: var(--fill-strong); } }

/* overview: compact list in the sidebar, chip strip on phones */
.summary { display: grid; gap: 2px; }
.summary__metric { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 5px 6px; }
.summary__label { display: flex; align-items: center; gap: 6px; flex: none; color: var(--muted); font-size: 12px; line-height: 1; white-space: nowrap; }
.summary__icon { width: 15px; height: 15px; }
.summary__value { min-width: 0; display: flex; align-items: baseline; gap: 3px; line-height: 1; white-space: nowrap; font-variant-numeric: tabular-nums; }
.summary__value strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 13px; font-weight: 600; }
.summary__value span { color: var(--muted); font-size: 11px; }

.page-title { font-size: 20px; font-weight: 600; line-height: 1.3; }
.section-title { margin: 0; font-size: 15px; font-weight: 600; }
.state-card { padding: 24px; display: grid; gap: 14px; justify-items: start; }
.card { position: relative; background: var(--page-surface); border: 0; border-radius: var(--radius-lg); color: var(--foreground); }

/* ------------------------------------------------------------------ segmented selector / tabs */
.slider {
  --slider-columns: 2;
  --slider-index: 0;
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: repeat(var(--slider-columns), minmax(0, 1fr));
  align-items: center;
  min-width: 0;
  padding: 3px;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--fill);
}
.slider::before {
  content: '';
  position: absolute;
  z-index: 0;
  top: 3px;
  left: calc(3px + (100% - 6px) / var(--slider-columns) * var(--slider-index));
  width: calc((100% - 6px) / var(--slider-columns));
  height: var(--selector-height);
  border-radius: 6px;
  background: var(--accent);
  pointer-events: none;
  transition: left 200ms cubic-bezier(.2, .8, .2, 1);
}
.slider > button {
  position: relative;
  z-index: 1;
  min-width: 0;
  height: var(--selector-height);
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 150ms ease;
}
.slider > button[data-active="true"] { color: #fff; font-weight: 600; }
@media (hover: hover) and (pointer: fine) { .slider > button:hover:not([data-active="true"]) { color: var(--foreground); } }
.slider--compact { --selector-height: 30px; }
/* tab style (admin sections): accent underline under the active tab */
.slider--nav { --selector-height: 44px; padding: 0; border-radius: 0; background: transparent; box-shadow: inset 0 -1px var(--divider); }
.slider--nav::before { top: auto; bottom: 0; left: calc(100% / var(--slider-columns) * var(--slider-index) + (100% / var(--slider-columns) - 24px) / 2); width: 24px; height: 3px; border-radius: 2px; }
.slider--nav > button { font-size: 15px; }
.slider--nav > button[data-active="true"] { color: var(--foreground); }
@media (prefers-reduced-motion: reduce) { .slider::before { transition: none; } }

/* ------------------------------------------------------------------ chip filter */
.filter-bar { min-height: 40px; display: flex; align-items: stretch; padding: 0; border-radius: 0; background: transparent; }
.filter-buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; width: 100%; min-width: 0; padding: 4px 0; }
.filter-buttons > button {
  display: inline-flex;
  flex: 0 0 auto;
  height: 32px;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--fill);
  color: var(--foreground);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.filter-buttons > button[aria-pressed="true"] { background: var(--accent); color: #fff; }
@media (hover: hover) and (pointer: fine) { .filter-buttons > button:hover:not([aria-pressed="true"]) { background: var(--fill-strong); } }
.filter-count { font-size: 11px; opacity: .72; }
.filter-bar--scroll .filter-buttons { flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
.filter-bar--scroll .filter-buttons::-webkit-scrollbar { display: none; }

/* ------------------------------------------------------------------ buttons and fields */
.btn {
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: none;
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--fill-strong);
  color: var(--foreground);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 150ms ease, color 150ms ease;
}
.btn .icon { width: 16px; height: 16px; }
@media (hover: hover) and (pointer: fine) { .btn:hover:not(:disabled) { background: color-mix(in srgb, var(--fill-strong) 100%, var(--foreground) 6%); } }
.btn--primary { background: var(--accent); color: #fff; }
@media (hover: hover) and (pointer: fine) { .btn--primary:hover:not(:disabled) { background: var(--accent-hover); color: #fff; } }
.btn--danger { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
@media (hover: hover) and (pointer: fine) { .btn--danger:hover:not(:disabled) { background: color-mix(in srgb, var(--danger) 20%, transparent); } }
.btn--row { height: 32px; padding: 0 12px; font-size: 13px; }
.btn--icon { width: 32px; padding: 0; border-radius: var(--radius-pill); }
.btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.input, .select-trigger, textarea.input {
  width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--fill);
  color: var(--foreground);
  font-size: 14px;
  box-shadow: none;
}
.input::placeholder { color: var(--faint); }
.input:focus-visible, .select-trigger:focus-visible, .select-trigger[aria-expanded="true"] { outline: none; border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.input:-webkit-autofill { -webkit-text-fill-color: var(--foreground); -webkit-box-shadow: 0 0 0 1000px var(--page-surface) inset; caret-color: var(--foreground); }
.input:disabled { opacity: .5; }
.select-trigger { display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 10px 0 12px; text-align: left; white-space: nowrap; }
.select-trigger__text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.select-trigger .icon { width: 16px; height: 16px; color: var(--muted); transition: transform 150ms ease; }
.select-trigger[aria-expanded="true"] .icon { color: var(--accent); transform: rotate(180deg); }
.select-trigger--compact { width: auto; height: 32px; font-size: 13px; font-weight: 500; border-radius: var(--radius-pill); }
.field { min-width: 0; display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
.field__label { color: var(--muted); font-weight: 500; }
.field__hint { color: var(--faint); font-size: 12px; line-height: 1.4; }
.form-stack { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-section { display: grid; gap: 12px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--divider); }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
/* round check for selections */
.check {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  border: 1.5px solid var(--faint);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}
.check:checked {
  border-color: var(--accent);
  background-color: var(--accent);
  background-image: url("data:image/svg+xml,%3Csvg width='14' height='14' viewBox='0 0 14 14' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3.1 7.2l2.2 2.1 5.4-5.6' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: center;
  background-repeat: no-repeat;
}
.check:disabled { opacity: .45; cursor: not-allowed; }
/* switch for settings: track turns accent when on */
.toggle { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; min-height: 40px; padding: 9px 0; color: var(--foreground); font-size: 14px; font-weight: 500; cursor: pointer; }
.toggle__text { order: 1; display: grid; gap: 2px; min-width: 0; }
.toggle__text small { color: var(--muted); font-size: 12px; font-weight: 400; }
.toggle > .check {
  order: 2;
  position: relative;
  width: 40px;
  height: 22px;
  flex: 0 0 40px;
  margin-top: 1px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--fill-strong);
  background-image: none;
  transition: background-color 180ms ease;
}
.toggle > .check::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform 180ms ease; }
.toggle > .check:checked { background: var(--accent); background-image: none; }
.toggle > .check:checked::after { transform: translateX(18px); }
.note { color: var(--muted); font-size: 13px; line-height: 1.5; }
.note--error { color: var(--danger); }
.note--success { color: var(--success); }
.note--warning { color: var(--warning); }
.pill { display: inline-flex; align-items: center; min-height: 22px; padding: 0 8px; border: 0; border-radius: var(--radius-sm); background: var(--fill); color: var(--muted); font-size: 12px; font-weight: 500; white-space: nowrap; }
.pill--green { background: color-mix(in srgb, var(--success) 14%, transparent); color: var(--success); }
.pill--red { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.pill--orange { background: color-mix(in srgb, var(--warning) 14%, transparent); color: var(--warning); }
.pill--accent { background: var(--accent-soft); color: var(--accent); }
.bar { position: relative; height: 4px; overflow: hidden; border-radius: var(--radius-pill); background: var(--fill-strong); }
.bar > span { position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: var(--accent); transition: width 300ms ease; }
.bar--done > span { background: var(--success); }
.bar--failed > span { background: var(--danger); }
.empty { display: grid; justify-items: center; gap: 8px; padding: 48px 16px; color: var(--muted); text-align: center; }
.empty strong { color: var(--foreground); font-size: 15px; font-weight: 600; }
.metric { display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.metric__label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.metric__label .icon { width: 16px; height: 16px; }
.metric__value { display: inline-flex; align-items: baseline; gap: 3px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.metric__value strong { font-size: 16px; font-weight: 600; }
.metric__value span { color: var(--muted); font-size: 12px; }
.metric--orange .metric__label .icon, .metric--red .metric__label .icon { color: var(--accent); }

/* ------------------------------------------------------------------ list rows */
.list { display: grid; }
.list-row { position: relative; min-width: 0; min-height: 64px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 12px 16px; border-top: 1px solid var(--divider); font-size: 13px; transition: background-color 150ms ease; }
.list-row:first-child { border-top: 0; }
@media (hover: hover) and (pointer: fine) { .list-row:hover { background: var(--fill); } }
.list-main { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.list-main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 500; line-height: 1.3; }
.list-main small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; line-height: 1.4; }
.row-actions { display: inline-flex; align-items: center; justify-content: flex-end; flex-wrap: nowrap; gap: 8px; }

/* ------------------------------------------------------------------ popovers (self-drawn) */
.popover {
  position: fixed;
  z-index: var(--z-popover);
  min-width: 128px;
  max-width: calc(100vw - 16px);
  overflow: auto;
  padding: 6px;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--page-surface);
  color: var(--foreground);
  box-shadow: var(--shadow-pop), 0 0 0 1px var(--divider);
}
.option-list { display: grid; grid-template-columns: repeat(var(--option-columns, 1), minmax(0, 1fr)); gap: 2px; }
.option {
  min-width: 0;
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--foreground);
  font-size: 14px;
  text-align: left;
}
.option span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.option small { margin-left: auto; color: var(--muted); font-size: 12px; }
.option .icon { width: 16px; height: 16px; color: var(--muted); }
.option[data-active="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.option[data-active="true"] .icon, .option[data-active="true"] small { color: var(--accent); }
@media (hover: hover) and (pointer: fine) { .option:hover:not([data-active="true"]) { background: var(--fill); } }
.option:focus-visible { outline: none; background: var(--fill-strong); }
.popover--panel { padding: 16px; }
.activity { display: grid; gap: 14px; }
.activity__section { display: grid; gap: 8px; }
.activity__section + .activity__section { padding-top: 14px; border-top: 1px solid var(--divider); }
.activity__section h3 { font-size: 14px; font-weight: 600; }
.activity__row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; }
.activity__row span { color: var(--muted); }
.activity__row strong { font-weight: 500; }
.activity__row .activity__title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--foreground); }
.activity__task { display: grid; gap: 6px; }
.activity__tasks { display: grid; gap: 10px; }
.activity__note { color: var(--muted); font-size: 12px; }
.activity__note--error { color: var(--danger); }
.activity .btn { justify-self: start; }

/* ------------------------------------------------------------------ modal */
.modal-backdrop { position: fixed; inset: 0; z-index: var(--z-modal); display: flex; align-items: center; justify-content: center; padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left)); background: var(--scrim); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.modal {
  width: min(900px, 100%);
  max-height: min(88vh, 820px);
  max-height: min(88dvh, 820px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 20px 24px;
  border: 0;
  border-radius: var(--radius-xl);
  background: var(--page-surface);
  color: var(--foreground);
  box-shadow: var(--shadow-pop);
}
.modal--small { width: min(460px, 100%); }
.modal--medium { width: min(640px, 100%); }
.modal--large { width: min(900px, 100%); }
.modal__header { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 14px; }
.modal__title { min-width: 0; font-size: 18px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.modal__close { background: transparent; }
.modal__body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: 2px; }
.modal__footer { flex: none; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding-top: 16px; margin-top: 16px; border-top: 1px solid var(--divider); }
.confirm__lead { font-size: 14px; color: var(--muted); }
.modal--confirm .modal__title { font-size: 17px; }

/* ------------------------------------------------------------------ toast */
.toast-root { position: fixed; z-index: var(--z-toast); left: 50%; top: 50%; transform: translate(-50%, -50%); width: max-content; max-width: calc(100vw - 48px); pointer-events: none; }
.toast { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-radius: var(--radius); background: rgba(22, 24, 35, 0.88); color: #fff; box-shadow: 0 8px 28px rgba(0, 0, 0, .3); font-size: 14px; font-weight: 500; text-align: center; pointer-events: none; -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.toast .btn { background: rgba(255, 255, 255, .14); color: #fff; pointer-events: auto; }
.toast--error { box-shadow: inset 3px 0 0 var(--danger), 0 8px 28px rgba(0, 0, 0, .3); }

/* ------------------------------------------------------------------ tablet: icon rail */
@media (max-width: 1023px) and (min-width: 768px) {
  :root { --sidebar-width: 76px; }
  .sidebar { align-items: stretch; padding: 16px 8px calc(16px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  .brand--side { justify-content: center; padding: 2px 0 6px; }
  .brand--side .brand__name { display: none; }
  .side-nav__item { height: 56px; flex-direction: column; justify-content: center; gap: 3px; padding: 0; font-size: 11px; text-align: center; }
  .sidebar__stats { display: none; }
  .page-host { padding: 8px 16px 32px; }
  .topbar { padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 16px; }
}

/* ------------------------------------------------------------------ phone: bottom tab bar */
@media (max-width: 767px) {
  :root { --icon-button: 32px; --topbar-height: 56px; }
  .app-shell { display: block; }
  .topbar { display: flex; height: calc(var(--topbar-height) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) calc(10px + env(safe-area-inset-right)) 0 calc(10px + env(safe-area-inset-left)); gap: 8px; }
  .brand--top { display: inline-flex; flex: none; }
  .topbar__search { flex: 1 1 auto; }
  .brand--top .brand__name { display: none; }
  .brand__logo { width: 30px; height: 30px; flex-basis: 30px; }
  .nav-actions { gap: 6px; }
  .icon-btn .icon { width: 16px; height: 16px; }
  .icon-btn::after { content: ''; position: absolute; inset: -6px; }
  .login-link { width: 32px; height: 32px; padding: 0; justify-content: center; background: transparent; }
  .login-link__name { display: none; }
  .login-link .icon { width: 28px; height: 28px; padding: 5px; }
  .sidebar {
    position: fixed;
    inset: auto 0 0 0;
    height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
    flex-direction: row;
    gap: 0;
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    overflow: visible;
    border-right: 0;
    border-top: 1px solid var(--divider);
    background: var(--chrome-bg);
    -webkit-backdrop-filter: saturate(1.4) blur(16px);
    backdrop-filter: saturate(1.4) blur(16px);
  }
  .brand--side, .sidebar__stats { display: none; }
  .side-nav { flex: 1; flex-direction: row; gap: 0; }
  .side-nav__item { flex: 1 1 0; min-width: 0; height: var(--tabbar-height); flex-direction: column; justify-content: center; gap: 2px; padding: 0; border-radius: 0; background: transparent; font-size: 11px; text-align: center; }
  .side-nav__item .icon { width: 22px; height: 22px; }
  .side-nav__item[aria-current="page"] { background: transparent; color: var(--foreground); }
  .page-host { padding: 8px calc(10px + env(safe-area-inset-right)) calc(var(--tabbar-height) + 24px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left)); gap: 12px; }
  .page { gap: 12px; }
  body[data-page="library"] .mobile-stats { display: block; }
  .mobile-stats .summary { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
  .mobile-stats .summary::-webkit-scrollbar { display: none; }
  .mobile-stats .summary__metric { flex: none; gap: 6px; padding: 6px 10px; border-radius: var(--radius-pill); background: var(--fill); }
  .page-title { font-size: 18px; }
  .filter-buttons { gap: 6px; }
  .filter-buttons > button { padding: 0 12px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .modal-backdrop { align-items: flex-end; padding: env(safe-area-inset-top) 0 0; }
  .modal { width: 100%; max-height: min(92vh, calc(100vh - 24px)); max-height: min(92dvh, calc(100dvh - 24px - env(safe-area-inset-top))); padding: 0; border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
  .modal--small, .modal--medium, .modal--large { width: 100%; }
  .modal__header { padding: 16px 16px 10px; }
  .modal__body { padding: 4px 16px 8px; }
  .modal__footer { margin: 0; padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); }
  .list-row { padding: 12px 10px; gap: 10px; }
  .row-actions { gap: 10px; }
}
