:root {
  color-scheme: light;
  --bg: #f5f2eb;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #18312d;
  --muted: #6f7d78;
  --line: #dedfd8;
  --primary: #1f4b43;
  --primary-hover: #173d36;
  --primary-soft: #dfeae5;
  --accent: #d98368;
  --accent-soft: #f6e5dc;
  --danger: #a8493f;
  --danger-soft: #f9e5e1;
  --shadow: 0 12px 35px rgba(32, 55, 49, 0.07);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 11px;
  --sidebar: 252px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% -5%, rgba(217, 131, 104, 0.11), transparent 30rem),
    var(--bg);
}

button, input, textarea, select { font: inherit; }
button { color: inherit; }

button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }

:focus-visible {
  outline: 3px solid rgba(217, 131, 104, 0.55);
  outline-offset: 2px;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  transform: translateY(-140%);
  padding: 10px 14px;
  border-radius: 8px;
  color: white;
  background: var(--primary);
}

.skip-link:focus { transform: translateY(0); }
.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: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: var(--sidebar);
  display: flex;
  flex-direction: column;
  gap: 38px;
  padding: 34px 24px 24px;
  border-right: 1px solid rgba(31, 75, 67, 0.1);
  background: rgba(255, 253, 248, 0.83);
  backdrop-filter: blur(20px);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  color: #fff;
  background: var(--primary);
  font-family: Georgia, "Songti SC", serif;
  font-size: 21px;
  box-shadow: 0 9px 20px rgba(31, 75, 67, 0.17);
}
.brand div { display: grid; gap: 2px; }
.brand strong { font-family: Georgia, "Songti SC", serif; font-size: 21px; letter-spacing: 0.08em; }
.brand span:last-child { color: var(--muted); font-size: 12px; }

.nav-list { display: grid; gap: 8px; }
.nav-item {
  appearance: none;
  border: 0;
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  text-align: left;
  transition: 160ms ease;
}
.nav-item > span:first-child { width: 21px; font-size: 21px; text-align: center; }
.nav-item:hover { color: var(--primary); background: rgba(31, 75, 67, 0.06); }
.nav-item.is-active { color: var(--primary); background: var(--primary-soft); font-weight: 700; }

.privacy-note {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(31, 75, 67, 0.11);
  border-radius: 14px;
  background: rgba(223, 234, 229, 0.48);
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #5b987c; box-shadow: 0 0 0 5px rgba(91, 152, 124, 0.12); }
.privacy-note div { display: grid; gap: 2px; }
.privacy-note strong { font-size: 12px; }
.privacy-note span:last-child { color: var(--muted); font-size: 11px; }

.main-content { margin-left: var(--sidebar); padding: 56px clamp(28px, 5vw, 76px) 80px; }
.view { display: none; max-width: 1180px; margin: 0 auto; animation: reveal 260ms ease; }
.view.is-active { display: block; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 34px; }
.page-header h1 { margin: 4px 0 8px; font-family: Georgia, "Songti SC", serif; font-size: clamp(32px, 4vw, 52px); font-weight: 600; letter-spacing: -0.035em; line-height: 1.08; }
.eyebrow, .card-kicker { margin: 0; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase; }
.header-copy { margin: 0; color: var(--muted); line-height: 1.7; }

.button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 17px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 750;
  cursor: pointer;
  transition: transform 140ms ease, background-color 140ms ease, border-color 140ms ease;
}
.button:active { transform: translateY(1px); }
.button-primary { color: white; background: var(--primary); box-shadow: 0 10px 23px rgba(31, 75, 67, 0.14); }
.button-primary:hover { background: var(--primary-hover); }
.button-secondary { border-color: var(--line); background: var(--surface-strong); }
.button-secondary:hover { border-color: #b7bdb8; }
.button-ghost { color: var(--danger); background: transparent; }
.button-danger { color: var(--danger); border-color: rgba(168, 73, 63, 0.25); background: var(--danger-soft); }
.text-button { padding: 8px 0; border: 0; color: var(--primary); background: transparent; font-weight: 700; cursor: pointer; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-strong); cursor: pointer; font-size: 20px; }

