:root {
  --ground: #F1F3F2;
  --surface: #FFFFFF;
  --ink: #14201C;
  --muted: #56645E;
  --rule: #DDE2DF;
  --rule-soft: #ECEFED;
  --field: #A9B3AE;
  --green: #0E5A4A;
  --green-tint: #E3EFEB;
  --orange: #A8460A;
  --weekend: #F7F8F7;
  --off: #66736D;
  /* Personenfarben setzt app.js aus den Nutzerdaten */
  --left: #A3245A;
  --right: #1F4E99;
}

.side-0 { --p: var(--left); }
.side-1 { --p: var(--right); }
.side-j { --p: #0E5A4A; }
.side-a { --p: #4A5560; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--ground);
  color: var(--ink);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--ink); }
[hidden] { display: none !important; }
svg { flex: 0 0 auto; }

/* --- Rahmen ------------------------------------------------------------- */

.shell { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; padding-top: env(safe-area-inset-top); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 48px; padding: 0 20px; flex: 0 0 auto; }
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.brand-date { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 14px; flex: 0 0 auto; }
.topbar-actions form { margin: 0; }
.link-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 2px; background: none; border: 0; font-size: 13px; color: var(--muted); }
.link-btn:hover { color: var(--ink); text-decoration: underline; }

.app { flex: 1 1 auto; display: flex; flex-direction: column; }
.loading { padding: 20px; color: var(--muted); }
.main { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 14px; padding: 0 20px 20px; }
.pane { flex: 1 1 100%; min-width: 0; background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; }
.pane-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 14px; min-height: 52px; padding: 6px 10px 6px 16px; border-bottom: 1px solid var(--rule); }
.head-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.head-title { display: flex; flex-direction: column; }
.head-title h2 { margin: 0; font-size: 16px; font-weight: 700; }
.head-tools { display: flex; align-items: center; gap: 8px; }
.month-nav { display: flex; align-items: center; gap: 2px; }
.month-label { padding: 4px 6px; font-size: 15px; font-weight: 700; white-space: nowrap; }
.hint { font-size: 12px; font-weight: 400; color: var(--muted); }

/* --- Bedienelemente ------------------------------------------------------ */

.seg { display: inline-flex; padding: 2px; border-radius: 7px; background: var(--rule-soft); }
.seg button { min-height: 28px; padding: 0 12px; border: 0; border-radius: 5px; background: transparent; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(20, 32, 28, 0.1); }

