:root {
  --ink: #18302d;
  --muted: #6d7c79;
  --line: #dbe4e1;
  --paper: #ffffff;
  --canvas: #f3f6f5;
  --teal: #147d73;
  --teal-dark: #0d625a;
  --teal-soft: #e7f4f1;
  --coral: #df6b57;
  --coral-soft: #fff0ec;
  --gold: #b78327;
  --danger: #b63d35;
  --shadow: 0 14px 36px rgba(31, 65, 59, .12);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif; color: var(--ink); background: var(--canvas); font-size: 14px; }
.login-screen { min-height: 100vh; display: grid; grid-template-rows: 1fr auto; align-items: center; justify-items: center; gap: 24px; padding: 40px 20px 18px; background: #eef1f3; }
.login-panel { width: min(380px, 100%); padding: 30px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 16px 40px rgba(24, 38, 46, .12); display: grid; gap: 16px; }
.login-panel h1 { margin: 0 0 8px; font-size: 28px; text-align: center; }
.login-panel label { display: grid; gap: 7px; font-size: 14px; font-weight: 700; }
.login-panel input { width: 100%; margin-top: 0; }
.password-field { position: relative; display: block; }
.password-field input { padding-right: 46px; }
.password-toggle { position: absolute; right: 4px; top: 4px; width: 36px; height: 36px; border: 0; background: transparent; color: var(--teal); font-size: 21px; line-height: 1; }
.password-toggle:hover { background: var(--teal-soft); border-radius: 6px; }
.login-error { min-height: 20px; margin: 0; color: #b42318; font-size: 13px; }
.filing-footer { color: var(--muted); font-size: 12px; text-align: center; }
.filing-footer a { color: inherit; text-decoration: none; }
.filing-footer a:hover { color: var(--teal); text-decoration: underline; }
.signed-in-user { font-size: 13px; color: var(--muted); white-space: nowrap; }
.read-only .write-only { display: none !important; }
.read-only .records-layout { grid-template-columns: 1fr; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; }
.topbar { height: 68px; padding: 0 24px; background: var(--paper); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; background: var(--teal); color: white; border-radius: 7px; font-size: 20px; font-weight: 700; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 17px; }
.brand span { color: var(--muted); font-size: 11px; margin-top: 2px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.workspace { min-height: calc(100vh - 68px); display: grid; grid-template-columns: 292px minmax(0, 1fr); }
.sidebar { background: var(--paper); border-right: 1px solid var(--line); padding: 20px 16px; overflow-y: auto; max-height: calc(100vh - 68px); }
.search-section, .appointment-section { padding-bottom: 20px; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
label, .field-label { display: block; color: #435a56; font-weight: 600; font-size: 12px; }
input, textarea, select { width: 100%; border: 1px solid #cbd8d5; border-radius: 6px; padding: 10px 11px; background: white; color: var(--ink); outline: none; margin-top: 6px; }
input:focus, textarea:focus, select:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(20,125,115,.12); }
textarea { min-height: 76px; resize: vertical; }
.search-wrap { position: relative; margin: 7px 0 10px; }
.search-wrap input { margin: 0; padding-left: 34px; }
.search-icon { position: absolute; z-index: 2; left: 11px; top: 9px; color: var(--muted); font-size: 19px; }
.suggestions { position: absolute; z-index: 10; top: 44px; width: 100%; background: white; border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); overflow: hidden; }
.suggestion { width: 100%; border: 0; background: white; text-align: left; padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; }
.suggestion:hover { background: var(--teal-soft); }
.suggestion small { color: var(--muted); }
.appointment-patient-picker { position: relative; }
.appointment-patient-picker .suggestions { top: 45px; }
.appointment-patient-picker input.invalid-selection { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(182,61,53,.1); }
.button { border: 0; border-radius: 6px; padding: 10px 15px; font-weight: 700; color: var(--ink); background: transparent; }
.button.primary { color: white; background: var(--teal); }
.button.primary:hover { background: var(--teal-dark); }
.button.secondary { border: 1px solid var(--line); background: white; }
.button.danger { background: var(--danger); color: white; }
.button.full { width: 100%; }
.text-button { color: var(--muted); }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--ink); font-size: 20px; }
.icon-button.small { width: 30px; height: 30px; font-size: 17px; }
.section-heading, .panel-heading { display: flex; justify-content: space-between; align-items: center; }
.heading-actions { display: flex; align-items: center; gap: 7px; }
.compact-link { border: 0; background: transparent; color: var(--teal); padding: 5px 2px; font-size: 11px; font-weight: 700; }
.section-heading h2, .panel-heading h2 { font-size: 15px; margin: 2px 0 0; }
.section-heading > span, .record-count { color: var(--muted); font-size: 12px; }
.eyebrow { color: var(--teal); text-transform: uppercase; font-weight: 700; font-size: 10px; }
.date-strip { margin: 12px 0 8px; color: var(--muted); font-size: 12px; }
.appointment-card { display: grid; grid-template-columns: 42px 1fr; gap: 10px; width: 100%; border: 0; border-left: 3px solid var(--teal); background: #f7faf9; padding: 10px; text-align: left; margin-top: 7px; border-radius: 0 6px 6px 0; }
.appointment-card:hover { background: var(--teal-soft); }
.appointment-card .time { color: var(--teal); font-weight: 800; }
.appointment-card strong, .appointment-card small { display: block; }
.appointment-card small { color: var(--muted); margin-top: 3px; }
.empty-list { color: var(--muted); text-align: center; padding: 20px 6px; font-size: 12px; }
.patient-list { margin-top: 8px; }
.patient-row { width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 8px; border: 0; border-radius: 6px; background: transparent; text-align: left; }
.patient-row:hover, .patient-row.active { background: var(--teal-soft); }
.mini-avatar, .avatar { display: grid; place-items: center; flex: 0 0 auto; color: var(--teal-dark); background: #d9eeea; font-weight: 800; }
.mini-avatar { width: 34px; height: 34px; border-radius: 50%; }
.patient-row span:last-child { min-width: 0; }
.patient-row strong, .patient-row small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.patient-row small { color: var(--muted); margin-top: 2px; }
.content { min-width: 0; }
.empty-state { height: calc(100vh - 68px); display: flex; flex-direction: column; justify-content: center; align-items: center; color: var(--muted); }
.empty-symbol { width: 62px; height: 62px; border-radius: 50%; display: grid; place-items: center; color: var(--teal); background: var(--teal-soft); font-size: 30px; }
.empty-state h1 { color: var(--ink); font-size: 22px; margin: 18px 0 4px; }
.empty-state p { margin: 0 0 18px; }
.patient-content { padding: 26px 28px 34px; }
.patient-header { display: flex; align-items: center; gap: 14px; }
.avatar { width: 54px; height: 54px; border-radius: 7px; font-size: 22px; }
.patient-title { flex: 1; }
.title-row { display: flex; align-items: center; gap: 10px; }
.title-row h1 { font-size: 23px; margin: 0; }
.status-tag { font-size: 11px; color: var(--teal-dark); background: var(--teal-soft); padding: 3px 7px; border-radius: 4px; }
.patient-meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.patient-alerts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.patient-alert { color: #a62925; background: #fff0ee; border: 1px solid #f0c5c0; border-radius: 4px; padding: 4px 7px; font-size: 11px; font-weight: 700; }
.tabs { display: flex; gap: 25px; border-bottom: 1px solid var(--line); margin-top: 24px; }
.tab { border: 0; border-bottom: 2px solid transparent; color: var(--muted); background: transparent; padding: 10px 1px; font-weight: 700; }
.tab.active { color: var(--teal); border-color: var(--teal); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.records-layout { display: grid; grid-template-columns: minmax(400px, 1.15fr) minmax(360px, .85fr); gap: 22px; padding-top: 22px; align-items: start; }
.timeline-area, .entry-panel, .detail-grid, .table-wrap, .audit-list { background: var(--paper); border: 1px solid var(--line); border-radius: 7px; }
.timeline-area, .entry-panel { padding: 20px; }
.entry-panel { position: sticky; top: 18px; }
.timeline { margin-top: 18px; }
.timeline-item { position: relative; padding: 0 0 24px 28px; border-left: 1px solid #cbd8d5; margin-left: 8px; }
.timeline-item:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline-dot { position: absolute; left: -6px; top: 2px; width: 11px; height: 11px; border-radius: 50%; background: var(--teal); border: 3px solid white; box-shadow: 0 0 0 1px var(--teal); }
.record-head { display: flex; justify-content: space-between; gap: 12px; }
.record-head h3 { margin: 0; font-size: 15px; }
.record-date { color: var(--muted); font-size: 11px; margin-top: 4px; }
.record-actions { display: flex; gap: 5px; }
.record-actions button { border: 0; background: transparent; color: var(--muted); padding: 3px 5px; font-size: 12px; }
.record-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; margin-top: 12px; background: var(--line); border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.record-field { min-width: 0; background: white; padding: 8px 9px; }
.record-field.wide { grid-column: 1 / -1; }
.record-field span, .record-field strong { display: block; }
.record-field span { color: var(--muted); font-size: 10px; margin-bottom: 4px; }
.record-field strong { color: #3d5752; font-size: 11px; font-weight: 600; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.summary-chip { padding: 4px 7px; border-radius: 4px; color: #3d5752; background: #eef3f2; font-size: 11px; }
.record-note { margin: 10px 0 0; color: #4e625e; line-height: 1.65; white-space: pre-wrap; }
.stage-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 7px 0 18px; }
.stage-button { min-height: 42px; border: 1px solid var(--line); border-radius: 5px; background: white; color: #46605b; font-size: 12px; font-weight: 700; padding: 5px; }
.stage-button.active { border-color: var(--teal); background: var(--teal-soft); color: var(--teal-dark); }
.dynamic-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.dynamic-grid .wide { grid-column: 1 / -1; }
.repeat-block { grid-column: 1 / -1; background: #f6f9f8; border-left: 3px solid var(--teal); padding: 12px; border-radius: 0 5px 5px 0; }
.repeat-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.repeat-head strong { font-size: 12px; }
.repeat-row { display: grid; grid-template-columns: repeat(4, 1fr) 28px; gap: 7px; margin-top: 7px; align-items: end; }
.repeat-row label { font-size: 10px; }
.repeat-row input { padding: 8px; }
.remove-row { width: 28px; height: 36px; border: 0; background: var(--coral-soft); color: var(--danger); border-radius: 5px; }
.add-row { border: 0; background: transparent; color: var(--teal); font-weight: 700; font-size: 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; padding-top: 17px; margin-top: 17px; border-top: 1px solid var(--line); }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 22px; overflow: hidden; }
.detail-item { padding: 18px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); min-height: 76px; }
.detail-item:nth-child(3n) { border-right: 0; }
.detail-item span, .detail-item strong { display: block; }
.detail-item span { color: var(--muted); font-size: 11px; margin-bottom: 7px; }
.detail-item strong { font-weight: 600; line-height: 1.5; }
.table-wrap, .audit-list { margin-top: 22px; padding: 18px; }
.wide-dialog { width: min(1040px, calc(100% - 30px)); }
.appointment-overview { max-height: min(620px, 70vh); overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.appointment-overview table { table-layout: fixed; }
.appointment-overview th { position: sticky; top: 0; z-index: 1; background: #f5f8f7; }
.appointment-overview th:first-child, .appointment-overview td:first-child { width: 32%; }
.appointment-overview tbody tr[data-overview-appointment] { cursor: pointer; }
.appointment-overview tbody tr[data-overview-appointment]:hover { background: var(--teal-soft); }
.appointment-overview .today-row { background: #f7fbfa; }
.date-main { display: block; font-weight: 700; color: var(--ink); }
.date-weekday { display: block; color: var(--muted); font-size: 10px; margin-top: 3px; }
.done-text { color: var(--muted); }
.time-selects { display: grid; grid-template-columns: 1fr auto 1fr; gap: 7px; align-items: center; margin-top: 6px; }
.time-selects select { margin: 0; }
.action-spacer { flex: 1; }
.table-action { border: 0; background: transparent; color: var(--teal); font-weight: 700; padding: 4px; }
.calendar-toolbar { display: flex; align-items: center; justify-content: center; gap: 18px; margin: -4px 0 14px; }
.calendar-toolbar strong { min-width: 110px; text-align: center; font-size: 16px; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.calendar-weekday { padding: 8px; background: #f4f7f6; color: var(--muted); text-align: center; font-size: 11px; font-weight: 700; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.calendar-cell { min-height: 112px; padding: 7px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: white; overflow: hidden; }
.calendar-cell.outside { background: #f7f9f8; }
.calendar-cell.today-cell { background: #f0f8f6; box-shadow: inset 0 0 0 1px var(--teal); }
.calendar-day { display: block; color: var(--muted); font-size: 11px; margin-bottom: 5px; }
.calendar-events { display: grid; gap: 4px; }
.calendar-event { display: grid; grid-template-columns: minmax(0, 1fr) 22px; align-items: stretch; background: var(--teal-soft); border-left: 2px solid var(--teal); border-radius: 0 4px 4px 0; overflow: hidden; }
.calendar-event.done { opacity: .62; }
.calendar-event-main { min-width: 0; border: 0; background: transparent; padding: 5px; text-align: left; }
.calendar-event-main strong, .calendar-event-main span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 10px; }
.calendar-event-main span { color: var(--muted); margin-top: 2px; }
.calendar-edit { width: 22px; border: 0; background: rgba(255,255,255,.45); color: var(--teal-dark); padding: 0; }
.settings-dialog { width: min(780px, calc(100% - 30px)); }
.settings-section { padding: 15px 0; border-top: 1px solid var(--line); }
.settings-section h3 { margin: 0; font-size: 14px; }
.settings-section p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.settings-checks { display: flex; flex-wrap: wrap; gap: 9px 20px; margin-top: 12px; }
.settings-checks label, .required-check { display: flex; align-items: center; gap: 6px; }
.settings-checks input, .required-check input { width: auto; margin: 0; }
.settings-section-head { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 12px; }
.settings-section-head select { width: 150px; margin: 0; }
.field-config-list { display: grid; gap: 7px; margin-bottom: 10px; }
.field-config-row { display: grid; grid-template-columns: minmax(190px, 1fr) 130px 65px 102px; gap: 8px; align-items: center; }
.field-config-row input, .field-config-row select { margin: 0; padding: 8px; }
.config-field-main { display: grid; gap: 6px; }
.config-options { color: #526763; font-size: 11px; }
.config-row-actions { display: flex; justify-content: flex-end; gap: 5px; }
.move-config-field, .remove-config-field { width: 30px; height: 34px; border: 0; border-radius: 5px; }
.move-config-field { color: var(--teal-dark); background: var(--teal-soft); font-size: 16px; }
.remove-config-field { color: var(--danger); background: var(--coral-soft); }
.move-config-field:disabled, .remove-config-field:disabled { opacity: .35; cursor: not-allowed; }
.account-dialog { width: min(980px, calc(100% - 30px)); }
.account-section { padding: 18px 0; border-top: 1px solid var(--line); }
.account-section:first-of-type { padding-top: 4px; border-top: 0; }
.account-section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.account-section-heading h3 { margin: 0; font-size: 15px; }
.account-section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.account-create-grid { display: grid; grid-template-columns: 1fr 1fr 150px 1.4fr; gap: 12px; align-items: end; }
.account-create-grid input, .account-create-grid select { margin-top: 6px; }
.generated-password-field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; align-items: end; }
.generated-password-field input, .generated-password-field .button { margin-top: 6px; }
.account-form-error { grid-column: 1 / -2; }
.account-create-button { min-height: 42px; }
.account-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 6px; }
.account-table { min-width: 790px; }
.account-table th { background: #f5f8f7; }
.account-table input, .account-table select { min-width: 120px; margin: 0; padding: 8px; }
.account-table .member-name { min-width: 130px; }
.account-table td:last-child { width: 280px; }
.account-username strong, .account-username small { display: block; }
.account-username small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.account-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.account-actions .button { padding: 7px 9px; font-size: 11px; }
.account-status { display: inline-block; min-width: 42px; padding: 4px 6px; border-radius: 4px; background: var(--teal-soft); color: var(--teal-dark); text-align: center; font-size: 11px; font-weight: 700; }
.account-status.disabled { background: #f0f1f1; color: var(--muted); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { font-size: 11px; color: var(--muted); }
.audit-item { padding: 13px 0; border-bottom: 1px solid var(--line); }
.audit-item:last-child { border-bottom: 0; }
.audit-item strong { font-size: 13px; }
.audit-item p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
dialog { width: min(680px, calc(100% - 30px)); border: 0; padding: 0; border-radius: 8px; color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(14, 33, 30, .45); }
.modal-form { padding: 22px; }
.modal-form.compact { max-width: 480px; margin: auto; }
.modal-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.modal-heading h2 { margin: 3px 0 0; font-size: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.check-row { display: flex; gap: 18px; padding: 12px; margin-top: 6px; border: 1px solid var(--line); border-radius: 6px; }
.check-row label { display: flex; align-items: center; gap: 6px; }
.check-row input { width: auto; margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.notice { color: #795f2d; background: #fff7e7; border-left: 3px solid var(--gold); padding: 10px; font-size: 12px; }
.toast { position: fixed; z-index: 30; right: 24px; bottom: 24px; padding: 11px 16px; color: white; background: var(--ink); border-radius: 6px; box-shadow: var(--shadow); transform: translateY(80px); opacity: 0; transition: .2s ease; }
.toast.show { transform: translateY(0); opacity: 1; }

@media (max-width: 1050px) {
  .records-layout { grid-template-columns: 1fr; }
  .entry-panel { position: static; }
}
@media (max-width: 760px) {
  .topbar { padding: 0 12px; }
  .topbar-actions .button { display: none; }
  .topbar-actions #logoutBtn { display: inline-flex; align-items: center; padding: 8px 10px; }
  .topbar-actions #accountManagementBtn:not([hidden]) { display: inline-flex; align-items: center; padding: 8px; font-size: 11px; }
  .topbar-actions #importBtn, .topbar-actions #exportBtn, .signed-in-user { display: none; }
  .workspace { display: block; }
  .sidebar { max-height: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .appointment-section { display: block; padding: 14px 0 16px; margin: 0; }
  .appointment-section .section-heading { margin-bottom: 8px; }
  .appointment-list { max-height: 210px; overflow-y: auto; }
  .patient-list-section { display: none; }
  .patient-content { padding: 18px 12px; }
  .patient-header { align-items: flex-start; flex-wrap: wrap; }
  .patient-header .button { margin-left: 68px; }
  .tabs { overflow-x: auto; gap: 20px; }
  .tab { white-space: nowrap; }
  .records-layout { display: block; }
  .entry-panel { margin-top: 16px; }
  .stage-grid { grid-template-columns: repeat(3, 1fr); }
  .dynamic-grid, .form-grid { grid-template-columns: 1fr; }
  .dynamic-grid .wide, .form-grid .wide { grid-column: auto; }
  .repeat-row { grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); padding-bottom: 9px; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .detail-item:nth-child(3n) { border-right: 1px solid var(--line); }
  .detail-item:nth-child(2n) { border-right: 0; }
  .wide-dialog { width: calc(100% - 12px); }
  .calendar-cell { min-height: 82px; padding: 3px; }
  .calendar-event { display: block; }
  .calendar-edit { display: none; }
  .calendar-event-main { width: 100%; padding: 4px 2px; }
  .calendar-event-main strong, .calendar-event-main span { font-size: 9px; }
  .field-config-row { grid-template-columns: minmax(0, 1fr) 105px 55px; }
  .config-row-actions { grid-column: 1 / -1; }
  .account-dialog { width: calc(100% - 12px); }
  .account-create-grid { grid-template-columns: 1fr; }
  .account-form-error { grid-column: auto; }
}
@media print {
  body { background: white; }
  .topbar, .sidebar, .tabs, .entry-panel, .record-actions, .patient-header .button { display: none !important; }
  .workspace { display: block; }
  .patient-content { padding: 0; }
  .patient-header { display: flex; border-bottom: 2px solid var(--ink); padding-bottom: 15px; }
  .tab-panel { display: block !important; }
  #appointmentsPanel, #auditPanel { display: none !important; }
  .records-layout { display: block; padding: 15px 0 0; }
  .timeline-area, .detail-grid { border: 0; padding: 0; }
  .timeline-item { break-inside: avoid; }
  #profilePanel { margin-top: 24px; }
}
