:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #1c1c1a;
  --muted: #76746d;
  --line: #e6e4dd;
  --accent: #2f7d5b;
  --accent-soft: #e2f0e8;
  --warn: #c2621d;
  --warn-soft: #fbeee3;
  --p: #3d6fd1;
  --c: #d19a3d;
  --f: #b0508a;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --card: #1f1f1e;
    --text: #eeede8;
    --muted: #9a988f;
    --line: #33322f;
    --accent: #5cc08f;
    --accent-soft: #1d3329;
    --warn: #f0995a;
    --warn-soft: #3a2a1d;
    --p: #7aa0ee;
    --c: #e3b766;
    --f: #dc85b9;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Kirjautuminen */
.login { max-width: 360px; margin: 20vh auto 0; padding: 0 16px; text-align: center; }
.login form { display: flex; flex-direction: column; gap: 10px; }

input, textarea {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
}
button.secondary { background: var(--line); color: var(--text); }
.link-btn { background: none; color: var(--accent); padding: 4px 6px; font-weight: 500; }
.icon-btn {
  background: none; color: var(--text);
  width: 40px; height: 40px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 22px; border-radius: 50%;
}

/* Yläpalkki */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top) + 6px) 12px 6px;
  background: var(--bg);
}
.day-title { flex: 1; background: none; color: var(--text); font-size: 18px; font-weight: 650; }
.settings-btn { font-size: 20px; color: var(--muted); }

main {
  max-width: 640px; margin: 0 auto;
  padding: 4px 16px 190px;
  display: flex; flex-direction: column; gap: 12px;
}
.card { background: var(--card); border-radius: var(--radius); padding: 16px; border: 1px solid var(--line); }

/* Yhteenveto */
.summary .big { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.summary .remaining { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.summary .remaining.over { color: var(--warn); }
.summary .remaining small { font-size: 15px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.summary .eaten { color: var(--muted); text-align: right; font-size: 14px; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 10px 0 8px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.over > i { background: var(--warn); }
.formula { font-size: 13px; color: var(--muted); }
.macros { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 14px; }
.macro { font-size: 13px; }
.macro b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.macro .bar { height: 5px; margin: 4px 0 0; }
.macro.p .bar > i { background: var(--p); }
.macro.c .bar > i { background: var(--c); }
.macro.f .bar > i { background: var(--f); }

/* Harjoitukset */
.activities h3, .entries h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.act { display: flex; justify-content: space-between; padding: 4px 0; gap: 8px; }
.act span:last-child { font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; white-space: nowrap; }
.act-note { font-size: 13px; color: var(--muted); }

/* Kirjaukset */
.entries { display: flex; flex-direction: column; gap: 8px; }
.entry { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.entry-head {
  display: grid; grid-template-columns: 48px 1fr auto; gap: 8px; align-items: start;
  width: 100%; background: none; color: var(--text); text-align: left;
  padding: 12px 14px; font-weight: 400;
}
.entry-time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px; padding-top: 1px; }
.entry-label { font-size: 12px; color: var(--muted); text-transform: capitalize; }
.entry-text { overflow: hidden; text-overflow: ellipsis; }
.entry-kcal { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.entry.pending { opacity: 0.6; }
.entry.pending .entry-kcal::after { content: "…"; }
.entry-note {
  margin: 0 14px 12px; padding: 8px 10px; border-radius: 8px;
  background: var(--warn-soft); color: var(--warn); font-size: 14px;
}
.entry-body { padding: 0 14px 14px; border-top: 1px solid var(--line); }
.item {
  display: grid; grid-template-columns: 1fr 70px 56px 28px; gap: 6px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px;
}
.item small { display: block; color: var(--muted); font-size: 12px; }
.item input { padding: 4px 6px; text-align: right; font-size: 14px; }
.item .k { text-align: right; font-variant-numeric: tabular-nums; }
.item .del { width: 28px; height: 28px; font-size: 16px; color: var(--muted); }
.entry-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.entry-actions .row { display: flex; gap: 8px; align-items: center; }
.entry-actions .row > input { flex: 1; }
.entry-actions .row input[type=time] { flex: 0 0 auto; width: auto; }
.danger { background: none; color: var(--warn); padding: 6px 0; text-align: left; font-weight: 500; }
.empty { text-align: center; color: var(--muted); }
.entry-photo { font-size: 12px; }

/* Kirjauskenttä */
.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: var(--bg); border-top: 1px solid var(--line);
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
}
.composer > * { max-width: 640px; margin-left: auto; margin-right: auto; }
.recent { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.recent:empty { display: none; }
.recent button {
  flex: 0 0 auto; background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 400; white-space: nowrap;
  max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
.log-row { display: flex; gap: 6px; align-items: flex-end; }
.log-row textarea { flex: 1; resize: none; max-height: 120px; border-radius: 20px; padding: 9px 14px; }
.camera { cursor: pointer; font-size: 22px; }
.send { width: 40px; height: 40px; border-radius: 50%; padding: 0; flex: 0 0 auto; }
.time-row { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); padding: 6px 0 0 46px; }
.time-row input { width: auto; padding: 2px 6px; font-size: 13px; border-radius: 6px; }
.photo-preview { position: relative; width: 72px; margin: 0 0 8px 46px !important; }
.photo-preview img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; display: block; }
.photo-preview button { position: absolute; top: -10px; right: -10px; width: 26px; height: 26px; background: var(--text); color: var(--bg); font-size: 16px; }

/* Asetukset */
dialog {
  border: 0; border-radius: var(--radius); padding: 20px; width: min(420px, calc(100vw - 32px));
  background: var(--card); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog h2 { margin: 0 0 12px; }
dialog label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 10px; }
dialog label input { margin-top: 4px; color: var(--text); }
dialog fieldset { border: 0; padding: 0; margin: 4px 0 0; }
dialog legend { font-weight: 600; margin-bottom: 8px; font-size: 14px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.dialog-actions .link-btn { margin-right: auto; color: var(--warn); }

.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 56px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 10px; z-index: 20;
  font-size: 14px; max-width: calc(100vw - 32px);
}
