:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #0f766e;
  --accent-hover: #115e59;
  --accent-soft: #ccfbf1;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --success: #16a34a;
  --success-soft: #dcfce7;
  --info-soft: #dbeafe;
  --radius: 10px;
  --sidebar-w: 230px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #0b3b38;
  color: #d7e5e3;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-user { display: flex; align-items: center; gap: 10px; }
.user-name { font-weight: 600; }
.user-roles { color: var(--text-muted); font-size: 12px; }
.content { padding: 24px; max-width: 1300px; width: 100%; }

/* ---------- brand & nav ---------- */
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; }
.brand-lg { padding: 0 0 6px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 20px; font-weight: 700;
}
.brand-name { font-weight: 700; font-size: 16px; color: inherit; }
.nav { display: flex; flex-direction: column; padding: 4px 10px 20px; gap: 2px; }
.nav-link {
  color: #b7cdca; padding: 8px 12px; border-radius: 8px; font-size: 14px;
}
.nav-link:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.nav-link.active { background: rgba(255,255,255,.13); color: #fff; font-weight: 600; }
.nav-link-muted { color: #7fa39f; font-size: 13px; }
.nav-group {
  margin-top: 16px; padding: 4px 12px; font-size: 11px; letter-spacing: .08em;
  text-transform: uppercase; color: #7fa39f;
}

/* ---------- cards & grids ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 20px;
}
.card.narrow { max-width: 640px; }
.card-danger { border-color: var(--danger); }
.card-warning { border-color: var(--warning); background: #fffbeb; }
.card-title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.stat-danger { border-color: var(--danger); }
.stat-danger .stat-value { color: var(--danger); }

.section-title { margin: 22px 0 12px; }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-muted); padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.table td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.row-muted td { opacity: .5; }

/* ---------- forms ---------- */
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: #334155; }
input, select, textarea {
  font: inherit; font-weight: 400; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-actions { display: flex; gap: 10px; align-items: center; }
.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.check input { width: auto; }
.inline { display: inline; }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.dl dt { color: var(--text-muted); }
.dl dd { margin: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  border-radius: 8px; border: 1px solid transparent; padding: 8px 14px;
  background: transparent; color: var(--text); white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: #fff; border-color: var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: #eef2f6; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- badges, tickets, misc ---------- */
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px;
  border-radius: 999px; text-transform: uppercase; letter-spacing: .03em;
}
.badge-success, .badge-checked_in, .badge-completed { background: var(--success-soft); color: var(--success); }
.badge-warning, .badge-booked { background: var(--warning-soft); color: var(--warning); }
.badge-muted, .badge-cancelled { background: #e9edf2; color: var(--text-muted); }
.badge-info { background: var(--info-soft); color: #1d4ed8; }
.badge-no_show { background: var(--danger-soft); color: var(--danger); }

.ticket {
  display: inline-block; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-weight: 700; background: var(--accent-soft); color: var(--accent-hover);
  border-radius: 8px; padding: 3px 9px; font-size: 14px;
}
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }

.flash { border-radius: var(--radius); padding: 10px 16px; margin: 16px 24px 0; font-size: 14px; }
.content .flash { margin: 0 0 16px; }
.flash-success { background: var(--success-soft); color: #14532d; }
.flash-error { background: var(--danger-soft); color: #7f1d1d; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.search-form { display: flex; gap: 8px; }
.search-form input { min-width: 280px; }

/* ---------- queue ---------- */
.queue-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.queue-tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; color: inherit; display: flex; flex-direction: column; gap: 6px;
}
.queue-tile:hover { border-color: var(--accent); text-decoration: none; }
.tile-danger { border-color: var(--danger); background: #fff7f7; }
.tile-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tile-meta { color: var(--text-muted); font-size: 13px; min-height: 18px; }
.tile-count { font-size: 22px; font-weight: 700; }

.queue-list { display: flex; flex-direction: column; gap: 10px; }
.queue-row {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px;
}
.row-danger { border-color: var(--danger); background: #fff7f7; }
.queue-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.queue-row-actions { display: flex; gap: 6px; }

/* ---------- appointments day view ---------- */
.doctor-columns { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; align-items: start; }
.doctor-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.doctor-col-head { display: flex; flex-direction: column; gap: 2px; padding-bottom: 10px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.appt { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.appt-checked_in { border-left: 3px solid var(--success); }
.appt-booked { border-left: 3px solid var(--warning); }
.appt-cancelled, .appt-no_show { opacity: .55; }
.appt-time { font-weight: 700; font-size: 13px; }
.appt-body { display: flex; flex-direction: column; gap: 2px; margin: 2px 0 6px; }
.appt-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- doctor route ---------- */
.route { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.route-done, .route-skipped { color: var(--text-muted); }
.route-in_progress, .route-called, .route-queued { font-weight: 600; }

.note { border-top: 1px solid var(--border); padding: 10px 0; font-size: 14px; }
.note p { margin: 4px 0; }
.note-head { display: flex; gap: 10px; align-items: center; }

/* ---------- autocomplete ---------- */
.autocomplete { position: relative; }
.autocomplete-list {
  position: absolute; z-index: 10; left: 0; right: 0; top: 2px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  max-height: 220px; overflow-y: auto;
}
.autocomplete-item { padding: 8px 12px; cursor: pointer; font-weight: 400; }
.autocomplete-item:hover { background: var(--accent-soft); }

/* ---------- login ---------- */
.login-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: #0b3b38;
}
.login-box {
  background: var(--surface); border-radius: 14px; padding: 34px 38px;
  width: 380px; display: flex; flex-direction: column; gap: 14px;
}
.login-box .flash { margin: 0; }

/* ---------- waiting-room board ---------- */
.board-page { background: #0b1f1e; color: #e6f2f0; min-height: 100vh; }
.board-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 22px 40px; border-bottom: 1px solid rgba(255,255,255,.12);
}
.board-clock { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.board-main { display: grid; grid-template-columns: 1.2fr 1fr; gap: 30px; padding: 30px 40px; }
.board-col h2 { font-size: 18px; text-transform: uppercase; letter-spacing: .1em; color: #8fb8b3; }
.board-list { display: flex; flex-direction: column; gap: 12px; }
.board-row {
  display: flex; align-items: center; gap: 20px;
  background: rgba(255,255,255,.06); border-radius: 12px; padding: 16px 22px;
}
.board-row.called { background: #10514c; outline: 2px solid #2dd4bf; }
.board-ticket { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 130px; }
.board-place { font-size: 20px; flex: 1; }
.board-wait { font-size: 16px; color: #8fb8b3; }
@media (max-width: 900px) { .board-main { grid-template-columns: 1fr; } }
