:root {
  --bg: #f6f7fb;
  --card: rgba(255,255,255,0.85);
  --border: rgba(17,24,39,0.12);
  --text: rgba(17,24,39,0.92);
  --muted: rgba(17,24,39,0.60);
  --link: rgba(37,99,235,0.95);
  --bg-grad-1: rgba(59,130,246,0.16);
  --bg-grad-2: rgba(34,197,94,0.12);
  --bg-grad-3: transparent;
  --shadow: rgba(0,0,0,0.10);
  --font-main: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  --topbar-bg: rgba(0,0,0,0.06);
  --nav-bg: rgba(0,0,0,0.04);
  --control-bg: rgba(255,255,255,0.55);
  --control-bg-dark: rgba(0,0,0,0.18);
  --button-bg: rgba(59,130,246,0.22);
  --button-border: rgba(59,130,246,0.35);
  --secondary-bg: rgba(255,255,255,0.35);
  --danger-bg: rgba(239,68,68,0.18);
  --danger-border: rgba(239,68,68,0.35);
  --tag-bg: rgba(255,255,255,0.35);
  --msg-bg: rgba(255,255,255,0.35);
  --chart-bg: rgba(255,255,255,0.35);
  --pos: rgba(34,197,94,0.95);
  --neg: rgba(239,68,68,0.95);
  --warn: #e67e22;
  --radius: 16px;
  --radius-control: 12px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-main);
  background:
    radial-gradient(1200px 700px at 20% 10%, var(--bg-grad-1), transparent 60%),
    radial-gradient(1000px 600px at 80% 30%, var(--bg-grad-2), transparent 60%),
    radial-gradient(900px 600px at 55% 86%, var(--bg-grad-3), transparent 62%),
    var(--bg);
  color: var(--text);
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
.content { max-width: 1200px; margin: 0 auto; padding: 16px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: var(--topbar-bg); backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 10;
  box-shadow: 0 16px 34px var(--shadow);
}
.logo { font-weight: 900; letter-spacing: 0.2px; }
.year-form { display: flex; align-items: center; gap: 10px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.nav { display: flex; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--nav-bg); overflow-x: auto; }
.nav a { padding: 8px 10px; border-radius: var(--radius-pill); border: 1px solid transparent; white-space: nowrap; }
.nav a:hover, .nav a.active { border-color: var(--border); background: var(--button-bg); text-decoration: none; }
.nav a.active { font-weight: 900; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 10px 0; box-shadow: 0 20px 50px var(--shadow); }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.muted { color: var(--muted); } .small { font-size: 0.9rem; } .right { text-align: right; } .bold { font-weight: 900; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }
.sep { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }

label { display: block; margin-top: 10px; margin-bottom: 6px; color: var(--muted); }
input, select, textarea, button { width: 100%; padding: 10px 12px; border-radius: var(--radius-control); border: 1px solid var(--border); background: var(--control-bg); color: var(--text); outline: none; }
html[data-theme="dark"] input, html[data-theme="dark"] select, html[data-theme="dark"] textarea, html[data-theme="dark"] button { background: var(--control-bg-dark); }
/* Standard */
/* Dropdown-Optionen: immer gut lesbar */
select option {
  background: #ffffff;
  color: #000000;
}

