:root {
    --bg: #eef7ff;
    --bg-soft: #f7fbff;
    --panel: #ffffff;
    --panel-blue: #f1f8ff;
    --text: #102033;
    --muted: #61738a;
    --line: #d8e8f8;
    --line-strong: #b9d8f7;
    --primary: #1d7ff0;
    --primary-dark: #135fc0;
    --primary-soft: #dceeff;
    --cyan: #13a8d8;
    --green: #19a974;
    --violet: #7c3aed;
    --pink: #db2777;
    --orange: #f97316;
    --amber: #d97706;
    --red: #dc2626;
    --danger: #c73737;
    --warn: #b7791f;
    --accent: var(--primary);
    --accent-soft: var(--primary-soft);
    --accent-dark: var(--primary-dark);
    --shadow: 0 18px 45px rgba(43, 107, 174, 0.12);
    --shadow-soft: 0 10px 28px rgba(43, 107, 174, 0.08);
    --radius: 8px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at 12% 8%, rgba(29, 127, 240, 0.16), transparent 28rem),
        radial-gradient(circle at 92% 12%, rgba(19, 168, 216, 0.14), transparent 30rem),
        linear-gradient(180deg, var(--bg) 0%, #f8fbff 46%, #edf6ff 100%);
    color: var(--text);
    font: 14px/1.5 "Segoe UI Variable", "Aptos", "Segoe UI", system-ui, sans-serif;
    font-variant-numeric: tabular-nums;
    overflow-x: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(29, 127, 240, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(29, 127, 240, 0.035) 1px, transparent 1px);
    background-size: 28px 28px;
    mask-image: linear-gradient(180deg, rgba(0,0,0,0.65), transparent 70%);
}

