/* ═══════════════════════════════════════
   BASE — Reset, Body, Layout, Scrollbars
   ═══════════════════════════════════════ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: 'Segoe UI',-apple-system,BlinkMacSystemFont,'Inter',sans-serif; background: var(--c-bg); color: var(--c-text); display: flex; }
.fade-up { animation: fadeUp 0.25s ease; }

/* ═══ ACCESSIBILITY — Reduzierte Bewegung ═══
   Respektiert die System-Einstellung "Bewegung reduzieren" (macOS/iOS/Windows).
   Schaltet Animationen und Transitions praktisch ab, damit Nutzer mit
   Vestibulaeren Problemen oder Konzentrationsschwaechen die App benutzen koennen. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ═══ SIDEBAR ═══ */
.sidebar { width: var(--sidebar); background: var(--c-sidebar); height: 100vh; display: flex; flex-direction: column; flex-shrink: 0; overflow: hidden; }
.sb-logo { padding: 18px 16px 14px; border-bottom: 1px solid rgba(255,255,255,0.07); display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.sb-logo-img { width: 100%; max-width: 170px; height: auto; object-fit: contain; background: rgba(255,255,255,0.92); border-radius: 6px; padding: 6px 10px; }
.sb-logo-sub { color: rgba(255,255,255,0.55); font-size: 10px; letter-spacing: 0.8px; text-transform: uppercase; }
.sb-nav { flex: 1; overflow-y: auto; padding: 14px 10px; }
.sb-section-title { color: rgba(255,255,255,0.45); font-size: 9px; font-weight: 700; letter-spacing: 1.6px; text-transform: uppercase; padding: 0 12px 8px; margin-top: 4px; }
.nav-btn { width: 100%; display: flex; align-items: center; gap: 9px; padding: 9px 12px; border: none; background: transparent; color: rgba(255,255,255,0.8); font-size: 12.5px; font-weight: 500; border-radius: var(--r-sm); cursor: pointer; transition: all 0.15s; text-align: left; margin-bottom: 2px; border-left: 3px solid transparent; }
.nav-btn:hover { background: var(--c-sidebar-hover); color: var(--c-white); border-left-color: rgba(200,16,46,0.4); }
.nav-btn.active { background: rgba(200,16,46,0.12); color: var(--c-active); border-left-color: var(--c-active); }
.nav-badge { margin-left: auto; background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.65); font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 20px; }
.nav-btn.active .nav-badge { background: rgba(200,16,46,0.2); color: var(--c-active); }
.sb-footer { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,0.07); font-size: 10px; color: rgba(255,255,255,0.6); }

/* ═══ MAIN LAYOUT ═══ */
.main { flex: 1; height: 100vh; overflow: hidden; display: flex; flex-direction: column; position: relative; }
/* Die Kopfzeile ist mindestens 62 px hoch und WÄCHST, wenn Titel, Reiter und Knöpfe in einer Zeile nicht
   Platz haben. Mit fester Höhe (height: var(--topbar)) schnitt sie den Titel oben ab und schob die Knöpfe unter
   die rote Linie auf den Inhalt; die Lupe der Suche (44 px) machte das auf jeder Seite früher passieren
   (Prüfung 2026-10-16, Befunde D2 und D3). .main ist eine Flex-Spalte, der Inhalt (.content, min-height: 0)
   schrumpft mit. Passt alles in eine Zeile, bleibt es bei genau 62 px. */
.topbar { height: auto; background: var(--c-surface); border-bottom: 2px solid var(--c-active); padding: var(--s-2) 22px; display: flex; align-items: center; gap: 12px; flex-shrink: 0; flex-wrap: nowrap; min-height: var(--topbar); }
/* Innerer Behälter, den renderTopbar() befüllt. Er trägt das bisherige
   Verhalten der .topbar (inklusive flex-wrap: wrap und dem margin-left: auto
   der .topbar-actions), damit alle Zweige von renderTopbar() unverändert
   weiterlaufen. Die .topbar selbst darf dagegen nicht mehr umbrechen, sonst
   rutschen Glocke und Avatar in eine zweite Zeile, die von .main mit
   overflow: hidden abgeschnitten wird. */
