:root {
  --ink: #172b35;
  --muted: #667981;
  --line: #dce7e8;
  --paper: #f5f8f7;
  --white: #fff;
  --teal: #0c756d;
  --teal-dark: #075b55;
  --teal-soft: #e3f2ef;
  --coral: #d96d55;
  --shadow: 0 16px 45px rgba(20, 54, 61, .09);
}

* { box-sizing: border-box; }
body { margin: 0; font-family: Inter, "Segoe UI", Arial, sans-serif; color: var(--ink); background: var(--paper); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 6px; color: var(--teal); font-size: 12px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 15% 15%, #d8efea, transparent 35%), linear-gradient(135deg, #f9fbfa, #e9f2f0); }
.login-card { width: min(430px, 100%); padding: 44px; border-radius: 22px; background: rgba(255,255,255,.94); box-shadow: var(--shadow); }
.login-card h1 { margin: 8px 0; font-family: Georgia, serif; font-size: 38px; }
.brand-mark { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 24px; border-radius: 16px; color: #fff; background: var(--teal); font-size: 34px; }
.brand-mark.small { width: 38px; height: 38px; margin: 0; border-radius: 11px; font-size: 25px; }
.stack { display: grid; gap: 16px; margin-top: 28px; }
label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; color: #38515a; }
input, select, textarea { width: 100%; padding: 12px 13px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft); }
textarea { min-height: 90px; resize: vertical; }
.primary { padding: 13px 18px; border: 0; border-radius: 9px; color: #fff; background: var(--teal); font-weight: 800; }
.primary:hover { background: var(--teal-dark); }
.primary.compact { padding: 10px 15px; }
.secondary { padding: 11px 16px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink); font-weight: 700; }
.danger { color: #a84331; }
.demo-hint { margin: 22px 0 0; padding: 12px; border-radius: 8px; background: var(--teal-soft); color: var(--teal-dark); font-size: 13px; text-align: center; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 68px minmax(0, 1fr) 0; grid-template-rows: auto 1fr; grid-template-areas: "topbar topbar topbar" "sidebar content docs"; }
.app-shell.has-current-visit { grid-template-columns: 68px minmax(0, 1fr) 68px; }
.sidebar { grid-area: sidebar; position: sticky; z-index: 9; top: 0; width: 68px; height: calc(100vh - 46px); display: flex; flex-direction: column; padding: 18px 10px; overflow: hidden; color: #e4f2ef; background: #103f42; transition: width .18s ease, padding .18s ease, box-shadow .18s ease; }
.sidebar:hover, .sidebar:focus-within, .sidebar.pinned { width: 245px; padding: 26px 18px; box-shadow: 12px 0 34px rgba(8,35,38,.18); }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 7px 32px; }
.brand strong { display: block; font-family: Georgia, serif; font-size: 20px; color: #fff; }
.brand small { display: block; max-width: 145px; margin-top: 3px; color: #a9c7c5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
nav { display: grid; gap: 6px; }
.brand > div, .user-panel > div:not(.avatar) { min-width: 0; opacity: 0; transform: translateX(-4px); transition: opacity .16s ease, transform .16s ease; }
.sidebar:hover .brand > div, .sidebar:focus-within .brand > div, .sidebar.pinned .brand > div, .sidebar:hover .user-panel > div:not(.avatar), .sidebar:focus-within .user-panel > div:not(.avatar), .sidebar.pinned .user-panel > div:not(.avatar) { opacity: 1; transform: translateX(0); }
nav button { display: flex; gap: 13px; align-items: center; width: 100%; padding: 12px 14px; overflow: hidden; border: 0; border-radius: 8px; color: #bcd1cf; background: transparent; text-align: left; white-space: nowrap; }
nav button:hover, nav button.active { color: #fff; background: rgba(255,255,255,.11); }
nav span { width: 20px; min-width: 20px; font-size: 20px; }
.user-panel { display: grid; grid-template-columns: 38px 1fr 28px; gap: 10px; align-items: center; margin-top: auto; padding-top: 20px; border-top: 1px solid rgba(255,255,255,.13); }
.user-panel strong, .user-panel small { display: block; }
.user-panel strong { font-size: 13px; color: #fff; }
.user-panel small { margin-top: 2px; color: #9ebcba; font-size: 11px; }
.user-panel button { border: 0; color: #c6d9d7; background: none; font-size: 20px; }
.avatar { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; color: var(--teal-dark); background: #d9eee9; font-weight: 900; }

.documents-sidebar { grid-area: docs; justify-self: end; position: sticky; z-index: 8; top: 0; width: 0; height: calc(100vh - 46px); overflow: hidden; color: #e8f3f1; background: #0b5b56; border-left: 1px solid rgba(255,255,255,.12); transition: width .18s ease, box-shadow .18s ease; }
.app-shell.has-current-visit .documents-sidebar { width: 68px; }
.app-shell.has-current-visit .documents-sidebar:hover, .app-shell.has-current-visit .documents-sidebar:focus-within, .app-shell.has-current-visit .documents-sidebar.pinned { width: 330px; box-shadow: -12px 0 34px rgba(8,35,38,.18); }
.app-shell.has-current-visit .documents-sidebar.force-collapsed { width: 68px !important; box-shadow: none !important; }
.documents-sidebar-mark { display: grid; place-items: center; width: 48px; height: 48px; margin: 18px 10px; border-radius: 13px; color: #fff; background: rgba(255,255,255,.12); font-size: 25px; font-weight: 900; }
.documents-sidebar-content { display: flex; flex-direction: column; width: 330px; height: calc(100vh - 130px); min-height: 0; padding: 4px 18px 18px; overflow: hidden; opacity: 0; transform: translateX(4px); transition: opacity .16s ease, transform .16s ease; }
.documents-sidebar:hover .documents-sidebar-content, .documents-sidebar:focus-within .documents-sidebar-content, .documents-sidebar.pinned .documents-sidebar-content { opacity: 1; transform: translateX(0); }
.documents-sidebar.force-collapsed .documents-sidebar-content { opacity: 0 !important; transform: translateX(4px) !important; pointer-events: none; }
.documents-sidebar h3 { margin: 0 0 8px; color: #fff; font-family: Georgia, serif; font-size: 20px; line-height: 1.15; }
.documents-sidebar-body { display: grid; flex: 1 1 auto; gap: 10px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 3px 18px 0; }
.documents-context { padding: 10px 0 12px; border-bottom: 1px solid rgba(255,255,255,.16); color: #cfe4e1; font-size: 12px; line-height: 1.45; }
.documents-context strong { display: block; color: #fff; font-size: 13px; }
.documents-sidebar-subtitle { margin: 8px 0 7px; color: #cfe4e1; font-size: 10px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.documents-create-panel, .documents-issued-panel { display: grid; gap: 8px; }
.documents-issued-panel { margin-top: 10px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.16); }
.document-create-list { display: grid; gap: 5px; }
.document-create-option { display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; align-items: center; gap: 8px; width: 100%; padding: 8px 9px; border: 1px solid rgba(255,255,255,.14); border-radius: 8px; color: #eef8f6; background: rgba(255,255,255,.06); text-align: left; }
.document-create-option:hover, .document-create-option:focus-visible { border-color: rgba(255,255,255,.32); background: rgba(255,255,255,.13); outline: none; }
.document-create-option span { display: grid; place-items: center; color: #bfe1dd; font-size: 14px; }
.document-create-option strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.document-create-option em { justify-self: end; max-width: 82px; overflow: hidden; color: #d7f6f1; font-size: 10px; font-style: normal; font-weight: 900; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.document-create-option.empty-slot { color: #a8c2be; border-color: rgba(255,255,255,.09); background: rgba(0,0,0,.16); }
.document-create-option.empty-slot strong { color: #c8d9d6; }
.document-create-option.empty-slot em { color: #78918d; }
.document-create-option.empty-slot .document-create-icon { color: #78918d; background: rgba(0,0,0,.18); }
.document-create-option.issued { color: #fff; border-color: #c5fff6; background: linear-gradient(90deg, rgba(156,226,216,.52), rgba(255,255,255,.20)); box-shadow: inset 5px 0 0 #c5fff6, 0 0 0 1px rgba(197,255,246,.24), 0 8px 18px rgba(0,0,0,.14); }
.document-create-option.issued strong { color: #fff; }
.document-create-option.issued em { color: #f2fffd; }
.document-create-option.issued:hover, .document-create-option.issued:focus-visible { border-color: #e5fffb; background: linear-gradient(90deg, rgba(156,226,216,.66), rgba(255,255,255,.26)); }
.document-create-option.issued .document-create-icon { color: #07514c; background: #c9f3ed; }
.document-create-icon { width: 20px; height: 20px; border-radius: 999px; background: rgba(255,255,255,.1); font-size: 11px !important; font-weight: 900; }
.documents-sidebar .primary, .documents-sidebar .secondary { width: 100%; padding: 9px 10px; font-size: 12px; }
.documents-sidebar .secondary { color: #e8f3f1; border-color: rgba(255,255,255,.2); background: rgba(255,255,255,.08); }
.documents-sidebar .primary { background: #0b8379; }
.documents-sidebar .empty { padding: 20px 12px; color: #cfe4e1; border: 1px dashed rgba(255,255,255,.22); border-radius: 10px; text-align: left; }
.document-menu-card { display: grid; gap: 9px; padding: 12px; border: 1px solid rgba(255,255,255,.18); border-radius: 11px; background: rgba(255,255,255,.08); }
.document-menu-card.active { border-color: #9ce2d8; background: rgba(156,226,216,.2); box-shadow: 0 0 0 2px rgba(156,226,216,.2); }
.document-menu-card strong { color: #fff; font-size: 13px; }
.document-menu-card .muted { color: #cfe4e1; font-size: 11px; }
.document-menu-card .badge { width: fit-content; }
.document-menu-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.document-menu-actions .primary, .document-menu-actions .secondary { width: auto; padding: 7px 8px; }
.document-menu-actions .wide { grid-column: 1 / -1; }
.document-execution-result { margin-top: 7px; padding: 7px 9px; border-radius: 8px; background: #eef8f6; color: #285f59; font-size: 12px; }
.document-workspace-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin: 8px 0 16px; padding: 18px 20px; border: 1px solid #d9e8e6; border-radius: 13px; background: linear-gradient(120deg, #fff, #eef7f5); }
.document-workspace-head h3 { margin: 0; font-family: Georgia, serif; font-size: 26px; }
.document-workspace-head p:last-child { margin: 6px 0 0; }
#page-document > .modal-message { position: static; margin: 0 0 14px; }
#page-document #document-form { max-width: 1150px; }

.content { grid-area: content; min-width: 0; padding: 14px 24px 60px; }
.topbar { grid-area: topbar; position: sticky; top: 0; z-index: 30; display: flex; align-items: center; flex-wrap: nowrap; gap: 6px; min-height: 46px; padding: 4px 10px; border-bottom: 1px solid var(--line); background: rgba(245,248,247,.98); box-shadow: 0 4px 14px rgba(20,54,61,.05); }
.topbar-title { flex: 0 0 auto; min-width: 0; max-width: 120px; }
.topbar .quick-context-actions { flex: 0 0 auto; }
.topbar h2 { margin: 0; overflow: hidden; color: var(--muted); font-family: Inter, "Segoe UI", Arial, sans-serif; font-size: 12px; font-weight: 900; line-height: 1; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.topbar .eyebrow { display: none; }
.topbar .primary.compact { padding: 7px 10px; border-radius: 8px; font-size: 12px; line-height: 1; white-space: nowrap; }
.topbar .patient-icon { width: 24px; height: 24px; min-width: 24px; border-radius: 7px; }
.topbar .patient-icon svg { width: 14px; height: 14px; }
.icon-button { border: 0; background: transparent; color: var(--ink); font-size: 21px; }
#menu-toggle { display: none; }
.quick-context-actions { display: flex; align-items: center; gap: 4px; }
.quick-context-button { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 1px solid #cfe0de; border-radius: 7px; color: var(--teal-dark); background: #fff; font-size: 11px; font-weight: 900; line-height: 1; }
.quick-context-button:hover, .quick-context-button.active { color: #fff; border-color: var(--teal); background: var(--teal); }
.quick-context-button#quick-main-menu { font-size: 18px; }
.current-patient-bar { flex: 0 1 auto !important; display: flex; align-items: center; gap: 5px; min-width: 190px; padding: 4px 6px 4px 9px; border: 1px solid #cfe0de; border-radius: 9px; background: var(--teal-soft); }
.current-patient-bar > div { min-width: 0; flex: 1; }
.current-patient-bar small, .current-patient-bar strong { display: block; }
.current-patient-bar small { display: none; }
.current-patient-bar strong { max-width: 180px; margin-top: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; line-height: 1.1; }
.current-context-details { display: block; max-width: min(560px, 42vw); margin-top: 1px; overflow: hidden; color: #38515a; font-size: 10px; line-height: 1.1; text-overflow: ellipsis; white-space: nowrap; }
.current-patient-bar.has-visit-context { min-width: min(360px, 28vw); border-color: #9bcfca; background: #eefaf8; box-shadow: none; }
.current-patient-bar.has-visit-context strong { max-width: 190px; }
.current-visit-bar { flex: 0 1 auto !important; display: flex; align-items: center; gap: 5px; min-width: 220px; max-width: min(430px, 31vw); padding: 4px 6px 4px 9px; border: 1px solid #c9dcd9; border-left: 3px solid var(--teal); border-radius: 9px; background: #fff; box-shadow: none; }
.current-visit-bar > div { min-width: 0; flex: 1; }
.current-visit-bar small, .current-visit-bar strong { display: block; }
.current-visit-bar small { display: none; }
.current-visit-bar strong { max-width: 230px; margin-top: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; line-height: 1.1; }
.current-document-bar { flex: 0 1 auto !important; display: flex; align-items: center; gap: 5px; min-width: 210px; max-width: min(360px, 25vw); padding: 4px 6px 4px 9px; border: 1px solid #d6dfdd; border-left: 3px solid #6f8f8a; border-radius: 9px; background: #fbfdfc; box-shadow: none; }
.current-document-bar > div { min-width: 0; flex: 1; }
.current-document-bar small, .current-document-bar strong { display: block; }
.current-document-bar small { display: none; }
.current-document-bar strong { max-width: 200px; margin-top: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; line-height: 1.1; }
.current-user-bar { flex: 0 0 auto; display: flex; align-items: center; gap: 5px; max-width: 220px; margin-left: auto; padding: 4px 6px 4px 9px; border: 1px solid #cfe0de; border-radius: 9px; background: #fff; }
.current-user-bar > div { min-width: 0; flex: 1; }
.current-user-bar small, .current-user-bar strong { display: block; }
.current-user-bar small { display: none; }
.current-user-bar strong { max-width: 145px; margin-top: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; line-height: 1.1; }
.clear-patient { width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; color: var(--muted); background: transparent; font-size: 16px; }
.clear-patient:hover { color: #fff; background: var(--coral); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.card { padding: 22px; border: 1px solid #e5eceb; border-radius: 13px; background: #fff; box-shadow: 0 4px 18px rgba(26,62,67,.035); }
.stat { display: flex; justify-content: space-between; align-items: center; }
.stat strong { display: block; margin-top: 6px; font-family: Georgia, serif; font-size: 35px; }
.stat-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 13px; color: var(--teal); background: var(--teal-soft); font-size: 23px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 15px; margin: 30px 0 13px; }
.section-head h3 { margin: 0; font-family: Georgia, serif; font-size: 22px; }
.toolbar { display: flex; gap: 10px; }
.search { min-width: 260px; }
.pagination-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0; padding: 10px 12px; border: 1px solid #e2eae9; border-radius: 11px; background: #fff; }
.pagination-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pagination-actions .secondary { padding: 8px 11px; }
.journal-period-actions { align-items: flex-end; }
.journal-period-actions .journal-month-button { width: 42px; min-width: 42px; padding-inline: 0; font-size: 20px; line-height: 1; }
.pagination-actions select { width: auto; min-width: 120px; padding: 8px 10px; }
.visits-pagination { margin: 8px 0 10px; padding: 8px 10px; }

.table-wrap { overflow-x: auto; border: 1px solid #e2eae9; border-radius: 12px; background: #fff; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; border-bottom: 1px solid #edf1f1; text-align: left; font-size: 13px; }
th { color: var(--muted); background: #f9fbfa; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fbfa; }
tbody tr.patient-row.current { background: #e7f4f1; box-shadow: inset 4px 0 0 var(--teal); }
.link-button { border: 0; padding: 0; color: var(--teal); background: none; font-weight: 800; text-align: left; }
.patient-actions { display: flex; gap: 7px; }
.select-patient { display: grid; place-items: center; width: 24px; height: 24px; padding: 0; border: 2px solid #b8ccca; border-radius: 50%; color: transparent; background: #fff; font-size: 13px; font-weight: 900; }
.select-patient:hover { border-color: var(--teal); color: #8db9b4; }
.select-patient.selected { color: #fff; border-color: var(--teal); background: var(--teal); }
.patient-icon { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 1px solid #cfe0de; border-radius: 8px; color: var(--teal); background: #fff; }
.patient-icon:hover { color: #fff; border-color: var(--teal); background: var(--teal); }
.patient-icon:focus-visible { outline: 3px solid var(--teal-soft); outline-offset: 2px; }
.patient-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.badge { display: inline-block; padding: 5px 9px; border-radius: 99px; color: var(--teal-dark); background: var(--teal-soft); font-size: 11px; font-weight: 800; }
.badge.inactive { color: #785c55; background: #f4e9e6; }
.badge.sent { color: #245e39; background: #e2f2e7; }
.badge.cancelled { color: #785c55; background: #f4e9e6; }
.empty { padding: 45px 20px; color: var(--muted); text-align: center; }

dialog { width: min(760px, calc(100% - 30px)); max-height: 90vh; padding: 0; border: 0; border-radius: 15px; box-shadow: 0 25px 80px rgba(10,40,43,.25); overflow: auto; }
dialog::backdrop { background: rgba(8, 35, 38, .55); backdrop-filter: blur(3px); }
.modal-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; padding: 22px 26px; border-bottom: 1px solid var(--line); background: #fff; }
.modal-head h2 { margin: 0; font-family: Georgia, serif; }
.modal-message { position: sticky; top: 84px; z-index: 3; margin: 14px 26px 0; padding: 13px 16px; border: 1px solid; border-radius: 9px; font-size: 13px; font-weight: 700; line-height: 1.45; }
.modal-message.error { color: #7f2e22; border-color: #e8b6ad; background: #fff0ed; }
.modal-message.success { color: #245e39; border-color: #b9dbc5; background: #eaf7ee; }
#modal-content { padding: 24px 26px 28px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.autocomplete { position: relative; display: block; }
.autocomplete-results { position: absolute; z-index: 8; top: calc(100% + 5px); left: 0; right: 0; max-height: 280px; overflow-y: auto; border: 1px solid var(--line); border-radius: 9px; background: #fff; box-shadow: var(--shadow); }
.autocomplete-results button { display: grid; width: 100%; padding: 10px 12px; border: 0; border-bottom: 1px solid #edf1f1; color: var(--ink); background: #fff; text-align: left; }
.autocomplete-results button:hover { background: var(--teal-soft); }
.autocomplete-results button strong { color: var(--teal-dark); }
.autocomplete-results button span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.autocomplete-empty { display: block; padding: 12px; color: var(--muted); font-weight: 400; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 23px; }

.patient-hero { display: flex; gap: 20px; align-items: center; }
.patient-avatar { display: grid; place-items: center; width: 66px; height: 66px; flex: 0 0 auto; border-radius: 17px; color: var(--teal); background: var(--teal-soft); font-family: Georgia, serif; font-size: 25px; font-weight: bold; }
.patient-hero h3 { margin: 0 0 5px; font-family: Georgia, serif; font-size: 26px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 22px; margin-top: 22px; }
.detail-grid dt { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.detail-grid dd { margin: 4px 0 10px; font-size: 14px; }
.note { padding: 15px; border-left: 3px solid var(--coral); background: #fff7f4; }
.patient-summary-card { display: flex; align-items: center; gap: 16px; min-width: 0; padding: 11px 14px; }
.patient-summary-main { display: flex; flex: 1; align-items: center; gap: 14px; min-width: 0; white-space: nowrap; }
.patient-avatar.compact { width: 38px; height: 38px; border-radius: 10px; font-size: 15px; }
.patient-summary-name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.patient-summary-name strong { overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.patient-summary-item, .patient-summary-note { min-width: 0; overflow: hidden; color: #38515a; font-size: 12px; text-overflow: ellipsis; }
.patient-summary-item small, .patient-summary-note small { display: block; margin-bottom: 2px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.patient-summary-location { max-width: 130px; }
.patient-summary-note { max-width: 170px; padding-left: 12px; border-left: 2px solid var(--coral); }
.patient-summary-actions { display: flex; flex: 0 0 auto; gap: 7px; }
.patient-workspace-nav { display: flex; gap: 8px; margin: 14px 0 12px; padding: 6px; border: 1px solid #dfe9e8; border-radius: 13px; background: #fff; }
.patient-workspace-tab { display: inline-flex; align-items: center; gap: 7px; padding: 10px 14px; border: 0; border-radius: 10px; color: #38515a; background: transparent; font-weight: 900; }
.patient-workspace-tab:hover { background: #eef7f5; }
.patient-workspace-tab.active { color: #fff; background: var(--teal); box-shadow: 0 7px 18px rgba(12,117,109,.16); }
.patient-workspace-tab span { min-width: 22px; padding: 2px 7px; border-radius: 99px; color: var(--teal-dark); background: var(--teal-soft); font-size: 11px; }
.patient-workspace-tab.active span { color: var(--teal-dark); background: #fff; }
.patient-workspace-panel { display: none; }
.patient-workspace-panel.active { display: block; }
.patient-details-card { display: grid; gap: 14px; }
.patient-detail-grid { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); gap: 12px 18px; margin: 0; }
.patient-detail-grid dt { color: var(--muted); font-size: 10px; font-weight: 900; letter-spacing: .04em; text-transform: uppercase; }
.patient-detail-grid dd { margin: 4px 0 0; color: var(--ink); font-size: 13px; }
.patient-detail-note { padding: 13px 15px; border-left: 3px solid var(--coral); border-radius: 9px; background: #fff7f4; }
.patient-detail-note h4 { margin: 0 0 5px; color: #8f3525; }
.patient-detail-note p { margin: 0; white-space: pre-wrap; }
.patient-workplace-details { padding: 14px 16px; border: 1px solid #dce9e6; border-radius: 11px; background: #fbfdfc; }
.patient-workplace-details h4 { margin: 0 0 10px; color: var(--teal-dark); }
.form-section-title { margin: 8px 0 0; padding-top: 10px; border-top: 1px solid var(--line); color: var(--teal-dark); font-size: 16px; }
.patient-visits-head { margin-top: 16px; }
.visit { margin-bottom: 8px; padding: 11px 13px; border: 1px solid var(--line); border-left-width: 5px; border-radius: 10px; background: #fff; }
.visit.current-visit { box-shadow: 0 0 0 2px rgba(12,117,109,.24); }
.visit-ambulatory { border-left-color: #0c756d; background: linear-gradient(90deg, #f1faf8, #fff 34%); }
.visit-remote { border-left-color: #4f6fd8; background: linear-gradient(90deg, #eef3ff, #fff 42%); }
.visit-dispensary { border-left-color: #8e4b9d; background: linear-gradient(90deg, #f8eafa, #fff 48%); }
.visit-prevention { border-left-color: #d39b2d; background: linear-gradient(90deg, #fff1c9, #fff 52%); }
.visit-nhif { box-shadow: inset 0 0 0 1px rgba(12,117,109,.18); }
.visit-paid { border-color: #e9c2b8; box-shadow: inset 0 0 0 1px rgba(178,72,48,.18); }
.visit-other-region { border-style: dashed; border-color: #9c7bc0; box-shadow: inset 0 0 0 1px rgba(156,123,192,.18); }
.visit-default { border-left-color: #b9c8ca; }
#visits-section { scroll-margin-top: 20px; }
.visit-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.visit-head-badges { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 5px; max-width: 44%; }
.visit-kind { display: inline-flex; align-items: center; min-height: 22px; padding: 4px 8px; border-radius: 999px; font-size: 10px; font-weight: 900; letter-spacing: .03em; text-transform: uppercase; white-space: nowrap; }
.visit-kind.prevention { color: #6c4a00; background: #ffe5a6; }
.visit-kind.dispensary { color: #5c2768; background: #f0d2f4; }
.visit-kind.remote { color: #28478c; background: #dbe6ff; }
.visit-kind.nhif { color: #07514c; background: #d8f0ec; }
.visit-kind.paid { color: #8f3525; background: #ffe0d7; }
.visit-kind.other-region { color: #50306f; background: #eadff7; }
.visit h4 { margin: 0 0 3px; font-size: 15px; }
.visit p { display: inline-block; margin: 6px 18px 0 0; color: #496169; font-size: 12px; }
.visit .visit-details { display: block; margin: 12px 0 4px; padding: 13px 14px; border: 1px solid #cfe4e0; border-radius: 10px; background: rgba(255,255,255,.78); box-shadow: inset 0 0 0 1px rgba(255,255,255,.7); }
.visit .visit-details .detail-grid { grid-template-columns: repeat(4, minmax(130px, 1fr)); gap: 8px 14px; margin-top: 0; }
.visit .visit-details .detail-grid dt { font-size: 9px; font-weight: 900; letter-spacing: .04em; }
.visit .visit-details .detail-grid dd { margin: 2px 0 6px; font-size: 12px; }
.visit-detail-section { margin-top: 10px; padding-top: 10px; border-top: 1px solid #e1eded; }
.visit-detail-section h4 { margin: 0 0 5px; color: var(--teal-dark); font-size: 13px; }
.visit-detail-section p, .visit .visit-detail-section p { display: block; margin: 0; color: #38515a; font-size: 12px; line-height: 1.45; white-space: pre-wrap; }
.visit-document-list { display: grid; gap: 7px; }
.visit-document-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 9px; border: 1px solid #d8e7e5; border-radius: 8px; background: #fff; }
.visit-document-row strong, .visit-document-row span { display: block; }
.visit-document-row strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.visit-document-row span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.visit-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-top: 9px; padding-top: 8px; border-top: 1px solid #edf1f1; }
.nhis-import-results { display: grid; gap: 12px; }
.import-result-summary { display: flex; flex-wrap: wrap; gap: 8px 18px; padding: 12px 14px; border-radius: 9px; background: var(--teal-soft); font-size: 13px; }
.error-text { color: #a53b2c; }
.compact-action { padding: 7px 10px; font-size: 12px; white-space: nowrap; }
button:disabled { cursor: not-allowed; opacity: .45; }
.detail-section { margin-top: 16px; padding: 14px 16px; border-radius: 9px; background: var(--paper); }
.detail-section h4 { margin: 0 0 7px; }
.detail-section p { margin: 0; white-space: pre-wrap; }
.technical-log { display: grid; gap: 14px; }
.technical-section { min-width: 0; padding: 13px; border: 1px solid var(--line); border-radius: 9px; background: var(--paper); }
.technical-section h4 { margin: 0 0 8px; color: var(--teal-dark); }
.technical-section pre { max-height: 360px; margin: 0; overflow: auto; white-space: pre-wrap; word-break: break-word; font: 12px/1.45 Consolas, monospace; }
.compact-head { margin-top: 0; }
.document-register { display: grid; gap: 12px; }
.document-card { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 15px; border: 1px solid var(--line); border-radius: 10px; }
.document-statuses { display: flex; align-items: flex-start; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.document-result { margin-top: 6px; color: #38515a; font-size: 12px; }
.prescription-booklet-summary { display: grid; gap: 5px; margin-bottom: 14px; }
.booklet-diagnoses { display: grid; gap: 9px; margin: 18px 0; }
.booklet-diagnosis { display: grid; grid-template-columns: minmax(160px, 1fr) minmax(170px, 2fr) auto; gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-left: 4px solid var(--teal); border-radius: 10px; background: #fff; }
.booklet-diagnosis.active { background: #f1fbf8; border-color: #bfe3d8; }
.booklet-diagnosis.inactive { border-left-color: #a8b3b6; background: #f4f5f5; color: #66767b; }
.booklet-diagnosis div { display: grid; gap: 3px; }
.booklet-diagnosis span { color: #61757d; font-size: 12px; }
.booklet-diagnosis-main strong { font-size: 16px; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-title-row h3 { margin: 0; }
.inactive-list { padding-top: 15px; border-top: 1px solid var(--line); }
.danger-outline { border: 1px solid #d8a59b; color: #9d3828; background: #fff7f5; }
.diagnosis-chips { display: flex; flex-wrap: wrap; gap: 7px; margin: 8px 0; }
.diagnosis-chip { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; padding: 6px 8px; border: 1px solid #cfdedd; border-radius: 8px; background: #f7faf9; font-size: 12px; }
.diagnosis-chip.primary-diagnosis { border-color: #79bdb3; background: var(--teal-soft); }
.diagnosis-chip button { padding: 0 3px; border: 0; color: #8a3c32; background: transparent; font-size: 17px; line-height: 1; }
.field-help { display: block; margin-top: 6px; color: var(--muted); font-size: 11px; font-weight: normal; }
.diagnosis-summary { display: inline-block; max-width: 360px; overflow: hidden; vertical-align: bottom; text-overflow: ellipsis; white-space: nowrap; }
.visit-diagnosis { display: flex; min-width: 0; gap: 5px; margin: 6px 0; }
.visit-diagnosis .diagnosis-summary { max-width: min(760px, 75vw); }
.booklet-medications { display: grid; gap: 10px; margin: 22px 0; padding-top: 16px; border-top: 1px solid var(--line); }
.booklet-medication { display: grid; gap: 11px; padding: 14px; border: 1px solid var(--line); border-left: 4px solid #c09b4b; border-radius: 11px; background: #fffdf7; }
.booklet-medication.fulfilled { border-left-color: var(--teal); background: #f3fbf9; }
.booklet-medication-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.booklet-medication-head > div { display: grid; gap: 3px; }
.booklet-medication-head span { color: var(--muted); font-size: 11px; }
.booklet-medication-grid { display: grid; grid-template-columns: repeat(3, minmax(110px, 1fr)); gap: 8px 14px; }
.booklet-medication-grid span { display: grid; gap: 2px; font-size: 12px; }
.booklet-medication-grid small { color: var(--muted); font-size: 9px; text-transform: uppercase; }
.booklet-medication-refs { display: flex; flex-wrap: wrap; gap: 8px 18px; padding-top: 8px; border-top: 1px solid #dce9e6; color: #526970; font-size: 11px; }
@media (max-width: 760px) { .booklet-medication-grid { grid-template-columns: 1fr 1fr; } }
.document-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; padding-top: 10px; border-top: 1px solid #edf1f1; }
.settings-card { max-width: 800px; }
.settings-note { padding: 13px 15px; border-radius: 9px; color: #38515a; background: var(--teal-soft); font-size: 13px; line-height: 1.5; }
.settings-hero { display: flex; align-items: center; justify-content: space-between; gap: 25px; margin-bottom: 20px; padding: 22px 25px; border: 1px solid #d9e8e6; border-radius: 16px; background: linear-gradient(120deg, #fff, #eef7f5); }
.settings-hero h3 { margin: 0; font-family: Georgia, serif; font-size: 29px; }
.settings-hero p:not(.eyebrow) { margin: 7px 0 0; color: var(--muted); }
.settings-status { display: flex; flex: 0 0 auto; align-items: center; gap: 10px; min-width: 165px; padding: 12px 15px; border: 1px solid #cfe0de; border-radius: 11px; background: #fff; }
.settings-status small, .settings-status strong { display: block; }
.settings-status small { color: var(--muted); font-size: 10px; text-transform: uppercase; }
.settings-status strong { margin-top: 2px; font-size: 13px; }
.status-dot { width: 11px; height: 11px; border-radius: 50%; background: #d3a43d; box-shadow: 0 0 0 4px #f8edcf; }
.status-dot.production { background: #2d9360; box-shadow: 0 0 0 4px #dff1e7; }
.settings-stack { display: grid; gap: 16px; }
.settings-panel { padding: 0; overflow: hidden; }
.settings-panel-head { display: flex; align-items: center; gap: 14px; padding: 19px 22px; border-bottom: 1px solid var(--line); background: #fbfcfc; }
.settings-panel-head > div { min-width: 0; flex: 1; }
.settings-panel-head h4 { margin: 0; font-family: Georgia, serif; font-size: 19px; }
.settings-panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.settings-panel-number { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 auto; border-radius: 9px; color: #fff; background: var(--teal); font-size: 13px; font-weight: 900; }
.connection-chip { flex: 0 0 auto; padding: 6px 9px; border-radius: 7px; color: var(--teal-dark); background: var(--teal-soft); font: 11px Consolas, monospace; }
.settings-fields { padding: 20px 22px; }
.settings-fields label { align-content: start; }
.field-help { color: var(--muted); font-size: 11px; font-weight: 400; line-height: 1.35; }
.advanced-settings { border-top: 1px solid var(--line); }
.advanced-settings summary { cursor: pointer; padding: 13px 22px; color: #38515a; background: #f9fbfa; font-size: 12px; font-weight: 800; }
.advanced-settings[open] summary { border-bottom: 1px solid var(--line); color: var(--teal-dark); }
.settings-panel-actions { display: flex; justify-content: flex-end; padding: 15px 22px; border-top: 1px solid var(--line); background: #fbfcfc; }
.settings-savebar { position: sticky; bottom: 12px; z-index: 4; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 14px 16px; border: 1px solid #bfd8d4; border-radius: 12px; background: rgba(255,255,255,.96); box-shadow: 0 12px 35px rgba(20,54,61,.14); backdrop-filter: blur(10px); }
.settings-savebar strong, .settings-savebar span { display: block; }
.settings-savebar strong { font-size: 13px; }
.settings-savebar span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.settings-import-panel { margin-top: 16px; }
.import-workspace { display: grid; grid-template-columns: minmax(260px, .8fr) minmax(320px, 1.2fr); gap: 16px; padding: 20px 22px; }
.import-file-box { display: grid; align-content: start; gap: 14px; padding: 16px; border: 1px solid var(--line); border-radius: 11px; background: #fbfcfc; }
.import-file-box p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.import-warning { grid-column: 2; padding: 14px 16px; border: 1px solid #edc6bd; border-radius: 10px; color: #7f2e22; background: #fff4f1; }
.import-warning strong, .import-warning span { display: block; }
.import-warning strong { font-size: 13px; }
.import-warning span { margin-top: 5px; font-size: 11px; line-height: 1.5; }
.import-preview { grid-column: 2; min-height: 110px; padding: 16px; border: 1px dashed #a9c9c5; border-radius: 10px; background: #f7fbfa; font-size: 13px; }
.import-preview strong, .import-preview span { display: block; }
.import-preview span { margin-top: 4px; }
.import-preview ul { margin: 10px 0 0; padding-left: 20px; }
.import-errors { margin-top: 10px; color: #a84331; font-weight: 700; }
.import-actions { grid-column: 2; padding: 0; border: 0; background: none; gap: 8px; }
.import-history { display: grid; gap: 0; padding: 0 22px 20px; font-size: 13px; }
.import-history-title { display: flex; justify-content: space-between; padding: 13px 0 9px; border-top: 1px solid var(--line); }
.import-history-title span { color: var(--muted); font-size: 11px; }
.import-history-row { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid #edf1f1; }
.import-history-row div { min-width: 0; }
.import-history-row strong, .import-history-row small { display: block; }
.import-history-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.import-history small { color: var(--muted); }
.file-mark { display: grid; place-items: center; height: 28px; border-radius: 7px; color: var(--teal-dark); background: var(--teal-soft); font-size: 9px; font-weight: 900; }
.empty-import-history { padding: 16px 0; color: var(--muted); text-align: center; }
.imported-clinical-data { margin-top: 10px; padding: 12px 15px; }
.imported-clinical-data summary { cursor: pointer; color: var(--teal-dark); font-weight: 800; }
.imported-clinical-list { display: grid; gap: 8px; margin-top: 12px; }
.imported-clinical-list div { display: grid; gap: 3px; padding-top: 8px; border-top: 1px solid var(--line); font-size: 12px; }
.imported-clinical-list span { color: var(--muted); }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: 360px; padding: 13px 17px; border-radius: 9px; color: #fff; background: #173f42; box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #a84331; }

@media (max-width: 850px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; grid-template-areas: "topbar" "content"; }
  .sidebar { position: fixed; z-index: 10; width: 245px; height: 100vh; transform: translateX(-100%); transition: .2s; }
  .sidebar.open, .sidebar.pinned { transform: translateX(0); box-shadow: 10px 0 40px rgba(0,0,0,.2); }
  .documents-sidebar { position: fixed; z-index: 9; right: 0; width: 0; height: 100vh; transform: none; }
  .app-shell.has-current-visit .documents-sidebar { width: 48px; }
  .app-shell.has-current-visit .documents-sidebar:hover, .app-shell.has-current-visit .documents-sidebar:focus-within, .app-shell.has-current-visit .documents-sidebar.pinned { width: min(330px, calc(100vw - 28px)); }
  .documents-sidebar-mark { width: 36px; height: 36px; margin: 14px 6px; }
  .documents-sidebar-content { height: calc(100vh - 84px); }
  .content { padding: 16px 20px 40px; }
  #menu-toggle { display: block; }
  .stats { grid-template-columns: 1fr; }
  .topbar { align-items: stretch; flex-wrap: wrap; }
  .topbar-title { flex: 1 1 220px; }
  .current-patient-bar, .current-visit-bar, .current-document-bar, .current-user-bar { order: 3; width: 100%; max-width: none; margin-left: 0; }
  .patient-summary-card { align-items: flex-start; flex-direction: column; }
  .patient-summary-main { width: 100%; flex-wrap: wrap; white-space: normal; }
  .patient-summary-actions { align-self: flex-end; }
  .patient-workspace-nav { flex-direction: column; }
  .patient-detail-grid { grid-template-columns: 1fr; }
  .document-workspace-head { flex-direction: column; }
  .document-workspace-head .secondary { width: 100%; }
  .settings-hero { align-items: flex-start; flex-direction: column; }
  .settings-status { width: 100%; }
  .import-workspace { grid-template-columns: 1fr; }
  .import-warning, .import-preview, .import-actions { grid-column: 1; }
}

@media (max-width: 560px) {
  .login-card { padding: 30px 24px; }
  .topbar { align-items: flex-start; }
  .topbar .primary { font-size: 0; }
  .topbar .primary::after { content: "+"; font-size: 22px; }
  .form-grid, .detail-grid { grid-template-columns: 1fr; }
  .toolbar { width: 100%; flex-direction: column; }
  .search { min-width: 0; }
  .section-head { align-items: flex-start; flex-direction: column; }
  .settings-panel-head { align-items: flex-start; }
  .connection-chip { display: none; }
  .settings-savebar { align-items: stretch; flex-direction: column; }
  .settings-savebar button { width: 100%; }
  .import-history-row { grid-template-columns: 38px 1fr; }
  .import-history-row > small { grid-column: 2; }
}
