:root {
  color-scheme: light;
  --brand: #8b3d11;
  --brand-deep: #4c1f0c;
  --brand-strong: #6d2b0a;
  --accent: #feb030;
  --accent-ink: #3d1908;
  --canvas: #f7eee1;
  --surface: #fffaf1;
  --surface-strong: #ffffff;
  --surface-tint: #f6e2c5;
  --text: #35170b;
  --muted: #806756;
  --line: #e5d2bb;
  --danger: #a62f24;
  --success: #286d4f;
  --shadow: 0 18px 48px rgba(76, 31, 12, .16);
  --radius-lg: 24px;
  --radius-md: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: #a84c16;
  --brand-deep: #180b07;
  --brand-strong: #d06c22;
  --accent: #f5a623;
  --accent-ink: #281207;
  --canvas: #1c0e09;
  --surface: #27130c;
  --surface-strong: #32180e;
  --surface-tint: #48210f;
  --text: #fff1d7;
  --muted: #c7a88c;
  --line: #5b2b16;
  --danger: #ff8a7a;
  --success: #7fd0a8;
  --shadow: 0 18px 48px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--brand-deep); }
body { margin: 0; min-height: 100dvh; background: var(--brand-deep) url('../assets/burnt-paper-texture.png') center / cover fixed; color: var(--text); }
button, input, textarea, select { font: inherit; }
button { color: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:active { transform: scale(.98); }
a { color: inherit; text-decoration: none; }
.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; }

.app-shell { min-height: 100dvh; background: var(--canvas); }
.side-nav { display: none; }
.main-column { min-width: 0; padding-bottom: calc(98px + var(--safe-bottom)); }
.page { width: min(100%, 760px); margin: 0 auto; padding: max(22px, env(safe-area-inset-top)) 18px 32px; }
.page-wide { width: 100%; }

