/* ==========================================================================
   Schadenportal – Stylesheet
   Akzentfarbe kommt als --accent aus den Einstellungen (siehe layout.php).
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

:root {
  --accent: #e2001a;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1a2333;
  --muted: #6b7280;
  --line: #e5e7eb;
  --good: #16a34a;
  --bad: #dc2626;
  --warn: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .07), 0 1px 2px rgba(16, 24, 40, .05);
}

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.02rem; margin: 0 0 .75rem; color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Kopfleiste ---------- */

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: .6rem 1rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); }
.brand:hover { text-decoration: none; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 1.15rem;
  flex: none;
}

.brand-mark-lg { width: 54px; height: 54px; font-size: 1.6rem; border-radius: 14px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 1rem; }
.brand-text small { color: var(--muted); font-size: .74rem; }

.mainnav { display: flex; gap: .25rem; flex: 1; }
.mainnav a {
  padding: .45rem .8rem;
  border-radius: 8px;
  color: var(--text);
  font-weight: 500;
}
.mainnav a:hover { background: var(--bg); text-decoration: none; }
.mainnav a.active { background: color-mix(in srgb, var(--accent) 10%, white); color: var(--accent); }
.mainnav a.cockpit-link { border: 1px solid var(--line); background: #fafbfc; color: var(--muted); }
.mainnav a.cockpit-link:hover { border-color: var(--accent); color: var(--accent); background: var(--card); }

.topbar-right { display: flex; align-items: center; gap: 1rem; }
.userbox { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .85rem; }
.userbox form { margin: 0; }

.linklike {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  font-size: .85rem;
}
.linklike:hover { text-decoration: underline; }

/* ---------- Layout ---------- */

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.container-bare { max-width: none; padding: 0; }

.page-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}
.page-head h1 { margin-right: auto; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}

.card.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

.grid-cards {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
  align-items: stretch;
}

.grid-two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* ---------- Statistik-Karten ---------- */

.stat-card { display: flex; flex-direction: column; }
.stat-big { font-size: 2.3rem; font-weight: 700; line-height: 1.1; margin: .25rem 0 .4rem; }
.stat-warn .stat-big { color: var(--warn); }
.cardlink { font-size: .85rem; margin-top: auto; }

.quota-card .quota-big {
  font-size: 2.9rem;
  font-weight: 800;
  line-height: 1.1;
  margin: .2rem 0 .55rem;
}
.quota-big.good { color: var(--good); }
.quota-big.bad { color: var(--bad); }

.progress {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background: var(--line);
  margin: .35rem 0 .8rem;
}
.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  background: var(--good);
}
.progress-fill.bad { background: var(--bad); }
.progress-target {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 3px;
  border-radius: 2px;
  background: var(--text);
  transform: translateX(-50%);
}

