/*
 * 社康体检解读 · 样式
 * 视觉语言与 eisapp 一致:令牌值逐个取自 enterprise-intelligence-stack 的 packages/ui/src/styles/tokens.css
 * (亮档),规则见该仓 DESIGN.md。本页是经典脚本静态页,用不了 @eis/ui 组件,只能对齐同一套令牌与形态:
 *   · 层次靠底色明度(sidebar < background < muted < card < popover),内容块、徽章、告警条、空态不画静息描边;
 *   · 字段静息不画描边,表面靠半透明墨色填色,焦点是 2px 实色 --ring;
 *   · 八级字阶、五级圆角、OS-first 中文字体栈;CJK 不加正字距;数字用等宽数字。
 */
:root {
  --background: oklch(0.965 0.006 92);
  --foreground: oklch(0.235 0.012 92);
  --card: oklch(0.995 0.003 92);
  --popover: oklch(0.998 0.002 92);
  --primary: oklch(0.52 0.105 168);
  --primary-foreground: oklch(0.99 0.004 160);
  --secondary: oklch(0.94 0.006 92);
  --secondary-foreground: oklch(0.32 0.012 92);
  --muted: oklch(0.978 0.004 92);
  --muted-foreground: oklch(0.5 0.01 92);
  --accent: oklch(0.945 0.007 92);
  --accent-foreground: oklch(0.32 0.012 92);
  --destructive: oklch(0.545 0.185 27);
  --border: oklch(0.93 0.005 92);
  --input-fill: color-mix(in oklab, var(--foreground) 6%, transparent);
  --input-fill-hover: color-mix(in oklab, var(--foreground) 9%, transparent);
  --indicator-border: oklch(0.63 0.008 92);
  --ring: oklch(0.555 0.1 168);
  --sidebar: oklch(0.955 0.007 92);

  --success: oklch(0.513 0.125 126);
  --warning: oklch(0.526 0.115 72);
  --info: oklch(0.519 0.135 248);
  --primary-tint: color-mix(in oklab, var(--primary) 10%, var(--card));
  --primary-tint-strong: color-mix(in oklab, var(--primary) 16%, var(--card));
  --primary-emphasis: color-mix(in oklab, var(--primary) 85%, black);
  --success-tint: color-mix(in oklab, var(--success) 12%, var(--card));
  --success-emphasis: oklch(0.44 0.12 126);
  --warning-tint: color-mix(in oklab, var(--warning) 13%, var(--card));
  --warning-emphasis: oklch(0.48 0.11 72);
  --destructive-tint: color-mix(in oklab, var(--destructive) 11%, var(--card));
  --destructive-emphasis: oklch(0.5 0.17 27);
  --info-tint: color-mix(in oklab, var(--info) 13%, var(--card));
  --info-emphasis: oklch(0.45 0.13 248);

  --radius-1: 6px;
  --radius-2: 10px;
  --radius-3: 13px;
  --radius-4: 16px;

  --shadow-card: 0 1px 2px rgb(40 35 20 / 0.05);
  --shadow-raised: 0 1px 2px rgb(40 35 20 / 0.05), 0 10px 30px -18px rgb(40 35 20 / 0.28);
  --shadow-dialog: 0 1px 2px rgb(40 35 20 / 0.06), 0 24px 60px -26px rgb(40 35 20 / 0.4);
  --shadow-menu: 0 1px 2px rgb(40 35 20 / 0.06), 0 16px 40px -20px rgb(40 35 20 / 0.32);
  --scrim: rgb(30 26 14 / 0.42);

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --duration-fast: 150ms;
  --duration-base: 200ms;

  --font-sans: 'Noto Sans SC', 'PingFang SC', 'HarmonyOS Sans SC', 'Microsoft YaHei', system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

  --fs-caption: 0.75rem;
  --lh-caption: 18px;
  --fs-label: 0.8125rem;
  --lh-label: 20px;
  --fs-body: 0.875rem;
  --lh-body: 22px;
  --fs-body-lg: 1rem;
  --lh-body-lg: 26px;
  --fs-section: 1rem;
  --lh-section: 24px;
  --fs-title: 1.25rem;
  --lh-title: 30px;
  --fs-page: 1.625rem;
  --lh-page: 34px;
  --fs-display: 3rem;
  --lh-display: 64px;

  --control-h: 40px;
  --control-h-sm: 36px;
  --chip-h: 28px;

  color-scheme: light;
}

