/* Palette = Nah&Fein app palette (mobile/src/theme/theme.js). Red only for the "Rot" traffic light. */
:root {
  --ink: #1f1913;
  --muted: #6f6456;
  --accent: #00BCD4;
  --accent-soft: #FFD54F;
  --accent-cool: #22c55e;
  --accent-warm: #F97316;
  --page: #F1F3F7;
  --card: #ffffff;
  --line: #e3e5ea;
  --red: #dc2626;

  --amp-green: var(--accent-cool);
  --amp-orange: var(--accent-warm);
  --amp-red: var(--red);

  --radius: 16px;
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

#view {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-b) + 24px);
  min-height: 100vh;
}

/* ---------- tab bar ---------- */
#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--card);
  border-top: 1px solid var(--line);
  z-index: 10;
}
#tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 11.5px; font-weight: 600;
}
#tabbar .ti { font-size: 20px; line-height: 1; }
#tabbar a.active { color: var(--accent); }
body.logged-out #tabbar { display: none; }

/* ---------- typography & layout ---------- */
h1 { font-size: 26px; line-height: 1.2; margin: 4px 0 2px; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 24px 0 10px; }
h3 { font-size: 16px; margin: 0 0 8px; }
.sub { color: var(--muted); margin: 0 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 2px rgba(31, 25, 19, 0.06);
}
.card + .card { margin-top: 12px; }

.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-weight: 600; margin-bottom: 4px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px;
  border: 0; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 700;
  cursor: pointer; text-decoration: none;
}
.btn.secondary { background: var(--page); color: var(--ink); border: 1px solid var(--line); }
.btn.ghost { background: transparent; color: var(--accent); padding: 0 8px; }
.btn.danger { background: transparent; color: var(--red); border: 1px solid var(--line); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: default; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; font-size: 18px; color: var(--ink);
}

/* ---------- home tiles ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.tile {
  aspect-ratio: 1 / 0.92;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 16px; border-radius: 20px; background: var(--card);
  text-decoration: none; color: var(--ink);
  box-shadow: 0 1px 2px rgba(31, 25, 19, 0.06);
  border-top: 5px solid var(--tile-color);
}
.tile .emoji { font-size: 34px; line-height: 1; }
.tile strong { font-size: 20px; display: block; }
.tile .status { font-size: 13px; color: var(--muted); }
.tile.food { --tile-color: var(--accent-warm); }
.tile.sport { --tile-color: var(--accent-cool); }
.tile.learn { --tile-color: var(--accent); }
.tile.reading { --tile-color: var(--accent-soft); }

/* ---------- date bar ---------- */
.datebar { display: flex; align-items: center; gap: 8px; margin: 4px 0 16px; }
.datebar .label { flex: 1; text-align: center; font-weight: 700; }
.datebar .label small { display: block; font-weight: 500; color: var(--muted); font-size: 12.5px; }

