/* ---------------------------------------------------------- Grundlagen */
:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --panel-2: #fbfcfe;
  --border: #e2e6ee;
  --border-strong: #cdd4e0;
  --text: #1a2233;
  --muted: #667089;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --green: #059669;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .06), 0 8px 24px rgba(20, 30, 60, .07);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 17px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0; }
a { color: var(--accent); }

/* ---------------------------------------------------------- Kopfzeile */
header.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 18px;
  padding: 10px 20px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.brand .dot {
  width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, #2563eb, #7c3aed); color: #fff; font-size: 13px;
}
nav.tabs { display: flex; gap: 4px; }
nav.tabs button {
  border: 0; background: none; padding: 7px 14px; border-radius: 8px;
  font: inherit; font-weight: 550; color: var(--muted); cursor: pointer;
}
nav.tabs button:hover { background: #eef1f7; color: var(--text); }
nav.tabs button.active { background: var(--accent-soft); color: var(--accent); }
nav.tabs .badge {
  display: inline-block; min-width: 18px; margin-left: 6px; padding: 1px 6px;
  border-radius: 999px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
}
.topbar .spacer { flex: 1; }
.topbar .actions { display: flex; gap: 8px; align-items: center; }

/* ---------------------------------------------------------- Buttons */
button.btn, a.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 9px; border: 1px solid var(--border-strong);
  background: #fff; color: var(--text); font: inherit; font-weight: 550;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
button.btn:hover, a.btn:hover { background: #f4f6fb; }
button.btn.primary, a.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.btn.primary:hover { background: #1d4ed8; }
button.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.btn.ghost:hover { background: #eef1f7; color: var(--text); }
button.btn.danger { border-color: #f3c4c4; color: var(--red); }
button.btn.danger:hover { background: #fdecec; }
button.btn.small, a.btn.small { padding: 4px 9px; font-size: 12.5px; border-radius: 8px; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.btn.mailwarn { border-color: #f3c4c4; background: #fdecec; color: var(--red); font-weight: 650; }
button.btn.mailwarn:hover { background: #fbdcdc; }

/* ---------------------------------------------------------- Layout */
main { padding: 18px 20px 60px; max-width: 1500px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
.panel {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.panel .panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.panel .panel-head .spacer { flex: 1; }
.panel .panel-body { padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---------------------------------------------------------- Kalender */
.calendar-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; }
@media (max-width: 1100px) { .calendar-layout { grid-template-columns: 1fr; } }

.cal-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cal-title { font-size: 16px; font-weight: 650; min-width: 165px; }
.filter-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: #fff; font-size: 12.5px; font-weight: 550; cursor: pointer;
}
.chip .swatch { width: 9px; height: 9px; border-radius: 50%; }
.chip.active { background: var(--accent-soft); border-color: #b9ceff; color: var(--accent); }

.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 1px; background: var(--border); border-top: 1px solid var(--border); }
.cal-grid .dow {
  background: var(--panel-2); padding: 7px 8px; font-size: 11.5px; font-weight: 650;
  color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
}
.cal-cell {
  background: #fff; min-height: 108px; padding: 6px 7px; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
}
.cal-cell:hover { background: #f7f9fd; }
.cal-cell.other { background: #fafbfd; color: #aab2c4; }
.cal-cell.today .daynum { background: var(--accent); color: #fff; }
.cal-cell.selected { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-cell .daynum {
  align-self: flex-start; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 999px; display: grid; place-items: center;
  font-size: 12.5px; font-weight: 600;
}
.cal-cell .weekend { color: #98a1b5; }
.evt {
  display: flex; align-items: center; gap: 5px; padding: 3px 6px; border-radius: 6px;
  font-size: 11.5px; font-weight: 550; color: #fff; overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis;
}
.evt.cancelled { opacity: .45; text-decoration: line-through; }
.evt .time { font-variant-numeric: tabular-nums; opacity: .85; }
.more { font-size: 11px; color: var(--muted); padding-left: 4px; }

.agenda-item {
  display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.agenda-item:last-child { border-bottom: 0; }
.agenda-item:hover { background: #f7f9fd; }
.agenda-item .bar { width: 4px; border-radius: 3px; flex: 0 0 4px; }
.agenda-item .when { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------------------------------------------------------- Anfragen */
.requests-layout { display: grid; grid-template-columns: 370px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .requests-layout { grid-template-columns: 1fr; } }

.req-filter { display: flex; gap: 5px; padding: 10px 12px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.req-search { padding: 10px 12px; border-bottom: 1px solid var(--border); }
input.search {
  width: 100%; padding: 8px 11px; border-radius: 9px; border: 1px solid var(--border-strong);
  font: inherit; background: #fff;
}
.req-list { max-height: calc(100vh - 260px); overflow-y: auto; }
.req-item {
  padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
  display: flex; gap: 10px; align-items: flex-start;
}
.req-item:hover { background: #f7f9fd; }
.req-item.active { background: var(--accent-soft); }
.req-item .avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: 0 0 32px; display: grid; place-items: center;
  background: #e7ecf6; color: #4a5673; font-weight: 700; font-size: 12px;
}
.req-item .name { font-weight: 600; }
.req-item .line { display: flex; align-items: center; gap: 6px; }
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 650; white-space: nowrap;
}
.pill.offen { background: #fee2e2; color: #b91c1c; }
.pill.in_bearbeitung { background: #fef3c7; color: #92400e; }
.pill.erledigt { background: #dcfce7; color: #15803d; }
.pill.kein_interesse { background: #e5e7eb; color: #4b5563; }
.pill.soft { background: #eef2f9; color: var(--muted); }

/* ---------------------------------------------------------- Formulare */
.field { margin-bottom: 14px; }
.field > label.q {
  display: block; font-weight: 600; margin-bottom: 6px; font-size: 13.5px;
}
.field .req-star { color: var(--red); margin-left: 3px; }
.field .help { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
input[type=text], input[type=email], input[type=tel], input[type=number],
input[type=date], input[type=time], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: 9px;
  font: inherit; background: #fff; color: var(--text);
}
textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfd3ff; border-color: var(--accent); }
.opts { display: flex; flex-direction: column; gap: 6px; }
.opts.row { flex-direction: row; flex-wrap: wrap; gap: 8px; }
label.opt {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px;
  border: 1px solid var(--border-strong); border-radius: 9px; background: #fff; cursor: pointer;
}
label.opt:hover { background: #f5f8ff; }
label.opt input { accent-color: var(--accent); }
label.opt.checked { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* Frei eintragbare Einträge - sehen aus wie die Ankreuzfelder, werden aber getippt. */
.opt.free {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px;
  border: 1px dashed var(--border-strong); border-radius: 9px; background: #fff;
}
.opt.free:focus-within { border-style: solid; border-color: var(--accent); outline: 2px solid #bfd3ff; }
.opt.free.checked { border-style: solid; border-color: var(--accent); background: var(--accent-soft); }
.opt.free .free-check { pointer-events: none; accent-color: var(--accent); }
.opt.free input.free-text {
  width: 160px; padding: 0; border: 0; outline: none; background: transparent;
  font: inherit; color: inherit;
}
.opt.free.checked input.free-text { color: var(--accent); }
.opt.free input.free-text::placeholder { color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 700px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

fieldset.section {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  margin: 0 0 14px; background: var(--panel-2);
}
fieldset.section > legend { padding: 0 8px; font-weight: 650; font-size: 13.5px; }

.info-box {
  padding: 10px 12px; border-radius: 9px; background: #eff6ff; border: 1px solid #d5e4ff;
  color: #1e40af; font-size: 13px;
}
.warn-box {
  padding: 10px 12px; border-radius: 9px; background: #fff7ed; border: 1px solid #fed7aa;
  color: #9a3412; font-size: 13px;
}

/* ---------------------------------------------------------- Termin-Block */
.appt-box {
  border: 2px solid #d5e4ff; border-radius: var(--radius); background: #f7faff; padding: 16px;
}
.appt-box .appt-question { font-size: 15px; font-weight: 650; margin-bottom: 12px; }
.slots { display: flex; flex-wrap: wrap; gap: 6px; max-height: 190px; overflow-y: auto; padding: 2px; }
.slot {
  padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: #fff; font-size: 12.5px; cursor: pointer; font-variant-numeric: tabular-nums;
}
.slot:hover { border-color: var(--accent); }
.slot.taken { opacity: .35; text-decoration: line-through; cursor: not-allowed; }
.slot.selected { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.appt-card {
  display: flex; gap: 10px; align-items: center; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: #fff; margin-bottom: 8px;
}
.appt-card .bar { width: 4px; align-self: stretch; border-radius: 3px; }

/* ---------------------------------------------------------- Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 22, 40, .45); z-index: 100;
  display: grid; place-items: center; padding: 20px;
}
.modal {
  background: #fff; border-radius: 14px; box-shadow: 0 20px 60px rgba(10, 20, 45, .3);
  width: min(720px, 100%); max-height: 88vh; display: flex; flex-direction: column;
}
.modal.wide { width: min(1000px, 100%); }
.modal .modal-head { padding: 15px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.modal .modal-body { padding: 18px; overflow-y: auto; }
.modal .modal-foot {
  padding: 13px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px;
  justify-content: flex-end; background: var(--panel-2); border-radius: 0 0 14px 14px;
}

/* ---------------------------------------------------------- Toast */
#toasts { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 11px 15px; border-radius: 10px; background: #10182b; color: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); font-size: 13.5px; max-width: 420px;
  animation: pop .18s ease-out;
}
.toast.error { background: #b91c1c; }
.toast.ok { background: #15803d; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.saving-hint { font-size: 12.5px; color: var(--muted); }
.saving-hint.saved { color: var(--green); }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13.5px; }
.kv .k { color: var(--muted); }
textarea.code {
  width: 100%; min-height: 420px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.55; white-space: pre; overflow-wrap: normal; overflow-x: auto;
}

/* ---------------------------------------------------------- Angebote, Kunden, Rechnungen */
nav.tabs .badge.amber { background: var(--amber); }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 900px) { .grid4 { grid-template-columns: 1fr 1fr; } }

.pill.st-entwurf { background: #eef2f9; color: #475569; }
.pill.st-versendet { background: #e0ecff; color: #1d4ed8; }
.pill.st-angenommen, .pill.st-bezahlt, .pill.st-k-aktiv { background: #dcfce7; color: #15803d; }
.pill.st-abgelehnt, .pill.st-storniert, .pill.st-k-beendet { background: #e5e7eb; color: #4b5563; }
.pill.st-abgelaufen, .pill.st-k-pausiert { background: #fef3c7; color: #92400e; }
.pill.st-offen { background: #fef3c7; color: #92400e; }
.pill.st-ueberfaellig, .pill.st-warn { background: #fee2e2; color: #b91c1c; }
.pill.st-nachfassen { background: #fbe9e2; color: #a85a3c; margin-left: 4px; }
.info-box.ok-box { background: #ecfdf3; border-color: #bbf7d0; color: #166534; }

.item-card {
  border: 1px solid var(--border); border-radius: 10px; background: #fff;
  padding: 12px 14px 2px; margin-bottom: 10px;
}
.item-card .item-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.item-card .item-head .spacer { flex: 1; }
.item-card .item-calc { font-size: 12.5px; font-weight: 600; color: var(--accent); }
.item-card .field { margin-bottom: 10px; }

.totals {
  margin: 10px 0 4px auto; max-width: 340px; padding: 10px 14px; border-radius: 10px;
  background: #f5efe6; display: flex; flex-direction: column; gap: 4px;
}
.totals > div { display: flex; justify-content: space-between; gap: 20px; }
.totals b { color: #10254a; font-size: 15px; }
.totals.inline { margin: 0; min-width: 260px; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; font-size: 11.5px; font-weight: 650; color: var(--muted); text-transform: uppercase;
  letter-spacing: .03em; padding: 9px 12px; border-bottom: 1px solid var(--border); background: var(--panel-2);
}
table.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.tbl .r { text-align: right; }
table.tbl tbody tr[data-invoice] { cursor: pointer; }
table.tbl tbody tr[data-invoice]:hover { background: #f7f9fd; }
table.tbl tr.sum td { font-weight: 700; border-bottom: 0; }
table.tbl.edit td { padding: 6px 6px; }
table.tbl.edit input, table.tbl.edit select { padding: 6px 8px; }
table.tbl.edit td:nth-child(2) { width: 46%; }
table.tbl.edit td:nth-child(1) input { min-width: 135px; }

/* ---------------------------------------------------------- Benutzer */
button.btn.user-chip { border-radius: 999px; background: #f5efe6; border-color: #e8dccb; color: #10254a; }
button.btn.user-chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #059669; }
.pill.st-gesperrt { background: #e5e7eb; color: #4b5563; }
.pill.st-einladung { background: #fef3c7; color: #92400e; }
.link-box { display: flex; gap: 8px; }
.link-box input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
@media (max-width: 1250px) { .brand #appName { display: none; } header.topbar { gap: 10px; } }

/* ---------------------------------------------------------- Ruhige Formulare
   Ein Raster fuer alle Formulare: gleich breite Spalten, die sich ueber alle Zeilen
   eines Formulars decken. Kurze Angaben belegen eine Spalte, .wide die ganze Zeile.
   Felder richten sich an der Unterkante aus, damit Eingabefelder auf einer Linie
   stehen, auch wenn eine Beschriftung zweizeilig wird. */
.form-grid, .grid2, .grid3, .grid4 {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0 16px; align-items: end;
}
.form-grid > .wide { grid-column: 1 / -1; }
.form-grid > .span2 { grid-column: span 2; }
@media (max-width: 700px) { .form-grid > .span2 { grid-column: 1 / -1; } }
.form-grid.compact { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px 16px; }
.check-grid > .field { margin: 0; display: flex; }
.check-grid > .field > .opts, .check-grid label.opt { flex: 1; height: 100%; }
.form-grid > [hidden] { display: none !important; }

input[type=text], input[type=email], input[type=tel], input[type=number], input[type=password],
input[type=date], input[type=time], input[type=month], select {
  height: 40px; padding-top: 0; padding-bottom: 0;
}
textarea { min-height: 84px; }
textarea[rows="2"] { min-height: 62px; }
.field > label.q { line-height: 1.3; }

/* Auswahl-Kacheln: alle gleich breit und in Spalten */
.opts.row { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px 16px; }
.opts { display: block; }
label.opt, .opt.free {
  display: flex; width: 100%; min-height: 40px; padding: 8px 12px; line-height: 1.3;
}
.opt.free input.free-text { flex: 1; width: auto; min-width: 0; }

/* Datum + "Heute" in einer Zeile */
.input-row { display: flex; gap: 8px; align-items: center; }
.input-row > input { flex: 1; min-width: 0; }
.input-row > .chip { height: 40px; border-radius: 9px; padding: 0 14px; flex: 0 0 auto; }

/* Abschnitte flach statt Kasten im Kasten */
.qsection { padding: 18px 0 4px; border-top: 1px solid var(--border); }
.qsection:first-of-type { border-top: 0; padding-top: 2px; }
.qsection-title {
  display: flex; align-items: center; gap: 10px; margin: 0 0 14px;
  font-size: 15px; font-weight: 650; color: var(--text);
}
.qsection-title::before { content: ""; width: 4px; height: 18px; border-radius: 2px; background: var(--accent); }

fieldset.section {
  border: 0; border-top: 1px solid var(--border); border-radius: 0; background: none;
  padding: 16px 0 2px; margin: 0 0 6px;
}
fieldset.section:first-of-type { border-top: 0; padding-top: 0; }
fieldset.section > legend {
  float: left; width: 100%; padding: 0; margin: 0 0 14px;
  display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 650;
}
fieldset.section > legend::before { content: ""; width: 4px; height: 18px; border-radius: 2px; background: var(--accent); }
fieldset.section > legend + * { clear: both; }
