:root {
  --bg: #F4EFE6;
  --bg-elev: #FFFCF7;
  --ink: #2A221C;
  --muted: #7A6E64;
  --line: #E4D9CC;
  --accent: #2F6F5E;
  --accent-ink: #F4FBF8;
  --accent-soft: #E3F0EB;
  --peach: #E08A58;
  --gold: #9A6B1F;
  --gold-fill: #FFF6E3;
  --danger: #9B3D32;
  --danger-soft: #F8E8E5;
  --shadow: 0 10px 28px rgba(42, 34, 28, 0.07);
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #161311;
  --bg-elev: #231E1A;
  --ink: #F3EDE6;
  --muted: #A89B90;
  --line: #3A322C;
  --accent: #7CB9A4;
  --accent-ink: #10211B;
  --accent-soft: #1E332C;
  --peach: #E0A07A;
  --gold: #E0B861;
  --gold-fill: #3A2F16;
  --danger: #E08A80;
  --danger-soft: #3A201D;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { height: 100%; }
body {
  min-height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.app {
  width: min(100%, 42rem);
  margin: 0 auto;
  padding: calc(20px + var(--safe-top)) 18px calc(40px + var(--safe-bot));
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: block;
}
h1 {
  margin: 0;
  font-size: 1.7rem;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.tag {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.intro {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.98rem;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--bg-elev);
  box-shadow: var(--shadow);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.theme-icon {
  width: 20px;
  height: 20px;
  display: block;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='12' r='4'/><path fill='none' stroke='black' stroke-width='2' stroke-linecap='round' d='M12 3v1.5M12 19.5V21M3 12h1.5M19.5 12H21M5.6 5.6l1.1 1.1M17.3 17.3l1.1 1.1M5.6 18.4l1.1-1.1M17.3 6.7l1.1-1.1'/></svg>") center / contain no-repeat;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><circle cx='12' cy='12' r='4'/><path fill='none' stroke='black' stroke-width='2' stroke-linecap='round' d='M12 3v1.5M12 19.5V21M3 12h1.5M19.5 12H21M5.6 5.6l1.1 1.1M17.3 17.3l1.1 1.1M5.6 18.4l1.1-1.1M17.3 6.7l1.1-1.1'/></svg>") center / contain no-repeat;
}
html[data-theme="dark"] .theme-icon {
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M16.5 13.5A7 7 0 0 1 10.5 4a7.5 7.5 0 1 0 9 9 7 7 0 0 1-3-0.5z'/></svg>") center / contain no-repeat;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M16.5 13.5A7 7 0 0 1 10.5 4a7.5 7.5 0 1 0 9 9 7 7 0 0 1-3-0.5z'/></svg>") center / contain no-repeat;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.stat {
  background: var(--bg-elev);
  border-radius: 18px;
  padding: 14px 10px 12px;
  box-shadow: var(--shadow);
  text-align: center;
  min-width: 0;
}
.stat .label {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.02em;
  margin: 0 0 6px;
}
.stat .value {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.stat .value.up { color: var(--accent); }
.stat .value.down { color: var(--peach); }

.card {
  background: var(--bg-elev);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 20px;
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
h2 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.legend, .count, .fine, .hint {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 0;
}
.legend { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  box-shadow: inset 0 0 0 2px var(--accent);
  background: var(--accent);
  margin-right: -2px;
}
.dot.estimated {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--gold);
}

.chart { width: 100%; height: 220px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .area { fill: var(--accent); opacity: 0.14; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .pt { fill: var(--accent); stroke: var(--bg-elev); stroke-width: 2; }
.chart .pt.est { fill: var(--bg-elev); stroke: var(--gold); stroke-width: 2.5; }

.preview {
  text-align: center;
  background: var(--accent-soft);
  border-radius: 18px;
  padding: 16px 12px 14px;
  margin: 4px 0 18px;
}
.preview-label, .preview-unit {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.preview-value {
  margin: 2px 0 0;
  font-size: clamp(3rem, 14vw, 4.25rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.preview-value.empty {
  color: var(--muted);
  font-size: 2.4rem;
  letter-spacing: 0.18em;
  font-weight: 500;
  line-height: 1.2;
}


.fields { display: grid; gap: 12px; }
.field span {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 6px;
}
.field input,
.field input[type="date"] {
  width: 100%;
  font-size: 1.25rem;
  min-height: 56px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  appearance: none;
  -webkit-appearance: none;
}
.field input::placeholder { color: var(--muted); opacity: 0.7; }
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 14px 0 4px;
  font-size: 0.95rem;
  color: var(--ink);
}
.check input {
  width: 22px;
  height: 22px;
  margin-top: 1px;
  accent-color: var(--accent);
  flex: none;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.form-actions .primary { flex: 1; }
.btn {
  min-height: 50px;
  padding: 0 16px;
  border: 0;
  border-radius: 14px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  border: 1.5px solid var(--line);
}
.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}
.btn.danger {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}
.btn.mic { display: inline-flex; align-items: center; gap: 8px; }
.btn.listening {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}
.mic-icon {
  width: 16px;
  height: 16px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 14a3 3 0 0 0 3-3V6a3 3 0 1 0-6 0v5a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.9V21h2v-3.1A7 7 0 0 0 19 11h-2z'/></svg>") center / contain no-repeat;
  mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M12 14a3 3 0 0 0 3-3V6a3 3 0 1 0-6 0v5a3 3 0 0 0 3 3zm5-3a5 5 0 0 1-10 0H5a7 7 0 0 0 6 6.9V21h2v-3.1A7 7 0 0 0 19 11h-2z'/></svg>") center / contain no-repeat;
}
.text-btn {
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}
.hint { margin-top: 10px; min-height: 1.2em; }

.log { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.row:last-child { border-bottom: 0; }
.row-main { min-width: 0; }
.row-date {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.row-weight {
  margin: 2px 0 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.badge {
  display: inline-block;
  margin-left: 8px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--gold);
  background: var(--gold-fill);
  border-radius: 999px;
  padding: 2px 8px;
  vertical-align: middle;
}
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions .btn { min-height: 40px; padding: 0 12px; font-size: 0.9rem; }

.data-card h2 { margin-bottom: 8px; }
.data-card .fine { margin-bottom: 4px; line-height: 1.5; }

.install {
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bot));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  z-index: 20;
  max-width: calc(100% - 32px);
  box-shadow: var(--shadow);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 14, 0.45);
  display: grid;
  place-items: end center;
  z-index: 30;
  padding: var(--safe-bot) 12px 12px;
}
.modal-card {
  background: var(--bg-elev);
  width: min(100%, 28rem);
  border-radius: 20px;
  padding: 22px 18px 18px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 8px; font-size: 1.15rem; }
.modal-card p { margin: 0 0 8px; color: var(--muted); line-height: 1.45; }
.modal[hidden], .toast[hidden], [hidden] { display: none !important; }

.empty {
  margin: 8px 0 0;
  color: var(--muted);
  text-align: center;
  padding: 12px 0 4px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
