:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --text: #2a2723;
  --muted: #7a736a;
  --line: #e2ddd5;
  --accent: #6b4f2e;
  --accent-text: #ffffff;
  --free: #e7f4e4;
  --free-line: #9ccc92;
  --mine: #dceaf8;
  --mine-line: #7aa8d8;
  --taken: #f1ece4;
  --lesson: #fbecc8;
  --lesson-line: #e2b34b;
  --danger: #b33a2b;
  --today: #fff6dd;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a17;
    --surface: #26231f;
    --text: #ece7df;
    --muted: #a39b90;
    --line: #3a3530;
    --accent: #c79a62;
    --accent-text: #1c1a17;
    --free: #233424;
    --free-line: #4f7d47;
    --mine: #1f2e3d;
    --mine-line: #4c7aa8;
    --taken: #2f2b26;
    --lesson: #3a3020;
    --lesson-line: #a5802f;
    --danger: #e0705f;
    --today: #332c1c;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; text-decoration: none; color: var(--text); }
.logo-img { height: 46px; width: auto; display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.auth-logo { display: block; width: min(340px, 80%); height: auto; margin: 24px auto -16px; }
#nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
#nav a { padding: 6px 10px; border-radius: 6px; text-decoration: none; color: var(--text); }
#nav a.active { background: var(--accent); color: var(--accent-text); }
#nav .spacer { flex: 1; }
.menu-toggle { display: none; margin-left: auto; background: none; border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
@media (max-width: 800px) {
  .menu-toggle { display: block; }
  #nav { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; background: var(--surface); border-bottom: 1px solid var(--line); padding: 8px 16px; }
  #nav.open { display: flex; }
  .topbar { flex-wrap: wrap; position: sticky; }
}

main { max-width: 1400px; margin: 0 auto; padding: 16px; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 18px; margin: 24px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text); }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 3px 8px; font-size: 13px; }
.btn.link { border: none; background: none; padding: 0; color: var(--accent); text-decoration: underline; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.toolbar .grow { flex: 1; }

.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.tabs button { border: none; background: none; padding: 7px 14px; cursor: pointer; }
.tabs button.active { background: var(--accent); color: var(--accent-text); }

.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
@media (max-width: 1000px) { .week { grid-template-columns: 1fr; } }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.day.today { background: var(--today); }
.day.past { opacity: .65; }
.day-head { padding: 8px 10px; font-weight: 600; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.day-body { padding: 6px; display: flex; flex-direction: column; gap: 5px; }
.empty { color: var(--muted); font-size: 13px; padding: 4px; }

.slot { border: 1px solid var(--line); border-left-width: 4px; border-radius: 6px; padding: 5px 7px; font-size: 13px; background: var(--taken); }
.slot .time { font-weight: 600; font-variant-numeric: tabular-nums; }
.slot.free { background: var(--free); border-left-color: var(--free-line); }
.slot.mine { background: var(--mine); border-left-color: var(--mine-line); }
.slot.lesson { background: var(--lesson); border-left-color: var(--lesson-line); }
.slot.service { background: var(--surface); border-left-color: var(--accent); }
.slot.full { opacity: .7; }
.slot .row { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.slot .who { margin-top: 2px; }
.slot.clickable { cursor: pointer; }
.slot.clickable:hover { filter: brightness(.97); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 6px; border-radius: 10px; background: var(--mine); font-size: 12px; margin: 2px 2px 0 0; }
.chip.other { background: var(--taken); }
.chip button { border: none; background: none; cursor: pointer; padding: 0 0 0 2px; color: var(--danger); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.auth { max-width: 380px; margin: 40px auto; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 12px; background: var(--taken); }
.badge.ok { background: var(--free); }
.badge.warn { background: var(--lesson); }
.actions { display: flex; gap: 4px; flex-wrap: wrap; }

dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; width: min(480px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.form h3 { margin: 0; font-size: 18px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 3px; }
.field input:not([type=checkbox]), .field select, .field textarea { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.field textarea { min-height: 60px; resize: vertical; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.field.check label { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
.weekdays { display: flex; flex-wrap: wrap; gap: 4px; }
.weekdays label { display: inline-flex; align-items: center; gap: 3px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; color: var(--text); font-size: 14px; margin: 0; cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.form .error { color: var(--danger); font-size: 14px; min-height: 0; }

#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100vw - 32px); z-index: 20; }
#toast.show { opacity: 1; }
#toast.err { background: var(--danger); color: #fff; }

.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin: 10px 0 0; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; background: var(--c); }
/* Tagesplan */
.timeline { display: flex; flex-direction: column; gap: 6px; max-width: 900px; }
.trow { display: grid; grid-template-columns: 72px 1fr auto; gap: 12px; align-items: start; background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--c, var(--line)); border-radius: var(--radius); padding: 10px 12px; }
.trow.roundpen { --c: var(--mine-line); }
.trow.service { --c: var(--accent); }
.trow.lesson { --c: var(--lesson-line); }
.trow.past { opacity: .5; }
.trow.running { box-shadow: 0 0 0 2px var(--free-line); }
.trow.empty-svc { padding-top: 6px; padding-bottom: 6px; }
.ttime { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 17px; }
.ttime small { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.ttime .live { color: var(--free-line); font-weight: 700; text-transform: uppercase; }
.tbody { min-width: 0; }
.tkind { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--c); font-weight: 700; }
.ttitle { font-weight: 600; font-size: 16px; }
.tact { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.count-badge { display: inline-block; margin-left: 6px; padding: 1px 9px; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-size: 14px; font-weight: 700; vertical-align: 1px; }
.count-badge small { font-weight: 500; opacity: .8; }
.count-badge.zero { background: var(--taken); color: var(--muted); }
.totals { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.total { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 6px; padding: 3px 10px; font-size: 14px; }
.total b { font-size: 16px; margin-right: 2px; }
.now-line { display: flex; align-items: center; gap: 8px; color: var(--danger); font-size: 12px; font-weight: 700; margin: 2px 0; }
.now-line::before, .now-line::after { content: ""; height: 2px; background: var(--danger); flex: 1; }
.now-line::before { flex: 0 0 20px; }
@media (max-width: 600px) {
  .trow { grid-template-columns: 58px 1fr; }
  .tact { grid-column: 1 / -1; justify-content: flex-start; }
}

.billing-customer summary { cursor: pointer; display: flex; justify-content: space-between; padding: 10px 12px; font-weight: 600; }
.billing-customer { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; }
.billing-customer table { border-top: 1px solid var(--line); }
