:root {
  --bg: #f6f3ee;
  --card: #ffffff;
  --ink: #2c2620;
  --muted: #8a8076;
  --line: #e7e0d6;
  --accent: #e8843c;
  --accent-soft: #f6c99a;
  --good: #6a994e;
}
* { box-sizing: border-box; }
html, body { overflow-x: hidden; max-width: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; }
.paw { font-size: 30px; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.sync { display: flex; align-items: center; gap: 12px; }
.sync-status { font-size: 13px; color: var(--muted); }
#sync-btn {
  border: 0; background: var(--accent); color: #fff; font-weight: 600;
  padding: 9px 16px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
#sync-btn:hover { filter: brightness(1.05); }
#sync-btn:disabled { opacity: .55; cursor: default; }

main { max-width: 1100px; margin: 24px auto; padding: 0 20px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px; }

.summary { display: grid; grid-template-columns: minmax(220px, 1fr) 2fr; gap: 22px; }
@media (max-width: 720px) { .summary { grid-template-columns: 1fr; } }
.today-card, .stats-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px 22px; box-shadow: 0 1px 2px rgba(0,0,0,.03); min-width: 0;
}
.today-card {
  background: linear-gradient(150deg, #fbe9d6, #fff);
  display: flex; flex-direction: column; justify-content: center;
}
.today-label { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.today-value { font-size: 48px; font-weight: 700; line-height: 1.05; margin: 6px 0 2px; color: var(--accent); }
.today-value .unit { font-size: 22px; margin-left: 4px; color: var(--accent); }
.today-sub { color: var(--muted); font-size: 12.5px; }
.stats { width: 100%; border-collapse: collapse; font-size: 14px; }
.stats th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase;
  letter-spacing: .03em; padding: 4px 10px 10px; border-bottom: 1px solid var(--line); }
.stats th.num, .stats td.num { text-align: right; font-variant-numeric: tabular-nums; }
.stats td { padding: 9px 10px; border-bottom: 1px solid var(--line); }
.stats tbody tr:last-child td { border-bottom: 0; }
.stats .wlabel { font-weight: 600; }
.stats .wdays { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.stats-note { color: var(--muted); font-size: 11.5px; margin: 12px 0 0; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px 22px; box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card h2 { margin: 0; font-size: 17px; }
.note { margin: 4px 0 14px; color: var(--muted); font-size: 12.5px; }
.controls { display: flex; align-items: center; gap: 10px; }
.controls input, .controls select {
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
  font-size: 13px; background: #fff; color: var(--ink);
}
.row-count { color: var(--muted); font-size: 12.5px; }
.chart-wrap { height: 340px; }

.table-wrap { overflow-x: auto; margin-top: 8px; max-height: 560px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  position: sticky; top: 0; background: var(--card); text-align: left;
  padding: 10px 12px; border-bottom: 2px solid var(--line); cursor: pointer;
  white-space: nowrap; user-select: none;
}
thead th.num { text-align: right; }
thead th:hover { color: var(--accent); }
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: #faf7f2; }
.tag { padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.tag.takeFood { background: #e7f0e0; color: var(--good); }
.tag.planFeeding { background: #fdeede; color: var(--accent); }
.tag.manualFeeding { background: #eee7f6; color: #7a5ea8; }
.empty { color: var(--muted); padding: 30px; text-align: center; }

/* ---------- phone ---------- */
@media (max-width: 720px) {
  .topbar { padding: 14px 16px; flex-wrap: wrap; gap: 10px; }
  .sync { flex: 1 1 100%; justify-content: space-between; }
  main { margin: 16px auto; padding: 0 14px; gap: 16px; }
  .card, .today-card, .stats-card { padding: 16px 16px; }
  .today-value { font-size: 42px; }
  .card-head { align-items: flex-start; }
  .controls { flex-wrap: wrap; width: 100%; }
  .controls input { flex: 1 1 140px; min-width: 0; }

  /* the wide events table becomes a stacked card list */
  .table-wrap { overflow: visible; max-height: none; margin-top: 12px; }
  #events { display: block; }
  #events thead { display: none; }
  #events tbody { display: flex; flex-direction: column; gap: 10px; }
  #events tbody tr {
    display: block; background: var(--card);
    border: 1px solid var(--line); border-radius: 12px; padding: 10px 13px;
  }
  #events tbody tr:hover { background: var(--card); }
  #events tbody td {
    display: flex; align-items: baseline; justify-content: space-between; gap: 14px;
    padding: 4px 0; border-bottom: 1px solid #f3eee5; white-space: normal; text-align: right;
  }
  #events tbody td:last-child { border-bottom: 0; }
  #events tbody td::before {
    content: attr(data-label); flex: none; text-align: left;
    color: var(--muted); font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .03em;
  }
  #events tbody td[data-label="Time"] {
    justify-content: flex-start; font-weight: 600; padding-bottom: 7px; text-align: left;
  }
  #events tbody td[data-label="Time"]::before { display: none; }
  #events tbody td.empty { display: block; text-align: center; }
  #events tbody td.empty::before { display: none; }

  /* keep the stats table inside its card on narrow screens */
  .stats { font-size: 12.5px; }
  .stats th, .stats td { padding-left: 6px; padding-right: 6px; }
  .stats th:first-child, .stats td:first-child { padding-left: 0; }
  .stats th:last-child, .stats td:last-child { padding-right: 0; }
  .stats .wdays { display: block; margin-left: 0; }
}