.brand-panel { position: relative; overflow: hidden; min-height: 174px; padding: 24px; border-radius: 30px; background: var(--brand) url('../assets/burnt-paper-texture.png') center / cover; color: #fff2d7; box-shadow: var(--shadow); }
.brand-panel::after { content: "记下"; position: absolute; right: -4px; bottom: -30px; color: var(--accent); opacity: .18; font-size: 108px; font-weight: 950; letter-spacing: -.12em; }
.brand-kicker { margin: 0 0 12px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .14em; }
.brand-panel h1 { position: relative; z-index: 1; max-width: 300px; margin: 0; font-size: clamp(34px, 10vw, 48px); line-height: 1.02; letter-spacing: -.06em; }
.brand-panel p { position: relative; z-index: 1; width: min(260px, 80%); margin: 16px 0 0; color: #f8d8bb; line-height: 1.55; }

.page-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.page-header h1 { margin: 0; font-size: 32px; letter-spacing: -.05em; }
.page-header p { margin: 5px 0 0; color: var(--muted); }
.header-actions { display: flex; gap: 8px; }

.icon { display: inline-block; width: 22px; height: 22px; flex: 0 0 auto; background: currentColor; mask: var(--icon) center / contain no-repeat; -webkit-mask: var(--icon) center / contain no-repeat; }
.icon-house { --icon: url('../assets/icons/house.svg'); }
.icon-search { --icon: url('../assets/icons/magnifying-glass.svg'); }
.icon-settings { --icon: url('../assets/icons/gear-six.svg'); }
.icon-plus { --icon: url('../assets/icons/plus.svg'); }
.icon-back { --icon: url('../assets/icons/arrow-left.svg'); }
.icon-more { --icon: url('../assets/icons/dots-three.svg'); }
.icon-trash { --icon: url('../assets/icons/trash.svg'); }
.icon-download { --icon: url('../assets/icons/download-simple.svg'); }
.icon-moon { --icon: url('../assets/icons/moon.svg'); }
.icon-sun { --icon: url('../assets/icons/sun.svg'); }
.icon-file { --icon: url('../assets/icons/file-text.svg'); }
.icon-right { --icon: url('../assets/icons/caret-right.svg'); }
.icon-close { --icon: url('../assets/icons/x.svg'); }
.icon-check { --icon: url('../assets/icons/check.svg'); }
.icon-edit { --icon: url('../assets/icons/pencil-simple.svg'); }
.icon-clock { --icon: url('../assets/icons/clock.svg'); }
.icon-warning { --icon: url('../assets/icons/warning-circle.svg'); }
.icon-restore { --icon: url('../assets/icons/arrow-counter-clockwise.svg'); }
.icon-shield { --icon: url('../assets/icons/shield-check.svg'); }

.icon-button { display: inline-grid; place-items: center; width: 46px; height: 46px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: var(--surface-strong); cursor: pointer; }
.primary-button, .secondary-button, .danger-button, .text-button { min-height: 46px; border-radius: 999px; padding: 0 20px; border: 1px solid transparent; font-weight: 760; cursor: pointer; transition: transform .16s ease, background .16s ease; }
.primary-button { background: var(--accent); color: var(--accent-ink); box-shadow: 0 8px 20px rgba(254, 176, 48, .24); }
.secondary-button { background: var(--surface-strong); border-color: var(--line); }
.danger-button { background: var(--danger); color: #fff; }
.text-button { min-height: 40px; padding: 0 10px; background: transparent; color: var(--brand-strong); }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }
.button-row > button { flex: 1; }

.draft-summary { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; margin: 18px 0 28px; padding: 18px; border-radius: var(--radius-lg); background: var(--accent); color: var(--accent-ink); box-shadow: 0 12px 28px rgba(120, 60, 12, .16); cursor: pointer; }
.draft-summary strong { display: block; font-size: 19px; }
.draft-summary p { margin: 6px 0 0; opacity: .74; }
.draft-count { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 50%; background: rgba(255,255,255,.55); font-size: 20px; font-weight: 900; }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 28px 2px 12px; }
.section-title h2 { margin: 0; font-size: 16px; letter-spacing: -.02em; }
.section-title span { color: var(--muted); font-size: 13px; }
.timeline-group { margin-bottom: 28px; }
.timeline-list { border-top: 1px solid var(--line); }
.desktop-detail { display: none; }
.record-row { display: grid; grid-template-columns: 58px 1fr auto; gap: 10px; align-items: start; min-height: 76px; padding: 17px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
.record-row:hover { color: var(--brand-strong); }
.record-time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.record-content { margin: 0; font-size: 16px; line-height: 1.55; }
.record-row .icon { width: 18px; height: 18px; margin-top: 3px; color: var(--muted); }

.empty-state { padding: 52px 22px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius-lg); background: color-mix(in srgb, var(--surface) 88%, transparent); }
.empty-state img { width: 86px; height: 86px; border-radius: 25px; }
.empty-state h2 { margin: 18px 0 8px; font-size: 24px; }
.empty-state p { max-width: 320px; margin: 0 auto 20px; color: var(--muted); line-height: 1.6; }

.bottom-nav { position: fixed; z-index: 20; left: 12px; right: 12px; bottom: calc(10px + var(--safe-bottom)); display: grid; grid-template-columns: 1fr 1fr 74px 1fr; align-items: end; height: 70px; padding: 8px 8px 6px; border: 1px solid color-mix(in srgb, var(--line) 70%, transparent); border-radius: 24px; background: color-mix(in srgb, var(--surface-strong) 92%, transparent); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.nav-item { display: flex; min-width: 0; min-height: 52px; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 0; background: transparent; color: var(--muted); font-size: 11px; cursor: pointer; }
.nav-item.active { color: var(--brand-strong); font-weight: 800; }
.nav-item .icon { width: 21px; height: 21px; }
.record-fab { align-self: end; width: 64px; height: 64px; margin: 0 auto 17px; border: 5px solid var(--surface-strong); border-radius: 50%; background: var(--accent); color: var(--accent-ink); box-shadow: 0 12px 30px rgba(113, 51, 9, .32); cursor: pointer; }
.record-fab .icon { width: 26px; height: 26px; }

.field, .search-box { display: grid; gap: 8px; margin-bottom: 16px; }
.field label { font-size: 13px; font-weight: 760; color: var(--muted); }
.field input, .field textarea, .search-input { width: 100%; border: 1px solid var(--line); border-radius: 16px; background: var(--surface-strong); color: var(--text); }
.field input, .search-input { min-height: 50px; padding: 0 15px; }
.field textarea { min-height: 108px; padding: 14px 15px; resize: vertical; line-height: 1.6; }
.search-box { position: relative; }
.search-box .icon { position: absolute; left: 16px; top: 15px; color: var(--muted); }
.search-input { padding-left: 48px; }
mark { border-radius: 4px; padding: 0 2px; background: var(--accent); color: var(--accent-ink); }

.settings-card, .draft-card, .trash-card, .consent-card { margin-bottom: 14px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface-strong); overflow: hidden; }
.setting-row { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; width: 100%; min-height: 72px; padding: 12px 16px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; }
.setting-row:last-child { border-bottom: 0; }
.setting-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px; background: var(--surface-tint); color: var(--brand-strong); }
.setting-copy strong { display: block; }
.setting-copy small { display: block; margin-top: 4px; color: var(--muted); line-height: 1.4; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 16px; background: var(--surface-tint); }
.segmented button { min-height: 40px; padding: 0 10px; border: 0; border-radius: 12px; background: transparent; cursor: pointer; }
.segmented button.active { background: var(--surface-strong); box-shadow: 0 4px 12px rgba(76,31,12,.12); font-weight: 800; }
.segmented.two-options { grid-template-columns: repeat(2, 1fr); }
.migration-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

