:root {
  --bg: #0b1622;
  --panel: #13212f;
  --panel-2: #1b2d3f;
  --line: #263a4d;
  --text: #e8f1f8;
  --muted: #8aa2b5;
  --accent: #4cc3ff;
  --water: #3ba7e6;
  --coffee: #b07a4a;
  --pee: #e0b84c;
  --poop: #8a6a4a;
  --urge: #e05c6a;
  --food: #5cba7d;
  --danger: #e05c6a;
  --ok: #5cba7d;
  --warn: #e0b84c;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.error { color: var(--danger); }

/* ---- login ---- */
.screen { min-height: 100vh; }
#login { display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 32px 24px; width: 100%; max-width: 340px; text-align: center;
  display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 4px 0 0; font-size: 1.6rem; }
.login-card p { margin: 0; }
.logo { font-size: 3rem; line-height: 1; }
input, select {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; font-size: 1rem; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); }

/* ---- top bar / tabs ---- */
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 10px 12px calc(env(safe-area-inset-top) * 0); padding-top: 12px;
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 8px;
}
.brand { font-weight: 700; }
.sync { justify-self: end; font-size: 1.4rem; color: var(--muted); }
.sync.ok { color: var(--ok); }
.sync.pending { color: var(--warn); }
.sync.offline { color: var(--danger); }
.tabs { grid-column: 1 / -1; display: flex; gap: 6px; margin-top: 8px; }
.tab {
  flex: 1; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 4px; font-size: 0.9rem; font-weight: 600;
}
.tab.active { background: var(--accent); color: #04263a; border-color: var(--accent); }

.tab-panel { padding: 14px; max-width: 720px; margin: 0 auto; }

/* ---- time row ---- */
.time-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; margin-bottom: 12px;
}
.time-row strong { color: var(--accent); }
.time-adjust { margin-left: auto; display: flex; gap: 6px; }
.time-adjust button, .day-nav button {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 0.85rem;
}

/* ---- big log grid ---- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.big {
  border: none; border-radius: 18px; color: #06202e; font-weight: 700;
  font-size: 1.15rem; padding: 22px 10px; display: flex; flex-direction: column;
  align-items: center; gap: 6px; min-height: 96px; cursor: pointer;
}
.big span { font-size: 0.95rem; }
.big:active { transform: scale(0.97); }
.big.water { background: var(--water); }
.big.coffee { background: var(--coffee); color: #fff; }
.big.pee { background: var(--pee); }
.big.poop { background: var(--poop); color: #fff; }
.big.urge { background: var(--urge); color: #fff; }
.big.food { background: var(--food); }

/* ---- recent + entry lists ---- */
.recent { margin-top: 18px; }
.recent h3, .tab-panel h3 { margin: 18px 0 8px; font-size: 1rem; }
#recent-list, .entry-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.entry {
  display: flex; align-items: center; gap: 10px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.entry .ico { font-size: 1.3rem; }
.entry .txt { flex: 1; }
.entry .txt .sub { font-size: 0.8rem; color: var(--muted); }
.entry .when { color: var(--muted); font-size: 0.85rem; }
.entry .del { background: transparent; border: none; color: var(--muted); font-size: 1.1rem; }
.entry.queued { border-style: dashed; opacity: 0.85; }

/* ---- chips / toggles (modal) ---- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.chip {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: 10px 16px; font-size: 0.95rem; cursor: pointer;
}
.chip.on { background: var(--accent); color: #04263a; border-color: var(--accent); }
.scale { display: flex; gap: 8px; }
.scale button {
  flex: 1; background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 0; font-size: 1.1rem; font-weight: 700;
}
.scale button.on { background: var(--urge); color: #fff; border-color: var(--urge); }
.field { margin: 12px 0; }
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }

/* ---- cards / stats ---- */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px;
}
.card .k { font-size: 0.78rem; color: var(--muted); }
.card .v { font-size: 1.5rem; font-weight: 700; margin-top: 2px; }
.card .u { font-size: 0.8rem; color: var(--muted); font-weight: 400; }
.card.wide { grid-column: 1 / -1; }

.chart-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 12px 0; }
.chart-box h4 { margin: 0 0 8px; font-size: 0.9rem; }
.chart-box .hint { font-size: 0.75rem; color: var(--muted); margin-top: 6px; }
.chart-canvas-wrap { position: relative; height: 190px; }

/* ---- timeline ---- */
#timeline { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }

/* ---- buttons ---- */
.btn, .btn-primary {
  display: inline-block; text-align: center; border-radius: 12px; padding: 14px 16px;
  font-size: 1rem; font-weight: 600; border: 1px solid var(--line); text-decoration: none;
  background: var(--panel-2); color: var(--text); cursor: pointer;
}
.btn-primary { background: var(--accent); color: #04263a; border-color: var(--accent); }
.btn.danger, .danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.export-buttons { display: flex; flex-wrap: wrap; gap: 10px; }
#logout { margin: 12px 0; }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.modal-card {
  background: var(--panel); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); width: 100%; max-width: 720px;
}
.modal-card h3 { margin: 0 0 8px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn, .modal-actions .btn-primary { flex: 1; }

/* ---- diary table ---- */
.diary-wrap { overflow-x: auto; }
table.diary { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.diary th, table.diary td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; white-space: nowrap; }
table.diary th { background: var(--panel-2); position: sticky; top: 0; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  padding: 12px 18px; border-radius: 999px; z-index: 30; box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
  .cards { grid-template-columns: repeat(4, 1fr); }
}
