:root {
  --nav: #17393d;
  --nav-deep: #102c2f;
  --accent: #168c86;
  --accent-dark: #0f6f6a;
  --accent-soft: #e7f3f1;
  --bg: #eef1f2;
  --panel: #ffffff;
  --line: #d9e0e2;
  --line-soft: #e8edef;
  --text: #263438;
  --muted: #6f7e82;
  --danger: #b3453e;
  --warning: #8b611a;
  --font: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: var(--font); color: var(--text); background: var(--bg); font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }

.admin-shell { min-width: 1280px; min-height: 100vh; display: flex; }
.sidebar { width: 236px; background: var(--nav); color: #dce8e8; position: fixed; inset: 0 auto 0 0; display: flex; flex-direction: column; z-index: 20; }
.brand { height: 92px; padding: 20px 22px 15px; border-bottom: 1px solid rgba(255,255,255,.11); }
.brand-mark, .brand-title { font-size: 18px; font-weight: 600; letter-spacing: 1px; line-height: 1.5; color: #fff; }
.brand-mark { margin-bottom: 1px; }
.side-nav { flex: 1; overflow: auto; padding: 12px 0; }
.nav-single, .nav-group-title, .nav-item { width: 100%; border: 0; background: transparent; color: inherit; text-align: left; }
.nav-single, .nav-group-title { height: 43px; padding: 0 21px; font-size: 14px; }
.nav-single:hover, .nav-group-title:hover { background: rgba(255,255,255,.05); }
.nav-single.active { background: var(--accent-dark); border-left: 3px solid #8fd0cb; padding-left: 18px; color: #fff; }
.nav-group-title { display: flex; align-items: center; justify-content: space-between; color: #fff; font-weight: 600; }
.nav-arrow { color: #9eb4b5; font-size: 11px; font-weight: 400; }
.nav-children { display: none; padding: 2px 0 7px; background: rgba(5,27,29,.18); }
.nav-group.expanded .nav-children { display: block; }
.nav-item { display: block; height: 36px; line-height: 36px; padding: 0 21px 0 35px; font-size: 13px; color: #bfd0d1; border-left: 3px solid transparent; }
button.nav-item:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav-item.active { color: #fff; background: rgba(22,140,134,.35); border-left-color: #8fd0cb; }
.nav-static { cursor: default; color: #bfd0d1; }

.main { margin-left: 236px; min-height: 100vh; flex: 1; min-width: 0; overflow-x: hidden; }
.page-header { height: 64px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 26px; }
.breadcrumb { font-size: 18px; color: var(--text); margin: 0; font-weight: 600; }
.page-header h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: .2px; }
.header-meta { display: flex; align-items: center; gap: 22px; color: var(--muted); font-size: 12px; }
.header-link { border: 0; background: transparent; color: var(--muted); padding: 3px 0 3px 18px; border-left: 1px solid var(--line); }
.header-link:hover { color: var(--text); text-decoration: underline; }
.content { padding: 18px 20px 30px; min-width: 0; max-width: 100%; }
.page { display: none; }
.page.active { display: block; }

.panel, .metric, .context-strip { background: var(--panel); border: 1px solid var(--line); }
.panel { margin-bottom: 16px; min-width: 0; max-width: 100%; }
.panel-head { min-height: 60px; padding: 13px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line-soft); }
.panel-head h2 { font-size: 16px; margin: 0 0 4px; font-weight: 600; }
.panel-head p, .modal-head p, .drawer-head p { margin: 0; color: var(--muted); font-size: 12px; }
.metric-grid { display: grid; gap: 12px; margin-bottom: 16px; }
.metric-grid-6 { grid-template-columns: repeat(6, 1fr); }
.metric-grid-5 { grid-template-columns: repeat(5, 1fr); }
.metric { padding: 15px 16px; min-height: 104px; }
.metric span { display: block; color: var(--muted); font-size: 13px; }
.metric strong { display: block; font-size: 25px; font-weight: 600; margin: 10px 0 7px; letter-spacing: -.5px; }
.metric small { color: var(--muted); font-size: 12px; }
.two-col { display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px; }
.two-col .panel { min-width: 0; }

table { width: 100%; border-collapse: collapse; table-layout: auto; }
th, td { border-bottom: 1px solid var(--line-soft); text-align: left; padding: 11px 12px; font-size: 13px; white-space: nowrap; }
th { background: #f4f6f6; color: #516064; font-weight: 600; }
tbody tr:hover { background: #f8faf9; }
tbody tr:last-child td { border-bottom: 0; }
.table-scroll { width: 100%; max-width: 100%; overflow-x: auto; overflow-y: hidden; }
.table-scroll table { width: max-content; min-width: 1450px; }
.simple-table th, .simple-table td { padding: 12px; }
.text-link { border: 0; background: none; color: var(--accent-dark); padding: 2px 5px; }
.text-link:hover { text-decoration: underline; }
.text-link:disabled { color: #a9b1b3; cursor: default; text-decoration: none; }
.btn { min-width: 68px; height: 34px; padding: 0 14px; border: 1px solid #bac5c7; background: #fff; border-radius: 3px; }
.btn:hover { border-color: var(--accent); color: var(--accent-dark); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); color: #fff; }
.plain-close { background: none; border: 0; color: var(--muted); padding: 5px; }
.plain-close:hover { color: var(--text); text-decoration: underline; }

.filter-bar, .filter-inline { background: #fff; border: 1px solid var(--line); margin-bottom: 16px; padding: 14px 16px; display: flex; align-items: flex-end; flex-wrap: wrap; gap: 10px; }
.filter-inline { margin: 0; border: 0; border-bottom: 1px solid var(--line-soft); }
label { color: #536166; font-size: 13px; }
label input, label select, label textarea { display: block; margin-top: 6px; }
input, select, textarea { border: 1px solid #c9d2d4; background: #fff; border-radius: 2px; outline: none; }
input, select { height: 34px; min-width: 148px; padding: 0 9px; }
textarea { width: 100%; padding: 9px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.date-sep { padding-bottom: 9px; color: var(--muted); }

.trend-chart { height: 267px; display: flex; padding: 18px 20px 20px; }
.chart-scale { width: 42px; height: 210px; display: flex; flex-direction: column; justify-content: space-between; color: var(--muted); font-size: 11px; padding-bottom: 3px; }
.line-plot { flex: 1; height: 232px; position: relative; }
.line-plot .grid-line { height: 52.5px; border-top: 1px solid var(--line-soft); }
.line-plot svg { position: absolute; inset: 0 0 22px; width: 100%; height: 210px; }
.chart-labels, .axis-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.bar-list { padding: 17px 20px 10px; }
.bar-list > div { display: grid; grid-template-columns: 125px 1fr 65px; align-items: center; gap: 10px; height: 43px; }
.bar-list span { color: #4b595d; font-size: 13px; }
.bar-list i { display: block; height: 12px; background: #7eaaa7; max-width: 100%; }
.bar-list b { font-weight: 500; text-align: right; }
.quality-lines { padding: 14px 20px 15px; }
.quality-legend { display: flex; gap: 17px; color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.quality-legend span::before { content: ""; width: 14px; height: 2px; background: #8ca3a1; display: inline-block; vertical-align: middle; margin-right: 5px; }
.quality-legend span:first-child::before { background: var(--accent); height: 3px; }
.quality-lines svg { width: 100%; height: 220px; display: block; }
.axis-labels { padding: 0 15px 0 28px; }

.context-strip { display: flex; align-items: center; gap: 48px; padding: 14px 17px; margin-bottom: 16px; }
.context-strip div { display: grid; gap: 5px; }
.context-strip span { font-size: 12px; color: var(--muted); }
.context-strip strong { font-size: 14px; font-weight: 600; }
.context-strip .btn { margin-left: auto; }

.drawer-mask, .modal-mask { position: fixed; inset: 0; background: rgba(13,29,31,.42); z-index: 100; }
.drawer { position: absolute; top: 0; right: 0; width: min(850px, 70vw); height: 100%; background: #fff; display: flex; flex-direction: column; box-shadow: -4px 0 16px rgba(0,0,0,.15); }
.drawer-head, .modal-head { min-height: 68px; display: flex; align-items: center; justify-content: space-between; padding: 13px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h2, .modal-head h2 { margin: 0 0 4px; font-size: 18px; }
.drawer-body { flex: 1; overflow: auto; padding: 17px 20px; }
.drawer-foot, .modal-foot { border-top: 1px solid var(--line); padding: 13px 20px; display: flex; justify-content: flex-end; gap: 9px; }
.detail-block { border: 1px solid var(--line); margin-bottom: 14px; }
.detail-block h3 { margin: 0; font-size: 14px; padding: 10px 12px; background: #f5f7f7; border-bottom: 1px solid var(--line); }
.detail-block > textarea { margin: 12px; width: calc(100% - 24px); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; margin: 0; }
.detail-grid div { display: grid; grid-template-columns: 92px 1fr; border-bottom: 1px solid var(--line-soft); }
.detail-grid div:nth-last-child(-n+2) { border-bottom: 0; }
.detail-grid dt, .detail-grid dd { margin: 0; padding: 10px 12px; }
.detail-grid dt { color: var(--muted); background: #fafbfb; }
.compare-table th, .compare-table td { padding: 9px 11px; }
.evidence { display: grid; grid-template-columns: 300px 1fr; min-height: 230px; }
.ct-preview { background: #111718; color: #d8e0df; padding: 12px; position: relative; display: block; text-decoration: none; overflow: hidden; }
.ct-preview > span { font-size: 11px; }
.ct-preview img { display: block; width: 205px; height: 205px; object-fit: cover; margin: 5px auto 0; }
.report-preview { padding: 17px 19px; line-height: 1.75; }
.report-preview h4 { text-align: center; font-size: 15px; margin: 0 0 15px; }
.report-preview p { margin: 9px 0; }

.modal-mask { display: flex; align-items: center; justify-content: center; }
.modal { width: 620px; max-height: 86vh; background: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.2); display: flex; flex-direction: column; }
.modal-wide { width: 820px; }
.modal-body { padding: 19px 20px; overflow: auto; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.form-grid label input, .form-grid label select { width: 100%; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
.form-grid-3 .full { grid-column: 1 / -1; }
.form-section-title { font-size: 14px; font-weight: 600; padding: 4px 0 10px; margin: 2px 0 14px; border-bottom: 1px solid var(--line); }
.form-section-title:not(:first-child) { margin-top: 24px; }
.notice { background: #f7f3ea; border: 1px solid #e1d2b4; padding: 11px 12px; margin-bottom: 16px; color: #5d5141; }
.toast { position: fixed; left: 50%; bottom: 38px; transform: translateX(-50%); z-index: 200; background: #213638; color: #fff; padding: 11px 20px; box-shadow: 0 5px 18px rgba(0,0,0,.18); }

@media (max-width: 1450px) {
  .metric-grid-6 { grid-template-columns: repeat(3, 1fr); }
  .metric-grid-5 { grid-template-columns: repeat(5, minmax(150px, 1fr)); overflow-x: auto; }
  .two-col { grid-template-columns: 1fr; }
}

/* HIS workstation */
.his-body { background: #dfe5e6; min-width: 1280px; overflow: hidden; }
.his-shell { height: 100vh; display: flex; flex-direction: column; }
.his-top { height: 48px; background: #284d51; color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; }
.his-top h1 { font-size: 17px; margin: 0; font-weight: 600; }
.his-top-meta { display: flex; gap: 22px; font-size: 12px; color: #d5e1e1; }
.patient-band { height: 54px; background: #fff; border-bottom: 1px solid #cbd3d4; display: flex; align-items: center; padding: 0 12px; gap: 20px; font-size: 12px; }
.patient-band strong { font-size: 16px; }
.patient-band span { white-space: nowrap; }
.patient-band .allergy { color: var(--danger); }
.his-main { flex: 1; min-height: 0; display: grid; grid-template-columns: 210px 1fr 285px; }
.queue, .order-set { background: #fff; min-width: 0; display: flex; flex-direction: column; }
.queue { border-right: 1px solid #cbd3d4; }
.order-set { border-left: 1px solid #cbd3d4; }
.his-section-title { height: 40px; display: flex; align-items: center; justify-content: space-between; padding: 0 11px; border-bottom: 1px solid var(--line); font-weight: 600; }
.queue-filter { padding: 8px; border-bottom: 1px solid var(--line); }
.queue-filter input { width: 100%; min-width: 0; }
.queue-stats { display: grid; grid-template-columns: repeat(3,1fr); border-bottom: 1px solid var(--line); }
.queue-stats div { text-align: center; padding: 8px 2px; border-right: 1px solid var(--line-soft); }
.queue-stats div:last-child { border-right: 0; }
.queue-stats b { display: block; color: var(--accent-dark); }
.patient-list { padding: 6px; overflow: auto; }
.patient-row { padding: 9px 8px; border-bottom: 1px solid var(--line-soft); font-size: 12px; }
.patient-row.active { background: var(--accent-soft); border-left: 3px solid var(--accent); }
.patient-row strong { display: block; font-size: 13px; margin-bottom: 4px; }
.clinical-work { display: flex; flex-direction: column; min-width: 0; background: #eef1f2; }
.clinical-tabs { height: 42px; background: #fff; border-bottom: 1px solid var(--line); display: flex; padding-left: 8px; }
.clinical-tabs button { border: 0; background: transparent; padding: 0 17px; border-bottom: 2px solid transparent; }
.clinical-tabs button.active { color: var(--accent-dark); border-bottom-color: var(--accent); font-weight: 600; }
.clinical-toolbar { height: 42px; background: #fff; border-bottom: 1px solid var(--line); padding: 4px 10px; display: flex; align-items: center; gap: 7px; }
.record-stage { flex: 1; overflow: auto; padding: 18px; }
.record-paper { max-width: 900px; min-height: 610px; margin: 0 auto; background: #fff; border: 1px solid #cfd7d8; padding: 28px 38px; }
.record-paper h2 { text-align: center; margin: 0 0 17px; font-size: 20px; }
.record-meta { display: grid; grid-template-columns: repeat(5, 1fr); border-bottom: 2px solid #536064; padding-bottom: 9px; margin-bottom: 18px; font-size: 12px; }
.record-line { display: grid; grid-template-columns: 88px 1fr; min-height: 45px; padding: 9px 0; border-bottom: 1px solid var(--line-soft); line-height: 1.65; }
.record-line label { font-weight: 600; color: var(--text); }
.record-line textarea { border: 0; padding: 0; resize: none; }
.order-set-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); }
.order-set-tabs button { height: 38px; background: #fff; border: 0; border-bottom: 2px solid transparent; }
.order-set-tabs button.active { border-bottom-color: var(--accent); color: var(--accent-dark); }
.order-set-search { padding: 8px; border-bottom: 1px solid var(--line); }
.order-set-search input { width: 100%; min-width: 0; }
.order-tree { padding: 9px; font-size: 12px; overflow: auto; }
.order-tree h3 { font-size: 13px; margin: 12px 0 7px; }
.order-tree button { display: block; width: 100%; background: #fff; border: 0; border-bottom: 1px solid var(--line-soft); text-align: left; padding: 9px 6px; }
.order-tree button:hover { background: #f4f7f6; color: var(--accent-dark); }
.his-status { height: 28px; background: #fff; border-top: 1px solid var(--line); padding: 6px 12px; color: var(--muted); font-size: 11px; display: flex; justify-content: space-between; }
.his-dialog { width: 720px; }
.duplicate-box { background: #f7f3ea; border: 1px solid #dfcda6; padding: 13px; margin-bottom: 15px; }
.duplicate-box h3 { margin: 0 0 5px; color: var(--warning); font-size: 15px; }
.duplicate-box p { margin: 0; line-height: 1.6; }
.study-list { border: 1px solid var(--line); }
.study-row { display: grid; grid-template-columns: 120px 100px 1fr 170px 90px; align-items: center; padding: 11px 12px; border-bottom: 1px solid var(--line-soft); }
.study-row:last-child { border-bottom: 0; }
.auth-layout { display: grid; grid-template-columns: 1fr 230px; gap: 20px; }
.auth-info { border: 1px solid var(--line); }
.auth-info dl { display: grid; grid-template-columns: 95px 1fr; margin: 0; }
.auth-info dt, .auth-info dd { margin: 0; padding: 10px; border-bottom: 1px solid var(--line-soft); }
.auth-info dt { background: #f6f8f8; color: var(--muted); }
.auth-code { border: 1px solid var(--line); padding: 17px; text-align: center; }
.auth-code strong { display: block; font-size: 30px; letter-spacing: 6px; margin: 18px 0; }
.auth-code p { color: var(--muted); font-size: 12px; line-height: 1.7; }
.viewer-mask { position: fixed; inset: 0; z-index: 300; background: #111; color: #d8dfdf; display: flex; flex-direction: column; }
.viewer-top { height: 50px; background: #1d292b; display: flex; align-items: center; justify-content: space-between; padding: 0 15px; border-bottom: 1px solid #3b4648; }
.viewer-top h2 { font-size: 15px; margin: 0; }
.viewer-tools { display: flex; gap: 6px; }
.viewer-tools button { background: #263638; color: #dce3e3; border: 1px solid #4a5759; padding: 7px 11px; }
.viewer-tools button.active { border-color: #93c5c2; color: #fff; }
.viewer-main { flex: 1; min-height: 0; display: grid; grid-template-columns: 190px 1fr 330px; }
.series-list { background: #182022; border-right: 1px solid #3a4446; padding: 10px; overflow: auto; }
.series-item { border: 1px solid #3e494b; padding: 9px; margin-bottom: 8px; font-size: 12px; }
.series-item.active { border-color: #9ac7c4; }
.series-thumb { height: 95px; background: #090b0c; margin-bottom: 7px; position: relative; overflow: hidden; }
.series-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; filter: contrast(1.03); }
.image-stage { display: flex; gap: 3px; align-items: stretch; justify-content: center; background: #060809; overflow: hidden; }
.dicom-view { flex: 1; min-width: 0; position: relative; display: flex; align-items: center; justify-content: center; }
.dicom-view.compare-view { display: none; border-left: 1px solid #555; }
.image-stage.comparing .compare-view { display: flex; }
.ct-large { display: block; width: min(62vh, 620px); aspect-ratio: 1; object-fit: contain; transform: scale(1); transition: transform .15s; }
.ct-large.alt { filter: contrast(1.18) brightness(.92); transform: rotate(2deg); }
.dicom-label { position: absolute; left: 12px; top: 12px; font-size: 11px; line-height: 1.55; z-index: 2; }
.measure-line { position: absolute; width: 150px; height: 1px; background: #e2d462; transform: rotate(-23deg); left: 49%; top: 43%; z-index: 3; display: none; }
.measure-line::after { content: "32.6 mm"; position: absolute; color: #e2d462; top: 6px; left: 45px; font-size: 11px; }
.report-side { background: #f5f6f6; color: var(--text); border-left: 1px solid #465052; padding: 18px; overflow: auto; }
.report-side h3 { text-align: center; margin-top: 0; }
.report-side dl { display: grid; grid-template-columns: 85px 1fr; margin: 0; font-size: 12px; }
.report-side dt, .report-side dd { margin: 0; padding: 8px 5px; border-bottom: 1px solid var(--line); }
.report-side p { line-height: 1.8; }
.viewer-external { color: #eef7f6; text-decoration: none; border: 1px solid #5b696b; padding: 7px 11px; }
.viewer-external:hover { border-color: #9ac7c4; text-decoration: underline; }

/* login */
.login-body { min-height: 100vh; background: #e9edef; display: flex; align-items: center; justify-content: center; }
.login-shell { width: 850px; min-height: 470px; background: #fff; border: 1px solid #cfd7d9; display: grid; grid-template-columns: 350px 1fr; }
.login-intro { background: var(--nav); color: #fff; padding: 66px 44px; }
.login-panel { padding: 66px 64px; display: flex; flex-direction: column; justify-content: center; }
.login-panel h2 { margin: 0 0 30px; font-size: 22px; font-weight: 600; }
.login-form { display: grid; gap: 19px; }
.login-form > label { font-size: 13px; color: var(--text); }
.login-form > label input { width: 100%; height: 42px; margin-top: 8px; }
.login-submit { width: 100%; height: 42px; margin-top: 3px; }
.login-error { color: var(--danger); font-size: 12px; margin-top: -9px; }
.login-options { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 12px; }
.login-options .remember { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.login-options .remember input { width: 14px; height: 14px; min-width: 14px; margin: 0; }
.login-options a { color: var(--muted); text-decoration: none; }
.login-options a:hover { color: var(--accent-dark); text-decoration: underline; }

@media (max-width: 1500px) {
  .his-main { grid-template-columns: 190px 1fr 240px; }
  .record-paper { padding: 23px; }
}