/* 手机宽度 ∪ 触摸设备:控件触达区不小于 44(DESIGN.md §三) */
@media (max-width: 767px), (pointer: coarse) {
  :root {
    --control-h: 44px;
    --control-h-sm: 44px;
    --chip-h: 44px;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--foreground);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

h1, h2, h3, p { margin: 0; }
a { color: var(--primary); text-underline-offset: 4px; }
a:hover { text-decoration: underline; }
strong { font-weight: 600; }
.subtle { color: var(--muted-foreground); }
.num, td.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

/* ── 按钮(@eis/ui buttonVariants) ─────────────────────────────── */
button, .button-link {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--control-h); padding: 0 16px;
  font: inherit; font-size: var(--fs-body); font-weight: 500; line-height: var(--lh-body);
  white-space: nowrap; text-decoration: none; cursor: pointer;
  border: 0; border-radius: var(--radius-2);
  background: var(--primary); color: var(--primary-foreground);
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out), scale var(--duration-fast) var(--ease-out);
}
button:hover:not(:disabled), .button-link:hover {
  background: color-mix(in oklab, var(--primary) 90%, transparent); text-decoration: none;
}
button:active:not(:disabled) { scale: 0.98; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button svg, .button-link svg { width: 16px; height: 16px; flex: none; }

button.secondary { background: var(--secondary); color: var(--secondary-foreground); }
button.secondary:hover:not(:disabled) { background: var(--accent); }
button.ghost { background: transparent; color: var(--foreground); }
button.ghost:hover:not(:disabled) { background: var(--accent); color: var(--accent-foreground); }
button.tint { background: var(--primary-tint); color: var(--primary-emphasis); }
button.tint:hover:not(:disabled) { background: var(--primary-tint-strong); }
button.sm { min-height: var(--control-h-sm); padding: 0 12px; }
button.lg { min-height: 48px; padding: 0 32px; font-size: 15px; }
button.block { width: 100%; }

/* ── 字段(@eis/ui FIELD_CHROME):静息无描边,填色 + 焦点环 ───────── */
input:not([type='checkbox']):not([type='radio']):not([type='file']), select, textarea {
  width: 100%; min-width: 0; min-height: var(--control-h);
  padding: 0 12px;
  font: inherit; font-size: var(--fs-body); line-height: var(--lh-body); color: var(--foreground);
  border: 0; border-radius: var(--radius-2);
  background: var(--input-fill);
  transition: background-color var(--duration-fast) var(--ease-out);
}
textarea { padding: 9px 12px; resize: vertical; }
select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23736f66' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) { background-color: var(--input-fill-hover); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--ring); outline-offset: 0; }
input[aria-invalid='true'], select[aria-invalid='true'] { box-shadow: 0 0 0 1.5px var(--destructive); }
::placeholder { color: var(--muted-foreground); opacity: 1; }
input:disabled, select:disabled, textarea:disabled { opacity: 0.5; cursor: not-allowed; }
input[type='checkbox'] {
  width: 18px; height: 18px; margin: 2px 0 0; flex: none;
  accent-color: var(--primary); cursor: pointer;
}
@media (forced-colors: active) {
  input:not([type='checkbox']), select, textarea { border: 1px solid; }
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
label, .field-label { font-size: var(--fs-label); line-height: var(--lh-label); color: var(--muted-foreground); font-weight: 500; }
label { display: flex; flex-direction: column; gap: 6px; }
.field-help { font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--muted-foreground); font-weight: 400; }
.field-error { font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--destructive-emphasis); font-weight: 400; }
.field-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin-top: 16px; }

/* ── 徽章(@eis/ui Badge):6px 圆角、淡底同色字、无描边 ──────────── */
.badge {
  display: inline-flex; align-items: center; width: fit-content; flex: none;
  padding: 2px 10px; border-radius: var(--radius-1);
  font-size: var(--fs-caption); line-height: var(--lh-caption); font-weight: 600; white-space: nowrap;
}
.badge-warn { background: var(--warning-tint); color: var(--warning-emphasis); }
.badge-ok { background: var(--success-tint); color: var(--success-emphasis); }
.badge-info { background: var(--info-tint); color: var(--info-emphasis); }
.badge-muted { background: color-mix(in oklab, var(--muted-foreground) 10%, transparent); color: var(--muted-foreground); }

