:root {
  --bg: #F5F8F7;
  --surface: #FFFFFF;
  --surface-sunken: #EEF3F1;
  --primary: #0E6B63;
  --primary-dark: #0A4F49;
  --primary-light: #E4F1EF;
  --accent: #E4694A;
  --accent-dark: #C7502F;
  --text: #17262A;
  --text-muted: #5C7370;
  --border: #DCE6E4;
  --success: #2E9E6D;
  --success-bg: #E5F5EC;
  --warning: #D98C2B;
  --warning-bg: #FBF0DE;
  --danger: #C6493E;
  --danger-bg: #FBEAE8;
  --radius: 12px;
  --radius-sm: 8px;
  --font-display: 'Manrope', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --shadow: 0 2px 8px rgba(15, 40, 38, 0.06), 0 1px 2px rgba(15,40,38,0.04);
  --shadow-md: 0 8px 24px rgba(15, 40, 38, 0.10);
}

* { box-sizing: border-box; }
html, body { margin:0; padding:0; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4 { font-family: var(--font-display); margin:0; color: var(--text); }
p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  outline: none;
  transition: border-color .15s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
label { display:block; font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 14px; }
label > input, label > select, label > textarea { margin-top: 6px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items:center; justify-content:center; gap:8px;
  padding: 10px 18px; border-radius: var(--radius-sm); border: none;
  font-weight: 600; font-size: 14px; transition: all .15s ease;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--surface-sunken); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== Login ===== */
.login-view {
  min-height: 100vh; display:flex; align-items:center; justify-content:center;
  background: radial-gradient(circle at 20% 20%, #123f3a 0%, #0A2E2A 60%, #071D1A 100%);
  padding: 20px;
}
.login-card {
  background: var(--surface); width: 100%; max-width: 380px;
  padding: 40px 32px; border-radius: 20px; box-shadow: var(--shadow-md);
}
.login-mark { display:flex; align-items:center; gap:10px; font-family: var(--font-display); font-weight:800; font-size: 22px; color: var(--primary-dark); }
.mark-dot { width: 14px; height:14px; border-radius: 4px; background: var(--accent); transform: rotate(45deg); }
.mark-dot.small { width: 10px; height:10px; }
.login-sub { color: var(--text-muted); font-size: 13px; margin: 6px 0 26px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ===== App shell ===== */
.app-shell { display:flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: var(--primary-dark); color: #fff;
  display:flex; flex-direction:column; padding: 24px 16px; flex-shrink:0;
}
.brand { display:flex; align-items:center; gap:10px; font-family: var(--font-display); font-weight: 800; font-size:18px; padding: 0 8px 24px; }
#nav-links { display:flex; flex-direction:column; gap:4px; flex:1; }
.nav-link {
  display:flex; align-items:center; gap:10px; padding: 11px 12px; border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.75); font-weight:600; font-size:14px; text-decoration:none; cursor:pointer;
  transition: all .15s ease;
}
.nav-link:hover { background: rgba(255,255,255,0.08); color:#fff; }
.nav-link.active { background: var(--accent); color:#fff; }
.nav-icon { font-size: 16px; width:20px; text-align:center; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,0.12); padding-top: 16px; }
.user-chip { display:flex; align-items:center; gap:10px; margin-bottom: 12px; padding: 0 8px; }
.avatar { width:36px; height:36px; border-radius:50%; background: var(--accent); color:#fff; display:flex; align-items:center; justify-content:center; font-weight:700; flex-shrink:0; }
.user-name { font-size:14px; font-weight:700; }
.user-role { font-size:12px; color: rgba(255,255,255,0.6); text-transform: capitalize; }
.sidebar-footer .btn-ghost { color: rgba(255,255,255,0.75); border-color: rgba(255,255,255,0.18); }
.sidebar-footer .btn-ghost:hover { background: rgba(255,255,255,0.08); color:#fff; }

.main-content { flex:1; min-width:0; display:flex; flex-direction:column; }
.topbar {
  padding: 22px 36px; background: var(--surface); border-bottom: 1px solid var(--border);
  display:flex; align-items:center; justify-content:space-between; position:sticky; top:0; z-index:10;
}
.topbar-date { color: var(--text-muted); font-size: 13px; font-weight:600; }
.hamburger-btn {
  display:none; align-items:center; justify-content:center; width:36px; height:36px; border-radius:8px;
  background: var(--surface-sunken); border:none; font-size:18px; color: var(--primary-dark); cursor:pointer; flex-shrink:0;
}
.hamburger-btn:hover { background: var(--primary-light); }
.page-content { padding: 28px 36px; flex:1; }

/* ===== Cards & layout ===== */
.card { background: var(--surface); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.grid { display:grid; gap: 18px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.stat-card { background:var(--surface); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stat-label { font-size:12px; color: var(--text-muted); font-weight:700; text-transform:uppercase; letter-spacing:.04em; }
.stat-value { font-family: var(--font-display); font-size: 32px; font-weight:800; margin-top:6px; color: var(--primary-dark); }

.section-title { font-size:18px; font-weight:800; margin-bottom:14px; }
.subtle { color: var(--text-muted); font-size: 13px; }

/* ===== Table ===== */
table { width:100%; border-collapse: collapse; }
th { text-align:left; font-size:12px; text-transform:uppercase; letter-spacing:.03em; color: var(--text-muted); padding: 10px 12px; border-bottom: 2px solid var(--border); }
td { padding: 12px; border-bottom: 1px solid var(--border); font-size:14px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-sunken); }

/* patient code badge - wristband style */
.code-badge {
  display:inline-flex; align-items:center; gap:6px; font-family: var(--font-mono); font-weight:700;
  background: var(--primary-light); color: var(--primary-dark); padding: 4px 10px; border-radius: 6px;
  font-size: 13px; letter-spacing: .03em; border: 1px dashed var(--primary);
}

.badge { display:inline-block; padding:3px 10px; border-radius: 20px; font-size:12px; font-weight:700; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: var(--surface-sunken); color: var(--text-muted); }

/* ===== Forms in modal ===== */
.form-grid { display:grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.form-grid label.full { grid-column: 1 / -1; }
.file-drop {
  border: 2px dashed var(--border); border-radius: var(--radius-sm); padding: 16px;
  text-align:center; cursor:pointer; font-size:13px; color: var(--text-muted); background: var(--surface-sunken);
  position:relative; overflow:hidden;
}
.file-drop img { max-height:80px; margin-top:8px; border-radius:6px; }
.file-drop input[type=file] { position:absolute; inset:0; opacity:0; cursor:pointer; }

/* ===== Modal ===== */
.modal-overlay {
  position:fixed; inset:0; background: rgba(10,25,23,0.55); display:flex; align-items:center; justify-content:center;
  z-index: 1000; padding: 20px; animation: fadeIn .15s ease;
}
.modal-box {
  background: var(--surface); border-radius: var(--radius); width:100%; max-width: 640px;
  max-height: 88vh; overflow-y:auto; box-shadow: var(--shadow-md);
}
.modal-header { display:flex; align-items:center; justify-content:space-between; padding: 20px 24px; border-bottom:1px solid var(--border); }
.modal-body { padding: 24px; }
.modal-close { background:none; border:none; font-size:20px; color: var(--text-muted); }
@keyframes fadeIn { from{opacity:0} to{opacity:1} }

/* ===== Scanner ===== */
.scan-wrap { display:flex; flex-direction:column; align-items:center; gap: 16px; }
#qr-reader { width: 100%; max-width: 420px; border-radius: var(--radius); overflow:hidden; box-shadow: var(--shadow); }
.scan-result-card { width:100%; max-width: 480px; }
.supplement-check-list { display:flex; flex-direction:column; gap:8px; margin: 14px 0; }
.supplement-check-item {
  display:flex; align-items:center; gap:10px; padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); cursor:pointer; transition: all .12s ease;
}
.supplement-check-item.checked { border-color: var(--primary); background: var(--primary-light); }
.supplement-check-item input { width:auto; }

.method-toggle { display:flex; gap:10px; }
.method-option {
  flex:1; text-align:center; padding: 12px 10px; border-radius: var(--radius-sm); border: 1.5px solid var(--border);
  cursor:pointer; font-weight:700; font-size:14px; color: var(--text-muted); transition: all .12s ease;
}
.method-option input { display:none; }
.method-option.selected { border-color: var(--primary); background: var(--primary-light); color: var(--primary-dark); }

/* ===== Toast ===== */
#toast-root { position:fixed; bottom:20px; right:20px; z-index:2000; display:flex; flex-direction:column; gap:10px; }
.toast {
  background: var(--text); color:#fff; padding: 12px 18px; border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  font-size: 14px; font-weight:600; animation: slideUp .2s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes slideUp { from{ transform:translateY(10px); opacity:0 } to{transform:translateY(0); opacity:1} }

/* patient card print */
.patient-id-card {
  width: 340px; border-radius: 16px; padding: 20px; background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color:#fff; position:relative; overflow:hidden;
}
.patient-id-card .qr-box { background:#fff; padding:10px; border-radius:10px; display:inline-block; margin-top:10px; }
.patient-id-card .pcode { font-family: var(--font-mono); font-size: 18px; font-weight:700; letter-spacing:.06em; margin-top: 6px; }

.empty-state { text-align:center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .emoji { font-size:36px; margin-bottom:12px; }

/* mini history calendar - shows recent visit dates colored by delivery method */
.mini-month-cal { width:100%; max-width:320px; margin: 0 auto; }
.mini-month-cal .cal-header {
  display:flex; align-items:center; justify-content:space-between; font-weight:800; font-family: var(--font-display);
  font-size:14px; color: var(--primary-dark); margin-bottom:8px;
}
.mini-month-cal .cal-nav {
  background: var(--surface-sunken); border:none; width:26px; height:26px; border-radius:6px; cursor:pointer;
  font-size:14px; color: var(--text-muted); font-weight:700;
}
.mini-month-cal .cal-nav:hover { background: var(--primary-light); color: var(--primary-dark); }
.cal-grid { display:grid; grid-template-columns: repeat(7, 1fr); gap:4px; }
.cal-weekdays { margin-bottom:4px; }
.cal-weekdays div { font-size:10px; font-weight:700; text-align:center; color: var(--text-muted); text-transform:uppercase; }
.cal-cell {
  aspect-ratio: 1; display:flex; align-items:center; justify-content:center; font-size:12px; font-weight:600;
  border-radius:7px; color: var(--text); background: var(--surface-sunken);
}
.cal-cell.empty { background: transparent; }
.cal-cell.cal-inperson { background: var(--success); color:#fff; font-weight:800; }
.cal-cell.cal-courier { background: var(--warning); color:#fff; font-weight:800; }
.cal-cell.cal-today { box-shadow: 0 0 0 2px var(--accent) inset; }
.cal-legend { display:flex; align-items:center; justify-content:center; gap:14px; margin-top:10px; font-size:11px; color: var(--text-muted); }
.cal-legend .dot { width:9px; height:9px; border-radius:50%; display:inline-block; margin-right:4px; vertical-align:middle; }
.cal-legend .cal-inperson { width:9px; height:9px; padding:0; }
.cal-legend .cal-courier { width:9px; height:9px; padding:0; }

/* mini torn-page calendar visual, used to show a selected date clearly */
.date-picker-row { display:flex; align-items:flex-end; gap:16px; margin-top:14px; }
.date-picker-row label { flex:1; margin-bottom:0; }
.mini-calendar {
  flex-shrink:0; width:74px; border-radius: 10px; overflow:hidden; box-shadow: var(--shadow);
  border: 1px solid var(--border); background: var(--surface); text-align:center; user-select:none;
}
.mini-calendar .mc-month {
  background: var(--accent); color:#fff; font-size:11px; font-weight:800; text-transform:uppercase;
  letter-spacing:.04em; padding: 4px 0;
}
.mini-calendar .mc-day {
  font-family: var(--font-display); font-size: 26px; font-weight:800; color: var(--primary-dark); line-height:1.1; padding: 6px 0 2px;
}
.mini-calendar .mc-weekday {
  font-size: 10px; font-weight:700; color: var(--text-muted); text-transform:uppercase; letter-spacing:.03em; padding-bottom:6px;
}

.search-bar { display:flex; gap:10px; margin-bottom:18px; }
.search-bar input { flex:1; }

.flex-between { display:flex; align-items:center; justify-content:space-between; }
.mb-16 { margin-bottom:16px; }
.mb-24 { margin-bottom:24px; }

@media (max-width: 800px) {
  .sidebar { position:fixed; z-index:200; height:100vh; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .page-content, .topbar { padding-left:16px; padding-right:16px; }
  .form-grid { grid-template-columns: 1fr; }

  .hamburger-btn { display:flex; }
  .sidebar-overlay { display:none; }
  .sidebar-overlay.open {
    display:block; position:fixed; inset:0; background:rgba(10,25,23,0.5); z-index:150;
  }
  .topbar { padding-top:16px; padding-bottom:16px; gap:10px; flex-wrap:wrap; }
  .topbar h1 { font-size:19px; }
  .topbar-date { font-size:11px; }
  .page-content { padding-top:20px; }

  /* tables scroll horizontally instead of squashing/breaking layout */
  table { min-width: 560px; }
  .card, .modal-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  .modal-box { max-width: 100% !important; width:100%; margin: 0 6px; max-height: 92vh; }
  .modal-header { padding: 16px; }
  .modal-body { padding: 16px; }

  .date-picker-row { flex-wrap: wrap; }
  .method-toggle { flex-direction:column; }
  .grid-4 { grid-template-columns: repeat(2, 1fr); }

  .login-card { padding: 32px 22px; }

  .stat-value { font-size: 26px; }
}

@media (max-width: 420px) {
  .grid-4 { grid-template-columns: 1fr; }
  table { min-width: 480px; }
}