.draft-card, .trash-card { padding: 18px; }
.card-topline { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.status-pill { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 999px; background: var(--surface-tint); color: var(--brand-strong); font-size: 12px; font-weight: 780; }
.draft-card p, .trash-card p { margin: 0 0 14px; line-height: 1.55; }
.card-meta { color: var(--muted); font-size: 12px; }

.detail-body { padding-bottom: 24px; }
.detail-content { margin: 12px 0 28px; font-size: clamp(24px, 7vw, 38px); font-weight: 800; line-height: 1.32; letter-spacing: -.04em; }
.meta-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 0 0 22px; }
.meta-item { padding: 15px; border-radius: var(--radius-md); background: var(--surface-tint); }
.meta-item span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; }
.meta-item strong { word-break: break-word; }
details.source-block { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 16px 0; }
details.source-block summary { cursor: pointer; font-weight: 760; }
details.source-block p { margin: 14px 0 0; color: var(--muted); line-height: 1.7; white-space: pre-wrap; }

.sheet-backdrop { position: fixed; z-index: 40; inset: 0; display: flex; align-items: flex-end; justify-content: center; padding: 12px; background: rgba(43, 17, 7, .56); backdrop-filter: blur(4px); }
.sheet { width: min(100%, 620px); max-height: min(88dvh, 760px); overflow: auto; padding: 20px; border-radius: 30px 30px 22px 22px; background: var(--surface); box-shadow: 0 28px 80px rgba(0,0,0,.35); animation: sheet-in .25s cubic-bezier(.16,1,.3,1); }
.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.sheet-header h2 { margin: 0; font-size: 25px; }
.composer-textarea { min-height: 160px !important; font-size: 18px; }

.processing { padding: 40px 20px; text-align: center; }
.processing-bar { width: 100%; height: 8px; margin: 24px 0; overflow: hidden; border-radius: 999px; background: var(--surface-tint); }
.processing-bar::after { content: ""; display: block; width: 42%; height: 100%; border-radius: inherit; background: var(--accent); animation: processing 1.1s ease-in-out infinite alternate; }
.source-preview { margin-bottom: 18px; padding: 15px; border-radius: var(--radius-md); background: var(--surface-tint); }
.source-preview summary { cursor: pointer; font-weight: 780; }
.source-preview p { margin: 12px 0 0; color: var(--muted); line-height: 1.6; }
.confirm-card { position: relative; margin-bottom: 14px; padding: 17px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface-strong); }
.confirm-card .remove-item { position: absolute; right: 10px; top: 10px; }
.confirm-card h3 { margin: 0 50px 16px 0; font-size: 14px; }
.optional-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.optional-fields .field { margin: 0; }
.confirm-footer { position: sticky; bottom: -20px; display: grid; gap: 8px; margin: 12px -20px -20px; padding: 14px 20px calc(14px + var(--safe-bottom)); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(14px); }
.inline-note { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 14px; background: var(--surface-tint); color: var(--muted); font-size: 13px; line-height: 1.5; }
.inline-note .icon { width: 18px; height: 18px; margin-top: 1px; color: var(--brand-strong); }

