:root {
  --paper: #f2eee5;
  --surface: #fffdf8;
  --ink: #26251e;
  --muted: #6e695e;
  --line: #ded7c9;
  --rust: #a9432c;
  --rust-hover: #8f3523;
  --selection: #eee4d7;
  --success: #34634d;
  --error: #9b3029;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-size: 15px; line-height: 1.5; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button, summary, .button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .6; }
a { color: var(--rust); }
button, textarea, summary, a { touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--rust); outline-offset: 4px; }
button:focus:not(:focus-visible), main:focus { outline: none; }
h1, h2, h3, p { margin-top: 0; }
.muted { color: var(--muted); font-size: 13px; }
.skip-link { position: fixed; top: -100px; left: 16px; padding: 10px 16px; background: var(--surface); z-index: 10; }
.skip-link:focus { top: 12px; }
.app-header { display: flex; align-items: center; gap: 18px; min-height: 76px; padding: 12px 32px; border-bottom: 1px solid var(--line); background: var(--surface); }
.wordmark { color: var(--ink); font: 500 35px/1 var(--serif); letter-spacing: -.05em; text-decoration: none; }
.wordmark-dot { color: var(--rust); }
.environment-label { color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 2px 7px; font-size: 11px; }
.account { display: flex; align-items: center; gap: 20px; margin-left: auto; font-size: 13px; }
.text-button { border: 0; padding: 6px 0; color: var(--muted); background: transparent; text-decoration: underline; text-underline-offset: 3px; }
.text-button:hover { color: var(--ink); }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; border: 1px solid transparent; border-radius: 7px; padding: 10px 18px; text-decoration: none; font-weight: 600; }
.primary { color: #fff; background: var(--rust); }
.primary:hover { background: var(--rust-hover); }
.secondary { color: var(--ink); border-color: #c8bca8; background: var(--surface); }
.secondary:hover { background: var(--selection); }
.small { font-size: 13px; padding: 7px 12px; min-height: 38px; }
.startup-status { padding: 48px 32px; color: var(--muted); }
.login-screen { display: grid; place-items: start center; padding: min(12vh, 110px) 20px 40px; }
.login-card { width: 100%; max-width: 440px; padding: 40px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.login-card h1 { font: 500 33px/1.2 var(--serif); letter-spacing: -.025em; margin-bottom: 14px; }
.login-card > p { color: var(--muted); margin-bottom: 26px; }
.login-card > .button { width: 100%; }
.demo-sign-in { margin-top: 26px; padding-top: 24px; border-top: 1px solid var(--line); }
.demo-sign-in .button { width: 100%; }
.demo-sign-in p { color: var(--muted); font-size: 12px; margin: 12px 0 0; text-align: center; }
.practice-layout { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: calc(100vh - 76px); }
.patient-sidebar { background: #f8f5ee; border-right: 1px solid var(--line); padding: 26px 16px; }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 10px; margin-bottom: 16px; }
.sidebar-heading h1 { font-size: 15px; margin: 0; font-weight: 650; }
.sidebar-heading button { font-size: 12px; }
.patient-sidebar > .muted { margin: 0 10px 12px; }
.patient-list { display: grid; gap: 5px; }
.patient-button { width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; border: 1px solid transparent; border-radius: 7px; padding: 12px 10px; color: var(--ink); background: transparent; }
.patient-button:hover { background: #eee9de; }
.patient-button[aria-current="page"] { border-color: #d5c7b5; background: var(--selection); }
.patient-button strong { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.patient-button span { color: var(--muted); font-size: 12px; }
.chart-workspace { padding: 35px clamp(22px, 4vw, 64px) 60px; min-width: 0; }
.chart-placeholder { color: var(--muted); margin: 28px 0; }
#chart { max-width: 1060px; margin: 0 auto; }
.chart-header { display: flex; justify-content: space-between; align-items: center; gap: 18px; padding-bottom: 26px; border-bottom: 1px solid var(--line); margin-bottom: 30px; }
.chart-header h2 { font: 500 37px/1.15 var(--serif); letter-spacing: -.03em; margin-bottom: 7px; overflow-wrap: anywhere; }
.patient-details { color: var(--muted); font-size: 13px; margin-bottom: 0; }
.chart-header .button { flex-shrink: 0; }
.chart-header-actions { display: flex; align-items: center; gap: 18px; flex-shrink: 0; }
.chart-header-actions .text-button { font-size: 13px; }
.contact-panel { border: 1px solid var(--line); border-radius: 9px; background: var(--surface); padding: 20px; margin-bottom: 30px; max-width: 760px; }
.contact-editor h3 { position: sticky; top: 0; z-index: 1; background: var(--surface); padding-block: 10px; margin: -10px 0 12px; font-size: 17px; overflow-wrap: anywhere; }
.contact-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 18px; }
.contact-field { min-width: 0; }
.contact-field.wide { grid-column: 1 / -1; }
.contact-field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
.contact-field input { width: 100%; min-height: 44px; border: 1px solid #bcaf9a; border-radius: 5px; padding: 8px 10px; color: var(--ink); background: var(--surface); font-size: 16px; }
.contact-current { border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 18px; font-size: 13px; }
.contact-current summary { font-weight: 600; }
.contact-current dl { margin: 12px 0 0; }
.contact-current dl > div { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 12px; padding: 3px 0; }
.contact-current dt { color: var(--muted); }
.contact-current dd { margin: 0; overflow-wrap: anywhere; }
.section-heading { margin-bottom: 14px; }
.section-heading h3 { font-size: 18px; margin: 0; letter-spacing: -.015em; }
.chart-view-switch { display: flex; gap: 22px; margin: -8px 0 24px; border-bottom: 1px solid var(--line); }
.chart-view-switch { overflow-x: auto; }
.chart-view-switch button { border: 0; border-bottom: 2px solid transparent; padding: 10px 0; background: transparent; color: var(--muted); font-size: 14px; white-space: nowrap; flex-shrink: 0; }
.chart-view-switch button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--rust); font-weight: 600; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.medication-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.medication-toolbar { display: flex; align-items: center; gap: 16px; flex-shrink: 0; }
.medication-toolbar .text-button { font-size: 13px; }
.medication-table { width: 100%; border-collapse: collapse; border: 1px solid var(--line); background: var(--surface); font-size: 13px; }
.medication-table th { color: var(--muted); background: #f8f5ee; font-size: 11px; font-weight: 600; text-align: left; white-space: nowrap; }
.medication-table th, .medication-table td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.medication-table th:first-child, .medication-table td:first-child { padding-left: 16px; }
.medication-table th:last-child, .medication-table td:last-child { padding-right: 16px; }
.medication-table td { overflow-wrap: anywhere; }
.medication-cell-value { min-width: 0; overflow-wrap: anywhere; }
.medication-name { font-weight: 600; min-width: 130px; }
.medication-note { color: var(--muted); font-weight: 400; margin-top: 5px; }
.medication-note summary { font-size: 12px; text-decoration: underline; text-underline-offset: 2px; }
.medication-note p { color: var(--ink); margin: 5px 0 0; white-space: pre-wrap; }
.medication-editor { margin-top: 18px; padding: 20px; border: 1px solid var(--line); border-radius: 9px; background: #f8f4ec; }
.medication-editor-heading { position: sticky; top: 0; z-index: 1; background: #f8f4ec; padding-block: 9px; margin: -9px 0 8px; font-size: 16px; overflow-wrap: anywhere; }
.medication-review-hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.medication-edit-rows { display: grid; gap: 12px; }
.medication-edit-row { min-width: 0; margin: 0; padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.medication-edit-row legend { font-size: 13px; font-weight: 600; padding: 0 5px; overflow-wrap: anywhere; }
.medication-edit-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 12px; }
.medication-field { min-width: 0; }
.medication-field-name { grid-column: span 2; }
.medication-field label { display: block; margin-bottom: 4px; font-size: 12px; font-weight: 600; }
.medication-field input, .medication-field select, .medication-field textarea { width: 100%; min-height: 40px; border: 1px solid #bcaf9a; border-radius: 5px; padding: 7px 9px; color: var(--ink); background: var(--surface); font-size: 14px; }
.medication-field textarea { min-height: 58px; resize: vertical; }
.medication-field-note { margin-top: 10px; }
.medication-row-actions { display: flex; justify-content: flex-end; min-height: 31px; font-size: 12px; }
.medication-add-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.intake-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.intake-heading .text-button { font-size: 13px; }
.intake-explanation { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.intake-list { display: grid; gap: 14px; }
.intake-item { border: 1px solid var(--line); border-radius: 9px; background: var(--surface); min-width: 0; overflow: clip; }
.intake-item-content { padding: 18px 20px; }
.intake-item-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.intake-item-heading > div { min-width: 0; }
.intake-item h4 { font-size: 15px; margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.intake-category { color: var(--muted); font-size: 12px; margin: 0 0 3px; }
.intake-state { border: 1px solid var(--line); border-radius: 20px; padding: 3px 9px; font-size: 12px; white-space: nowrap; }
.intake-state.pending { color: #82462c; background: #f6eee2; border-color: #dcc6a8; }
.intake-state.approved { color: var(--success); border-color: #bdcabc; }
.intake-state.rejected { color: var(--error); border-color: #d9afa5; }
.intake-received, .intake-reviewed { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.intake-review-note { display: block; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 4px; }
.intake-actions { display: flex; align-items: center; gap: 22px; margin-top: 8px; font-size: 13px; }
.intake-review { padding: 20px; border-top: 1px solid var(--line); background: #f8f4ec; }
.intake-review .intake-review-heading { position: sticky; top: 0; z-index: 1; background: #f8f4ec; padding-block: 9px; margin: -9px 0 12px; }
.intake-review-choices { margin: 0 0 18px; padding: 0; border: 0; display: flex; flex-wrap: wrap; gap: 8px 20px; }
.intake-review-choices legend, .intake-note-label { font-weight: 500; font-size: 13px; margin-bottom: 7px; }
.intake-review-choices label { display: inline-flex; align-items: center; min-height: 40px; gap: 8px; font-size: 14px; }
.intake-review-choices input { width: 17px; height: 17px; accent-color: var(--rust); }
.intake-note-label { display: block; }
.intake-review textarea { width: 100%; min-height: 90px; resize: vertical; color: var(--ink); background: var(--surface); border: 1px solid #bcaf9a; border-radius: 6px; padding: 10px; font-size: 16px; }
.intake-current-review { padding: 10px 12px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: 5px; font-size: 13px; }
.intake-current-review p { margin: 5px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
#chart[data-full-chart="true"] { max-width: none; }
.native-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.native-toolbar p { font-size: 13px; color: var(--muted); margin: 0; }
.native-toolbar button { font-size: 13px; flex-shrink: 0; }
.native-frame { width: 100%; height: 78vh; min-height: 680px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
#native-status:not(:empty) { margin-bottom: 14px; }
.problem-list { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.problem-item + .problem-item { border-top: 1px solid var(--line); }
.problem-content { padding: 18px 20px; display: grid; grid-template-columns: minmax(150px, .75fr) minmax(0, 1.5fr) auto; gap: 22px; align-items: start; }
.problem-title { font-size: 15px; line-height: 1.4; font-weight: 600; margin: 0 0 4px; }
.problem-meta { color: var(--muted); font-size: 12px; }
.plan-content { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font-size: 14px; line-height: 1.55; }
.plan-content.empty { color: var(--muted); }
.problem-content > .text-button { font-size: 13px; padding-top: 0; }
.empty-state { padding: 22px 20px; margin: 0; color: var(--muted); }
.plan-editor { border-top: 1px solid var(--line); padding: 20px; background: #f8f4ec; }
.plan-editor label { display: block; margin-bottom: 9px; font-weight: 600; font-size: 14px; }
.plan-editor textarea { display: block; width: 100%; min-height: 140px; resize: vertical; color: var(--ink); background: var(--surface); border: 1px solid #bcaf9a; border-radius: 6px; padding: 12px; line-height: 1.5; }
.editor-actions { display: flex; gap: 14px; align-items: center; margin-top: 14px; }
.editor-feedback { margin: 12px 0 0; font-size: 13px; }
.editor-feedback.error { color: var(--error); }
.editor-feedback .text-button { color: inherit; margin-left: 10px; }
.message { max-width: 1060px; padding: 12px 15px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); font-size: 14px; margin: 0 auto 22px; }
.message.error { border-color: #d9afa5; color: var(--error); }
.message.success { color: var(--success); border-color: #bdcabc; }
.login-card .message { margin: 22px 0 0; }
.audit-panel { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 17px; }
.audit-panel summary { color: var(--muted); font-size: 14px; width: fit-content; padding: 3px 0; }
.audit-panel[open] summary { color: var(--ink); margin-bottom: 18px; }
.audit-events { list-style: none; padding: 0; margin: 0; }
.audit-events li { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.audit-events time { color: var(--muted); font-size: 12px; }
.audit-event-copy { min-width: 0; overflow-wrap: anywhere; }
.audit-event-copy strong { display: block; font-weight: 500; }
.audit-event-copy span { color: var(--muted); font-size: 12px; }

@media (max-width: 800px) {
  .app-header { padding-inline: 20px; gap: 12px; }
  .practice-layout { grid-template-columns: 210px minmax(0, 1fr); }
  .patient-sidebar { padding-inline: 10px; }
  .chart-workspace { padding: 28px 22px 48px; }
  .chart-header { align-items: flex-start; flex-direction: column; gap: 14px; }
  .chart-header h2 { font-size: 32px; }
  .problem-content { grid-template-columns: 1fr auto; gap: 12px; }
  .problem-identity { grid-column: 1; }
  .problem-content > .text-button { grid-column: 2; grid-row: 1; }
  .problem-content > .plan-content { grid-column: 1 / -1; }
  .medication-table th, .medication-table td { padding-inline: 8px; }
  .medication-edit-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .medication-field-name { grid-column: span 2; }
}

@media (max-width: 580px) {
  .app-header { min-height: 68px; padding: 14px 18px; }
  .wordmark { font-size: 31px; }
  .account { gap: 12px; }
  #account-name { display: none; }
  .practice-layout { display: block; }
  .patient-sidebar { padding: 18px 14px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-heading { margin-bottom: 12px; }
  .patient-list { display: flex; overflow-x: auto; gap: 7px; padding: 3px 2px 6px; }
  .patient-button { min-width: 170px; width: auto; flex-shrink: 0; padding: 10px; }
  .chart-workspace { padding: 25px 18px 40px; }
  .chart-header { margin-bottom: 24px; padding-bottom: 22px; }
  .chart-header h2 { font-size: 31px; }
  .problem-content, .plan-editor { padding: 16px; }
  .audit-events li { grid-template-columns: 1fr; gap: 4px; }
  .login-card { padding: 30px 24px; }
  .login-card h1 { font-size: 30px; }
  .native-toolbar { align-items: flex-start; flex-direction: column; gap: 6px; }
  .native-frame { min-height: 640px; }
  .contact-panel { padding: 16px; }
  .contact-grid { grid-template-columns: 1fr; }
  .contact-field.wide { grid-column: auto; }
  .contact-current dl > div { grid-template-columns: 110px minmax(0, 1fr); gap: 8px; }
  .intake-item-content, .intake-review { padding: 16px; }
  .intake-item-heading { flex-direction: column; gap: 8px; }
  .chart-view-switch { gap: 18px; }
  .medication-heading { align-items: flex-start; flex-direction: column; gap: 10px; }
  .medication-table, .medication-table tbody, .medication-table tr, .medication-table td { display: block; }
  .medication-table { border-radius: 8px; overflow: hidden; }
  .medication-table thead { display: none; }
  .medication-table tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .medication-table tr:last-child { border-bottom: 0; }
  .medication-table td, .medication-table td:first-child, .medication-table td:last-child { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 10px; border: 0; padding: 3px 0; }
  .medication-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 400; }
  .medication-editor { padding: 16px; }
  .medication-edit-fields { grid-template-columns: 1fr; }
  .medication-field-name { grid-column: auto; }
}

@media (prefers-reduced-motion: no-preference) {
  button, .button { transition: background-color 120ms ease, border-color 120ms ease; }
}
