/* Theme tokens cover controls, overlays and all SLA states. */
:root {
  color-scheme: light;
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px;
  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px;
  --control-height: 40px; --control-small: 36px; --chip-height: 32px;
  --font-xs: 11px; --font-sm: 12px; --font-md: 13px; --font-body: 14px;
  --font-section: 16px; --font-title: 28px; --font-order: 22px; --font-timer: 32px;
  --page-padding: var(--space-8); --section-gap: var(--space-5);
  --sidebar-width: 240px; --branch-width: 256px;
  --page: #f4f6f8; --surface: #ffffff; --surface-soft: #edf1f4; --surface-hover: #dfe8ed;
  --text: #182637; --muted: #596879; --line: #dde3e9; --input-border: #c5ced8;
  --brand: #233e52; --brand-hover: #152d40; --on-brand: #ffffff; --focus: #1c69bc;
  --success: #186348; --success-bg: #e9f5ee;
  --warning: #855000; --warning-bg: #fff3d6; --warning-border: #e6cf9c;
  --critical: #ae2836; --critical-bg: #ffeaed; --critical-border: #edc2c7;
  --paused: #275fa0; --paused-bg: #eaf2ff; --shadow: #18263714;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #101820; --surface: #19242f; --surface-soft: #22313e; --surface-hover: #2d4050;
  --text: #edf3f9; --muted: #b0c0ce; --line: #344655; --input-border: #506577;
  --brand: #aacde5; --brand-hover: #c3e0f2; --on-brand: #132635; --focus: #86c2f8;
  --success: #85ddb1; --success-bg: #153c2d;
  --warning: #f3ce7c; --warning-bg: #43351b; --warning-border: #75623a;
  --critical: #ffadb6; --critical-bg: #47262e; --critical-border: #80505b;
  --paused: #a6cdff; --paused-bg: #233b57; --shadow: #00000055;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; font-size: var(--font-body); line-height: 1.4; }
button, input, select { font: inherit; }
button, summary { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }
button, input, select, summary { touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
.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; }
.app-header { min-height: 64px; padding: var(--space-2) var(--page-padding); background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: var(--space-5); }
.brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: var(--control-small); height: var(--control-small); flex: 0 0 var(--control-small); border-radius: var(--radius-md); background: var(--brand); color: var(--on-brand); font-size: 26px; line-height: 1; }
.brand-name { font-size: var(--font-section); font-weight: 750; letter-spacing: -.4px; }
.branch-name { color: var(--muted); font-size: var(--font-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; gap: var(--space-3); align-items: center; flex-shrink: 0; min-width: 0; }
.connection { display: flex; align-items: center; justify-content: center; width: var(--space-6); height: var(--control-height); flex-shrink: 0; }
.connection-dot { width: 8px; height: 8px; border-radius: 50%; background: #778493; }
.connection[data-state="online"] .connection-dot { background: var(--success); box-shadow: 0 0 0 4px var(--success-bg); }
.connection[data-state="offline"] .connection-dot { background: var(--warning); box-shadow: 0 0 0 4px var(--warning-bg); }
.profile-menu { position: relative; }
#profileName { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-menu summary { display: flex; align-items: center; gap: var(--space-2); height: var(--control-height); cursor: pointer; list-style: none; color: var(--muted); font-size: var(--font-md); }
.profile-menu summary::-webkit-details-marker { display: none; }
.avatar { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--surface-soft); color: var(--text); font-size: var(--font-sm); font-weight: 700; }
.menu-popover { position: absolute; right: 0; top: calc(100% + var(--space-2)); z-index: 10; background: var(--surface); padding: var(--space-2); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: 0 10px 30px var(--shadow); width: 220px; max-width: calc(100vw - 32px); }
.menu-caption, .menu-account { display: block; padding: 0 var(--space-2); }
.menu-caption { color: var(--muted); font-size: var(--font-sm); }
.menu-account { font-weight: 600; margin: var(--space-1) 0 var(--space-2); overflow-wrap: anywhere; }
.menu-action { min-height: var(--control-small); text-align: left; width: 100%; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--text); padding: var(--space-2); font-size: var(--font-md); }
.menu-action:hover { background: var(--page); }
.menu-link { display: block; text-decoration: none; }