/* ── 告警条(@eis/ui Alert / InlineAlert) ─────────────────────── */
.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 16px; border-radius: var(--radius-3);
  font-size: var(--fs-body); line-height: var(--lh-body);
  background: var(--warning-tint); color: var(--warning-emphasis);
}
.notice.error { background: var(--destructive-tint); color: var(--destructive-emphasis); }
.notice.ok { background: var(--success-tint); color: var(--success-emphasis); }
.notice.info { background: var(--info-tint); color: var(--info-emphasis); }
.notice svg { width: 16px; height: 16px; flex: none; margin-top: 3px; }
.notice a { color: inherit; font-weight: 600; text-decoration: underline; }

.status { min-height: var(--lh-body); margin-top: 10px; font-size: var(--fs-body); color: var(--muted-foreground); }
.status:empty { min-height: 0; margin-top: 0; }
.status.error { color: var(--destructive-emphasis); }
.status.warn { color: var(--warning-emphasis); }
.status.ok { color: var(--success-emphasis); }
.status a { color: inherit; font-weight: 600; }

/* 加载中(@eis/ui Spinner) */
.spinner { display: inline-flex; align-items: center; gap: 8px; color: var(--muted-foreground); }
.spinner::before {
  content: ''; width: 16px; height: 16px; flex: none; border-radius: 50%;
  border: 2px solid currentcolor; border-top-color: transparent;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { rotate: 360deg; } }

/* ── 登录(对齐 console-kit AuthGate:左栏品牌、右栏表单) ──────────── */
.login-view { min-height: 100vh; background: var(--sidebar); }
.login-brand-panel { display: none; }
.login-form-panel {
  display: flex; align-items: flex-start; justify-content: center;
  min-height: 100vh; padding: 72px 24px 40px; background: var(--card);
}
.login-card { display: flex; flex-direction: column; width: 100%; max-width: 352px; }
.login-card h1 { font-size: var(--fs-page); line-height: var(--lh-page); letter-spacing: -0.015em; font-weight: 600; }
.login-card .login-description { margin-top: 6px; color: var(--muted-foreground); }
.login-fields { display: flex; flex-direction: column; gap: 14px; margin-top: 30px; }
.login-fields .field-label { font-size: var(--fs-caption); line-height: var(--lh-caption); }
.login-card input:not([type='checkbox']) { min-height: 48px; padding: 0 15px; font-size: 15px; border-radius: 11px; }
/* 等宽与字距只给输入的值,占位字仍用正文字体(中文占位字加字距会被拆散) */
.login-card #login-phone:not(:placeholder-shown) { font-family: var(--font-mono); }
.password-wrap { position: relative; }
.password-wrap input:not([type='checkbox']) { padding-right: 48px; }
.password-wrap input[type='password']:not(:placeholder-shown) { letter-spacing: 0.22em; }
.password-toggle {
  position: absolute; top: 50%; right: 4px; translate: 0 -50%;
  width: 40px; min-height: 40px; padding: 0;
  background: transparent; color: var(--muted-foreground);
}
.password-toggle:hover:not(:disabled) { background: var(--accent); color: var(--foreground); }
.password-toggle svg { width: 18px; height: 18px; }
.login-card #login-button { margin-top: 24px; }
.login-card .status { margin-top: 14px; }
.login-meta { margin-top: 16px; font-size: var(--fs-label); line-height: var(--lh-label); color: var(--muted-foreground); }
.login-card hr { margin: 28px 0 0; border: 0; border-top: 1px solid var(--border); }
.login-footnote { margin-top: 16px; font-size: var(--fs-caption); line-height: 20px; color: var(--muted-foreground); }
.login-brand-mobile { margin-bottom: 32px; }

