:root {
  --font: Helvetica, "Helvetica Neue", Arial, sans-serif;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-50: #eff6ff;
  --blue-100: #dbeafe;
  --green-600: #16a34a;
  --green-50: #f0fdf4;
  --green-100: #dcfce7;
  --amber-600: #d97706;
  --amber-50: #fffbeb;
  --amber-100: #fef3c7;
  --red-600: #dc2626;
  --red-50: #fef2f2;
  --red-100: #fee2e2;
  --gray-900: #0f172a;
  --gray-700: #334155;
  --gray-600: #475569;
  --gray-500: #64748b;
  --gray-400: #94a3b8;
  --gray-300: #cbd5e1;
  --gray-200: #e2e8f0;
  --gray-100: #f1f5f9;
  --gray-50: #f8fafc;
  --white: #ffffff;
  --bg-app: var(--gray-50);
  --surface: var(--white);
  --raised: rgba(255, 255, 255, 0.82);
  --border: var(--gray-200);
  --text: var(--gray-900);
  --muted: var(--gray-500);
  --accent: var(--blue-600);
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-full: 9999px;
  --fluid: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    linear-gradient(135deg, rgba(239, 246, 255, 0.86), rgba(248, 250, 252, 0.96) 38%, rgba(255, 255, 255, 0.88)),
    var(--bg-app);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: var(--font); }

.app-frame {
  width: min(100%, 480px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 16px;
}

.state-container {
  width: 100%;
  min-height: calc(100vh - 32px);
  min-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.loading-view,
.error-view {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: var(--r-lg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(145deg, var(--white), var(--blue-50));
  border: 1px solid var(--blue-100);
  color: var(--accent);
  font-weight: 900;
  overflow: hidden;
  flex: 0 0 auto;
}

.brand-logo {
  width: 72%;
  height: 72%;
  object-fit: contain;
  display: block;
}

.loader-ring {
  width: 56px;
  height: 56px;
  border: 4px solid var(--blue-100);
  border-top-color: var(--accent);
  border-radius: var(--r-full);
  animation: spin 0.9s linear infinite;
}

.loading-text,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.track-header,
.doctor-panel,
.token-hero,
.now-serving-card,
.stat-card,
.journey-card,
.travel-planner,
.counter-alert,
.completed-card,
.cancelled-card,
.feedback-card,
.tv-card,
.tv-login-card {
  background:
    linear-gradient(135deg, rgba(239, 246, 255, 0.68), rgba(255, 255, 255, 0.96) 54%, rgba(248, 250, 252, 0.88)),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}

.track-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
}

.brand-block {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-block > span:last-child {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.2;
}

.brand-sub {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--r-full);
  background: var(--green-50);
  border: 1px solid var(--green-100);
  color: var(--green-600);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.connection-status.reconnecting {
  background: var(--amber-50);
  border-color: var(--amber-100);
  color: var(--amber-600);
}

.connection-status.disconnected {
  background: var(--red-50);
  border-color: var(--red-100);
  color: var(--red-600);
}

.conn-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--r-full);
  background: currentColor;
  animation: blink 1.6s ease-in-out infinite;
}

.doctor-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
}

.doctor-panel h1 {
  font-size: 20px;
  line-height: 1.15;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tv-link,
.primary-btn,
.secondary-btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: var(--r-sm);
  padding: 8px 14px;
  background: linear-gradient(145deg, var(--accent), var(--blue-700));
  color: var(--white);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.secondary-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--gray-700);
}

.notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  font-size: 13px;
}

.delay-alert,
.paused-banner {
  background: var(--amber-50);
  border: 1px solid var(--amber-100);
  color: var(--amber-600);
}

.token-hero {
  padding: 24px 18px;
  text-align: center;
  overflow: hidden;
  position: relative;
}

.token-hero::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--blue-100), var(--accent));
  background-size: 220% 100%;
  animation: shimmer 2.4s linear infinite;
}

