:root {
  --ground: #EEF1EF;
  --surface: #FFFFFF;
  --ink: #14201C;
  --muted: #53615B;
  --rule: #D5DBD7;
  --rule-soft: #E6EAE7;
  --field: #9AA6A0;
  --green: #0E5A4A;
  --green-tint: #DCEBE6;
  --orange: #A8460A;
  --weekend: #F5F6F5;
  --off: #66736D;
}

/* Farbpalette: muss mit PALETTE in app.py und app.js übereinstimmen.
   cN = Füllfarbe (Kategorie), rN = Rahmenfarbe (Klasse) */
.c0 { --c: #0E5A4A; } .r0 { --r: #0E5A4A; }
.c1 { --c: #1F4E99; } .r1 { --r: #1F4E99; }
.c2 { --c: #0B6E7F; } .r2 { --r: #0B6E7F; }
.c3 { --c: #5B3FA0; } .r3 { --r: #5B3FA0; }
.c4 { --c: #A3245A; } .r4 { --r: #A3245A; }
.c5 { --c: #B42318; } .r5 { --r: #B42318; }
.c6 { --c: #7A5300; } .r6 { --r: #7A5300; }
.c7 { --c: #4A5560; } .r7 { --r: #4A5560; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--ground);
  color: var(--ink);
  font: 16px/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 { font: inherit; color: var(--ink); }
[hidden] { display: none !important; }
svg { flex: 0 0 auto; }

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

.shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 56px; padding: 0 20px; flex: 0 0 auto;
}
.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.brand-name { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.brand-date { font-size: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.link-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 4px; background: none; border: 0; font-size: 15px; text-decoration: underline; }

.app { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.loading { padding: 20px; color: var(--muted); }
.main { flex: 1 1 auto; min-height: 0; display: flex; gap: 16px; padding: 0 20px 20px; }

.pane {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; overflow: hidden;
}
.pane-todo { flex: 0 0 420px; }
.pane-cal { flex: 1 1 0; }
.pane-head {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px;
  min-height: 64px; padding: 8px 12px 8px 20px; border-bottom: 1px solid var(--rule); flex: 0 0 auto;
}
.pane-head h2 { margin: 0 8px 0 0; font-size: 20px; font-weight: 700; }
.head-left { display: flex; align-items: center; gap: 4px; flex: 1 1 auto; min-width: 0; }
.head-right { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.scroll { flex: 1 1 0; min-height: 0; overflow-y: auto; }
.pane-add-bottom { display: none; }
.hint { font-size: 14px; font-weight: 400; color: var(--muted); }

.tabbar { display: none; }

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

.seg { display: flex; padding: 3px; border-radius: 8px; background: var(--rule-soft); }
.seg button { min-height: 38px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; font-size: 15px; font-weight: 600; }
.seg button[aria-pressed="true"] { background: var(--surface); }

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

.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; border: 0; border-radius: 8px;
  background: var(--green); color: #FFFFFF; font-weight: 600; text-decoration: none;
}
.btn-small { min-height: 40px; padding: 0 14px 0 10px; gap: 6px; }
.btn-wide { width: 100%; min-height: 48px; }
.btn-ghost { min-height: 44px; padding: 0 14px; background: none; border: 0; font-weight: 600; }
.btn-danger { min-height: 44px; padding: 0 12px; background: none; border: 0; font-weight: 600; color: var(--orange); }
.btn-outline { min-height: 44px; padding: 0 18px; background: var(--surface); border: 1.5px solid var(--green); border-radius: 8px; font-weight: 600; color: var(--green); }

/* Kategorie (gefüllter Punkt) und Klasse (Ring) */
.pill { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-weight: 600; }
.pill-dot { display: inline-block; flex: 0 0 auto; width: 11px; height: 11px; border-radius: 6px; }
.pill-dot.fill { background: var(--c); }
.pill-dot.ring { border: 2.5px solid var(--r); background: var(--surface); }
.pill-dot.empty { border: 1.5px dashed var(--field); background: transparent; }

/* --- Aufgaben ------------------------------------------------------------ */

.task {
  display: flex; align-items: flex-start; gap: 0; padding: 2px 4px 2px 4px;
  border-bottom: 1px solid var(--rule-soft); background: var(--surface);
}
.task.dragging { opacity: 0.5; background: var(--green-tint); }
.grip {
  display: flex; align-items: center; justify-content: center; flex: 0 0 24px; height: 44px;
  color: var(--field); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
.check { display: flex; align-items: center; justify-content: center; flex: 0 0 44px; height: 44px; padding: 0; background: none; border: 0; }
.check .box { display: flex; align-items: center; justify-content: center; width: 22px; height: 22px; border: 2px solid var(--muted); border-radius: 6px; background: var(--surface); color: #FFFFFF; }
.check.checked .box { background: var(--muted); }
.task-body {
  display: flex; flex-direction: column; gap: 2px; flex: 1 1 0; min-width: 0; min-height: 44px;
  padding: 10px 4px 8px; background: none; border: 0; text-align: left;
}
.task-title { font-weight: 600; overflow-wrap: anywhere; }
.task-note { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 14px; margin-top: 2px; }
.due { color: var(--orange); font-weight: 600; }
.when-event { display: inline-flex; align-items: center; gap: 5px; color: var(--ink); font-weight: 600; }
.row-edit { margin-top: 0; }
.empty { padding: 16px 20px; color: var(--muted); margin: 0; }

.done-toggle {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 0 20px;
  background: none; border: 0; font-size: 15px; font-weight: 500; color: var(--muted);
}
.done-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.done-row { display: flex; align-items: center; gap: 2px; padding: 0 12px 0 28px; }
.done-text { display: flex; flex-direction: column; min-width: 0; padding: 6px 0; }
.done-title { color: var(--muted); text-decoration: line-through; }
.done-gone { font-size: 13px; color: var(--muted); }

/* --- Kalender ------------------------------------------------------------ */

.weekdays, .month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekdays { border-bottom: 1px solid var(--rule); }
.weekdays span { padding: 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.month { grid-auto-rows: minmax(104px, 1fr); gap: 1px; background: var(--rule); }
.cell { position: relative; display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 4px; background: var(--surface); overflow: hidden; }
.cell.weekend, .cell.off { background: var(--weekend); }
.cell.selected { background: var(--green-tint); }
.cell-hit { position: absolute; inset: 0; background: none; border: 0; padding: 0; }
.cell-head { position: relative; display: flex; align-items: center; justify-content: space-between; pointer-events: none; }
.num { display: flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 13px; font-size: 14px; font-weight: 600; }
.cell.off .num { color: var(--off); }
.cell.today .num { background: var(--ink); color: #FFFFFF; }
.cell-add {
  display: flex; align-items: center; justify-content: center; width: 26px; height: 26px; padding: 0;
  border: 0; border-radius: 13px; background: var(--surface); color: var(--green); pointer-events: auto; opacity: 0;
}
.cell:hover .cell-add, .cell.selected .cell-add, .cell-add:focus-visible { opacity: 1; }
.cell-add:hover { background: var(--green); color: #FFFFFF; }

/* Termin: Füllung = Kategorie, Rahmen = Klasse (mit weißem Abstand nach innen) */
.chip {
  position: relative; display: flex; align-items: stretch; min-width: 0; height: 24px; border-radius: 5px;
  background: var(--c, var(--green)); color: #FFFFFF;
}
.chip.has-ring { box-shadow: inset 0 0 0 2px var(--r), inset 0 0 0 3px #FFFFFF; }
.chip.is-task { background: var(--surface); color: var(--orange); box-shadow: inset 0 0 0 1.5px var(--orange); }
.chip-main {
  flex: 1 1 auto; min-width: 0; padding: 0 6px; background: none; border: 0; color: inherit;
  font-size: 13px; font-weight: 600; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip.has-ring .chip-main { padding-left: 7px; }
.chip-edit {
  display: none; align-items: center; justify-content: center; flex: 0 0 22px; padding: 0;
  background: none; border: 0; color: inherit;
}
.chip:hover .chip-edit, .chip:focus-within .chip-edit { display: flex; }
.more { position: relative; font-size: 12px; color: var(--muted); padding-left: 4px; pointer-events: none; }
.dots { display: none; gap: 3px; height: 9px; }
.dot { display: block; width: 9px; height: 9px; border-radius: 5px; background: var(--c, var(--green)); border: 2px solid var(--r, var(--c, var(--green))); }
.dot.is-task { border-radius: 2px; background: var(--surface); border-color: var(--orange); }
.daylist { display: none; }

.agenda-week { padding: 14px 20px 6px; font-size: 14px; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--rule); }
.agenda-day { display: flex; align-items: flex-start; gap: 8px; padding: 6px 4px 6px 20px; border-bottom: 1px solid var(--rule-soft); }
.agenda-date { display: flex; flex-direction: column; align-items: center; flex: 0 0 44px; padding-top: 6px; line-height: 1.15; }
.agenda-wd { font-size: 13px; font-weight: 600; color: var(--muted); }
.agenda-num { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 16px; font-size: 18px; font-weight: 700; }
.agenda-day.today .agenda-num { background: var(--ink); color: #FFFFFF; }
.agenda-items { display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; }
.entry { display: flex; align-items: flex-start; }
.entry-main {
  display: flex; align-items: flex-start; gap: 12px; flex: 1 1 0; min-width: 0; min-height: 48px; padding: 7px 4px;
  background: none; border: 0; text-align: left;
}
.entry-time { flex: 0 0 96px; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); padding-top: 2px; }
.entry.is-task .entry-time { color: var(--orange); }
.entry-text { display: flex; flex-direction: column; gap: 2px; flex: 1 1 0; min-width: 0; }
.entry-title { font-weight: 600; overflow-wrap: anywhere; }
.entry-sub { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 14px; color: var(--muted); }
.entry-dot {
  display: inline-block; width: 12px; height: 12px; margin-right: 8px; border-radius: 6px; vertical-align: -1px;
  background: var(--c, var(--green)); border: 2.5px solid var(--r, var(--c, var(--green)));
}
.entry-dot.is-task { border-radius: 3px; background: var(--surface); border: 2px solid var(--orange); }

/* --- Formular, Details, Verwaltung ---------------------------------------- */

.scrim {
  position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center;
  justify-content: flex-start; padding: 72px 16px 16px; background: rgba(20, 32, 28, 0.5);
}
.sheet {
  display: flex; flex-direction: column; gap: 14px; width: 560px; max-width: 100%; max-height: 100%;
  overflow-y: auto; padding: 20px; background: var(--surface); border-radius: 12px;
}
.sheet h2 { margin: 0; font-size: 18px; font-weight: 700; }
.sheet p { margin: 0; }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -8px -8px -6px 0; }
.detail-kind { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; font-size: 14px; }
.detail-edit { color: var(--green); }
.sheet .detail-title { font-size: 22px; }
.kind { font-size: 14px; font-weight: 700; color: var(--green); }
.kind.is-task { color: var(--orange); }
.muted { color: var(--muted); white-space: pre-line; }
.field, .field-title, textarea.field {
  width: 100%; min-height: 44px; padding: 0 10px; border: 1.5px solid var(--field); border-radius: 8px; background: var(--surface); font-size: 15px;
}
.field-title { min-height: 48px; padding: 0 12px; font-size: 18px; font-weight: 600; }
textarea.field { padding: 10px 12px; font-size: 16px; resize: vertical; }
.group { display: flex; flex-direction: column; gap: 6px; }
.group-label { font-size: 14px; font-weight: 600; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.dchip { min-height: 40px; padding: 0 12px; border-radius: 20px; border: 1.5px solid var(--field); background: var(--surface); font-size: 15px; font-weight: 600; }
.dchip[aria-pressed="true"] { background: var(--green); border-color: var(--green); color: #FFFFFF; }
.field.field-date { width: auto; min-height: 40px; padding: 0 8px; }
.row3 { display: flex; flex-wrap: wrap; gap: 10px; }
.row3 label { display: flex; flex-direction: column; gap: 4px; flex: 1 1 100px; min-width: 0; font-size: 14px; font-weight: 600; color: var(--muted); }
.row3 label.wide { flex: 2 1 180px; }

.labels-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; }
.add-link {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 2px;
  background: none; border: 0; font-size: 15px; font-weight: 600; color: var(--green); text-decoration: underline;
}
.combo {
  display: inline-flex; align-items: center; gap: 8px; flex: 1 1 200px; min-width: 0; max-width: 260px;
  min-height: 42px; padding: 0 4px 0 12px; border: 1.5px solid var(--field); border-radius: 21px; background: var(--surface);
}
.combo-input { flex: 1 1 auto; min-width: 0; height: 38px; padding: 0; border: 0; background: transparent; font-size: 15px; font-weight: 600; outline: none; }
.combo:focus-within { border-color: var(--green); box-shadow: 0 0 0 2px var(--green-tint); }
.combo-clear { display: flex; align-items: center; justify-content: center; flex: 0 0 34px; height: 34px; padding: 0; border: 0; border-radius: 17px; background: none; color: var(--muted); }
.combo-clear:hover { background: var(--rule-soft); color: var(--ink); }

.color-note { font-weight: 400; }
.inline-link { padding: 0; background: none; border: 0; font-size: 14px; color: var(--green); text-decoration: underline; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 40px; height: 40px; padding: 0; border: 0; border-radius: 20px; background: var(--c); }
.swatch.ring-swatch { background: var(--surface); border: 5px solid var(--r); }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--ink); }

.toggles { display: flex; flex-wrap: wrap; gap: 4px 20px; }
.toggle { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 15px; }
.toggle input { width: 22px; height: 22px; margin: 0; accent-color: var(--green); }

.sheet-foot, .detail-foot { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1 1 auto; }

.labels-section { display: flex; flex-direction: column; gap: 12px; padding-top: 4px; }
.labels-section h3 { margin: 0; font-size: 16px; font-weight: 700; }
.label-row { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--rule-soft); }
.label-row-foot { display: flex; align-items: center; justify-content: space-between; }
.label-new { display: flex; gap: 8px; }
.label-new .field { flex: 1 1 auto; }

.toast {
  position: fixed; left: 50%; bottom: 84px; z-index: 20; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 8px; background: var(--ink); color: #FFFFFF;
  font-size: 15px; 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: 380px; padding: 32px 24px; }
.login h1 { margin: 0 0 24px; font-size: 32px; font-weight: 700; letter-spacing: -0.01em; }
.login form { display: flex; flex-direction: column; gap: 16px; }
.login label { display: flex; flex-direction: column; gap: 6px; font-size: 15px; font-weight: 600; }
.login input[type="text"], .login input[type="password"] {
  min-height: 52px; padding: 0 14px; border: 1.5px solid var(--field); border-radius: 8px; background: var(--surface); font-size: 17px; font-weight: 400;
}
.login .login-remember { flex-direction: row; align-items: center; gap: 10px; min-height: 44px; font-weight: 400; }
.login-remember input { width: 22px; height: 22px; margin: 0; accent-color: var(--green); }
.login-error { padding: 10px 12px; border-radius: 8px; background: #FBEADD; color: #7A3307; }
.login-hint { color: var(--muted); }

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

@media (max-width: 759px) {
  .topbar { padding: 0 8px 0 16px; gap: 8px; }
  .topbar-actions { gap: 4px; }
  .brand { gap: 8px; }
  .hide-phone { display: none; }
  .main { padding: 0; gap: 0; }
  .pane { flex: 1 1 0; border: 0; border-radius: 0; }
  .shell[data-tab="aufgaben"] .pane-cal,
  .shell[data-tab="kalender"] .pane-todo { display: none; }
  .head-right { flex: 1 1 100%; }
  .head-add { display: none; }
  .pane-add-bottom { display: block; padding: 12px 16px; border-top: 1px solid var(--rule); flex: 0 0 auto; }

  .tabbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); flex: 0 0 auto; background: var(--surface); border-top: 1px solid var(--rule); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 60px;
    background: none; border: 0; border-top: 3px solid transparent; font-size: 14px; font-weight: 600; color: var(--muted);
  }
  .tabbar button[aria-current="page"] { color: var(--green); border-top-color: var(--green); }

  .weekdays span { padding: 6px 0; font-size: 13px; text-align: center; }
  .month { grid-auto-rows: 52px; gap: 0; background: var(--surface); border-bottom: 1px solid var(--rule); }
  .cell { align-items: center; gap: 3px; padding: 4px 0 0; }
  .cell.weekend, .cell.off { background: var(--surface); }
  .cell.selected { background: var(--green-tint); }
  .cell-head { justify-content: center; }
  .num { width: 28px; height: 28px; border-radius: 14px; font-size: 15px; }
  .cell-add, .chip, .more { display: none; }
  .dots { display: flex; position: relative; pointer-events: none; }
  .daylist { display: block; }
  .daylist h3 { margin: 0; padding: 14px 16px 6px; font-size: 16px; font-weight: 700; }
  .daylist .entry { padding: 0 4px 0 12px; border-top: 1px solid var(--rule-soft); }
  .entry-time { flex-basis: 64px; }
  .agenda-day { padding-left: 12px; }

  .scrim { justify-content: flex-end; padding: 48px 0 0; }
  .sheet { width: 100%; border-radius: 16px 16px 0 0; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .combo { max-width: none; }
}
