/* Tokens and patterns: DESIGN.md is the source of truth. */
:root {
  color-scheme: light dark;
  --bg: #F2F2F7; --surface: #FFFFFF; --surface-2: #F7F7FA; --text: #1C1C1E; --text-2: #6E6E73;
  --separator: #D1D1D6; --accent: #0A66C2; --danger: #C62828; --warn: #B26A00; --ok: #2E7D32;
  --radius-group: 12px; --radius-btn: 10px; --radius-badge: 6px;
  --gutter: 16px; --tabbar: 56px;
  font-size: 17px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --surface: #1C1C1E; --surface-2: #2C2C2E; --text: #F2F2F7; --text-2: #98989F;
    --separator: #38383A; --accent: #4C9FF0; --danger: #FF6B6B; --warn: #FFB74D; --ok: #66BB6A; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 1rem/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }

/* Page */
.page { max-width: 640px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) var(--gutter) calc(var(--tabbar) + env(safe-area-inset-bottom) + 88px); }
.large-title { font-size: 1.647rem; line-height: 2rem; font-weight: 700; margin: 4px 0 0; }
.subtitle-date { color: var(--text-2); font-size: .765rem; margin: 2px 0 12px; }
.section-header { font-size: .765rem; line-height: 1.06rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin: 24px 16px 6px; display: flex; justify-content: space-between; align-items: center; }
.section-header button { background: none; border: 0; color: var(--accent); text-transform: none; letter-spacing: 0; font-weight: 400; font-size: .765rem; min-height: 32px; cursor: pointer; }
.muted { color: var(--text-2); }

/* Chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 32px; padding: 0 14px; border-radius: 16px; border: 1px solid var(--separator); background: var(--surface); font-size: .882rem; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip[aria-pressed="true"] { border-color: var(--chip, var(--accent)); color: var(--chip, var(--accent)); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 4px; background: var(--chip, var(--separator)); }

/* List group and rows */
.group { background: var(--surface); border-radius: var(--radius-group); overflow: hidden; }
.row { position: relative; display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 12px 10px 16px; background: var(--surface); touch-action: pan-y; transition: transform .15s ease-out, opacity .2s ease-out; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 52px; right: 0; border-top: .5px solid var(--separator); }
.row .bar { position: absolute; left: 0; top: 8px; bottom: 8px; width: 4px; border-radius: 0 2px 2px 0; background: var(--child, transparent); }
.row .check { flex: none; width: 44px; height: 44px; margin: -10px -8px -10px -10px; display: grid; place-items: center; background: none; border: 0; cursor: pointer; }
.row .check span { width: 24px; height: 24px; border-radius: 12px; border: 1.5px solid var(--separator); display: grid; place-items: center; }
.row.done .check span { background: var(--ok); border-color: var(--ok); }
.row.done .check span::after { content: ""; width: 6px; height: 11px; border: solid #fff; border-width: 0 2px 2px 0; transform: translateY(-1px) rotate(45deg); }
.row .body { flex: 1; min-width: 0; cursor: pointer; }
.row .title { font-size: 1rem; line-height: 1.3rem; overflow-wrap: anywhere; }
.row .meta { font-size: .765rem; line-height: 1.06rem; color: var(--text-2); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.row .time { font-variant-numeric: tabular-nums; font-weight: 600; margin-right: 4px; }
.row.overdue .title { font-weight: 600; }
.row.overdue .due { color: var(--danger); }
.row.done .title { color: var(--text-2); text-decoration: line-through; }
.row .chev { flex: none; color: var(--separator); width: 12px; }
.review-dot { flex: none; width: 24px; height: 24px; border-radius: 12px; border: 1.5px dashed var(--warn); margin-right: 2px; }
.badge { font-size: .706rem; font-weight: 600; padding: 1px 6px; border-radius: var(--radius-badge); }
.badge.warn { color: var(--warn); border: 1px solid var(--warn); }
.badge.outline { color: var(--text-2); border: 1px solid var(--separator); }
.swipe-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; font-weight: 600; color: #fff; }

/* States */
.skeleton { height: 56px; background: linear-gradient(var(--surface-2), var(--surface-2)) 52px 14px / 60% 12px no-repeat, linear-gradient(var(--surface-2), var(--surface-2)) 52px 34px / 35% 10px no-repeat, var(--surface); }
.skeleton + .skeleton { border-top: .5px solid var(--separator); }
.empty { color: var(--text-2); padding: 16px; text-align: left; }
.banner { background: var(--surface); color: var(--danger); border-radius: var(--radius-group); padding: 12px 16px; margin: 8px 0; display: flex; gap: 12px; justify-content: space-between; align-items: center; font-size: .882rem; }
.banner button { background: none; border: 0; color: var(--accent); font-weight: 600; min-height: 44px; cursor: pointer; }

/* Buttons */
.btn { min-height: 44px; padding: 0 16px; border-radius: var(--radius-btn); border: 0; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
.btn.secondary { background: var(--surface-2); color: var(--accent); }
.btn.danger { background: var(--surface-2); color: var(--danger); }
.btn:disabled { opacity: .5; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row .btn { flex: 1 1 auto; }

/* Tab bar and floating button */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-top: .5px solid var(--separator); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tabbar a { flex: 1; max-width: 128px; min-height: var(--tabbar); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--text-2); text-decoration: none; font-size: .647rem; font-weight: 500; }
.tabbar a[aria-current="page"] { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.fab { position: fixed; right: max(var(--gutter), calc((100vw - 640px) / 2 + var(--gutter))); bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 16px); width: 56px; height: 56px; border-radius: 28px; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; box-shadow: 0 4px 16px rgba(0,0,0,.18); cursor: pointer; z-index: 11; }
.fab svg { width: 26px; height: 26px; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; fill: none; }

/* Sheet */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; max-height: 88vh; overflow: auto; background: var(--bg); border-radius: 14px 14px 0 0; padding: 8px var(--gutter) calc(env(safe-area-inset-bottom) + 16px); box-shadow: 0 -4px 24px rgba(0,0,0,.2); }
.sheet .grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--separator); margin: 0 auto 12px; }
.sheet h2 { font-size: 1.176rem; margin: 4px 0 4px; }
.kv { background: var(--surface); border-radius: var(--radius-group); margin: 12px 0; }
.kv div { display: flex; justify-content: space-between; gap: 16px; padding: 12px 16px; font-size: .882rem; }
.kv div + div { border-top: .5px solid var(--separator); }
.kv dt, .kv span:first-child { color: var(--text-2); }
.kv span:last-child { text-align: right; overflow-wrap: anywhere; }
textarea, input[type=text], input[type=password], input[type=date], input[type=time], select { font: inherit; width: 100%; min-height: 44px; padding: 10px 12px; border-radius: var(--radius-btn); border: 1px solid var(--separator); background: var(--surface); color: var(--text); }
textarea { min-height: 120px; resize: vertical; }

/* Forms (Popraw) */
.form { display: grid; gap: 12px; margin-top: 8px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > span { font-size: .765rem; color: var(--text-2); padding-left: 4px; }
.field-row { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
input[type=date], input[type=time] { -webkit-appearance: none; appearance: none; min-width: 0; }

/* W klasie, Najbliższe dni */
.section-major { font-size: .882rem; color: var(--text); margin-top: 32px; }
.section-header.day { margin-top: 16px; }
.row.static { align-items: flex-start; padding-left: 20px; }
.log { margin: 4px 0 0; padding: 0; list-style: none; font-size: .882rem; line-height: 1.25rem; display: grid; gap: 4px; }
.photos { display: flex; gap: 6px; overflow-x: auto; margin: 8px 0 2px; scrollbar-width: none; }
.photos button { flex: none; padding: 0; border: 0; background: none; border-radius: 8px; overflow: hidden; width: 64px; height: 64px; cursor: pointer; }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; background: var(--surface-2); }
.photo-full { display: block; width: 100%; height: auto; border-radius: 10px; }

/* Toast */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 84px); background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 8px 10px 16px; display: flex; gap: 12px; align-items: center; font-size: .882rem; z-index: 30; max-width: calc(100vw - 32px); }
.toast button { background: none; border: 0; color: inherit; font-weight: 700; min-height: 36px; padding: 0 8px; cursor: pointer; }