.icon-btn { display: flex; align-items: center; justify-content: center; flex: 0 0 auto; width: 32px; height: 32px; padding: 0; background: none; border: 0; border-radius: 6px; color: var(--muted); }
.icon-btn:hover { background: var(--rule-soft); color: var(--ink); }
.icon-btn svg { width: 15px; height: 15px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 5px; flex: 0 0 auto; min-height: 32px; padding: 0 12px; border: 0; border-radius: 7px; background: none; font-size: 13px; font-weight: 600; white-space: nowrap; text-decoration: none; }
.btn svg { width: 12px; height: 12px; }
.btn-primary { background: var(--green); color: #FFFFFF; padding: 0 16px; }
.btn-primary:hover { background: #0A4A3C; }
.btn-tint { background: var(--green-tint); color: var(--green); padding-left: 9px; }
.btn-tint:hover { background: #D3E7E0; }
.btn-ghost { color: var(--ink); }
.btn-ghost:hover { background: var(--rule-soft); }
.btn-danger { color: var(--orange); padding: 0 8px; }
.btn-danger:hover { background: #FBEADD; }
.btn-wide { width: 100%; min-height: 44px; font-size: 14px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.add-link { display: inline-flex; align-items: center; gap: 5px; min-height: 28px; padding: 0; background: none; border: 0; font-size: 13px; font-weight: 600; color: var(--green); }
.add-link:hover { text-decoration: underline; }
.add-link svg { width: 11px; height: 11px; }

/* --- Legende --------------------------------------------------------------- */

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; padding: 7px 16px; border-bottom: 1px solid var(--rule); font-size: 12px; color: var(--muted); }
.lg { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; }
.lg svg { width: 12px; height: 12px; }
.lg-hint { font-weight: 400; }
.lg-sep { width: 1px; height: 14px; background: var(--rule); }
.dot { display: inline-block; flex: 0 0 auto; width: 14px; height: 12px; border-radius: 3px; background: color-mix(in srgb, var(--p) 45%, #FFF); }
.dot.busy { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--p) 10%, #FFF) 0 3px, color-mix(in srgb, var(--p) 50%, #FFF) 3px 5px); }

/* --- Monat ------------------------------------------------------------------ */

.weekdays, .month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekdays { border-bottom: 1px solid var(--rule); }
.weekdays span { padding: 6px 8px; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.month { grid-auto-rows: minmax(118px, auto); gap: 1px; background: var(--rule); }
.cell { position: relative; display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 4px 4px 6px; background: var(--surface); }
.cell.weekend, .cell.off { background: var(--weekend); }
.cell.holiday { background: #F4F7EC; }
.cell-hit { position: absolute; inset: 0; padding: 0; border: 0; background: none; }
.cell-hit:focus-visible { outline: 2px solid var(--green); outline-offset: -2px; }
.chead { position: relative; display: flex; align-items: flex-start; gap: 4px; min-height: 22px; pointer-events: none; }
.num { display: flex; align-items: center; justify-content: center; flex: 0 0 22px; height: 22px; border-radius: 11px; font-size: 12px; font-weight: 600; }
.cell.off .num { color: var(--off); font-weight: 400; }
.cell.today .num { background: var(--ink); color: #FFFFFF; }
.gens { display: flex; flex-direction: column; gap: 1px; min-width: 0; padding-top: 3px; }
.gen { display: flex; align-items: center; gap: 4px; min-width: 0; font-size: 11px; line-height: 1.3; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gen svg { width: 11px; height: 11px; }
.lanes { position: relative; display: flex; flex-direction: column; gap: 3px; flex: 1 1 auto; pointer-events: none;
  background: linear-gradient(var(--rule-soft), var(--rule-soft)) center top / 1px 100% no-repeat; }
.cell.off .lanes { opacity: 0.55; }
.lrow { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; }
.chip { display: flex; flex-direction: column; min-width: 0; padding: 2px 5px 3px; border: 0; border-radius: 5px; text-align: left; pointer-events: auto;
  background: color-mix(in srgb, var(--p) 14%, #FFF); color: color-mix(in srgb, var(--p) 80%, #000); }
.chip:hover { background: color-mix(in srgb, var(--p) 22%, #FFF); }
.chip.busy { background: repeating-linear-gradient(135deg, color-mix(in srgb, var(--p) 7%, #FFF) 0 4px, color-mix(in srgb, var(--p) 19%, #FFF) 4px 6px); }
.chip.span2 { grid-column: 1 / -1; flex-direction: row; align-items: baseline; gap: 6px; background: color-mix(in srgb, var(--p) 16%, #FFF); }
.chip.span2:hover { background: color-mix(in srgb, var(--p) 24%, #FFF); }
.chip.span2 .ci { order: -1; flex: 0 0 auto; }
.ct, .ci { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ct { font-size: 11.5px; font-weight: 600; line-height: 1.25; }
.ci { font-size: 11px; line-height: 1.25; font-variant-numeric: tabular-nums; }
.gap { min-height: 1px; }

/* --- Liste ------------------------------------------------------------------- */

.colhead { position: sticky; top: 0; z-index: 2; display: flex; gap: 10px; padding: 8px 16px 7px; border-bottom: 1px solid var(--rule); background: var(--surface); }
.colhead .spacer { flex: 0 0 40px; }
.colhead .lrow { flex: 1 1 0; gap: 16px; }
.colname { display: flex; align-items: center; gap: 7px; padding-left: 8px; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: color-mix(in srgb, var(--p) 80%, #000); }
.kw { padding: 12px 16px 5px; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--rule); }
.lday { display: flex; gap: 10px; padding: 5px 16px; border-bottom: 1px solid var(--rule-soft); }
.lday.weekend { background: var(--weekend); }
.lday.past { opacity: 0.6; }
.ldate { display: flex; flex-direction: column; align-items: center; flex: 0 0 40px; padding-top: 4px; line-height: 1.15; }
.lwd { font-size: 11px; font-weight: 600; color: var(--muted); }
.lnum { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 14px; font-size: 15px; font-weight: 700; }
.lday.today .lnum { background: var(--ink); color: #FFFFFF; }
.lrows { display: flex; flex-direction: column; gap: 4px; flex: 1 1 0; min-width: 0; padding: 3px 0; }
.lrows .lrow { gap: 16px; }
.lgens { display: flex; flex-wrap: wrap; gap: 2px 14px; padding: 2px 8px 0; }
.lcol { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.lcol.span2 { grid-column: 1 / -1; padding: 3px 0; border-radius: 7px; background: var(--green-tint); }
.ent { display: flex; flex-direction: column; min-width: 0; padding: 3px 8px; border: 0; border-radius: 6px; background: none; text-align: left; }
.ent:hover { background: color-mix(in srgb, var(--p) 8%, transparent); }
.eti { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 8px; font-size: 14px; font-weight: 600; }
.eti .dot { align-self: center; }
.etl { overflow-wrap: anywhere; }
.etm { font-size: 12.5px; font-weight: 500; font-variant-numeric: tabular-nums; color: var(--muted); }
.es { padding-left: 22px; font-size: 12px; color: var(--muted); }
.ent.busy .etl { font-weight: 500; color: var(--muted); }
.empty { padding: 14px 16px; color: var(--muted); margin: 0; }

/* --- Quellen ------------------------------------------------------------------ */

.pane-list { flex: 999 1 560px; }
.pane-side { flex: 1 1 380px; }
.sec { --g: var(--field); --g-tint: var(--rule-soft); margin-top: 10px; }
.sec:first-of-type { margin-top: 0; }
.sec.side-0 { --g: var(--left); --g-tint: color-mix(in srgb, var(--left) 9%, #FFF); }
.sec.side-1 { --g: var(--right); --g-tint: color-mix(in srgb, var(--right) 9%, #FFF); }
.sec.side-a { --g: #4A5560; }
.sec-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; margin: 0; padding: 7px 16px 6px 13px; border-left: 3px solid var(--g); background: var(--g-tint);
  font-size: 12.5px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; color: color-mix(in srgb, var(--g) 85%, #000); }
.sec-sub { font-weight: 600; letter-spacing: 0; text-transform: none; color: var(--ink); opacity: 0.75; }
.src { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 9px 12px 9px 16px; border: 0; border-bottom: 1px solid var(--rule-soft); background: none; text-align: left; }
button.src:hover { background: var(--weekend); }
.src-ico { display: flex; align-items: center; justify-content: center; flex: 0 0 34px; height: 34px; border-radius: 8px; background: color-mix(in srgb, var(--p) 13%, #FFF); color: color-mix(in srgb, var(--p) 85%, #000); }
.src-ico svg { width: 17px; height: 17px; }
.src-text { display: flex; flex-direction: column; gap: 1px; flex: 1 1 auto; min-width: 0; }
.src-name { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.src-meta { font-size: 12px; color: var(--muted); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag { padding: 1px 7px; border-radius: 8px; background: var(--rule-soft); font-size: 11.5px; font-weight: 600; color: var(--muted); }
.src-state { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.st-dot { width: 8px; height: 8px; border-radius: 4px; background: #2F7A55; }
.st-dot.wait { background: var(--field); }
.src-state.err { color: var(--orange); font-weight: 600; }
.src-state.err .st-dot { background: var(--orange); }
.role { padding: 1px 8px; border-radius: 8px; background: var(--green-tint); font-size: 11.5px; font-weight: 700; color: var(--green); }
.role.plain { background: var(--rule-soft); color: var(--muted); }
.add-row { display: flex; padding: 8px 16px 12px; }
.side-body { display: flex; flex-direction: column; gap: 12px; padding: 14px 16px 16px; }

/* --- Dialoge -------------------------------------------------------------------- */

.scrim { position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding: 64px 16px 16px; background: rgba(20, 32, 28, 0.38); }
.sheet { display: flex; flex-direction: column; gap: 14px; width: 560px; max-width: 100%; max-height: 100%; overflow-y: auto; padding: 16px 18px 14px; background: var(--surface); border-radius: 12px; box-shadow: 0 12px 40px rgba(20, 32, 28, 0.18); }
.sheet p { margin: 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; margin-bottom: -4px; }
.sheet-head h2 { margin: 0; font-size: 15px; font-weight: 700; }
.sheet .detail-title { margin: 0; font-size: 19px; font-weight: 700; }
.detail-kind { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: color-mix(in srgb, var(--p) 85%, #000); }
.muted { color: var(--muted); white-space: pre-line; }
.sheet-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding-top: 10px; margin-top: 2px; border-top: 1px solid var(--rule-soft); }
.spacer-flex { flex: 1 1 auto; }

.field { width: 100%; min-height: 34px; padding: 0 10px; border: 1px solid var(--field); border-radius: 7px; background: var(--surface); font-size: 14px; }
.field:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-tint); }
.field-title { min-height: 40px; padding: 0 11px; font-size: 16px; font-weight: 600; }
.field.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
textarea.field { padding: 7px 10px; resize: vertical; }
.group { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.group-label { font-size: 12px; font-weight: 600; color: var(--muted); }
.group-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 8px; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; }
.form-row > .group { flex: 1 1 140px; }
.check-row { display: flex; align-items: center; gap: 8px; min-height: 32px; font-size: 14px; }
.check-row input { width: 18px; height: 18px; margin: 0; accent-color: var(--green); }
.form-error { padding: 8px 10px; border-radius: 7px; background: #FBEADD; color: #7A3307; font-size: 13px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 26px; height: 26px; padding: 0; border: 0; border-radius: 13px; background: var(--c); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--ink); }

/* Regeln */
.rules { display: flex; flex-direction: column; gap: 8px; }
.rule { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border: 1px solid var(--rule); border-radius: 8px; }
.rule-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.rule-n { display: flex; align-items: center; justify-content: center; flex: 0 0 20px; height: 20px; border-radius: 10px; background: var(--rule-soft); font-size: 11.5px; font-weight: 700; color: var(--muted); }
.rule-conds { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; }
.rule-then { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rule-then .field { width: 160px; }
.w { font-size: 13px; font-weight: 600; color: var(--muted); }
.rule .icon-btn { width: 28px; height: 28px; }

/* Vorschau */
.pv { display: flex; flex-direction: column; border-top: 1px solid var(--rule-soft); }
.pv-row { display: flex; align-items: baseline; gap: 10px; padding: 5px 2px; border-bottom: 1px solid var(--rule-soft); font-size: 13px; }
.pv-row.hide { color: var(--muted); text-decoration: line-through; }
.pv-d { flex: 0 0 96px; font-size: 12px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }
.pv-t { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0 8px; min-width: 0; }
.pv-t .dot { align-self: center; }
.pv-o { font-size: 12px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 40; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 9px 14px; border-radius: 8px; background: var(--ink); color: #FFFFFF; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.toast.show { opacity: 1; }

/* --- Anmeldung -------------------------------------------------------------------- */

.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login { width: 100%; max-width: 360px; padding: 32px 24px; }
.login h1 { margin: 0 0 20px; font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.login form { display: flex; flex-direction: column; gap: 14px; }
.login label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; }
.login input[type="text"], .login input[type="password"] { min-height: 46px; padding: 0 12px; border: 1px solid var(--field); border-radius: 8px; background: var(--surface); font-size: 16px; font-weight: 400; }
.login .btn-primary { min-height: 46px; }
.login-error { padding: 10px 12px; border-radius: 8px; background: #FBEADD; color: #7A3307; }
.login-hint { margin: 0; font-size: 13px; color: var(--muted); }

/* --- Handy --------------------------------------------------------------------------- */

@media (max-width: 759px) {
  body { font-size: 15px; }
  .topbar { padding: 0 8px 0 16px; gap: 8px; }
  .topbar-actions { gap: 4px; }
  .link-btn { min-height: 44px; padding: 0 6px; }
  .hide-phone { display: none; }
  .main { padding: 0 0 env(safe-area-inset-bottom); gap: 10px; }
  .pane { border-radius: 0; border-left: 0; border-right: 0; }
  .pane-head { padding: 6px 8px; }
  .head-tools { margin-left: auto; }
  .icon-btn { width: 44px; height: 44px; }
  .btn { min-height: 40px; font-size: 14px; }
  .seg button { min-height: 36px; padding: 0 12px; font-size: 14px; }
  .legend { padding: 6px 10px; gap: 4px 12px; }
  .legend .lg-hint { display: none; }

  .weekdays span { padding: 4px 0; text-align: center; font-size: 11px; }
  .month { grid-auto-rows: minmax(84px, auto); }
  .cell { gap: 1px; padding: 2px 1px 2px; }
  .chead { justify-content: center; }
  .num { flex-basis: 20px; height: 20px; font-size: 11.5px; }
  .gens { display: none; }
  .cell.has-gen .num { box-shadow: inset 0 -2px 0 var(--field); border-radius: 10px 10px 4px 4px; }
  .lrow { gap: 1px; }
  .chip { padding: 1px 2px; border-radius: 3px; pointer-events: none; }
  .chip.span2 { flex-direction: column; }
  .ci { display: none; }
  .ct { font-size: 10px; line-height: 13px; text-overflow: clip; }

  .colhead, .lday { padding-left: 8px; padding-right: 8px; gap: 6px; }
  .colhead .spacer, .ldate { flex-basis: 32px; }
  .lrows .lrow, .colhead .lrow { gap: 6px; }
  .ent { padding: 3px 4px; }
  .eti { font-size: 14px; gap: 0 6px; }
  .eti .dot { width: 10px; height: 10px; }
  .etm { font-size: 12px; flex-basis: 100%; padding-left: 16px; }
  .es { padding-left: 16px; }

  .scrim { justify-content: flex-end; padding: 40px 0 0; }
  .sheet { width: 100%; border-radius: 14px 14px 0 0; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .field { min-height: 44px; font-size: 16px; }
  .field.mono { font-size: 14px; }
  .rule-conds { grid-template-columns: 1fr; }
  .rule-then .field { width: 100%; }
  .src-state .txt { display: none; }
}