.route-dashboard { --accent: #1d7ff0; --accent-soft: #dceeff; --accent-dark: #135fc0; }
.route-queue { --accent: #0ea5e9; --accent-soft: #e0f2fe; --accent-dark: #0369a1; }
.route-visits { --accent: #19a974; --accent-soft: #dcfce7; --accent-dark: #047857; }
.route-patients { --accent: #7c3aed; --accent-soft: #ede9fe; --accent-dark: #5b21b6; }
.route-appointments { --accent: #f97316; --accent-soft: #ffedd5; --accent-dark: #c2410c; }
.route-reminders { --accent: #0d9488; --accent-soft: #ccfbf1; --accent-dark: #0f766e; }
.route-guides { --accent: #2563eb; --accent-soft: #dbeafe; --accent-dark: #1d4ed8; }
.route-prescriptions, .route-medicines { --accent: #db2777; --accent-soft: #fce7f3; --accent-dark: #be185d; }
.route-lab { --accent: #0891b2; --accent-soft: #cffafe; --accent-dark: #0e7490; }
.route-billing { --accent: #d97706; --accent-soft: #fef3c7; --accent-dark: #a16207; }
.route-reports { --accent: #2563eb; --accent-soft: #dbeafe; --accent-dark: #1d4ed8; }
.route-settings { --accent: #64748b; --accent-soft: #f1f5f9; --accent-dark: #334155; }

a { color: var(--primary-dark); text-decoration: none; }
a:hover { color: var(--primary); }
i[data-lucide] {
    display: inline-grid;
    place-items: center;
    width: 1.15em;
    height: 1.15em;
    font-style: normal;
    font-size: 0.86em;
    font-weight: 800;
    line-height: 1;
}
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { border-bottom: 1px solid var(--line); border-right: 1px solid rgba(216, 232, 248, 0.72); padding: 11px 12px; text-align: left; vertical-align: middle; }
th:first-child, td:first-child { border-left: 1px solid rgba(216, 232, 248, 0.72); }
thead th {
    background: linear-gradient(180deg, #f8fbff 0%, #edf6ff 100%);
    color: #48627d;
    font-size: 12px;
    font-weight: 700;
    text-transform: none;
}
tbody tr { transition: background 180ms ease; }
tbody tr:nth-child(even) { background: rgba(248, 251, 255, 0.56); }
tbody tr:hover { background: linear-gradient(90deg, var(--accent-soft), #fff); }
tbody td:first-child { font-weight: 800; color: var(--accent-dark); }
tbody td:nth-child(2) { color: #173b62; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    padding: 9px 11px;
    background: #fff;
    color: var(--text);
    outline: none;
    transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(29, 127, 240, 0.14);
}
textarea { min-height: 74px; resize: vertical; }
label span { display: block; margin-bottom: 5px; color: #415b76; font-weight: 650; }
label:not(.check) {
    padding: 8px;
    border: 1px solid rgba(185, 216, 247, 0.62);
    border-radius: 8px;
    background: linear-gradient(180deg, #ffffff, #f8fbff);
}

.skip-link {
    position: fixed;
    left: 14px;
    top: -48px;
    z-index: 10;
    padding: 9px 12px;
    background: var(--primary-dark);
    color: #fff;
    border-radius: 6px;
    transition: top 160ms ease;
}
.skip-link:focus { top: 12px; }

.shell { display: flex; min-height: 100vh; position: relative; }
.sidebar {
    width: 248px;
    background: linear-gradient(180deg, #eaf5ff 0%, #f8fbff 100%);
    border-right: 1px solid var(--line);
    color: var(--text);
    padding: 18px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    box-shadow: 10px 0 30px rgba(29, 127, 240, 0.05);
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 800;
    color: #0b356b;
    margin: 3px 7px 18px;
}
.brand-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--primary), var(--cyan));
    color: #fff;
    box-shadow: 0 12px 24px rgba(29, 127, 240, 0.22);
}
.brand-mark svg { width: 19px; height: 19px; }
.sidebar nav { display: grid; gap: 5px; }
.sidebar a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #38526f;
    padding: 10px 12px;
    border-radius: 7px;
    font-weight: 650;
    transition: background 180ms ease, color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}
.sidebar a:hover {
    background: rgba(29, 127, 240, 0.10);
    color: var(--accent-dark);
    transform: translateX(2px);
}
.sidebar a.active {
    background: #fff;
    color: var(--accent-dark);
    box-shadow: inset 3px 0 0 var(--accent), var(--shadow-soft);
}
.sidebar a svg {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    color: currentColor;
}
.sidebar a[data-icon="layout-dashboard"] { color: #135fc0; }
.sidebar a[data-icon="list-ordered"] { color: #0369a1; }
.sidebar a[data-icon="stethoscope"] { color: #047857; }
.sidebar a[data-icon="users"] { color: #5b21b6; }
.sidebar a[data-icon="calendar-days"] { color: #c2410c; }
.sidebar a[data-icon="bell-ring"] { color: #0f766e; }
.sidebar a[data-icon="book-open-check"] { color: #1d4ed8; }
.sidebar a[data-icon="pill"], .sidebar a[data-icon="package-plus"] { color: #be185d; }
.sidebar a[data-icon="flask-conical"] { color: #0e7490; }
.sidebar a[data-icon="receipt"] { color: #a16207; }
.sidebar a[data-icon="chart-column"] { color: #1d4ed8; }
.sidebar a[data-icon="settings"] { color: #334155; }
.public-link {
    margin-top: 18px;
    border: 1px solid var(--line-strong);
    background: rgba(255, 255, 255, 0.64);
}

.main {
    flex: 1;
    min-width: 0;
    padding: 22px clamp(18px, 3vw, 34px) 34px;
}
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 0 auto 18px;
    max-width: 1440px;
}
.topbar h1 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: clamp(24px, 2.2vw, 34px);
    line-height: 1.1;
    margin: 0 0 4px;
    color: #0f2d4f;
    text-wrap: balance;
}
.title-icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent-dark);
}
.title-icon svg { width: 22px; height: 22px; }
.topbar span { color: var(--muted); }
.topbar form {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px;
    box-shadow: var(--shadow-soft);
}

.panel {
    background: linear-gradient(180deg, rgba(255,255,255,0.96) 0%, rgba(248,251,255,0.92) 100%);
    border: 1px solid var(--line-strong);
    border-top: 4px solid var(--accent);
    border-radius: var(--radius);
    padding: 17px;
    overflow: auto;
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(10px);
}
.panel h2, .waiting-list h2, .setup-card h1, .dialog-head h2 {
    display: flex;
    align-items: center;
    gap: 8px;
}
.panel h2 { margin: 0 0 12px; font-size: 18px; color: #12395f; line-height: 1.2; }
.panel h2::after {
    content: "";
    flex: 1;
    height: 1px;
    min-width: 32px;
    background: linear-gradient(90deg, var(--accent), transparent);
    opacity: 0.38;
}
.panel h2 svg, .waiting-list h2 svg, .setup-card h1 svg, .dialog-head h2 svg {
    width: 19px;
    height: 19px;
    color: var(--accent-dark);
}
.panel h3 { color: #12395f; }
.grid { display: grid; gap: 16px; max-width: 1440px; margin-inline: auto; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.catalog-grid {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    align-items: start;
}
.catalog-grid > .panel:first-child {
    position: sticky;
    top: 18px;
}
.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin: 0 auto 16px;
    max-width: 1440px;
}
.stats article {
    position: relative;
    overflow: hidden;
    background: linear-gradient(145deg, #fff 0%, #f3f9ff 100%);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 17px;
    box-shadow: var(--shadow-soft);
}
.stats article:nth-child(1) { border-top: 3px solid #7c3aed; }
.stats article:nth-child(2) { border-top: 3px solid #19a974; }
.stats article:nth-child(3) { border-top: 3px solid #0ea5e9; }
.stats article:nth-child(4) { border-top: 3px solid #d97706; }
.stats article::after {
    content: "";
    position: absolute;
    right: -18px;
    top: -22px;
    width: 78px;
    height: 78px;
    border-radius: 50%;
    background: rgba(29, 127, 240, 0.12);
}
.stats span { color: var(--muted); display: block; font-weight: 650; }
.stats strong {
    font-size: clamp(24px, 2.4vw, 32px);
    display: block;
    margin-top: 6px;
    color: #0d376e;
    line-height: 1;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 auto 14px;
    max-width: 1440px;
}
.toolbar form, .row, .actions { display: flex; gap: 8px; align-items: center; }
.btn {
    border: 1px solid var(--line-strong);
    background: #fff;
    color: #173b62;
    border-radius: 7px;
    padding: 9px 13px;
    cursor: pointer;
    white-space: nowrap;
    display: inline-block;
    font-weight: 700;
    align-items: center;
    gap: 7px;
    transition: transform 160ms ease, box-shadow 180ms ease, background 180ms ease, border-color 180ms ease;
}
.btn.has-icon { display: inline-flex; justify-content: center; }
.btn svg { width: 16px; height: 16px; flex: 0 0 auto; }
.btn:hover {
    transform: translateY(-1px);
    border-color: #9dc8f2;
    box-shadow: 0 10px 18px rgba(29, 127, 240, 0.12);
}
.btn:active { transform: translateY(0) scale(0.99); }
.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 4px rgba(29, 127, 240, 0.18);
}
.btn.primary {
    background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 72%, white));
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 12px 24px rgba(29, 127, 240, 0.24);
}
.btn.ghost { background: var(--accent-soft); color: var(--accent-dark); }
.btn.danger {
    border-color: #fecaca;
    background: linear-gradient(135deg, #fff5f5, #fee2e2);
    color: #b91c1c;
}
.btn.danger:hover {
    border-color: #fca5a5;
    box-shadow: 0 10px 18px rgba(220, 38, 38, 0.14);
}
.btn.success {
    border-color: #86efac;
    background: linear-gradient(135deg, #ecfdf5, #bbf7d0);
    color: #166534;
}
.btn.success:hover {
    border-color: #4ade80;
    box-shadow: 0 10px 18px rgba(22, 101, 52, 0.14);
}
.btn.full { width: 100%; text-align: center; }
.action-cell {
    min-width: 156px;
    white-space: nowrap;
}
.action-cell > .btn,
.action-cell > form,
.action-cell > .muted {
    display: inline-flex;
    vertical-align: middle;
    margin: 2px 5px 2px 0;
}
.action-cell > form { margin-right: 0; }
button[data-dialog-open] {
    border-color: color-mix(in srgb, var(--accent) 32%, var(--line-strong));
    background: linear-gradient(135deg, #ffffff, var(--accent-soft));
    color: var(--accent-dark);
}
body:not(.print) .route-medicines .panel table,
body:not(.print) .route-lab .panel table,
body:not(.print) .route-settings .panel table {
    min-width: 820px;
}
.badge {
    display: inline-block;
    border-radius: 6px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 750;
}
.badge.status-waiting { background: #e0f2fe; color: #0369a1; }
.badge.status-progress { background: #dcfce7; color: #047857; }
.badge.status-done { background: #ecfdf5; color: #166534; }
.badge.status-cancel { background: #fee2e2; color: #b91c1c; }
.badge.status-priority { background: linear-gradient(135deg, #fff7ed, #fed7aa); color: #9a3412; border: 1px solid #fdba74; }
.muted { color: var(--muted); font-weight: 650; }
.code-pill,
.role-chip,
.money-highlight {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    border-radius: 7px;
    font-weight: 800;
}
.code-pill {
    padding: 4px 8px;
    color: var(--accent-dark);
    background: linear-gradient(135deg, var(--accent-soft), #fff);
    border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--line));
}
.role-chip {
    padding: 4px 9px;
    color: #334155;
    background: linear-gradient(135deg, #f8fafc, #e2e8f0);
    border: 1px solid #cbd5e1;
}
.money-highlight {
    color: #8a4b05;
    background: linear-gradient(135deg, #fff7ed, #fef3c7);
    border: 1px solid #fcd34d;
    padding: 3px 8px;
}
.link-action {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 800;
    color: var(--accent-dark);
    padding: 5px 9px;
    border-radius: 7px;
    border: 1px solid var(--line);
    background: #fff;
}
.link-action:hover {
    background: var(--accent-soft);
    color: var(--accent-dark);
}
.queue-row td:first-child,
.reminder-row td:first-child {
    border-left-width: 4px;
}
.queue-row.status-waiting td:first-child { border-left-color: #0ea5e9; }
.queue-row.status-in_progress td:first-child { border-left-color: #19a974; }
.queue-row.status-completed td:first-child { border-left-color: #16a34a; }
.queue-row.status-cancelled td:first-child,
.reminder-row.status-failed td:first-child { border-left-color: #dc2626; }
.queue-row.is-priority {
    background: linear-gradient(90deg, rgba(255, 247, 237, 0.88), rgba(255, 255, 255, 0.96));
}
.queue-row small,
.reminder-row small,
td small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-weight: 650;
}
.queue-actions {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
    min-width: 360px;
}
.queue-actions form { display: inline-flex; }
.compact-form {
    min-width: 440px;
    flex-wrap: wrap;
}
.compact-form select { max-width: 160px; }
.compact-form input { max-width: 190px; }
.notice-strip {
    max-width: 1440px;
    margin: 0 auto 14px;
    padding: 11px 13px;
    border: 1px solid var(--line-strong);
    border-left: 4px solid var(--accent);
    border-radius: 8px;
    background: linear-gradient(135deg, #ffffff, var(--accent-soft));
    color: #173b62;
    box-shadow: var(--shadow-soft);
}
.reminder-row.status-pending { background: rgba(236, 253, 245, 0.45); }
.reminder-row.status-failed { background: rgba(254, 242, 242, 0.72); }
.reminder-row.status-sent { background: rgba(248, 250, 252, 0.72); }
.guide-jump {
    max-width: 1440px;
    margin: 0 auto 14px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.guide-jump a {
    padding: 9px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: linear-gradient(180deg, #fff, #f4f9ff);
    color: #173b62;
    font-weight: 800;
    box-shadow: var(--shadow-soft);
}
.guide-hero,
.guide-section {
    max-width: 1440px;
    margin: 0 auto 16px;
}
.guide-hero {
    display: grid;
    grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
    gap: 16px;
    align-items: stretch;
}
.guide-hero > div:first-child,
.guide-section {
    border: 1px solid var(--line-strong);
    border-top: 4px solid var(--accent);
    border-radius: var(--radius);
    background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(248,251,255,0.92));
    box-shadow: var(--shadow-soft);
    padding: 18px;
}
.guide-hero h2,
.guide-section h2 {
    margin: 0 0 12px;
    color: #12395f;
}
.guide-hero p,
.guide-card li,
.guide-service dd {
    color: #395672;
}
.guide-flow {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}
.guide-flow article,
.guide-card,
.guide-service {
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow-soft);
}
.guide-flow article {
    position: relative;
    padding: 14px;
    overflow: hidden;
}
.guide-flow article:nth-child(2n) { background: linear-gradient(145deg, #fff, #eef7ff); }
.guide-flow article:nth-child(3n) { background: linear-gradient(145deg, #fff, #ecfdf5); }
.guide-flow span {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    margin-bottom: 8px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 900;
}
.guide-flow strong {
    display: block;
    color: #12395f;
    font-size: 16px;
}
.guide-flow p { margin: 6px 0 0; color: var(--muted); }
.guide-role-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}
.guide-card {
    padding: 15px;
}
.guide-card header,
.guide-service header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
.guide-card header i,
.guide-service header i {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent-dark);
    flex: 0 0 auto;
}
.guide-card h3,
.guide-service h3 {
    margin: 0;
    color: #12395f;
}
.guide-card ol {
    margin: 12px 0 0;
    padding-left: 20px;
}
.guide-card li {
    margin: 8px 0;
    padding-left: 3px;
}
.guide-service-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}
.guide-service {
    padding: 14px;
}
.guide-service dl {
    margin: 0;
    display: grid;
    gap: 8px;
}
.guide-service dt {
    width: fit-content;
    padding: 3px 7px;
    border-radius: 7px;
    border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--line));
    background: linear-gradient(135deg, var(--accent-soft), #fff);
    color: var(--accent-dark);
    font-weight: 900;
}
.guide-service dd {
    margin: -4px 0 4px;
    padding-bottom: 7px;
    border-bottom: 1px solid var(--line);
}
.guide-service dd:last-child { border-bottom: 0; }
.guide-checks {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.guide-checks label {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 11px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #fff;
    color: #173b62;
    font-weight: 750;
}
.guide-checks input { width: auto; margin-top: 3px; }
.edit-dialog {
    width: min(760px, calc(100vw - 28px));
    max-height: min(86vh, 820px);
    padding: 0;
    overflow: auto;
    border: 1px solid var(--line-strong);
    border-top: 4px solid var(--accent);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    box-shadow: 0 28px 80px rgba(15, 45, 79, 0.24);
}
.edit-dialog::backdrop {
    background: rgba(15, 45, 79, 0.34);
    backdrop-filter: blur(3px);
}
.dialog-head {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, #ffffff 0%, #f4f9ff 100%);
}
.dialog-head h2 {
    margin: 0;
    font-size: 20px;
    color: #12395f;
}
.edit-dialog form {
    padding: 18px;
}
.subnav {
    max-width: 1440px;
    margin: 0 auto 14px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.subnav a {
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid var(--line-strong);
    background: linear-gradient(180deg, #fff, #f4f9ff);
    color: #173b62;
    font-weight: 800;
    box-shadow: var(--shadow-soft);
}
.subnav a:hover {
    background: linear-gradient(135deg, var(--accent-soft), #fff);
    color: var(--accent-dark);
}
.flash {
    max-width: 1440px;
    margin: 0 auto 14px;
    padding: 11px 13px;
    border-radius: 7px;
    border: 1px solid #9de6c4;
    background: #eefcf6;
    color: #176a4a;
    box-shadow: var(--shadow-soft);
}
.flash.error { border-color: #ffc7c7; background: #fff4f4; color: var(--danger); }
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.form-grid .wide, fieldset.wide, .actions { grid-column: 1 / -1; }
.patient-editor {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow: visible;
}
.visit-editor {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow: visible;
}
.patient-lookup {
    position: relative;
    overflow: visible;
}
.patient-suggestions {
    position: absolute;
    z-index: 20;
    left: 8px;
    right: 8px;
    top: calc(100% - 6px);
    display: grid;
    gap: 4px;
    max-height: 260px;
    overflow: auto;
    padding: 7px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
}
.patient-suggestions[hidden] { display: none; }
.patient-suggestions button {
    width: 100%;
    border: 0;
    border-radius: 7px;
    padding: 9px 10px;
    background: #fff;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}
.patient-suggestions button:hover {
    background: var(--accent-soft);
}
.patient-suggestions small {
    display: block;
    color: var(--muted);
    font-weight: 650;
}
.prescription-editor {
    overflow: visible;
}
.visit-toolbar {
    align-items: center;
}
.visit-toolbar form {
    display: flex;
    gap: 8px;
}
.visit-workspace {
    display: grid;
    grid-template-columns: minmax(300px, 0.8fr) minmax(360px, 1.35fr) minmax(300px, 0.85fr);
    gap: 16px;
    max-width: 1440px;
    margin-inline: auto;
    align-items: start;
}
.visit-summary,
.visit-quick-card {
    overflow: visible;
    min-width: 0;
}
.visit-status-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin: -2px 0 12px;
}
.visit-info {
    grid-template-columns: 110px 1fr;
    margin-bottom: 12px;
}
.visit-ajax-form {
    display: grid;
    gap: 10px;
}
.visit-ajax-form .item-row {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) 68px minmax(84px, 0.75fr) minmax(84px, 0.75fr) minmax(110px, 1fr);
    gap: 8px;
    align-items: center;
    width: 100%;
}
.visit-ajax-form .item-row input,
.visit-ajax-form .item-row select {
    min-width: 0;
}
.visit-form-actions {
    flex-wrap: wrap;
}
.visit-ajax-form.prescription-editor .item-row {
    grid-template-columns: minmax(150px, 1.4fr) 76px minmax(100px, 0.9fr) minmax(100px, 0.9fr);
}
.visit-ajax-form.prescription-editor .item-row input[name="instruction[]"] {
    grid-column: 1 / -1;
}
.visit-template-form {
    display: grid;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}
.visit-template-form label {
    padding: 7px;
}
.quick-check-list {
    display: grid;
    gap: 7px;
    max-height: 300px;
    overflow: auto;
    padding: 7px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #fff;
}
.quick-check-list label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #f8fbff;
}
.quick-check-list input {
    width: auto;
    margin-top: 3px;
}
.quick-check-list span {
    font-weight: 750;
}
.quick-check-list small {
    display: block;
    color: var(--muted);
    font-weight: 650;
}
.visit-result {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}
.mini-list {
    display: grid;
    gap: 8px;
}
.mini-list article {
    display: grid;
    gap: 3px;
    padding: 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: linear-gradient(180deg, #fff, #f8fbff);
}
.mini-list span,
.mini-list small {
    color: var(--muted);
    font-weight: 650;
}
.ajax-message {
    min-height: 20px;
    color: #176a4a;
    font-weight: 750;
}
.ajax-message.error {
    color: var(--danger);
}
.patient-editor label,
.visit-editor label,
.prescription-editor label {
    padding: 7px;
}
.patient-editor textarea,
.visit-editor textarea,
.prescription-editor textarea {
    min-height: 58px;
    line-height: 1.42;
}
.visit-editor textarea[name="doctor_note"],
.visit-editor textarea[name="treatment_plan"],
.prescription-editor textarea[name="note"] {
    min-height: 70px;
}
.compact-field {
    grid-column: auto;
}
.sticky-actions {
    position: sticky;
    top: 10px;
    z-index: 4;
    justify-content: flex-end;
    padding: 9px;
    border: 1px solid var(--line-strong);
    border-left: 4px solid var(--accent);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 12px 28px rgba(43, 107, 174, 0.16);
    backdrop-filter: blur(10px);
}
.prescription-editor .sticky-actions {
    margin-bottom: 12px;
}
fieldset {
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    padding: 13px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    background: linear-gradient(180deg, #f8fbff, #ffffff);
}
legend { font-weight: 800; color: #234b72; padding: 0 6px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
.item-row, .result-row { margin-bottom: 8px; }
.bill-summary,
.rx-summary {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    width: fit-content;
    margin: 12px 0;
    padding: 10px 12px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: linear-gradient(135deg, #fff, var(--accent-soft));
    color: #173b62;
}
.bill-summary span,
.rx-summary span {
    color: var(--accent-dark);
}
.ref-range {
    display: inline-block;
    margin: 0 8px 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
}
.item-row select { min-width: 230px; }
.visit-ajax-form .item-row select,
.visit-ajax-form .item-row input {
    min-width: 0;
}
.prescription-editor .item-row {
    display: grid;
    grid-template-columns: minmax(220px, 1.45fr) 76px repeat(3, minmax(130px, 1fr));
    gap: 8px;
    align-items: center;
}
.prescription-editor .item-row select,
.prescription-editor .item-row input {
    min-width: 0;
}
.info {
    display: grid;
    grid-template-columns: 150px 1fr;
    gap: 0;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}
.info dt,
.info dd {
    margin: 0;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
}
.info dt {
    color: #38526f;
    font-weight: 800;
    background: linear-gradient(180deg, #f4f9ff, #edf6ff);
}
.info dd {
    color: #122b46;
    font-weight: 650;
    background: #fff;
}
.info dt:nth-last-child(2),
.info dd:last-child { border-bottom: 0; }
.timeline { display: grid; gap: 10px; }
.timeline article {
    border-left: 4px solid var(--accent);
    padding: 10px 13px;
    background: linear-gradient(90deg, var(--accent-soft), #fff);
    border-radius: 0 8px 8px 0;
}
.timeline h3 { margin: 2px 0 4px; font-size: 16px; }
.pager { display: flex; gap: 6px; margin-top: 12px; }
.pager a {
    border: 1px solid var(--line);
    padding: 6px 10px;
    border-radius: 6px;
    background: #fff;
    font-weight: 700;
}
.pager a.active { background: var(--primary); color: #fff; }
.checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
.checks label {
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #f8fbff;
}

.login {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    width: 100%;
    padding: 24px;
}
.login-card {
    width: min(560px, 100%);
    display: grid;
    gap: 0;
}
.eyebrow {
    display: inline-flex;
    width: fit-content;
    margin-bottom: 12px;
    color: inherit;
    opacity: 0.82;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
}
.enterprise-login {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.login-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 22px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(180deg, #ffffff 0%, #f5faff 100%);
}
.brand.compact {
    margin: 0;
    font-size: 17px;
    flex: 0 0 auto;
}
.login-header-copy {
    display: grid;
    gap: 2px;
    text-align: right;
    color: #284a6e;
}
.login-header-copy strong { color: #102f55; }
.login-header-copy span { color: var(--muted); font-size: 13px; }
.login-box {
    background: transparent;
    border: 0;
    border-radius: 0;
    padding: clamp(24px, 4vw, 34px) clamp(24px, 4vw, 38px);
    display: grid;
    align-content: center;
    gap: 15px;
    box-shadow: none;
    backdrop-filter: none;
}
.login-box h2 {
    margin: 0;
    font-size: 28px;
    color: #102f55;
}
.form-hint {
    margin: 5px 0 0;
    color: var(--muted);
}
.login-box small { color: var(--muted); }
.login-box .eyebrow { color: var(--primary-dark); margin-bottom: 4px; }
.login-foot {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 22px;
    border-top: 1px solid var(--line);
    background: #f8fbff;
    color: var(--muted);
    font-size: 13px;
}
.setup-warning {
    display: grid;
    gap: 4px;
    padding: 11px 12px;
    border: 1px solid #ffd79a;
    border-radius: 8px;
    background: #fff8eb;
    color: #7a4b0b;
}
.setup-warning span { color: #7a4b0b; }

.setup-page {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 24px;
}
.setup-card {
    width: min(680px, 100%);
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: clamp(24px, 4vw, 40px);
    box-shadow: var(--shadow);
}
.setup-card h1 {
    margin: 0 0 10px;
    font-size: clamp(30px, 4vw, 46px);
    color: #12395f;
    line-height: 1.05;
}
.setup-card p {
    max-width: 64ch;
    color: var(--muted);
    font-size: 16px;
}
.setup-card ol {
    display: grid;
    gap: 10px;
    margin: 18px 0 22px;
    padding-left: 22px;
}
.setup-card li { padding-left: 4px; }

.waiting-room { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; min-height: 80vh; align-items: center; }
.now-calling {
    background: linear-gradient(145deg, #fff, #eef7ff);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 42px;
    text-align: center;
    box-shadow: var(--shadow);
}
.now-calling span { color: var(--muted); font-size: 26px; }
.now-calling strong { display: block; font-size: 130px; color: var(--primary-dark); line-height: 1; }
.now-calling p { font-size: 30px; }
.waiting-list {
    background: rgba(255,255,255,0.9);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 26px;
    box-shadow: var(--shadow-soft);
}

body.print { background: #fff; padding: 24px; color: #000; }
body.print::before { display: none; }
body.print header { border-bottom: 2px solid #000; margin-bottom: 20px; }
body.print table { margin: 18px 0; border-collapse: collapse; }
body.print th, body.print td { border: 1px solid #444; }
@media print {
    .no-print, .btn { display: none !important; }
    body.print { padding: 0; }
}

@media (max-width: 1040px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .guide-hero,
    .guide-role-grid,
    .guide-service-grid,
    .guide-checks { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .guide-hero > div:first-child { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
    .shell { display: block; }
    .sidebar { width: auto; height: auto; position: static; }
    .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .topbar, .toolbar { align-items: stretch; flex-direction: column; }
    .topbar form, .toolbar form, .row, .actions { flex-wrap: wrap; }
    .grid.two, .catalog-grid, .form-grid, fieldset, .waiting-room { grid-template-columns: 1fr; }
    .guide-flow { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .prescription-editor .item-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .visit-workspace { grid-template-columns: 1fr; }
    .visit-ajax-form .item-row,
    .visit-ajax-form.prescription-editor .item-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .visit-ajax-form.prescription-editor .item-row input[name="instruction[]"] { grid-column: 1 / -1; }
    .catalog-grid > .panel:first-child { position: static; }
    .main { padding: 14px; }
}

@media (max-width: 560px) {
    .stats, .checks, .guide-hero, .guide-flow, .guide-role-grid, .guide-service-grid, .guide-checks { grid-template-columns: 1fr; }
    .prescription-editor .item-row { grid-template-columns: 1fr; }
    .visit-ajax-form .item-row,
    .visit-ajax-form.prescription-editor .item-row { grid-template-columns: 1fr; }
    .visit-ajax-form.prescription-editor .item-row input[name="instruction[]"] { grid-column: auto; }
    .login { padding: 12px; }
    .login-header, .login-foot { align-items: flex-start; flex-direction: column; }
    .login-header-copy { text-align: left; }
    th, td { padding: 9px 8px; }
}
