/* ─── FIBU Programm - Hauptstyles ─────────────────────────────────────────── */

:root {
  --sidebar-width: 260px;
  --sidebar-collapsed: 64px;
  --topbar-height: 56px;

  /* Farb-Token (Light-Mode) */
  --primary: #0d6efd;
  --primary-soft: #f0f4ff;
  --surface-0: #f4f6f9;         /* body-bg */
  --surface-1: #ffffff;         /* cards, tables, topbar */
  --surface-2: #f8f9fa;         /* table-head, subtle */
  --surface-3: #f0f4ff;         /* hover, sum rows */
  --border: #dee2e6;
  --border-subtle: #e9ecef;
  --border-soft: #f1f3f5;
  --text-1: #212529;
  --text-muted: #6c757d;
  --text-dim: #9ca3af;
  --sidebar-bg: #1a1d23;
  --sidebar-fg: #adb5bd;
  --sidebar-hover: #2d3039;
  --sidebar-active: #0d6efd;
  --overlay: rgba(255,255,255,.7);
  --shadow-card: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-modal: 0 20px 60px rgba(0,0,0,.2);

  /* Status */
  --ok-bg: #d1fae5;   --ok-fg: #065f46;
  --warn-bg: #fef3c7; --warn-fg: #92400e;
  --err-bg: #fee2e2;  --err-fg: #991b1b;
  --pos: #16a34a;
  --neg: #dc2626;

  /* Kompatibilität mit alten Regeln */
  --border-color: var(--border);
  --card-shadow: var(--shadow-card);
}

/* ─── Dark-Mode Overrides ──────────────────────────────────────────────── */
[data-bs-theme="dark"] {
  --primary: #3b82f6;
  --primary-soft: #1e293b;
  --surface-0: #0f1115;
  --surface-1: #1a1d23;
  --surface-2: #242830;
  --surface-3: #2d3340;
  --border: #2d333b;
  --border-subtle: #242830;
  --border-soft: #1f2329;
  --text-1: #e6e8eb;
  --text-muted: #9aa4af;
  --text-dim: #6b7280;
  --sidebar-bg: #0b0d11;
  --sidebar-fg: #9aa4af;
  --sidebar-hover: #1f2329;
  --sidebar-active: #3b82f6;
  --overlay: rgba(15,17,21,.75);
  --shadow-card: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-modal: 0 20px 60px rgba(0,0,0,.6);

  --ok-bg: #064e3b;   --ok-fg: #6ee7b7;
  --warn-bg: #78350f; --warn-fg: #fcd34d;
  --err-bg: #7f1d1d;  --err-fg: #fca5a5;
  --pos: #4ade80;
  --neg: #f87171;
}

* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  background: var(--surface-0);
  color: var(--text-1);
  margin: 0;
  overflow-x: hidden;
}

/* ─── Theme-Toggle ─────────────────────────────────────────────────────── */

.theme-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 36px; height: 36px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.theme-toggle:hover {
  background: var(--surface-2);
  color: var(--text-1);
  border-color: var(--primary);
}
.theme-toggle .bi-sun-fill { display: none; }
.theme-toggle .bi-moon-stars-fill { display: inline-block; }
[data-bs-theme="dark"] .theme-toggle .bi-sun-fill { display: inline-block; }
[data-bs-theme="dark"] .theme-toggle .bi-moon-stars-fill { display: none; }

/* ─── Login ──────────────────────────────────────────────────────────────── */

.login-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #1a1d23 0%, #0d6efd 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
[data-bs-theme="dark"] .login-overlay {
  background: linear-gradient(135deg, #0b0d11 0%, #1e3a8a 100%);
}

.login-box {
  background: var(--surface-1);
  color: var(--text-1);
  border-radius: 16px;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  transition: width .2s ease;
  z-index: 1000;
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed);
}

.sidebar-header {
  padding: 1rem 1.25rem;
  background: rgba(255,255,255,.05);
  border-bottom: 1px solid rgba(255,255,255,.08);
  font-weight: 700;
  color: #fff;
  font-size: 1.05rem;
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: .5rem 0;
}

.sidebar .nav-link {
  color: var(--sidebar-fg);
  padding: .6rem 1.25rem;
  display: flex;
  align-items: center;
  gap: .75rem;
  border: none;
  border-radius: 0;
  font-size: .9rem;
  white-space: nowrap;
  transition: background .15s, color .15s;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar .nav-link.active {
  background: var(--sidebar-active);
  color: #fff;
  border-left: 3px solid #fff;
  padding-left: calc(1.25rem - 3px);
}

.sidebar .nav-link i {
  width: 20px;
  text-align: center;
  font-size: 1rem;
}

.sidebar-section {
  padding: .75rem 1.25rem .25rem;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--text-muted);
  font-weight: 700;
}

