/* MediCore EHR - Presentation layer styles */
:root {
  --primary: #0f8b8d; --primary-dark: #0b6a6c; --primary-soft: #e3f4f4;
  --accent: #f2a541; --danger: #d64545; --danger-soft: #fdecec;
  --success: #2e9e5b; --success-soft: #e6f6ec; --warn: #c98a12; --warn-soft: #fdf4e1;
  --info: #3a7bd5; --info-soft: #e8f0fc;
  --bg: #f1f6f7; --surface: #ffffff; --surface-2: #f7fafb; --border: #dbe6e8;
  --text: #1d2b2f; --muted: #5f7479; --shadow: 0 2px 10px rgba(15, 60, 70, .08);
  --radius: 12px;
}
[data-theme="dark"] {
  --primary: #2bb3b5; --primary-dark: #1f9294; --primary-soft: #16383a;
  --danger-soft: #3d2222; --success-soft: #1c3627; --warn-soft: #3a311c; --info-soft: #1d2b42;
  --bg: #0f1a1c; --surface: #172427; --surface-2: #1c2c30; --border: #2a3d41;
  --text: #e4eef0; --muted: #93a8ad; --shadow: 0 2px 10px rgba(0, 0, 0, .35);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", Tahoma, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); }
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero { background: linear-gradient(135deg, #0b6a6c, #0f8b8d 55%, #33b6a8); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: center; }
.login-hero h1 { font-size: 40px; margin: 18px 0 8px; }
.login-hero p { opacity: .9; font-size: 16px; line-height: 1.6; max-width: 460px; }
.login-hero ul { padding: 0; list-style: none; margin-top: 24px; }
.login-hero li { margin: 10px 0; font-size: 15px; }
.logo { width: 64px; height: 64px; border-radius: 18px; background: #fff; color: var(--primary); display: grid; place-items: center; font-size: 34px; font-weight: 800; box-shadow: var(--shadow); }
.login-panel { display: grid; place-items: center; padding: 32px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); padding: 36px; border-radius: 18px; box-shadow: var(--shadow); }
.login-card h2 { margin: 0 0 4px; }
.demo-accounts { margin-top: 18px; font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px dashed var(--border); border-radius: 10px; padding: 10px 12px; }
.demo-accounts code { color: var(--text); }
.demo-accounts button { border: 0; background: none; color: var(--primary); cursor: pointer; padding: 0; text-decoration: underline; font-size: 12px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: linear-gradient(180deg, #0b6a6c, #0f8b8d); color: #fff; padding: 20px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; border-bottom: 1px solid rgba(255,255,255,.18); }
.brand .logo { width: 40px; height: 40px; font-size: 20px; border-radius: 12px; }
.brand b { font-size: 17px; display: block; }
.brand small { opacity: .8; font-size: 11px; }
.nav { margin-top: 14px; flex: 1; overflow: auto; }
.nav button { width: 100%; text-align: left; border: 0; background: transparent; color: #fff; padding: 10px 12px; border-radius: 10px; cursor: pointer; display: flex; align-items: center; gap: 10px; font-size: 14px; opacity: .88; }
.nav button:hover { background: rgba(255,255,255,.12); opacity: 1; }
.nav button.active { background: #fff; color: var(--primary-dark); opacity: 1; font-weight: 600; }
.nav .badge { margin-left: auto; background: var(--accent); color: #222; border-radius: 10px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.18); padding-top: 12px; font-size: 12px; }
.sidebar-foot button { width: 100%; margin-top: 8px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 26px; display: flex; align-items: center; gap: 14px; position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 20px; margin: 0; flex: 1; }
.topbar .who { text-align: right; font-size: 12px; color: var(--muted); }
.topbar .who b { color: var(--text); font-size: 13px; display: block; }
.icon-btn { position: relative; border: 1px solid var(--border); background: var(--surface-2); width: 38px; height: 38px; border-radius: 10px; cursor: pointer; font-size: 17px; }
.icon-btn .dot { position: absolute; top: -6px; right: -6px; background: var(--danger); color: #fff; font-size: 10px; border-radius: 9px; padding: 1px 5px; font-weight: 700; }
.content { padding: 24px 26px 40px; }

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card h3 { margin: 0 0 12px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h3 { margin: 0; flex: 1; }
.grid { display: grid; gap: 18px; }
.g2 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: repeat(3, 1fr); } .g4 { grid-template-columns: repeat(4, 1fr); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; }
.kpi .ic { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; background: var(--primary-soft); }
.kpi b { font-size: 22px; display: block; }
.kpi span { color: var(--muted); font-size: 12px; }
.kpi.warn .ic { background: var(--warn-soft); } .kpi.danger .ic { background: var(--danger-soft); } .kpi.ok .ic { background: var(--success-soft); }

.btn { border: 1px solid transparent; background: var(--primary); color: #fff; padding: 8px 14px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.light { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.light:hover { background: var(--primary-soft); }
.btn.danger { background: var(--danger); } .btn.danger:hover { filter: brightness(.92); }
.btn.success { background: var(--success); } .btn.warn { background: var(--warn); }
.btn.sm { padding: 5px 9px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; padding: 11px; font-size: 14px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.field label .req { color: var(--danger); }
.input, select.input, textarea.input { border: 1px solid var(--border); background: var(--surface-2); border-radius: 9px; padding: 9px 11px; outline: none; width: 100%; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input.invalid { border-color: var(--danger); }
.err-msg { color: var(--danger); font-size: 12px; min-height: 0; }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.form-grid .span2 { grid-column: span 2; } .form-grid .span3 { grid-column: span 3; }
.section-title { grid-column: 1 / -1; font-size: 13px; font-weight: 700; color: var(--primary); margin: 6px 0 10px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.search-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.search-bar .input { max-width: 320px; }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { background: var(--primary-soft); color: var(--primary-dark); text-align: left; font-size: 12px; padding: 9px 10px; white-space: nowrap; }
[data-theme="dark"] .tbl th { color: var(--primary); }
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:hover td { background: var(--surface-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-wrap { overflow: auto; max-height: 560px; border: 1px solid var(--border); border-radius: 10px; }
.empty { text-align: center; color: var(--muted); padding: 26px; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.pill.gray { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.pill.blue { background: var(--info-soft); color: var(--info); }
.pill.green { background: var(--success-soft); color: var(--success); }
.pill.red { background: var(--danger-soft); color: var(--danger); }
.pill.amber { background: var(--warn-soft); color: var(--warn); }
.pill.teal { background: var(--primary-soft); color: var(--primary); }

.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; } .mono { font-family: Consolas, monospace; }
.money { font-variant-numeric: tabular-nums; font-weight: 600; }
.alert { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 13px; }
.alert.red { background: var(--danger-soft); color: var(--danger); }
.alert.amber { background: var(--warn-soft); color: var(--warn); }
.alert.green { background: var(--success-soft); color: var(--success); }
.alert.blue { background: var(--info-soft); color: var(--info); }

.patient-banner { display: flex; gap: 16px; align-items: center; background: var(--primary-soft); border-radius: 12px; padding: 14px 16px; margin-bottom: 16px; flex-wrap: wrap; }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 20px; font-weight: 700; }
.patient-banner .meta { display: flex; gap: 18px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.patient-banner .meta b { color: var(--text); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 22px; border-left: 2px solid var(--border); position: relative; margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 12px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 120px 1fr 110px; gap: 10px; align-items: center; font-size: 13px; }
.bar-track { background: var(--surface-2); border-radius: 6px; height: 16px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #33b6a8); border-radius: 6px; }

.temp-gauge { display: flex; align-items: center; gap: 16px; }
.temp-gauge .big { font-size: 38px; font-weight: 800; }
.temp-gauge .range { font-size: 12px; color: var(--muted); }

/* ---------- Modal / toast / notifications ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(8, 25, 30, .55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 760px; max-height: 92vh; overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal.sm { max-width: 460px; } .modal.lg { max-width: 980px; }
.modal-h { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-h h3 { margin: 0; flex: 1; font-size: 17px; }
.modal-b { padding: 18px 20px; }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: 0; background: var(--surface); }
.x-btn { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }

#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: #1d2b2f; color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; min-width: 240px; border-left: 4px solid var(--primary); animation: tin .25s ease; }
.toast.error { border-left-color: var(--danger); } .toast.success { border-left-color: var(--success); } .toast.warn { border-left-color: var(--accent); }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } }

.notif-panel { position: absolute; right: 26px; top: 60px; width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.18); z-index: 30; max-height: 420px; overflow: auto; }
.notif-panel .n { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; cursor: pointer; }
.notif-panel .n.unread { background: var(--primary-soft); }
.notif-panel .n small { color: var(--muted); display: block; margin-top: 3px; }

/* ---------- Printable documents (face sheet, receipt, statement, report) ---------- */
.doc { background: #fff; color: #111; padding: 26px; border: 1px solid #ccc; font-size: 13px; }
.doc-h { display: flex; justify-content: space-between; align-items: center; border-bottom: 3px solid #0f8b8d; padding-bottom: 10px; margin-bottom: 14px; }
.doc-h h2 { margin: 0; color: #0b6a6c; }
.doc table { width: 100%; border-collapse: collapse; margin: 8px 0 14px; }
.doc td, .doc th { border: 1px solid #c9d5d7; padding: 6px 8px; text-align: left; }
.doc th { background: #e3f4f4; }
.doc .lbl { width: 30%; background: #f4f8f8; font-weight: 600; }
.doc .sig { display: flex; justify-content: space-between; margin-top: 40px; }
.doc .sig div { border-top: 1px solid #333; width: 40%; text-align: center; padding-top: 4px; }

@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; left: 0; top: 0; width: 100%; border: 0; }
}
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, 1fr); } .g3 { grid-template-columns: 1fr 1fr; } .form-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 800px) {
  .login-wrap { grid-template-columns: 1fr; } .login-hero { display: none; }
  .shell { grid-template-columns: 1fr; } .sidebar { position: static; height: auto; }
  .g2, .g3, .g4, .form-grid { grid-template-columns: 1fr; } .form-grid .span2, .form-grid .span3 { grid-column: auto; }
}
.mono { white-space: nowrap; }
[id$="-r"]:empty { display: none; }
