/*
 * Gemeinsame Oberflächenbausteine für alle neuen Module.
 * Baut auf dem bestehenden Design auf (main.css): blauer Hintergrund
 * #1c60ab, weiße Karten, dunkle Seitenleiste, grüne Speichern-Buttons.
 * Seiten mit <body class="app"> erhalten zusätzlich ein responsives Layout.
 */
:root {
  --blau: #1c60ab;
  --blau-dunkel: #164d8a;
  --blau-hell: #e8f0fa;
  --menue: rgb(29, 35, 39);
  --gruen: #4caf50;
  --gruen-dunkel: #3d8b40;
  --rot: #d32f2f;
  --orange: #ef8a00;
  --grau: #6b7280;
  --grau-hell: #f3f4f6;
  --rahmen: #dcdfe4;
  --text: #1f2937;
  --radius: 6px;
}

/* ---------------------------------------------------------------- Layout */
body.app {
  height: auto;
  min-height: 100vh;
  justify-content: flex-start;
  color: var(--text);
}
body.app .container1 { height: auto; align-items: center; }
body.app .container1 img { max-height: 60px; width: auto; }
body.app .container2 { height: auto; min-height: 75vh; align-items: stretch; }
body.app .menu { align-items: flex-start; padding-top: 10px; flex-shrink: 0; }
body.app .menu ul { margin-top: 0; }
body.app .menu li a { border-radius: 0; }

