:root {
  --pine: #173f37;
  --pine-700: #1d4d43;
  --pine-600: #2a6155;
  --sage: #6f8d83;
  --paper: #f4efe4;
  --paper-2: #fbf8f1;
  --ink: #1c241f;
  --ink-soft: #4a544c;
  --line: #ddd4c2;
  --amber: #c98a2b;
  --coral: #b8503f;
  --ok: #3f7d5a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23, 63, 55, 0.06), 0 12px 30px -18px rgba(23, 63, 55, 0.35);
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(111, 141, 131, 0.18), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(201, 138, 43, 0.1), transparent 55%),
    var(--paper);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.boot {
  display: grid;
  place-items: center;
  min-height: 100vh;
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--pine);
  letter-spacing: 0.01em;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
}
@media (max-width: 860px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-aside { display: none; }
}

.login-aside {
  background:
    linear-gradient(180deg, rgba(23, 63, 55, 0.92), rgba(23, 63, 55, 0.98)),
    radial-gradient(600px 300px at 80% 10%, rgba(201, 138, 43, 0.35), transparent 60%);
  color: #f1ede2;
  padding: 56px 52px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.login-aside::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px);
  background-size: 22px 22px;
  opacity: 0.5;
  pointer-events: none;
}
.cross-mark {
  width: 54px; height: 54px;
  display: grid; place-items: center;
  border: 2px solid rgba(241, 237, 226, 0.6);
  border-radius: 14px;
}
.cross-mark span { font-family: var(--font-display); font-size: 1.7rem; font-weight: 600; }
.cross-mark .sda-logo { width: 36px; height: 36px; }
.login-aside h1 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(2rem, 4vw, 3.1rem);
  line-height: 1.05;
  margin: 0 0 14px;
  letter-spacing: -0.01em;
}
.login-aside p { max-width: 34ch; color: #d8d2c2; margin: 0; }
.login-aside .feat { display: grid; gap: 10px; margin-top: 26px; }
.login-aside .feat div {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.95rem; color: #e7e2d4;
}
.login-aside .feat .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }

.login-panel {
  display: grid;
  place-items: center;
  padding: 40px 24px;
}
.login-card {
  width: min(420px, 100%);
}
.login-card .eyebrow {
  font-size: 0.78rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--sage); font-weight: 600; margin: 0 0 6px;
}
.login-card h2 {
  font-family: var(--font-display); font-weight: 600;
  font-size: 1.9rem; margin: 0 0 24px; color: var(--pine);
}

.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 0.82rem; font-weight: 600;
  color: var(--ink-soft); margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--paper-2); color: var(--ink);
  font-size: 0.96rem; transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--pine-700);
  box-shadow: 0 0 0 3px rgba(29, 77, 67, 0.12);
}
.field textarea { resize: vertical; min-height: 72px; }

