/* Cancer Manager Clinical UI v1.1.0
   Major visual rebuild focused on readability, calmer hierarchy and mature desktop ergonomics.
   Business logic, database schema and medical parsing are untouched. */

:root{
  --sidebar-width:252px;
  --sidebar-collapsed-width:72px;
  --topbar-height:78px;
  --app-bg:#f5f7fa;
  --surface:#ffffff;
  --surface-soft:#f8fafc;
  --surface-muted:#f2f5f8;
  --line:#e4e9f0;
  --line-strong:#d6dde7;
  --text-strong:#182230;
  --text:#344054;
  --text-soft:#667085;
  --text-faint:#98a2b3;
  --brand:#2f6fed;
  --brand-strong:#245bd1;
  --brand-soft:#eef4ff;
  --brand-soft-2:#f6f9ff;
  --success:#177a55;
  --success-soft:#ecfdf3;
  --warning:#a15c12;
  --warning-soft:#fff7e8;
  --danger:#b63a32;
  --danger-soft:#fff1f0;
  --shadow-xs:0 1px 2px rgba(16,24,40,.035);
  --shadow-sm:0 4px 12px rgba(16,24,40,.045);
  --shadow-md:0 14px 36px rgba(16,24,40,.10);
  --radius-sm:8px;
  --radius:12px;
  --radius-lg:16px;
}

html{background:var(--app-bg);scroll-behavior:smooth}
body{
  background:var(--app-bg);
  color:var(--text);
  font-family:"Microsoft YaHei UI","Microsoft YaHei","PingFang SC","Noto Sans CJK SC",system-ui,-apple-system,"Segoe UI",sans-serif;
  font-size:14px;
  line-height:1.62;
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
}