/* Settings (Więcej) */
.stack { display: grid; gap: 8px; padding: 12px 16px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 10px 16px; }
.setting-row + .setting-row { border-top: .5px solid var(--separator); }
.setting-row small { display: block; color: var(--text-2); font-size: .765rem; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: .8rem; word-break: break-all; background: var(--surface-2); padding: 8px; border-radius: 8px; user-select: all; }
label.check-line { display: flex; gap: 10px; align-items: center; min-height: 44px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.group > .more { display: block; width: 100%; min-height: 44px; border: 0; border-top: .5px solid var(--separator); background: none; color: var(--accent); text-align: left; padding: 0 16px 0 52px; cursor: pointer; }
.field-row.dates { grid-auto-flow: initial; grid-template-columns: 2fr 1fr 1fr; }
.digest { white-space: pre-wrap; font: .882rem/1.35 -apple-system, BlinkMacSystemFont, system-ui, sans-serif; background: var(--surface); border-radius: var(--radius-group); padding: 12px 16px; margin: 12px 0 0; }

/* Phase 9: cards, segmented controls, row actions */
.page > .group + .group { margin-top: 12px; }
.group.card { margin-bottom: 12px; position: relative; }
.card-head { position: relative; display: flex; gap: 12px; align-items: flex-start; padding: 12px 8px 4px 20px; }
.card-head .bar { position: absolute; left: 0; top: 12px; bottom: 4px; width: 4px; border-radius: 0 2px 2px 0; background: var(--child, transparent); }
.card-head .body { flex: 1; min-width: 0; }
.card-head .title { font-size: 1rem; font-weight: 600; }
.card-head .meta { font-size: .765rem; color: var(--text-2); margin-top: 2px; }
.card-body { display: grid; gap: 10px; padding: 8px 16px 16px 20px; }
.muted-card .card-head .title { color: var(--text-2); }
.place { display: inline-block; margin-top: 4px; font-size: .882rem; color: var(--accent); text-decoration: none; min-height: 28px; }
.icon-btn { flex: none; min-width: 44px; min-height: 44px; border: 0; background: none; color: var(--text-2); font-size: 1.1rem; cursor: pointer; }
.seg-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.seg-line > span { font-size: .882rem; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { min-height: 32px; padding: 0 12px; border: 0; border-radius: 7px; background: none; font-size: .824rem; cursor: pointer; color: var(--text); }
.seg button[aria-checked="true"] { background: var(--surface); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.sheet .seg-line { margin: 12px 0; }
.small { font-size: .824rem; margin: 0; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.btn.small { min-height: 36px; font-size: .882rem; padding: 0 12px; display: inline-flex; align-items: center; text-decoration: none; }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.link-row { width: 100%; border: 0; text-align: left; cursor: pointer; color: inherit; font: inherit; }
.section-header + .group.card { margin-top: 0; }
.plan-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 16px; }
.plan-row + .plan-row { border-top: .5px solid var(--separator); }
.plan-row > input[type=checkbox] { width: 22px; height: 22px; margin-top: 11px; flex: none; accent-color: var(--accent); }
.plan-fields { flex: 1; display: grid; gap: 6px; min-width: 0; }
.plan-fields .field-row { align-items: center; }

/* Phase 14: Dzieci, Nauczyciele */
.back { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); text-decoration: none; margin: -8px 0 -4px; }
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.title-actions { display: flex; gap: 8px; padding-bottom: 2px; }
.nav-row { color: inherit; text-decoration: none; }
.nav-row .chev, .link-row .chev { color: var(--text-2); font-size: 1.2rem; }
.row .contact { display: grid; place-items: center; color: var(--accent); margin: -10px -4px; }
.row .contact svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.assignments { display: grid; gap: 8px; }
.assignment { display: grid; grid-template-columns: 1fr 1fr 44px; gap: 6px; align-items: center; }
.assignment input { grid-column: 1 / 3; }
.assignment + .assignment { padding-top: 8px; border-top: .5px solid var(--separator); }
.field-row.wide-first { grid-auto-flow: initial; grid-template-columns: 1.6fr 1fr; }
input[type=color] { width: 100%; min-height: 44px; padding: 4px; border-radius: var(--radius-btn); border: 1px solid var(--separator); background: var(--surface); }
input[type=file] { font: inherit; font-size: .882rem; }