.btn {
  border: none; border-radius: 10px; padding: 12px 18px;
  font-weight: 600; font-size: 0.95rem;
  background: var(--pine-700); color: #f4efe4;
  transition: transform 0.08s ease, background 0.15s, box-shadow 0.15s;
  box-shadow: 0 8px 20px -12px rgba(23, 63, 55, 0.8);
}
.btn:hover { background: var(--pine); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.6; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.ghost {
  background: transparent; color: var(--pine-700);
  border: 1px solid var(--line); box-shadow: none;
}
.btn.ghost:hover { background: rgba(23, 63, 55, 0.06); }
.btn.sm { padding: 8px 13px; font-size: 0.85rem; }

.hint {
  margin-top: 22px; padding: 14px 16px;
  background: rgba(111, 141, 131, 0.12);
  border: 1px dashed var(--sage); border-radius: 12px;
  font-size: 0.82rem; color: var(--ink-soft);
}
.hint b { color: var(--pine); }
.hint code {
  background: var(--paper-2); padding: 1px 6px; border-radius: 6px;
  font-size: 0.8rem; border: 1px solid var(--line);
}

.form-error {
  color: var(--coral); font-size: 0.85rem; margin: 0 0 14px;
  min-height: 1.1em;
}

/* ---------- Auth tabs (sign in / register) ---------- */
.auth-tabs {
  display: flex; gap: 6px; margin-bottom: 24px;
  background: rgba(111, 141, 131, 0.12);
  border: 1px solid var(--line); border-radius: 12px; padding: 4px;
}
.auth-tab {
  flex: 1; padding: 9px 12px; border: none; background: transparent;
  font-family: inherit; font-weight: 600; font-size: 0.88rem;
  color: var(--ink-soft); border-radius: 9px; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.auth-tab.active {
  background: var(--paper-2); color: var(--pine);
  box-shadow: 0 1px 2px rgba(23, 63, 55, 0.08);
}

/* ---------- BMI calculator ---------- */
.bmi-calc { grid-column: 1 / -1; }
.bmi-calc .bmi-row {
  display: flex; align-items: center; gap: 8px;
}
.bmi-calc .bmi-row input { width: 100%; }
.bmi-calc .bmi-row #rf-bmi { max-width: 110px; }
.bmi-calc .bmi-op {
  color: var(--sage); font-weight: 700; flex: none;
}
.bmi-calc #rf-bmi {
  font-weight: 700; color: var(--pine); background: rgba(111, 141, 131, 0.12);
}
.bmi-calc .bmi-cat {
  display: block; margin-top: 6px; font-size: 0.78rem; color: var(--sage); font-weight: 600;
}
.bmi-calc .bmi-legend {
  list-style: none; margin: 8px 0 0; padding: 8px 10px;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 14px;
  background: rgba(111, 141, 131, 0.08); border: 1px solid rgba(111, 141, 131, 0.18);
  border-radius: 8px; font-size: 0.74rem; color: var(--pine);
}
.bmi-calc .bmi-legend li { display: flex; gap: 6px; align-items: baseline; }
.bmi-calc .bmi-legend span { font-weight: 700; color: var(--sage); white-space: nowrap; }

/* ---------- Blood sugar ---------- */
.bs-row { display: flex; align-items: center; gap: 8px; }
.bs-row select { flex: 0 0 auto; width: auto; min-width: 130px; }
.bs-row input { flex: 1 1 auto; min-width: 0; }
.bs-field { grid-column: 1 / -1; }
.bs-note {
  display: block; margin-top: 6px; font-size: 0.78rem; color: var(--sage); font-weight: 600;
}
.bs-note.ok { color: var(--pine); }
.bs-note.out { color: var(--coral); }
.bs-legend {
  list-style: none; margin: 8px 0 0; padding: 8px 10px;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 14px;
  background: rgba(111, 141, 131, 0.08); border: 1px solid rgba(111, 141, 131, 0.18);
  border-radius: 8px; font-size: 0.74rem; color: var(--pine);
}
.bs-legend li { display: flex; flex-direction: column; gap: 2px; }
.bs-legend span { font-weight: 700; color: var(--sage); white-space: nowrap; }

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px clamp(18px, 5vw, 48px);
  background: rgba(244, 239, 228, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--pine-700); color: #f4efe4;
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 700; font-size: 1.1rem;
}
.brand .logo .sda-logo { width: 26px; height: 26px; }
.brand .name { font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; color: var(--pine); }
.brand .sub { font-size: 0.72rem; color: var(--sage); letter-spacing: 0.12em; text-transform: uppercase; }

.topbar .who { display: flex; align-items: center; gap: 14px; }
.who .id { text-align: right; }
.who .id .n { font-weight: 600; font-size: 0.9rem; }
.who .id .r { font-size: 0.74rem; color: var(--ink-soft); }

