:root {
  --paper: #f7f0df;
  --paper-2: #fffaf0;
  --ink: #28231d;
  --ink-soft: #746a5d;
  --line: #302a23;
  --orange: #ff6634;
  --orange-soft: #ffd8c8;
  --teal: #137668;
  --teal-soft: #dceee8;
  --cream-cell: #eadcb3;
  --white: #fffdf7;
  --shadow: 5px 6px 0 var(--line);
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 8%, rgba(255,255,255,.75), transparent 28rem),
    var(--paper);
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}
button, textarea, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, textarea:focus-visible, input:focus-visible, label:focus-within {
  outline: 3px solid rgba(19,118,104,.35);
  outline-offset: 2px;
}
.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; }
.muted { color: var(--ink-soft); }
.eyebrow { margin: 0 0 4px; font-size: .78rem; font-weight: 800; letter-spacing: .12em; color: var(--teal); text-transform: uppercase; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 186px minmax(0,1fr); }
.side-rail {
  position: sticky; top: 0; height: 100vh; padding: 26px 18px;
  border-right: 2px solid rgba(48,42,35,.16);
  display: flex; flex-direction: column; background: rgba(255,250,240,.65);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border: 2px solid var(--line); border-radius: 14px; background: var(--orange); color: white; font-weight: 900; box-shadow: 3px 3px 0 var(--line); transform: rotate(-2deg); }
.brand b { display: block; font-size: 1.24rem; line-height: 1.1; letter-spacing: -.03em; }
.brand small { display: block; margin-top: 4px; font: 700 .58rem/1 monospace; letter-spacing: .15em; color: var(--ink-soft); }
.desktop-nav { display: grid; gap: 8px; margin-top: 58px; }
.nav-item { display: flex; align-items: center; gap: 13px; border: 0; border-radius: 13px; padding: 12px 14px; background: transparent; text-align: left; font-weight: 760; }
.nav-item span { width: 20px; text-align: center; }
.nav-item.active { background: var(--ink); color: var(--white); transform: translateX(4px); }
.sync-pill { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 999px; font-size: .76rem; font-weight: 700; background: var(--white); }
.sync-pill i { width: 8px; height: 8px; border-radius: 50%; background: #c8b98e; }
.sync-pill.synced i { background: var(--teal); box-shadow: 0 0 0 4px var(--teal-soft); }

.main-stage { min-width: 0; }
.mobile-header, .mobile-nav { display: none; }
.view { display: none; min-height: 100vh; }
.view.active { display: block; }
#view-chat.active { display: grid; grid-template-columns: minmax(420px, 1fr) 360px; }
.chat-column { min-width: 0; height: 100vh; display: flex; flex-direction: column; padding: 28px 34px 18px; border-right: 2px solid rgba(48,42,35,.16); }
.chat-heading, .page-heading, .card-title-row, .ledger-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.chat-heading h1, .page-heading h1 { margin: 0; font-size: clamp(2rem, 4vw, 3.6rem); letter-spacing: -.065em; line-height: 1; }
.week-jump, .card-title-row button { border: 0; background: transparent; color: var(--teal); font-weight: 800; padding: 8px 0; }
.week-jump span { display: inline-block; transition: transform .18s ease; }
.week-jump:hover span { transform: translateX(4px); }

.today-strip { display: flex; gap: 8px; overflow-x: auto; padding: 20px 2px 12px; scrollbar-width: none; }
.status-chip { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 8px 11px; border: 1.5px solid var(--line); border-radius: 999px; background: rgba(255,253,247,.65); font-size: .82rem; font-weight: 760; }
.status-chip i { display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--cream-cell); font-style: normal; font-size: .7rem; }
.status-chip.done i { background: var(--orange); color: white; }

