:root {
  --bg: #f5f5f7; --surface: #ffffff; --surface-2: #fbfbfd; --sidebar: rgba(246,246,248,.82);
  --text: #1d1d1f; --text-2: #6e6e73; --text-3: #a1a1a6; --hair: rgba(0,0,0,.08);
  --accent: #0071e3; --accent-soft: rgba(0,113,227,.10);
  --ring: #ff9f0a; --ring-soft: rgba(255,159,10,.14);
  --live: #30d158; --live-ink: #1e8e3e; --live-soft: rgba(48,209,88,.14);
  --warn: #ff3b30; --chip: #f2f2f7;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --surface: #1c1c1e; --surface-2: #232325; --sidebar: rgba(28,28,30,.78);
    --text: #f5f5f7; --text-2: #a1a1a6; --text-3: #6e6e73; --hair: rgba(255,255,255,.09);
    --accent: #0a84ff; --accent-soft: rgba(10,132,255,.16);
    --ring-soft: rgba(255,159,10,.18); --live-ink: #30d158; --live-soft: rgba(48,209,88,.16);
    --chip: #2c2c2e; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --surface: #1c1c1e; --surface-2: #232325; --sidebar: rgba(28,28,30,.78);
  --text: #f5f5f7; --text-2: #a1a1a6; --text-3: #6e6e73; --hair: rgba(255,255,255,.09);
  --accent: #0a84ff; --accent-soft: rgba(10,132,255,.16);
  --ring-soft: rgba(255,159,10,.18); --live-ink: #30d158; --live-soft: rgba(48,209,88,.16);
  --chip: #2c2c2e; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; letter-spacing: -0.01em; }
[hidden] { display: none !important; }
h1 { font: 700 28px/1.15 var(--font-display); letter-spacing: -0.025em; margin: 0; }
h2 { font: 600 13px/1.3 var(--font); color: var(--text-2); text-transform: none; margin: 0 0 10px; }
.mt { margin-top: 24px; }
.muted { color: var(--text-2); margin: 2px 0 0; }
.small { font-size: 12px; }
.error { color: var(--warn); min-height: 18px; margin: 0; font-size: 13px; }
button { font: inherit; color: inherit; }
.btn-primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 600; cursor: pointer; }
.btn-primary:disabled { opacity: .5; }
.btn-plain { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 6px 8px; border-radius: 8px; }
.btn-plain:hover { background: var(--accent-soft); }
.brand-mark { font: 800 15px/1 var(--font-display); letter-spacing: .08em; color: var(--surface); background: var(--text); border-radius: 10px; width: 48px; height: 48px; display: grid; place-items: center; }
.brand-mark.sm { width: 32px; height: 32px; font-size: 11px; border-radius: 8px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); padding: 32px 28px; display: grid; gap: 14px; }
.login-card h1 { margin-top: 6px; }
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--text-2); }
.login-card input { font: inherit; font-size: 16px; color: var(--text); background: var(--surface-2); border: 1px solid var(--hair); border-radius: 10px; padding: 11px 12px; outline: none; }
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

