:root {
  color-scheme: light;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --accent: #2563eb;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b91c1c;
  --ink: #172033;
  --muted: #64748b;
  --line: #dbe4ea;
  --surface: #ffffff;
  --background: #eef5f5;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--background); color: var(--ink); min-height: 100vh; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
.shell { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: 24px 0 48px; }
.header { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.logo { width: 72px; height: 72px; object-fit: contain; background: white; border-radius: 14px; padding: 6px; }
.header h1 { margin: 0; font-size: clamp(1.4rem, 4vw, 2.2rem); }
.header p { margin: 4px 0 0; color: var(--muted); }
.header-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 22px; box-shadow: 0 12px 35px rgba(15, 52, 65, .08); margin-bottom: 18px; }
.card h2, .card h3 { margin-top: 0; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.six { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.station-picker { width: min(540px, 100%); margin-left: auto; margin-right: auto; }
.station-picker h2 { margin-bottom: 10px; }
.station-help { margin: 0 0 16px; color: #334e79; font-size: .9rem; }
.station-list { grid-template-columns: 1fr; }
.choice { border: 2px solid var(--line); background: white; color: var(--ink); padding: 16px; border-radius: 14px; text-align: left; }
.choice:hover, .choice.active { border-color: var(--brand); background: #ecfdf5; }
.choice strong { display: block; font-size: 1.05rem; }
.choice span { color: var(--muted); font-size: .9rem; }
.field { display: grid; gap: 7px; margin-bottom: 14px; }
.field label { font-weight: 700; }
.field input, .field select { width: 100%; border: 1px solid #b9c8d1; border-radius: 11px; padding: 12px 13px; background: white; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 50px; }
.password-toggle { position: absolute; inset-block: 1px; right: 2px; width: 44px; border: 0; border-radius: 9px; background: transparent; color: var(--ink); font-size: 1.2rem; }
.password-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions.center { justify-content: center; }
.actions.between { justify-content: space-between; }
.spaced-top { margin-top: 18px; }
.btn { border: 0; border-radius: 11px; padding: 11px 16px; font-weight: 750; background: #e2e8f0; color: var(--ink); }
.btn.primary { background: var(--brand); color: white; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.blue { background: var(--accent); color: white; }
.btn.success { background: var(--success); color: white; }
.btn.warning { background: var(--warning); color: white; }
.btn.danger { background: var(--danger); color: white; }
.btn.large { padding: 15px 22px; font-size: 1.05rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.pill { display: inline-flex; align-items: center; border-radius: 999px; background: #dff6f1; color: var(--brand-dark); padding: 6px 11px; font-weight: 750; }
.summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.summary-item { background: white; border: 1px solid var(--line); border-radius: 14px; padding: 15px; }
.summary-item span { color: var(--muted); font-size: .85rem; }
.summary-item strong { display: block; font-size: 1.8rem; margin-top: 4px; }
.queue-list { display: grid; gap: 10px; }
.queue-row { display: flex; justify-content: space-between; gap: 16px; align-items: center; border: 1px solid var(--line); border-radius: 13px; padding: 14px; }
.queue-no { font-size: 1.5rem; font-weight: 900; color: var(--brand-dark); }
.queue-meta { color: var(--muted); font-size: .9rem; }
.queue-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.queue-actions .btn { padding: 8px 10px; font-size: .85rem; }
.ticket { text-align: center; }
.ticket-number { font-size: clamp(3.5rem, 15vw, 7rem); font-weight: 950; color: var(--brand); line-height: 1; margin: 18px 0; }
.ticket-status { padding: 14px; border-radius: 12px; background: #eef2ff; font-weight: 750; }
.ticket-status.called { background: #fef3c7; color: #92400e; }
.ticket-status.done { background: #dcfce7; color: #166534; }
.ticket-status.cancelled { background: #fee2e2; color: #991b1b; }
.live-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.live-box { border: 1px solid var(--line); border-radius: 13px; padding: 14px; }
.live-value { font-size: 1.8rem; font-weight: 900; }
.toast { position: fixed; right: 18px; bottom: 18px; max-width: min(420px, calc(100% - 36px)); background: #172033; color: white; padding: 13px 16px; border-radius: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.22); z-index: 30; }
.connection { font-size: .82rem; color: var(--muted); }
.connection.online { color: var(--success); }
.display-body { background: #071f2a; color: white; }
.display-body .shell { width: min(1500px, calc(100% - 36px)); }
.display-body .card { background: #0c2e3b; border-color: #28505d; color: white; }
.display-body .muted { color: #a9bdc6; }
.display-number { font-size: clamp(5rem, 17vw, 12rem); font-weight: 950; color: #facc15; line-height: 1; }
.display-counter { font-size: clamp(2rem, 6vw, 4rem); font-weight: 850; }
.counter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.counter-card { background: #123f4e; border: 2px solid #2c6070; border-radius: 16px; padding: 18px; text-align: center; }
.counter-card .queue-no { color: #facc15; font-size: 2.4rem; }
.announcement { text-align: center; padding: 28px; border: 2px solid #facc15; }
.page-tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.page-tabs button.active { background: #facc15; color: #172033; }
.empty { padding: 18px; color: var(--muted); text-align: center; }

.display-start-overlay { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1000; border: 0; background: rgba(15, 23, 42, .94); color: white; font: inherit; font-size: clamp(1.5rem, 4vw, 3rem); cursor: pointer; padding: 2rem; }
.clipboard-helper { position: fixed; left: -9999px; top: 0; }

/* Public displays are viewport layouts: only their content, not the page, may shrink. */
.display-body { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }
.display-body .shell {
  width: min(1500px, calc(100% - 24px));
  height: 100vh; height: 100dvh;
  padding: clamp(8px, 1.3vh, 16px) 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr);
  gap: clamp(7px, 1.2vh, 14px);
  overflow: hidden;
}
.display-body .header { min-width: 0; margin: 0; gap: 10px; flex-wrap: nowrap; }
.display-body .header > div:nth-child(2) { min-width: 0; }
.display-body .header h1 { font-size: clamp(1.2rem, 2.1vw, 2rem); line-height: 1.12; }
.display-body .header p { font-size: clamp(.75rem, 1.05vw, 1rem); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.display-body .logo { width: clamp(46px, 7vh, 68px); height: clamp(46px, 7vh, 68px); flex: none; }
.display-body .header-actions { min-width: 0; flex-wrap: nowrap; gap: 6px; }
.display-body .header-actions select { max-width: clamp(110px, 14vw, 190px); }
.display-body .header-actions .btn { padding: 8px 10px; white-space: nowrap; }
.display-body .card { margin: 0; min-height: 0; box-shadow: none; }
.display-body .announcement {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(2px, .8vh, 9px); padding: clamp(8px, 1.4vh, 20px);
  overflow: hidden;
}
.display-body .display-number { font-size: clamp(4rem, min(15vw, 22vh), 11rem); line-height: .98; }
.display-body .display-counter { font-size: clamp(1.6rem, min(4vw, 7vh), 3.5rem); line-height: 1.1; }
.display-body .counter-card { min-width: 0; padding: clamp(3px, .55vh, 7px); display: flex; flex-direction: column; justify-content: center; line-height: 1.14; }
.display-body .counter-card strong, .display-body .counter-card .muted { overflow-wrap: break-word; }
.display-body .counter-card .queue-no { font-size: clamp(1.2rem, 2.1vw, 2rem); line-height: 1.1; }
.display-body .empty { padding: 8px; text-align: left; }

.display-body .shell { width: min(1880px, calc(100% - 24px)); }
.display-body .display-station-name { max-width: 100%; color: #5eead4; font-size: clamp(1rem, 1.65vw, 1.8rem); font-weight: 800; line-height: 1.2; text-wrap: balance; }
.display-body .announcement > .muted { font-size: clamp(1rem, 1.7vw, 1.7rem); font-weight: 750; letter-spacing: .16em; text-transform: uppercase; }
.display-body .display-number { font-size: clamp(4.5rem, min(16vw, 26vh), 14rem); line-height: 1; }
.display-body .display-counter { font-size: clamp(1.6rem, min(3.7vw, 7vh), 4rem); }
.display-body .display-sidebar { min-width: 0; min-height: 0; display: grid; gap: clamp(7px, 1.1vh, 13px); }
.display-body .side-card, .master-display #panel { min-width: 0; min-height: 0; padding: clamp(9px, 1.3vh, 18px); overflow: hidden; }
.display-body .side-card h2, .master-display #panel h3 { margin: 0 0 clamp(5px, .8vh, 10px); color: #5eead4; font-size: clamp(1.1rem, 1.6vw, 1.7rem); line-height: 1.15; }
.display-body .counter-grid { min-width: 0; min-height: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: max-content; gap: clamp(4px, .7vh, 9px); align-content: start; }
.display-body .counter-card { min-width: 0; min-height: clamp(66px, 9vh, 100px); padding: clamp(4px, .65vh, 8px); gap: 1px; }
.display-body .counter-card strong { font-size: clamp(.82rem, 1.1vw, 1.1rem); line-height: 1.12; }
.display-body .counter-card .queue-no { font-size: clamp(1.5rem, 2.6vw, 2.65rem); line-height: 1.02; }
.display-body .counter-card .muted { font-size: clamp(.7rem, .9vw, .9rem); line-height: 1.12; }
.display-body .counter-grid > .counter-card:only-child { grid-column: 1 / -1; }
.display-body .waiting-card { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.display-body .waiting-card .grid.six { min-height: 0; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(4px, .6vh, 8px); align-content: start; }
.display-body .waiting-card .counter-card { min-height: clamp(36px, 5vh, 52px); padding: 3px 6px; }
.display-body .waiting-card .counter-card .queue-no { font-size: clamp(1.2rem, 1.8vw, 1.8rem); }
.display-body .waiting-more { margin-top: 4px; color: #a9bdc6; font-size: clamp(.75rem, 1vw, .95rem); font-weight: 700; }

.station-display #displaySection, .master-display .display-stage {
  min-width: 0; min-height: 0; display: grid;
  grid-template-columns: minmax(0, 1.42fr) minmax(330px, 1fr);
  gap: clamp(7px, 1.1vh, 13px);
}
.station-display .display-lower { grid-template-rows: minmax(0, 1fr) minmax(140px, 27%); }
.station-display .display-lower > .card { display: flex; flex-direction: column; }
.station-display .display-lower .counter-grid { flex: 1; }

.master-display .shell { grid-template-rows: auto minmax(0, 1fr); }
.master-display .display-sidebar { grid-template-rows: auto minmax(0, 1fr); }
.master-display .page-tabs { min-height: 0; margin: 0; gap: 6px; overflow: hidden; }
.master-display .page-tabs .btn { padding: 7px 11px; font-size: clamp(.8rem, 1.15vw, 1rem); }
.master-display #panel { display: grid; grid-template-rows: auto auto minmax(0, 1fr) minmax(130px, 26%); gap: clamp(4px, .6vh, 8px); }
.master-display #panel h2, .master-display #panel p { margin: 0; }
.master-display #panel h2 { font-size: clamp(1rem, 1.4vw, 1.35rem); line-height: 1.15; }
.master-display #panel p { font-size: clamp(.75rem, .95vw, .95rem); }
.master-display .master-side-section { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.master-display .master-side-section .counter-grid { min-height: 0; }
.master-display .counter-card { min-height: clamp(49px, 7vh, 72px); padding: 3px 5px; }
.master-display .counter-card strong { font-size: clamp(.8rem, .95vw, 1rem); }
.master-display .counter-card .queue-no { font-size: clamp(1.35rem, 1.9vw, 2rem); }
.master-display .counter-card .muted { font-size: clamp(.65rem, .78vw, .8rem); }
.master-display .waiting-card { border-top: 1px solid #28505d; padding-top: clamp(4px, .6vh, 8px); }
.master-display .waiting-card .counter-card { min-height: clamp(36px, 5vh, 52px); }

@media (max-height: 650px) {
  .display-body .shell { padding: 6px 0; gap: 6px; }
  .station-display .display-lower { grid-template-rows: minmax(0, 1fr) minmax(110px, 24%); }
  .station-display .counter-card { min-height: 56px; padding: 3px; }
  .station-display .counter-card .queue-no { font-size: 1.45rem; }
  .master-display #panel { grid-template-rows: auto auto minmax(0, 1fr) minmax(105px, 23%); }
  .master-display .counter-card { min-height: 46px; padding: 2px; }
  .master-display .waiting-card .counter-card { min-height: 32px; padding: 1px 4px; }
}

@media (max-width: 760px) {
  .grid.two, .grid.three, .grid.six, .summary, .live-grid, .counter-grid { grid-template-columns: 1fr; }
  .header { align-items: flex-start; flex-wrap: wrap; }
  .header-actions { margin-left: 0; width: 100%; }
  .queue-row { align-items: flex-start; flex-direction: column; }
  .queue-actions { justify-content: flex-start; }
}
