/* 方向 B「数据台」色板（任务书 13.2）：深色为主，浅色等价；四种类型色相不变。 */
:root {
  --bg: #0d0f12;
  --surface: #16191e;
  --border: #262b33;
  --divider: #1e2228;
  --text: #e6e8eb;
  --muted: #9ba1a9;
  --inv-bg: #e6e8eb;
  --inv-fg: #0d0f12;
  --accent: #5e9bff;
  --accent-fg: #8ab6ff;
  --good: #3dd08f;
  --good-line: rgba(61, 208, 143, 0.4);
  --bad: #ff6b6b;
  --bad-line: rgba(255, 107, 107, 0.4);
  --warn-text: #ffc46b;
  --warn-tint: rgba(255, 184, 77, 0.1);
  --warn-border: rgba(255, 184, 77, 0.45);
  --work: #8ab6ff;
  --work-rgb: 94, 155, 255;
  --study: #c7adff;
  --study-rgb: 180, 140, 255;
  --health: #3dd08f;
  --health-rgb: 61, 208, 143;
  --life: #ffc46b;
  --life-rgb: 255, 184, 77;
  --tint-a: 0.16;
  --line-a: 0.45;
  --shadow: none;
  --font:
    -apple-system, 'PingFang SC', 'Helvetica Neue', 'Noto Sans CJK SC', 'Microsoft YaHei', system-ui,
    sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #dce0e5;
    --divider: #eef0f3;
    --text: #14171c;
    --muted: #5b636d;
    --inv-bg: #14171c;
    --inv-fg: #ffffff;
    --accent: #2f6feb;
    --accent-fg: #1d5bd6;
    --good: #0e7a52;
    --good-line: rgba(22, 128, 88, 0.4);
    --bad: #e5484d;
    --bad-line: rgba(229, 72, 77, 0.4);
    --warn-text: #8f5300;
    --warn-tint: rgba(245, 165, 36, 0.12);
    --warn-border: rgba(245, 165, 36, 0.5);
    --work: #1d5bd6;
    --work-rgb: 47, 111, 235;
    --study: #6a3fc9;
    --study-rgb: 124, 77, 219;
    --health: #0e7a52;
    --health-rgb: 22, 128, 88;
    --life: #9a5b00;
    --life-rgb: 210, 122, 18;
    --tint-a: 0.1;
    --shadow: 0 6px 20px rgba(20, 23, 28, 0.12);
  }
}

* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
.mono {
  font-family: var(--mono);
}
.muted {
  color: var(--muted);
}
button {
  font-family: inherit;
  cursor: pointer;
}
button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 顶栏 */
.top {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 18px) 20px 10px;
}
.stamp {
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--muted);
  text-transform: uppercase;
}
h1 {
  margin: 2px 0 0;
  font-size: 26px;
  font-weight: 600;
}

/* 消息流 */
.stream {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
}
.stream > :first-child {
  margin-top: auto;
}
.sep {
  align-self: center;
  font-size: 11px;
  color: var(--muted);
  padding: 4px 0;
}
.bubble {
  align-self: flex-end;
  max-width: min(300px, 82%);
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  background: var(--inv-bg);
  color: var(--inv-fg);
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.pending {
  opacity: 0.7;
}

/* 卡片 */
.card {
  align-self: stretch;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px 8px;
}
.card-head .title {
  font-size: 15px;
  font-weight: 600;
  min-width: 0;
  overflow-wrap: anywhere;
}
.badge {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  white-space: nowrap;
}
.badge.warn {
  color: var(--warn-text);
  border-color: var(--warn-border);
  background: var(--warn-tint);
}
.cells {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 0 14px 10px;
}
.cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  text-align: left;
  min-height: 44px;
}
.cell .k {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--muted);
}
.cell .v {
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.cell.inferred {
  border-color: var(--warn-border);
  background: var(--warn-tint);
}
.cell.inferred .k {
  color: var(--warn-text);
}
.cell.t-work {
  border-color: rgba(var(--work-rgb), var(--line-a));
  background: rgba(var(--work-rgb), var(--tint-a));
}
.cell.t-work .k {
  color: var(--work);
}
.cell.t-study {
  border-color: rgba(var(--study-rgb), var(--line-a));
  background: rgba(var(--study-rgb), var(--tint-a));
}
.cell.t-study .k {
  color: var(--study);
}
.cell.t-health {
  border-color: rgba(var(--health-rgb), var(--line-a));
  background: rgba(var(--health-rgb), var(--tint-a));
}
.cell.t-health .k {
  color: var(--health);
}
.cell.t-life {
  border-color: rgba(var(--life-rgb), var(--line-a));
  background: rgba(var(--life-rgb), var(--tint-a));
}
.cell.t-life .k {
  color: var(--life);
}
.edit {
  padding: 10px 14px;
  border-top: 1px solid var(--divider);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hint {
  font-size: 11px;
  color: var(--muted);
}
.chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.chip {
  height: 34px;
  padding: 0 12px;
  border-radius: 17px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
}
.chip[aria-pressed='true'] {
  background: var(--inv-bg);
  color: var(--inv-fg);
  border-color: var(--inv-bg);
}
.actions {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 6px;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--divider);
}
.actions button,
.primary {
  height: 44px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
}
.primary {
  border: none;
  background: var(--inv-bg);
  color: var(--inv-fg);
  font-size: 15px;
  font-weight: 600;
}
.primary:disabled {
  opacity: 0.5;
  cursor: default;
}
.ghost {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
}
.ghost.reject {
  color: var(--muted);
}
.ghost.small {
  height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}
.card.done {
  opacity: 0.6;
}
.card.done .actions,
.card.done .edit {
  display: none;
}

.card.written,
.card.failed {
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.card.written {
  border-color: var(--good-line);
}
.card.written.todo {
  border-color: var(--border);
}
.card.failed {
  border-color: var(--bad-line);
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 4px;
  background: var(--good);
  flex-shrink: 0;
}
.card.written.todo .dot {
  background: var(--muted);
}
.card.failed .dot {
  background: var(--bad);
}
.card .body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.card .body .title {
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.card .body .meta {
  font-size: 11.5px;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.card.rejected {
  border-style: dashed;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 13px;
}
.top-actions {
  display: flex;
  gap: 8px;
}
.card.stats {
  padding: 12px 14px;
}
.card.stats .text {
  margin: 0;
  font: inherit;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

/* 输入栏 */
.composer {
  flex-shrink: 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 12px);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
}
.field {
  flex: 1;
  height: 48px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  padding: 0 6px 0 16px;
  gap: 6px;
}
.field input {
  flex: 1;
  min-width: 0;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 16px; /* ≥16px 避免 iOS 自动缩放 */
  outline: none;
}
.field input::placeholder {
  color: var(--muted);
}
.send {
  width: 36px;
  height: 36px;
  border-radius: 18px;
  border: none;
  background: transparent;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.send:not(:disabled) {
  color: var(--text);
}
.mic {
  width: 56px;
  height: 56px;
  border-radius: 28px;
  border: none;
  background: var(--inv-bg);
  color: var(--inv-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  transform: translateX(-50%) translateY(8px);
  background: var(--inv-bg);
  color: var(--inv-fg);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.15s,
    transform 0.15s;
  max-width: calc(100vw - 32px);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%);
}

/* 登录页 */
body.login {
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.login-box {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-box form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-box input {
  height: 48px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0 14px;
  font-size: 16px;
  font-family: var(--mono);
}
.login-box .primary {
  height: 48px;
}
.login-box .small {
  font-size: 12px;
}
code {
  font-family: var(--mono);
  font-size: 0.92em;
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}
