:root {
  --ink: #28322f; --muted: #6f7b76; --paper: #fbfaf6; --cream: #f2eee3;
  --sage: #718a7b; --sage-dark: #526c5d; --sage-soft: #e4ebe5;
  --rose: #a45b62; --line: rgba(40, 50, 47, .14);
  --shadow: 0 24px 70px rgba(52, 64, 59, .12);
  --surface: rgba(255,255,255,.78); --surface-strong: #fff; --soft-surface: rgba(242,238,227,.55);
}
:root[data-theme="dark"] {
  --ink: #e8f0ea; --muted: #afbeb4; --paper: #111814; --cream: #1b2820;
  --sage: #82a991; --sage-dark: #5f8b70; --sage-soft: #26382d;
  --rose: #ef9aa2; --line: rgba(226, 240, 231, .16);
  --shadow: 0 24px 70px rgba(0,0,0,.42);
  --surface: rgba(28,40,33,.88); --surface-strong: #1b2820; --soft-surface: rgba(32,48,38,.76);
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; color: var(--ink);
  background: radial-gradient(circle at 8% 4%, rgba(210,222,208,.75), transparent 32rem),
              radial-gradient(circle at 92% 88%, rgba(235,216,204,.6), transparent 30rem), var(--paper);
  font-family: "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif;
}
button, textarea, select, input { font: inherit; }
button { cursor: pointer; }
.shell { width: min(880px, calc(100% - 28px)); margin: 0 auto; padding: 34px 0 56px; }
.app-version { width: min(880px, calc(100% - 28px)); margin: -34px auto 24px; color: var(--muted); font-size: 11px; text-align: center; }
.brand { position: relative; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; margin-bottom: 26px; }
.brand-mark { position: relative; display: block; width: 50px; height: 50px; }
.mark {
  position: absolute; inset: 0; display: block; width: 50px; height: 50px; object-fit: contain;
  mix-blend-mode: multiply;
}
.mark--dark { display: none; }
:root[data-theme="dark"] .mark--light { display: none; }
:root[data-theme="dark"] .mark--dark { display: block; mix-blend-mode: lighten; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(20px,3vw,28px); letter-spacing: .04em; }
h2 { font-size: clamp(27px,4.6vw,42px); line-height: 1.22; letter-spacing: -.02em; }
.eyebrow, .step { margin-bottom: 5px; color: var(--muted); font-size: 12px; letter-spacing: .18em; text-transform: uppercase; }
.menu-toggle { display: inline-grid; gap: 4px; width: 38px; height: 38px; place-content: center; padding: 0; border: 0; border-radius: 10px; color: var(--ink); background: transparent; }
.menu-toggle:hover, .menu-toggle[aria-expanded="true"] { background: var(--sage-soft); }
.menu-toggle span { display: block; width: 18px; height: 2px; border-radius: 2px; background: currentColor; }
.brand-menu { position: absolute; z-index: 12; top: calc(100% + 8px); right: 0; display: none; min-width: 154px; padding: 6px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-strong); box-shadow: var(--shadow); }
.brand-menu.is-open { display: grid; }
.mini-link, .theme-toggle { border: 0; color: var(--sage-dark); background: transparent; font-size: 14px; }
.menu-item { display: flex; align-items: center; justify-content: space-between; min-height: 38px; padding: 8px 10px; border-radius: 9px; text-align: left; text-decoration: none; }
.menu-item:hover { background: var(--sage-soft); }
.account-menu { margin: 3px 0; padding: 5px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.menu-account-name { margin: 0; padding: 7px 10px 4px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.account-menu .menu-item { width: 100%; }
.brand-menu .theme-toggle { width: 100%; }
.theme-label { flex: 1; }
.theme-icon { display: inline-grid; width: 19px; height: 19px; place-items: center; }
.theme-icon svg { display: block; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.8; }
.card, .chat { border: 1px solid var(--line); border-radius: 28px; background: var(--surface); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.card { padding: clamp(24px,6vw,54px); }
.welcome .lead { max-width: 650px; color: var(--muted); font-size: 17px; line-height: 1.8; }
.kicker { margin-bottom: 10px; color: var(--sage-dark); font-weight: 700; letter-spacing: .12em; }
.notice { margin: 26px 0 22px; padding: 18px 20px; border-left: 4px solid var(--sage); border-radius: 4px 15px 15px 4px; background: var(--sage-soft); }
.notice p { margin: 7px 0 0; color: var(--muted); line-height: 1.65; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; line-height: 1.45; }
.check input { width: 18px; height: 18px; accent-color: var(--sage-dark); }
.primary, .outline, .text-button { border: 0; border-radius: 14px; transition: transform .16s ease, background .16s ease, opacity .16s ease; }
.primary { width: 100%; margin-top: 22px; padding: 15px 20px; color: white; background: var(--sage-dark); font-weight: 700; }
.primary:hover { background: #435c4d; transform: translateY(-1px); }
.primary:disabled { cursor: wait; opacity: .55; transform: none; }
.outline { padding: 10px 16px; border: 1px solid var(--line); background: var(--surface-strong); color: var(--ink); }
.text-button { display: block; margin: 15px auto 0; padding: 8px; color: var(--muted); background: transparent; }
.danger, .danger-text { color: var(--rose); }
fieldset { margin: 28px 0; padding: 0; border: 0; }
legend, .field { color: var(--muted); font-size: 14px; font-weight: 700; }
.choice-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-top: 10px; }
.choice { display: flex; flex-direction: column; gap: 5px; padding: 16px; text-align: left; border: 1px solid var(--line); border-radius: 15px; background: var(--surface-strong); color: var(--ink); }
.choice span { color: var(--muted); font-size: 12px; }
.choice.selected { border-color: var(--sage); background: var(--sage-soft); box-shadow: inset 0 0 0 1px var(--sage); }
.field { display: block; margin: 25px 0; }
select, textarea, .field input { width: 100%; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); background: var(--surface-strong); }
select, .field input { margin-top: 9px; padding: 13px 14px; }
.auth .lead { color: var(--muted); line-height: 1.7; }
.form-error { min-height: 22px; margin: -8px 0 0; color: var(--rose); font-size: 13px; }
.records-list { display: grid; gap: 10px; margin: 22px 0; }
.record { padding: 16px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface-strong); }
.record strong { display: block; margin-bottom: 6px; }
.record span { color: var(--muted); font-size: 13px; }
.full { width: 100%; }
input[type="range"] { width: 100%; margin: 17px 0 4px; accent-color: var(--sage-dark); }
.range-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; font-weight: 400; }
.chat { overflow: hidden; }
.chat-top { display: flex; justify-content: space-between; align-items: center; padding: 22px 24px; border-bottom: 1px solid var(--line); }
.chat-top h2 { margin: 0; font-size: 22px; }
.messages { min-height: 380px; max-height: 58vh; overflow-y: auto; padding: 26px; }
.message { display: flex; margin-bottom: 18px; }
.message.user { justify-content: flex-end; }
.bubble { max-width: min(640px,86%); padding: 13px 16px; border-radius: 18px; line-height: 1.7; white-space: pre-wrap; }
.assistant .bubble { border-top-left-radius: 5px; background: var(--sage-soft); }
.user .bubble { border-top-right-radius: 5px; color: white; background: var(--sage-dark); }
.typing .bubble { color: var(--muted); }
.chat-bottom { border-top: 1px solid var(--line); background: var(--surface-strong); }
.composer { display: grid; grid-template-columns: minmax(0,1fr) 64px; gap: 10px; align-items: stretch; padding: 12px 20px; background: var(--surface-strong); }
.text-entry { position: relative; min-width: 0; }
.composer textarea { display: block; height: 138px; min-height: 138px; resize: none; padding: 12px 14px 31px; line-height: 1.55; }
.composer button { min-width: 0; border: 0; border-radius: 16px; color: white; background: var(--sage-dark); font-weight: 700; }
.action-stack { display: grid; grid-template-rows: repeat(2, minmax(0,1fr)); gap: 10px; }
.action-stack button { display: flex; width: 64px; min-height: 0; align-items: center; justify-content: center; padding: 0; text-align: center; line-height: 1.16; }
.composer .voice-input { background: var(--sage); touch-action: none; user-select: none; -webkit-user-select: none; }
.voice-button-label { white-space: pre-line; }
.composer .voice-input[aria-pressed="true"] { background: var(--rose); animation: voice-pulse 1.2s ease-in-out infinite; }
.voice-status { position: absolute; right: 11px; bottom: 7px; left: 11px; margin: 0; overflow: hidden; color: var(--muted); font-size: 11px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
@keyframes voice-pulse { 50% { opacity: .7; } }
.chat-scroll-note { margin: 22px 0 2px; overflow: hidden; color: var(--muted); font-size: 10px; line-height: 1.4; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
.report-body { padding: 18px; border-radius: 16px; background: var(--cream); line-height: 1.8; white-space: pre-wrap; }
.report-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; }
.report-actions .primary { margin: 0; }
dialog { width: min(540px,calc(100% - 28px)); padding: 0; border: 0; border-radius: 24px; color: var(--ink); background: var(--surface-strong); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(29,37,33,.55); backdrop-filter: blur(5px); }
.dialog-inner { padding: 30px; line-height: 1.7; }
.dialog-inner h2 { font-size: 28px; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
:root[data-theme="dark"] body { background: radial-gradient(circle at 8% 4%, rgba(65,96,76,.38), transparent 32rem), radial-gradient(circle at 92% 88%, rgba(91,66,55,.3), transparent 30rem), var(--paper); }
:root[data-theme="dark"] .primary:hover { background: #4d765e; }
@media (max-width: 650px) {
  input:not([type="checkbox"]):not([type="range"]), select, textarea { font-size: 16px; }
  .shell { padding-top: 18px; }
  .brand { position: relative; grid-template-columns: auto minmax(0,1fr) auto; }
  .brand-mark, .mark { width: 44px; height: 44px; }
  .brand h1 { font-size: 20px; }
  .choice-grid { grid-template-columns: 1fr; }
  .messages { min-height: 52vh; padding: 18px; }
  .report-actions { grid-template-columns: 1fr; }

  html.chat-active { height: 100%; overflow: hidden; }
  body.chat-active { height: 100%; min-height: 0; overflow: hidden; }
  body.chat-active .shell { display: flex; width: 100%; height: 100vh; min-height: 100vh; margin: 0; padding: 0; flex-direction: column; }
  @supports (height: 100svh) {
    body.chat-active .shell { height: 100svh; min-height: 100svh; }
  }
  body.chat-active .brand { flex: 0 0 auto; gap: 10px; margin: 0; padding: max(12px, env(safe-area-inset-top)) 16px 10px; border-bottom: 1px solid var(--line); background: var(--paper); }
  body.chat-active .brand-mark, body.chat-active .mark { width: 40px; height: 40px; }
  body.chat-active .brand .eyebrow { margin-bottom: 2px; font-size: 10px; letter-spacing: .12em; }
  body.chat-active .brand h1 { font-size: 18px; letter-spacing: .02em; }
  body.chat-active .brand-menu { right: 12px; }
  body.chat-active .chat { display: flex; min-height: 0; flex: 1 1 auto; padding: 8px 10px 10px; border: 0; border-radius: 0; box-shadow: none; flex-direction: column; gap: 8px; background: var(--paper); }
  body.chat-active .chat-top { flex: 0 0 auto; padding: 12px 14px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface-strong); }
  body.chat-active .chat-top .eyebrow { margin-bottom: 2px; font-size: 10px; }
  body.chat-active .chat-top h2 { font-size: 19px; }
  body.chat-active .chat-top .outline { padding: 8px 13px; }
  body.chat-active .messages { min-height: 0; max-height: none; flex: 1 1 auto; padding: 18px 16px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  body.chat-active .message { margin-bottom: 14px; }
  body.chat-active .bubble { max-width: 88%; padding: 12px 14px; }
  body.chat-active .chat-bottom { display: grid; flex: 0 0 auto; border: 0; background: transparent; }
  body.chat-active .composer { grid-template-columns: minmax(0,1fr) 56px; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface-strong); }
  body.chat-active .action-stack { gap: 8px; }
  body.chat-active .action-stack button { width: 56px; min-height: 0; border-radius: 14px; font-size: 12px; }
  body.chat-active .composer textarea { height: 120px; min-height: 120px; padding: 12px 12px 32px; font-size: 16px; }
  body.chat-active .voice-status { right: 10px; bottom: 8px; left: 10px; font-size: 11px; }
  body.chat-active .chat-scroll-note { margin-top: 22px; font-size: 10px; }
  body.chat-active .app-version { display: none; }
}
