:root {
  --blau: #2563eb;
  --tuerkis: #0891b2;
  --gold: #f59e0b;
  --dunkel: #16324f;
  --bg: #f4f6f9;
  --karte: #ffffff;
  --rand: #e2e8f0;
  --text: #1f2933;
  --muted: #64748b;
  --gruen: #16a34a;
  --rot: #dc2626;
  --gelb: #d97706;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
button { cursor: pointer; font: inherit; }
a, .link { color: var(--blau); background: none; border: none; text-decoration: none; }
.link { padding: 0; }

/* --- Login --- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--dunkel), var(--blau)); }
.card { background: var(--karte); border: 1px solid var(--rand); border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.15); }
.login-card { width: 340px; padding: 32px; display: flex; flex-direction: column; gap: 14px; align-items: stretch; }
.login-logo { width: 64px; height: 64px; align-self: center; margin-bottom: 2px; }
.brand { margin: 0; font-size: 28px; color: var(--dunkel); text-align: center; }
.brand span { color: var(--tuerkis); }
.sub { margin: 0; color: var(--muted); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.login-card input { padding: 10px; border: 1px solid var(--rand); border-radius: 8px; font-size: 15px; }
.login-card button { padding: 11px; background: var(--blau); color: #fff; border: none; border-radius: 8px; font-weight: 600; }
.secret { display: block; background: var(--bg); padding: 8px; border-radius: 6px; word-break: break-all; font-size: 12px; }
.error { color: var(--rot); font-size: 13px; margin: 0; min-height: 16px; }

/* --- App-Shell --- */
.app-shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { background: var(--dunkel); color: #cdd9e5; display: flex; flex-direction: column; padding: 18px 0; }
.logo { font-size: 20px; font-weight: 700; padding: 0 20px 18px; color: #fff; display: flex; align-items: center; gap: 9px; }
.logo-img { width: 30px; height: 30px; background: #fff; border-radius: 7px; padding: 2px; }
.logo span { color: var(--tuerkis); }
nav { flex: 1; display: flex; flex-direction: column; }
.nav-item { padding: 11px 20px; color: #cdd9e5; text-align: left; background: none; border: none; border-left: 3px solid transparent; font-size: 14px; }
.nav-item:hover { background: rgba(255,255,255,.06); }
.nav-item.active { background: rgba(31,111,235,.25); border-left-color: var(--tuerkis); color: #fff; font-weight: 600; }
.user-box { padding: 14px 20px 0; border-top: 1px solid rgba(255,255,255,.1); display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.rolle-chip { align-self: flex-start; background: var(--tuerkis); color: #fff; padding: 1px 8px; border-radius: 10px; font-size: 11px; text-transform: uppercase; }
.user-box .link { color: #9db4cc; margin-top: 6px; }

.content { padding: 26px 32px; overflow: auto; }
.content h2 { margin: 0 0 18px; color: var(--dunkel); }

/* --- Bausteine --- */
.panel { background: var(--karte); border: 1px solid var(--rand); border-radius: 10px; padding: 20px; margin-bottom: 18px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.kpi { background: var(--karte); border: 1px solid var(--rand); border-radius: 10px; padding: 16px; }
.kpi .wert { font-size: 26px; font-weight: 700; color: var(--dunkel); }
.kpi .label { color: var(--muted); font-size: 13px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--rand); font-size: 14px; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.btn { padding: 8px 14px; background: var(--blau); color: #fff; border: none; border-radius: 7px; font-size: 14px; }
.btn.sek { background: #eef2f7; color: var(--dunkel); }
.btn.gefahr { background: var(--rot); }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; }
.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.form-row input, .form-row select { padding: 9px; border: 1px solid var(--rand); border-radius: 7px; font-size: 14px; font-weight: 400; color: var(--text); }
.platzhalter { color: var(--muted); font-style: italic; }

/* --- Filterleiste --- */
.filter { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filter input, .filter select { padding: 8px 10px; border: 1px solid var(--rand); border-radius: 7px; font-size: 14px; }
.filter input[type=search] { min-width: 240px; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f8fafc; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 11px; font-size: 12px; font-weight: 600; }
.st-interessent { background: #fef3c7; color: #92400e; }
.st-aktiv { background: #dcfce7; color: #166534; }
.st-pausiert { background: #e0e7ff; color: #3730a3; }
.st-gekuendigt { background: #fee2e2; color: #991b1b; }
.st-verloren { background: #f1f5f9; color: #475569; }
.rst-entwurf { background: #f1f5f9; color: #475569; }
.rst-offen { background: #e0e7ff; color: #3730a3; }
.rst-teilbezahlt { background: #fef3c7; color: #92400e; }
.rst-bezahlt { background: #dcfce7; color: #166534; }
.rst-ueberfaellig { background: #fee2e2; color: #991b1b; }
.rst-storniert { background: #e5e7eb; color: #6b7280; text-decoration: line-through; }
.summe-box { max-width: 320px; margin-left: auto; }
.summe-box .feld .k { background: #f8fafc; }
.pst-offen { background: #e0e7ff; color: #3730a3; }
.pst-freigegeben { background: #fef3c7; color: #92400e; }
.pst-ausgezahlt { background: #dcfce7; color: #166534; }
.pst-storniert { background: #e5e7eb; color: #6b7280; text-decoration: line-through; }
tfoot td { font-weight: 700; border-top: 2px solid var(--rand); }

/* --- Ladebalken --- */
#ladebalken { position: fixed; top: 0; left: 0; height: 3px; width: 0; z-index: 9999;
  background: linear-gradient(90deg, var(--tuerkis), var(--blau)); opacity: 0; transition: width .3s ease, opacity .3s ease; }
#ladebalken.aktiv { opacity: 1; }

/* --- Toasts --- */
#toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 9998; display: flex; flex-direction: column; gap: 10px; }
.toast { min-width: 220px; max-width: 360px; padding: 12px 16px; border-radius: 9px; color: #fff; font-size: 14px;
  box-shadow: 0 8px 26px rgba(0,0,0,.22); animation: toast-in .25s ease; display: flex; align-items: center; gap: 9px; }
.toast.ok { background: var(--gruen); }
.toast.err { background: var(--rot); }
.toast.info { background: var(--dunkel); }
.toast.raus { animation: toast-out .3s ease forwards; }
@keyframes toast-in { from { transform: translateX(30px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toast-out { to { transform: translateX(30px); opacity: 0; } }

/* --- Responsive / Mobil --- */
.hamburger { display: none; }
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 50; flex-direction: row; align-items: center; flex-wrap: wrap;
    padding: 10px 12px; gap: 8px; }
  .logo { padding: 0; flex: 1; }
  .hamburger { display: block; background: none; border: none; color: #fff; font-size: 22px; order: 2; }
  nav { flex: 1 0 100%; flex-direction: column; display: none; }
  .sidebar.offen nav { display: flex; }
  .user-box { flex: 1 0 100%; border-top: none; padding-top: 6px; flex-direction: row; align-items: center; gap: 10px; }
  .content { padding: 18px 16px; }
  .feld-grid { grid-template-columns: 1fr; }
  .filter input[type=search] { min-width: 0; flex: 1; }
  .summe-box { max-width: none; }
  table { font-size: 13px; }
}
@media (max-width: 560px) {
  .detail-kopf { align-items: flex-start; }
  .aktion-leiste { margin-left: 0; flex-wrap: wrap; }
  .panel { padding: 14px; }
}
/* Waagerecht scrollbare Tabellen auf schmalen Screens */
.panel { overflow-x: auto; }

/* --- Detailansicht (Praxis) --- */
.detail-kopf { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 6px; }
.detail-kopf h2 { margin: 0; }
.detail-kopf .zurueck { font-size: 14px; }
.detail-meta { color: var(--muted); font-size: 13px; margin-bottom: 16px; }
.sektion { border: 1px solid var(--rand); border-radius: 10px; padding: 14px 18px 18px; margin-bottom: 16px; background: var(--karte); }
.sektion > legend, .sektion > .sektion-titel { font-weight: 700; color: var(--blau); font-size: 15px; padding: 0 6px; margin-bottom: 12px; display: block; }
.feld-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 8px 18px; }
.feld { display: grid; grid-template-columns: 46% 54%; align-items: center; border: 1px solid var(--rand); border-radius: 6px; overflow: hidden; }
.feld .k { background: #eef1f5; padding: 8px 10px; font-size: 13px; font-weight: 600; color: #334155; }
.feld .v { padding: 8px 10px; font-size: 14px; }
.feld.voll { grid-column: 1 / -1; }
.feld .v input, .feld .v select, .feld .v textarea { width: 100%; border: none; background: #fffbe6; padding: 6px; font: inherit; border-radius: 4px; }
.feld .v textarea { min-height: 54px; resize: vertical; }
.bearbeiten .feld .v { background: #fffdf5; }

.sub-tabelle th, .sub-tabelle td { padding: 7px 8px; }
.tag { display: inline-block; background: #e2e8f0; color: #334155; padding: 1px 8px; border-radius: 6px; font-size: 12px; }
.mini { font-size: 13px; padding: 5px 10px; }
.aktion-leiste { display: flex; gap: 8px; margin-left: auto; }
.inline-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; align-items: end; margin-top: 10px; padding-top: 12px; border-top: 1px dashed var(--rand); }
.inline-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); font-weight: 600; }
.inline-form input, .inline-form select, .inline-form textarea { padding: 7px; border: 1px solid var(--rand); border-radius: 6px; font: inherit; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--rand); margin: 4px 0 16px; }
.tab { padding: 9px 16px; border: none; background: none; font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tab.active { color: var(--blau); border-bottom-color: var(--blau); font-weight: 600; }