.token-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  min-height: 82px;
  margin: 4px 0 12px;
  color: var(--text);
  font-size: 66px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.token-status-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: var(--r-full);
  padding: 6px 13px;
  background: var(--amber-50);
  border: 1px solid var(--amber-100);
  color: var(--amber-600);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chip-dot {
  width: 7px;
  height: 7px;
  border-radius: var(--r-full);
  background: currentColor;
}

.status-called .token-status-chip {
  background: var(--blue-50);
  border-color: var(--blue-100);
  color: var(--accent);
}

.status-in_consultation .token-status-chip,
.status-completed .token-status-chip {
  background: var(--green-50);
  border-color: var(--green-100);
  color: var(--green-600);
}

.status-cancelled .token-status-chip,
.status-skipped .token-status-chip {
  background: var(--red-50);
  border-color: var(--red-100);
  color: var(--red-600);
}

.now-serving-card,
.stat-card {
  padding: 16px;
  text-align: center;
}

.ns-token {
  display: inline-flex;
  justify-content: center;
  flex-wrap: nowrap;
  min-height: 38px;
  margin-top: 3px;
  color: var(--green-600);
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-value {
  display: inline-flex;
  justify-content: center;
  flex-wrap: nowrap;
  min-height: 44px;
  color: var(--text);
  font-size: 36px;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.journey-card {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 14px 10px;
  gap: 8px;
}

.journey-step {
  display: grid;
  gap: 7px;
  justify-items: center;
  color: var(--gray-400);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.journey-step span {
  width: 18px;
  height: 18px;
  border-radius: var(--r-full);
  border: 2px solid var(--gray-300);
  background: var(--white);
}

.journey-step.completed,
.journey-step.current {
  color: var(--accent);
}

.journey-step.completed span,
.journey-step.current span {
  border-color: var(--accent);
  background: var(--accent);
}

.travel-planner,
.counter-alert,
.completed-card,
.cancelled-card,
.feedback-card {
  padding: 16px;
}

.tp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.tp-select,
.form-input,
.feedback-comment {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--white);
  color: var(--text);
  outline: none;
  padding: 10px 12px;
  font-size: 14px;
}

.tp-select { width: auto; padding: 7px 10px; }
.tp-body { text-align: center; color: var(--gray-700); }
.tp-highlight { color: var(--accent); font-weight: 900; }

.counter-alert {
  border-color: var(--blue-100);
  text-align: center;
}

.counter-alert h2,
.completed-card h2,
.cancelled-card h2,
.feedback-card h2 {
  font-size: 20px;
}

.alert-counter {
  margin-top: 8px;
  color: var(--accent);
  font-size: 28px;
  font-weight: 900;
}

.status-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: var(--r-full);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--green-50);
  border: 1px solid var(--green-100);
  color: var(--green-600);
  font-weight: 900;
}

.status-icon.danger {
  background: var(--red-50);
  border-color: var(--red-100);
  color: var(--red-600);
}

.rating-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 14px 0 12px;
}

.rating-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--white);
  color: var(--gray-400);
  cursor: pointer;
  font-size: 24px;
  font-weight: 900;
}

.rating-btn.active {
  background: var(--amber-50);
  border-color: var(--amber-100);
  color: var(--amber-600);
}

.feedback-comment {
  resize: vertical;
  margin-bottom: 12px;
}

.feedback-success { color: var(--green-600); font-weight: 800; }
.feedback-error { margin-top: 10px; color: var(--red-600); font-size: 13px; }

.track-footer {
  margin-top: auto;
  padding: 18px 4px 4px;
  display: grid;
  gap: 8px;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  color: var(--gray-600);
}

.footer-links a {
  color: var(--accent);
  font-weight: 800;
}