/* Collapsible Sidebar-Gruppen */
.nav-category {
  padding: .75rem 1rem .25rem;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(255,255,255,.4);
  font-weight: 700;
  list-style: none;
}
.nav-category.nav-toggle {
  cursor: pointer;
  display: flex;
  align-items: center;
  user-select: none;
  transition: color .15s;
}
.nav-category.nav-toggle:hover { color: #fff; }
.nav-category.nav-toggle .caret { transition: transform .15s; font-size: .65rem; }
.nav-category.nav-toggle.open .caret { transform: rotate(180deg); }
.nav-group { overflow: hidden; transition: max-height .2s ease; max-height: 1000px; }
.nav-group.collapsed { max-height: 0; }

.sidebar-cta { font-weight: 600; font-size: .9rem; padding: .55rem; }

.glossar-icon {
  color: var(--text-muted);
  cursor: help;
  font-size: .85em;
  margin-left: .2em;
  transition: color .15s;
}
.glossar-icon:hover { color: var(--primary); }

.onboarding-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1040;
  width: 320px;
  max-width: calc(100vw - 40px);
}
.onboarding-panel a { color: var(--text-1); }
.onboarding-panel a:hover { color: var(--primary); }
.sidebar.collapsed .sidebar-cta span { display: none; }

.sidebar.collapsed .sidebar-section,
.sidebar.collapsed .nav-link span,
.sidebar.collapsed .sidebar-header span {
  display: none;
}

.sidebar.collapsed .nav-link {
  justify-content: center;
  padding: .6rem 0;
}

.sidebar-footer {
  padding: .75rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: .8rem;
  color: var(--sidebar-fg);
}

/* ─── Main Content ───────────────────────────────────────────────────────── */

.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  transition: margin-left .2s ease;
  display: flex;
  flex-direction: column;
}

.main-content.sidebar-collapsed {
  margin-left: var(--sidebar-collapsed);
}

.topbar {
  height: var(--topbar-height);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  color: var(--text-1);
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

#pageContent {
  flex: 1;
}

/* Mobile-Menü-Button: ausreichend großes Touch-Target (Apple HIG / Material: ≥44px) */
.mobile-menu-btn {
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.mobile-menu-btn i {
  font-size: 1.5rem;
  line-height: 1;
}

/* ─── Cards ──────────────────────────────────────────────────────────────── */

.card {
  background: var(--surface-1);
  color: var(--text-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
}

.card-header {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
  border-radius: 12px 12px 0 0 !important;
  font-weight: 600;
}

/* ─── KPI Cards ──────────────────────────────────────────────────────────── */

.kpi-card {
  background: var(--surface-1);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
  transition: transform .15s;
}

.kpi-card:hover {
  transform: translateY(-2px);
}

.kpi-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.kpi-value {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
}

.kpi-label {
  font-size: .8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 600;
}

/* ─── Tabellen ───────────────────────────────────────────────────────────── */

.table-container {
  background: var(--surface-1);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
  overflow: hidden;
}

.table {
  margin-bottom: 0;
  font-size: .875rem;
  color: var(--text-1);
}

.table thead th {
  background: var(--surface-2);
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  padding: .75rem 1rem;
  white-space: nowrap;
}

.table tbody td {
  padding: .65rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-soft);
}

.table tbody tr:hover {
  background: var(--surface-3);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

/* ─── Toolbar ────────────────────────────────────────────────────────────── */

.page-toolbar {
  background: var(--surface-1);
  border-radius: 12px;
  padding: .75rem 1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}

/* ─── Forms ──────────────────────────────────────────────────────────────── */

.form-label {
  font-weight: 600;
  font-size: .85rem;
  color: var(--text-1);
  margin-bottom: .35rem;
}

.form-control, .form-select {
  background: var(--surface-1);
  color: var(--text-1);
  border-radius: 8px;
  border-color: var(--border);
  font-size: .875rem;
}

.form-control::placeholder { color: var(--text-dim); }

.form-control:focus, .form-select:focus {
  background: var(--surface-1);
  color: var(--text-1);
  border-color: var(--primary);
  box-shadow: 0 0 0 .15rem rgba(13,110,253,.15);
}

[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
  background: var(--surface-2);
}

.form-text { color: var(--text-muted); }

/* ─── Badges & Status ────────────────────────────────────────────────────── */

.badge-status {
  font-size: .75rem;
  padding: .25rem .6rem;
  border-radius: 6px;
  font-weight: 600;
}

.status-gebucht,
.status-bezahlt     { background: var(--ok-bg);   color: var(--ok-fg); }
.status-entwurf,
.status-offen       { background: var(--warn-bg); color: var(--warn-fg); }
.status-storniert,
.status-überfällig  { background: var(--err-bg);  color: var(--err-fg); }

/* ─── Beträge ────────────────────────────────────────────────────────────── */

.betrag-positiv { color: var(--pos); font-weight: 600; }
.betrag-negativ { color: var(--neg); font-weight: 600; }
.betrag-neutral { color: var(--text-1); }
.text-right { text-align: right; }
.font-mono { font-family: 'Cascadia Code', 'Courier New', monospace; }

/* ─── Buchungszeilen-Editor ──────────────────────────────────────────────── */

.buchungszeile-row {
  background: var(--surface-2);
  border-radius: 8px;
  padding: .5rem;
  margin-bottom: .4rem;
  border: 1px solid var(--border-subtle);
}

.buchungszeile-row:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

/* ─── Upload Area ────────────────────────────────────────────────────────── */

.upload-area {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  color: var(--text-muted);
}

.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--primary);
  background: var(--primary-soft);
}