.chat-log { flex: 1; overflow-y: auto; padding: 14px 4px 28px; scrollbar-color: #cdbf9d transparent; }
.message { display: flex; gap: 10px; max-width: 82%; margin: 0 0 18px; }
.message.user { margin-left: auto; flex-direction: row-reverse; }
.assistant-dot { flex: 0 0 auto; width: 12px; height: 12px; border: 2px solid var(--line); border-radius: 50%; background: var(--orange); margin-top: 13px; }
.message-card { border: 2px solid var(--line); border-radius: 20px; padding: 14px 16px; background: var(--white); box-shadow: 3px 3px 0 rgba(48,42,35,.92); }
.message.user .message-card { background: var(--teal); color: white; border-color: var(--line); }
.message-card p { margin: 0; white-space: pre-wrap; }
.message-card p + p { margin-top: 6px; }
.message.user .muted { color: rgba(255,255,255,.75); }
.message-images { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 6px; margin-bottom: 9px; }
.message-images img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border: 1.5px solid var(--line); border-radius: 10px; background: #eee; }
.message-tag { margin-top: 9px; display: inline-flex; padding: 4px 8px; border-radius: 999px; background: rgba(255,255,255,.18); font-size: .72rem; font-weight: 760; }

.composer-wrap { position: relative; }
.composer { display: grid; grid-template-columns: 48px 1fr 50px; gap: 9px; align-items: end; padding: 9px; border: 2px solid var(--line); border-radius: 24px; background: var(--white); box-shadow: var(--shadow); }
.composer textarea { width: 100%; min-height: 46px; max-height: 132px; padding: 11px 6px 7px; resize: none; overflow-y: auto; border: 0; outline: 0; background: transparent; font-size: 1rem; line-height: 1.45; }
.photo-button, .send-button { display: grid; place-items: center; width: 46px; height: 46px; border: 2px solid var(--line); border-radius: 16px; background: var(--paper-2); font-size: 1.6rem; line-height: 1; }
.send-button { width: 48px; height: 48px; background: var(--orange); color: white; box-shadow: 2px 2px 0 var(--line); font-weight: 900; }
.composer-hint { margin: 10px 0 0; text-align: center; color: var(--ink-soft); font-size: .72rem; }
.image-preview { display: flex; gap: 8px; overflow-x: auto; margin: 0 0 10px; padding: 8px 3px; }
.preview-item { position: relative; flex: 0 0 auto; width: 78px; height: 78px; }
.preview-item img { width: 100%; height: 100%; object-fit: cover; border: 2px solid var(--line); border-radius: 15px; background: var(--white); }
.preview-item button { position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; border: 2px solid var(--line); border-radius: 50%; background: var(--ink); color: white; line-height: 1; }

.desktop-dashboard { height: 100vh; overflow-y: auto; padding: 28px 24px; display: grid; align-content: start; gap: 22px; }
.board-card { border: 2px solid var(--line); border-radius: var(--radius); background: rgba(255,253,247,.84); box-shadow: var(--shadow); }
.today-board, .mini-week, .rule-card { padding: 21px; }
.card-title-row { align-items: center; }
.card-title-row h2, .settings-card h2 { margin: 0; font-size: 1.2rem; letter-spacing: -.03em; }
.card-title-row > span { font-size: .78rem; color: var(--ink-soft); font-weight: 700; }
.today-metrics { display: grid; grid-template-columns: 1fr 1fr; margin-top: 18px; border: 1.5px solid var(--line); border-radius: 15px; overflow: hidden; }
.metric { min-height: 86px; padding: 12px; border-right: 1px solid rgba(48,42,35,.25); border-bottom: 1px solid rgba(48,42,35,.25); }
.metric:nth-child(2n) { border-right: 0; }
.metric:nth-last-child(-n+2) { border-bottom: 0; }
.metric span { display: block; color: var(--ink-soft); font-size: .72rem; font-weight: 760; }
.metric strong { display: block; margin-top: 6px; font-size: 1.25rem; line-height: 1.15; letter-spacing: -.04em; }
.rule-card { background: var(--orange); color: white; }
.rule-card p { margin: 12px 0 0; font-size: 1.2rem; font-weight: 800; line-height: 1.45; }
.rule-index { display: inline-block; border-bottom: 2px solid rgba(255,255,255,.7); padding-bottom: 3px; font-size: .72rem; font-weight: 850; letter-spacing: .08em; }

.mini-hm, .full-hm { display: grid; gap: 5px; margin-top: 18px; }
.hm-row { display: grid; grid-template-columns: 42px repeat(7,minmax(20px,1fr)); gap: 5px; align-items: center; }
.hm-label { font-size: .68rem; color: var(--ink-soft); font-weight: 760; }
.hm-day { text-align: center; font-size: .65rem; color: var(--ink-soft); font-weight: 760; }
.cell { display: block; width: 100%; aspect-ratio: 1; border: 1.5px solid rgba(48,42,35,.5); border-radius: 5px; background: var(--cream-cell); }
.cell.done { background: var(--orange-soft); }
.cell.goal { background: var(--orange); border-color: var(--line); }
.cell.today { outline: 2px solid var(--teal); outline-offset: 2px; }

.workspace-page { max-width: 1280px; margin: 0 auto; padding: 38px 44px 80px; }
.narrow-page { max-width: 780px; }
.page-heading { align-items: flex-end; margin-bottom: 34px; }
.outline-button, .wide-outline, .inline-field button { border: 2px solid var(--line); border-radius: 14px; padding: 10px 15px; background: var(--white); box-shadow: 3px 3px 0 var(--line); font-weight: 800; }
.week-ledger { overflow: hidden; }
.ledger-head { align-items: stretch; border-bottom: 2px solid var(--line); }
.ledger-head > div { flex: 1; min-height: 112px; padding: 20px 24px; border-right: 1.5px solid var(--line); }
.ledger-head > div:last-child { border-right: 0; }
.tiny-label { display: block; color: var(--ink-soft); font-size: .78rem; font-weight: 760; }
.ledger-head strong { display: block; margin-top: 10px; font-size: clamp(1.7rem,4vw,2.7rem); letter-spacing: -.055em; }
.heatmap-wrap { overflow-x: auto; padding: 25px; }
.full-hm { min-width: 640px; gap: 8px; }
.full-hm .hm-row { grid-template-columns: 90px repeat(7,minmax(52px,1fr)); gap: 8px; }
.legend { display: flex; gap: 18px; flex-wrap: wrap; padding: 0 25px 24px; color: var(--ink-soft); font-size: .76rem; font-weight: 700; }
.legend span { display: flex; align-items: center; gap: 7px; }
.legend .cell { width: 14px; height: 14px; aspect-ratio: auto; }
.week-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 28px; margin-top: 28px; }
.insight-card, .recent-card { padding: 24px; }
.insight-card { min-height: 250px; background: var(--teal); color: white; }
.insight-card .eyebrow { color: var(--orange-soft); }
.insight-card h2 { margin: 26px 0 14px; max-width: 18ch; font-size: clamp(1.7rem,3vw,2.6rem); line-height: 1.18; letter-spacing: -.05em; }
.insight-card .muted { color: rgba(255,255,255,.72); }