.brand-row { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex: none; border-radius: var(--radius-2);
  background: var(--primary); color: var(--primary-foreground);
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-title { font-size: 15px; font-weight: 600; }
.brand-tagline { font-size: var(--fs-label); line-height: var(--lh-label); color: var(--muted-foreground); }

@media (min-width: 1024px) {
  .login-view { display: grid; grid-template-columns: minmax(0, 1fr) 600px; }
  .login-brand-panel { display: flex; flex-direction: column; padding: 52px 64px; }
  .login-brand-body { display: flex; flex: 1; flex-direction: column; justify-content: center; max-width: 640px; }
  .login-brand-body h1 { font-size: var(--fs-display); line-height: var(--lh-display); letter-spacing: -0.025em; font-weight: 600; }
  .login-brand-body p { margin-top: 22px; font-size: 17px; line-height: 29px; color: var(--muted-foreground); }
  .login-points { display: flex; flex-direction: column; gap: 11px; margin: 34px 0 0; padding: 0; list-style: none; }
  .login-points li { display: flex; align-items: center; gap: 11px; color: color-mix(in oklab, var(--foreground) 85%, transparent); }
  .login-points .point-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 26px; height: 26px; flex: none; border-radius: var(--radius-1);
    background: var(--card); color: var(--primary);
  }
  .login-points svg { width: 15px; height: 15px; }
  .login-brand-foot { font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--muted-foreground); }
  .login-form-panel { align-items: center; min-height: 0; padding: 32px; }
  .login-brand-mobile { display: none; }
}

/* ── 顶栏与导航 ────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 12px 24px; background: var(--sidebar);
}
.topbar .brand-row { flex: none; }
.main-nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; min-width: 0; }
.main-nav a {
  display: inline-flex; align-items: center; min-height: var(--control-h-sm); padding: 0 12px;
  border-radius: var(--radius-2); color: color-mix(in oklab, var(--foreground) 70%, transparent);
  font-weight: 500; text-decoration: none;
  transition: background-color var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out);
}
.main-nav a:hover { background: var(--accent); color: var(--foreground); text-decoration: none; }
/* 选中是「这一行被抬起来」:抬到 card 档的中性面,不用品牌绿(绿只留给动作) */
.main-nav a.active { background: var(--card); color: var(--foreground); box-shadow: var(--shadow-card); }
.session { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.session-name { font-weight: 500; margin-right: 4px; }

.prototype-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 24px; font-size: var(--fs-caption); line-height: var(--lh-caption);
  background: var(--warning-tint); color: var(--warning-emphasis);
}
.prototype-bar svg { width: 14px; height: 14px; flex: none; }

/* ── 页面骨架 ─────────────────────────────────────────────── */
.page { padding: 24px 24px 48px; max-width: 1440px; margin: 0 auto; }
.layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 20px; align-items: start; }
.layout > * { min-width: 0; }

.panel, .detail { background: var(--card); border-radius: var(--radius-3); box-shadow: var(--shadow-card); }
.panel { padding: 16px; }
.detail { padding: 24px; border-radius: var(--radius-4); }
.panel h2 { font-size: var(--fs-section); line-height: var(--lh-section); font-weight: 600; margin-bottom: 12px; }
.panel-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.divider { height: 1px; background: var(--border); margin: 20px 0 16px; }

.page-heading {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 16px;
  flex-wrap: wrap; margin-bottom: 20px;
}
.page-heading h2 { font-size: var(--fs-page); line-height: var(--lh-page); letter-spacing: -0.014em; font-weight: 600; }
.page-heading p { margin-top: 4px; }
.back-link {
  display: inline-flex; align-items: center; gap: 4px; margin-bottom: 8px;
  font-size: var(--fs-label); line-height: var(--lh-label); color: var(--muted-foreground); text-decoration: none;
}
.back-link:hover { color: var(--foreground); text-decoration: none; }
.back-link svg { width: 16px; height: 16px; }

/* ── 上传区 ───────────────────────────────────────────────── */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 22px 16px; border-radius: var(--radius-3);
  background: var(--muted); color: var(--foreground);
  font-size: var(--fs-body); text-align: center; cursor: pointer;
  transition: background-color var(--duration-fast) var(--ease-out), box-shadow var(--duration-fast) var(--ease-out);
}
.dropzone:hover { background: var(--accent); }
.dropzone.dragging { background: var(--primary-tint); box-shadow: inset 0 0 0 2px var(--ring); }
.dropzone:focus-within { outline: 2px solid var(--ring); outline-offset: 2px; }
.dropzone-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; margin-bottom: 4px; border-radius: var(--radius-2);
  background: var(--primary-tint); color: var(--primary-emphasis);
}
.dropzone-icon svg { width: 20px; height: 20px; }
.dropzone strong { font-weight: 600; }
.dropzone .subtle { font-size: var(--fs-caption); line-height: var(--lh-caption); }
.file-list { white-space: pre-line; color: var(--foreground); }
.upload-panel form > label:not(.dropzone) { margin-top: 12px; }
#upload-button { width: 100%; margin-top: 16px; }