.topbar-main { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
/* Die Titel stecken in klassenlosen <div>s. Ohne min-width:0 behalten die ihre
   Min-Content-Breite, das Auslassungszeichen an .topbar-title greift nie, und
   ein langer Kostenstellen-Titel schiebt sich unter Glocke und Avatar. */
.topbar-main > * { min-width: 0; }
.topbar-title { font-size: 17px; font-weight: 800; color: var(--c-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-sub { font-size: 12px; color: var(--c-muted); margin-top: 1px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.topbar-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.content { flex: 1; overflow: auto; padding: 22px; min-height: 0; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.content.no-pad { padding: 0; overflow: hidden; }

/* ═══ SCROLLBARS ═══ */
.sticky-scroll { overflow: auto; max-height: calc(100vh - var(--topbar) - 140px); scrollbar-width: thin; scrollbar-color: rgba(0,0,0,0.25) transparent; -webkit-overflow-scrolling: touch; }
.sticky-scroll::-webkit-scrollbar { height: 10px; width: 8px; background: transparent; }
.sticky-scroll::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.25); border-radius: 5px; }
.sticky-scroll::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.4); }
.sticky-scroll thead th { position: sticky; top: 0; z-index: 2; background: inherit; }
.sticky-scroll thead tr { background: var(--c-tint-1); }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-slate-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--c-slate-400); }

/* ═══════════════════════════════════════
   RESPONSIVE
   Breakpoints: 480 / 768 / 1024 / 1280
   Vgl. Design-System.md
   ═══════════════════════════════════════ */

/* ─── Hamburger-Toggle (wird per JS eingeblendet) ─── */
.sidebar-toggle { display: none; width: 40px; height: 40px; border: none; background: transparent; cursor: pointer; font-size: 20px; color: var(--c-text); flex-shrink: 0; border-radius: var(--r-sm); }
.sidebar-toggle:hover { background: var(--c-bg); }

/* ─── Tablet (<=1024px): kompaktere Abstände ─── */
@media (max-width: 1024px) {
  .content { padding: 16px; }
  .topbar { padding: var(--s-2) 16px; gap: 8px; }
}