.history-filters { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 24px; padding: 3px; }
.history-filters button { border: 1.5px solid var(--line); border-radius: 999px; padding: 8px 15px; background: var(--white); font-weight: 760; }
.history-filters button.active { background: var(--ink); color: white; }
.record-list { display: grid; gap: 12px; }
.record-item { display: grid; grid-template-columns: 78px 36px 1fr; gap: 16px; align-items: start; padding: 16px; border: 1.5px solid var(--line); border-radius: 16px; background: var(--white); }
.record-date { font: 800 .75rem/1.4 monospace; color: var(--ink-soft); }
.record-icon { display: grid; place-items: center; width: 34px; height: 34px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--orange-soft); }
.record-main strong { display: block; margin-bottom: 3px; }
.record-main p { margin: 0; color: var(--ink-soft); font-size: .88rem; }
.full-list .record-item { box-shadow: 3px 3px 0 rgba(48,42,35,.8); }
.empty-state { padding: 36px 20px; border: 2px dashed rgba(48,42,35,.35); border-radius: 18px; text-align: center; color: var(--ink-soft); }

.settings-card { margin-bottom: 24px; padding: 24px; }
.settings-card label { display: block; margin: 20px 0 7px; font-weight: 800; }
.inline-field { display: grid; grid-template-columns: 1fr auto; gap: 9px; }
.inline-field input { min-width: 0; border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px; background: var(--white); }
.inline-field button { background: var(--orange); color: white; }
.field-status { margin: 12px 0 0; font-size: .82rem; color: var(--ink-soft); }
.wide-outline { width: 100%; margin-top: 12px; }
.sync-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sync-actions .wide-outline { min-width: 0; }
.toast { position: fixed; left: 50%; bottom: 34px; z-index: 30; transform: translate(-50%,20px); opacity: 0; pointer-events: none; padding: 10px 16px; border: 2px solid var(--line); border-radius: 999px; background: var(--ink); color: white; font-weight: 760; transition: .18s ease; }
.toast.show { opacity: 1; transform: translate(-50%,0); }

