:root {
  --navy-950: #082342;
  --navy-900: #0b2e57;
  --navy-800: #143f70;
  --navy-100: #e9f1f8;
  --blue-50: #f5f9fc;
  --coral-700: #a83930;
  --coral-600: #b9473c;
  --coral-100: #fbe9e6;
  --green-700: #0a6e52;
  --green-100: #e2f5ee;
  --amber-800: #704400;
  --amber-100: #fff1cc;
  --red-700: #9f2f22;
  --red-100: #fce8e5;
  --ink: #18293d;
  --muted: #606b76;
  --line: #d8e1ea;
  --white: #fff;
  --shadow: 0 18px 48px rgba(8, 35, 66, .10);
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--blue-50);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--blue-50); }
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { outline-offset: 3px; }
:focus-visible { outline: 3px solid #1f70b7; }
.skip-link { position: fixed; z-index: 100; top: 8px; left: 8px; transform: translateY(-150%); padding: 10px 14px; color: var(--white); background: var(--navy-950); border-radius: 8px; }
.skip-link:focus { transform: none; }
.hidden { display: none !important; }

.login-page { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(420px, .95fr); background: var(--white); }
.login-brand { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; min-height: 100vh; padding: clamp(36px, 6vw, 78px); color: var(--white); background: linear-gradient(150deg, var(--navy-950), var(--navy-800)); }
.login-brand::after { content: ""; position: absolute; width: 460px; height: 460px; right: -180px; bottom: -160px; border: 72px solid rgba(255,255,255,.08); border-radius: 50%; }
.brand-lockup { position: relative; z-index: 1; display: flex; align-items: center; gap: 14px; font-size: 22px; font-weight: 750; }
.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; flex: 0 0 auto; border-radius: 15px; color: var(--navy-950); background: var(--white); font-size: 24px; font-weight: 850; }
.login-message { position: relative; z-index: 1; max-width: 620px; }
.login-message p { max-width: 510px; color: #d7e7f5; font-size: clamp(18px, 2.3vw, 24px); line-height: 1.55; }
.login-panel { display: grid; place-items: center; padding: 32px; }
.login-card { width: min(440px, 100%); }
.login-card h1 { margin: 0 0 10px; color: var(--navy-950); font-size: clamp(30px, 5vw, 42px); letter-spacing: -.035em; }
.login-card > p { margin: 0 0 32px; color: var(--muted); line-height: 1.6; }

.field { display: grid; gap: 8px; margin-bottom: 20px; }
.field label, .field-label { color: var(--navy-950); font-weight: 700; }
.field-help { margin: -2px 0 0; color: var(--muted); font-size: 14px; }
.control { width: 100%; min-height: 48px; padding: 11px 14px; color: var(--ink); background: var(--white); border: 1px solid #b9c8d7; border-radius: 11px; }
.control:hover { border-color: #7f98b0; }
textarea.control { min-height: 132px; resize: vertical; line-height: 1.5; }
textarea.control-compact { min-height: 84px; }
.password-wrap { position: relative; }
.password-wrap .control { padding-right: 92px; }
.password-toggle { position: absolute; top: 4px; right: 4px; min-height: 40px; padding: 0 12px; border: 0; border-radius: 8px; color: var(--navy-800); background: transparent; font-weight: 700; cursor: pointer; }
.form-error { margin: 0 0 18px; padding: 12px 14px; color: var(--red-700); background: var(--red-100); border-radius: 10px; line-height: 1.45; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 16px; border: 1px solid transparent; border-radius: 10px; cursor: pointer; font-weight: 750; text-decoration: none; transition: transform .12s ease, background .12s ease; }
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { cursor: not-allowed; opacity: .58; }
.btn-primary { color: var(--white); background: var(--coral-700); }
.btn-primary:hover:not(:disabled) { background: #8f2f28; }
.btn-secondary { color: var(--navy-900); background: var(--white); border-color: #b9c8d7; }
.btn-ghost { color: var(--navy-800); background: transparent; }
.btn-danger { color: var(--red-700); background: var(--red-100); }
.btn-block { width: 100%; }
.btn-small { min-height: 38px; padding: 7px 12px; font-size: 14px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 24px 18px; color: var(--white); background: var(--navy-950); }
.sidebar .brand-lockup { margin-bottom: 40px; }
.nav-label { margin: 0 8px 8px; color: #9eb8d0; font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.nav-link { display: flex; align-items: center; min-height: 46px; padding: 10px 13px; color: #dce8f3; border-radius: 11px; text-decoration: none; font-weight: 700; }
.nav-link:hover, .nav-link[aria-current="page"] { color: var(--white); background: rgba(255,255,255,.11); }
.sidebar-user { margin-top: auto; padding: 15px 12px 0; border-top: 1px solid rgba(255,255,255,.16); }
.sidebar-user strong, .sidebar-user span { display: block; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user span { margin-top: 4px; color: #b9ccde; font-size: 13px; text-transform: capitalize; }
.sidebar-user .btn { width: 100%; margin-top: 12px; color: var(--white); border-color: rgba(255,255,255,.3); }

.workspace { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 76px; padding: 14px clamp(20px, 4vw, 52px); background: rgba(255,255,255,.9); border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); }
.mobile-brand { display: none; color: var(--navy-950); font-weight: 800; }
.page { width: min(1220px, 100%); margin: 0 auto; padding: 38px clamp(20px, 4vw, 52px) 70px; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 7px; color: var(--coral-700); font-size: 12px; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
h1, h2, h3 { color: var(--navy-950); }
.page-header h1 { margin: 0; font-size: clamp(28px, 4vw, 40px); letter-spacing: -.035em; }
.page-header p { margin: 8px 0 0; color: var(--muted); line-height: 1.55; }
.breadcrumb { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; color: var(--muted); font-size: 14px; }
.breadcrumb a { color: var(--navy-800); }

.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 14px; margin-bottom: 20px; padding: 18px; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); }
.toolbar .field { min-width: 230px; margin: 0; flex: 1 1 300px; }
.toolbar .compact-field { flex: 0 1 210px; min-width: 180px; }
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 5px 22px rgba(8,35,66,.045); }
.card-pad { padding: 24px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
caption { padding: 18px 20px 0; text-align: left; color: var(--muted); }
th, td { padding: 16px 18px; text-align: left; border-bottom: 1px solid #e7edf2; vertical-align: middle; }
th { color: var(--muted); background: #f8fafc; font-size: 12px; letter-spacing: .045em; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
.patient-name { color: var(--navy-950); font-weight: 800; }
.meta { color: var(--muted); font-size: 14px; }
.progress { display: flex; align-items: center; gap: 9px; }
.progress-native { width: 82px; height: 8px; overflow: hidden; border: 0; border-radius: 999px; background: #dde7ef; accent-color: var(--green-700); }
.progress-native::-webkit-progress-bar { background: #dde7ef; border-radius: 999px; }
.progress-native::-webkit-progress-value { background: var(--green-700); border-radius: 999px; }
.progress-native::-moz-progress-bar { background: var(--green-700); border-radius: 999px; }

.chip { display: inline-flex; align-items: center; min-height: 30px; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 800; }
.chip-draft { color: var(--muted); background: #edf1f4; }
.chip-active { color: var(--navy-900); background: var(--navy-100); }
.chip-success { color: var(--green-700); background: var(--green-100); }
.chip-warning { color: var(--amber-800); background: var(--amber-100); }
.chip-danger { color: var(--red-700); background: var(--red-100); }

.empty-state { padding: 58px 24px; text-align: center; }
.empty-icon { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 18px; color: var(--navy-800); background: var(--navy-100); border-radius: 20px; font-size: 28px; font-weight: 800; }
.empty-state h2 { margin: 0 0 8px; }
.empty-state p { max-width: 540px; margin: 0 auto 20px; color: var(--muted); line-height: 1.55; }
.loading { display: flex; align-items: center; justify-content: center; min-height: 280px; color: var(--muted); }

.search-step { max-width: 780px; }
.stepper { display: flex; gap: 8px; margin: 0 0 26px; padding: 0; list-style: none; }
.stepper li { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; font-weight: 700; }
.stepper li:not(:last-child)::after { content: ""; width: 34px; height: 1px; background: #bdc9d4; }
.stepper .current { color: var(--navy-950); }
.result-list { display: grid; gap: 12px; margin-top: 20px; }
.result-card { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--white); }
.result-card h3 { margin: 0 0 6px; }
.result-card p { margin: 3px 0; color: var(--muted); }
.notice { padding: 14px 16px; border-radius: 12px; line-height: 1.5; }
.notice-warning { color: var(--amber-800); background: var(--amber-100); }
.notice-danger { color: var(--red-700); background: var(--red-100); }
.notice-info { color: var(--navy-900); background: var(--navy-100); }

.patient-hero { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(260px, .6fr); gap: 18px; margin-bottom: 22px; }
.patient-identity { padding: 26px; color: var(--white); background: linear-gradient(145deg, var(--navy-950), var(--navy-800)); border-radius: var(--radius); }
.patient-identity h1 { margin: 8px 0 14px; color: var(--white); font-size: clamp(27px, 4vw, 38px); }
.patient-identity p { margin: 5px 0; color: #d4e3f0; }
.clinical-alerts { padding: 22px; }
.clinical-alerts h2 { margin: 0 0 12px; font-size: 18px; }
.clinical-alerts ul { margin: 0; padding-left: 20px; color: var(--muted); }
.clinical-alerts li + li { margin-top: 7px; }
.sections-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.section-card { display: grid; gap: 15px; padding: 22px; }
.section-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.section-card h2 { margin: 0 0 5px; font-size: 20px; }
.section-card p { margin: 0; color: var(--muted); }
.section-actions { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.section-actions .field { flex: 1 1 210px; margin: 0; }

.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 20px; align-items: start; }
.editor-card { padding: 26px; }
.editor-card > fieldset { margin: 0; padding: 0; border: 0; }
.editor-card > fieldset > legend { margin-bottom: 22px; color: var(--navy-950); font-size: 22px; font-weight: 800; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 18px; align-items: start; }
.field-wide { grid-column: 1 / -1; }
.form-section-title { grid-column: 1 / -1; margin: 16px 0 18px; padding-bottom: 10px; border-bottom: 1px solid var(--line); font-size: 18px; }
.form-section-title:first-child { margin-top: 0; }
.checkbox-field { margin: 0 0 20px; padding: 17px; border: 1px solid var(--line); border-radius: 12px; }
.checkbox-field > legend { padding: 0 6px; color: var(--navy-950); font-size: 15px; font-weight: 800; }
.checkbox-grid { display: grid; gap: 10px; margin-top: 4px; }
.checkbox-option { display: flex; align-items: flex-start; gap: 10px; color: var(--ink); line-height: 1.4; cursor: pointer; }
.checkbox-option input { width: 18px; height: 18px; margin: 1px 0 0; flex: 0 0 auto; accent-color: var(--navy-800); }
.editor-side { position: sticky; top: 96px; display: grid; gap: 14px; }
.save-status { min-height: 24px; color: var(--muted); font-size: 14px; }
.save-status.error { color: var(--red-700); font-weight: 700; }
.save-status.success { color: var(--green-700); font-weight: 700; }
.side-actions { display: grid; gap: 9px; }

.toast-region { position: fixed; z-index: 50; right: 20px; bottom: 20px; display: grid; gap: 10px; width: min(380px, calc(100vw - 40px)); }
.toast { padding: 14px 16px; color: var(--white); background: var(--navy-950); border-radius: 12px; box-shadow: var(--shadow); }

@media (max-width: 900px) {
  .login-page { grid-template-columns: 1fr; }
  .login-brand { min-height: 250px; padding: 34px; }
  .login-message p { font-size: 18px; }
  .login-panel { padding: 42px 24px; }
  .app-shell { display: block; }
  .sidebar { display: none; }
  .mobile-brand { display: flex; align-items: center; gap: 9px; }
  .topbar { position: sticky; z-index: 10; top: 0; }
  .patient-hero, .editor-layout { grid-template-columns: 1fr; }
  .editor-side { position: static; }
}

@media (max-width: 760px) {
  .topbar .meta { display: none; }
  .page { padding-top: 26px; }
  .page-header { display: grid; }
  .page-header .btn { width: 100%; }
  .sections-grid, .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .table-wrap table, .table-wrap thead, .table-wrap tbody, .table-wrap th, .table-wrap td, .table-wrap tr { display: block; }
  .table-wrap thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-wrap tbody { display: grid; gap: 12px; padding: 12px; }
  .table-wrap tr { padding: 15px; border: 1px solid var(--line); border-radius: 12px; }
  .table-wrap td { display: flex; justify-content: space-between; gap: 15px; padding: 8px 0; border: 0; }
  .table-wrap td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; }
  .result-card { align-items: stretch; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