/* ── 居民列表 ─────────────────────────────────────────────── */
.resident-list { display: flex; flex-direction: column; gap: 2px; }
.resident {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; min-height: 0; padding: 10px 12px;
  text-align: left; white-space: normal; font-weight: 400;
  background: transparent; color: var(--foreground); border-radius: var(--radius-2);
}
.resident:hover:not(:disabled) { background: var(--accent); }
.resident strong { font-size: var(--fs-body); font-weight: 600; }
.resident > span { font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--muted-foreground); }
.resident .badge { margin-top: 4px; }
.resident.active, .resident.active:hover:not(:disabled) { background: var(--primary-tint); }
.resident.active strong { color: var(--primary-emphasis); }

/* ── 居民详情 ─────────────────────────────────────────────── */
.detail-header { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.detail-header h2 { font-size: var(--fs-title); line-height: var(--lh-title); letter-spacing: -0.01em; font-weight: 600; }
.detail-header p { margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.year-timeline { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.year {
  display: flex; flex-direction: column; padding: 6px 10px; border-radius: var(--radius-2);
  background: var(--muted); font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--muted-foreground);
}
.year strong { color: var(--foreground); font-size: var(--fs-label); line-height: var(--lh-label); font-variant-numeric: tabular-nums; }

.detail > .status, .detail > .notice { margin-top: 16px; }
.preview-note { margin-top: 24px; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; margin: 16px 0; }
.info-grid div { padding: 10px 12px; border-radius: var(--radius-2); background: var(--muted); }
.info-grid dt { font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--muted-foreground); }
.info-grid dd { margin: 2px 0 0; font-weight: 600; }

.section { margin-top: 24px; }
.section h3 { font-size: var(--fs-section); line-height: var(--lh-section); font-weight: 600; margin-bottom: 8px; }
.section p { margin: 6px 0; }
.section ul { margin: 6px 0; padding-left: 20px; }
.section li { margin: 4px 0; }
.insert-body { font-size: var(--fs-body-lg); line-height: var(--lh-body-lg); }
.insert-body .section h3 { font-size: var(--fs-section); }
.insert-signature { margin-top: 24px; font-size: var(--fs-label); line-height: var(--lh-label); }

details.section > summary, .parse-details > summary {
  display: flex; align-items: center; gap: 8px; min-height: var(--control-h-sm);
  cursor: pointer; list-style: none; font-weight: 500;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: ''; width: 8px; height: 8px; flex: none; margin: 0 4px;
  border-right: 2px solid var(--muted-foreground); border-bottom: 2px solid var(--muted-foreground);
  rotate: -45deg; transition: rotate var(--duration-fast) var(--ease-out);
}
details[open] > summary::before { rotate: 45deg; }
.parse-details { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border); }
.parse-details details.section { margin-top: 8px; }

