:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #e7e5e0;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f2f0;
  --green: #15803d; --green-soft: #dcfce7;
  --amber: #b45309; --amber-soft: #fef3c7;
  --red: #b91c1c; --red-soft: #fee2e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(28 25 23 / .05), 0 4px 16px rgb(28 25 23 / .05);
  --fc-border-color: var(--line);
  --fc-today-bg-color: #f0fdfa;
  --fc-now-indicator-color: #dc2626;
  --fc-page-bg-color: var(--surface);
  --fc-neutral-bg-color: #faf9f6;
  --fc-list-event-hover-bg-color: #f5f5f4;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  touch-action: manipulation;
}
[hidden] { display: none !important; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; font-weight: 600; }
small { color: var(--muted); }
.muted { color: var(--muted); }
input, select, button, textarea { font: inherit; color: inherit; }
input, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  font-size: 16px; min-height: 44px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: #44403c; }

/* Buttons */
.btn {
  border: 1px solid var(--line); background: var(--surface); padding: 10px 16px; border-radius: 999px;
  font-weight: 600; cursor: pointer; min-height: 44px; white-space: nowrap;
}
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: #fecaca; }
.btn:active { transform: translateY(1px); }
.icon-btn {
  border: 0; background: transparent; width: 40px; height: 40px; border-radius: 999px; cursor: pointer;
  display: inline-grid; place-items: center; color: var(--muted); font-size: 17px;
}
.icon-btn:hover { background: #f1f0ec; color: var(--ink); }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); background: var(--surface); padding: 28px; border-radius: 20px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.login-card .brand { font-size: 22px; margin-bottom: 6px; }
.form-error { color: var(--red); margin: 0; min-height: 1em; font-size: 14px; }

/* Topbar */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.01em; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 16px;
}
.topbar {
  position: sticky; top: 0; z-index: 20; background: rgb(246 245 241 / .9); backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px;
  padding: calc(8px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
}
.tabs { display: flex; gap: 4px; justify-content: center; }
.tabs button {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 999px; cursor: pointer; font-weight: 600;
  color: var(--muted); display: inline-flex; align-items: center; gap: 6px; min-height: 40px;
}
.tabs button.active { background: var(--ink); color: #fff; }
.badge {
  background: #dc2626; color: #fff; border-radius: 999px; font-size: 11px; min-width: 18px; height: 18px;
  display: inline-grid; place-items: center; padding: 0 5px;
}
.who { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.who-dot { width: 10px; height: 10px; border-radius: 50%; }

/* Panels */
.panel { max-width: 1180px; margin: 0 auto; padding: 16px max(16px, env(safe-area-inset-left)) calc(40px + env(safe-area-inset-bottom)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack.compact .card { box-shadow: none; padding: 10px 14px; opacity: .85; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid .wide { grid-column: 1 / -1; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.empty { color: var(--muted); margin: 4px 0; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 12px; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; }
.tag.green { background: var(--green-soft); color: var(--green); }
.tag.amber { background: var(--amber-soft); color: var(--amber); }
.tag.red { background: var(--red-soft); color: var(--red); }
.tag.grey { background: #f1f0ec; color: var(--muted); }
.who-chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.who-chip::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }

/* Kalender */
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 4px; display: inline-block; }
.legend i.free { border: 2px dashed #94a3b8; }
.legend i.exam { background: var(--red-soft); border: 1px solid #dc2626; }
#calendar { background: var(--surface); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.fc .fc-toolbar-title { font-size: 18px; font-weight: 700; color: var(--ink); }
.fc .fc-button { border-radius: 999px !important; background: #fff; color: var(--ink); border: 1px solid var(--line); font-weight: 600; text-transform: none; padding: 6px 12px; box-shadow: none !important; }
.fc .fc-button-group { gap: 4px; }
.fc .fc-button-primary:not(:disabled).fc-button-active, .fc .fc-button-primary:not(:disabled):active { background: var(--ink); border-color: var(--ink); color: #fff; }
.fc .fc-button-primary:hover { background: #f1f0ec; color: var(--ink); border-color: var(--line); }
.fc .fc-button-primary:disabled { background: #fff; color: var(--muted); border-color: var(--line); opacity: .6; }
.fc .fc-col-header-cell-cushion, .fc .fc-daygrid-day-number { color: var(--ink); text-decoration: none; font-weight: 600; }
.fc-event.ev-lesson { border-radius: 8px; border-width: 2px; font-weight: 600; cursor: pointer; }
.fc-event.ev-free { border-style: dashed; background: repeating-linear-gradient(45deg, #fff, #fff 6px, #f8fafc 6px, #f8fafc 12px) !important; }
.fc-event.ev-other { opacity: .55; }
.fc-event.ev-cancelled { opacity: .45; text-decoration: line-through; filter: grayscale(.8); }
.fc-event.ev-exam { border-radius: 6px; font-weight: 600; cursor: pointer; }
.fc-list-event.ev-free .fc-list-event-dot { border-style: dashed; }
.fc-list-event.ev-cancelled { text-decoration: line-through; opacity: .5; }
.fc .fc-list-event-title { font-weight: 600; }
.fc-theme-standard .fc-list { border-radius: 10px; overflow: hidden; }

/* Dialog */
dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(520px, calc(100vw - 24px)); box-shadow: 0 24px 64px rgb(0 0 0 / .25);
  background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgb(28 25 23 / .4); }
dialog form { padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-head h3 { margin: 0; font-size: 18px; }
.dlg-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
#lesson-body { display: flex; flex-direction: column; gap: 12px; }
.slot { margin: 0; }
.toggles { display: flex; flex-direction: column; gap: 6px; }
.check { flex-direction: row; align-items: center; gap: 10px; font-size: 15px; font-weight: 500; min-height: 40px; }
.check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--accent); }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font-size: 15px; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 6px 10px; }
.choice input[type=radio] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }
.choice select { grid-column: 1 / -1; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.note { background: var(--amber-soft); color: var(--amber); padding: 8px 12px; border-radius: 10px; margin: 0; font-size: 14px; }

/* Anfragen */
.req { display: flex; flex-direction: column; gap: 8px; }
.req-text { line-height: 1.7; }
.slot-pill { background: #f1f0ec; border-radius: 6px; padding: 1px 7px; white-space: nowrap; font-size: 14px; }
.req-msg { color: #44403c; font-style: italic; }
.req-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.req-meta small { margin-right: auto; }

/* Klausuren */
.exam-form { margin-bottom: 8px; }
.exam-form h2 { margin-top: 0; }
.exam { display: flex; gap: 14px; align-items: center; }
.exam.soon { border-color: #fca5a5; background: #fffafa; }
.exam-date {
  width: 52px; height: 52px; border-radius: 12px; background: var(--red-soft); color: var(--red);
  display: flex; flex-direction: column; align-items: center; justify-content: center; flex-shrink: 0; line-height: 1.1;
}
.exam-date span { font-size: 19px; font-weight: 800; }
.exam-date small { color: var(--red); font-size: 11px; text-transform: uppercase; font-weight: 600; }
.exam-main { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.exam-actions { display: flex; }
.past { margin-top: 18px; }
.past summary { cursor: pointer; color: var(--muted); font-weight: 600; margin-bottom: 10px; }

/* Abrechnung */
.billing-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.billing-head > label { min-width: 200px; }
.rate { display: flex; align-items: flex-end; gap: 8px; }
.euro-input { display: flex; align-items: center; gap: 6px; font-size: 16px; }
.euro-input input { width: 90px; text-align: right; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 18px 0; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi b { font-size: 22px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi.ok b { color: var(--green); }
.kpi.due { background: var(--amber-soft); border-color: #fde68a; }
.kpi.due b { color: var(--amber); }
.bill summary { display: flex; align-items: center; gap: 12px; cursor: pointer; flex-wrap: wrap; list-style: none; }
.bill summary::-webkit-details-marker { display: none; }
.bill-sum { color: var(--muted); font-variant-numeric: tabular-nums; }
.bill-open { margin-left: auto; font-weight: 700; color: var(--amber); }
.bill-open.zero { color: var(--green); }
.bill-open.none { color: var(--muted); font-weight: 500; }
.bill-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-variant-numeric: tabular-nums; }
.bill-table td { padding: 8px 6px; border-top: 1px solid var(--line); font-size: 14px; }
.bill-table .num { text-align: right; white-space: nowrap; }
.bill-table tr.is-paid td:not(:last-child) { color: var(--muted); }
.pay-toggle {
  border: 1px solid #fde68a; background: var(--amber-soft); color: var(--amber); border-radius: 999px;
  padding: 5px 12px; font-size: 13px; font-weight: 700; cursor: pointer; min-width: 84px; min-height: 32px;
}
.pay-toggle.paid { border-color: #bbf7d0; background: var(--green-soft); color: var(--green); }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--red); }

/* Mobil */
@media (max-width: 720px) {
  .topbar { grid-template-columns: 1fr auto; gap: 6px 10px; }
  .brand-text { display: none; }
  .tabs { grid-column: 1 / -1; grid-row: 2; justify-content: space-between; overflow-x: auto; }
  .tabs button { padding: 8px 10px; font-size: 14px; white-space: nowrap; flex-shrink: 0; }
  .tabs { gap: 2px; scrollbar-width: none; }
  .topbar .brand { grid-row: 1; }
  .who { grid-row: 1; justify-self: end; }
  .cols { grid-template-columns: 1fr; gap: 0; }
  .grid { grid-template-columns: 1fr 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  #calendar { padding: 8px; }
  .fc .fc-toolbar { flex-wrap: wrap; gap: 8px; }
  .fc .fc-toolbar-title { font-size: 16px; }
  .fc .fc-toolbar-chunk:nth-child(2) { order: -1; width: 100%; text-align: center; }
  .fc .fc-toolbar.fc-header-toolbar { justify-content: space-between; }
  .bill-table td:nth-child(2) { display: none; }
  dialog { width: calc(100vw - 16px); margin-top: 8vh; }
}
@media (hover: none) { .icon-btn:hover { background: transparent; } }
