/* ================================================================ colour schemes
   The real colours come from the database (palette + schemes, migration 003) and are set as
   variables on <html>. These values are only the fallback before the first start.
   Fallback = scheme Ruhig (light) and Dunkel (dark) from Konzept/Farben.md */
:root {
  --bg: #FCF7F2; --surface: #FFFFFF; --surface-2: #F2EBDE; --ink: #344042; --muted: #4F4843;
  --line: #F2EBDE; --line-strong: #DDD1C3;
  --accent: #003D54; --accent-ink: #003D54; --accent-soft: #CCF2FA; --on-accent: #FFFFFF;
  --p1: #3B0012; --p1-soft: #FFD9DE; --p2: #5C4500; --p2-soft: #FFF2D4; --p3: #002C60; --p3-soft: #C0E6FF;
  --good: #124F00; --good-soft: #E3FAE0;
  --overlay: rgba(52, 64, 66, .45);
  --shadow: 0 1px 2px rgba(52, 64, 66, .08);
  --r: 16px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #344042; --surface: #4F4843; --surface-2: #344042; --ink: #E4EEEF; --muted: #D0DDDD;
  --line: rgba(228, 238, 239, .14); --line-strong: rgba(228, 238, 239, .32);
  --accent: #7DCEFF; --accent-ink: #7DCEFF; --accent-soft: #002C60; --on-accent: #002C60;
  --p1: #FF9EAD; --p1-soft: #3B0012; --p2: #FFDE8F; --p2-soft: #5C4500; --p3: #BFABF7; --p3-soft: #330066;
  --good: #BAF2B5; --good-soft: #124F00;
  --overlay: rgba(0, 0, 0, .6);
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
/* the page itself never scrolls, only #app (iOS moves fixed bars when the page scrolls) */
html.app-shell, html.app-shell body { height: 100%; overflow: hidden; overscroll-behavior: none; }
html.app-shell #app { height: 100%; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }
html.app-shell #app:has(> .overlay) { overflow: hidden; }
body { font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-ink); font-weight: 700; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ================================================================ layout */
.screen { max-width: 640px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 16px) 16px 32px; display: flex; flex-direction: column; gap: 16px; }
.screen.with-nav { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.screen.narrow { max-width: 420px; padding-top: calc(env(safe-area-inset-top) + 56px); }
.center { display: flex; justify-content: center; padding: 48px 0; }
.center.full { height: 80vh; align-items: center; }
.center-text { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.strong { font-weight: 800; }
.pad { padding: 4px 4px 8px; }
.pad-l { padding: 18px; }

/* ================================================================ header */
.top { display: flex; align-items: flex-end; gap: 10px; padding-top: 8px; }
.top-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.top-sub { font-size: 14px; font-weight: 600; color: var(--muted); }
.title { margin: 0; font-size: 30px; font-weight: 800; line-height: 1.15; }
.top-actions { display: flex; gap: 8px; }
.h2 { margin: 0; font-size: 19px; font-weight: 800; }
.label { margin: 0 4px; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 800; display: flex; align-items: center; gap: 6px; }
.label-btn { border: 0; background: none; padding: 6px 4px; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 800; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; }
.count { font-size: 12px; font-weight: 800; color: var(--muted); background: var(--surface-2); border-radius: 10px; padding: 1px 7px; letter-spacing: 0; }

/* ================================================================ buttons */
.icon-btn { width: 44px; height: 44px; flex: none; border-radius: 14px; border: 0; background: var(--surface); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; box-shadow: var(--shadow); position: relative; }
.icon-btn.solid { background: var(--accent); color: var(--on-accent); }
.icon-btn .dot { position: absolute; top: 9px; right: 10px; width: 9px; height: 9px; border-radius: 50%; background: var(--p1); border: 2px solid var(--surface); }
.btn { min-height: 48px; border-radius: 14px; border: 0; padding: 0 20px; font-weight: 800; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.ghost { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line-strong); }
.btn.small { min-height: 40px; font-size: 14px; padding: 0 14px; }
.btn.danger, .menu-row.danger { color: var(--p1); }
.btn:disabled { opacity: .55; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 2px 16px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 40px; border: 0; border-radius: 20px; padding: 0 14px; background: var(--surface); color: var(--ink); font-weight: 700; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; box-shadow: inset 0 0 0 1px var(--line); }
.chip.on { background: var(--accent); color: var(--on-accent); box-shadow: none; }
.chip.on .count { background: rgba(255, 255, 255, .25); color: inherit; }
.chip.ghost { background: transparent; color: var(--muted); }
.chip.small { min-height: 34px; font-size: 13px; padding: 0 12px; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; background: var(--surface-2); border-radius: 14px; padding: 4px; }
.seg-btn { min-height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 700; font-size: 14px; padding: 0 6px; }
.seg-btn.on { background: var(--surface); color: var(--ink); font-weight: 800; box-shadow: var(--shadow); }
.seg.small .seg-btn { min-height: 38px; font-size: 13px; }
.seg.wrap { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.seg-btn.on.p1 { color: var(--p1); } .seg-btn.on.p2 { color: var(--p2); } .seg-btn.on.p3 { color: var(--p3); }

/* ================================================================ capture (Today) */
.capture { background: var(--surface); border-radius: 20px; padding: 10px; display: flex; flex-direction: column; gap: 8px; box-shadow: var(--shadow); }
.capture-types { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.capture-types::-webkit-scrollbar { display: none; }
.ctype { flex: none; min-height: 34px; border: 0; border-radius: 17px; padding: 0 12px; background: var(--surface-2); color: var(--muted); font-weight: 700; font-size: 13px; }
.ctype.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 800; }
.capture-row { display: flex; align-items: center; gap: 8px; }
.capture-row.card { padding: 6px 6px 6px 14px; }
.capture-row input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-size: 17px; padding: 10px 6px; }
.capture-hint { margin: 0 6px 2px; font-size: 12px; color: var(--muted); }

/* ================================================================ lists and rows */
.block { display: flex; flex-direction: column; gap: 8px; }
.list { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.row { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 0; background: transparent; text-align: start; border-bottom: 1px solid var(--line); min-height: 56px; }
.list > .row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; border: 0; background: transparent; text-align: start; padding: 4px 0; }
.row-title { font-size: 16px; font-weight: 700; overflow-wrap: anywhere; }
.row-meta { font-size: 13px; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 0 4px; }
.row-meta svg { vertical-align: -2px; }
.row-meta .late { color: var(--p1); font-weight: 800; }
.row-meta .clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.row-meta .pending { color: var(--p2); font-weight: 700; display: inline-flex; gap: 4px; align-items: center; }
.row-ic { color: var(--muted); display: flex; }
.row.done .row-title { text-decoration: line-through; color: var(--muted); font-weight: 600; }
.check { width: 26px; height: 26px; flex: none; border-radius: 50%; border: 2px solid var(--line-strong); background: transparent; display: inline-flex; align-items: center; justify-content: center; color: var(--on-accent); padding: 0; position: relative; }
.check::after { content: ''; position: absolute; inset: -9px; }   /* 44 px touch area */
.check.p1 { border-color: var(--p1); } .check.p2 { border-color: var(--p2); } .check.p3 { border-color: var(--p3); }
.check.on { background: var(--good); border-color: var(--good); }
.prio { font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 8px; flex: none; }
.prio.p1 { color: var(--p1); background: var(--p1-soft); } .prio.p2 { color: var(--p2); background: var(--p2-soft); } .prio.p3 { color: var(--p3); background: var(--p3-soft); }
.badge { font-size: 12px; font-weight: 800; padding: 2px 8px; border-radius: 8px; background: var(--surface-2); color: var(--muted); flex: none; }
.badge.st-new { background: var(--accent-soft); color: var(--accent-ink); }
.badge.st-pursuing { background: var(--p2-soft); color: var(--p2); }
.row.ev { cursor: pointer; }
.row.ev.tentative .row-title { font-style: italic; }
.when { width: 64px; flex: none; display: flex; flex-direction: column; font-weight: 800; color: var(--accent-ink); font-size: 15px; line-height: 1.2; }
.when-sub { font-size: 12px; color: var(--muted); font-weight: 700; }
.when-main.allday { font-size: 11.5px; line-height: 1.15; hyphens: auto; -webkit-hyphens: auto; }
.cards { display: grid; gap: 10px; }
.card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); }
.note-card { border: 0; text-align: start; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; width: 100%; }
.note-body { font-size: 14px; color: var(--muted); white-space: pre-line; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.empty { background: var(--surface); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); }
.empty p { margin: 0; }
.empty p + p { margin-top: 4px; }
.list-edit input { flex: 1; min-width: 0; border: 0; background: transparent; font-weight: 700; font-size: 16px; padding: 8px 0; }