@media (max-width: 980px) {
  .app-shell { display: block; }
  .side-rail, .desktop-dashboard { display: none; }
  .mobile-header { position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; min-height: 67px; padding: 10px 17px; border-bottom: 1.5px solid rgba(48,42,35,.25); background: rgba(247,240,223,.92); backdrop-filter: blur(14px); }
  .brand.compact { gap: 9px; }
  .brand.compact .brand-mark { width: 36px; height: 36px; border-radius: 12px; box-shadow: 2px 2px 0 var(--line); }
  .brand.compact b { font-size: 1.05rem; }
  .date-badge { border: 1.5px solid var(--line); border-radius: 999px; padding: 7px 10px; background: var(--white); font-size: .78rem; font-weight: 800; }
  #view-chat.active { display: block; }
  .chat-column { height: calc(100dvh - 68px - 66px - var(--safe-bottom)); padding: 19px 15px 10px; border-right: 0; }
  .chat-heading h1 { font-size: 2rem; }
  .today-strip { padding-top: 15px; }
  .chat-log { padding-bottom: 18px; }
  .message { max-width: 92%; }
  .composer { grid-template-columns: 44px 1fr 46px; border-radius: 21px; padding: 7px; box-shadow: 4px 4px 0 var(--line); }
  .photo-button, .send-button { width: 42px; height: 42px; border-radius: 14px; }
  .composer textarea { min-height: 42px; padding-top: 9px; }
  .composer-hint { display: none; }
  .mobile-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; display: grid; grid-template-columns: repeat(4,1fr); min-height: calc(64px + var(--safe-bottom)); padding: 7px 8px var(--safe-bottom); border-top: 1.5px solid rgba(48,42,35,.28); background: rgba(255,253,247,.96); backdrop-filter: blur(14px); }
  .mobile-nav button { display: grid; justify-items: center; gap: 2px; border: 0; background: transparent; color: var(--ink-soft); font-size: .72rem; font-weight: 760; }
  .mobile-nav button span { font-size: 1.1rem; line-height: 1; }
  .mobile-nav button.active { color: var(--teal); }
  .workspace-page { padding: 24px 15px calc(92px + var(--safe-bottom)); }
  .page-heading { align-items: center; margin-bottom: 24px; }
  .page-heading h1 { font-size: 2.15rem; }
  .outline-button { padding: 9px 12px; }
  .ledger-head { display: grid; grid-template-columns: repeat(3,1fr); gap: 0; }
  .ledger-head > div { min-height: 88px; padding: 13px; }
  .ledger-head strong { font-size: 1.32rem; }
  .week-grid { grid-template-columns: 1fr; gap: 20px; }
  .insight-card { min-height: 220px; }
  .record-item { grid-template-columns: 63px 33px 1fr; gap: 10px; padding: 14px 12px; }
  .sync-actions { grid-template-columns: 1fr; gap: 0; }
  .toast { bottom: calc(78px + var(--safe-bottom)); white-space: nowrap; max-width: calc(100vw - 30px); overflow: hidden; text-overflow: ellipsis; }
}

@media (max-width: 520px) {
  .week-jump { font-size: .8rem; }
  .today-strip { margin-right: -15px; padding-right: 15px; }
  .welcome-message .message-card { max-width: 100%; }
  .ledger-head strong { font-size: 1.12rem; }
  .ledger-head > div { padding: 11px 8px; }
  .tiny-label { font-size: .67rem; }
  .heatmap-wrap { padding: 18px 14px; }
  .legend { padding: 0 14px 18px; }
  .page-heading h1 { font-size: 1.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
