:root {
    --navy-950: #0b1f33;
    --navy-900: #102a43;
    --navy-800: #173f5f;
    --teal-700: #087e8b;
    --teal-600: #0797a5;
    --teal-100: #d9f3f3;
    --blue-50: #f2f8fb;
    --gray-950: #17212b;
    --gray-700: #485767;
    --gray-600: #647383;
    --gray-500: #82909d;
    --gray-300: #d4dce3;
    --gray-200: #e4e9ed;
    --gray-100: #f1f4f6;
    --gray-50: #f7f9fa;
    --white: #ffffff;
    --red-700: #b42318;
    --red-100: #fee4e2;
    --green-700: #087443;
    --green-100: #dff7e9;
    --shadow-sm: 0 1px 2px rgba(16, 42, 67, 0.06);
    --shadow-md: 0 8px 24px rgba(16, 42, 67, 0.1);
    --radius-sm: 5px;
    --radius-md: 9px;
    --radius-lg: 14px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; color: var(--gray-950); background: var(--gray-50); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 15px; line-height: 1.5; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--teal-700); text-decoration: none; }
a:hover { color: var(--navy-800); }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid rgba(7, 151, 165, 0.28); outline-offset: 2px; }

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--navy-950); font-size: 18px; font-weight: 750; letter-spacing: -0.02em; }
.brand:hover { color: var(--navy-950); }
.brand-mark { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 8px; color: var(--white); background: var(--teal-700); font-size: 16px; font-weight: 800; }
.eyebrow { display: block; margin-bottom: 7px; color: var(--teal-700); font-size: 11px; font-weight: 800; letter-spacing: 0.11em; text-transform: uppercase; }
.auth-layout { display: grid; min-height: 100vh; min-height: 100svh; padding: 32px 20px; place-items: center; background: var(--gray-50); }
.auth-panel { width: min(100%, 480px); min-width: 0; padding: 38px; border: 1px solid var(--gray-200); border-radius: var(--radius-lg); background: var(--white); box-shadow: var(--shadow-md); }
.auth-brand { margin-bottom: 42px; }
.auth-copy { margin-bottom: 30px; }
.auth-copy h1 { margin: 0 0 8px; color: var(--navy-950); font-size: clamp(29px, 3vw, 38px); line-height: 1.15; letter-spacing: -0.035em; }
.auth-copy p, .auth-switch { margin: 0; color: var(--gray-600); }
.auth-switch { margin-top: 24px; text-align: center; }
.auth-switch a { font-weight: 700; }