.card { border: 1px solid rgba(31, 75, 67, 0.09); border-radius: var(--radius-lg); background: rgba(255, 253, 248, 0.92); box-shadow: var(--shadow); }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.metric-card { min-height: 142px; padding: 22px; display: flex; flex-direction: column; justify-content: space-between; }
.metric-card .metric-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.metric-card .metric-icon { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; color: var(--primary); background: var(--primary-soft); }
.metric-card strong { font-family: Georgia, "Songti SC", serif; font-size: 31px; font-weight: 600; line-height: 1; }
.metric-card strong small { margin-left: 3px; color: var(--muted); font-family: inherit; font-size: 13px; font-weight: 500; }
.metric-card > span, .metric-meta { color: var(--muted); font-size: 12px; }
.metric-trend.good { color: #4f826c; }
.metric-trend.warn { color: var(--accent); }

.insight-card { display: flex; align-items: flex-start; gap: 17px; margin-top: 16px; padding: 24px; background: linear-gradient(135deg, rgba(223, 234, 229, 0.95), rgba(255, 253, 248, 0.96)); }
.insight-icon { flex: 0 0 auto; width: 43px; height: 43px; display: grid; place-items: center; border-radius: 13px; color: white; background: var(--primary); font-size: 20px; }
.insight-card h2 { margin: 5px 0 6px; font-family: Georgia, "Songti SC", serif; font-size: 21px; }
.insight-card p:last-child { margin: 0; color: var(--muted); line-height: 1.65; }

.recent-section { margin-top: 16px; padding: 25px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.section-heading h2 { margin: 4px 0 0; font-family: Georgia, "Songti SC", serif; font-size: 23px; font-weight: 600; }
.section-heading.compact { margin-bottom: 22px; }

.record-list { display: grid; }
.record-row { display: grid; grid-template-columns: 64px minmax(0, 1fr) auto; align-items: center; gap: 16px; padding: 16px 4px; border-top: 1px solid var(--line); }
.record-row:first-child { border-top: 0; }
.record-date { width: 58px; padding: 9px 4px; display: grid; place-items: center; border-radius: 12px; background: var(--primary-soft); }
.record-date strong { font-family: Georgia, serif; font-size: 22px; line-height: 1; }
.record-date span { margin-top: 3px; color: var(--muted); font-size: 10px; }
.record-body { min-width: 0; }
.record-body strong { display: block; margin-bottom: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-body p { margin: 0; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-duration { color: var(--primary); font-family: Georgia, serif; font-size: 18px; white-space: nowrap; }
.record-row-button { appearance: none; width: 100%; border: 0; color: inherit; background: transparent; text-align: left; cursor: pointer; }
.record-row-button:hover .record-body strong { color: var(--accent); }

.empty-state { padding: 42px 20px; color: var(--muted); text-align: center; }
.empty-state .empty-icon { width: 54px; height: 54px; display: grid; place-items: center; margin: 0 auto 14px; border-radius: 17px; color: var(--primary); background: var(--primary-soft); font-size: 24px; }
.empty-state strong { display: block; margin-bottom: 7px; color: var(--ink); font-family: Georgia, "Songti SC", serif; font-size: 19px; }
.empty-state p { max-width: 420px; margin: 0 auto; line-height: 1.65; }

.toolbar { display: flex; gap: 12px; padding: 14px; margin-bottom: 16px; }
.search-box { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; padding: 0 13px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.search-box input { width: 100%; min-width: 0; padding: 10px 0; border: 0; outline: 0; background: transparent; }
select { min-height: 44px; padding: 8px 36px 8px 12px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background: #fff; }
.history-list { display: grid; gap: 12px; }
.history-group { padding: 8px 22px 2px; }
.history-group-title { margin: 8px 0 2px; color: var(--muted); font-size: 13px; font-weight: 800; }

.report-header { align-items: center; }
.segmented { display: inline-flex; padding: 4px; border: 1px solid var(--line); border-radius: 13px; background: rgba(255, 255, 255, 0.72); }
.segmented button { min-width: 54px; padding: 8px 15px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; cursor: pointer; font-weight: 700; }
.segmented button.is-active { color: white; background: var(--primary); }
.period-switcher { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px; margin-bottom: 16px; padding: 14px 16px; }
.period-switcher div { display: grid; gap: 3px; text-align: center; }
.period-switcher span { color: var(--muted); font-size: 12px; }
.report-metrics { margin-bottom: 16px; }
.report-grid { display: grid; grid-template-columns: 1.25fr 0.75fr; gap: 16px; }
.report-grid > .card { padding: 25px; }
.summary-card { background: linear-gradient(145deg, var(--primary), #2d5b51); color: white; }
.summary-card .card-kicker { color: #f1b7a4; }
.summary-card p:last-child { margin: 0; color: rgba(255,255,255,.83); font-size: 15px; line-height: 1.8; }

.bar-chart { min-height: 220px; display: flex; align-items: flex-end; gap: 10px; padding-top: 12px; }
.bar-column { flex: 1; min-width: 0; display: grid; grid-template-rows: 1fr auto; align-items: end; gap: 9px; height: 210px; text-align: center; }
.bar-track { position: relative; width: min(34px, 80%); height: 100%; margin: auto; border-radius: 10px; background: rgba(31,75,67,.06); overflow: hidden; }
.bar-fill { position: absolute; inset: auto 0 0; min-height: 3px; border-radius: 10px; background: var(--primary); transition: height 300ms ease; }
.bar-column.is-today .bar-fill { background: var(--accent); }
.bar-label { display: grid; gap: 2px; color: var(--muted); font-size: 10px; }
.bar-label strong { color: var(--ink); font-size: 12px; }

.goal-item { margin-top: 18px; }
.goal-item:first-child { margin-top: 0; }
.goal-label { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.goal-label span:last-child { color: var(--muted); }
.progress-track { height: 9px; border-radius: 999px; background: #e7e7e1; overflow: hidden; }
.progress-fill { height: 100%; border-radius: inherit; background: var(--primary); }
.progress-fill.over { background: var(--accent); }
.pattern-group + .pattern-group { margin-top: 19px; }
.pattern-group > span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 7px; }
.data-tag { padding: 6px 9px; border-radius: 999px; color: var(--primary); background: var(--primary-soft); font-size: 12px; }

.settings-grid { display: grid; gap: 16px; }
.settings-card { padding: 27px; }
.form-grid { display: grid; gap: 15px; }
.form-grid.two-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three-cols { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 20px; }
.field { display: grid; gap: 7px; }
.field > span, .tag-fieldset legend { font-size: 13px; font-weight: 750; }
.field input, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  outline: 0;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.field input:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 75, 67, 0.09); }
.field textarea { resize: vertical; min-height: 88px; }
.input-suffix { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 11px; background: #fff; overflow: hidden; }
.input-suffix:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 75, 67, 0.09); }
.input-suffix input { border: 0; border-radius: 0; box-shadow: none !important; }
.input-suffix span { padding-right: 12px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.muted { color: var(--muted); line-height: 1.7; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.data-status { margin-top: 18px; padding: 13px 15px; border-radius: 12px; color: var(--muted); background: var(--primary-soft); font-size: 12px; }
.danger-zone { border-color: rgba(168, 73, 63, 0.14); }

.record-dialog { width: min(720px, calc(100% - 28px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 24px; color: var(--ink); background: var(--surface); box-shadow: 0 30px 80px rgba(18, 37, 33, .28); }
.record-dialog::backdrop { background: rgba(16, 34, 30, 0.48); backdrop-filter: blur(5px); }
.record-dialog form { padding: 28px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 24px; }
.dialog-header h2 { margin: 4px 0 0; font-family: Georgia, "Songti SC", serif; font-size: 28px; }
.record-dialog .form-grid + .form-grid { margin-top: 15px; }
.tag-fieldset { margin: 23px 0 0; padding: 0; border: 0; }
.tag-fieldset legend { margin-bottom: 10px; }
.tag-options { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-chip { position: relative; }
.tag-chip input { position: absolute; opacity: 0; pointer-events: none; }
.tag-chip span { display: block; padding: 8px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: #fff; font-size: 12px; cursor: pointer; transition: 130ms ease; }
.tag-chip input:checked + span { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); font-weight: 700; }
.tag-chip input:focus-visible + span { outline: 3px solid rgba(217, 131, 104, 0.55); outline-offset: 2px; }
.custom-tag { margin-top: 10px; }
.custom-tag > span { color: var(--muted); font-weight: 500; }
.range-field { margin-top: 23px; }
.range-field > span { display: flex; justify-content: space-between; }
.range-field output { color: var(--accent); font-size: 16px; }
.range-field input { padding: 0; accent-color: var(--primary); }
.record-dialog textarea { margin-bottom: 4px; }
.dialog-actions { display: flex; align-items: center; gap: 10px; margin-top: 25px; padding-top: 20px; border-top: 1px solid var(--line); }
.action-spacer { flex: 1; }

.toast { position: fixed; z-index: 80; left: 50%; bottom: 28px; transform: translate(-50%, 24px); padding: 12px 18px; border-radius: 999px; color: white; background: var(--primary); box-shadow: 0 12px 32px rgba(31, 75, 67, .24); opacity: 0; pointer-events: none; transition: 180ms ease; }
.toast.is-visible { transform: translate(-50%, 0); opacity: 1; }
.floating-add, .bottom-nav { display: none; }

@media (max-width: 1000px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .report-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  :root { --radius-lg: 19px; }
  body { background: var(--bg); }
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 27px 16px calc(96px + env(safe-area-inset-bottom)); }
  .page-header { align-items: flex-start; margin-bottom: 24px; }
  .page-header h1 { font-size: 34px; }
  .header-copy { font-size: 14px; }
  .home-header .desktop-add { display: none; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .metric-card { min-height: 126px; padding: 17px; }
  .metric-card strong { font-size: 26px; }
  .insight-card { padding: 19px; }
  .recent-section, .settings-card, .report-grid > .card { padding: 19px; }
  .record-row { grid-template-columns: 55px minmax(0, 1fr) auto; gap: 11px; }
  .record-date { width: 51px; }
  .toolbar { flex-direction: column; }
  .search-box { flex-basis: 44px; }
  .report-header { align-items: flex-start; }
  .report-header .segmented { flex: 0 0 auto; }
  .form-grid.three-cols { grid-template-columns: 1fr; }
  .button-row .button { flex: 1 1 130px; }
  .bottom-nav { position: fixed; z-index: 30; inset: auto 0 0; display: grid; grid-template-columns: repeat(4, 1fr); padding: 7px 8px calc(7px + env(safe-area-inset-bottom)); border-top: 1px solid rgba(31,75,67,.1); background: rgba(255,253,248,.94); backdrop-filter: blur(18px); }
  .bottom-nav .nav-item { display: grid; justify-items: center; gap: 1px; padding: 6px; text-align: center; }
  .bottom-nav .nav-item > span:first-child { width: auto; font-size: 18px; }
  .bottom-nav small { font-size: 10px; }
  .floating-add { position: fixed; z-index: 40; right: 19px; bottom: calc(78px + env(safe-area-inset-bottom)); width: 54px; height: 54px; display: grid; place-items: center; border: 0; border-radius: 50%; color: white; background: var(--primary); box-shadow: 0 12px 27px rgba(31,75,67,.29); font-size: 28px; cursor: pointer; }
  .record-dialog { width: 100%; max-width: none; max-height: calc(100dvh - 20px); margin: auto 0 0; border-radius: 24px 24px 0 0; }
  .record-dialog form { padding: 22px 17px calc(22px + env(safe-area-inset-bottom)); }
  .record-dialog .form-grid.two-cols { grid-template-columns: 1fr 1fr; }
  .dialog-actions { position: sticky; bottom: 0; margin-inline: -17px; padding: 14px 17px calc(5px + env(safe-area-inset-bottom)); background: var(--surface); }
}

@media (max-width: 430px) {
  .page-header h1 { font-size: 30px; }
  .metric-card { min-height: 118px; padding: 15px; }
  .metric-card .metric-icon { width: 31px; height: 31px; }
  .metric-card strong { font-size: 23px; }
  .record-duration { font-size: 15px; }
  .report-header { display: grid; }
  .record-dialog .form-grid.two-cols { grid-template-columns: 1fr; }
}

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

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #101815;
    --surface: #18231f;
    --surface-strong: #1d2a25;
    --ink: #f1efe8;
    --muted: #a9b5b0;
    --line: #35443e;
    --primary: #4d8276;
    --primary-hover: #5b9185;
    --primary-soft: #253c35;
    --accent: #eda087;
    --accent-soft: #472f29;
    --danger: #ef9b90;
    --danger-soft: #432824;
    --shadow: 0 14px 38px rgba(0, 0, 0, 0.16);
  }
  body { background: radial-gradient(circle at 88% -5%, rgba(217, 131, 104, 0.08), transparent 30rem), var(--bg); }
  .sidebar, .bottom-nav { background: rgba(24, 35, 31, 0.9); }
  .card, .record-dialog { background: rgba(24, 35, 31, 0.95); }
  .insight-card { background: linear-gradient(135deg, rgba(37, 60, 53, 0.98), rgba(24, 35, 31, 0.96)); }
  .field input, .field textarea, .input-suffix, .tag-chip span, select, .search-box, .icon-button { background: var(--surface-strong); }
  .progress-track { background: #2b3733; }
  .summary-card { background: linear-gradient(145deg, #315f56, #23473f); }
  @media (max-width: 760px) { .dialog-actions { background: var(--surface); } }
}