/* ─── Chart Container ────────────────────────────────────────────────────── */

.chart-container {
  position: relative;
  height: 280px;
}

/* ─── Modals ─────────────────────────────────────────────────────────────── */

.modal-header {
  background: var(--primary);
  color: #fff;
  border-radius: 12px 12px 0 0;
}

.modal-header .btn-close {
  filter: invert(1);
}

.modal-content {
  background: var(--surface-1);
  color: var(--text-1);
  border-radius: 12px;
  border: none;
  box-shadow: var(--shadow-modal);
}

/* ─── Toast ──────────────────────────────────────────────────────────────── */

.toast {
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}

/* ─── Loading Spinner ────────────────────────────────────────────────────── */

.loading-overlay {
  position: absolute; inset: 0;
  background: var(--overlay);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
  border-radius: 12px;
}

/* ─── Empty State ────────────────────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-dim);
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: 1rem;
  display: block;
}

/* ─── Highlights (Summenzeilen) ──────────────────────────────────────────── */

.table-sum-row {
  background: var(--primary-soft) !important;
  font-weight: 700;
  border-top: 2px solid var(--primary) !important;
}

/* ─── Bootstrap Dropdown/Nav im Dark Mode ────────────────────────────────── */

[data-bs-theme="dark"] .dropdown-menu {
  background: var(--surface-2);
  border-color: var(--border);
}
[data-bs-theme="dark"] .dropdown-item { color: var(--text-1); }
[data-bs-theme="dark"] .dropdown-item:hover,
[data-bs-theme="dark"] .dropdown-item:focus {
  background: var(--surface-3);
  color: var(--text-1);
}
[data-bs-theme="dark"] .dropdown-divider { border-color: var(--border); }

[data-bs-theme="dark"] .alert-info {
  background: #1e293b; color: #93c5fd; border-color: #1e40af;
}
[data-bs-theme="dark"] .alert-success {
  background: var(--ok-bg); color: var(--ok-fg); border-color: transparent;
}
[data-bs-theme="dark"] .alert-warning {
  background: var(--warn-bg); color: var(--warn-fg); border-color: transparent;
}
[data-bs-theme="dark"] .alert-danger {
  background: var(--err-bg); color: var(--err-fg); border-color: transparent;
}

[data-bs-theme="dark"] .bg-light,
[data-bs-theme="dark"] .bg-white { background: var(--surface-1) !important; color: var(--text-1); }
[data-bs-theme="dark"] .text-muted { color: var(--text-muted) !important; }

[data-bs-theme="dark"] .btn-outline-secondary {
  color: var(--text-1);
  border-color: var(--border);
}
[data-bs-theme="dark"] .btn-outline-secondary:hover {
  background: var(--surface-3);
  color: var(--text-1);
}

[data-bs-theme="dark"] .nav-tabs { border-color: var(--border); }
[data-bs-theme="dark"] .nav-tabs .nav-link {
  color: var(--text-muted);
  border-color: transparent;
}
[data-bs-theme="dark"] .nav-tabs .nav-link.active {
  background: var(--surface-1);
  color: var(--text-1);
  border-color: var(--border) var(--border) var(--surface-1);
}

[data-bs-theme="dark"] .list-group-item {
  background: var(--surface-1);
  color: var(--text-1);
  border-color: var(--border);
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
}

/* ─── Print ──────────────────────────────────────────────────────────────── */

@media print {
  .sidebar, .topbar, .page-toolbar, .btn { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .card { box-shadow: none !important; }
}