.form-stack { display: grid; gap: 18px; }
.field-grid { display: grid; gap: 16px; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { min-width: 0; }
.field label, .label-row { display: block; margin-bottom: 7px; color: var(--navy-900); font-size: 13px; font-weight: 700; }
.label-row { display: flex; justify-content: space-between; align-items: center; }
.label-row label { margin: 0; }
.field input, .field select, .field textarea, .search-input { width: 100%; min-width: 0; border: 1px solid var(--gray-300); border-radius: var(--radius-sm); color: var(--gray-950); background: var(--white); transition: border-color 120ms ease, box-shadow 120ms ease; }
.field input, .field select, .search-input { height: 44px; padding: 0 12px; }
.field textarea { min-height: 105px; padding: 10px 12px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .search-input:focus { border-color: var(--teal-600); box-shadow: 0 0 0 3px rgba(7, 151, 165, 0.1); outline: none; }
.field input[aria-invalid="true"], .field select[aria-invalid="true"], .field textarea[aria-invalid="true"] { border-color: var(--red-700); }
.field-error, .form-error { min-height: 18px; margin: 5px 0 0; color: var(--red-700); font-size: 12px; }
.form-error:empty { display: none; }
.text-button { padding: 0; border: 0; color: var(--teal-700); background: transparent; font-size: 12px; font-weight: 700; }

.button { display: inline-flex; min-height: 40px; padding: 0 15px; gap: 8px; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: var(--radius-sm); font-size: 13px; font-weight: 750; transition: background 120ms ease, border-color 120ms ease, color 120ms ease; }
.button.primary { color: var(--white); background: var(--teal-700); }
.button.primary:hover { color: var(--white); background: #066c76; }
.button.secondary { border-color: var(--gray-300); color: var(--navy-900); background: var(--white); }
.button.secondary:hover { border-color: var(--gray-500); color: var(--navy-950); background: var(--gray-50); }
.button.danger { color: var(--white); background: var(--red-700); }
.button.ghost-danger { border-color: var(--red-100); color: var(--red-700); background: var(--white); }
.button.full { width: 100%; min-height: 46px; }
.button:disabled { cursor: not-allowed; opacity: 0.58; }
.button-spinner { display: none; width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.4); border-top-color: var(--white); border-radius: 50%; animation: spin 650ms linear infinite; }
.button.is-loading .button-spinner { display: block; }
.icon-button { display: inline-grid; width: 38px; height: 38px; padding: 0; place-items: center; border: 1px solid var(--gray-300); border-radius: var(--radius-sm); color: var(--navy-900); background: var(--white); }

.app-layout { display: grid; min-height: 100vh; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; display: flex; min-width: 0; height: 100vh; padding: 24px 16px 18px; border-right: 1px solid #203e56; color: var(--white); background: var(--navy-950); flex-direction: column; z-index: 30; }
.sidebar .brand { padding: 0 8px; color: var(--white); }
.sidebar-head { display: flex; margin-bottom: 38px; align-items: center; justify-content: space-between; }
.sidebar-close { display: none; color: var(--white); border-color: #34536b; background: transparent; font-size: 24px; }
.nav { display: grid; gap: 5px; }
.nav a, .nav.logout { display: flex; width: 100%; min-width: 0; height: 42px; padding: 0 11px; gap: 11px; align-items: center; border: 0; border-radius: var(--radius-sm); color: #c7d6e1; background: transparent; font-size: 13px; font-weight: 650; text-align: left; }
.nav a:hover, .nav.logout:hover { color: var(--white); background: rgba(255,255,255,.07); }
.nav a[aria-current="page"] { color: var(--white); background: #173f5f; box-shadow: inset 3px 0 var(--teal-600); }
.nav-icon { width: 18px; color: #8fb5c7; text-align: center; }
.sidebar-foot { display: grid; margin-top: auto; gap: 12px; }
.account-summary { display: flex; min-width: 0; padding: 14px 9px; gap: 10px; align-items: center; border-top: 1px solid #29475e; }
.avatar { display: grid; width: 34px; height: 34px; flex: 0 0 auto; place-items: center; border-radius: 50%; color: var(--navy-950); background: #84e2e5; font-size: 13px; font-weight: 800; }
.account-text { min-width: 0; }
.account-text strong, .account-text small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-text strong { color: var(--white); font-size: 12px; }
.account-text small { color: #90a9bb; font-size: 10px; }
.app-main { min-width: 0; }
.topbar { display: flex; height: 68px; padding: 0 34px; gap: 16px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--gray-200); background: var(--white); }
.topbar > div { display: grid; }
.topbar-label { display: none; }
.topbar strong { color: var(--navy-950); font-size: 14px; }
.topbar-date { color: var(--gray-600); font-size: 12px; }
.menu-button { display: none; }
.content { width: min(100%, 1440px); margin: 0 auto; padding: 34px; }
.sidebar-backdrop { display: none; }

.page-heading { display: flex; margin-bottom: 28px; gap: 24px; align-items: flex-end; justify-content: space-between; }
.page-heading h1 { margin: 0 0 5px; color: var(--navy-950); font-size: 29px; line-height: 1.15; letter-spacing: -0.035em; }
.page-heading p, .section-heading p { margin: 0; color: var(--gray-600); font-size: 13px; }
.metric-grid { display: grid; margin-bottom: 32px; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--gray-200); border-radius: var(--radius-md); background: var(--white); box-shadow: var(--shadow-sm); }
.metric { min-width: 0; padding: 22px 24px; border-right: 1px solid var(--gray-200); }
.metric:last-child { border-right: 0; }
.metric > span { display: block; color: var(--gray-600); font-size: 12px; font-weight: 700; }
.metric strong { display: block; margin: 7px 0 3px; color: var(--navy-950); font-size: 30px; line-height: 1; letter-spacing: -0.04em; }
.metric small { color: var(--gray-500); font-size: 11px; }
.metric.accent { background: var(--blue-50); }
.section-block { border: 1px solid var(--gray-200); border-radius: var(--radius-md); background: var(--white); box-shadow: var(--shadow-sm); }
.section-heading { display: flex; min-height: 74px; padding: 17px 20px; gap: 20px; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--gray-200); }
.section-heading h2 { margin: 0 0 3px; color: var(--navy-950); font-size: 16px; }
.text-link { font-size: 12px; font-weight: 750; }
.table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; text-align: left; }
.data-table th { padding: 11px 20px; color: var(--gray-600); background: var(--gray-50); font-size: 10px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
.data-table td { min-width: 0; padding: 14px 20px; border-top: 1px solid var(--gray-200); color: var(--gray-700); font-size: 13px; vertical-align: middle; }
.data-table tbody tr:hover { background: #fbfcfd; }
.table-primary, .table-secondary { display: block; min-width: 0; }
.table-primary { overflow: hidden; color: var(--navy-900); font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.table-secondary { margin-top: 2px; color: var(--gray-500); font-size: 11px; }
.badge { display: inline-flex; min-height: 23px; padding: 2px 8px; align-items: center; border-radius: 999px; font-size: 10px; font-weight: 750; line-height: 1; white-space: nowrap; }
.badge.neutral { color: var(--navy-800); background: var(--blue-50); }
.badge.success { color: var(--green-700); background: var(--green-100); }
.state-panel { display: flex; min-height: 230px; padding: 36px; align-items: center; justify-content: center; flex-direction: column; text-align: center; }
.state-panel strong { color: var(--navy-900); font-size: 15px; }
.state-panel p { max-width: 420px; margin: 6px 0 16px; color: var(--gray-600); font-size: 13px; }
.loader { width: 28px; height: 28px; border: 3px solid var(--gray-200); border-top-color: var(--teal-700); border-radius: 50%; animation: spin 700ms linear infinite; }
.loading-state p { margin-top: 12px; }
.toast-region { position: fixed; right: 20px; bottom: 20px; display: grid; width: min(340px, calc(100vw - 40px)); gap: 8px; z-index: 100; }
.toast { padding: 12px 14px; border: 1px solid var(--gray-300); border-left: 4px solid var(--teal-700); border-radius: var(--radius-sm); color: var(--navy-900); background: var(--white); box-shadow: var(--shadow-md); font-size: 13px; }
.toast.error { border-left-color: var(--red-700); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.page-heading.compact { margin-bottom: 20px; }
.back-link { display: inline-block; margin-bottom: 14px; color: var(--gray-600); font-size: 12px; font-weight: 700; }
.heading-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar { display: flex; min-height: 68px; padding: 12px 16px; gap: 10px; align-items: center; border-bottom: 1px solid var(--gray-200); }
.search-control { position: relative; display: flex; width: min(100%, 360px); align-items: center; }
.search-control > span { position: absolute; left: 12px; color: var(--gray-500); font-size: 19px; pointer-events: none; }
.search-control .search-input { padding-left: 36px; }
.filter-control select { height: 44px; min-width: 190px; padding: 0 34px 0 12px; border: 1px solid var(--gray-300); border-radius: var(--radius-sm); color: var(--gray-700); background: var(--white); }
.result-count { margin-left: auto; color: var(--gray-500); font-size: 11px; font-weight: 700; white-space: nowrap; }
.row-actions { display: flex; gap: 12px; align-items: center; justify-content: flex-end; white-space: nowrap; }
.row-actions a, .row-actions button, .text-danger { padding: 0; border: 0; color: var(--teal-700); background: transparent; font-size: 11px; font-weight: 750; }
.row-actions button, .text-danger { color: var(--red-700); }
.owner-note { color: var(--gray-500); font-size: 11px; }
.form-section { max-width: 820px; border: 1px solid var(--gray-200); border-radius: var(--radius-md); background: var(--white); box-shadow: var(--shadow-sm); }
.form-section-heading { padding: 20px 24px; border-bottom: 1px solid var(--gray-200); }
.form-section-heading h2 { margin: 0 0 3px; color: var(--navy-950); font-size: 16px; }
.form-section-heading p { margin: 0; color: var(--gray-600); font-size: 12px; }
.record-form { display: grid; padding: 24px; gap: 18px; }
.form-actions { display: flex; padding-top: 7px; gap: 9px; align-items: center; justify-content: flex-end; border-top: 1px solid var(--gray-100); }
.page-state { min-height: 60vh; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(340px, .9fr); gap: 20px; align-items: start; }
.detail-list { display: grid; margin: 0; padding: 8px 20px 20px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.detail-list > div { min-width: 0; padding: 17px 0; border-bottom: 1px solid var(--gray-100); }
.detail-list > div:nth-child(odd):not(.wide) { padding-right: 20px; }
.detail-list > div:nth-child(even):not(.wide) { padding-left: 20px; border-left: 1px solid var(--gray-100); }
.detail-list .wide { grid-column: 1 / -1; }
.detail-list dt { margin-bottom: 5px; color: var(--gray-500); font-size: 10px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; color: var(--navy-900); font-size: 13px; font-weight: 650; }
.preserve-lines { white-space: pre-wrap; }
.assigned-list { display: grid; }
.assigned-item { display: grid; min-width: 0; padding: 16px 20px; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 11px; align-items: center; border-bottom: 1px solid var(--gray-100); }
.assigned-item:last-child { border-bottom: 0; }
.doctor-avatar { display: grid; width: 36px; height: 36px; place-items: center; border-radius: 50%; color: var(--navy-800); background: var(--teal-100); font-size: 13px; font-weight: 800; }
.assigned-item div { min-width: 0; }
.assigned-item strong, .assigned-item span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assigned-item strong { color: var(--navy-900); font-size: 13px; }
.assigned-item div span { color: var(--gray-500); font-size: 11px; }
.compact-empty { padding: 40px 20px; text-align: center; }
.compact-empty strong { color: var(--navy-900); font-size: 13px; }
.compact-empty p { margin: 5px 0 0; color: var(--gray-500); font-size: 11px; }
.assignment-form-section { margin-bottom: 24px; padding: 20px; border: 1px solid var(--gray-200); border-radius: var(--radius-md); background: var(--white); box-shadow: var(--shadow-sm); }
.assignment-form-section form { display: grid; grid-template-columns: minmax(220px, 1fr) minmax(280px, 1.3fr) auto; gap: 14px; align-items: start; }
.assignment-form-section .button { margin-top: 26px; height: 44px; }
.assignment-form-section .form-error { grid-column: 1 / -1; }
.assignments-section { margin-bottom: 30px; }
.confirm-dialog { width: min(440px, calc(100% - 30px)); padding: 0; border: 0; border-radius: var(--radius-md); color: var(--gray-950); background: var(--white); box-shadow: 0 24px 80px rgba(11, 31, 51, .25); }
.confirm-dialog::backdrop { background: rgba(11, 31, 51, .55); }
.confirm-dialog form { padding: 26px; }
.dialog-icon { display: grid; width: 38px; height: 38px; margin-bottom: 17px; place-items: center; border-radius: 50%; color: var(--red-700); background: var(--red-100); font-weight: 800; }
.confirm-dialog h2 { margin: 0 0 7px; color: var(--navy-950); font-size: 19px; }
.confirm-dialog p { margin: 0; color: var(--gray-600); font-size: 13px; }
.dialog-actions { display: flex; margin-top: 24px; gap: 8px; justify-content: flex-end; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 980px) {
    .app-layout { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: 0; transform: translateX(-100%); width: 230px; transition: transform 180ms ease; }
    .sidebar.is-open { transform: translateX(0); }
    .sidebar-close, .menu-button { display: inline-grid; }
    .sidebar-backdrop { position: fixed; inset: 0; display: block; visibility: hidden; background: rgba(11, 31, 51, .48); opacity: 0; transition: opacity 180ms ease, visibility 180ms ease; z-index: 20; }
    .sidebar-backdrop.is-open { visibility: visible; opacity: 1; }
    .nav-open { overflow: hidden; }
    .topbar { padding: 0 22px; justify-content: flex-start; }
    .topbar-date { margin-left: auto; }
    .content { padding: 28px 22px; }
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .metric:nth-child(2) { border-right: 0; }
    .metric:nth-child(-n+2) { border-bottom: 1px solid var(--gray-200); }
    .detail-grid { grid-template-columns: 1fr; }
    .assignment-form-section form { grid-template-columns: 1fr 1fr; }
    .assignment-form-section .button { grid-column: 1 / -1; width: fit-content; margin-top: 0; }
}

@media (max-width: 640px) {
    .auth-layout { padding: 18px 12px; }
    .auth-panel { width: 100%; padding: 28px 20px; border-radius: var(--radius-md); }
    .auth-brand { margin-bottom: 34px; }
    .field-grid.two { grid-template-columns: 1fr; }
    .topbar { height: 62px; padding: 0 14px; }
    .topbar-date { display: none; }
    .content { padding: 24px 14px; }
    .page-heading { align-items: stretch; flex-direction: column; }
    .page-heading .button { align-self: flex-start; }
    .detail-heading .heading-actions { align-self: stretch; }
    .detail-heading .heading-actions .button { flex: 1 1 auto; }
    .metric-grid { grid-template-columns: 1fr 1fr; }
    .metric { padding: 18px 16px; }
    .metric strong { font-size: 26px; }
    .section-heading { align-items: flex-start; flex-direction: column; }
    .responsive-table thead { display: none; }
    .responsive-table, .responsive-table tbody, .responsive-table tr, .responsive-table td { display: block; width: 100%; }
    .responsive-table tr { padding: 12px 14px; border-top: 1px solid var(--gray-200); }
    .responsive-table td { display: grid; min-height: 34px; padding: 6px 0; grid-template-columns: 120px minmax(0, 1fr); border: 0; gap: 12px; text-align: right; }
    .responsive-table td::before { content: attr(data-label); color: var(--gray-500); font-size: 10px; font-weight: 800; letter-spacing: .04em; text-align: left; text-transform: uppercase; }
    .responsive-table td > * { justify-self: end; }
    .table-primary, .table-secondary { text-align: right; }
    .toolbar { align-items: stretch; flex-direction: column; }
    .search-control, .filter-control select { width: 100%; max-width: none; }
    .result-count { margin-left: 0; }
    .row-actions { flex-wrap: wrap; }
    .record-form, .form-section-heading { padding-right: 16px; padding-left: 16px; }
    .detail-list { grid-template-columns: 1fr; }
    .detail-list > div, .detail-list > div:nth-child(odd):not(.wide), .detail-list > div:nth-child(even):not(.wide) { padding-right: 0; padding-left: 0; grid-column: 1; border-left: 0; }
    .assignment-form-section form { grid-template-columns: 1fr; }
    .assignment-form-section .button { grid-column: 1; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
