:root {
  --tide: #121e28;
  --flat: #1b2b37;
  --line: #2b3f4d;
  --foam: #e9f0f2;
  --dim: #93a6b2;
  --sand: #e3c286;
  --water: #7ed6c8;
  --buoy: #e0503f;
  --school: #3f6e93;
  --termin: #d9a24a;
  --weg: #4b5c68;
  --essen: #5d9c82;
  --night: #232e4f;
  --routine: #33435f;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--tide); color: var(--foam); font: 16px/1.5 var(--sans);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--sand); }
:focus-visible { outline: 2px solid var(--sand); outline-offset: 2px; }

#app { max-width: 720px; margin: 0 auto; padding: 0 16px calc(150px + env(safe-area-inset-bottom)); }
.head {
  position: sticky; top: 0; z-index: 20; background: var(--tide);
  padding: calc(10px + env(safe-area-inset-top)) 0 10px; border-bottom: 1px solid var(--line);
}
.headrow { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
h1 { font: 600 clamp(1.1rem, 4.7vw, 1.5rem)/1.2 var(--serif); margin: 0; text-align: center; flex: 1; letter-spacing: 0.005em; }
h2 { font: 600 1.15rem/1.3 var(--serif); margin: 28px 0 8px; }
.nav {
  width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--line); background: var(--flat);
  font-size: 1.6rem; line-height: 1; color: var(--sand);
}
.plain { background: none; border: 0; color: var(--sand); padding: 6px 4px; }
.small { font-size: 0.875rem; }
.dim { color: var(--dim); }

.summary { font-size: 1.05rem; margin: 14px 0 6px; max-width: 60ch; }
.notice { margin: 6px 0; padding: 8px 12px; border-left: 3px solid var(--sand); background: var(--flat); border-radius: 0 8px 8px 0; font-size: 0.95rem; }
.chip { display: inline-block; margin: 4px 6px 4px 0; padding: 4px 12px; border-radius: 16px; background: var(--flat); border: 1px solid var(--line); }

/* Zeitleiste */
.timeline { position: relative; margin: 20px 0 0 52px; }
.hour { position: absolute; left: -52px; right: 0; border-top: 1px solid var(--line); }
.hour span { position: absolute; left: 0; top: -11px; font-size: 0.75rem; color: var(--dim); background: var(--tide); padding-right: 6px; font-variant-numeric: tabular-nums; }
.block {
  position: absolute; left: 6px; right: 0; z-index: 2; border: 0; border-radius: 6px; padding: 1px 9px;
  text-align: left; color: #fff; overflow: hidden; display: flex; flex-direction: column; justify-content: center;
  line-height: 1.25; min-height: 0;
}
.block .bt { font-size: 0.875rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.block .bs { font-size: 0.75rem; opacity: 0.85; font-variant-numeric: tabular-nums; }
.t-schule { background: var(--school); }
.t-termin { background: var(--termin); color: #1c1406; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25); }
.t-weg { background: var(--weg); opacity: 0.85; }
.t-essen { background: var(--essen); }
.t-schlaf { background: var(--night); color: var(--dim); }
.t-routine { background: var(--routine); }
.t-frei, .t-schlaf { justify-content: flex-start; padding-top: 5px; }
.t-frei { background: rgba(126, 214, 200, 0.14); color: var(--water); border-left: 4px solid var(--water); border-radius: 2px 6px 6px 2px; }
.t-frei.w-schule { border-left-style: dashed; border-left-color: var(--sand); color: var(--sand); background: rgba(227, 194, 134, 0.1); }
.t-kurz { background: transparent; color: var(--dim); border-left: 1px dashed var(--line); border-radius: 0; }
.t-kurz .bt { font-weight: 400; font-size: 0.75rem; }
.block.cancelled, .block.missed { z-index: 1; opacity: 0.5; }
.block.cancelled .bt { text-decoration: line-through; }
.block.missed {
  background-image: repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.16) 0 6px, transparent 6px 12px);
}
.now { position: absolute; left: -8px; right: 0; height: 2px; background: var(--buoy); z-index: 6; pointer-events: none; }
.now::before { content: ""; position: absolute; left: 0; top: -4px; width: 10px; height: 10px; border-radius: 5px; background: var(--buoy); }

/* Woche und Listen */
.week, .more { margin-top: 12px; }
.weekrow, .listrow {
  display: grid; grid-template-columns: 1fr; gap: 2px; width: 100%; text-align: left; padding: 12px 14px; margin: 8px 0;
  background: var(--flat); border: 1px solid var(--line); border-radius: 10px;
}
.weekrow.is-today { border-color: var(--sand); }
.wd { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; }
.wl { color: var(--foam); font-size: 0.95rem; }
.wf { color: var(--water); font-size: 0.9rem; }
.listrow.static { display: flex; align-items: center; justify-content: space-between; }

/* Formulare */
.form { display: block; }
.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 0.9rem; color: var(--dim); margin-bottom: 4px; }
.field small { display: block; margin-top: 4px; color: var(--dim); font-size: 0.8rem; }
input[type=text], input[type=date], input[type=time], input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; background: var(--tide); border: 1px solid var(--line); border-radius: 8px; font-size: 16px; color-scheme: dark;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; gap: 10px; align-items: center; margin: 14px 0; }
.check input { width: 20px; height: 20px; }
button.primary { background: var(--sand); color: #1c1506; border: 0; border-radius: 10px; padding: 12px 18px; font-weight: 600; }
button.danger { color: var(--buoy); border-color: var(--buoy); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions button, .more > button, .more .form + button { border: 1px solid var(--line); background: var(--flat); border-radius: 10px; padding: 10px 14px; }
.actions button.primary { background: var(--sand); border: 0; }
.form-msg { color: var(--buoy); min-height: 1.4em; margin: 6px 0; }
.detail p { margin: 8px 0; }

/* Chat */
.chat { margin-top: 12px; }
.chatlist { min-height: 38vh; display: flex; flex-direction: column; gap: 10px; padding: 8px 0; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; }
.msg p { margin: 0; }
.msg.me { align-self: flex-end; background: var(--school); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--flat); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chatform {
  position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); display: flex; gap: 8px; padding: 10px 0; background: var(--tide);
}
.chatform input { flex: 1; }

/* Navigation unten */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center; gap: 0;
  background: var(--flat); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tab { flex: 1; max-width: 180px; padding: 14px 8px; background: none; border: 0; color: var(--dim); font-weight: 500; border-top: 3px solid transparent; }
.tab.on { color: var(--sand); border-top-color: var(--sand); }
.fab {
  position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 25; padding: 12px 20px; border: 0; border-radius: 26px;
  background: var(--sand); color: #1c1506; font-weight: 600; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

/* Sheet und Hinweis */
.sheet { position: fixed; inset: 0; z-index: 50; display: none; }
.sheet.open { display: block; }
.sheet-back { position: absolute; inset: 0; background: rgba(6, 12, 18, 0.65); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-width: 640px; margin: 0 auto; max-height: 90vh; overflow: auto;
  background: var(--flat); border-radius: 18px 18px 0 0; padding: 8px 18px calc(24px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--flat); padding: 10px 0; }
.sheet-head h2 { margin: 0; }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(132px + env(safe-area-inset-bottom)); z-index: 60; max-width: 560px; margin: 0 auto;
  display: none; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: var(--foam); color: #10202b; border-radius: 12px;
}
.toast.show { display: flex; }
.toast button { background: none; border: 0; color: #14536b; font-weight: 700; }

/* Anmeldung */
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 20px; }
.login h1 { text-align: left; margin-bottom: 18px; }

@media (prefers-reduced-motion: no-preference) {
  .sheet.open .sheet-panel { animation: rise 0.18s ease-out; }
  @keyframes rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
}
@media (min-width: 720px) { .block .bt { font-size: 0.9rem; } }
