:root {
  color-scheme: light;
  --bg: #E9EEF2;
  --surface: #FFFFFF;
  --ink: #16202B;
  --muted: #5B6875;
  --rail: #C9D3DC;
  --done: #2F7D5B;
  --warn: #9A6412;
  --danger: #A33A2C;
  --focus: #1F6FB2;
  --radius-s: 8px;
  --radius-l: 18px;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #10161D;
    --surface: #18212B;
    --ink: #E4EAF0;
    --muted: #93A1AE;
    --rail: #2A3542;
    --done: #5DB88C;
    --warn: #E0A84A;
    --danger: #E07A6B;
    --focus: #7DB6E8;
  }
}

*, *::before, *::after { box-sizing: inherit; }

html, body { margin: 0; background: var(--bg); color: var(--ink); }

body {
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 96px;
}

button, input, textarea, select { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.loading { color: var(--muted); }

/* ---------- Nagłówek dnia ---------- */
.day-head { margin: 8px 0 18px; }

.day-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 15px;
}

.icon-btn {
  border: 1px solid var(--rail);
  background: var(--surface);
  border-radius: 999px;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 18px;
}

.day-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(34px, 9vw, 52px);
  line-height: 1.02;
  letter-spacing: -0.02em;
  margin: 10px 0 4px;
}

.day-sub { color: var(--muted); margin: 0; }

.today-link {
  border: none;
  background: none;
  color: var(--focus);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* Pasek postępu: jeden segment = jedno zadanie */
.segments {
  display: flex;
  gap: 3px;
  margin: 16px 0 6px;
  height: 10px;
}

.segments span {
  flex: 1;
  border-radius: 3px;
  background: var(--rail);
  transition: background .25s ease;
}

.segments span.on { background: var(--done); }
.segments span.miss { background: var(--warn); }

.progress-text { font-size: 15px; color: var(--muted); margin: 0; }

/* ---------- Oś dnia ---------- */
.part {
  font-family: var(--display);
  font-weight: 500;
  font-size: 22px;
  margin: 28px 0 8px;
}

.timeline { list-style: none; margin: 0; padding: 0; }

.task {
  display: grid;
  grid-template-columns: 52px 22px 1fr;
  align-items: start;
  gap: 0 8px;
  padding: 10px 4px;
  border-radius: var(--radius-s);
  cursor: pointer;
  position: relative;
}

.task:hover { background: color-mix(in srgb, var(--surface) 70%, transparent); }

.task .time {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 15px;
  padding-top: 2px;
  text-align: right;
}

.task .dot-col { position: relative; height: 100%; display: flex; justify-content: center; }

.task .dot-col::before {
  content: "";
  position: absolute;
  top: -10px;
  bottom: -10px;
  width: 2px;
  background: var(--rail);
}

.task:first-child .dot-col::before { top: 12px; }
.task:last-child .dot-col::before { bottom: auto; height: 22px; }

.dot {
  position: relative;
  margin-top: 4px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 3px solid var(--area);
  background: var(--bg);
  transition: background .2s ease;
}

.task.done .dot { background: var(--area); }
.task.missed .dot { border-color: var(--warn); border-style: dashed; }

.task .body { min-width: 0; }

.task .title { margin: 0; overflow-wrap: anywhere; }
.task.done .title { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--rail); }

.task .meta { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
.task .meta .area-name { color: var(--area); }

.task .value-pill {
  display: inline-block;
  margin-left: 6px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--rail);
  font-size: 14px;
}

.task .note { margin: 4px 0 0; font-size: 14px; color: var(--muted); }

/* Wpisywanie wartości */
.value-form {
  grid-column: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.value-form input[type="text"], .value-form input[type="number"] {
  flex: 1 1 140px;
  min-width: 0;
  padding: 8px 10px;
  border-radius: var(--radius-s);
  border: 1px solid var(--rail);
  background: var(--surface);
}

.scale { display: flex; flex-wrap: wrap; gap: 4px; }

.scale button {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-s);
  border: 1px solid var(--rail);
  background: var(--surface);
  cursor: pointer;
}