/* ── 表格(@eis/ui Table):表头淡底、行间 2px、无单元格描边 ───────── */
table {
  width: 100%; margin-top: 8px; border-collapse: separate; border-spacing: 0 2px;
  font-size: var(--fs-body); line-height: var(--lh-body);
}
th {
  height: 36px; padding: 0 12px; background: var(--muted); text-align: left; vertical-align: middle;
  font-size: var(--fs-caption); line-height: var(--lh-caption); font-weight: 500; color: var(--muted-foreground); white-space: nowrap;
}
td { padding: 8px 12px; vertical-align: top; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { border-radius: var(--radius-2) 0 0 var(--radius-2); }
th:last-child, td:last-child { border-radius: 0 var(--radius-2) var(--radius-2) 0; }
tbody tr:hover td { background: var(--muted); }
th.num { text-align: right; }
.table-scroll { overflow-x: auto; }

/* ── 放行确认 ─────────────────────────────────────────────── */
.approval { padding: 16px; border-radius: var(--radius-3); background: var(--warning-tint); }
.approval h3 { color: var(--warning-emphasis); margin-bottom: 4px; }
.approval > p { margin: 0 0 8px; }
.approval-list { display: flex; flex-direction: column; gap: 2px; }
.approval-item {
  display: flex; flex-direction: row; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border-radius: var(--radius-2); background: var(--card);
  font-size: var(--fs-body); line-height: var(--lh-body); font-weight: 400; color: var(--foreground); cursor: pointer;
}
.approval-item strong { display: block; }
.approval-item .subtle { font-size: var(--fs-label); line-height: var(--lh-label); }
.approval-actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.approval-actions input:not([type='checkbox']) { flex: 1 1 220px; width: auto; background: var(--card); }
.approval-actions input:not([type='checkbox']):hover { background: var(--card); }
.approval.approved { background: var(--success-tint); }
.approval.approved h3 { color: var(--success-emphasis); }

/* ── 问这位居民 ───────────────────────────────────────────── */
.assistant-panel { padding: 16px; border-radius: var(--radius-3); background: var(--muted); }
.assistant-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.assistant-head h3 { margin: 0; }
.assistant-head p { margin: 4px 0 0; }
.assistant-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.assistant-panel .notice { margin-top: 12px; }
.assistant-tasks, .chat-samples { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }

/* 动作型 chip(@eis/ui size="chip-action" + variant="tint") */
.chip {
  min-height: var(--chip-h); padding: 0 10px; border-radius: var(--radius-1);
  font-size: var(--fs-caption); line-height: var(--lh-caption); font-weight: 500;
  background: var(--primary-tint); color: var(--primary-emphasis);
}
.chip:hover:not(:disabled) { background: var(--primary-tint-strong); }

.assistant-messages {
  display: flex; flex-direction: column; gap: 12px;
  min-height: 72px; max-height: 360px; overflow-y: auto; padding: 4px 0;
}
.assistant-empty, .chat-empty { margin: auto 0; text-align: center; font-size: var(--fs-label); }
.assistant-more { margin: 0; font-size: var(--fs-caption); line-height: var(--lh-caption); text-align: center; }
.assistant-panel .chat-form { margin-top: 12px; }
.assistant-panel .chat-form textarea { background: var(--card); }
.assistant-panel .chat-form textarea:hover:not(:disabled) { background: var(--card); }
.assistant-brief-preview { margin-top: 8px; }
.assistant-brief-preview summary { color: var(--primary); font-size: var(--fs-label); }
.assistant-brief-preview pre {
  margin: 8px 0 0; padding: 12px; max-height: 260px; overflow: auto;
  border-radius: var(--radius-2); background: var(--card);
  font: inherit; font-size: var(--fs-label); line-height: var(--lh-label); white-space: pre-wrap; overflow-wrap: anywhere;
}

/* ── 对话:用户在右(品牌实底),助手在左 ────────────────────────── */
.chat-panel { padding: 16px; border-radius: var(--radius-4); background: var(--card); box-shadow: var(--shadow-card); }
.chat-messages {
  display: flex; flex-direction: column; gap: 14px;
  min-height: 280px; max-height: 56vh; overflow-y: auto; padding: 4px 2px 12px;
}
.chat-bubble { display: flex; flex-direction: column; max-width: 80%; }
.chat-bubble.user { align-self: flex-end; align-items: flex-end; }
.chat-bubble.assistant { align-self: flex-start; align-items: flex-start; }
.bubble-text { padding: 8px 12px; border-radius: var(--radius-3); overflow-wrap: anywhere; }
.chat-bubble.user .bubble-text { white-space: pre-wrap; background: var(--primary); color: var(--primary-foreground); }
.chat-bubble.assistant .bubble-text { background: var(--muted); color: var(--foreground); font-size: var(--fs-body-lg); line-height: var(--lh-body-lg); }
.assistant-panel .chat-bubble.assistant .bubble-text { background: var(--card); }
.chat-bubble.failed .bubble-text { background: var(--destructive-tint); color: var(--destructive-emphasis); font-size: var(--fs-body); line-height: var(--lh-body); }
.chat-bubble.pending .bubble-text { color: var(--muted-foreground); font-size: var(--fs-body); }
.bubble-copy {
  min-height: var(--chip-h); margin-top: 2px; padding: 0 8px; gap: 4px;
  background: transparent; color: var(--muted-foreground);
  font-size: var(--fs-caption); line-height: var(--lh-caption); font-weight: 500;
}
.bubble-copy:hover:not(:disabled) { background: var(--accent); color: var(--foreground); }
.bubble-copy svg { width: 14px; height: 14px; }

.chat-form { display: flex; gap: 8px; align-items: flex-end; }
.chat-form textarea { flex: 1; min-height: 64px; }
.chat-form-hint { margin-top: 6px; font-size: var(--fs-caption); line-height: var(--lh-caption); color: var(--muted-foreground); }
.chat-resident-picker { min-width: 260px; max-width: 360px; }
.chat-panel + .notice, .notice + .chat-panel { margin-top: 12px; }
.page-heading + .notice { margin-bottom: 12px; }

/* 渲染后的 Markdown 回答(对齐 @eis/ui Markdown 的排版) */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; }
.md .md-heading { margin: 12px 0 4px; font-weight: 600; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md li > ul, .md li > ol { margin: 2px 0 0; }
.md strong { font-weight: 600; }
.md code { padding: 1px 4px; border-radius: var(--radius-1); background: var(--input-fill); font-family: var(--font-mono); font-size: 0.85em; }
.md pre { margin: 0 0 8px; padding: 10px 12px; overflow-x: auto; border-radius: var(--radius-2); background: var(--input-fill); font-size: var(--fs-caption); }
.md pre code { padding: 0; background: transparent; }
.md blockquote { margin: 0 0 8px; padding-left: 12px; border-left: 2px solid var(--border); color: var(--muted-foreground); }
.md hr { margin: 12px 0; border: 0; border-top: 1px solid var(--border); }
.md .md-table { margin: 0 0 8px; overflow-x: auto; }
.md table { margin: 0; border-collapse: collapse; border-spacing: 0; font-size: var(--fs-label); line-height: var(--lh-label); }
.md th { height: auto; padding: 4px 8px; background: transparent; border-bottom: 1px solid var(--border); font-size: var(--fs-label); font-weight: 600; color: var(--foreground); }
.md td { padding: 4px 8px; border-bottom: 1px solid color-mix(in oklab, var(--border) 50%, transparent); border-radius: 0; }
.md th:first-child, .md th:last-child, .md td:first-child, .md td:last-child { border-radius: 0; }
.md tbody tr:hover td { background: transparent; }

/* ── 历史记录 ─────────────────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  width: 100%; min-height: 0; padding: 14px 16px;
  text-align: left; white-space: normal; font-weight: 400;
  background: var(--card); color: var(--foreground);
  border-radius: var(--radius-3); box-shadow: var(--shadow-card);
}
.history-item:hover:not(:disabled) { background: var(--card); box-shadow: var(--shadow-raised); }
.history-main { display: flex; flex-direction: column; gap: 2px; }
.history-main strong { font-size: var(--fs-section); line-height: var(--lh-section); }
.history-main .subtle { font-size: var(--fs-label); line-height: var(--lh-label); font-variant-numeric: tabular-nums; }
.history-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.history-detail { padding: 24px; border-radius: var(--radius-4); background: var(--card); box-shadow: var(--shadow-card); }
.history-detail > .status, .history-detail > .notice { margin: 0 0 12px; }

/* ── 空态(@eis/ui DataState):不画框,图标 + 标题 + 说明 ─────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px;
  padding: 48px 20px; text-align: center;
}
.empty-state h2 { font-size: var(--fs-section); line-height: var(--lh-section); font-weight: 600; }
.empty-state .button-link { margin-top: 8px; }
.empty-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: var(--radius-2);
  background: var(--muted); color: var(--muted-foreground);
}
.empty-icon svg { width: 20px; height: 20px; }
.panel .empty-state, .resident-list .subtle { padding: 16px 8px; }
.resident-list > .subtle { font-size: var(--fs-label); text-align: center; }

/* ── 主动健康管理(占位) ───────────────────────────────────── */
.placeholder-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.placeholder-card { padding: 20px; border-radius: var(--radius-3); background: var(--card); box-shadow: var(--shadow-card); }
.placeholder-card h3 { margin: 12px 0 6px; font-size: var(--fs-section); line-height: var(--lh-section); font-weight: 600; }

/* ── 轻提示(替代浏览器原生 alert) ─────────────────────────────── */
.toast-region {
  position: fixed; z-index: 100; left: 50%; bottom: 24px; translate: -50% 0;
  display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px;
  border-radius: var(--radius-3); background: var(--popover); color: var(--foreground);
  box-shadow: var(--shadow-menu); pointer-events: auto;
  animation: toast-in var(--duration-base) var(--ease-out);
}
.toast svg { width: 16px; height: 16px; flex: none; margin-top: 3px; }
.toast.error svg { color: var(--destructive-emphasis); }
.toast.ok svg { color: var(--success-emphasis); }
@keyframes toast-in { from { opacity: 0; translate: 0 8px; } }

/* ── 应用内自动演示 ───────────────────────────────────────── */
body.tour-active #app-view { pointer-events: none; }
body.tour-active .tour-card,
body.tour-active .tour-card * { pointer-events: auto; }

[data-demo-id="compose"],
[data-demo-id="download"],
[data-demo-id="approval"],
[data-demo-id="approval-actions"],
[data-demo-id="history-item"],
[data-demo-id="chat-panel"],
[data-demo-id="resident-assistant"] { scroll-margin-top: 90px; scroll-margin-bottom: 260px; }

.tour-spotlight {
  position: fixed; z-index: 80; pointer-events: none;
  border-radius: var(--radius-3);
  box-shadow: 0 0 0 2px var(--ring), 0 0 0 9999px var(--scrim);
  background: transparent;
}

.tour-card {
  position: fixed; z-index: 90; left: 50%; bottom: 24px; translate: -50% 0;
  width: min(640px, calc(100vw - 32px)); max-height: 45vh; overflow: auto;
  padding: 20px 24px; border-radius: var(--radius-4);
  background: var(--popover); color: var(--foreground);
  box-shadow: var(--shadow-dialog);
  outline: none;
}
.tour-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.tour-progress {
  padding: 2px 8px; border-radius: var(--radius-1);
  background: var(--primary-tint); color: var(--primary-emphasis);
  font-size: var(--fs-caption); line-height: var(--lh-caption); font-weight: 600; font-variant-numeric: tabular-nums;
}
.tour-title { font-size: var(--fs-section); line-height: var(--lh-section); font-weight: 600; }
.tour-narration { margin-top: 8px; font-size: var(--fs-body-lg); line-height: var(--lh-body-lg); color: color-mix(in oklab, var(--foreground) 85%, transparent); }
.tour-note { margin-top: 10px; padding: 8px 12px; border-radius: var(--radius-2); background: var(--warning-tint); color: var(--warning-emphasis); font-size: var(--fs-label); line-height: var(--lh-label); }
.tour-note:empty { display: none; }
.tour-controls { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.tour-card button { min-height: var(--control-h-sm); padding: 0 12px; }
.tour-card-complete .tour-title { color: var(--success-emphasis); }
.tour-card-failed .tour-title { color: var(--destructive-emphasis); }

/* ── 窄屏 ─────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .page { padding: 16px 16px 32px; }
  /* 窄屏顶栏折成三行,吸顶会吃掉近 1/5 屏高;改为随页面滚走 */
  .topbar { position: static; gap: 12px; padding: 10px 16px; }
  .main-nav { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; }
  .main-nav a { flex: none; }
  .session { margin-left: auto; }
  .session-name { display: none; }
  .prototype-bar { padding: 6px 16px; }
  .detail, .history-detail { padding: 16px; }
  .chat-bubble { max-width: 92%; }
  .tour-card { bottom: 12px; width: calc(100vw - 24px); padding: 16px; }
  .tour-controls button { flex: 1 1 auto; }
}
@media (max-width: 480px) {
  .field-row { grid-template-columns: 1fr; }
  .chat-form { flex-wrap: wrap; }
  .chat-form textarea { flex-basis: 100%; }
  .chat-form button { flex: 1 1 auto; }
}

/* 放在所有层之外,保证优先级(同 @eis/ui base.css) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* 次级链接按钮(工作台助手里的「完整对话」) */
.button-link.ghost-link { min-height: var(--control-h-sm); padding: 0 12px; background: transparent; color: var(--primary); }
.button-link.ghost-link:hover { background: var(--accent); }
.md th.center, .md td.center { text-align: center; }