/* auch im Dark Mode erzwingen */
html[data-theme="dark"] select option {
  background: #ffffff;
  color: #000000;
}
textarea { resize: vertical; }
button, .btn { margin-top: 12px; cursor: pointer; background: var(--button-bg); border: 1px solid var(--button-border); font-weight: 800; }
button:hover, .btn:hover { filter: brightness(1.08); }
.secondary { background: var(--secondary-bg); border-color: var(--border); }
.btn-danger { background: var(--danger-bg); border-color: var(--danger-border); }
.btn-small { margin-top: 0; padding: 8px 10px; width: auto; }
.theme-toggle, .logout, .year-form select { width: auto; border-radius: var(--radius-pill); }
.theme-toggle { padding: 8px 10px; cursor: pointer; line-height: 1; }
.logout { padding: 8px 10px; border: 1px solid var(--border); background: var(--secondary-bg); }
.inline { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.inline label { margin: 0; color: var(--text); }
.inline input { width: auto; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 900px) { .row-2 { grid-template-columns: 1fr; } }

.btn-icon { width: 34px; height: 34px; display: inline-flex; align-items: center; justify-content: center; padding: 0; margin-top: 0; line-height: 1; border-radius: var(--radius-pill); }
a.btn-icon { text-decoration: none; }
.btn-icon .icon { width: 18px; height: 18px; display: block; fill: currentColor; }
.btn-icon-edit { border: 1px solid var(--border); background: var(--secondary-bg); color: var(--link); }
.btn-icon-toggle { border: 1px solid var(--border); background: var(--secondary-bg); color: var(--text); }
.toggle-open .btn-icon-toggle { transform: rotate(180deg); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.booking-grid { display: grid; grid-template-columns: 20% 80%; gap: 12px; }
.grid-settings { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.settings-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.grid-2 > .card, .booking-grid > .card, .grid-settings > .card { min-width: 0; }
@media (max-width: 1000px) { .grid-2, .booking-grid, .grid-settings { grid-template-columns: 1fr; } }

.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; min-width: 900px; }
.table th, .table td { border-bottom: 1px solid var(--border); padding: 10px 8px; vertical-align: top; }
.table th { color: var(--muted); font-weight: 900; text-align: left; }
/* Aktueller Monat: geschlossene Spalte */
.table th.current-month,
.table td.current-month {
  background: color-mix(in srgb, var(--link) 10%, transparent);
  font-weight: 900;
  box-shadow:
    inset 1px 0 0 color-mix(in srgb, var(--link) 35%, var(--border)),
    inset -1px 0 0 color-mix(in srgb, var(--link) 35%, var(--border));
}

/* obere Kante */
.table th.current-month {
  box-shadow:
    inset 1px 0 0 color-mix(in srgb, var(--link) 35%, var(--border)),
    inset -1px 0 0 color-mix(in srgb, var(--link) 35%, var(--border)),
    inset 0 1px 0 color-mix(in srgb, var(--link) 35%, var(--border));
}

/* untere Kante */
.table tbody tr:last-child td.current-month {
  box-shadow:
    inset 1px 0 0 color-mix(in srgb, var(--link) 35%, var(--border)),
    inset -1px 0 0 color-mix(in srgb, var(--link) 35%, var(--border)),
    inset 0 -1px 0 color-mix(in srgb, var(--link) 35%, var(--border));
}
.grid-settings .table-scroll, .contracts-wrap .table-scroll { overflow-x: hidden; }
.grid-settings .table, .contracts-wrap .table { min-width: 0 !important; width: 100%; table-layout: fixed; }
.grid-settings .table th, .grid-settings .table td, .contracts-wrap .table th, .contracts-wrap .table td { word-break: break-word; }
.total-row td { border-top: 2px solid var(--border); padding-top: 12px; }

.pills, .month-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { display: inline-block; padding: 6px 10px; border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--secondary-bg); color: var(--text); font-weight: 800; }
.pill:hover { filter: brightness(1.06); text-decoration: none; }
.pill-active { border-color: var(--button-border); background: var(--button-bg); }
.tag { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; max-width: 240px; overflow: hidden; text-overflow: ellipsis; padding: 6px 10px; border-radius: var(--radius-pill); border: 1px solid var(--border); background: var(--tag-bg); margin: 4px 6px 0 0; font-size: 0.9rem; vertical-align: middle; }
.tag-text { display: inline-block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-muted { opacity: 0.65; }
.tag form { display: inline-flex; margin: 0; }
.tag .btn-icon { width: 28px; height: 28px; }
.overline { display: inline-flex; align-items: center; gap: 10px; white-space: nowrap; }
.overline .overname { display: inline-block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.under-hidden { display: none; }
.settings-category-unders { padding-top: 2.1rem; }

.settings-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.settings-title, .settings-export-title { margin: 0; }
.settings-export { display: flex; align-items: baseline; gap: 12px; }
.settings-export-form { display: inline-flex !important; align-items: center; gap: 10px; flex-wrap: nowrap; }
.settings-export-select { width: auto !important; min-width: 120px; margin: 0 !important; }
.settings-export-btn { width: auto !important; margin-top: 0 !important; padding: 10px 12px; white-space: nowrap; flex: 0 0 auto; }
@media (max-width: 420px) { .settings-export-form { width: 100%; justify-content: space-between; } .settings-export-select { min-width: 0; flex: 1 1 auto; } }

.messages { margin: 10px 0; display: grid; gap: 8px; }
.msg { padding: 10px 12px; border-radius: var(--radius-control); border: 1px solid var(--border); background: var(--msg-bg); }
.msg.ok { border-color: rgba(34,197,94,0.35); background: rgba(34,197,94,0.12); }
.msg.error { border-color: rgba(239,68,68,0.35); background: rgba(239,68,68,0.12); }
.login-container { max-width: 420px; margin: 30px auto; }
.login-form { display: grid; gap: 8px; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { display: flex; justify-content: space-between; padding: 10px 8px; border-bottom: 1px solid var(--border); }

.bar-chart-wrap { width: 100%; overflow-x: auto; }
.bar-chart { width: 100%; min-width: 980px; height: 280px; display: block; border: 1px solid var(--border); border-radius: var(--radius); background: var(--chart-bg); }
.bar-grid { stroke: var(--border); stroke-width: 1; opacity: 0.9; }
.bar-zero { opacity: 1; stroke-width: 1.5; }
.bar-axis-label, .bar-month-label { fill: var(--muted); font-size: 12px; }
.bar { opacity: 0.95; cursor: default; }
.bar:hover { filter: brightness(1.08); opacity: 1; }
.bar-pos { fill: rgba(34,197,94,0.55); stroke: rgba(34,197,94,0.80); stroke-width: 1; }
.bar-neg { fill: rgba(239,68,68,0.50); stroke: rgba(239,68,68,0.80); stroke-width: 1; }

@media (max-width: 760px) {
  .topbar { position: static; flex-direction: column; align-items: stretch; gap: 10px; }
  .topbar-left, .topbar-center, .topbar-right { display: flex; justify-content: space-between; align-items: center; }
  .topbar-right { flex-wrap: wrap; }
  .nav { flex-wrap: nowrap; }
}
/* =========================
   Contracts: Tabellenbreite + Aktionen
   ========================= */

/* Die globale Regel oben setzt contracts-wrap auf overflow hidden.
   Für die Vertragsliste brauchen wir wieder horizontalen Scroll,
   damit Aktiv und Aktionen nicht ineinander gequetscht werden. */
.contracts-wrap .table-scroll {
  overflow-x: auto;
}

/* Nur die eigentliche Vertragsliste bekommt feste Mindestbreite.
   Die Übersicht oben bleibt kompakt. */
.contracts-table {
  min-width: 1080px !important;
  width: 100%;
  table-layout: auto !important;
}

/* Aktiv-Spalte etwas schmaler und linksbündig */
.contracts-table th:nth-child(7),
.contracts-table td:nth-child(7) {
  width: 70px;
  min-width: 70px;
  text-align: left;
  white-space: nowrap;
}

/* Aktionen-Spalte bekommt genug Platz */
.contract-actions-cell {
  width: 310px;
  min-width: 310px;
  white-space: nowrap;
}

/* Alles in einer Reihe: Datum, €, Bearbeiten, Löschen */
.contract-actions-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  flex-wrap: nowrap;
}

/* Buchungsformular darf nicht umbrechen */
.contract-book-form {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  margin: 0;
}

/* Datum kompakt, aber lesbar */
.contract-book-date {
  width: 145px !important;
  min-width: 145px;
  height: 34px;
  padding: 6px 8px;
}

/* €-Button rund und gleich groß wie Icon-Buttons */
.contract-book-form .btn-small {
  width: 34px;
  height: 34px;
  min-width: 34px;
  padding: 0;
  margin: 0;
  border-radius: 999px;
}

/* Delete-Form soll keinen Extra-Abstand erzeugen */
.contract-delete-form {
  display: inline-flex;
  margin: 0;
}

/* Icon-Buttons einheitlich */
.contract-actions-row .btn-icon {
  width: 34px;
  height: 34px;
  min-width: 34px;
  margin: 0;
}

/* Auf kleinen Bildschirmen darf die Tabelle scrollen,
   die Aktionsreihe bleibt trotzdem stabil. */
@media (max-width: 900px) {
  .contracts-table {
    min-width: 1080px !important;
  }

  .contract-actions-cell {
    width: 310px;
    min-width: 310px;
  }
}

.logout-form {
  display: inline;
  margin: 0;
}

.logout-form .logout {
  font: inherit;
  cursor: pointer;
}