/* ---------- Szczegóły ---------- */
.details-btn {
  margin-top: 6px;
  border: 1px solid var(--rail);
  background: var(--surface);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 14px;
  cursor: pointer;
  color: var(--ink);
}

.details {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: var(--radius-s);
  border-left: 3px solid var(--area, var(--rail));
  font-size: 15px;
  cursor: auto;
}

.details p { margin: 0 0 8px; }
.details p:last-child { margin-bottom: 0; }
.details .details-head { font-weight: 700; margin-top: 10px; }
.details .details-head:first-child { margin-top: 0; }
.details ul { margin: 0 0 8px; padding-left: 20px; }
.details li { margin-bottom: 3px; }

.once-extra { grid-column: 2; }

/* ---------- Przyciski ---------- */
.btn {
  border: none;
  border-radius: var(--radius-s);
  padding: 10px 16px;
  cursor: pointer;
  background: var(--ink);
  color: var(--bg);
  font-weight: 700;
}

.btn.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--rail); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Zadania jednorazowe ---------- */
.once { list-style: none; padding: 0; margin: 0; }

.once > li {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 10px;
  padding: 12px 0;
  border-top: 1px solid var(--rail);
}

.once > li > input[type="checkbox"] { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--done); }

.once .due { font-size: 14px; color: var(--muted); }
.once > li.overdue .due { color: var(--danger); font-weight: 700; }
.once .area-name { color: var(--area); }

/* ---------- Okno powodów ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--ink) 45%, transparent);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}

.sheet {
  background: var(--bg);
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: var(--radius-l) var(--radius-l) 0 0;
  padding: 22px 16px calc(22px + env(safe-area-inset-bottom, 0px));
}

.sheet h2 { font-family: var(--display); font-size: 28px; margin: 0 0 6px; line-height: 1.1; }
.sheet .lead { color: var(--muted); margin: 0 0 14px; }

.pending-day { font-family: var(--display); font-weight: 500; font-size: 19px; margin: 20px 0 6px; }

.pending {
  background: var(--surface);
  border-radius: var(--radius-s);
  padding: 12px;
  margin-bottom: 8px;
  border-left: 4px solid var(--area);
}

.pending p { margin: 0 0 8px; }

.choice { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  border: 1px solid var(--rail);
  background: var(--bg);
  border-radius: 999px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 15px;
}

.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.pending .reasons { margin-top: 8px; }

.pending textarea {
  width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-s);
  border: 1px solid var(--rail);
  background: var(--bg);
  min-height: 40px;
}

.bulk { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 8px; font-size: 15px; color: var(--muted); }

.sheet-actions {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

/* ---------- Formularze logowania ---------- */
.auth { max-width: 380px; margin: 10vh auto 0; }
.auth h1 { font-family: var(--display); font-size: 44px; margin: 0 0 6px; line-height: 1; }
.auth p { color: var(--muted); }
.auth label { display: block; margin: 14px 0 4px; font-weight: 700; }

.auth input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-s);
  border: 1px solid var(--rail);
  background: var(--surface);
}

.auth .btn { width: 100%; margin-top: 18px; padding: 12px; }
.error { color: var(--danger); font-weight: 700; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; background: var(--surface); padding: 8px; border-radius: var(--radius-s); }
#qr { margin: 12px 0; background: #fff; padding: 10px; display: inline-block; border-radius: var(--radius-s); }

/* ---------- Dolny pasek ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--rail);
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
  z-index: 10;
}

.tabbar button {
  border: none;
  background: none;
  padding: 8px 18px;
  border-radius: var(--radius-s);
  cursor: pointer;
  color: var(--muted);
  font-weight: 700;
}

.tabbar button[aria-current="page"] { color: var(--ink); background: var(--bg); }

.settings section { background: var(--surface); border-radius: var(--radius-s); padding: 14px; margin-bottom: 12px; }
.settings h2 { font-family: var(--display); font-size: 22px; margin: 0 0 8px; }
.settings p { margin: 4px 0; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: var(--radius-s);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 30;
  max-width: 90vw;
}

#toast.show { opacity: 1; }

.empty { color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
