:root {
  --brand: #1668dc;
  --brand-deep: #0d47a1;
  --brand-soft: #eaf2ff;
  --cyan: #0891b2;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --ink: #172b4d;
  --ink-2: #42526e;
  --muted: #7b8aa3;
  --line: #e6ebf2;
  --bg: #f4f7fb;
  --card: #ffffff;
  --shadow: 0 1px 2px rgba(22, 45, 80, .04), 0 8px 24px rgba(22, 45, 80, .06);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#app, .app-shell { min-height: 100vh; }

/* ---------- shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 252px; flex: 0 0 252px; background: linear-gradient(180deg, #0b3b78 0%, #0a2f61 58%, #082751 100%);
  color: #d7e6fb; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 22px 18px 20px; border-bottom: 1px solid rgba(255,255,255,.09); }
.brand-mark { width: 38px; height: 38px; flex: 0 0 38px; border-radius: 11px; background: linear-gradient(145deg, #3b9dff, #1466d8); display: grid; place-items: center; box-shadow: 0 6px 16px rgba(0,0,0,.2); }
.brand-mark svg { width: 22px; height: 22px; stroke: #fff; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 15px; color: #fff; letter-spacing: .3px; white-space: nowrap; }
.brand-text span { font-size: 10.5px; color: #9fc2ee; white-space: nowrap; }
.side-nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.nav-label { padding: 14px 12px 7px; color: #7ea6d8; font-size: 11px; letter-spacing: 1.4px; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 10px 12px; margin: 2px 0; border-radius: 9px; color: #c9dcf5; font-size: 13.5px; transition: .18s; position: relative; }
.nav-item svg { width: 18px; height: 18px; opacity: .9; }
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: linear-gradient(90deg, rgba(59,157,255,.32), rgba(59,157,255,.12)); color: #fff; font-weight: 600; }
.nav-item.active::before { content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px; border-radius: 3px; background: #59b0ff; }
.sidebar-foot { padding: 14px 18px 18px; border-top: 1px solid rgba(255,255,255,.09); font-size: 11px; color: #8fb1da; }
.side-status { display: flex; align-items: center; gap: 7px; margin-bottom: 5px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #38d39f; box-shadow: 0 0 0 3px rgba(56,211,159,.15); }
.side-version { color: #6e94c3; }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 78px; flex: 0 0 78px; background: rgba(255,255,255,.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 30px; position: sticky; top: 0; z-index: 20; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.crumb { font-size: 11px; color: var(--muted); }
.topbar h1 { margin: 1px 0 0; font-size: 19px; font-weight: 700; letter-spacing: .2px; }
.topbar-right { display: flex; align-items: center; gap: 20px; }
.top-date { font-size: 12px; color: var(--muted); }
.identity { display: flex; align-items: center; gap: 9px; position: relative; padding: 6px 10px 6px 6px; border: 1px solid var(--line); border-radius: 40px; background: #fff; cursor: pointer; }
.identity:hover { border-color: #bcd5f5; box-shadow: 0 3px 12px rgba(22,104,220,.08); }
.avatar { width: 32px; height: 32px; flex: 0 0 32px; border-radius: 50%; background: linear-gradient(145deg, #e3efff, #cfe1ff); color: var(--brand-deep); display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.identity-text { display: flex; flex-direction: column; line-height: 1.3; }
.identity-text strong { font-size: 12.5px; }
.identity-text span { font-size: 10.5px; color: var(--muted); }
.identity-arrow { width: 14px; height: 14px; color: var(--muted); }
#userSwitch { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.icon-btn { border: 0; background: transparent; color: var(--ink-2); width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; }
.icon-btn:hover { background: var(--brand-soft); color: var(--brand); }
.mobile-menu { display: none; }
.view { padding: 24px 30px 46px; max-width: 1680px; width: 100%; margin: 0 auto; }

/* ---------- generic ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 20px; letter-spacing: .2px; }
.page-head p { margin: 5px 0 0; color: var(--muted); font-size: 12.5px; }
.page-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 15px; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink-2); font-size: 12.5px; font-weight: 600; transition: .16s; white-space: nowrap; }
.btn svg { width: 15px; height: 15px; }
.btn:hover { border-color: #bcd5f5; color: var(--brand); background: #f8fbff; }
.btn-primary { background: linear-gradient(135deg, #2378e8, #1258c4); border-color: transparent; color: #fff; box-shadow: 0 4px 12px rgba(22,104,220,.2); }
.btn-primary:hover { color: #fff; background: linear-gradient(135deg, #3185f2, #1a63d2); }
.btn-danger { color: var(--red); }
.btn-danger:hover { border-color: #f3b6b6; background: #fff5f5; color: #b91c1c; }
.btn-sm { padding: 5px 10px; font-size: 11.5px; border-radius: 7px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 700; }
.card-head .sub { font-size: 11.5px; color: var(--muted); font-weight: 400; margin-left: 8px; }
.card-body { padding: 18px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-7-5 { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }
.grid-8-4 { grid-template-columns: minmax(0, 8fr) minmax(0, 4fr); }
.mb16 { margin-bottom: 16px; }
.mt16 { margin-top: 16px; }

.stat-card { position: relative; overflow: hidden; padding: 17px 18px; }
.stat-card::after { content: ""; position: absolute; right: -20px; top: -28px; width: 96px; height: 96px; border-radius: 50%; background: var(--brand-soft); opacity: .65; }
.stat-card .label { font-size: 12px; color: var(--muted); position: relative; z-index: 1; }
.stat-card .value { font-size: 27px; font-weight: 750; line-height: 1.25; margin-top: 6px; letter-spacing: -.4px; position: relative; z-index: 1; }
.stat-card .value small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.stat-card .foot { font-size: 11.5px; color: var(--muted); margin-top: 5px; position: relative; z-index: 1; }
.stat-card .foot b { font-weight: 700; }
.stat-card.blue::after { background: #e8f1ff; }
.stat-card.green::after { background: #e5f7ee; }
.stat-card.amber::after { background: #fff3df; }
.stat-card.red::after { background: #ffeded; }
.up { color: var(--green); }
.down { color: var(--red); }

.chart { width: 100%; height: 260px; }
.chart-sm { height: 220px; }
.chart-lg { height: 310px; }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; background: #f0f4f9; color: var(--ink-2); white-space: nowrap; }
.tag.blue { background: #e9f2ff; color: #1558b8; }
.tag.green { background: #e7f7ee; color: #127a45; }
.tag.amber { background: #fff2dc; color: #9a5b06; }
.tag.red { background: #fdeaea; color: #b3261e; }
.tag.cyan { background: #e5f6fa; color: #0b7285; }
.tag.slate { background: #eef1f5; color: #52637a; }

.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
.data-table th { text-align: left; padding: 10px 14px; background: #f8fafc; color: var(--ink-2); font-weight: 700; font-size: 11.5px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data-table td { padding: 11px 14px; border-bottom: 1px solid #eef2f7; vertical-align: middle; }
.data-table tbody tr:hover { background: #fafcff; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .num { font-variant-numeric: tabular-nums; font-weight: 600; }
.data-table .ellipsis { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; gap: 4px; }
.link { color: var(--brand); font-weight: 600; cursor: pointer; }
.link:hover { text-decoration: underline; }
.empty { padding: 38px 18px; text-align: center; color: var(--muted); font-size: 13px; }
.empty svg { width: 34px; height: 34px; color: #c9d6e8; margin-bottom: 8px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
input[type=text], input[type=number], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #dbe3ee; border-radius: 8px; background: #fff; outline: none; transition: .16s; font-size: 12.5px;
}
input:focus, select:focus, textarea:focus { border-color: #7db3f5; box-shadow: 0 0 0 3px rgba(22,104,220,.09); }
textarea { resize: vertical; min-height: 80px; line-height: 1.6; }
.filters input, .filters select { min-width: 145px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
.required::after { content: " *"; color: var(--red); }

.tabs { display: flex; gap: 4px; padding: 4px; background: #f2f5f9; border-radius: 10px; width: fit-content; }
.tab { padding: 6px 14px; border-radius: 7px; font-size: 12.5px; color: var(--ink-2); border: 0; background: transparent; font-weight: 600; }
.tab.active { background: #fff; color: var(--brand); box-shadow: 0 1px 4px rgba(22,45,80,.1); }

.patient-strip { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-radius: 12px; background: linear-gradient(100deg, #eff6ff, #f8fbff); border: 1px solid #dbeaff; }
.patient-avatar { width: 46px; height: 46px; border-radius: 12px; background: linear-gradient(145deg, #3b9dff, #1466d8); color: #fff; display: grid; place-items: center; font-size: 18px; font-weight: 700; }
.patient-meta { display: flex; flex-wrap: wrap; gap: 18px; }
.patient-meta div { display: flex; flex-direction: column; }
.patient-meta span { font-size: 10.5px; color: var(--muted); }
.patient-meta strong { font-size: 13px; }

.record { border: 1px solid var(--line); border-radius: 12px; padding: 16px; background: #fff; }
.record + .record { margin-top: 12px; }
.record-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.record-time { font-weight: 700; font-size: 13px; color: var(--brand-deep); }
.record-desc { margin: 10px 0; color: var(--ink-2); font-size: 12.5px; line-height: 1.75; }
.record-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; border-top: 1px dashed var(--line); padding-top: 10px; font-size: 11.5px; color: var(--muted); }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.thumb { width: 92px; height: 68px; border-radius: 8px; border: 1px solid var(--line); object-fit: cover; background: #f5f8fc; cursor: zoom-in; transition: .18s; }
.thumb:hover { border-color: var(--brand); transform: translateY(-2px); box-shadow: 0 6px 16px rgba(22,104,220,.14); }
.thumb-video { display: grid; place-items: center; color: var(--muted); font-size: 11px; }

.tree { font-size: 12.5px; }
.tree-root { padding: 8px 10px; background: #f8fafc; border-radius: 8px; color: var(--ink-2); font-weight: 700; display: flex; gap: 7px; align-items: center; }
.tree-folder { margin: 7px 0 7px 10px; padding-left: 10px; border-left: 1px dashed #d7e1ee; }
.tree-folder-title { display: flex; align-items: center; gap: 7px; cursor: pointer; padding: 5px 4px; font-weight: 600; color: var(--brand-deep); }
.tree-folder-title svg { width: 15px; height: 15px; }
.tree-file { display: flex; align-items: center; gap: 7px; padding: 4px 4px 4px 24px; color: var(--ink-2); font-size: 11.5px; }
.tree-file svg { width: 14px; height: 14px; color: var(--muted); }
.tree-count { margin-left: auto; color: var(--muted); font-size: 10.5px; }

.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ""; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: #dce8f8; }
.timeline-item { position: relative; padding: 0 0 20px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before { content: ""; position: absolute; left: -22px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 2px solid var(--brand); box-shadow: 0 0 0 3px #eaf2ff; }
.timeline-item.done::before { background: var(--brand); }
.timeline-item .t-title { font-weight: 700; font-size: 13px; }
.timeline-item .t-meta { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

.kanban { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.kanban-col { background: #f5f8fc; border: 1px solid var(--line); border-radius: 12px; padding: 12px; min-height: 180px; }
.kanban-col h4 { margin: 0 0 10px; font-size: 12.5px; display: flex; justify-content: space-between; align-items: center; }
.kanban-card { background: #fff; border: 1px solid var(--line); border-radius: 9px; padding: 10px; margin-bottom: 8px; cursor: pointer; box-shadow: 0 2px 8px rgba(22,45,80,.04); }
.kanban-card:hover { border-color: #a9cdf8; }
.kanban-card .k-title { font-size: 12px; font-weight: 700; margin-bottom: 5px; }
.kanban-card .k-meta { font-size: 10.5px; color: var(--muted); }

.alert-item { display: flex; gap: 11px; padding: 11px 0; border-bottom: 1px dashed var(--line); }
.alert-item:last-child { border-bottom: 0; }
.alert-icon { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 9px; display: grid; place-items: center; background: #fff2dc; color: var(--amber); }
.alert-icon.red { background: #fdeaea; color: var(--red); }
.alert-icon.blue { background: #e9f2ff; color: var(--brand); }
.alert-item .a-title { font-size: 12.5px; font-weight: 700; }
.alert-item .a-desc { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.progress { height: 6px; border-radius: 6px; background: #edf2f8; overflow: hidden; margin-top: 7px; }
.progress span { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, #3b9dff, #1668dc); }

.modal-mask { position: fixed; inset: 0; background: rgba(9,27,56,.45); backdrop-filter: blur(3px); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 20px; animation: fade .16s ease; }
.modal { width: 100%; max-width: 620px; max-height: 90vh; background: #fff; border-radius: 16px; box-shadow: 0 24px 70px rgba(8,30,60,.3); display: flex; flex-direction: column; animation: pop .18s ease; }
.modal.wide { max-width: 900px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 13px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 9px; }
#toast-root { position: fixed; top: 88px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { min-width: 240px; background: #fff; border: 1px solid var(--line); border-left: 3px solid var(--brand); border-radius: 9px; box-shadow: 0 10px 30px rgba(15,40,75,.16); padding: 11px 15px; font-size: 12.5px; animation: slide .2s ease; }
.toast.ok { border-left-color: var(--green); }
.toast.warn { border-left-color: var(--amber); }
.toast.err { border-left-color: var(--red); }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: .6 } to { transform: none; opacity: 1 } }
@keyframes slide { from { transform: translateX(20px); opacity: 0 } to { transform: none; opacity: 1 } }

.pill-nav { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { padding: 5px 12px; border-radius: 20px; border: 1px solid var(--line); background: #fff; font-size: 11.5px; color: var(--ink-2); }
.pill.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.mini-note { font-size: 11px; color: var(--muted); background: #f8fafc; border: 1px solid var(--line); padding: 9px 12px; border-radius: 8px; line-height: 1.7; }
.image-viewer { max-width: 100%; max-height: 72vh; border-radius: 10px; display: block; margin: 0 auto; }
.stat-inline { display: flex; gap: 22px; flex-wrap: wrap; }
.stat-inline div { display: flex; flex-direction: column; }
.stat-inline span { font-size: 11px; color: var(--muted); }
.stat-inline strong { font-size: 20px; color: var(--brand-deep); }

@media (max-width: 1180px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-7-5, .grid-8-4 { grid-template-columns: 1fr; }
  .kanban { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 820px) {
  .sidebar { position: fixed; left: -260px; transition: .22s; }
  .sidebar.open { left: 0; }
  .mobile-menu { display: grid; }
  .view { padding: 18px 14px 40px; }
  .topbar { padding: 0 14px; height: 66px; flex-basis: 66px; }
  .top-date { display: none; }
  .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .kanban { grid-template-columns: 1fr; }
  .identity-text { display: none; }
}
