/* ---------------------------------------------------------------------------
   Bio Cell Wellness Group -- Medical Notes
   Brand: Poppins; navy #003970, deep blue #002678, cyan accent #27a7de.
   Built for a clinic tablet in landscape and a desktop workstation.
--------------------------------------------------------------------------- */

:root {
  --navy: #003970;
  --deep: #002678;
  --cyan: #27a7de;
  --ink: #16202e;
  --muted: #5c6b7f;
  --line: #dde3ec;
  --bg: #f4f7fb;
  --card: #ffffff;
  --ok: #128a56;
  --warn: #b26a00;
  --bad: #c0392b;
  --radius: 10px;
  --sidebar-w: 268px;
}

* { box-sizing: border-box; }

/* The gate and the overlays set `display`, which otherwise beats the `hidden`
   attribute and leaves them stuck on screen. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

button, input, select, textarea {
  font-family: inherit;
  font-size: 15px;
  color: inherit;
}

/* ------------------------------- buttons ------------------------------- */

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 18px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  background: #fff;
  white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--deep); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { border-color: var(--cyan); color: var(--navy); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-danger { background: transparent; border-color: #f0c9c4; color: var(--bad); }
.btn-danger:hover:not(:disabled) { background: #fdf3f2; }

.icon-btn {
  display: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  width: 38px; height: 38px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

/* -------------------------------- gate --------------------------------- */

.gate {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: linear-gradient(160deg, var(--deep), var(--navy) 55%, #001b4f);
  padding: 24px;
  z-index: 60;
}
.gate-card {
  width: 100%; max-width: 380px;
  background: var(--card);
  border-radius: 14px;
  padding: 32px 28px;
  box-shadow: 0 20px 50px rgba(0, 20, 60, .35);
}
.gate-logo { width: 100%; max-width: 210px; display: block; margin: 0 auto 22px; filter: invert(1) brightness(.35) saturate(2); }
.gate-card h1 { font-size: 21px; text-align: center; color: var(--navy); }
.gate-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 8px 0 22px; line-height: 1.5; }
.gate-card label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.gate-card input {
  width: 100%; padding: 12px 14px; margin-bottom: 14px;
  border: 1px solid var(--line); border-radius: 8px; background: #fbfcfe;
  letter-spacing: .3em;
}
.gate-card input:focus { outline: 2px solid var(--cyan); outline-offset: 1px; }
.gate-error { color: var(--bad); font-size: 13px; text-align: center; margin: 12px 0 0; }
.gate-hint { text-align: center; font-size: 12px; color: var(--muted); margin: 10px 0 18px; }
a.btn { display: block; text-align: center; text-decoration: none; }
#fallback { border-top: 1px solid var(--line); padding-top: 14px; }
#fallback summary {
  cursor: pointer; font-size: 12px; color: var(--muted);
  text-align: center; list-style: none; margin-bottom: 14px;
}
#fallback summary::-webkit-details-marker { display: none; }
#fallback summary:hover { color: var(--navy); }

.gate-or {
  display: flex; align-items: center; gap: 10px;
  margin: 18px 0 14px; color: var(--muted); font-size: 12px;
}
.gate-or::before, .gate-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ------------------------------- users --------------------------------- */

/* The users table lives on its own page and needs the full window width,
   unlike the note form which reads better capped. */
.content-wide { max-width: none; padding-left: 20px; padding-right: 20px; }

/* On that page the sidebar is dropped outright -- 268px the table would rather
   have, and the page carries its own "Back to the note" button. */
.app.full-bleed .sidebar { display: none; }

.user-filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.user-filters input { flex: 1; min-width: 200px; }
.user-filters select { width: 150px; flex: 0 0 auto; }

.user-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }

/* Natural column widths, nothing wrapping. Fixed percentages were squeezing
   emails onto two lines and breaking "ENABLE" in half. */
.user-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.user-table th {
  background: var(--navy); color: #fff; text-align: left;
  padding: 9px 10px; font-weight: 500; font-size: 11px;
  letter-spacing: .03em; white-space: nowrap;
}
.user-table td {
  padding: 9px 10px; border-bottom: 1px solid var(--line);
  vertical-align: middle; white-space: nowrap;
}
.user-table tr:last-child td { border-bottom: 0; }
.user-table tr:nth-child(even) td { background: #fafcfe; }
.user-table tr.inactive td { opacity: .55; }
.user-table strong { font-weight: 600; }

/* Name and email take whatever is left over; everything else stays compact. */
.user-table td:nth-child(4) { width: 100%; }

.role-select { padding: 4px 8px; font-size: 12.5px; width: auto; min-width: 118px; }

.pill {
  display: inline-block; white-space: nowrap;
  font-size: 10.5px; font-weight: 600; padding: 4px 9px;
  border-radius: 4px; letter-spacing: .03em;
}
.pill-on { background: #e7f5ee; color: var(--ok); }
.pill-off { background: #fdecea; color: var(--bad); }
.users-list { margin: 16px 0 22px; }
.user-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.user-row.inactive { opacity: .5; }
.user-row strong { display: block; font-size: 14px; }
.user-meta { font-size: 12px; color: var(--muted); }
.user-actions { display: flex; gap: 5px; flex-wrap: nowrap; }
.user-actions .chip { padding: 4px 10px; font-size: 11.5px; white-space: nowrap; }
.injection-row { border: 1px solid var(--line); border-radius: 8px; padding: 14px; margin-bottom: 10px; background: #fbfcfe; }
.injection-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.injection-no { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.injection-row .field { margin-bottom: 0; }

.service-name { font-size: 14px; font-weight: 500; align-self: center; }
.chip-danger { color: var(--bad); border-color: #f0c9c4; }
.chip-danger:hover { background: #fdf3f2; border-color: var(--bad); }
#users-form .card { margin-bottom: 0; }
#users-form h3 { margin-bottom: 14px; }
.gate-fine { color: var(--muted); font-size: 11px; line-height: 1.6; margin: 20px 0 0; text-align: center; }

/* ------------------------------- layout -------------------------------- */

.app { display: flex; min-height: 100%; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: linear-gradient(175deg, var(--deep), var(--navy) 60%, #001e56);
  color: #eaf2fb;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { padding: 26px 22px 18px; }
.sidebar-brand img { width: 100%; max-width: 176px; display: block; }

.stepper { flex: 1; overflow-y: auto; padding: 6px 12px 12px; }
.step {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: transparent; border: 0; color: #c3d6ec;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  font-size: 13.5px; line-height: 1.3;
}
.step:hover { background: rgba(255,255,255,.07); color: #fff; }
.step.active { background: rgba(39,167,222,.20); color: #fff; font-weight: 500; }
.step-num {
  flex: 0 0 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
  background: rgba(255,255,255,.13); color: #eaf2fb;
}
.step.active .step-num { background: var(--cyan); color: #00263f; }
.step.done .step-num { background: rgba(18,138,86,.85); color: #fff; }

.sidebar-foot { padding: 16px 18px 20px; border-top: 1px solid rgba(255,255,255,.12); }
.who { font-size: 12px; color: #a9c3e0; margin-bottom: 10px; line-height: 1.4; }
.sidebar-foot .btn-ghost { border-color: rgba(255,255,255,.28); color: #dbe8f7; width: 100%; }
.sidebar-foot .btn-ghost + .btn-ghost { margin-top: 8px; }
.sidebar-foot .btn-ghost:hover { border-color: var(--cyan); color: #fff; background: rgba(255,255,255,.06); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 24px; background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-patient { flex: 1; min-width: 0; line-height: 1.3; }
.topbar-patient strong { display: block; font-size: 14.5px; font-weight: 600; }
.topbar-patient span { font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; gap: 8px; }

.content { flex: 1; padding: 26px 24px 40px; max-width: 980px; width: 100%; }

.navbar {
  position: sticky; bottom: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 24px; background: #fff; border-top: 1px solid var(--line);
}
.progress { font-size: 12.5px; color: var(--muted); }

/* ------------------------------- sections ------------------------------ */

.section-head { margin-bottom: 20px; }
.section-head h2 { font-size: 20px; color: var(--navy); }
.section-head p { margin: 6px 0 0; color: var(--muted); font-size: 13.5px; line-height: 1.55; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}
.card > h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin-bottom: 14px;
}

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field > label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--ink); margin-bottom: 6px;
}
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; line-height: 1.5; }

input[type="text"], input[type="date"], input[type="number"],
input[type="search"], input[type="tel"], select, textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: #fbfcfe;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--cyan); outline-offset: 1px; background: #fff; }
textarea { min-height: 92px; resize: vertical; line-height: 1.55; }
textarea.tall { min-height: 150px; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* ---------------------------- repeating rows --------------------------- */

.rows { display: flex; flex-direction: column; gap: 8px; }
.row-item {
  display: grid; gap: 8px; align-items: start;
  grid-template-columns: 1fr auto;
}
.row-item.two { grid-template-columns: 2fr 1fr auto; }
.row-item.verb { grid-template-columns: 130px 1fr auto; }
.row-del {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  width: 38px; height: 38px; cursor: pointer; color: var(--muted); font-size: 16px;
}
.row-del:hover { border-color: #f0c9c4; color: var(--bad); }
.row-add { margin-top: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 5px 12px; font-size: 12px; cursor: pointer; color: var(--navy);
}
.chip:hover { border-color: var(--cyan); background: #f2fafe; }

/* ------------------------------ ROS / exam ----------------------------- */

.sys { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; background: #fff; }
.sys-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid transparent;
}
.sys.edited .sys-head { border-bottom-color: var(--line); }
.sys-label { flex: 1; font-size: 12.5px; font-weight: 600; letter-spacing: .02em; }
.sys-state { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: #eef7f2; color: var(--ok); }
.sys-state.pos { background: #fdf2ec; color: var(--warn); }
.sys-body { padding: 0 14px 12px; }
.sys-body textarea { min-height: 62px; font-size: 13.5px; }
.sys-actions { display: flex; gap: 6px; padding: 0 14px 12px; }

/* -------------------------------- labs --------------------------------- */

.lab-group { margin-bottom: 18px; }
.lab-group h4 {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 0 0 10px;
}
.lab-grid { display: grid; gap: 10px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.lab {
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: #fff;
}
.lab-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.lab-name { flex: 1; font-size: 12px; font-weight: 600; }
.lab-input { display: flex; gap: 6px; }
.lab-input input { flex: 1; padding: 7px 10px; font-size: 13.5px; }
.lab-input select { width: 82px; padding: 7px 6px; font-size: 12px; }
.lab-range { font-size: 10.5px; color: var(--muted); margin-top: 5px; }
.flag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 5px; }
.flag-OK, .flag-G { background: #e7f5ee; color: var(--ok); }
.flag-SO { background: #fdf4e6; color: var(--warn); }
.flag-hi { background: #fdecea; color: var(--bad); }
.flag-LOW { background: #eaf1fb; color: #1d5fbf; }

/* ------------------------------- patient ------------------------------- */

.search-wrap { position: relative; }
.results {
  border: 1px solid var(--line); border-radius: 8px; margin-top: 8px;
  max-height: 320px; overflow-y: auto; background: #fff;
}
.result {
  display: block; width: 100%; text-align: left;
  border: 0; border-bottom: 1px solid var(--line); background: #fff;
  padding: 12px 14px; cursor: pointer;
}
.result:last-child { border-bottom: 0; }
.result:hover { background: #f2fafe; }
.result strong { display: block; font-size: 14px; }
.result span { font-size: 12px; color: var(--muted); }

.patient-card {
  border: 1px solid var(--cyan); background: #f4fbfe;
  border-radius: var(--radius); padding: 16px 18px;
}
.patient-card h3 { font-size: 17px; color: var(--navy); margin-bottom: 10px; }
.patient-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px 18px; }
.fact span { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.fact strong { font-size: 13.5px; font-weight: 500; }

.prior { margin-top: 14px; }
.prior-item {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px;
}
.prior-item:last-child { border-bottom: 0; }
.prior-item span { color: var(--muted); font-size: 12px; }

/* ------------------------------- review -------------------------------- */

.review dl { margin: 0; }
.review dt {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin-top: 14px;
}
.review dt:first-child { margin-top: 0; }
.review dd {
  margin: 4px 0 0; font-size: 13.5px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
}

.alert { border-radius: 8px; padding: 12px 14px; font-size: 13px; line-height: 1.55; margin-bottom: 14px; }
.alert-bad { background: #fdecea; border: 1px solid #f5c6c0; color: #8c2c21; }
.alert-warn { background: #fdf6e9; border: 1px solid #f0dcb4; color: #7a5510; }
.alert ul { margin: 6px 0 0; padding-left: 20px; }

.check { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; font-size: 13.5px; line-height: 1.5; }
.check input { width: 18px; height: 18px; margin-top: 1px; flex: 0 0 18px; accent-color: var(--navy); }

/* ------------------------------ overlays ------------------------------- */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(0, 20, 45, .55); padding: 24px;
}
.overlay-card {
  background: #fff; border-radius: 14px; padding: 32px;
  text-align: center; max-width: 420px; width: 100%;
  box-shadow: 0 20px 50px rgba(0, 20, 60, .3);
}
.overlay-card h2 { font-size: 20px; color: var(--navy); margin-bottom: 8px; }
.overlay-card p { color: var(--muted); font-size: 13.5px; line-height: 1.6; margin: 0; }
.overlay-actions { margin-top: 22px; }
.spinner {
  width: 34px; height: 34px; margin: 0 auto 16px;
  border: 3px solid var(--line); border-top-color: var(--cyan);
  border-radius: 50%; animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.tick {
  width: 46px; height: 46px; margin: 0 auto 14px; border-radius: 50%;
  background: #e7f5ee; color: var(--ok);
  display: grid; place-items: center; font-size: 24px;
}

/* ----------------------------- responsive ------------------------------ */

@media (max-width: 1023px) {
  .app { flex-direction: column; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.3);
  }
  .sidebar.open { transform: translateX(0); }
  .icon-btn { display: block; }
  .content { padding: 20px 16px 32px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .lab-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row-item.verb { grid-template-columns: 110px 1fr auto; }
}

@media (max-width: 620px) {
  .lab-grid { grid-template-columns: 1fr; }
  .row-item.two, .row-item.verb { grid-template-columns: 1fr auto; }
  .row-item.two > :nth-child(2), .row-item.verb > :nth-child(1) { grid-column: 1 / -1; }
  .topbar-actions { display: none; }
}

@media print { .sidebar, .topbar, .navbar { display: none; } }