/* ---------- Layout ---------- */
.sidebar{
  width:var(--sidebar-width);
  padding:18px 14px 14px;
  background:#fff;
  border-right:1px solid var(--line);
  box-shadow:none;
  color:var(--text);
}
.sidebar-header{min-height:48px;gap:10px;padding:0 3px}
.brand{gap:11px;padding:0;align-items:center}
.brand-mark{
  width:38px;height:38px;flex:0 0 38px;border-radius:11px;
  color:#fff;background:linear-gradient(145deg,#3f7cf0,#2f64d8);
  box-shadow:0 5px 14px rgba(47,111,237,.20);font-size:12px;letter-spacing:.02em;
}
.brand-title{font-size:14px;font-weight:800;color:#182230;letter-spacing:.01em}
.brand-subtitle{font-size:10.5px;color:#98a2b3;margin-top:1px;letter-spacing:0}
.sidebar-collapse-btn{
  width:30px;height:30px;flex:0 0 30px;border:1px solid var(--line);background:#fff;color:#667085;
  border-radius:9px;font-size:18px;box-shadow:var(--shadow-xs);
}
.sidebar-collapse-btn:hover{background:#f7f9fc;color:#344054;border-color:#cfd7e3}

.sidebar-patient{
  margin:15px 0 18px;padding:11px 12px;min-height:62px;border:1px solid #e2e9f3;
  background:#f8fbff;border-radius:12px;gap:10px;
}
.sidebar-patient-avatar{
  width:32px;height:32px;flex:0 0 32px;border-radius:10px;background:#e8f0ff;color:#285ec7;font-size:12px;
}
.sidebar-patient-copy strong{color:#182230;font-size:12.5px;font-weight:800}
.sidebar-patient-copy span{color:#718096;font-size:10.5px;margin-top:2px;line-height:1.4}

.nav{padding:0 0 12px;margin:0;scrollbar-width:thin;scrollbar-color:#d7dee8 transparent}
.nav-section{margin:0 0 15px}
.nav-section-title{padding:4px 11px 6px;color:#a0a8b5;font-size:10px;font-weight:800;letter-spacing:.08em;text-transform:none}
.nav-item{
  min-height:42px;padding:8px 10px;margin:2px 0;border-radius:10px;gap:10px;
  color:#4d5a6c;background:transparent;font-size:13px;font-weight:600;
}
.nav-item:hover{background:#f6f8fb;color:#182230}
.nav-item.active{background:#edf4ff;color:#245bc5;font-weight:800;box-shadow:none}
.nav-icon{
  width:26px;height:26px;flex:0 0 26px;border-radius:8px;background:transparent;color:#7a8798;
  display:grid;place-items:center;font-size:0;
}
.nav-icon svg{width:18px;height:18px;stroke:currentColor;stroke-width:1.8;fill:none;stroke-linecap:round;stroke-linejoin:round}
.nav-item.active .nav-icon{background:#dce9ff;color:#2f6fed}
.nav-item:hover .nav-icon{color:#475467}
.nav-label{font-size:13.2px}

.sidebar-footer{border-top:1px solid #eef1f5;padding:12px 9px 2px;font-size:10.5px}
.sidebar-footer-row{color:#98a2b3;margin:4px 0}
.sidebar-footer-row strong{color:#667085;font-weight:700}
.production-badge{margin-top:9px;background:#f2f8f5;color:#4e7b68;border:1px solid #dfeee6;padding:5px 7px}

.main{
  margin-left:var(--sidebar-width);width:calc(100% - var(--sidebar-width));padding:0 34px 56px;
}
.main>.view,.main>#loading,.main>#errorBox{max-width:1640px;margin-left:auto;margin-right:auto}
.topbar{
  min-height:var(--topbar-height);margin:0 -34px 26px;padding:12px 34px;
  background:rgba(255,255,255,.94);backdrop-filter:blur(14px);border-bottom:1px solid #e7ebf1;
  box-shadow:0 1px 0 rgba(16,24,40,.015);
}
.topbar-leading{gap:12px}
.page-context{font-size:11px;color:#98a2b3;margin-bottom:1px}
.topbar h1{font-size:22px;line-height:1.25;color:#182230;font-weight:800;letter-spacing:-.01em}
.topbar p{font-size:12.5px;color:#667085;margin-top:3px;max-width:760px}
.top-actions{gap:8px}
.refresh-meta{margin-right:5px}
.refresh-meta span{font-size:9.5px;color:#a4acb8}
.refresh-meta strong{font-size:11px;color:#667085}

.global-search-trigger{
  min-width:220px;height:40px;padding:0 10px 0 12px;border:1px solid #dce3ec;border-radius:10px;
  background:#f8fafc;color:#667085;display:flex;align-items:center;gap:8px;cursor:pointer;text-align:left;
  box-shadow:inset 0 1px 0 rgba(255,255,255,.8);
}
.global-search-trigger:hover{background:#fff;border-color:#cbd5e1;color:#344054}
.global-search-trigger .search-icon{width:17px;height:17px;color:#8792a2;flex:0 0 17px}
.global-search-trigger .search-copy{flex:1;font-size:12.5px;white-space:nowrap}
.global-search-trigger .kbd{margin-left:auto}

.density-toggle{min-width:72px;padding-inline:10px}
.density-toggle .density-dot{width:7px;height:7px;border-radius:50%;background:#69a2ff;display:inline-block;margin-right:6px}

/* ---------- Core components ---------- */
.button{
  min-height:39px;padding:8px 13px;border-radius:10px;font-size:13px;font-weight:650;box-shadow:none;
  transition:background .12s,border-color .12s,color .12s,box-shadow .12s;
}
.button:hover{transform:none;filter:none}
.button.primary{background:#2f6fed;border-color:#2f6fed;box-shadow:0 2px 6px rgba(47,111,237,.16)}
.button.primary:hover{background:#285fd2;border-color:#285fd2}
.button.secondary{background:#fff;border-color:#d8e0ea;color:#344054}
.button.secondary:hover{background:#f8fafc;border-color:#c9d2de}
.button.ghost{background:transparent;border-color:transparent;color:#667085}
.button.ghost:hover{background:#f4f6f9;color:#344054}
.button.danger{background:#fff;color:#b43b34;border-color:#f0c7c3}
.button.danger:hover{background:#fff6f5;border-color:#e7aaa5}
.button.small{min-height:32px;padding:5px 10px;font-size:12px;border-radius:8px}
.icon-button{width:38px;height:38px;border-radius:10px;border-color:#dce3eb;background:#fff;color:#5f6b7a}
.icon-button:hover{background:#f8fafc;border-color:#cbd5e1}
.kbd{font-size:9px;background:#fff;border-color:#d7dee8;color:#7c8796;padding:1px 5px}

.input,textarea.input,select.input{
  min-height:41px;border-radius:10px;border:1px solid #dbe2eb;background:#fff;font-size:13.5px;color:#344054;
  padding-left:11px;padding-right:11px;
}
.input:focus,textarea.input:focus,select.input:focus{border-color:#8bb0ff;box-shadow:0 0 0 3px rgba(47,111,237,.095)}
label>span:not(.badge){font-size:12.5px;color:#667085;font-weight:600;margin-bottom:5px;display:block}
textarea.input{line-height:1.6}

.panel{
  border:1px solid #e5eaf0;border-radius:14px;padding:20px 22px;margin-bottom:18px;background:#fff;
  box-shadow:0 2px 7px rgba(16,24,40,.025);
}
.panel-head{margin-bottom:16px;gap:14px;align-items:flex-start}
.panel-head h2{font-size:17px;color:#182230;font-weight:800;letter-spacing:-.005em}
.panel-head .muted{font-size:12.5px;line-height:1.55;color:#7a8696}
.grid-2{gap:18px}

.patient-hero{
  background:#fff;border:1px solid #e3e9f1;border-radius:16px;padding:20px 22px;margin-bottom:16px;
  box-shadow:0 3px 10px rgba(16,24,40,.025);position:relative;overflow:hidden;
}
.patient-hero:before{content:"";position:absolute;left:0;top:0;bottom:0;width:4px;background:#4b7ff0}
.patient-name{font-size:25px;color:#182230;font-weight:800;letter-spacing:-.01em}
.patient-diagnosis{color:#4f5d70;margin-top:4px;font-size:13.5px}
.patient-meta{color:#7a8696;margin-top:11px;font-size:12.5px}
.patient-hero .badge.primary{background:#edf4ff;color:#285fc9;border:1px solid #d7e5ff}

.summary-grid{gap:12px;margin-bottom:18px}
.summary-card{padding:15px 16px;border:1px solid #e8ecf2;border-radius:12px;background:#fff;box-shadow:none}
.summary-label{font-size:11px;color:#8c97a7;margin-bottom:6px;font-weight:700}
.summary-value{font-size:16px;color:#283548;line-height:1.35;font-weight:750}

.record{border:1px solid #e7ebf1;border-radius:12px;padding:16px 17px;margin-bottom:10px;background:#fff;box-shadow:none}
.record:hover{border-color:#d9e0e9;background:#fdfefe}
.record-title{margin-bottom:10px;gap:12px}
.record-title h3{font-size:15px;color:#182230;font-weight:800}
.record-date{color:#7e8998;font-size:11.5px}
.record-body{font-size:13.5px;line-height:1.72;color:#425066}
.kv-grid{gap:2px 22px}
.kv{grid-template-columns:138px minmax(0,1fr);padding:8px 0;font-size:13px;border-bottom:1px solid #f1f3f6}
.kv:last-child{border-bottom:0}
.kv>div:first-child{color:#7b8695}

.note,.trend-hint,.followup-note,.report-note{
  font-size:12.5px;line-height:1.65;border:0;background:#f7f9fc;color:#657185;border-radius:10px;padding:10px 12px;
}
.empty{padding:34px 18px;font-size:13px;color:#8a94a3;background:#fbfcfd;border:1px dashed #dbe1e9;border-radius:11px}
.muted{color:#7d8897}

.badge{font-size:11px;padding:3px 8px;border-radius:999px;font-weight:750}
.abnormal{color:#b13932!important;font-weight:750}

/* ---------- Home / dashboard ---------- */
.home-dashboard-grid{gap:12px;grid-template-columns:repeat(auto-fit,minmax(230px,1fr))}
.home-metric-card{
  min-height:116px;padding:14px 15px;border:1px solid #e6eaf0;border-radius:12px;background:#fff;box-shadow:none;
}
.home-metric-card:hover{border-color:#cfd8e5;box-shadow:0 6px 18px rgba(16,24,40,.05)}
.home-metric-value{font-size:24px;line-height:1.15;color:#1f2c3d;font-weight:800;letter-spacing:-.02em}
.home-kpi{border:1px solid #e8ecf1;border-radius:12px;padding:13px 14px;background:#fff}
.home-kpi-value{font-size:21px;color:#253347;font-weight:800}
.dashboard-alert-chip{font-size:11px;padding:4px 9px}
.dashboard-alert-row{border-color:#e6ebf1;border-radius:10px;padding:11px 13px}
.dashboard-alert-row.high{border-left:3px solid #d95a52}
.dashboard-alert-row.medium{border-left:3px solid #d59a42}
.dashboard-alert-row.info{border-left:3px solid #5b8ee8}
.dashboard-editor{border-color:#e3e9f1;background:#f8fafc;border-radius:12px;padding:16px}

/* ---------- Tables ---------- */
.filter-grid,
.trend-toolbar,.cycle-compare-toolbar,.imaging-toolbar,.imaging-compare-toolbar,.dictionary-toolbar,.quality-toolbar,.followup-settings{
  background:#f8fafc;border:1px solid #e8edf3;border-radius:12px;padding:12px;gap:10px;
}
.lab-filter-grid{grid-template-columns:minmax(260px,2fr) minmax(160px,1fr) minmax(140px,1fr) minmax(145px,1fr) minmax(145px,1fr) auto}
.document-filter-grid{grid-template-columns:minmax(260px,2fr) minmax(170px,1fr) minmax(155px,1fr) minmax(145px,1fr) minmax(145px,1fr) auto}
.table-wrap{border:1px solid #e4e9ef;border-radius:12px;max-height:72vh;background:#fff;box-shadow:none}
table{min-width:800px;border-collapse:separate;border-spacing:0}
th,td{padding:11px 12px;font-size:13px;line-height:1.45;border-bottom:1px solid #eef1f4}
th{background:#f8fafc;color:#667085;font-size:11.5px;font-weight:800;letter-spacing:.01em}
tbody tr:last-child td{border-bottom:0}
tbody tr:hover td{background:#fafcff}
td strong{color:#283548;font-weight:750}
.table-pager{padding:12px 2px 0}
.table-pager-info,.table-page-current{font-size:11.5px}

/* Compact row action dropdown — avoids 3-5 buttons fighting for horizontal space */
.row-menu{position:relative;display:inline-block}
.row-menu>summary{
  list-style:none;cursor:pointer;min-width:64px;height:32px;padding:0 10px;border:1px solid #d8e0e9;border-radius:8px;
  background:#fff;color:#4d5968;font-size:12px;font-weight:700;display:inline-flex;align-items:center;justify-content:center;gap:5px;
}
.row-menu>summary::-webkit-details-marker{display:none}
.row-menu>summary:after{content:"⌄";font-size:11px;color:#8993a1;margin-top:-2px}
.row-menu[open]>summary{border-color:#a9bce3;background:#f7faff;color:#285fc9}
.row-menu-popover{
  position:absolute;right:0;top:38px;z-index:30;min-width:148px;padding:6px;background:#fff;border:1px solid #dfe5ed;
  border-radius:10px;box-shadow:0 14px 34px rgba(16,24,40,.14);display:flex;flex-direction:column;gap:2px;
}
.row-menu-popover .button,.row-menu-popover a.button{
  width:100%;min-height:34px;border:0!important;background:transparent!important;color:#344054!important;
  justify-content:flex-start;text-align:left;border-radius:7px;padding:7px 9px;box-shadow:none!important;
}
.row-menu-popover .button:hover,.row-menu-popover a.button:hover{background:#f4f7fb!important;color:#245bc5!important}
.row-menu-popover .button.danger{color:#b43b34!important}
.row-menu-popover .button.danger:hover{background:#fff3f2!important;color:#a83029!important}
.document-actions{min-width:auto;white-space:nowrap}
.row-actions{gap:6px}

/* ---------- Trend / comparison ---------- */
.trend-preset-row{gap:7px;margin-bottom:12px}
.trend-options-line{gap:14px;margin:11px 0}
.trend-stat-card,.cycle-summary-chip,.imaging-compare-card,.quality-card,.dictionary-kpi,.followup-kpi,.followup-snapshot{
  box-shadow:none;border-color:#e4e9ef;background:#fff;
}
.trend-chart-wrap{border:1px solid #e5eaf0;border-radius:12px;background:#fff;padding:8px}
.help-details{border:0;background:#f7f9fc;border-radius:10px;font-size:12px}
.help-details summary{padding:9px 11px;color:#667085}
.help-details>div{padding:0 11px 10px;line-height:1.65}

/* ---------- Timeline / course ---------- */
.timeline{padding-left:2px}
.timeline-item,.course-card{border-color:#e6eaf0;box-shadow:none}
.course-card{border-radius:12px;background:#fff}
.course-node{box-shadow:0 0 0 4px #f4f7fb}
.course-kpi-grid{gap:10px}

/* ---------- Follow-up: calmer matrix and cards ---------- */
.followup-kpi-grid{gap:12px}
.followup-kpi{border-color:#e5eaf0;border-radius:12px;padding:15px 16px}
.followup-kpi strong{font-size:22px;color:#283548}
.followup-kpi span{font-size:12px;color:#7b8695}
.followup-calendar-grid{border-color:#e6eaf0;background:#e6eaf0;border-radius:12px}
.followup-weekday{background:#f8fafc;color:#7b8695;font-size:11.5px;padding:9px}
.followup-day{min-height:116px;padding:8px;background:#fff}
.followup-day.outside{background:#fbfcfd;color:#a5adb8}
.followup-event{font-size:10.5px;padding:3px 6px;border-radius:6px}
.followup-event.lab{background:#edf4ff;color:#315fbd}
.followup-event.imaging{background:#edf9f4;color:#26765a}
.followup-event.treatment{background:#fff6e9;color:#966022}
.followup-event.document{background:#f4f1ff;color:#6651a3}
.followup-alert{border-color:#e6eaf0;border-radius:10px;padding:11px 13px}
.followup-alert.high{border-left:3px solid #d85c53}
.followup-alert.medium{border-left:3px solid #d7a04b}
.followup-alert.info{border-left:3px solid #628ee2}
.followup-snapshot{border-radius:12px;padding:14px;background:#fff}
.followup-chip{background:#f8fafc;border-color:#e6eaf0;color:#647083}
.followup-metric{border-color:#e8ecf1;padding:7px 8px}
.followup-missing,.followup-missing-soft{color:#8b96a5!important;background:#fbfcfd!important;border-color:#e3e8ee!important}
.followup-fix-note{border:0;background:#f3f7ff;color:#4d6c9d;border-radius:10px}
.stage-matrix-wrap{border-color:#e3e8ef;border-radius:12px;box-shadow:none}
.stage-matrix th{background:#f8fafc;color:#667085;font-size:11.5px;padding:10px 9px;border-bottom-color:#e8ecf1}
.stage-matrix td{font-size:12.5px;padding:10px 9px;border-bottom-color:#f0f2f5;border-right-color:#f3f4f6}
.stage-matrix-stage{background:#fbfcfd;min-width:142px}
.stage-matrix-value{background:#fff}
.stage-matrix-value:hover{background:#f7faff}
.stage-matrix-value strong{font-size:13.5px;color:#283548}
.stage-matrix-missing{background:#fbfcfd;color:#98a2b3}
.stage-matrix-missing:hover{background:#f7f8fa}

/* ---------- Imaging / quality / report ---------- */
.imaging-compare-card,.quality-card,.dictionary-kpi{border-radius:12px}
.report-sheet{border-color:#e2e7ee;box-shadow:none;border-radius:14px}
.report-section{border-color:#e9edf2}
.report-table th{background:#f8fafc}

/* ---------- Command palette ---------- */
.command-palette-backdrop{background:rgba(31,41,55,.30);backdrop-filter:blur(3px)}
.command-palette-card{border-color:#dfe5ed;border-radius:16px;box-shadow:0 28px 72px rgba(16,24,40,.22)}
.command-palette-input{font-size:14px;border-radius:11px}
.command-item{border-radius:9px;padding:10px 11px}
.command-item:hover,.command-item.active{background:#f0f5ff;color:#285fc9}
.command-item-icon{background:#f3f6fa;color:#6d7888}
.command-palette-foot{background:#fafbfc}

.quick-action-menu{width:205px;border-color:#dfe5ed;border-radius:12px;box-shadow:0 16px 38px rgba(16,24,40,.14);padding:7px}
.quick-action-menu button,.quick-action-menu a{padding:10px 11px;border-radius:8px;font-size:12.5px}
.quick-action-menu button:hover,.quick-action-menu a:hover{background:#f4f7fb;color:#245bc5}

.back-to-top{right:24px;bottom:22px;width:40px;height:40px;border-radius:11px;box-shadow:0 8px 22px rgba(16,24,40,.10)}

/* ---------- Comfortable / compact density ---------- */
body.ui-compact{font-size:13px}
body.ui-compact .panel{padding:15px 17px;margin-bottom:13px}
body.ui-compact .panel-head{margin-bottom:11px}
body.ui-compact .record{padding:12px 13px;margin-bottom:7px}
body.ui-compact .kv{padding:6px 0;font-size:12px}
body.ui-compact th,body.ui-compact td{padding:7px 9px;font-size:11.8px}
body.ui-compact .input,body.ui-compact textarea.input,body.ui-compact select.input{min-height:36px;font-size:12.5px}
body.ui-compact .button{min-height:34px;font-size:12px;padding:6px 10px}
body.ui-compact .button.small{min-height:29px;font-size:11px}
body.ui-compact .nav-item{min-height:37px;padding:6px 9px}
body.ui-compact .home-metric-card{min-height:100px;padding:11px 12px}
body.ui-compact .summary-card{padding:11px 12px}

/* ---------- Collapsed sidebar ---------- */
body.sidebar-collapsed .sidebar{width:var(--sidebar-collapsed-width);padding-left:10px;padding-right:10px}
body.sidebar-collapsed .main{margin-left:var(--sidebar-collapsed-width);width:calc(100% - var(--sidebar-collapsed-width))}
body.sidebar-collapsed .sidebar-header{flex-direction:column;gap:8px}
body.sidebar-collapsed .nav-item{padding-left:7px;padding-right:7px}
body.sidebar-collapsed .nav-icon{width:32px;height:32px;flex-basis:32px}
body.sidebar-collapsed .nav-item.active .nav-icon{background:#e5efff}

/* ---------- Responsive ---------- */
@media(max-width:1320px){
  .main{padding-left:24px;padding-right:24px}.topbar{margin-left:-24px;margin-right:-24px;padding-left:24px;padding-right:24px}
  .global-search-trigger{min-width:185px}.refresh-meta{display:none}
}
@media(max-width:1120px){
  .global-search-trigger{min-width:48px;width:48px;padding:0;justify-content:center}.global-search-trigger .search-copy,.global-search-trigger .kbd{display:none}
  .density-toggle{display:none}
  .lab-filter-grid,.document-filter-grid{grid-template-columns:1fr 1fr 1fr}
}
@media(max-width:960px){
  .sidebar{width:272px;box-shadow:18px 0 45px rgba(16,24,40,.12)}
  .main{margin-left:0;width:100%;padding:0 18px 42px}.topbar{margin:0 -18px 20px;padding:11px 18px}
  .mobile-nav-btn{display:inline-grid}.page-context{display:none}.topbar h1{font-size:20px}.topbar p{max-width:420px}
  .sidebar-backdrop{background:rgba(31,41,55,.26)}
}
@media(max-width:720px){
  .main{padding-left:12px;padding-right:12px}.topbar{margin-left:-12px;margin-right:-12px;padding-left:12px;padding-right:12px}
  .topbar p{display:none}.top-actions{gap:5px}.quick-action-wrap>.button{padding-inline:10px}.global-search-trigger{display:none}
  .panel{padding:16px 15px;border-radius:12px}.patient-hero{padding:17px 16px}.patient-name{font-size:22px}
  .grid-2{gap:12px}.lab-filter-grid,.document-filter-grid{grid-template-columns:1fr}.table-wrap{max-height:none}
  .home-dashboard-grid{grid-template-columns:1fr 1fr}.summary-grid{grid-template-columns:1fr 1fr}
}
@media(max-width:520px){.home-dashboard-grid,.summary-grid{grid-template-columns:1fr}.topbar h1{font-size:18px}.quick-action-wrap>.button{font-size:0;min-width:38px}.quick-action-wrap>.button:before{content:"＋";font-size:18px}}
.global-search-trigger .search-icon{fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
.table-wrap .row-menu-popover{top:auto;bottom:38px}
.record .row-menu-popover{top:38px;bottom:auto}
