/* CavalPlan – gemeinsame Gestaltung für Care und Stable. Regeln: brand/GESTALTUNGSREGELN.md */
@import url('./tokens.css');

@font-face { font-family: 'Inter'; font-weight: 400; font-display: swap; src: url('/shared/fonts/inter-400.woff') format('woff'); }
@font-face { font-family: 'Inter'; font-weight: 600; font-display: swap; src: url('/shared/fonts/inter-600.woff') format('woff'); }
@font-face { font-family: 'Inter'; font-weight: 700; font-display: swap; src: url('/shared/fonts/inter-700.woff') format('woff'); }

:root {
  --bg: var(--c-paper);
  --surface: var(--c-white);
  --surface-2: #FBF9F4;
  --text: var(--c-ink);
  --text-2: var(--c-stone);
  --line: var(--c-line);
  --primary: var(--c-care);
  --primary-soft: var(--c-care-soft);
  --on-primary: var(--c-white);
  --accent: var(--c-hay);
  --focus: #1A73E8;
  --radius-s: 8px; --radius-m: 12px; --radius-l: 16px;
  --shadow: 0 1px 2px rgba(21, 48, 42, .06), 0 2px 8px rgba(21, 48, 42, .06);
  --tap: 48px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}
body[data-product='stable'] { --primary: var(--c-stable); --primary-soft: var(--c-stable-soft); }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F2420; --surface: #16302A; --surface-2: #1B3832; --text: #F1EDE3; --text-2: #B9C3BD; --line: #2C4A43;
    --primary: var(--c-care-tint); --primary-soft: #1E3F33; --on-primary: var(--c-ink); color-scheme: dark;
  }
  body[data-product='stable'] { --primary: var(--c-stable-tint); --primary-soft: #1D3546; }
  .chip--done { background: #1E3F33 !important; color: #BFE6CF !important; }
  .chip--pending { background: #3A2E12 !important; color: #F4D58C !important; }
  .chip--review, .chip--conflict { background: #44201C !important; color: #F6B8B0 !important; }
  .chip--offline { background: #26303C !important; color: #C8D3E0 !important; }
  .logo-light, .topbar .brand img.logo-light { display: none !important; } .logo-dark, .topbar .brand img.logo-dark { display: block !important; }
}
.logo-dark, .topbar .brand img.logo-dark { display: none; }
body.large-text { font-size: 19px; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 400 16px/1.5 var(--font);
  font-feature-settings: 'tnum' 1; -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 .75rem; }
a { color: var(--primary); font-weight: 600; }
small, .muted { color: var(--text-2); }
.muted { font-size: .92em; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Layout ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar .brand { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.topbar .brand img { height: 30px; width: auto; display: block; }
.topbar .spacer { flex: 1; }
.main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.main > .stack, .main > .grid-2 { margin-top: 12px; }
.main > .banner { margin-bottom: 12px; }
section.stack > h2 { margin-top: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 10px; min-height: 56px;
  color: var(--text-2); text-decoration: none; font-size: .75rem; font-weight: 600;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a[aria-current='page'] { color: var(--primary); }
.tabbar a { position: relative; }
.tabbar a .badge { position: absolute; top: 4px; left: calc(50% + 6px); }

/* Stable auf großen Bildschirmen: Seitenleiste statt Tabbar */
@media (min-width: 960px) {
  body[data-product='stable'] .app { display: grid; grid-template-columns: 240px 1fr; grid-template-rows: auto 1fr; }
  body[data-product='stable'] .topbar { grid-column: 1 / -1; }
  body[data-product='stable'] .tabbar {
    position: sticky; top: 61px; align-self: start; height: calc(100dvh - 61px); flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--line); padding: 12px 8px; gap: 2px; background: var(--surface-2);
  }
  body[data-product='stable'] .tabbar a { flex: 0; flex-direction: row; gap: 12px; justify-content: flex-start; padding: 10px 12px; border-radius: var(--radius-s); font-size: .95rem; min-height: 44px; }
  body[data-product='stable'] .tabbar a[aria-current='page'] { background: var(--primary-soft); }
  body[data-product='stable'] .tabbar a .badge { position: static; margin-left: auto; }
  body[data-product='stable'] .main { max-width: 1120px; padding-bottom: 32px; }
}

/* ---------- Karten ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 16px; box-shadow: var(--shadow); }
.card--flat { box-shadow: none; }
.card--accent { border-left: 4px solid var(--primary); }
.card h2 { margin-bottom: .25rem; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.divider { height: 1px; background: var(--line); margin: 12px 0; border: 0; }

/* ---------- Schaltflächen ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 0 18px;
  border-radius: var(--radius-m); border: 1.5px solid transparent; font: 600 1rem var(--font); cursor: pointer; text-decoration: none;
  background: var(--primary); color: var(--on-primary); transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; filter: none; }
.btn--secondary { background: var(--surface); color: var(--primary); border-color: var(--primary); }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn--danger { background: var(--c-danger); color: #fff; }
.btn--small { min-height: 40px; padding: 0 12px; font-size: .92rem; border-radius: var(--radius-s); }
.btn--block { width: 100%; }
.btn--big { min-height: 56px; font-size: 1.05rem; }
.btn svg, .syncbar svg { width: 20px; height: 20px; flex: none; }
.btn--big svg { width: 24px; height: 24px; }
.linkbtn { background: none; border: 0; color: var(--primary); font: 600 1rem var(--font); cursor: pointer; padding: 8px 0; text-decoration: underline; }

/* ---------- Status ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .82rem; font-weight: 600; line-height: 1.35; max-width: 100%; }
.chip::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.chip--done { background: var(--c-care-soft); color: var(--c-care); }
.chip--open { background: #EEEBE3; color: var(--c-stone); }
.chip--open::before { background: transparent; border: 2px solid currentColor; width: 6px; height: 6px; }
.chip--pending { background: var(--c-warn-soft); color: var(--c-hay-deep); }
.chip--review, .chip--conflict { background: var(--c-danger-soft); color: var(--c-danger); }
.chip--partial, .chip--skipped { background: var(--c-warn-soft); color: var(--c-hay-deep); }
.chip--offline { background: var(--c-slate-soft); color: var(--c-slate); }
.chip--info { background: var(--primary-soft); color: var(--primary); }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--c-danger); color: #fff; font-size: .75rem; font-weight: 700; }

/* Datenstand-Leiste: zeigt Abgleich, Offline-Zustand und wartende Aktionen */
.syncbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 16px; font-size: .9rem;
  background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.syncbar--offline { background: var(--c-slate-soft); color: var(--c-slate); }
.syncbar--pending { background: var(--c-warn-soft); color: var(--c-hay-deep); }
.syncbar strong { font-weight: 700; }
.syncbar .btn { min-height: 36px; }
@media (max-width: 600px) { .syncbar { font-size: .85rem; padding: 6px 12px; gap: 6px; } }
.syncbar .spacer { flex: 1; }

/* ---------- Aufgaben ---------- */
.task { display: grid; grid-template-columns: 56px 1fr; gap: 4px 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.task:first-child { border-top: 0; }
.task__time { font-weight: 700; font-size: 1.05rem; }
.task__body { min-width: 0; }
.task__title { font-weight: 600; }
.task__meta { color: var(--text-2); font-size: .9rem; margin-top: 2px; }
.task__actions { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.task--muted .task__title { color: var(--text-2); }
.items { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.items li { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; font-size: .92rem; }
.items li.added { border-color: var(--c-care); background: var(--c-care-soft); color: var(--c-care); font-weight: 600; }
.items li.removed { text-decoration: line-through; color: var(--text-2); }
.hint-line { font-size: .88rem; color: var(--text-2); margin-top: 4px; }

.banner { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-m); background: var(--c-warn-soft); color: var(--c-hay-deep); }
.banner--info { background: var(--primary-soft); color: var(--primary); }
.banner--danger { background: var(--c-danger-soft); color: var(--c-danger); }
.banner--neutral { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.banner strong { display: block; }
.banner p { margin: 2px 0 0; color: var(--text); }

/* Hinweis auf das andere Produkt – als solcher erkennbar (Konzept S. 12) */
.promo { display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: start; padding: 14px; border-radius: var(--radius-l); border: 1px dashed var(--line); background: var(--surface-2); }
.promo img { width: 44px; height: 44px; border-radius: 10px; }
.promo .promo__kicker { font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-2); }
.promo h3 { margin: 2px 0 4px; }
.promo p { margin: 0 0 8px; font-size: .95rem; }

/* ---------- Formulare ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-weight: 600; font-size: .95rem; }
.field .help { font-size: .85rem; color: var(--text-2); }
input[type='text'], input[type='email'], input[type='date'], input[type='time'], input[type='number'], select, textarea {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: var(--radius-s); border: 1.5px solid var(--line);
  background: var(--surface); color: var(--text); font: 400 1rem var(--font);
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
.check { display: grid; grid-template-columns: 28px 1fr; gap: 8px; align-items: start; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: var(--radius-m); cursor: pointer; background: var(--surface); }
.check input { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--primary); }
.check:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.check small { display: block; }
.error-text { color: var(--c-danger); font-weight: 600; font-size: .92rem; }

.meal-editor { border: 1px solid var(--line); border-radius: var(--radius-m); padding: 12px; margin-bottom: 10px; background: var(--surface-2); }
.meal-editor__head { display: grid; grid-template-columns: 1fr 110px auto; gap: 8px; margin-bottom: 8px; }
.item-row { display: grid; grid-template-columns: 1fr 84px 120px 40px; gap: 6px; margin-bottom: 6px; }
.item-row input, .item-row select { min-height: 44px; }
.iconbtn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: var(--radius-s); border: 1.5px solid var(--line); background: var(--surface); cursor: pointer; color: var(--text-2); font-size: 1.2rem; }

/* ---------- Tabelle ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); padding: 8px; border-bottom: 1.5px solid var(--line); }
.table td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--surface-2); }
@media (max-width: 640px) { .table--stack thead { display: none; } .table--stack tr { display: block; padding: 8px 0; border-bottom: 1px solid var(--line); } .table--stack td { display: block; border: 0; padding: 2px 4px; } }

/* KPI */
.kpis { margin-bottom: 24px; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-l); padding: 14px 16px; }
.kpi__value { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.kpi__label { color: var(--text-2); font-size: .9rem; }

/* Segmentauswahl */
.segments { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--radius-m); border: 1px solid var(--line); overflow-x: auto; }
.segments button { flex: 1; min-height: 40px; border: 0; background: transparent; border-radius: var(--radius-s); font: 600 .95rem var(--font); color: var(--text-2); cursor: pointer; white-space: nowrap; padding: 0 12px; }
.segments button[aria-pressed='true'] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* Dialog */
dialog { border: 0; border-radius: var(--radius-l); padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
dialog::backdrop { background: rgba(15, 36, 32, .45); }
.dialog__body { padding: 20px; overflow: auto; max-height: calc(100dvh - 120px); }
.dialog__foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px 20px; flex-wrap: wrap; }

/* Hinweise */
.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 100; background: var(--c-ink); color: var(--c-paper); padding: 12px 18px; border-radius: var(--radius-m); box-shadow: var(--shadow); max-width: calc(100vw - 32px); font-weight: 600; }
.toast--error { background: var(--c-danger); color: #fff; }
.empty { text-align: center; padding: 28px 16px; color: var(--text-2); }
.empty img { width: 56px; opacity: .9; margin-bottom: 8px; }

/* Anmeldung */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth__box { width: 100%; max-width: 440px; }
.auth__logo { height: 52px; margin: 0 auto 20px; display: block; }
.demo-list { display: flex; flex-direction: column; gap: 8px; }
.demo-list button { text-align: left; justify-content: flex-start; }

.codebox { font: 700 1.4rem/1 ui-monospace, 'SFMono-Regular', Menlo, monospace; letter-spacing: .08em; padding: 12px 16px; border-radius: var(--radius-m); background: var(--surface-2); border: 1.5px dashed var(--line); display: inline-block; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--line); position: relative; font-size: .92rem; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }

@media print {
  .topbar, .tabbar, .syncbar, .btn, .promo { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.main:focus { outline: none; }

/* Wochentage-Auswahl und Wochenplan */
.daypicker { display: flex; gap: 6px; flex-wrap: wrap; }
.daypicker label { display: inline-flex; }
.daypicker input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.daypicker span { min-width: 44px; min-height: 44px; display: grid; place-items: center; border-radius: var(--radius-s); border: 1.5px solid var(--line); font-weight: 600; cursor: pointer; background: var(--surface); }
.daypicker input:checked + span { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.daypicker input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.routine { display: grid; grid-template-columns: 56px 1fr auto; gap: 4px 12px; padding: 12px 0; border-top: 1px solid var(--line); align-items: start; }
.routine:first-of-type { border-top: 0; }
.week-day { border-top: 1px solid var(--line); padding: 10px 0; }
.week-day--today { background: var(--primary-soft); border-radius: var(--radius-m); padding: 10px 12px; border-top: 0; }
.week-day h3 { margin: 0 0 6px; }
.week-line { display: grid; grid-template-columns: 52px 1fr; gap: 8px; font-size: .95rem; padding: 2px 0; }
.week-line .muted { font-size: .88rem; }
.source-tag { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); }
