:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --border: #e2e6eb;
  --accent: #2563eb;
  --accent-soft: #dbe6fd;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --ok: #15803d;
  --warn: #b45309;
  --heat0: #eef2fb;
  --heat1: #1d4ed8;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --card: #171b21;
    --text: #e8ecf1;
    --muted: #98a3b3;
    --border: #2a313b;
    --accent: #3b82f6;
    --accent-soft: #1e2b45;
    --accent-text: #ffffff;
    --danger: #ef6a5b;
    --ok: #4ade80;
    --warn: #fbbf24;
    --heat0: #1b2230;
    --heat1: #60a5fa;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 1000px; margin: 0 auto; padding: 16px 16px 40px; }
header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { margin: 0; font-size: 1.45rem; }
h2 { margin: 0 0 6px; font-size: 1.05rem; }
.sub { margin: 2px 0 0; color: var(--muted); display: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; margin: 0 0 8px; }
.pill { font-size: .8rem; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); }
.pill.warn { color: var(--warn); }

.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-top: 14px; }

.tap-card { display: grid; justify-items: center; gap: 10px; text-align: center; }
#tapBtn {
  width: min(360px, 100%); height: 170px;
  border: 0; border-radius: 22px;
  background: var(--accent); color: var(--accent-text);
  font-size: 3rem; font-weight: 800; line-height: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  cursor: pointer; user-select: none; touch-action: manipulation;
  transition: transform .08s ease, box-shadow .2s ease;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
}
#tapBtn span { font-size: 1rem; font-weight: 600; opacity: .9; }
#tapBtn:active { transform: scale(.97); }
#tapBtn.flash { animation: flash .35s ease; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); } 100% { box-shadow: 0 0 0 22px transparent; } }
.today-num { font-size: 2.8rem; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.hint { font-size: .8rem; margin: 0; }

button.ghost {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 12px; font: inherit; cursor: pointer;
}
button.ghost:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: default; }

.controls { display: grid; gap: 12px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; width: fit-content; max-width: 100%; }
.seg button { background: transparent; color: var(--text); border: 0; padding: 8px 14px; font: inherit; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.custom[hidden], .card[hidden] { display: none; }
.custom { display: flex; gap: 12px; flex-wrap: wrap; }
.custom input { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--text); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 14px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.stat .label { color: var(--muted); font-size: .8rem; }
.stat .value { font-size: 1.5rem; font-weight: 750; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .detail { color: var(--muted); font-size: .8rem; }
@media (max-width: 720px) { .stats { grid-template-columns: repeat(2, 1fr); } }

.chart-box { position: relative; height: 260px; }

.heat-wrap { overflow-x: auto; }
.heat { border-collapse: separate; border-spacing: 3px; font-size: .75rem; font-variant-numeric: tabular-nums; }
.heat th { color: var(--muted); font-weight: 500; padding: 2px 4px; white-space: nowrap; }
.heat td { min-width: 34px; height: 28px; text-align: center; border-radius: 5px; }

.recent { list-style: none; margin: 0; padding: 0; }
.recent li { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); }
.recent li:last-child { border-bottom: 0; }
.recent .x { background: none; border: 0; color: var(--danger); cursor: pointer; font: inherit; padding: 2px 6px; }
.recent .tag { font-size: .75rem; color: var(--warn); margin-left: 6px; }
.recent .tag.merged { color: var(--muted); font-style: italic; }
.recent .src { font-size: .75rem; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; margin-left: 6px; }
button.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; }
.footer { margin-top: 18px; text-align: center; }

.import { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 14px; }
.import summary { cursor: pointer; list-style: revert; }
.import summary h2 { display: inline; margin: 0; }
.import[open] summary { margin-bottom: 8px; }
.import textarea, .import input[type=date], .import input[type=text] {
  font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); color: var(--text);
}
.import textarea { width: 100%; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.import-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin: 10px 0; }
.import-row label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); }
.import-row .file-btn {
  display: inline-block; color: var(--text); font-size: inherit; cursor: pointer;
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px;
}
.import-row .file-btn:hover { border-color: var(--accent); }
#importPreview { margin: 0 0 10px; }
#importPreview ul { margin: 4px 0; padding-left: 18px; }
#importPreview .warn { color: var(--warn); }
#importPreview .ok { color: var(--ok); }
button.primary {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 10px;
  padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer;
}

/* Read-only dashboard for management: ?report */
body.report .no-report { display: none !important; }
body.report .recent .x { display: none; }
body.report .sub { display: block; }

/* Print / Save as PDF — sized to fit one Letter/A4 page. */
@page { margin: 0.4in; }
@media print {
  :root { --bg: #fff; --card: #fff; --text: #000; --muted: #444; --border: #ccc; --heat0: #eef2fb; --heat1: #1d4ed8; --accent: #2563eb; }
  body { background: #fff; font-size: 12px; }
  .no-print, .no-report { display: none !important; }
  .sub { display: block; }
  .card, .stat { break-inside: avoid; }
  .pill { display: none; }
  main { max-width: none; padding: 0; }
  h1 { font-size: 1.3rem; }
  h2 { font-size: .95rem; margin-bottom: 2px; }
  .card { padding: 10px 12px; margin-top: 8px; border-radius: 8px; }
  .stats { grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
  .stat { padding: 8px 10px; border-radius: 8px; }
  .stat .value { font-size: 1.2rem; }
  .small { margin-bottom: 4px; }
  /* The canvas fills its box; app.js redraws the bitmap at print size in beforeprint. */
  .chart-box { height: 190px; }
  .chart-box canvas { width: 100% !important; height: 100% !important; }
  /* Browsers drop backgrounds when printing unless told not to — the heatmap needs them. */
  .heat td, .stat, .card { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .heat { font-size: .7rem; border-spacing: 2px; width: 100%; }
  .heat td { height: 20px; min-width: 0; }
  .heat-wrap { overflow: visible; }
  .footer { margin-top: 8px; }
}
