:root {
  --blue: #2563eb;
  --blue-d: #1d4ed8;
  --ink: #0f172a;
  --muted: #64748b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --line: #e2e8f0;
  --danger: #dc2626;
  --ok: #059669;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 8px 24px rgba(15,23,42,.06);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; font-size: 14px;
  font-weight: 600; cursor: pointer; transition: filter .15s, background .15s;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-d); }
.btn-light { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.3); padding: 7px 12px; }
.btn-ghost:hover { background: rgba(255,255,255,.12); }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(160deg, #2563eb 0%, #1e40af 60%, #0f172a 100%);
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px; background: #fff; border-radius: 20px;
  padding: 32px 28px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 14px;
}
.brand { text-align: center; margin-bottom: 6px; }
.brand h1 { margin: 8px 0 2px; font-size: 24px; }
.brand p { margin: 0; color: var(--muted); font-size: 13px; }
.brand-badge {
  display: inline-grid; place-items: center; width: 54px; height: 54px; font-size: 26px;
  background: #dbeafe; border-radius: 16px; margin: 0 auto;
}
.brand-badge.sm { width: 30px; height: 30px; font-size: 16px; border-radius: 9px; }
.login-card label, .row-form label, .grid-form label {
  display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: #334155;
}
input, select {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px;
  font-family: inherit; background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus { outline: 2px solid #bfdbfe; border-color: var(--blue); }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0; text-align: center; }
.hint { text-align: center; color: var(--muted); font-size: 12px; margin: 0; }

/* ---------- app shell ---------- */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar {
  background: #0f172a; color: #e2e8f0; display: flex; flex-direction: column; padding: 18px 14px;
}
.sidebar-brand { font-weight: 800; font-size: 17px; display: flex; align-items: center; gap: 8px; padding: 4px 6px 18px; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  text-align: left; background: transparent; color: #cbd5e1; border: 0; padding: 11px 12px;
  border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: var(--blue); color: #fff; }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.1); padding-top: 14px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; }
#admin-name { color: #94a3b8; padding-left: 4px; }

.content { padding: 26px 30px; overflow: auto; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.section-head h2 { margin: 0; font-size: 22px; }

/* ---------- dashboard cards ---------- */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
  border-left: 5px solid var(--blue);
}
.card-num { font-size: 40px; font-weight: 800; line-height: 1; }
.card-label { color: var(--muted); font-size: 13px; font-weight: 600; margin-top: 8px; }
.card-blue { border-left-color: #2563eb; } .card-blue .card-num { color: #2563eb; }
.card-teal { border-left-color: #0d9488; } .card-teal .card-num { color: #0d9488; }
.card-purple { border-left-color: #7c3aed; } .card-purple .card-num { color: #7c3aed; }
.card-green { border-left-color: #059669; } .card-green .card-num { color: #059669; }
.card.clickable { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.card.clickable:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(15,23,42,.12), 0 12px 30px rgba(15,23,42,.10); }

/* dashboard charts */
.charts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-top: 18px; }
.chart-card { background: #fff; border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.chart-head h3 { margin: 0 0 14px; font-size: 15px; }
.chart-body { min-height: 160px; }
.chart-empty { color: var(--muted); font-size: 13px; padding: 30px 0; text-align: center; }

/* horizontal bars */
.hbar-row { display: grid; grid-template-columns: 96px 1fr 30px; align-items: center; gap: 8px; margin-bottom: 12px; }
.hbar-label { font-size: 12.5px; color: #334155; font-weight: 600; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { background: #eef2f7; border-radius: 8px; height: 20px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 8px; }
.hbar-val { font-size: 12.5px; font-weight: 700; color: var(--ink); }

/* vertical bars (trend) */
.vbars { display: flex; align-items: flex-end; gap: 10px; height: 150px; padding-top: 8px; }
.vbar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.vbar-fill { width: 60%; max-width: 34px; background: var(--blue); border-radius: 6px 6px 0 0; min-height: 2px; transition: height .2s; }
.vbar-count { font-size: 11.5px; font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.vbar-label { font-size: 10.5px; color: var(--muted); margin-top: 6px; white-space: nowrap; }

/* donut */
.donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.donut-legend { display: flex; flex-direction: column; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: #334155; }
.legend-dot { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto; }
.legend-item b { color: var(--ink); }

/* patient detail */
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 24px; }
.detail-field { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.detail-field .k { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.detail-field .v { font-size: 16px; font-weight: 600; margin-top: 4px; color: var(--ink); word-break: break-word; }
.detail-h3 { font-size: 16px; margin: 6px 0 10px; }
.tbl tbody tr.clickable-row { cursor: pointer; }
.tbl tbody tr.clickable-row:hover td { background: #f1f5f9; }
@media (max-width: 820px) { .detail-grid { grid-template-columns: 1fr 1fr; } }

/* ---------- forms & tables ---------- */
.row-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 20px; }
.row-form input, .row-form select { width: auto; min-width: 180px; flex: 1; }
.row-form .btn { flex: 0 0 auto; }
.grid-form { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 22px; }
.grid-2 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }

.tbl { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.tbl th, .tbl td { text-align: left; padding: 12px 14px; font-size: 14px; border-bottom: 1px solid var(--line); }
.tbl th { background: #f8fafc; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .empty { text-align: center; color: var(--muted); padding: 24px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: #0f172a; color: #fff;
  padding: 13px 18px; border-radius: 12px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); z-index: 50; max-width: 340px;
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .charts { grid-template-columns: 1fr; }
}
