/* 1440 · 样式(移动优先,浅/深色自适应)
 * 视觉方向:暖纸手账 —— 米白纸面、暖墨文字、茶绿点缀,衬线标题,柔和圆角。
 */

:root {
  color-scheme: light;
  --page: #f4efe6;
  --surface: #fdfbf5;
  --ink: #2b251a;
  --ink-2: #5c5442;
  --muted: #948a74;
  --hairline: #e6ddc9;
  --border: rgba(80, 65, 35, 0.10);
  --accent: #5d7a52;
  --accent-ink: #ffffff;
  --danger: #bc4327;
  --track: #ece5d4;
  --shadow: 0 1px 2px rgba(93, 77, 46, 0.05), 0 4px 14px rgba(93, 77, 46, 0.06);
  --radius: 18px;
  --serif: Georgia, "Times New Roman", "Songti SC", "STSong", "Noto Serif CJK SC", serif;
}

/* 深色:中性深灰(不带棕调),分「跟随系统」与「手动指定」两种入口,变量一致 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #131417;
    --surface: #1d1f23;
    --ink: #e8eaed;
    --ink-2: #b3b7bd;
    --muted: #83878e;
    --hairline: #33363b;
    --border: rgba(255, 255, 255, 0.08);
    --accent: #8ab380;
    --accent-ink: #14200f;
    --danger: #e5735a;
    --track: #2a2c31;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #131417;
  --surface: #1d1f23;
  --ink: #e8eaed;
  --ink-2: #b3b7bd;
  --muted: #83878e;
  --hairline: #33363b;
  --border: rgba(255, 255, 255, 0.08);
  --accent: #8ab380;
  --accent-ink: #14200f;
  --danger: #e5735a;
  --track: #2a2c31;
  --shadow: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 12px 14px calc(76px + env(safe-area-inset-bottom));
}

h1 { font-size: 23px; margin: 0; font-family: var(--serif); font-weight: 700; letter-spacing: 0.02em; }
h2 {
  font-size: 13px; margin: 0 0 10px; color: var(--muted); font-weight: 700;
  letter-spacing: 0.08em;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 2px 14px;
}

.brand { letter-spacing: 0.1em; font-weight: 700; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- 日期导航 ---------- */
.day-nav { display: flex; align-items: center; gap: 2px; }
.day-label {
  border: 0; background: none; color: var(--ink); font-size: 15px; font-weight: 600;
  padding: 6px 8px; cursor: pointer; border-radius: 8px;
}
.day-label:hover { background: var(--track); }
.icon-btn {
  border: 0; background: none; color: var(--ink-2); font-size: 22px; line-height: 1;
  width: 34px; height: 34px; border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { background: var(--track); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }

/* ---------- 24h 分布条 ---------- */
.day-strip-wrap { padding: 12px 14px 8px; }
.day-strip {
  display: flex;
  height: 26px;
  border-radius: 6px;
  overflow: hidden;
  background:
    repeating-linear-gradient(135deg, var(--track) 0 6px, transparent 6px 12px);
  gap: 0;
}
.day-strip i, .day-rows .strip i { display: block; font-style: normal; }
.day-strip .seg {
  height: 100%;
  min-width: 1px;
  box-shadow: inset -1px 0 0 var(--surface); /* 相邻段之间留出表面色缝隙 */
}
.strip-hours {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--muted); margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

/* ---------- 记录输入 ---------- */
.capture-row { display: flex; gap: 8px; align-items: stretch; }
#cap-text {
  flex: 1;
  resize: none;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: var(--page);
  color: var(--ink);
  font: inherit;
  padding: 12px;
  min-height: 48px;
  max-height: 120px;
}
#cap-text:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.mic-btn {
  width: 48px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: var(--page);
  color: var(--ink-2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.mic-btn.recording { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
.mic-btn[hidden] { display: none; }
@keyframes pulse { 50% { opacity: 0.65; } }

.capture-meta {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-top: 10px; font-size: 13px; color: var(--ink-2);
  flex-wrap: wrap; gap: 4px;
}
.end-time input {
  border: 1px solid var(--hairline); border-radius: 8px; padding: 3px 6px;
  background: var(--surface); color: var(--ink); font: inherit; font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.start-hint { color: var(--muted); }
.tz-chip {
  border: 1px solid var(--hairline); border-radius: 999px; padding: 2px 8px;
  background: var(--surface); color: var(--ink-2); font: inherit; font-size: 12px;
  cursor: pointer;
}
.tz-chip:hover { border-color: var(--accent); }
#tz-select {
  width: 100%; margin: 4px 0 8px;
  border: 1px solid var(--hairline); border-radius: 8px; padding: 6px 8px;
  background: var(--surface); color: var(--ink); font: inherit;
}

.cat-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, border-color .15s, color .15s;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.chip.active {
  border-color: var(--accent); color: var(--ink); font-weight: 600;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

.primary-btn {
  width: 100%;
  margin-top: 12px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 700;
  padding: 13px;
  cursor: pointer;
  letter-spacing: 0.12em;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: filter .15s, box-shadow .15s;
}
.primary-btn:hover { filter: brightness(1.06); }
.primary-btn:active { transform: scale(0.99); }
.primary-btn:disabled { opacity: 0.5; cursor: default; box-shadow: none; }

.ghost-btn {
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.ghost-btn:hover { background: var(--track); border-color: var(--muted); }

.danger-btn {
  border: 1px solid transparent;
  background: none;
  color: var(--danger);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
}
.danger-btn:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }

.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

.btn-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }

/* ---------- 时间轴 ---------- */
.tl-head { display: flex; align-items: center; justify-content: space-between; margin: 16px 2px 8px; }
.tl-head h2 { margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.tl-item {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
}
.tl-item:hover { border-color: var(--accent); }
.tl-time {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: var(--ink-2);
  display: flex; flex-direction: column; justify-content: center;
}
.tl-time .dur { color: var(--muted); font-size: 12px; }
.tl-body { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.tl-text { font-size: 15px; overflow-wrap: anywhere; }
.tl-cat { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 2px; }
.tl-cat .dot { width: 8px; height: 8px; border-radius: 50%; }
.tl-note { grid-column: 1 / -1; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }

/* ---------- 统计明细 ---------- */
#stats-detail summary {
  cursor: pointer; font-size: 15px; font-weight: 600; color: var(--ink);
  list-style: none; display: flex; align-items: center; gap: 6px;
}
#stats-detail summary::before { content: '▸'; color: var(--muted); transition: transform .15s; }
#stats-detail[open] summary::before { transform: rotate(90deg); }
.detail-list { margin-top: 8px; }
.detail-day {
  font-size: 12px; color: var(--muted); font-weight: 600;
  margin: 10px 0 4px; padding-bottom: 3px; border-bottom: 1px solid var(--hairline);
}
.detail-row {
  display: grid; grid-template-columns: 88px 1fr auto auto; gap: 8px;
  align-items: baseline; padding: 5px 2px; border-radius: 6px; cursor: pointer;
  font-size: 13px;
}
.detail-row:hover { background: var(--surface-2, rgba(128,128,128,.08)); }
.dr-time { font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.dr-text { min-width: 0; overflow-wrap: anywhere; }
.dr-note { display: block; font-size: 12px; color: var(--muted); }
.dr-cat { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.dr-cat .dot { width: 7px; height: 7px; border-radius: 50%; }
.dr-dur { font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }

/* ---------- 时间检查 ---------- */
.check-ok { color: var(--accent); font-size: 14px; margin: 0; font-weight: 600; }
.check-item {
  padding: 7px 10px; margin: 6px 0; border-radius: 10px; cursor: pointer;
  font-size: 13px; color: var(--ink-2);
  background: color-mix(in srgb, var(--danger) 7%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 22%, transparent);
  transition: border-color .15s;
}
.check-item:hover { border-color: var(--danger); }

/* ---------- 迁移教程 ---------- */
.migrate-guide { margin-top: 10px; }
.migrate-guide summary { cursor: pointer; font-size: 14px; color: var(--ink-2); font-weight: 600; }
.migrate-guide ol { margin: 8px 0 4px; padding-left: 20px; color: var(--ink-2); }
.migrate-guide li { margin: 6px 0; }

/* 编辑对话框:「现在」按钮与结束时间同行 */
.end-with-now { display: flex; gap: 6px; align-items: center; }
.end-with-now input { flex: 1; min-width: 0; }
.end-with-now .ghost-btn { flex: 0 0 auto; padding: 6px 10px; }
.empty-hint { color: var(--muted); text-align: center; padding: 24px 0; }

/* ---------- 区间选择 ---------- */
.range-picker { display: flex; gap: 6px; overflow-x: auto; padding: 2px; margin-bottom: 12px; scrollbar-width: none; }
.range-picker::-webkit-scrollbar { display: none; }
.range-picker button {
  flex: 0 0 auto;
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.range-picker button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }

/* ---------- 统计 ---------- */
.hero-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.tile { padding: 12px 10px; margin: 0; }
.tile-label { font-size: 12px; color: var(--muted); }
.tile-value { font-size: 17px; font-weight: 700; margin-top: 2px; font-family: var(--serif); line-height: 1.35; }

.cat-bars .row { margin-bottom: 12px; }
.cat-bars .row:last-child { margin-bottom: 0; }
.cat-bars .meta {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; margin-bottom: 4px;
}
.cat-bars .name { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); }
.cat-bars .name .dot { width: 9px; height: 9px; border-radius: 50%; }
.cat-bars .val { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.cat-bars .bar { height: 10px; background: var(--track); border-radius: 5px; overflow: hidden; }
.cat-bars .bar > i { display: block; height: 100%; border-radius: 5px; }

.day-rows .drow {
  display: grid; grid-template-columns: 68px 1fr 44px; gap: 8px; align-items: center;
  margin-bottom: 6px; font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.day-rows .strip {
  display: flex; height: 14px; border-radius: 4px; overflow: hidden;
  background: repeating-linear-gradient(135deg, var(--track) 0 5px, transparent 5px 10px);
}
.day-rows .strip .seg { height: 100%; box-shadow: inset -1px 0 0 var(--surface); min-width: 1px; }
.day-rows .dtotal { text-align: right; }

.top-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.top-table th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  border-bottom: 1px solid var(--hairline); padding: 4px 6px;
}
.top-table td { padding: 7px 6px; border-bottom: 1px solid var(--hairline); }
.top-table tr:last-child td { border-bottom: 0; }
.top-table td:nth-child(2), .top-table td:nth-child(3),
.top-table th:nth-child(2), .top-table th:nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.top-table .t-cat { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; }

/* ---------- AI ---------- */
#ai-question {
  width: 100%; border: 1px solid var(--hairline); border-radius: 10px;
  background: var(--page); color: var(--ink); font: inherit; padding: 10px; resize: vertical;
}
.ai-status { margin-top: 10px; font-size: 14px; color: var(--ink-2); }
.ai-status.error { color: var(--danger); }
.report { margin-top: 14px; font-size: 15px; }
.report h1, .report h2, .report h3 { font-size: 16px; margin: 14px 0 6px; color: var(--ink); }
.report p { margin: 6px 0; }
.report ul, .report ol { margin: 6px 0; padding-left: 22px; }
.report li { margin: 3px 0; }
.report table { border-collapse: collapse; width: 100%; font-size: 13px; margin: 8px 0; }
.report th, .report td { border: 1px solid var(--hairline); padding: 4px 8px; text-align: left; }
.report code { background: var(--track); border-radius: 4px; padding: 1px 5px; font-size: 13px; }
.report blockquote { margin: 6px 0; padding: 2px 12px; border-left: 3px solid var(--hairline); color: var(--ink-2); }

/* ---------- 设置 ---------- */
.field { display: block; margin: 10px 0; font-size: 14px; color: var(--ink-2); }
.field input, .field select {
  display: block; width: 100%; margin-top: 4px;
  border: 1px solid var(--hairline); border-radius: 10px;
  background: var(--page); color: var(--ink);
  font: inherit; padding: 10px;
}
.field input[type="color"] { padding: 2px; height: 42px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--ink-2); margin: 10px 0; }

.cat-list { list-style: none; margin: 0 0 10px; padding: 0; }
.cat-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 4px; border-bottom: 1px solid var(--hairline);
  cursor: pointer;
}
.cat-list li:last-child { border-bottom: 0; }
.cat-list .dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.cat-list .nm { flex: 1; }
.cat-list .kw { color: var(--muted); font-size: 12px; max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 底部导航 ---------- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--hairline);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tabbar button {
  flex: 1;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 12px;
  padding: 8px 0 10px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: color .15s;
}
.tabbar button.active { color: var(--accent); font-weight: 700; }
.tabbar button.active .tab-ic { transform: translateY(-1px); }
.tab-ic { font-size: 20px; line-height: 1.2; transition: transform .15s; }

/* ---------- 对话框 ---------- */
dialog {
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--ink);
  padding: 20px;
  width: min(92vw, 420px);
  margin: auto;
  box-shadow: 0 12px 40px rgba(40, 30, 10, 0.18);
}
dialog::backdrop { background: rgba(24, 22, 17, 0.44); backdrop-filter: blur(3px); }
.edit-form h2 {
  font-size: 18px; color: var(--ink); margin-bottom: 6px;
  font-family: var(--serif); letter-spacing: 0.02em;
}
.edit-form .btn-row { justify-content: flex-end; margin-top: 14px; }
.edit-form .danger-btn { margin-right: auto; }

/* ---------- 导入对话框 ---------- */
#import-dialog { width: min(94vw, 540px); }
#imp-paste {
  width: 100%; margin-top: 10px;
  border: 1px solid var(--hairline); border-radius: 10px;
  background: var(--page); color: var(--ink);
  font: inherit; font-size: 13px; padding: 10px; resize: vertical;
}
#imp-status { margin-top: 8px; color: var(--ink-2); }
#imp-status.error { color: var(--danger); }
#imp-preview { max-height: 40vh; overflow: auto; }
#imp-preview table { border-collapse: collapse; width: 100%; font-size: 12px; margin-top: 6px; }
#imp-preview th, #imp-preview td { border: 1px solid var(--hairline); padding: 3px 6px; text-align: left; }
#imp-preview th { color: var(--muted); font-weight: 500; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--surface);
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 14px;
  z-index: 30;
  max-width: 86vw;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}

@media (min-width: 700px) {
  #app { padding-top: 20px; }
}