.badge {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; padding: 4px 9px; border-radius: 999px;
}
.badge.admin { background: rgba(201, 138, 43, 0.18); color: #8a5b15; }
.badge.staff { background: rgba(63, 125, 90, 0.18); color: #2c5a40; }
.badge.viewer { background: rgba(111, 141, 131, 0.2); color: #455952; }

main { padding: clamp(22px, 4vw, 44px) clamp(18px, 5vw, 48px) 80px; max-width: 1180px; margin: 0 auto; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 26px; }
.page-head h1 {
  font-family: var(--font-display); font-weight: 600;
  font-size: clamp(1.7rem, 3.5vw, 2.5rem); margin: 0; color: var(--pine);
  letter-spacing: -0.01em;
}
.page-head p { margin: 4px 0 0; color: var(--ink-soft); }

.crumb { background: none; border: none; color: var(--sage); font-weight: 600; padding: 0; margin-bottom: 10px; font-size: 0.88rem; }
.crumb:hover { color: var(--pine); }

/* cards */
.card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { padding: 22px 24px; margin-bottom: 26px; }
.panel h3 { font-family: var(--font-display); font-weight: 600; margin: 0 0 16px; color: var(--pine); font-size: 1.25rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 680px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.row-actions { display: flex; gap: 10px; margin-top: 6px; }

/* patient list */
.patient-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.patient-card {
  text-align: left; padding: 18px 20px; cursor: pointer;
  display: flex; flex-direction: column; gap: 8px;
  transition: transform 0.12s ease, box-shadow 0.15s;
}
.patient-card:hover { transform: translateY(-3px); box-shadow: 0 18px 36px -22px rgba(23, 63, 55, 0.5); }
.patient-card .pc-top { display: flex; align-items: center; justify-content: space-between; }
.patient-card .code { font-size: 0.74rem; letter-spacing: 0.08em; color: var(--sage); font-weight: 600; }
.patient-card .pname { font-family: var(--font-display); font-size: 1.2rem; font-weight: 600; color: var(--ink); }
.patient-card .meta { font-size: 0.84rem; color: var(--ink-soft); display: flex; gap: 12px; flex-wrap: wrap; }
.patient-card .reccount { font-size: 0.78rem; color: var(--pine-700); font-weight: 600; }

/* account cards */
.account-card { display: flex; flex-direction: column; gap: 14px; padding: 18px 20px; }
.account-card .ac-main { display: flex; align-items: center; gap: 12px; }
.account-card .pname { font-family: var(--font-display); font-size: 1.1rem; font-weight: 600; color: var(--ink); }
.account-card .meta { font-size: 0.82rem; color: var(--ink-soft); display: flex; gap: 12px; flex-wrap: wrap; }
.account-card .ac-foot { display: flex; align-items: center; justify-content: space-between; }
.btn.danger { color: var(--coral); border-color: rgba(199, 84, 80, 0.35); }
.btn.danger:hover { background: rgba(199, 84, 80, 0.1); }

.avatar {
  width: 40px; height: 40px; border-radius: 11px; flex: none;
  background: linear-gradient(140deg, var(--sage), var(--pine-700));
  color: #f4efe4; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 600;
}

/* patient header */
.patient-hero { display: flex; gap: 18px; align-items: center; padding: 22px 24px; margin-bottom: 24px; }
.patient-hero .avatar { width: 64px; height: 64px; border-radius: 16px; font-size: 1.5rem; }
.patient-hero h2 { font-family: var(--font-display); font-weight: 600; margin: 0; font-size: 1.6rem; color: var(--pine); }
.patient-hero .facts { display: flex; gap: 18px; flex-wrap: wrap; color: var(--ink-soft); font-size: 0.88rem; margin-top: 4px; }
.patient-hero .facts b { color: var(--ink); font-weight: 600; }

/* record cards */
.records { display: grid; gap: 14px; }
.record {
  padding: 18px 20px;
  display: grid; gap: 14px;
}
.record .rhead { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.record .date { font-weight: 600; color: var(--pine); }
.record .when { font-size: 0.78rem; color: var(--sage); }
.vitals { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
@media (max-width: 720px) { .vitals { grid-template-columns: repeat(2, 1fr); } }
.vital { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.vital .k { font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--sage); font-weight: 600; }
.vital .v { font-size: 1.05rem; font-weight: 600; color: var(--ink); margin-top: 3px; }
.vital .v small { font-weight: 500; color: var(--ink-soft); font-size: 0.72rem; }
.note { font-size: 0.9rem; color: var(--ink-soft); border-left: 3px solid var(--sage); padding-left: 12px; }

/* empty state */
.empty {
  text-align: center; padding: 56px 24px; color: var(--ink-soft);
  border: 1px dashed var(--line); border-radius: var(--radius); background: var(--paper-2);
}
.empty .glyph {
  width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 14px;
  display: grid; place-items: center; background: rgba(111, 141, 131, 0.15);
  font-family: var(--font-display); font-size: 1.6rem; color: var(--sage);
}
.empty h3 { font-family: var(--font-display); color: var(--pine); margin: 0 0 6px; }

/* details / disclosure */
.disclosure summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
}
.disclosure summary::-webkit-details-marker { display: none; }

/* toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--paper-2);
  padding: 12px 20px; border-radius: 12px; font-size: 0.9rem; font-weight: 500;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  z-index: 50; box-shadow: var(--shadow); max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--coral); }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 6px 0 16px; flex-wrap: wrap; }
.section-title h2 { font-family: var(--font-display); font-weight: 600; color: var(--pine); margin: 0; font-size: 1.35rem; }

.search-input {
  padding: 9px 16px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--paper-2); color: var(--ink); font-size: 0.9rem;
  min-width: min(280px, 60vw); transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input::placeholder { color: var(--sage); }
.search-input:focus {
  outline: none; border-color: var(--pine-700);
  box-shadow: 0 0 0 3px rgba(29, 77, 67, 0.12);
}

.fade-in { animation: fade 0.4s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.stagger > * { animation: fade 0.45s ease both; }
.stagger > *:nth-child(2) { animation-delay: 0.05s; }
.stagger > *:nth-child(3) { animation-delay: 0.1s; }
.stagger > *:nth-child(4) { animation-delay: 0.15s; }
.stagger > *:nth-child(5) { animation-delay: 0.2s; }
.stagger > *:nth-child(6) { animation-delay: 0.25s; }

/* ---------- modal (password change / reset) ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 38, 33, 0.42); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 20px;
  animation: fade 0.2s ease both;
}
.modal {
  width: min(420px, 100%); background: var(--paper); color: var(--ink);
  border: 1px solid var(--line); border-radius: 16px;
  padding: 22px 24px; box-shadow: 0 24px 60px rgba(20, 38, 33, 0.28);
  animation: fade 0.25s ease both;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-family: var(--font-display); font-weight: 600; margin: 0; color: var(--pine); font-size: 1.2rem; }
.modal-close {
  border: none; background: none; cursor: pointer; color: var(--sage);
  font-size: 1.4rem; line-height: 1; padding: 0 4px;
}
.modal-close:hover { color: var(--ink); }
