:root {
  --bg: #060c1c;
  --panel: #0a132b;
  --card: #0e1838;
  --border: #20305c;
  --text: #f3f6fa;
  --muted: #9fadcc;
  --accent: #5aadff;
  --green: #3fb950;
  --amber: #e3b341;
  --red: #ff7b72;
  --mw: #c49bff;
  --icog: #5aadff;
  --eyris: #56d364;
  --bioage: #ffa657;
  --summary: #58a6ff;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px; line-height: 1.5;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #0a132b, #060c1c);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { height: 64px; width: auto; display: block; object-fit: contain; }
.topbar h1 { margin: 0; font-size: 21px; font-weight: 700; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
.topright { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: flex-end; }
.modeSwitch {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--panel);
}
.modeLabel { font-size: 12px; color: var(--muted); padding: 0 6px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.modeBtn {
  border: 0; background: transparent; color: var(--muted);
  font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 999px;
  cursor: pointer;
}
.modeBtn:hover { color: var(--text); }
.modeBtn.active { background: var(--accent); color: #fff; }
.modeHint { font-size: 12px; color: var(--muted); max-width: 280px; line-height: 1.4; }
.modeHint.warn { color: var(--amber); }
.link { color: var(--accent); text-decoration: none; font-size: 14px; }
.status { font-size: 14px; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status.ok .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status.down .dot { background: var(--red); }

.wrap { max-width: 960px; margin: 0 auto; padding: 26px 22px 60px; }

.block {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px; margin-bottom: 20px;
}
.block-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.block-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.block-head h2 small { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 8px; }
.step {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent);
  color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 700;
}

.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.patient-grid {
  width: 100%;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: start;
}
.patient-grid.has-patient-id {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.patient-field {
  display: flex;
  flex-direction: column;
  margin: 0;
  min-width: 0;
  width: 100%;
}
.patient-field input,
.patient-field select,
.patient-field .dob-row {
  width: 100%;
  margin-top: 6px;
}
.field-label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}
.patient-hint { margin: 8px 0 0; }
#patientIdField[hidden],
#patientIdHint[hidden] { display: none !important; }
label { display: block; font-size: 14px; font-weight: 600; color: var(--text); }
.req { color: var(--red); }
input, select {
  width: 100%; margin-top: 8px; padding: 11px 13px;
  background: #040a18; border: 1px solid var(--border); border-radius: 8px;
  color: #f0f6fc; font-size: 15px; font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(90, 173, 255, 0.2); }
input[readonly] { background: #0a1224; color: var(--muted); cursor: default; }
input[readonly]:focus { border-color: var(--border); box-shadow: none; }
.fieldhint { display: block; font-size: 12px; font-weight: 400; color: var(--muted); line-height: 1.4; }
.dob-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px;
  gap: 8px;
  margin-top: 6px;
}
.dob-row select, .dob-row input { margin-top: 0; min-width: 0; }
#birth_year { padding-left: 10px; padding-right: 10px; text-align: center; }
#exam_date {
  min-width: 0;
  padding-right: 10px;
  color-scheme: dark;
}
input[type="date"]::-webkit-calendar-picker-indicator {
  margin-left: 0;
  padding: 0;
}
select option { background: #0a132b; color: var(--text); }

.folderbar { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.folderbtn {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  background: #18202e; border: 1px solid var(--accent); color: var(--accent);
  padding: 9px 16px; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.folderbtn:hover { background: #1d2738; }
.folderbtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.folderhint { color: var(--muted); font-size: 14px; }
.folderhint.ok { color: var(--green); }
.folderhint.warn { color: var(--amber); }

.shots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.shot-label { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 8px; min-height: 34px; }
.drop {
  position: relative; display: grid; place-items: center; height: 130px;
  border: 1.5px dashed var(--border); border-radius: 10px; cursor: pointer;
  background: #040a18; overflow: hidden; text-align: center;
}
.drop:hover { border-color: var(--accent); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop span { color: var(--muted); font-size: 14px; padding: 0 8px; }
.drop.filled { border-style: solid; border-color: var(--green); }
.drop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.drop .tag {
  position: absolute; bottom: 6px; right: 6px; background: rgba(0,0,0,.7);
  color: #fff; font-size: 10px; padding: 2px 6px; border-radius: 5px; z-index: 2;
}

.pkg-modes { display: inline-flex; gap: 4px; margin-bottom: 14px; padding: 4px;
  background: #11161f; border: 1.5px solid var(--border); border-radius: 10px; }
.pkg-mode { cursor: pointer; border: none; background: transparent; color: var(--muted);
  font-size: 14px; font-weight: 600; padding: 8px 20px; border-radius: 7px; transition: background .15s, color .15s; }
.pkg-mode:hover { color: var(--text); }
.pkg-mode.active { background: var(--accent); color: #0d1117; }

.packages { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.packages[data-group="combo"] { grid-template-columns: repeat(2, 1fr); }
.packages[hidden] { display: none; }
.pkg { cursor: pointer; display: block; }
.pkg input { display: none; }
.pkg-body {
  border: 1.5px solid var(--border); border-radius: 12px; padding: 16px; height: 100%;
  transition: border-color .15s, background .15s;
}
.pkg:hover .pkg-body { border-color: var(--muted); }
.pkg input:checked + .pkg-body { border-color: var(--accent); background: #18202e; }
.pkg-body h3 { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.pkg-body p { margin: 0 0 12px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.badges { display: flex; gap: 6px; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 6px; color: #0d1117; }
.badge.mw { background: var(--mw); }
.badge.icog { background: var(--icog); }
.badge.eyris { background: var(--eyris); }
.badge.bioage { background: var(--bioage); }
.badge.summary { background: var(--summary); }

.actions { display: flex; gap: 12px; margin-top: 6px; }
.run {
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  padding: 13px 26px; border-radius: 10px; font-size: 15px; font-weight: 700;
}
.run:hover { filter: brightness(1.08); }
.run:disabled { opacity: .6; cursor: not-allowed; }
.reset {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  padding: 13px 20px; border-radius: 10px; font-size: 14px; cursor: pointer;
}

.results { margin-top: 30px; }
.results-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.results-head h2 { margin: 0; font-size: 17px; }
.copy { background: transparent; border: 1px solid var(--border); color: var(--text);
  padding: 7px 14px; border-radius: 8px; font-size: 13px; cursor: pointer; }

.vcard {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; margin-bottom: 16px; overflow: hidden;
}
.vcard-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.vcard-head h3 { margin: 0; font-size: 16px; flex: 1; font-weight: 600; }
.pill { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 20px; }
.pill.run { background: #1f2a3d; color: var(--accent); }
.pill.ok { background: #1b3a26; color: var(--green); }
.pill.err { background: #3a1d1d; color: var(--red); }
.steps { padding: 12px 18px; display: flex; flex-direction: column; gap: 7px; }
.sline { font-size: 14px; display: flex; gap: 9px; align-items: baseline; }
.sline .ic { width: 16px; text-align: center; }
.sline.ok .ic { color: var(--green); }
.sline.err .ic { color: var(--red); }
.sline.run .ic { color: var(--amber); }
.sline .lbl { color: var(--text); font-weight: 500; }
.sline .det { color: var(--muted); font-family: var(--mono); font-size: 13px; }
.report-links { padding: 0 18px 14px; display: flex; gap: 10px; flex-wrap: wrap; }
.report-links a {
  font-size: 14px; color: #fff; background: var(--accent);
  padding: 7px 13px; border-radius: 8px; text-decoration: none;
}
.report-links a.dlbtn,
.report-links button.dlbtn { background: var(--green); font-weight: 600; border: none; cursor: pointer; }
.report-links a.dlbtn:hover,
.report-links button.dlbtn:hover { filter: brightness(1.08); }
.report-links button.dlbtn:disabled,
.combo-dlbtn:disabled { opacity: 0.88; cursor: wait; }

.combo-dl { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); text-align: center; }
.combo-dlbtn { width: 100%; max-width: 520px; }

details.raw { border-top: 1px solid var(--border); }
details.raw summary { cursor: pointer; padding: 10px 18px; color: var(--muted); font-size: 14px; }
pre.json {
  margin: 0; padding: 14px 18px; background: #040a18; overflow: auto;
  font-family: var(--mono); font-size: 13px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
  color: var(--text);
}
.json .k { color: #7ee787; } .json .s { color: #a5d6ff; }
.json .n { color: #f0883e; } .json .b { color: #d2a8ff; } .json .null { color: var(--muted); }

.banner { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 13.5px; }
.banner.err { background: #3a1d1d; color: #ffb4ae; border: 1px solid #5a2a2a; }
.banner.keep-awake {
  position: sticky;
  top: 56px;
  z-index: 4;
  background: #1a2f4a;
  color: #b8d9ff;
  border: 1px solid #2f5f9a;
  line-height: 1.5;
}
.banner.keep-awake strong { color: #e8f3ff; }
.keep-awake-tip { color: #8eb8e8; font-size: 12.5px; }

.linkbtn {
  background: none; border: 0; color: var(--muted); cursor: pointer;
  font-size: 14px; padding: 0; font-family: inherit;
}
.linkbtn:hover { color: var(--text); }
.logout-form { margin: 0; }

/* Dashboard modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 60px 20px; overflow-y: auto;
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: 100%; max-width: 860px;
  background: var(--card, #15171c); color: var(--text, #e9edf2);
  border: 1px solid var(--border, #2a2e36); border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border, #2a2e36);
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-close {
  background: none; border: 0; color: var(--muted, #9aa3af);
  font-size: 26px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.modal-close:hover { color: var(--text, #fff); }
.modal-body { padding: 16px 20px; }

.dash-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.dash-table th, .dash-table td {
  text-align: left; padding: 10px 12px;
  border-bottom: 1px solid var(--border, #2a2e36);
}
.dash-table th { color: var(--muted, #9aa3af); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.03em; }
.dash-table td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.dash-empty { text-align: center; color: var(--muted, #9aa3af); padding: 24px 12px; }
.dash-status {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; background: #2a2e36; color: #cfd5de; text-transform: capitalize;
}
.dash-status.ok { background: #143a24; color: #7ee2a8; }
.dash-status.bad { background: #3a1d1d; color: #ffb4ae; }

.dash-api {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; background: #2a2e36; color: #cfd5de;
}
.dash-api.real { background: #3a2f14; color: #ffd78a; }
.dash-api.mock { background: #16303a; color: #8ad4e2; }

.userbadge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 12px; border-radius: 999px;
  background: #23283025; border: 1px solid var(--border);
  color: var(--text); font-size: 13px; font-weight: 600; white-space: nowrap;
}

.login-page {
  --login-form-min: 360px;
  --login-cover-width: min(1080px, max(0px, 100vw - var(--login-form-min)));
  --login-cover-y: 35%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  padding: 0;
  overflow-x: auto;
  overflow-y: hidden;
  background-color: var(--bg);
}
.login-cover {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--login-cover-width);
  height: 100vh;
  height: 100dvh;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(6, 12, 28, 0.2), rgba(6, 12, 28, 0.35)),
    url("/assets/cover_page.png");
  background-size: cover;
  background-position: center var(--login-cover-y);
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 0;
}
.login-wrap {
  position: relative;
  z-index: 1;
  margin-left: var(--login-cover-width);
  flex: 1 1 auto;
  width: calc(100% - var(--login-cover-width));
  min-width: var(--login-form-min);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
}
.login-card {
  background: rgba(10, 19, 43, 0.94);
  border: none;
  border-left: 1px solid var(--border);
  border-radius: 0;
  padding: clamp(28px, 4vw, 48px) clamp(24px, 3.5vw, 44px) clamp(24px, 3vw, 36px);
  flex: 1;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  box-shadow: none;
  backdrop-filter: blur(6px);
  overflow-y: auto;
}
.login-logo {
  height: clamp(56px, 8vw, 84px);
  width: auto;
  max-width: 100%;
  display: block;
  object-fit: contain;
  align-self: center;
  flex-shrink: 0;
  margin-bottom: 24px;
}
.login-card h1 {
  margin: 0 0 10px;
  font-size: clamp(22px, 2.4vw, 28px);
  font-weight: 700;
  color: var(--text);
}
.login-sub {
  margin: 0 0 clamp(20px, 3vw, 32px);
  color: #c9d1d9;
  font-size: clamp(14px, 1.6vw, 16px);
}
.login-form {
  text-align: left;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
}
.login-form label {
  display: block; margin-bottom: 20px;
  font-size: 15px; font-weight: 600; color: var(--text);
}
.login-form input {
  width: 100%;
  margin-top: 10px; padding: 14px 16px; font-size: 16px;
  background: #040a18; border: 1px solid var(--border); color: #f0f6fc;
}
.login-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 156, 255, 0.25); }
.login-btn {
  width: 100%; margin-top: 12px; justify-content: center;
  padding: 16px 26px; font-size: 17px; border-radius: 12px;
}
.login-err {
  background: #3a1d1d; color: #ffb4ae; border: 1px solid #5a2a2a;
  border-radius: 10px; padding: 14px 16px; font-size: 15px; margin-bottom: 20px;
  text-align: left;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}
.op-err { color: #ffb4ae; }
.op-err-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: #ff8a80; }
.op-err-action { display: block; margin-top: 6px; font-size: 13px; opacity: 0.92; }
.op-err-detail { margin-top: 8px; font-size: 12.5px; opacity: 0.85; }
.op-err-card {
  background: #2a1a1a; border: 1px solid #5a2a2a; border-radius: 8px;
  padding: 10px 12px; margin-bottom: 10px; font-size: 13px; color: #ffb4ae;
}
.status .op-err-id { margin-left: 6px; font-size: 11px; opacity: 0.9; }

.report-wrap { max-width: 720px; }
.report-banner { margin-bottom: 20px; }
.report-banner.ok {
  background: #143a24; color: #b8f0d0; border: 1px solid #2a5a3a;
}
.report-ref { font-size: 1.25rem; margin: 8px 0; color: #7ee2a8; }
.report-hint { font-size: 13px; opacity: 0.9; margin: 0; }
.report-hint.warn { color: var(--amber); }
.report-form textarea {
  width: 100%; min-height: 140px; resize: vertical;
  padding: 12px 14px; border-radius: 10px; font-size: 15px;
  background: #040a18; border: 1px solid var(--border); color: #f0f6fc;
  font-family: inherit; line-height: 1.5;
}
.report-form textarea:focus { border-color: var(--accent); outline: none; }
.report-desc-hint { margin: 6px 0 0; }
.report-grid .span2 { grid-column: 1 / -1; }
.report-note { color: var(--muted); font-size: 13px; margin: 0 0 16px; line-height: 1.5; }
.op-err-report { margin: 10px 0 0; font-size: 13px; }
.op-err-report a { color: #8ec8ff; text-decoration: underline; }
.login-notice {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  text-align: left;
  width: 100%;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}
.login-notice p { margin: 0 0 12px; }
.login-notice p:last-child { margin-bottom: 0; }

@media (max-width: 760px) {
  .grid, .shots, .packages { grid-template-columns: 1fr 1fr; }
  .patient-grid { grid-template-columns: 1fr 1fr; }
}

/* Download-complete popup */
.download-toast-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(8, 12, 20, 0.55);
}
.download-toast {
  position: relative;
  width: min(360px, 100%);
  padding: 22px 22px 18px;
  border: 1px solid var(--border, #2a3a52);
  border-radius: 14px;
  background: var(--panel, #121a28);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  text-align: center;
}
.download-toast h4 {
  margin: 0 0 8px;
  font-size: 18px;
  color: var(--text, #eef3fb);
}
.download-toast p {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted, #9db0c9);
}
.download-toast-ok {
  min-width: 96px;
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  background: var(--accent, #4da3ff);
  color: #081018;
  font-weight: 600;
  cursor: pointer;
}
.download-toast-ok:hover { filter: brightness(1.08); }
.download-toast-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: transparent;
  color: var(--muted, #9db0c9);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.download-toast-close:hover { color: var(--text, #eef3fb); }
.download-toast.success h4 { color: var(--green, #3fb950); }

/* WhatsApp floating support button */
.whatsapp-float {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #25d366;
  color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  transition: transform 0.15s ease, filter 0.15s ease, box-shadow 0.15s ease;
}
.whatsapp-float:hover {
  transform: translateY(-2px) scale(1.04);
  filter: brightness(1.06);
  box-shadow: 0 10px 28px rgba(37, 211, 102, 0.45);
  color: #fff;
}
.whatsapp-float:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}
.whatsapp-float svg {
  width: 28px;
  height: 28px;
  display: block;
}
@media (max-width: 760px) {
  .whatsapp-float {
    right: 16px;
    bottom: 16px;
    width: 52px;
    height: 52px;
  }
}