.menu-popover { position: fixed; z-index: 50; top: max(72px, env(safe-area-inset-top)); right: 18px; width: 190px; padding: 8px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface-strong); box-shadow: var(--shadow); }
.menu-popover button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 46px; padding: 0 12px; border: 0; border-radius: 12px; background: transparent; text-align: left; cursor: pointer; }
.menu-popover button:hover { background: var(--surface-tint); }
.menu-popover .danger { color: var(--danger); }

#toast-root { position: fixed; z-index: 80; left: 50%; bottom: calc(92px + var(--safe-bottom)); transform: translateX(-50%); width: min(calc(100% - 32px), 440px); pointer-events: none; }
.toast { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 54px; padding: 10px 12px 10px 16px; border-radius: 16px; background: var(--brand-deep); color: #fff3df; box-shadow: var(--shadow); pointer-events: auto; animation: toast-in .22s ease-out; }
.toast button { min-height: 38px; border: 0; border-radius: 12px; padding: 0 12px; background: var(--accent); color: var(--accent-ink); font-weight: 800; cursor: pointer; }
.error-banner { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 18px; padding: 14px; border-radius: 16px; background: color-mix(in srgb, var(--danger) 13%, var(--surface)); color: var(--danger); }

@keyframes sheet-in { from { opacity: 0; transform: translateY(30px) scale(.98); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes processing { from { transform: translateX(-25%); } to { transform: translateX(165%); } }

@media (min-width: 980px) {
  body { padding: 18px; }
  .app-shell { display: grid; grid-template-columns: 238px minmax(0, 1fr); min-height: calc(100dvh - 36px); overflow: hidden; border-radius: 34px; box-shadow: 0 28px 100px rgba(31, 10, 3, .42); }
  .side-nav { display: flex; flex-direction: column; padding: 26px 18px; background: var(--brand) url('../assets/burnt-paper-texture.png') center / cover; color: #fff1d7; }
  .side-brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 28px; font-size: 26px; font-weight: 900; }
  .side-brand img { width: 46px; height: 46px; border-radius: 14px; }
  .side-nav .nav-item { align-items: center; flex-direction: row; justify-content: flex-start; gap: 12px; margin-bottom: 5px; padding: 0 14px; border-radius: 16px; color: #f1ceb2; font-size: 14px; }
  .side-nav .nav-item.active { background: rgba(255,255,255,.13); color: #fff; }
  .side-record { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 50px; margin: 12px 4px 20px; border: 0; border-radius: 16px; background: var(--accent); color: var(--accent-ink); font-weight: 850; cursor: pointer; }
  .side-note { margin-top: auto; padding: 16px; border: 1px solid rgba(255,255,255,.14); border-radius: 18px; color: #edc7aa; font-size: 12px; line-height: 1.55; }
  .main-column { padding-bottom: 0; overflow: auto; max-height: calc(100dvh - 36px); }
  .bottom-nav { display: none; }
  .page { width: min(100%, 1160px); padding: 30px 34px 50px; }
  .desktop-grid { display: grid; grid-template-columns: minmax(420px, .9fr) minmax(390px, 1.1fr); gap: 26px; }
  .desktop-detail { display: block; position: sticky; top: 30px; align-self: start; min-height: calc(100dvh - 96px); padding: 28px; border-radius: 28px; background: var(--surface-strong); box-shadow: var(--shadow); }
  .desktop-grid .brand-panel { min-height: 210px; }
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 30px; }
  #toast-root { bottom: 26px; }
}

@media (max-width: 420px) {
  .optional-fields { grid-template-columns: 1fr; }
  .meta-grid { grid-template-columns: 1fr; }
  .record-row { grid-template-columns: 52px 1fr auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