/* calendar */
.range-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.day { display: flex; flex-direction: column; gap: 8px; }
.day-head { margin: 4px 4px 0; display: flex; justify-content: space-between; align-items: baseline; font-size: 16px; font-weight: 800; }
.day-head .muted { font-size: 14px; font-weight: 600; }
.day.is-today .day-head span:first-child { color: var(--accent-ink); }

/* more */
.menu { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.menu-row { width: 100%; min-height: 60px; display: flex; align-items: center; gap: 14px; padding: 10px 16px; border: 0; background: transparent; text-align: start; border-bottom: 1px solid var(--line); color: var(--ink); }
.menu-row:last-child { border-bottom: 0; }
.menu-row > svg:first-child { color: var(--accent-ink); flex: none; }
.menu-row.danger > svg:first-child { color: var(--p1); }
.menu-text { flex: 1; display: flex; flex-direction: column; font-weight: 700; }
.changes { margin: 0; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.card.changes { padding: 16px 16px 16px 34px; }

/* ================================================================ forms */
.field { display: flex; flex-direction: column; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field > span:first-child, .field > legend { font-size: 13px; font-weight: 800; color: var(--muted); padding: 0; }
.field input, .field select, .field textarea { width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--surface); padding: 10px 12px; font-size: 16px; }
.field textarea { resize: vertical; min-height: 80px; line-height: 1.45; }
.field input:disabled { opacity: .5; }
.field input[type="date"], .field input[type="time"], .field input[type="datetime-local"] { -webkit-appearance: none; appearance: none; }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.code-input { font-size: 26px !important; letter-spacing: .3em; text-align: center; font-weight: 800; }
.quick-dates { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -4px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; font-weight: 700; min-height: 44px; }
.switch { width: 52px; height: 32px; border-radius: 16px; border: 0; background: var(--line-strong); position: relative; padding: 0; flex: none; }
.switch span { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: left .15s ease; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch.on { background: var(--accent); }
.switch.on span { left: 23px; }
.msg { margin: 0; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; display: flex; flex-direction: column; gap: 10px; }
.msg.bad { background: var(--p1-soft); color: var(--p1); }
.brand-mark { width: 64px; height: 64px; border-radius: 20px; background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center; margin: 0 auto; }

/* ================================================================ bottom navigation */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); background: var(--surface); box-shadow: 0 -1px 0 var(--line); display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
.nav-item { border: 0; background: none; min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 700; }
.nav-item.on { color: var(--accent-ink); font-weight: 800; }

/* ================================================================ sheets (pop-ups from below) */
.overlay { position: fixed; inset: 0; z-index: 10; background: var(--overlay); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; max-height: calc(100% - env(safe-area-inset-top) - 24px); overflow-y: auto; overscroll-behavior: contain; background: var(--bg); border-radius: 24px 24px 0 0; padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; box-shadow: 0 -8px 30px rgba(0, 0, 0, .18); will-change: transform; }
.sheet.in { animation: sheet-in .24s ease-out; }
@keyframes sheet-in { from { transform: translateY(40%); opacity: .4; } to { transform: none; opacity: 1; } }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 4px auto 2px; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet .field input, .sheet .field select, .sheet .field textarea { background: var(--surface); }
.sheet-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 4px; }
.sheet-actions .btn.primary { min-width: 140px; }

/* ================================================================ feedback */
.toast { position: fixed; z-index: 20; left: 16px; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); max-width: 520px; margin: 0 auto; background: var(--ink); color: var(--bg); border-radius: 14px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 700; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); }
.toast { pointer-events: none; }   /* never blocks the buttons below it */
.toast-btn { pointer-events: auto; border: 0; background: transparent; color: var(--accent-soft); font-weight: 800; min-height: 36px; padding: 0 6px; }
:root[data-theme="dark"] .toast-btn { color: var(--accent); }
.offline-bar { position: sticky; top: 0; z-index: 6; background: var(--p2-soft); color: var(--p2); font-weight: 800; font-size: 13px; padding: calc(env(safe-area-inset-top) + 6px) 16px 6px; display: flex; gap: 6px; align-items: center; justify-content: center; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
/* ================================================================ motion modes (attributes set by assets/motion.js from the database)
   data-elastic   on|off   spring at the edges (assets/elastic.js)
   data-transitions none|subtle|playful
   data-entrance  on|off   lists and cards fly in when a screen opens
   data-press     on|off   buttons give way when pressed */
.elastic-back { transition: transform .45s cubic-bezier(.22, 1.25, .36, 1) !important; }
.chip, .seg-btn, .ctype, .check, .switch, .switch span { transition: background-color .15s ease, color .15s ease, left .15s ease; }
[data-transitions="playful"] .sheet.in { animation: sheet-in-fun .42s cubic-bezier(.2, .9, .3, 1.25); }
@keyframes sheet-in-fun { from { transform: translateY(60%); } to { transform: none; } }
[data-entrance="on"] main.enter .row, [data-entrance="on"] main.enter .card, [data-entrance="on"] main.enter .empty,
[data-entrance="on"] main.enter .menu-row, [data-entrance="on"] main.enter .day-head {
  animation: rise-in .42s cubic-bezier(.2, .9, .3, 1.2) both; animation-delay: calc(var(--i, 0) * 40ms); }
@keyframes rise-in { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
[data-press="on"] button:active:not(:disabled), [data-press="on"] .row:active { transform: scale(.96); transition: transform .12s ease; }
[data-press="on"] .check.on { animation: pop .3s cubic-bezier(.2, .9, .3, 1.6); }
@keyframes pop { 0% { transform: scale(.7); } 100% { transform: scale(1); } }
/* Focus: nothing moves */
[data-transitions="none"] *, [data-transitions="none"] *::before, [data-transitions="none"] *::after { animation: none !important; transition: none !important; }
/* the phone's "reduce motion" always wins */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .spinner { animation: spin 2s linear infinite !important; }
}