/* ---------- questions ---------- */
.q { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.q:first-child { border-top: 0; padding-top: 0; }
.q:last-child { padding-bottom: 0; }
.q .text { flex: 1; min-width: 0; }
.q .text .meta { font-size: 12.5px; color: var(--muted); }
.seg { display: inline-flex; background: var(--page); border-radius: 12px; padding: 3px; flex-shrink: 0; }
.seg button {
  min-width: 52px; min-height: 38px; padding: 0 10px; border: 0; border-radius: 9px;
  background: transparent; font-weight: 700; color: var(--muted); cursor: pointer; font-size: 14.5px;
}
.seg button.on.good { background: var(--accent-cool); color: #fff; }
.seg button.on.bad { background: var(--accent-warm); color: #fff; }
.seg button.on.neutral { background: var(--ink); color: #fff; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--page); color: var(--muted); vertical-align: middle;
}
.badge.planned { background: var(--accent); color: #fff; }
.badge.open { background: var(--accent-soft); color: var(--ink); }
.badge.good { background: var(--accent-cool); color: #fff; }
.badge.bad { background: var(--accent-warm); color: #fff; }

.pts { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 14px; white-space: nowrap; }
.pts.plus { color: #15803d; }
.pts.minus { color: var(--red); }

/* ---------- report ---------- */
.report { border-left: 6px solid var(--amp, var(--line)); }
.report.green { --amp: var(--amp-green); }
.report.orange { --amp: var(--amp-orange); }
.report.red { --amp: var(--amp-red); }
.ampel { display: flex; align-items: center; gap: 14px; }
.lights { display: flex; flex-direction: column; gap: 4px; padding: 6px; background: var(--ink); border-radius: 12px; }
.lights i { width: 14px; height: 14px; border-radius: 50%; background: #4a4038; display: block; }
.lights i.on.red { background: var(--amp-red); }
.lights i.on.orange { background: var(--amp-orange); }
.lights i.on.green { background: var(--amp-green); }
.score-big { font-size: 34px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.score-big small { font-size: 15px; font-weight: 600; color: var(--muted); }
.ampel-label { font-weight: 700; }
.provisional { display: inline-block; margin-top: 4px; font-size: 12.5px; font-weight: 700; color: var(--ink); background: var(--accent-soft); padding: 2px 8px; border-radius: 999px; }
.report ul { margin: 6px 0 0; padding-left: 20px; }
.report li { margin: 2px 0; }
.report .cols { display: grid; gap: 12px; margin-top: 14px; }
.report h4 { margin: 0; font-size: 14px; }

.list-items { list-style: none; margin: 0; padding: 0; }
.list-items li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.list-items li:first-child { border-top: 0; }

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=password], input[type=date], input[type=time], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); font-size: 16px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.set-row { display: grid; grid-template-columns: 1fr 54px 54px 64px 32px; gap: 6px; align-items: center; margin-bottom: 6px; }
.set-row input { padding: 8px 6px; min-height: 40px; min-width: 0; width: 100%; }
.set-head { font-size: 11.5px; font-weight: 700; color: var(--muted); }
.x-btn { border: 0; background: transparent; font-size: 20px; color: var(--muted); cursor: pointer; padding: 0; }

/* ---------- progress bar ---------- */
.bar { height: 12px; border-radius: 999px; background: var(--page); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent-soft); border-radius: 999px; }
.bar.done > i { background: var(--accent-cool); }

/* ---------- planning ---------- */
.week { padding: 4px 16px; }
.week-day {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 14px 0; border: 0; border-top: 1px solid var(--line); background: none;
  text-align: left; cursor: pointer; color: var(--ink);
}
.week-day:first-child { border-top: 0; }
.week-day .wd-name { width: 96px; flex-shrink: 0; font-weight: 700; }
.week-day .wd-name small { display: block; font-size: 12px; color: var(--accent); }
.week-day.today .wd-name { color: var(--accent); }
.week-day .wd-body { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.week-day .wd-target { flex-basis: 100%; font-size: 12.5px; color: var(--muted); }
.week-day .chev { color: var(--muted); font-size: 22px; line-height: 1; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; color: #fff; background: var(--area); }
.sport { --area: var(--accent-cool); }
.learn { --area: var(--accent); }
.dotmark { width: 10px; height: 10px; border-radius: 50%; background: var(--area); flex-shrink: 0; }
.group-title { margin: 16px 0 6px; font-size: 14px; color: var(--muted); }
.group-title:first-child { margin-top: 0; }

.toggles { display: grid; gap: 8px; }
.toggle {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 50px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  font-weight: 600; text-align: left; cursor: pointer; color: var(--ink);
}
.toggle .tick {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 14px;
}
.toggle.on { border-color: var(--area); }
.toggle.on .tick { background: var(--area); border-color: var(--area); }

.field-label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
div.field { margin-bottom: 12px; }
.tabs.bordered { border: 1px solid var(--line); background: var(--page); }
.daypick { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.daypick button {
  min-height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--page);
  font-weight: 700; color: var(--muted); cursor: pointer; padding: 0;
}
.daypick button.on { background: var(--accent); border-color: var(--accent); color: #fff; }

details.fold > summary {
  list-style: none; cursor: pointer; font-weight: 700;
  display: flex; justify-content: space-between; align-items: center;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: '›'; font-size: 22px; line-height: 1; color: var(--muted); transition: transform .15s; }
details.fold[open] > summary::after { transform: rotate(90deg); }
details.fold + details.fold { margin-top: 12px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 10px;
  font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- tabs ---------- */
.tabs { display: flex; background: var(--card); padding: 4px; border-radius: 12px; gap: 4px; }
.tabs button { flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent; font-weight: 700; color: var(--muted); cursor: pointer; }
.tabs button.on { background: var(--accent); color: #fff; }

/* ---------- stats & charts ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px 14px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--muted); }
.chart { width: 100%; display: block; overflow: visible; }
.chart text { font-size: 11px; fill: var(--muted); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .goal { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart-tip { min-height: 22px; font-size: 13.5px; margin-top: 6px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
table.simple { width: 100%; border-collapse: collapse; font-size: 14px; }
table.simple th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 6px 4px; }
table.simple td { padding: 7px 4px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }

/* ---------- sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(31, 25, 19, 0.4); }
.sheet-panel {
  position: relative; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(20px + var(--safe-b));
}
.sheet-panel h2 { margin-top: 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 30;
  max-width: calc(100% - 32px); font-size: 14.5px; box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
#toast.error { background: var(--red); }

.empty { text-align: center; color: var(--muted); padding: 12px 0; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login { max-width: 360px; margin: 12vh auto 0; }

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