.made-by {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.made-by span {
  color: var(--gray-500);
  font-weight: 700;
}

.copyright { color: var(--gray-400); }
.compact { margin-top: 16px; }

.error-view h1 {
  font-size: 24px;
}

.error-view p {
  max-width: 320px;
  color: var(--muted);
  line-height: 1.5;
}

.rolling-value {
  font-variant-numeric: tabular-nums;
}

.roll-digit,
.roll-char {
  display: inline-block;
  flex: 0 0 auto;
  min-width: 0.64em;
  text-align: center;
  color: inherit;
  line-height: inherit;
}

.value-changed .roll-digit {
  animation: digitRoll 560ms var(--fluid);
}

.value-changed .roll-char {
  animation: charPop 360ms var(--fluid);
}

.value-changed {
  animation: valueGlow 580ms var(--fluid);
}

/* Adapted from the requested rolling counter: the digit scrolls through a short vertical stack on change. */
@keyframes digitRoll {
  0% { transform: translateY(-0.52em); filter: blur(1px); }
  72% { transform: translateY(0.08em); filter: blur(0); }
  100% { transform: translateY(0); }
}

@keyframes charPop {
  0% { transform: scale(0.92); opacity: 0.55; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes valueGlow {
  0% { color: var(--accent); }
  100% { color: inherit; }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

@keyframes shimmer {
  0% { background-position: -220% 0; }
  100% { background-position: 220% 0; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Hospital TV */
.tv-app {
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
  min-height: 100dvh;
}

.tv-shell {
  min-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tv-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.tv-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tv-brand h1 {
  font-size: clamp(22px, 3vw, 36px);
  line-height: 1.1;
}

.tv-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tv-login-view {
  min-height: calc(100vh - 40px);
  display: grid;
  place-items: center;
}

.tv-login-card {
  width: min(100%, 420px);
  padding: 24px;
  display: grid;
  gap: 14px;
}

.tv-login-card h1 {
  font-size: 28px;
}

.form-group {
  display: grid;
  gap: 6px;
}

.form-group label {
  color: var(--gray-600);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.tv-dashboard {
  display: grid;
  grid-template-columns: minmax(280px, 0.7fr) minmax(420px, 1.3fr);
  gap: 16px;
  align-items: start;
}

.tv-card {
  padding: 18px;
}

.doctor-select-card {
  display: grid;
  gap: 14px;
}

.tv-current {
  min-height: 420px;
  display: grid;
  place-items: center;
  text-align: center;
}

.tv-token-label {
  color: var(--muted);
  font-size: 16px;
  font-weight: 900;
  text-transform: uppercase;
}

.tv-token {
  display: inline-flex;
  justify-content: center;
  min-height: 128px;
  color: var(--accent);
  font-size: clamp(82px, 13vw, 156px);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: 0;
}

.tv-status {
  margin-top: 12px;
  display: inline-flex;
  border-radius: var(--r-full);
  padding: 8px 18px;
  background: var(--blue-50);
  border: 1px solid var(--blue-100);
  color: var(--accent);
  font-size: 16px;
  font-weight: 900;
  text-transform: uppercase;
}

.tv-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 16px;
}

.tv-stat {
  padding: 16px;
  border-radius: var(--r-md);
  background: var(--white);
  border: 1px solid var(--border);
  text-align: center;
}

.tv-stat strong {
  display: block;
  font-size: 34px;
  line-height: 1;
}

.tv-stat span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.tv-list {
  display: grid;
  gap: 8px;
}

.tv-row {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--white);
}

.tv-row-token {
  color: var(--accent);
  font-size: 24px;
  font-weight: 900;
}

.tv-row-name {
  min-width: 0;
  font-size: 16px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tv-row-status {
  color: var(--gray-600);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.tv-error {
  color: var(--red-600);
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 760px) {
  .app-frame { padding: 12px; }
  .state-container { min-height: calc(100vh - 24px); }
  .doctor-panel { align-items: flex-start; flex-direction: column; }
  .token-number { font-size: 56px; min-height: 68px; }
  .tv-app { padding: 14px; }
  .tv-header,
  .tv-actions { align-items: stretch; flex-direction: column; }
  .tv-dashboard { grid-template-columns: 1fr; }
  .tv-stats { grid-template-columns: 1fr; }
}
