:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --axis: #c3c2b7;
  --grid: #e1e0d9;
  --border: rgba(11, 11, 11, 0.12);
  --wash: rgba(11, 11, 11, 0.05);
  --accent: #256abf;
  --on-accent: #ffffff;
  --period-predicted: rgba(227, 73, 72, 0.13);
  --period-confirmed: rgba(227, 73, 72, 0.3);
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #e87ba4;
  --s6: #008300;
  --s7: #6250d6;
  --s8: #e34948;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #a3a29a;
    --axis: #383835;
    --grid: #2c2c2a;
    --border: rgba(255, 255, 255, 0.12);
    --wash: rgba(255, 255, 255, 0.07);
    --accent: #3987e5;
    --on-accent: #ffffff;
    --period-predicted: rgba(230, 103, 103, 0.16);
    --period-confirmed: rgba(230, 103, 103, 0.36);
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --s5: #d55181;
    --s6: #008300;
    --s7: #9085e9;
    --s8: #e66767;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 17px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px 16px;
}

h1 { font-size: 22px; line-height: 1.2; margin: 0; }
h2 { font-size: 18px; line-height: 1.25; margin: 0 0 8px; }
p { margin: 0 0 10px; }

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

button { cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}

.btn {
  min-height: 48px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.wide { width: 100%; }

.muted { color: var(--muted); font-size: 15px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > .btn { flex: 1 1 130px; }

/* Spodné menu */
.tabs {
  position: fixed;
  inset: auto 0 0 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 2;
}
.tabs button {
  min-height: 60px;
  border: 0;
  background: none;
  color: var(--ink-2);
  font-size: 15px;
  font-weight: 600;
  padding: 6px 4px;
}
.tabs button[aria-current="page"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

/* Kalendár */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.cal-head h1 { text-align: center; flex: 1; font-size: 20px; }
.cal-head button {
  width: 48px; height: 48px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-size: 22px;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.cal-dow { text-align: center; font-size: 13px; color: var(--muted); padding-bottom: 2px; }
.day {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 66px;
  padding: 4px 1px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--surface);
}
.day:disabled { cursor: default; color: var(--muted); }
.day.predicted { background: var(--period-predicted); }
.day.confirmed { background: var(--period-confirmed); }
.day.today .num { background: var(--accent); color: var(--on-accent); border-radius: 999px; }
.day[aria-pressed="true"] { border: 2px solid var(--ink); padding: 3px 0; }
.num { min-width: 24px; line-height: 24px; font-size: 15px; font-weight: 600; text-align: center; }
.dots { display: grid; grid-template-columns: repeat(4, 8px); grid-auto-rows: 8px; gap: 2px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.note-mark { position: absolute; top: 5px; right: 4px; width: 7px; height: 7px; border-radius: 1px; background: var(--ink-2); }

.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; font-size: 14px; color: var(--ink-2); margin: 0; padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; gap: 7px; min-width: 0; }
.swatch { flex: none; width: 16px; height: 16px; border-radius: 4px; border: 1px solid var(--border); }
.legend .dot { flex: none; margin: 0 4px; }
.swatch.predicted { background: var(--period-predicted); }
.swatch.confirmed { background: var(--period-confirmed); }
.swatch.note { width: 7px; height: 7px; margin: 0 4px; border: 0; border-radius: 1px; background: var(--ink-2); }

.detail-list { list-style: none; margin: 0 0 12px; padding: 0; }
.detail-list li { display: flex; align-items: baseline; gap: 8px; padding: 4px 0; }
.detail-list .dot { flex: none; align-self: center; }

/* Formulár */
dialog#form {
  width: 100%;
  max-width: 560px;
  height: 100%;
  max-height: 100%;
  margin: auto;
  padding: 0;
  border: 0;
  background: var(--page);
  color: var(--ink);
  overflow: hidden;
}
dialog#form[open] { display: flex; flex-direction: column; }
dialog#form::backdrop { background: var(--page); }
.form-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 10px;
}
.form-head button {
  flex: none; width: 48px; height: 48px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); font-size: 20px;
}
.form-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 16px 12px; }
.form-foot { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface); }
.q { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 12px; margin-bottom: 8px; }
.q-main { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.q-label { font-weight: 600; min-width: 0; }
.q-hint { display: block; font-weight: 400; font-size: 14px; color: var(--muted); }
.yn { display: flex; flex: none; gap: 6px; }
.choice {
  min-width: 62px; min-height: 48px; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--page); font-weight: 600;
}
.choice[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.field { margin-top: 10px; }
.field-label { font-size: 15px; color: var(--ink-2); margin-bottom: 5px; }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.scale .choice { min-width: 0; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
textarea, input[type="date"] {
  width: 100%; border: 1px solid var(--border); border-radius: 12px;
  background: var(--page); padding: 12px; font-size: 17px;
}
input[type="date"] { min-height: 48px; }
textarea { min-height: 76px; resize: vertical; }
label.stack { display: block; font-size: 15px; color: var(--ink-2); flex: 1 1 130px; min-width: 0; }
label.stack input { margin-top: 4px; color: var(--ink); }

/* Grafy */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 44px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); font-size: 15px;
}
.chip[aria-pressed="true"] { border: 2px solid var(--ink); padding: 5px 11px; font-weight: 600; }
.stat { font-size: 30px; font-weight: 600; line-height: 1.1; }
.chart { display: block; width: 100%; height: auto; touch-action: pan-y; margin-top: 10px; }
.chart text { font-size: 12px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.readout { min-height: 24px; font-size: 15px; color: var(--ink-2); margin: 6px 0 2px; }
details summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
td:first-child { white-space: nowrap; font-variant-numeric: tabular-nums; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(76px + env(safe-area-inset-bottom));
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--ink); color: var(--page); font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 5;
}
#toast.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}