.hint { padding: .55rem .8rem; border-radius: 8px; font-size: .9rem; margin: .5rem 0; }
.hint-good { background: #ecfdf3; color: #027a48; }
.hint-bad { background: #fef3f2; color: #b42318; }

/* ---------- Donut & Legende ---------- */

.donut-row { display: flex; gap: 1.5rem; align-items: center; flex-wrap: wrap; }
.donut { flex: none; }

.legend { border-collapse: collapse; flex: 1; min-width: 220px; }
.legend td { padding: .32rem .5rem; border-bottom: 1px solid var(--line); }
.legend tr:last-child td { border-bottom: none; }
.legend-total td { font-weight: 600; }
.swatch { display: inline-block; width: 26px; height: 13px; border-radius: 4px; vertical-align: middle; }

.minitable { width: 100%; border-collapse: collapse; }
.minitable td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
.minitable tr:last-child td { border-bottom: none; }

/* ---------- Kritisch-Leiste & Chips ---------- */

.critical-bar {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  background: #fef3f2;
  border: 1px solid #fecdca;
  color: #b42318;
  border-radius: var(--radius);
  padding: .65rem 1rem;
  margin-bottom: 1.1rem;
}

.chip {
  display: inline-block;
  padding: .25rem .7rem;
  border-radius: 999px;
  font-size: .84rem;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
}
.chip-critical { border-color: #fecdca; color: #b42318; }
.chip:hover { text-decoration: none; border-color: var(--accent); }

.dot-critical {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--bad);
  margin-right: .45rem;
  vertical-align: middle;
}

/* ---------- Status-Badges ---------- */

.badge {
  display: inline-block;
  padding: .22rem .6rem;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-lg { font-size: .92rem; padding: .3rem .85rem; }

.badge-neu { background: #eff6ff; color: #1d4ed8; }
.badge-offen { background: #fefce8; color: #a16207; }
.badge-warten_kva { background: #fffbeb; color: #b45309; }
.badge-warten_rechnung { background: #fff7ed; color: #c2410c; }
.badge-warten_vu { background: #f5f3ff; color: #6d28d9; }
.badge-abgeschlossen { background: #ecfdf3; color: #027a48; }

.age-warn { color: var(--warn); font-size: .8rem; white-space: nowrap; }

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: .35rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.tab {
  padding: .45rem .85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-weight: 500;
  font-size: .9rem;
}
.tab:hover { text-decoration: none; border-color: var(--accent); }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tab .count {
  display: inline-block;
  min-width: 1.4em;
  text-align: center;
  padding: 0 .35em;
  margin-left: .3em;
  border-radius: 999px;
  background: rgba(0, 0, 0, .08);
  font-size: .8em;
}
.tab.active .count { background: rgba(255, 255, 255, .25); }

/* ---------- Tabellen ---------- */

.table-card { padding: 0; overflow: hidden; }

table.claims { width: 100%; border-collapse: collapse; }
table.claims th {
  text-align: left;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--muted);
  padding: .7rem .9rem;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
}
table.claims td {
  padding: .65rem .9rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.claims tbody tr { cursor: pointer; }
table.claims tbody tr:hover { background: #f8fafc; }
table.claims tbody tr:last-child td { border-bottom: none; }

/* ---------- Formulare ---------- */

.form-card { margin-bottom: 1rem; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .9rem 1.1rem;
}
.form-grid-wide {
  grid-template-columns: 2fr 1fr;
  margin-top: 1rem;
}

.field { display: flex; flex-direction: column; gap: .3rem; }
.field > span { font-size: .82rem; font-weight: 600; color: var(--muted); }

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="search"], select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: .5rem .65rem;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 35%, white);
  border-color: var(--accent);
}
textarea { resize: vertical; }

.field-hint { font-size: .8rem; font-style: normal; color: var(--muted); }
.field-hint.warn, #dup-hint { color: var(--warn); font-weight: 600; }

.checklist {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  background: #fafbfc;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .8rem .95rem;
  align-self: start;
}
.check {
  display: flex;
  align-items: center;
  gap: .55rem;
  cursor: pointer;
  padding: .18rem 0;
}
.check input { width: 17px; height: 17px; accent-color: var(--accent); flex: none; }
.check.disabled { opacity: .45; }
.check .stamp { font-size: .8rem; color: var(--muted); font-style: normal; margin-left: auto; }
.check-critical { color: #b42318; font-weight: 600; }
.check-critical input { accent-color: #b42318; }
.check-inline { display: inline-flex; align-items: center; gap: .4rem; margin-left: .75rem; font-weight: 600; cursor: pointer; }

/* Teilrechnungen */
.re-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr auto auto;
  gap: .9rem 1.1rem;
  align-items: end;
  padding: .55rem 0;
  border-bottom: 1px dashed var(--line);
}
.re-row .re-check { padding-bottom: .5rem; }
.re-row .re-check .stamp { margin-left: .1rem; }
.re-remove {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: .45rem .55rem;
  margin-bottom: .35rem;
  border-radius: 6px;
}
.re-remove:hover { color: #b42318; background: #fee4e2; }
#btn-re-add { margin-top: .85rem; }
input[type="text"][readonly] { background: #f3f4f6; color: var(--muted); }

.form-actions {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  align-items: center;
  margin: 1.1rem 0;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  padding: .5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  text-align: center;
}
.btn:hover { text-decoration: none; border-color: var(--accent); color: var(--accent); }

.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { color: #fff; filter: brightness(.92); }

.btn-good { background: var(--good); border-color: var(--good); color: #fff; }
.btn-good:hover { color: #fff; filter: brightness(.92); }

.btn-outline-danger { background: var(--card); border-color: var(--bad); color: var(--bad); }
.btn-outline-danger:hover { background: #fef3f2; color: var(--bad); }

.btn-plain { border-color: transparent; background: transparent; color: var(--muted); }
.btn-block { width: 100%; }

/* ---------- Flash-Meldungen ---------- */

.flash {
  padding: .7rem 1rem;
  border-radius: 10px;
  margin-bottom: .9rem;
  border: 1px solid transparent;
}
.flash-ok { background: #ecfdf3; border-color: #a6f4c5; color: #027a48; }
.flash-fehler { background: #fef3f2; border-color: #fecdca; color: #b42318; }
.flash-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.flash-quote-good { background: #ecfdf3; border-color: #a6f4c5; color: #027a48; }
.flash-quote-bad { background: #fef3f2; border-color: #fecdca; color: #b42318; }
.flash-quote-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.flash-quote-neutral { background: #f8fafc; border-color: var(--line); color: var(--muted); }

/* ---------- Suche & Jahr ---------- */

.searchbox { display: flex; gap: .5rem; }
.searchbox input[type="search"] { width: 260px; }
.year-select label { display: flex; align-items: center; gap: .5rem; font-size: .88rem; color: var(--muted); }
.year-select select { width: auto; }

/* ---------- Verlauf ---------- */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  display: grid;
  grid-template-columns: 170px 140px 1fr;
  gap: .75rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--line);
  font-size: .88rem;
}
.timeline li:last-child { border-bottom: none; }
.tl-time { color: var(--muted); white-space: nowrap; }
.tl-user { font-weight: 600; }

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 2rem;
}
.login-brand { text-align: center; margin-bottom: 1.4rem; }
.login-brand .brand-mark-lg { margin-bottom: .6rem; }
.login-brand h1 { font-size: 1.3rem; margin: 0; }
.login-card .field { margin-bottom: .9rem; }

/* ---------- Logo & Branding ---------- */

.brand-logo { height: 40px; max-width: 170px; object-fit: contain; flex: none; }
.login-logo { max-height: 60px; max-width: 220px; object-fit: contain; margin-bottom: .6rem; }
.logo-preview { display: flex; align-items: center; gap: .8rem; }
.logo-preview img { max-height: 44px; max-width: 160px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; padding: 3px; background: #fff; }
a.username { color: var(--muted); }
a.username:hover { color: var(--accent); }

/* ---------- Mail-Bereich am Schaden ---------- */

.mailrows { list-style: none; margin: 0; padding: 0; }
.mailrows li {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .55rem 0;
  border-bottom: 1px solid var(--line);
}
.mailrows li:last-child { border-bottom: none; }
.mailrows form { margin: 0; display: inline-flex; align-items: center; gap: .5rem; }
.mail-label { font-weight: 600; min-width: 250px; }
.mail-ok { color: var(--good); font-weight: 600; }
.mail-geplant { color: var(--warn); font-weight: 600; }
.btn-sm { padding: .32rem .75rem; font-size: .86rem; }

/* ---------- Einstellungen ---------- */

.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
input[type="color"] { padding: .15rem; height: 40px; width: 100%; border: 1px solid #d1d5db; border-radius: 8px; background: var(--card); }
input[type="file"] { font-size: .88rem; }
.vorlage { border-top: 1px solid var(--line); padding-top: .9rem; margin-top: .9rem; }
.vorlage h3 { font-size: .92rem; margin: 0 0 .6rem; }
.vorlage .field { margin-bottom: .7rem; }
code {
  background: #f1f5f9;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: .05rem .35rem;
  font-size: .82rem;
}
.arten-table input[type="text"] { max-width: 260px; }
.arten-table td { vertical-align: middle; }
.arten-head td { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.aktionen form { display: flex; gap: .8rem; flex-wrap: wrap; }
.betrag-erwartet { color: var(--muted); }

.danger-row { display: flex; justify-content: flex-end; margin: -0.3rem 0 1rem; }

.demo-banner {
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  color: #92400e;
  text-align: center;
  padding: .45rem 1rem;
  font-size: .88rem;
  font-weight: 500;
}

.th-sort { color: var(--muted); }
.th-sort:hover { color: var(--accent); text-decoration: none; }
.th-sort.active { color: var(--accent); }

/* ---------- Responsiv ---------- */

@media (max-width: 1000px) {
  .grid-cards { grid-template-columns: 1fr 1fr; }
  .quota-card { grid-column: 1 / -1; }
  .grid-two { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid-wide { grid-template-columns: 1fr; }
  .re-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .grid-cards { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar-inner { gap: .6rem; }
  .mainnav { order: 3; flex-basis: 100%; }
  .topbar-right { margin-left: auto; }
  .userbox .username { display: none; }
  .searchbox { width: 100%; }
  .searchbox input[type="search"] { flex: 1; width: auto; }
  .page-head h1 { flex-basis: 100%; }

  /* Tabelle wird zu Karten */
  table.claims thead { display: none; }
  table.claims, table.claims tbody, table.claims tr, table.claims td { display: block; width: 100%; }
  table.claims tr { border-bottom: 6px solid var(--bg); padding: .4rem 0; }
  table.claims td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    border-bottom: none;
    padding: .28rem .9rem;
    text-align: right;
  }
  table.claims td::before {
    content: attr(data-label);
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--muted);
    text-align: left;
    flex: none;
  }
  .timeline li { grid-template-columns: 1fr; gap: .1rem; }
}

/* ---------- 2FA-Wiederherstellungscodes ---------- */
.recovery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .55rem;
  margin-top: 1rem;
}
.recovery-code {
  display: block;
  padding: .5rem .7rem;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 1.02rem;
  letter-spacing: .06em;
  text-align: center;
}
@media print {
  .topbar, .sidebar, .form-actions, .flash { display: none !important; }
}

/* ---------- Portaleigene Dialoge (statt Browser-confirm) ---------- */
dialog.portal-dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(16, 24, 40, .25);
  padding: 1.4rem 1.6rem;
  max-width: 520px;
  width: calc(100% - 2rem);
  color: var(--text);
  background: var(--card);
}
dialog.portal-dialog::backdrop { background: rgba(16, 24, 40, .45); }
dialog.portal-dialog h2 { margin: 0 0 .5rem; font-size: 1.15rem; }
dialog.portal-dialog p { margin: 0 0 .8rem; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