/* ─── Tablet schmal / großes Smartphone (<=768px): Sidebar Collapse ─── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s var(--ease-standard, ease);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; align-items: center; justify-content: center; }
  .sidebar-overlay {
    display: none; position: fixed; inset: 0; z-index: 99;
    background: rgba(0,0,0,0.35);
  }
  .sidebar.open ~ .sidebar-overlay { display: block; }

  /* height schlägt min-height: ohne die height-Angabe bliebe die Leiste
     auf var(--topbar) = 62px stehen und die min-height wäre wirkungslos.
     height:auto statt eines festen Wertes: passt der Inhalt in eine Zeile, gilt
     die min-height von 52px. Bricht er um (Zahlungsübersicht: Titel, Sync-Pille,
     Excel- und Neue-Rechnung-Knopf), wächst die Leiste mit, statt den zweiten
     Knopf unsichtbar abzuschneiden. */
  .topbar { height: auto; min-height: var(--topbar-mobile); padding-top: 0; padding-bottom: 0; }   /* mobil unverändert: kein zusätzlicher Innenabstand oben und unten */
  .topbar-sub { display: none; }
  .content { padding: 12px; }

  /* Kopfzeile mit Reitern und Knöpfen (Kalkulation, Zahlungen, Veröffentlichung), nicht auf der Startseite:
     erste Zeile Menüknopf, Titel, Lupe, Glocke und Avatar; darunter die Reiter in einer Zeile zum seitlichen
     Wischen (statt untereinander zu stapeln); darunter die Knöpfe. #topbarMain gibt dafür seine Kinder an die
     Kopfzeile ab (display: contents), so laufen die Zeilen über die ganze Breite. Prüfung 2026-10-16, B3 und D9. */
  body:not(.home-mode) .topbar { flex-wrap: wrap; align-items: flex-start; align-content: flex-start; row-gap: 0; }
  body:not(.home-mode) .topbar-main { display: contents; }
  body:not(.home-mode) .topbar-main > .sidebar-toggle, body:not(.home-mode) .topbar-main > .btn { order: 1; }   /* Menüknopf zuerst, dann ein Zurück-Knopf (Bauleitung, Aufträge) */
  body:not(.home-mode) .topbar-main > .sidebar-toggle { margin: calc((var(--topbar-mobile) - 40px) / 2) 0; }
  body:not(.home-mode) .topbar-main > div:not(.view-tabs):not(.topbar-actions) { order: 2; flex: 1 1 0; min-width: 0; min-height: var(--topbar-mobile); display: flex; flex-direction: column; justify-content: center; }
  body:not(.home-mode) .topbar-main .topbar-title { white-space: normal; line-height: 1.2; }
  body:not(.home-mode) .topbar-user { order: 3; align-self: flex-start; min-height: var(--topbar-mobile); }
  body:not(.home-mode) .topbar-main > .view-tabs.u-ml-24 { order: 5; flex: 1 1 100%; margin-left: 0; display: flex; flex-wrap: nowrap; gap: var(--s-1); overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding-bottom: var(--s-1); }
  body:not(.home-mode) .topbar-main > .view-tabs.u-ml-24::-webkit-scrollbar { display: none; }
  body:not(.home-mode) .topbar-main > .view-tabs .vt-btn { flex: 0 0 auto; white-space: nowrap; min-height: 36px; }
  body:not(.home-mode) .topbar-main > .topbar-actions { order: 6; flex: 1 1 100%; justify-content: flex-end; padding-bottom: var(--s-2); }
  /* Umschalter (Personal, Bauleitung) liegen in den Aktionen: breiter als der Bildschirm, wischen statt links abzuschneiden */
  body:not(.home-mode) .topbar-actions > .view-toggle { max-width: 100%; overflow-x: auto; scrollbar-width: none; flex: 0 1 auto; }
  body:not(.home-mode) .topbar-actions > .view-toggle::-webkit-scrollbar { display: none; }
  body:not(.home-mode) .topbar-actions > .view-toggle button { flex: 0 0 auto; white-space: nowrap; padding: 8px 12px; }

  /* Grids auf weniger Spalten */
  .stats-row { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
  .team-grid { grid-template-columns: 1fr; }
  .kol-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr; }

  /* Tabellen: horizontales Scrollen im Container */
  .inv-table-wrap, .urlaub-table-wrap, .sticky-scroll { max-height: calc(100vh - 180px); }

  /* Bigger scrollbar area for touch on tablets */
  .sticky-scroll::-webkit-scrollbar, .inv-table-wrap::-webkit-scrollbar, .table-scroll::-webkit-scrollbar { height: 12px; width: 10px; }
}

/* ─── Smartphone (<=480px) ─── */
@media (max-width: 480px) {
  .topbar-title { font-size: 14px; }
  .topbar-actions { gap: 4px; }
  .btn { padding: 6px 10px; font-size: 11.5px; }
  .content { padding: 8px; }
  .stat-card { padding: 14px 16px; }
  .stat-value { font-size: 24px; }
  .modal { padding: 18px; width: 98vw; max-height: 94vh; }
  .modal-lg, .modal-xl, .modal-xxl { width: 98vw; }
  .tab-btn { padding: 10px 12px; font-size: 12px; }
}

/* ─── Responsive Sichtbarkeit ─── */
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
}
@media (min-width: 769px) {
  .hide-desktop { display: none !important; }
}