.app-content {
  flex: 1;
  min-width: 0;
  padding: 20px 24px 30px 4px;
  overflow-x: auto;
}
.app-content h2 { margin-top: 0; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
.page-head h2 { margin: 0; font-size: 26px; color: #333; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--rahmen);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  font-size: 14px;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color .15s, border-color .15s;
}
.btn:hover { background: var(--grau-hell); }
.btn:focus-visible, .app input:focus-visible, .app select:focus-visible, .app textarea:focus-visible {
  outline: 2px solid var(--blau);
  outline-offset: 1px;
}
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn .material-symbols-outlined { font-size: 18px; margin: 0; }
.btn-primary { background: var(--blau); border-color: var(--blau); color: #fff; }
.btn-primary:hover { background: var(--blau-dunkel); }
.btn-success { background: var(--gruen); border-color: var(--gruen); color: #fff; }
.btn-success:hover { background: var(--gruen-dunkel); }
.btn-danger { background: #fff; border-color: var(--rot); color: var(--rot); }
.btn-danger:hover { background: #fdecec; }
.btn-danger-solid { background: var(--rot); border-color: var(--rot); color: #fff; }
.btn-sm { padding: 5px 9px; font-size: 13px; }
.btn-link { border: 0; background: none; color: var(--blau); padding: 0; }
.btn-link:hover { text-decoration: underline; background: none; }

/* ---------------------------------------------------------------- Filter */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  background: var(--grau-hell);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 14px;
}
.filters label { display: flex; flex-direction: column; font-size: 12px; color: var(--grau); gap: 3px; }
.app input:not([type]), .app input[type=text], .app input[type=search], .app input[type=date], .app input[type=time], .app input[type=datetime-local],
.app input[type=number], .app input[type=email], .app input[type=tel], .app select, .app textarea {
  font: inherit;
  font-size: 14px;
  padding: 7px 9px;
  border: 1px solid var(--rahmen);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  box-sizing: border-box;
  max-width: 100%;
}
.app textarea { min-height: 90px; resize: vertical; width: 100%; }
.app input.invalid, .app select.invalid, .app textarea.invalid { border-color: var(--rot); background: #fff8f8; }

/* ---------------------------------------------------------------- Formulare */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px 16px;
  margin-bottom: 14px;
}
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span, .field > label { font-size: 13px; font-weight: bold; color: #374151; }
.field .hint { font-size: 12px; color: var(--grau); font-weight: normal; }
.field input, .field select, .field textarea { width: 100%; }
.field-error { color: var(--rot); font-size: 12px; }
.req::after { content: ' *'; color: var(--rot); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.check-list { display: flex; flex-wrap: wrap; gap: 6px 16px; }
fieldset.box { border: 1px solid var(--rahmen); border-radius: var(--radius); padding: 12px 14px; margin: 0 0 14px; }
fieldset.box legend { font-weight: bold; padding: 0 6px; color: var(--blau); }

/* ---------------------------------------------------------------- Tabellen */
.table-wrap { overflow-x: auto; border: 1px solid var(--rahmen); border-radius: var(--radius); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td {
  border: 0;
  border-bottom: 1px solid #eceef1;
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  width: auto;
}
table.data th { background: #f7f8fa; color: #374151; font-size: 13px; position: sticky; top: 0; white-space: nowrap; }
table.data tbody tr:hover { background: #fafbff; }
table.data tr.clickable { cursor: pointer; }
table.data td.num, table.data th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.data td.actions { white-space: nowrap; text-align: right; }
table.data .muted { color: var(--grau); font-size: 12px; }
table.data tfoot td { font-weight: bold; background: #f7f8fa; }

/* ---------------------------------------------------------------- Status */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: bold;
  line-height: 18px;
  white-space: nowrap;
  background: var(--grau-hell);
  color: #374151;
}
.badge-blau { background: #dbe8f8; color: #134a85; }
.badge-gruen { background: #dcf3dd; color: #1e6b22; }
.badge-gelb { background: #fff1cc; color: #7a5300; }
.badge-orange { background: #ffe4c7; color: #8a4500; }
.badge-rot { background: #fde0e0; color: #9b1c1c; }
.badge-grau { background: #eceef1; color: #4b5563; }
.dot-new { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--blau); margin-right: 6px; }

/* ---------------------------------------------------------------- Karten */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { border: 1px solid var(--rahmen); border-radius: var(--radius); padding: 12px 14px; background: #fff; }
.stat .label { font-size: 12px; color: var(--grau); text-transform: uppercase; letter-spacing: .03em; }
.stat .value { font-size: 24px; font-weight: bold; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat.pos .value { color: var(--gruen-dunkel); }
.stat.neg .value { color: var(--rot); }
.card { border: 1px solid var(--rahmen); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; background: #fff; }
.card.wichtig { border-left: 4px solid var(--rot); }
.card.ungelesen { border-left: 4px solid var(--blau); }
.card h3 { margin: 0 0 6px; font-size: 17px; }
.card .meta { font-size: 12px; color: var(--grau); margin-bottom: 6px; }
.prewrap { white-space: pre-wrap; word-wrap: break-word; }

/* ---------------------------------------------------------------- Hinweise */
.alert { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: 14px; border: 1px solid; }
.alert-info { background: var(--blau-hell); border-color: #b8cff0; color: #123d6e; }
.alert-warn { background: #fff7e0; border-color: #f0d68c; color: #6b4b00; }
.alert-error { background: #fdecec; border-color: #f2b8b8; color: #8a1c1c; }
.alert-ok { background: #e9f7ea; border-color: #b7e0b9; color: #1e5a21; }

.empty-state { text-align: center; color: var(--grau); padding: 40px 10px; }
.empty-state .material-symbols-outlined { font-size: 44px; margin: 0; color: #9ca3af; }
.empty-state h2 { color: #374151; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--grau); padding: 30px 10px; justify-content: center; }
.spinner { width: 20px; height: 20px; border: 3px solid #d6dbe3; border-top-color: var(--blau); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.progress { height: 10px; background: #e5e7eb; border-radius: 999px; overflow: hidden; min-width: 80px; }
.progress > div { height: 100%; background: var(--gruen); }

/* ---------------------------------------------------------------- Dialoge */
.dlg-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 12px; z-index: 1000; overflow-y: auto;
}
.dlg {
  background: #fff; border-radius: 8px; width: 100%; max-width: 560px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.dlg.wide { max-width: 980px; }
.dlg header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid #eceef1; }
.dlg header h3 { margin: 0; font-size: 18px; }
.dlg .dlg-body { padding: 16px 18px; }
.dlg footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid #eceef1; flex-wrap: wrap; }
.dlg .close { border: 0; background: none; cursor: pointer; font-size: 22px; color: var(--grau); }

/* ---------------------------------------------------------------- Toast */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 32px); }
.toast {
  background: #1f2937; color: #fff; padding: 11px 16px; border-radius: var(--radius);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .25); font-size: 14px; max-width: 420px;
  animation: toastIn .2s ease-out;
}
.toast.ok { background: #2e7d32; }
.toast.error { background: #b71c1c; }
.toast.warn { background: #8a5a00; }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------------------------------------------------------- Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--rahmen); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button {
  border: 0; background: none; padding: 9px 14px; cursor: pointer; font-size: 14px;
  border-bottom: 3px solid transparent; color: var(--grau);
}
.tabs button.active { border-bottom-color: var(--blau); color: var(--blau); font-weight: bold; }

/* ---------------------------------------------------------------- Balkendiagramm */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 200px; padding: 10px 4px 0; border-bottom: 1px solid var(--rahmen); overflow-x: auto; }
.chart .col { display: flex; flex-direction: column; align-items: center; min-width: 46px; flex: 1; height: 100%; justify-content: flex-end; }
.chart .bars { display: flex; align-items: flex-end; gap: 3px; height: 100%; }
.chart .bar { width: 14px; border-radius: 3px 3px 0 0; min-height: 1px; }
.chart .bar.ein { background: var(--gruen); }
.chart .bar.aus { background: var(--rot); }
.chart .lbl { font-size: 11px; color: var(--grau); margin-top: 4px; white-space: nowrap; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--grau); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* ---------------------------------------------------------------- Startseite */
.tile-badge {
  display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 999px; background: var(--rot); color: #fff;
  font-size: 12px; line-height: 18px; text-align: center; margin-left: 6px; vertical-align: 2px;
}

/* ---------------------------------------------------------------- Responsiv */
@media (max-width: 900px) {
  body.app .container1, body.app .container2, body.app .container3 { width: calc(100% - 24px); max-width: none; }
  body.app .container1 { padding: 12px; }
  body.app .container1 h1 { font-size: 18px; }
  body.app .container1 h2 { font-size: 14px; }
  body.app .container1 img { max-height: 44px; margin-right: 10px; }
  body.app .container2 { flex-direction: column; }
  body.app .menu { max-width: none; width: 100%; margin-right: 0; padding-top: 0; }
  body.app .menu ul { display: flex; overflow-x: auto; margin: 0; width: 100%; }
  body.app .menu li a { margin-bottom: 0; white-space: nowrap; padding: 10px 12px; font-size: 13px; }
  .app-content { padding: 14px 12px 24px; }
  .page-head h2 { font-size: 21px; }
  table.data { font-size: 13px; }
  table.data .hide-sm { display: none; }
}
@media (max-width: 520px) {
  .form-grid { grid-template-columns: 1fr; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters label, .filters input, .filters select { width: 100%; }
  .dlg footer .btn { flex: 1; justify-content: center; }
}

@media print {
  body.app { background: #fff; }
  body.app .menu, .no-print, .filters, #toasts { display: none !important; }
  body.app .container1, body.app .container2 { box-shadow: none; width: 100%; }
}

/* ---------------------------------------------------------------- Korrekturen */
/* [hidden] muss gegenüber display:flex/inline-flex gewinnen */
.app [hidden] { display: none !important; }
/* Icons: feste Breite, damit das Layout auch ohne geladene Iconschrift stabil bleibt */
.app .material-symbols-outlined { display: inline-block; width: 1em; overflow: hidden; white-space: nowrap; flex-shrink: 0; vertical-align: middle; }
.field input[type=checkbox], .field input[type=radio], .check input { width: auto; margin: 0; }
body.app .menu { width: 200px; max-width: 200px; overflow: hidden; }
body.app .menu li a { white-space: normal; line-height: 1.25; }
@media (max-width: 900px) {
  body.app .menu { width: 100%; max-width: none; overflow: visible; }
  body.app .menu li a { white-space: nowrap; }
}
/* Aktionsspalten dürfen umbrechen, Titelspalten nicht zu schmal werden */
table.data td.actions { white-space: normal; min-width: 120px; }
table.data td.actions > * { margin: 2px 0; }
table.data td > strong:first-child { display: inline-block; min-width: 110px; }
