:root {
  --rust: #a1522d;
  --rust-dark: #7d3d20;
  --rust-soft: #f6ece5;
  --olive: #6d7b4b;
  --olive-soft: #eef1e6;
  --ink: #23201d;
  --muted: #7b736c;
  --line: #e2dbd3;
  --bg: #faf7f4;
  --card: #ffffff;
  --danger: #b3341f;
  --amber: #b07d15;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(35, 32, 29, .06), 0 8px 24px rgba(35, 32, 29, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
}

a { color: var(--rust); }

/* ------------------------------------------------------------- top bar */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar img.logo { height: 30px; }

.topbar .branch {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .08em;
  text-transform: uppercase;
  border-left: 1px solid var(--line);
  padding-left: 18px;
}

.topbar nav {
  margin-left: auto;
  display: flex;
  gap: 6px;
  align-items: center;
}

.topbar nav a {
  padding: 7px 14px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}

.topbar nav a:hover { background: var(--rust-soft); color: var(--rust-dark); }
.topbar nav a.active { background: var(--rust); color: #fff; }

.clock {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 13px;
  padding-left: 10px;
}

/* --------------------------------------------------------------- layout */

.wrap { max-width: 1500px; margin: 0 auto; padding: 18px 20px 60px; }

.split {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.split.wide-left { grid-template-columns: 440px minmax(0, 1fr); }

@media (max-width: 1100px) {
  .split, .split.wide-left { grid-template-columns: 1fr; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card > h2 {
  margin: 0;
  padding: 12px 16px;
  font-size: 13px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--rust-dark);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(#fff, #fdfaf7);
  border-radius: var(--radius) var(--radius) 0 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card > h2 .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.card .body { padding: 14px 16px; }
.card .body.tight { padding: 0; }

/* ---------------------------------------------------------------- forms */

label.field { display: block; margin-bottom: 10px; }

label.field > span {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

input, select, textarea, button {
  font: inherit;
  color: inherit;
}

input[type=text], input[type=tel], input[type=number], input[type=date],
input[type=search], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--rust);
  box-shadow: 0 0 0 3px rgba(161, 82, 45, .12);
}

textarea { resize: vertical; min-height: 62px; }

.row { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.row.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row.six { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.row.age { grid-template-columns: 1fr 1fr 1.2fr; }
.row.guardian { grid-template-columns: 110px 1fr; }

@media (max-width: 700px) {
  .row, .row.three, .row.four, .row.six { grid-template-columns: 1fr 1fr; }
}

/* -------------------------------------------------------------- buttons */

button, .btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

button:hover, .btn:hover { border-color: var(--rust); color: var(--rust-dark); }

.btn-primary, button.primary {
  background: var(--rust);
  border-color: var(--rust);
  color: #fff;
}

.btn-primary:hover, button.primary:hover {
  background: var(--rust-dark);
  border-color: var(--rust-dark);
  color: #fff;
}

button.olive { background: var(--olive); border-color: var(--olive); color: #fff; }
button.olive:hover { background: #5b6840; border-color: #5b6840; color: #fff; }
button.ghost { background: transparent; }
button.small { padding: 4px 9px; font-size: 13px; }
button.link { border: 0; background: none; color: var(--rust); padding: 2px 4px; }
button:disabled { opacity: .5; cursor: not-allowed; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions.end { justify-content: flex-end; }

/* --------------------------------------------------------------- tables */

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: 11px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: #fcfaf8;
  position: sticky;
  top: 0;
}

td { padding: 7px 10px; border-bottom: 1px solid #f1ece6; vertical-align: middle; }
td input, td select { padding: 6px 8px; }
td select { min-width: 120px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--rust-soft); }
tr.selected { background: var(--olive-soft); }

/* --------------------------------------------------------------- tokens */

.token-list { max-height: calc(100vh - 260px); overflow: auto; }
.token-list table { min-width: 700px; }

.token-no {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 30px;
  border-radius: 8px;
  background: var(--rust);
  color: #fff;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.token-no.done { background: var(--olive); }
.token-no.consult { background: var(--amber); }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.pill.waiting { background: var(--rust-soft); color: var(--rust-dark); }
.pill.in_consult { background: #fbf1da; color: var(--amber); }
.pill.completed { background: var(--olive-soft); color: #4f5b38; }
.pill.new { background: #e9f0f7; color: #35506b; }
.pill.followup { background: #f3eef7; color: #5b4570; }

.pill.role-admin { background: #f3eef7; color: #5b4570; }
.pill.role-doctor { background: var(--rust-soft); color: var(--rust-dark); }
.pill.role-helpdesk { background: #e9f0f7; color: #35506b; }
.pill.role-pharmacy { background: var(--olive-soft); color: #4f5b38; }

.whoami {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 12px;
  margin-left: 4px;
  border-left: 1px solid var(--line);
  font-size: 13px;
}

.whoami a { color: var(--ink); font-weight: 600; text-decoration: none; }
.whoami a:hover { color: var(--rust); }

/* ------------------------------------------------------------------ sign in */

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 26px;
}

.auth-card img.logo { height: 34px; display: block; margin: 0 auto 4px; }

.auth-card .tag {
  text-align: center;
  font-size: 10px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--olive);
  margin-bottom: 20px;
}

.auth-card h1 { font-size: 17px; margin: 0 0 16px; text-align: center; font-weight: 600; }
.auth-card button[type=submit] { width: 100%; justify-content: center; margin-top: 6px; }

.auth-note {
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.auth-error {
  background: #fdf3ef;
  border: 1px solid #f0cec2;
  color: var(--danger);
  border-radius: 7px;
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; font-family: "Consolas", monospace; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.danger-text { color: var(--danger); font-weight: 600; }

.empty { padding: 26px 16px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------------------------------------------------------------- stats */

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }

.stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.stat b { display: block; font-size: 22px; line-height: 1.1; }
.stat span { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }

/* --------------------------------------------------------------- search */

.search-results { max-height: 300px; overflow: auto; border-top: 1px solid var(--line); }

.result {
  padding: 9px 16px;
  border-bottom: 1px solid #f1ece6;
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: baseline;
}

.result:hover { background: var(--rust-soft); }
.result b { font-weight: 600; }
.result .uhid { font-size: 12px; color: var(--rust); font-family: Consolas, monospace; }

/* --------------------------------------------------------------- toasts */

#toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

.toast {
  background: var(--ink);
  color: #fff;
  padding: 11px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 14px;
  max-width: 380px;
}

.toast.err { background: var(--danger); }
.toast.ok { background: var(--olive); }

/* -------------------------------------------------------------- section */

.section-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--olive);
  margin: 18px 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px dashed var(--line);
}

.section-title:first-child { margin-top: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

.chip {
  border: 1px dashed var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  cursor: pointer;
  background: #fff;
  color: var(--muted);
}

.chip:hover { border-color: var(--olive); color: var(--olive); border-style: solid; }

.alert-allergy {
  background: #fdf3ef;
  border: 1px solid #f0cec2;
  color: var(--danger);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
}

.patient-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #fdfbf9;
}

.patient-strip div { font-size: 13px; }
.patient-strip label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; display: block; }
.patient-strip b { font-weight: 600; }

.history-item {
  border-bottom: 1px solid #f1ece6;
  padding: 10px 16px;
  font-size: 13px;
}

.history-item h4 { margin: 0 0 4px; font-size: 13px; color: var(--rust-dark); }
.history-item .meds { color: var(--muted); }

kbd {
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  font-size: 11px;
  font-family: Consolas, monospace;
  background: #fff;
}