.dashboard { padding: var(--space-4) var(--page-padding) var(--space-6); max-width: 2000px; margin: 0 auto; }
.workspace-heading { display: flex; justify-content: space-between; align-items: center; gap: var(--space-5); margin-bottom: var(--space-3); }
.eyebrow { color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: 1px; }
h1 { font-size: var(--font-title); line-height: 1.2; font-weight: 730; letter-spacing: -.7px; }
.branch-date { color: var(--muted); font-size: var(--font-md); }
.entry-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--space-3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 10px var(--space-3); margin-bottom: var(--section-gap); }
.number-form { display: flex; position: relative; gap: var(--space-2); }
input, select { min-width: 0; border: 1px solid var(--input-border); border-radius: var(--radius-md); height: var(--control-height); padding: 0 var(--space-3); font-size: var(--font-md); color: var(--text); background: var(--surface); }
input::placeholder { color: var(--muted); opacity: 1; }
#numberInput { width: 208px; padding-left: var(--space-8); font-variant-numeric: tabular-nums; }
.input-prefix { position: absolute; left: var(--space-3); top: 50%; transform: translateY(-50%); color: var(--muted); }
.primary-button, .secondary-button, .danger-button { min-height: var(--control-height); border-radius: var(--radius-md); padding: var(--space-2) var(--space-4); font-size: var(--font-md); font-weight: 600; border: 1px solid transparent; }
.primary-button { background: var(--brand); color: var(--on-brand); }
.primary-button:hover:not(:disabled) { background: var(--brand-hover); }
.add-btn { display: flex; align-items: center; justify-content: center; gap: var(--space-2); }
.add-btn span { font-size: 20px; line-height: 1; }
.secondary-button { background: var(--surface); border-color: var(--input-border); color: var(--text); }
.sound-toggle { height: var(--control-height); display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-1); border: 0; background: transparent; color: var(--muted); font-size: var(--font-sm); }
#soundIcon { font-size: 18px; }
.switch-track { position: relative; width: 28px; height: 16px; border-radius: 20px; background: #7e8a96; margin-left: 3px; }
.switch-track::after { content: ""; position: absolute; left: 3px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: #ffffff; }
.sound-toggle[aria-pressed="true"] { color: var(--success); }
.sound-toggle[aria-pressed="true"] .switch-track { background: var(--success); }
.sound-toggle[aria-pressed="true"] .switch-track::after { left: 15px; }
.workspace-grid { display: grid; grid-template-columns: minmax(0, 1fr) var(--sidebar-width); align-items: start; gap: var(--section-gap); }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); min-height: var(--space-6); }
h2 { display: flex; align-items: center; gap: var(--space-2); font-size: var(--font-section); font-weight: 680; }
.count-badge { display: inline-flex; align-items: center; justify-content: center; min-width: var(--space-5); height: var(--space-5); padding: 0 var(--space-1); background: var(--surface-soft); border-radius: var(--radius-sm); color: var(--muted); font-size: var(--font-xs); font-weight: 650; font-variant-numeric: tabular-nums; }
.state-summary { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); margin: var(--space-2) 0 var(--space-3); font-size: var(--font-xs); color: var(--muted); }
.state-summary span { display: inline-flex; gap: var(--space-1); align-items: center; }
.state-summary span::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--muted); }
.summary-normal::before { background: var(--success) !important; }
.summary-warning::before { background: var(--warning) !important; }
.summary-critical::before { background: var(--critical) !important; }
.summary-paused::before { background: var(--paused) !important; }
.orders { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr)); gap: var(--space-3); align-items: start; }
.order-card { --accent: var(--success); --tint: var(--success-bg); background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: var(--radius-lg); padding: var(--space-4); min-width: 0; }
.order-card.yellow { --accent: var(--warning); --tint: var(--warning-bg); }
.order-card.red { --accent: var(--critical); --tint: var(--critical-bg); border-color: var(--critical-border); border-top-color: var(--accent); }
.order-card.pause { --accent: var(--paused); --tint: var(--paused-bg); }
.order-card-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-1); }
.number { font-size: var(--font-order); line-height: 1.2; font-weight: 750; letter-spacing: -.5px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.status { display: inline-flex; align-items: center; gap: var(--space-1); padding: var(--space-1) var(--space-2); border-radius: var(--radius-sm); font-size: var(--font-xs); line-height: 1.2; font-weight: 650; color: var(--accent); background: var(--tint); white-space: nowrap; }
.time { font-size: var(--font-timer); line-height: 1.15; letter-spacing: -1px; font-weight: 680; font-variant-numeric: tabular-nums; margin-top: var(--space-2); overflow-wrap: anywhere; }
.time-caption { font-size: var(--font-xs); color: var(--muted); margin-bottom: var(--space-3); }
/* Resume has a longer label: preserve its intrinsic width and wrap only if needed. */
.card-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.card-actions button { flex: 1 0 auto; min-width: 0; height: var(--control-small); border-radius: var(--radius-md); padding: 0 var(--space-1); border: 1px solid var(--line); font-size: var(--font-sm); font-weight: 650; white-space: nowrap; }
.pause-btn { background: var(--surface); color: var(--muted); }
.complete-btn { background: var(--surface-soft); border-color: var(--line) !important; color: var(--text); }
.card-actions button:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--input-border); }
.available-section { position: sticky; top: var(--space-4); min-width: 0; padding: var(--space-3); background: var(--surface-soft); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.available-section h2 { font-size: var(--font-body); gap: var(--space-1); flex-wrap: wrap; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; width: var(--control-height); height: var(--control-height); flex: 0 0 var(--control-height); border: 0; background: transparent; border-radius: var(--radius-md); color: var(--muted); font-size: 20px; }
.icon-button:hover:not(:disabled) { background: var(--surface-hover); }
.section-hint { color: var(--muted); font-size: var(--font-xs); margin: var(--space-1) 0 var(--space-3); }
.number-rack { display: grid; grid-template-columns: repeat(auto-fill, 40px); gap: var(--space-2); max-height: min(400px, calc(100dvh - 320px)); overflow-y: auto; padding: var(--space-1); margin: calc(-1 * var(--space-1)); }
.number-chip { min-width: 0; height: var(--chip-height); padding: 0; border: 1px solid var(--input-border); background: var(--surface); border-radius: var(--radius-sm); color: var(--text); font-size: var(--font-md); font-weight: 650; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.number-chip:hover:not(:disabled) { border-color: var(--text); background: var(--surface-hover); }
.number-chip-wide { grid-column: span 2; }
.free-empty { color: var(--muted); font-size: var(--font-sm); padding: var(--space-2) 0; }
.empty-state { min-height: 180px; display: flex; align-items: center; justify-content: center; flex-direction: column; text-align: center; padding: var(--space-5); border: 1px dashed var(--input-border); border-radius: var(--radius-lg); }
.empty-icon { display: grid; place-items: center; width: var(--control-height); height: var(--control-height); border-radius: 50%; background: var(--surface-soft); color: var(--muted); font-size: 20px; margin-bottom: var(--space-2); }
.empty-state h3 { font-size: var(--font-section); font-weight: 650; margin-bottom: var(--space-1); }
.empty-state p { max-width: 320px; color: var(--muted); font-size: var(--font-sm); }
.message { position: relative; z-index: 20; padding: var(--space-3) var(--page-padding); background: var(--warning-bg); color: var(--warning); border-bottom: 1px solid var(--warning-border); overflow-wrap: anywhere; }
.connection-warning { border: 1px solid var(--warning-border); color: var(--warning); background: var(--warning-bg); padding: var(--space-2) var(--space-3); border-radius: var(--radius-md); margin: 0 0 var(--space-4); font-size: var(--font-md); }
.boot-state { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }
.access-state { max-width: 640px; margin: 50px auto; padding: 28px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
.access-state p { color: var(--muted); margin-top: var(--space-3); }
.login-screen { min-height: 100dvh; display: grid; place-items: center; padding: 32px 20px; }
.login-panel { position: relative; width: 100%; max-width: 380px; padding: var(--space-8); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: 0 8px 32px var(--shadow); }
.login-panel .brand-mark { margin-bottom: var(--space-4); }
.login-panel h1 { font-size: 25px; }
.login-intro { margin-top: var(--space-2); color: var(--muted); font-size: var(--font-md); }
.login-form { display: grid; gap: var(--space-2); margin-top: var(--space-6); }
.login-form label { font-weight: 600; font-size: var(--font-sm); }
.login-form input { width: 100%; margin-bottom: var(--space-2); }
.login-form button { margin-top: var(--space-2); }
.login-help { font-size: var(--font-xs); color: var(--muted); margin-top: var(--space-5); }
dialog { background: var(--surface); width: min(440px, calc(100% - 32px)); padding: var(--space-5); border: 1px solid var(--line); border-radius: var(--radius-lg); color: var(--text); box-shadow: 0 16px 64px var(--shadow); }
dialog::backdrop { background: #13233366; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
dialog p { font-size: var(--font-md); color: var(--muted); margin: var(--space-2) 0 var(--space-5); }
dialog label { display: block; font-size: var(--font-sm); font-weight: 600; margin-bottom: var(--space-2); }
dialog select { width: 100%; }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-6); }
.danger-button { color: var(--critical); background: var(--critical-bg); border-color: var(--critical-border); }

.brand > div, .active-section { min-width: 0; }
.available-section .icon-button { width: var(--chip-height); height: var(--chip-height); flex-basis: var(--chip-height); }
.login-theme { position: absolute; top: var(--space-5); right: var(--space-5); }
.theme-toggle { border: 1px solid var(--line); background: var(--surface); color: var(--text); }

/* The wrapper is the only width owner. Both trigger and popup fill its border box. */
#branchSwitcher { position: relative; width: var(--branch-width); min-width: 0; flex-shrink: 0; }
.branch-trigger { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); width: 100%; height: var(--control-height); padding: 0 var(--space-3); border: 1px solid var(--input-border); border-radius: var(--radius-md); background: var(--surface); color: var(--text); font-size: var(--font-md); text-align: left; }
.branch-trigger:hover:not(:disabled), .branch-trigger[aria-expanded="true"] { background: var(--surface-soft); border-color: var(--focus); }
.branch-trigger-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.branch-chevron { flex-shrink: 0; color: var(--muted); }
.branch-popover { position: absolute; left: 0; top: calc(100% + var(--space-2)); z-index: 30; width: 100%; min-width: 0; max-height: min(300px, calc(100dvh - 160px)); display: flex; flex-direction: column; gap: var(--space-2); overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-2); background: var(--surface); box-shadow: 0 12px 36px var(--shadow); }
.branch-popover > .menu-caption { padding: 0 var(--space-1); font-size: var(--font-xs); }
.branch-search { display: block; width: 100%; min-width: 0; height: var(--control-small); flex-shrink: 0; padding: 0 var(--space-2); background: var(--page); }
.branch-options { min-height: 0; min-width: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }
.branch-option { width: 100%; min-width: 0; height: var(--control-height); display: flex; gap: var(--space-2); align-items: center; text-align: left; border: 1px solid transparent; border-radius: var(--radius-md); padding: 0 var(--space-2); color: var(--text); background: transparent; font-size: var(--font-md); }
.branch-option:hover, .branch-option.is-highlighted { background: var(--surface-hover); }
.branch-option[aria-selected="true"] { border-color: var(--input-border); background: var(--surface-soft); }
.branch-option.is-highlighted { outline: 2px solid var(--focus); outline-offset: -2px; }
.branch-code { flex-shrink: 0; max-width: 30%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: var(--font-sm); font-variant-numeric: tabular-nums; }
.branch-option-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.branch-check { color: var(--success); width: var(--space-4); flex-shrink: 0; }
.branch-empty { color: var(--muted); padding: var(--space-3) var(--space-2); text-align: center; font-size: var(--font-sm); }

@media (max-width: 1199px) {
  .workspace-grid { grid-template-columns: minmax(0, 1fr); }
  .available-section { position: static; }
  .number-rack { max-height: 200px; }
}
@media (max-width: 767px) {
  :root { --page-padding: var(--space-4); --branch-width: 200px; }
  .app-header { gap: var(--space-3); }
  .header-actions { gap: var(--space-2); }
  #profileName, .branch-date { display: none; }
  .brand { gap: var(--space-2); }
  .brand-name { font-size: var(--font-body); }
  .branch-name { font-size: var(--font-xs); }
  .entry-toolbar { gap: var(--space-2); }
  .number-form { flex: 1 1 280px; }
  #numberInput { min-width: 0; flex: 1; width: 130px; }
  .orders { grid-template-columns: repeat(auto-fill, minmax(min(195px, 100%), 1fr)); }
  .message { padding: var(--space-3) var(--page-padding); }
}
@media (max-width: 600px) {
  :root { --branch-width: min(240px, calc(100vw - 176px)); }
  .app-header { flex-wrap: wrap; }
  .header-actions { margin-left: auto; }
  /* Still anchored below its trigger: never turn this into a viewport-wide panel. */
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; } }