/* Shell */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100%; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--sidebar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-right: 1px solid var(--hair); display: flex; flex-direction: column; padding: 18px 12px; gap: 18px; }
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.seat { min-width: 0; flex: 1; }
.seat-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat select { width: 100%; font: inherit; font-weight: 600; color: var(--text); background: transparent; border: 0; padding: 2px 0; cursor: pointer; }
nav { display: grid; gap: 2px; }
nav a { white-space: nowrap; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 500; cursor: pointer; }
nav a:hover:not(.soon) { background: var(--hair); }
nav a.active { background: var(--accent); color: #fff; }
nav a.soon { color: var(--text-3); cursor: default; }
nav .ico { width: 18px; text-align: center; opacity: .8; }
nav .tag { margin-left: auto; font-size: 11px; background: var(--chip); color: var(--text-2); padding: 1px 7px; border-radius: 99px; }
.nav-live { margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: var(--ring); box-shadow: 0 0 0 3px var(--ring-soft); }
.nav-live.on_call { background: var(--live); box-shadow: 0 0 0 3px var(--live-soft); }
.sidebar-foot { margin-top: auto; display: flex; justify-content: space-between; }
main { min-width: 0; padding: 28px 36px 48px; }
.view-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; }
.head-actions { display: flex; align-items: center; gap: 8px; }
.fresh { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.fresh.stale { color: var(--ring); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.stat .n { font: 700 28px/1.1 var(--font-display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--text-2); margin-top: 4px; }
.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; align-items: start; }
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.list { display: grid; }
.row { display: grid; grid-template-columns: 76px 1fr auto; gap: 12px; align-items: center; padding: 11px 4px; border-top: 1px solid var(--hair); }
.row:first-child { border-top: 0; }
.row .when { font-weight: 600; font-variant-numeric: tabular-nums; }
.row .when small { display: block; font-weight: 400; color: var(--text-2); font-size: 12px; }
.row .who { min-width: 0; }
.row .who b { font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .who span { color: var(--text-2); font-size: 12px; }
.chip { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--chip); color: var(--text-2); white-space: nowrap; }
.chip.appointment { background: var(--accent-soft); color: var(--accent); }
.chip.callback { background: var(--ring-soft); color: #c77700; }
.chip.unresolved { background: rgba(255,59,48,.10); color: var(--warn); }
.empty { color: var(--text-3); padding: 18px 4px; }
.week { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 12px; }
.week div b { display: block; font: 600 20px/1.2 var(--font-display); font-variant-numeric: tabular-nums; }
.week div span { font-size: 12px; color: var(--text-2); }
.grade-line { margin-top: 12px; font-size: 13px; color: var(--text-2); }

/* Now Dialing */
.now-card { background: var(--surface); border-radius: 24px; box-shadow: var(--shadow); padding: 44px 48px; min-height: 380px; display: grid; align-content: center; position: relative; overflow: hidden; transition: box-shadow .4s ease; }
.now-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 6px; background: var(--text-3); transition: background .4s ease; }
.now-card.calling::before { background: var(--ring); }
.now-card.on_call::before { background: var(--live); }
.now-status { display: inline-flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; color: var(--text-2); margin-bottom: 18px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-3); }
.calling .dot { background: var(--ring); animation: pulse 1.4s ease-in-out infinite; }
.on_call .dot { background: var(--live); }
.calling .now-status { color: #c77700; }
.on_call .now-status { color: var(--live-ink); }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 var(--ring-soft); } 50% { box-shadow: 0 0 0 8px var(--ring-soft); } }
.now-name { font: 700 clamp(40px, 5.6vw, 76px)/1.02 var(--font-display); letter-spacing: -0.035em; margin: 0; color: var(--text); overflow-wrap: anywhere; }
.now-phone { font: 500 clamp(20px, 2.2vw, 30px)/1.2 var(--font-display); color: var(--text-2); margin-top: 10px; font-variant-numeric: tabular-nums; }
.now-facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; margin-top: 34px; padding-top: 24px; border-top: 1px solid var(--hair); }
.fact span { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.fact b { font: 600 18px/1.25 var(--font-display); overflow-wrap: anywhere; }
.now-note { margin-top: 22px; background: var(--surface-2); border-radius: 12px; padding: 14px 16px; font-size: 15px; }
.now-note span { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.idle-msg { text-align: center; color: var(--text-2); }
.idle-msg b { display: block; font: 600 26px/1.2 var(--font-display); color: var(--text); margin-bottom: 6px; letter-spacing: -0.02em; }
.now-today { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.now-today .stat .n { font-size: 24px; }
.now:fullscreen { background: var(--bg); padding: 40px; overflow: auto; }
.now:fullscreen .now-card { min-height: 60vh; }

/* Sheets */
main:has(.sheets-view:not([hidden])) { padding: 0; }
.sheets-layout { display: grid; grid-template-columns: 248px minmax(0, 1fr); height: 100vh; }
.sheets-layout.with-script { grid-template-columns: 248px minmax(0, 1fr) 360px; }
.sheet-list { border-right: 1px solid var(--hair); overflow-y: auto; padding: 22px 10px; background: var(--surface-2); }
.sheet-list h2 { padding: 0 8px; }
.sheet-item { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 10px; padding: 9px 10px; cursor: pointer; margin-bottom: 2px; }
.sheet-item:hover { background: var(--hair); }
.sheet-item.active { background: var(--accent-soft); }
.sheet-item b { display: flex; align-items: center; gap: 6px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-item b i { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--ring); }
.sheet-item b i.on_call { background: var(--live); }
.sheet-item > span { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-2); margin-top: 2px; }
.grade { display: inline-block; font-weight: 700; font-size: 10.5px; line-height: 16px; padding: 0 5px; border-radius: 5px; background: var(--chip); color: var(--text); }
.grade:first-of-type { margin-left: auto; }
.sheet-main { min-width: 0; display: flex; flex-direction: column; height: 100vh; padding: 22px 24px 10px; }
.sheet-toolbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.with-script .sheet-toolbar { flex-wrap: wrap; }
.sheet-title { min-width: 0; }
.sheet-title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar-right { display: flex; align-items: center; gap: 8px; flex: none; }
.search, .filter { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--hair); border-radius: 9px; padding: 7px 11px; outline: none; }
.search { width: 220px; }
.with-script .search { width: 160px; }
.toolbar-right a.btn-plain { text-decoration: none; font-weight: 500; }
.search:focus, .filter:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn-pill { font-weight: 600; background: var(--chip); color: var(--text); border: 0; border-radius: 99px; padding: 7px 14px; cursor: pointer; }
.btn-pill[aria-pressed="true"] { background: var(--text); color: var(--surface); }
.live-bar { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; cursor: pointer; border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; font-weight: 600; background: var(--ring-soft); color: #b36b00; }
.live-bar.on_call { background: var(--live-soft); color: var(--live-ink); }
.live-bar .dot { flex: none; }
.live-bar.calling .dot { background: var(--ring); animation: pulse 1.4s ease-in-out infinite; }
.live-bar.on_call .dot { background: var(--live); }
.live-bar small { margin-left: auto; font-weight: 500; opacity: .8; }
.grid-wrap { flex: 1; min-height: 0; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; position: relative; }
.grid-head, .grow { display: grid; grid-template-columns: var(--cols); min-width: max-content; }
.grid-head { position: sticky; top: 0; z-index: 2; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-bottom: 1px solid var(--hair); }
.grid-head div { font-size: 12px; font-weight: 600; color: var(--text-2); padding: 10px 10px; cursor: pointer; user-select: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid-head div:hover { color: var(--text); }
.grid-head div.sorted { color: var(--accent); }
.grid-body { position: relative; }
.grid-rows { position: absolute; left: 0; right: 0; top: 0; }
.grow { height: 40px; align-items: center; border-bottom: 1px solid var(--hair); background: var(--surface); }
.grow.tinted { background: color-mix(in srgb, var(--row-tint) 42%, var(--surface)); }
:root[data-theme="dark"] .grow.tinted { background: color-mix(in srgb, var(--row-tint) 14%, var(--surface)); box-shadow: inset 3px 0 0 var(--row-tint); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .grow.tinted { background: color-mix(in srgb, var(--row-tint) 14%, var(--surface)); box-shadow: inset 3px 0 0 var(--row-tint); } }
.grow:hover { filter: brightness(0.985); }
.grow > div { padding: 0 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.grow .rn { color: var(--text-3); font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; }
.grow .rn a { color: inherit; text-decoration: none; }
.grow .rn a:hover { color: var(--accent); }
.grow.live { box-shadow: inset 4px 0 0 var(--ring), inset 0 0 0 1px var(--ring); background: color-mix(in srgb, var(--ring) 16%, var(--surface)); }
.grow.live.on_call { box-shadow: inset 4px 0 0 var(--live), inset 0 0 0 1px var(--live); background: color-mix(in srgb, var(--live) 14%, var(--surface)); }
.grow .name { font-weight: 600; }
.rchip { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--chip); color: var(--text-2); }
.rchip.good { background: var(--accent-soft); color: var(--accent); }
.rchip.win { background: var(--live-soft); color: var(--live-ink); }
.rchip.bad { background: rgba(255,59,48,.10); color: var(--warn); }
.rchip.wait { background: rgba(175,82,222,.12); color: #8e44ad; }
.rchip.next { background: var(--ring-soft); color: #b36b00; }
.grid-empty { padding: 40px; text-align: center; color: var(--text-2); }
.grid-foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); padding: 8px 4px 0; }
.script-panel { border-left: 1px solid var(--hair); background: var(--surface); display: flex; flex-direction: column; height: 100vh; padding: 18px 18px 12px; min-width: 0; }
.script-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.script-head b { font: 600 17px/1.2 var(--font-display); }
.script-actions { display: flex; gap: 2px; }
.script-view { flex: 1; overflow-y: auto; white-space: pre-wrap; font-size: var(--script-size, 16px); line-height: 1.55; padding-right: 4px; }
.script-view .empty { font-size: 14px; }
.script-text { flex: 1; resize: none; font: inherit; font-size: 14px; line-height: 1.5; color: var(--text); background: var(--surface-2); border: 1px solid var(--hair); border-radius: 10px; padding: 12px; outline: none; }
.script-text:focus { border-color: var(--accent); }
.script-note { margin-top: 8px; }

@media (prefers-reduced-motion: reduce) { .calling .dot { animation: none; } * { transition: none !important; } }
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 10px; }
  nav { grid-auto-flow: column; overflow-x: auto; min-width: 0; flex: 1 1 100%; order: 3; justify-content: start; }
  nav .tag { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; }
  main { padding: 20px 16px 40px; }
  .stats, .now-today { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cols { grid-template-columns: 1fr; }
  .now-card { padding: 28px 22px; min-height: 300px; }
  .now-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sheets-layout, .sheets-layout.with-script { grid-template-columns: minmax(0, 1fr); height: auto; }
  .sheet-list { border-right: 0; display: flex; gap: 6px; overflow-x: auto; padding: 12px 16px; }
  .sheet-list h2 { display: none; }
  .sheet-item { flex: none; width: auto; max-width: 220px; }
  .sheet-main { height: 80vh; padding: 12px 16px; }
  .sheet-toolbar { flex-direction: column; align-items: stretch; }
  .sheet-title h1 { font-size: 22px; }
  .toolbar-right { flex-wrap: wrap; flex: 1 1 auto; }
  .search, .with-script .search { width: auto; flex: 1 1 100%; }
  .script-panel { height: 60vh; border-left: 0; border-top: 1px solid var(--hair); }
}
