/* ============================================================
   E-Rechnung — Design-System
   Leitidee: das ordentliche Rechnungsbuch eines Handwerksbetriebs,
   digitalisiert. Tinte, Papier, ein Stempel für den Status.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,600;9..144,700&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
  --ink: #1B2A4A;
  --ink-light: #2D4372;
  --paper: #F6F4EE;
  --surface: #FFFFFF;
  --text: #23262B;
  --muted: #6B7280;
  --border: #DDD7C7;
  --accent: #B9812E;
  --accent-ink: #6E4B12;
  --success: #3F7159;
  --success-bg: #E7F0EA;
  --danger: #B3452C;
  --danger-bg: #F7E9E4;
  --info-bg: #EAEFF8;
  /* Überschriften-/Emphase-Textfarbe - im Hellmodus identisch zu --ink
     (das gleichzeitig als Hintergrundfarbe für Sidebar/Primär-Buttons
     dient und dafür NICHT umgefärbt werden soll). Im Dunkelmodus muss nur
     dieses Token hell werden, --ink selbst bleibt als Hintergrundfarbe
     unverändert dunkel. */
  --heading: var(--ink);
  --stamp-draft-bg: #F1EFE8;
  --stamp-accent-bg: #FBF1DE;

  --font-display: 'Fraunces', serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', monospace;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(27, 42, 74, 0.06), 0 8px 24px -12px rgba(27, 42, 74, 0.18);
}

/* ============================================================
   Dunkelmodus
   Gleiche "Tinte auf Papier"-Leitidee wie oben, nur umgekehrt: warmes
   Dunkelgrau statt cremefarbenem Papier, helle Warmtöne statt Tinte für
   Überschriften/Fließtext. --ink/--ink-light bleiben UNVERÄNDERT (dienen
   als Hintergrundfarbe für Sidebar/Primär-Buttons, die als dunkler Block
   in beiden Modi funktionieren) - nur die Tokens, die tatsächlich
   Lesbarkeit auf hellem vs. dunklem Untergrund betreffen, werden ersetzt.

   Zwei Wege, in den Dunkelmodus zu kommen:
   1. System-Einstellung (prefers-color-scheme), sofern der Nutzer noch
      KEINE explizite Wahl getroffen hat (siehe :not([data-theme="light"])
      unten - verhindert, dass diese Regel eine explizite Hell-Wahl
      überstimmt).
   2. Manuelle Wahl über den Umschalter (setzt data-theme="dark"/"light"
      auf <html>, siehe app.js: applyTheme/toggleTheme), persistiert in
      localStorage.
   ============================================================ */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #14161C;
    --surface: #1D212B;
    --text: #DDDBD0;
    --muted: #93927F;
    --border: #333748;
    --heading: #F2F0E4;
    --accent: #D9A857;
    --accent-ink: #F2C978;
    --success-bg: #1E3229;
    --danger-bg: #3A241D;
    --info-bg: #1D2436;
    --stamp-draft-bg: #262A34;
    --stamp-accent-bg: #3A311C;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.55);
  }
}
:root[data-theme="dark"] {
  --paper: #14161C;
  --surface: #1D212B;
  --text: #DDDBD0;
  --muted: #93927F;
  --border: #333748;
  --heading: #F2F0E4;
  --accent: #D9A857;
  --accent-ink: #F2C978;
  --success-bg: #1E3229;
  --danger-bg: #3A241D;
  --info-bg: #1D2436;
  --stamp-draft-bg: #262A34;
  --stamp-accent-bg: #3A311C;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
}

a { color: inherit; }

button {
  font-family: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.hidden { display: none !important; }

/* ---------- Landing / Marketing ---------- */

.landing-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.landing-header-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.landing-header .brand-mark { margin-bottom: 0; }
.landing-nav {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}
.landing-nav a:not(.btn) {
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
}
.landing-nav a:not(.btn):hover { color: var(--heading); }
.landing-nav .btn { text-decoration: none; }

.landing-hero {
  max-width: 720px;
  margin: 0 auto;
  padding: 72px 24px 56px;
  text-align: center;
}
.landing-hero h1 {
  font-family: var(--font-display);
  font-size: 42px;
  line-height: 1.15;
  font-weight: 600;
  color: var(--heading);
  margin: 0 0 20px;
}
.landing-lead {
  font-size: 17px;
  color: var(--muted);
  margin: 0 0 32px;
  line-height: 1.6;
}
.landing-cta-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.landing-cta-row .btn { text-decoration: none; width: auto; }
.landing-trust {
  margin: 18px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.btn-lg { padding: 14px 28px; font-size: 16px; }

.landing-features {
  max-width: 1080px;
  margin: 0 auto;
  padding: 8px 24px 64px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.landing-feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 20px;
}
.landing-feature-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--success-bg);
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 12px;
}
.landing-feature-card h2 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--heading);
  margin: 0 0 6px;
}
.landing-feature-card p {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}

.landing-steps {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 56px 24px;
}
.landing-section-title {
  text-align: center;
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  color: var(--heading);
  margin: 0 0 36px;
}
.landing-steps-row {
  max-width: 960px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}
.landing-step { text-align: center; }
.landing-step-num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 600;
  margin: 0 auto 14px;
}
.landing-step h3 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--heading);
  margin: 0 0 6px;
}
.landing-step p {
  font-size: 13px;
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}

.landing-pricing {
  max-width: 1080px;
  margin: 0 auto;
  padding: 56px 24px;
}
.landing-pricing-sub {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  margin: -20px 0 8px;
}
.landing-plan-grid .plan-card { text-align: left; }

.landing-bottom-cta {
  background: var(--ink);
  color: #fff;
  text-align: center;
  padding: 56px 24px;
}
.landing-bottom-cta h2 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  margin: 0 0 24px;
}
.landing-bottom-cta .btn { text-decoration: none; width: auto; }

.landing-footer {
  text-align: center;
  padding: 32px 24px 40px;
  font-size: 13px;
  color: var(--muted);
}
.landing-footer p { margin: 4px 0; }
.landing-footer a { color: var(--muted); text-decoration: underline; }
.landing-footer a:hover { color: var(--heading); }

/* ---------- Plan-Karten (Abo-Seite in der App + Landingpage) ---------- */

.plan-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 16px;
}
.plan-card { display: flex; flex-direction: column; text-align: left; }
.plan-card-current { border-color: var(--heading); box-shadow: 0 0 0 1px var(--ink), var(--shadow); }
.plan-card h2 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--heading);
  margin: 0 0 6px;
}
.plan-price {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 16px;
}
.plan-price span { font-size: 13px; font-weight: 500; color: var(--muted); }
.plan-features {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  flex: 1;
  font-size: 13px;
  color: var(--muted);
}
.plan-features li { padding: 5px 0 5px 20px; position: relative; }
.plan-features li::before { content: "✓"; position: absolute; left: 0; color: var(--success); font-weight: 700; }
.plan-card .btn { width: 100%; }

/* ---------- Auth Screen ---------- */

#auth-screen,
#verify-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px 36px;
  transition: max-width 0.15s ease;
}
/* Registrieren-Modus: die Unternehmensdaten (#auth-company-fields, zwei
   Spalten wie .form-grid) brauchen deutlich mehr Platz als die schmale
   Login-Karte - siehe app.js: applyAuthMode() setzt/entfernt diese Klasse. */
.auth-card--wide { max-width: 720px; }

.auth-section-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--heading);
  margin: 22px 0 12px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.brand-stamp {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  color: var(--heading);
  flex-shrink: 0;
}

/* Logo-Bild (favicon.svg) statt CSS-Kreis mit Buchstabe: eigene, bereits
   im SVG enthaltene Form/Farbe - Kreis-Rahmen & Schrift-Styling von
   .brand-stamp werden hier bewusst zurückgesetzt. */
.brand-stamp-logo {
  border-radius: 22%;
  border: none;
  display: block;
}
/* Das Logo hat selbst einen dunkelblauen Hintergrund (var(--ink)) - auf
   der ebenfalls dunkelblauen Sidebar/Topbar würde die Kachel sonst mit
   dem Hintergrund verschmelzen, deshalb hier ein dezenter heller Ring. */
.sidebar .brand-stamp-logo,
.mobile-topbar-logo {
  box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.3);
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  color: var(--heading);
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: -2px;
}

.auth-card h1 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--heading);
}

.auth-card p.lead {
  color: var(--muted);
  font-size: 14px;
  margin: 0 0 24px;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--ink-light);
}

/* Native <select>-Pfeile sehen je nach Browser/OS unterschiedlich aus und
   wirken neben den sonst durchgestalteten Formularfeldern (Radius, Border,
   Schrift) fremd - hier durch ein eigenes, zur Marke passendes Chevron-Icon
   ersetzt. Gilt für ALLE Selects der App (Formularfelder wie auch
   eigenständige, z.B. den Zeitraum-Filter im Admin-Bereich), damit
   Dropdowns überall einheitlich aussehen. */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%232D4372' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
  padding-right: 34px !important;
  cursor: pointer;
}
select::-ms-expand { display: none; }
select:disabled { cursor: not-allowed; opacity: 0.65; }

/* Eigenständige Selects außerhalb von .field (z.B. Zeitraum-Filter im
   Admin-Bereich) bekommen dieselbe Feld-Optik wie Formular-Selects. */
.metrics-range-select {
  padding: 8px 34px 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 13px;
  background-color: var(--surface);
  color: var(--text);
}
.metrics-range-select:focus { border-color: var(--ink-light); }

.field-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.req-mark {
  color: var(--danger);
  margin-left: 2px;
}

.password-requirements {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  font-size: 12px;
  color: var(--muted);
}
.password-requirements li { padding: 2px 0 2px 20px; position: relative; }
.password-requirements li::before {
  content: "○";
  position: absolute; left: 0;
}
.password-requirements li.met { color: var(--success); }
.password-requirements li.met::before { content: "●"; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.05s ease, opacity 0.15s ease;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--ink);
  color: #fff;
  width: 100%;
}
.btn-primary:hover { background: var(--ink-light); }

.btn-secondary {
  background: transparent;
  color: var(--heading);
  border: 1px solid var(--border);
  width: 100%;
  margin-top: 8px;
}
.btn-secondary:hover { border-color: var(--heading); }

.btn-accent {
  background: var(--accent);
  color: #fff;
}
.btn-accent:hover { opacity: 0.9; }

/* Sekundäre Aktionen ("Bearbeiten", "Löschen", "Abbrechen", "Alle
   ansehen", "+ Position hinzufügen"): früher komplett ohne Rahmen und
   Hintergrund - dadurch waren sie in den Tabellenzeilen von normalem
   Text nicht zu unterscheiden und wurden schlicht nicht als anklickbar
   erkannt. Ein dezenter Rahmen gibt ihnen eine erkennbare Schaltflächen-
   Form, ohne der Hauptaktion (btn-accent) die Aufmerksamkeit zu nehmen. */
.btn-ghost {
  background: var(--surface);
  color: var(--heading);
  border: 1px solid var(--border);
  padding: 8px 14px;
}
.btn-ghost:hover { background: var(--info-bg); border-color: var(--muted); }

.btn-danger-ghost {
  background: var(--surface);
  color: var(--danger);
  border: 1px solid var(--border);
  padding: 7px 12px;
  font-size: 13px;
}
.btn-danger-ghost:hover { background: var(--danger-bg); border-color: var(--danger); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { opacity: 0.9; }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.auth-toggle {
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-top: 18px;
}
.auth-toggle button {
  background: none;
  border: none;
  color: var(--heading);
  font-weight: 600;
  text-decoration: underline;
  padding: 0;
}

.turnstile-field {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

.error-banner {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

.info-banner {
  background: var(--info-bg);
  color: var(--heading);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ---------- App Shell ---------- */

#app-shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--ink);
  color: #fff;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  /* Ohne "sticky" ist die Sidebar nur ein normales Grid-Item: wird der
     Hauptinhalt (z.B. das lange Firmenprofil-Formular) höher als der
     Viewport, wächst #app-shell insgesamt mit - die Sidebar wächst als
     Grid-Item gleich mit und scrollt komplett aus dem Bild, sodass
     Nutzer:in-Kennung/"Abmelden" im sidebar-footer erst nach Runterscrollen
     sichtbar sind. "position: sticky" + "height: 100vh" hält die Sidebar
     dagegen dauerhaft am Viewport-Rand fixiert, unabhängig davon, wie lang
     der Inhalt daneben ist. */
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand-mark {
  padding: 0 8px;
  margin-bottom: 32px;
  /* Ist jetzt ein <button> (führt zur Übersicht), nicht mehr nur ein <div> -
     Button-Grundstile zurücksetzen, damit es weiterhin wie reine Markenoptik
     aussieht statt wie ein Formular-Button. */
  background: none;
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font: inherit;
}
.sidebar .brand-mark:hover .brand-name { color: var(--accent); }
.sidebar .brand-name { color: #fff; }
.sidebar .brand-sub { color: rgba(255,255,255,0.55); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,0.75);
  font-size: 14px;
  font-weight: 500;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  margin-bottom: 2px;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.14); color: #fff; }
.nav-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: 0; }
.nav-item.active .dot { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.12);
}
.sidebar-user {
  font-size: 12px;
  color: rgba(255,255,255,0.55);
  padding: 0 12px 10px;
  word-break: break-all;
}

/* Der Inhaltsbereich füllt die volle Fensterbreite neben der Sidebar.
   Früher stand hier ein harter Deckel von 1080px - auf einem üblichen
   1920px-Bildschirm blieben dadurch rund 500px rechts dauerhaft
   ungenutzt, während Rechnungs- und Kundentabellen daneben umbrachen.
   Damit der gewonnene Platz nicht zu überlangen Zeilen führt, wachsen
   die Formularraster jetzt in der Spaltenzahl mit (siehe .form-grid) -
   statt dieselben zwei Spalten immer breiter zu ziehen.
   min-width:0 ist im Grid-Kontext nötig, damit breite Tabellen den
   Bereich nicht über die Fensterbreite hinaus aufdehnen, sondern in
   ihrem eigenen Scroll-Container bleiben (siehe .card:has(.data-table)). */
.main {
  padding: 32px 40px 60px;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  color: var(--heading);
  margin: 0 0 4px;
}
.page-header p { color: var(--muted); font-size: 14px; margin: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 24px;
}

.card h2 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--heading);
  margin: 0 0 18px;
}

/* ---------- Dashboard ---------- */

.dashboard-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--info-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--text);
}
.dashboard-alert.warn { background: var(--danger-bg); }
.dashboard-alert p { margin: 0; }

.metric-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.metric-card .metric-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 6px;
}
.metric-card .metric-value {
  font-family: var(--font-mono, monospace);
  font-size: 24px;
  font-weight: 700;
  color: var(--heading);
}
.metric-card .metric-value.metric-warn { color: var(--danger); }
.metric-card .metric-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

@media (max-width: 900px) {
  .metric-cards { grid-template-columns: 1fr 1fr; }
}

/* Spaltenzahl wächst mit der verfügbaren Breite mit (2 Spalten bei ~600px,
   4 bei ~1200px, 5-6 auf sehr breiten Bildschirmen), statt zwei feste
   Spalten immer weiter auseinanderzuziehen. 260px ist die Untergrenze,
   ab der ein Eingabefeld mit Label noch bequem lesbar bleibt. */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px 16px;
}
.form-grid .field.full { grid-column: 1 / -1; }

.checkbox-field {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  grid-column: 1 / -1;
  background: var(--info-bg);
  padding: 12px 14px;
  border-radius: 8px;
}
.checkbox-field input { width: auto; margin-top: 3px; }
.checkbox-field .label-text { font-size: 13px; }
.checkbox-field .label-text strong { display: block; font-size: 14px; color: var(--heading); margin-bottom: 2px; }

/* ---------- Tables / Lists ---------- */

.card:has(.data-table) {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
  padding: 0 10px 10px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 14px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table .num, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
/* NICHT display:flex direkt auf die <td class="actions">: ein Flex-
   Container ist kein table-cell mehr und nimmt dadurch nicht mehr an der
   normalen Höhenangleichung der Tabellenzeile teil - die Zelle blieb dann
   kürzer als ihre Geschwisterzellen, wodurch die Trennlinien zwischen den
   Zeilen sichtbar versetzt waren. Der Flex-Layout sitzt stattdessen auf
   einem inneren Wrapper (.actions-inner), die <td> selbst bleibt ein
   normales, höhenangeglichenes table-cell. */
.data-table .actions-inner { display: flex; gap: 6px; justify-content: flex-end; align-items: center; flex-wrap: wrap; position: relative; }
.data-table .row-title { font-weight: 600; color: var(--heading); }
.data-table .row-sub { font-size: 12px; color: var(--muted); }

/* Zeilen-Aktionen (Rechnungsliste): statt bis zu 6 nebeneinander
   gestapelten Text-Buttons pro Zeile (unübersichtlich, besonders in der
   mobilen Kartenansicht) nur noch die wichtigste nächste Aktion + PDF
   direkt sichtbar, alles Weitere (XML, Mahnung, Löschen) hinter einem
   "Weitere Aktionen"-Menü (siehe renderInvoices/toggleRowMenu in app.js). */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--heading);
  cursor: pointer;
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--info-bg); }
.btn-icon svg { width: 17px; height: 17px; }
.btn-with-icon { display: inline-flex; align-items: center; gap: 6px; }
.btn-with-icon svg { width: 15px; height: 15px; flex-shrink: 0; }

.row-menu { display: inline-flex; }
/* position:fixed statt absolute + JS-berechnete top/left (siehe
   toggleRowMenu in app.js): die Rechnungstabelle steckt in einer Karte mit
   overflow-x:auto (siehe .card:has(.data-table) oben) - sobald EINE Achse
   eines Elements nicht "visible" ist, rechnet der Browser laut CSS-Spec
   automatisch auch die andere Achse als "auto" statt "visible", auch wenn
   nur overflow-x gesetzt wurde. Ein absolut positioniertes Menü innerhalb
   dieser Karte wurde dadurch am unteren Kartenrand abgeschnitten
   (unsichtbarer zweiter Menüpunkt). position:fixed entzieht sich jeder
   Vorfahren-Overflow-Begrenzung, da es relativ zum Viewport positioniert
   wird.
*/
.row-menu-list {
  position: fixed;
  /* Breiter als früher (220px): die Einträge benennen jetzt zusätzlich das
     Ergebnis der Aktion ("Stornieren - erzeugt eine Gutschrift") und
     tragen ein Symbol, damit man sie im Menü auch ohne Lesen wiederfindet. */
  width: 290px;
  max-width: calc(100vw - 16px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 200;
}
.row-menu-list.hidden { display: none; }
.row-menu-list button {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border: none;
  background: none;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.35;
  color: var(--heading);
  cursor: pointer;
  font-family: inherit;
}
.row-menu-list button svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  color: var(--muted);
}
.row-menu-list button:hover { background: var(--info-bg); }
.row-menu-list button:hover svg { color: inherit; }
.row-menu-list button.danger { color: var(--danger); }
.row-menu-list button.danger svg { color: var(--danger); }
.row-menu-list button.danger:hover { background: var(--danger-bg); }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-state .glyph {
  font-family: var(--font-display);
  font-size: 32px;
  color: var(--heading);
  margin-bottom: 8px;
}
.empty-state p { margin: 4px 0; font-size: 14px; }

/* ---------- Status Stamp (Signature-Element) ---------- */

.stamp {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1.5px dashed currentColor;
  transform: rotate(-1.5deg);
}
.stamp.draft { color: var(--muted); background: var(--stamp-draft-bg); }
.stamp.sent { color: var(--accent-ink); background: var(--stamp-accent-bg); }
.stamp.paid { color: var(--success); background: var(--success-bg); }
.stamp.cancelled { color: var(--danger); background: var(--danger-bg); }
.stamp.credit-note { color: var(--accent-ink); background: var(--stamp-accent-bg); font-size: 10px; padding: 2px 8px; transform: none; }

/* ---------- Invoice line items ---------- */

.line-items { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
/* --line-item-cols wird per JS gesetzt (renderLineItems in app.js), damit
   die Tabelle je nach Anzahl der vom Nutzer hinzugefügten Zusatzspalten
   (extraColumns) unterschiedlich viele Spalten hat. Der Fallback-Wert
   greift nur, solange JS die Variable noch nicht gesetzt hat. Bewusst über
   eine Custom Property statt direkt per Inline-Style auf
   grid-template-columns, da Inline-Styles die @media-Regel für Mobile
   unten (grid-template-columns: 1fr) sonst überschreiben würden. */
.line-item-row {
  display: grid;
  grid-template-columns: var(--line-item-cols, minmax(260px, 760px) 90px 130px 90px 34px);
  gap: 8px;
  align-items: center;
}
.line-item-row input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; font-family: var(--font-body); }
.line-item-row input:disabled { background: var(--info-bg); color: var(--muted); cursor: not-allowed; }
.li-field { min-width: 0; }
/* Nur auf Mobile sichtbar (siehe @media unten) - am Desktop übernimmt
   bereits .line-items-head die Spaltenbeschriftung, ein zweites Label pro
   Feld wäre dort redundant. */
.li-mobile-label { display: none; }
/* Einzelpreis: die Auf/Ab-Pfeile des nativen number-Inputs suggerieren ein
   Hoch-/Runterzählen in Cent-Schritten, das bei einem Preis kaum sinnvoll
   per Klick bedienbar ist - deshalb bewusst ausgeblendet (Tippen bleibt
   möglich, nur die Klick-Spinner verschwinden). */
.li-price::-webkit-outer-spin-button,
.li-price::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.li-price { -moz-appearance: textfield; }
.line-item-row .remove-btn {
  background: none; border: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 6px;
}
.line-item-row .remove-btn:hover { color: var(--danger); }
.line-items-head {
  display: grid;
  grid-template-columns: var(--line-item-cols, minmax(260px, 760px) 90px 130px 90px 34px);
  gap: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 0 2px;
  align-items: center;
}
.line-items-head .col-remove-btn {
  background: none; border: none; color: var(--muted); font-size: 13px; line-height: 1;
  cursor: pointer; margin-left: 4px;
}
.line-items-head .col-remove-btn:hover { color: var(--danger); }

.totals-box {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.totals-row { display: flex; gap: 24px; font-size: 14px; min-width: 220px; justify-content: space-between; }
.totals-row.grand { font-weight: 700; font-size: 17px; color: var(--heading); font-family: var(--font-mono); }
.totals-row span:first-child { color: var(--muted); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- In-App-Bestätigungsdialog (statt window.confirm) ---------- */

.confirm-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 500;
}
.confirm-dialog-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  max-width: 380px;
  width: 100%;
}
.confirm-dialog-card p {
  margin: 0 0 20px;
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
}
.confirm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
.confirm-dialog-actions .btn { width: auto; }

/* Hell-/Dunkelmodus-Umschalter - fest positioniert, auf jedem Screen
   sichtbar (siehe index.html: einmalig direkt nach <body>). Zeigt per CSS
   (nicht JS) je nach aktivem Modus Sonne oder Mond - ein Icon ist per
   Default versteckt, [data-theme] auf <html> blendet das jeweils
   passende ein/aus. */
.theme-toggle-btn {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--heading);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  font-size: 16px;
  line-height: 1;
  padding: 0;
}
.theme-toggle-btn:hover { border-color: var(--heading); }
.theme-toggle-icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle-icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle-icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle-icon-sun { display: none; }
  :root:not([data-theme="light"]) .theme-toggle-icon-moon { display: block; }
}
/* Auf Mobile überschneidet sich die feste Topbar sonst mit dem Umschalter
   oben rechts (siehe .mobile-topbar unten) - dort stattdessen links neben
   dem Rand, unterhalb der Topbar-Höhe. */
@media (max-width: 780px) {
  .theme-toggle-btn { top: auto; bottom: 24px; right: auto; left: 16px; }
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 100;
  max-width: 360px;
}
.toast.error { background: var(--danger); }
.toast-undo { display: flex; align-items: center; gap: 16px; }
.toast-action {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  padding: 0;
  font-family: inherit;
}
.toast-action:hover { opacity: 0.85; }

/* Mobile-Topbar (Logo -> Startseite, Menü-Button -> öffnet Sidebar als
   Drawer) - auf Desktop nie sichtbar, siehe app-shell/app-shell-Regel
   oben ("display:grid") und hier drunter "display:none" als Default. */
.mobile-topbar { display: none; }
.mobile-drawer-backdrop { display: none; }

@media (max-width: 780px) {
  /* display:block statt grid-template-columns:1fr - sonst verteilt CSS Grid
     die durch min-height:100vh entstehende Resthöhe ungleich zwischen der
     (jetzt eigenen) Sidebar-Zeile und der Main-Zeile, statt die Sidebar an
     ihrem tatsächlichen Inhalt auszurichten. */
  #app-shell { display: block; padding-top: 56px; }

  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    padding: 0 16px;
    background: var(--ink);
    z-index: 220;
  }
  .mobile-menu-btn {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    padding: 0;
  }
  .mobile-menu-btn span {
    display: block;
    width: 20px;
    height: 2px;
    border-radius: 2px;
    background: #fff;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }
  .mobile-menu-btn.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .mobile-menu-btn.open span:nth-child(2) { opacity: 0; }
  .mobile-menu-btn.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  .mobile-topbar-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    background: none;
    border: none;
    padding: 0;
  }
  .mobile-topbar-logo { width: 30px; height: 30px; flex-shrink: 0; }
  .mobile-topbar-name {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 16px;
    color: #fff;
  }

  .mobile-drawer-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 210;
  }

  /* Die Sidebar bleibt strukturell/optisch die gleiche vertikale Spalte
     wie am Desktop (siehe .sidebar-Basisregel oben: flex-direction:column
     etc. bleibt unverändert gültig) - hier wird sie nur zu einem fixen,
     standardmäßig ausgeblendeten Drawer von links positioniert. */
  .sidebar {
    position: fixed;
    /* Startet UNTER der Topbar (56px), sonst läge die Topbar (höherer
       z-index) über dem oberen Sidebar-Bereich und würde ihn optisch
       abschneiden. */
    top: 56px;
    left: 0;
    bottom: 0;
    /* Setzt die "height: 100vh" der Desktop-Basisregel (siehe .sidebar
       oben, für den sticky-Fix dort) explizit zurück: mit top+bottom UND
       einer festen height von 100vh gleichzeitig ragte die Sidebar 56px
       (die Höhe der Topbar) über den unteren Viewport-Rand hinaus - genau
       so viel fehlte dann von "Abmelden" im sidebar-footer. Ohne feste
       height ergibt sich die Höhe bei position:fixed korrekt aus
       top+bottom (= Viewport-Höhe minus Topbar). */
    height: auto;
    width: 260px;
    max-width: 82vw;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 215;
    overflow-y: auto;
    /* Verhindert Scroll-Chaining: erreicht ein Swipe im Drawer dessen
       oberes/unteres Ende, soll die Geste NICHT an den (jetzt zusätzlich
       per JS gesperrten, siehe _lockBodyScroll in app.js) Hintergrund
       weitergereicht werden. */
    overscroll-behavior: contain;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
  }
  .sidebar.open { transform: translateX(0); }
  /* Logo/Markenname stehen bereits dauerhaft in der Topbar - im Drawer
     selbst wäre das doppelt. */
  .sidebar .brand-mark { display: none; }

  .main { padding: 20px; }
  .form-grid { grid-template-columns: 1fr; }
  /* Leere Spacer-Felder dienen nur der 2-Spalten-Ausrichtung am Desktop -
     auf Mobile (1 Spalte) erzeugen sie sonst eine unmotivierte Lücke. */
  .form-grid .field:empty { display: none; }
  .line-item-row {
    grid-template-columns: 1fr;
    border-bottom: 1px solid var(--border);
    padding-bottom: 14px;
  }
  .line-items-head { display: none; }
  .li-mobile-label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    font-weight: 600;
    margin-bottom: 4px;
  }
  .line-item-row .remove-btn {
    justify-self: end;
    padding: 10px;
    font-size: 20px;
  }
  .line-item-row:last-child { border-bottom: none; padding-bottom: 0; }

  .metric-cards { grid-template-columns: 1fr 1fr; }
  .dashboard-alert { flex-direction: column; align-items: stretch; }

  /* Tabellen (Rechnungen, Kunden, Admin-Nutzer/-Blog/-Abos/-Zahlungen) auf
     einer 390px-Breite mit 4-5 Spalten liefen bisher nur mit unsichtbarem
     Horizontal-Scroll (siehe .card:has(.data-table) oben) - Status und vor
     allem die Aktions-Buttons (Bearbeiten/Löschen/Sperren/PDF/Senden...)
     lagen dadurch faktisch verborgen außerhalb des sichtbaren Bereichs,
     ohne jeden Hinweis, dass dort noch etwas ist. Jede Zeile wird hier
     stattdessen zu einer eigenen, vertikal gestapelten Karte - jede Zelle
     bekommt ihre Spaltenüberschrift als kleines Label direkt über sich
     (per data-label-Attribut in app.js/admin.js, ausgegeben über
     ::before/attr()), außer der ersten Zelle (Titel+Unterzeile, z.B.
     Rechnungsnummer oder Kundenname - selbsterklärend, kein Label nötig). */
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td {
    display: block;
    width: 100%;
  }
  .data-table tr {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
  }
  .data-table tr:last-child { border-bottom: none; }
  .data-table td {
    padding: 3px 0;
    border-bottom: none;
    text-align: left;
  }
  .data-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    font-weight: 600;
    margin-top: 10px;
  }
  .data-table td.actions { margin-top: 4px; }
  .data-table .actions-inner { justify-content: flex-start; }
}

@media (max-width: 480px) {
  #auth-screen, #verify-screen { padding: 16px; }
  .metric-cards { grid-template-columns: 1fr; }
  .auth-card { padding: 28px 20px; }
  .toast { left: 16px; right: 16px; bottom: 16px; max-width: none; }
}

@media (max-width: 780px) {
  .landing-hero { padding: 48px 20px 40px; }
  .landing-hero h1 { font-size: 30px; }
  .landing-features { grid-template-columns: 1fr 1fr; padding: 8px 20px 48px; }
  .landing-steps-row { grid-template-columns: 1fr; gap: 28px; }
  .landing-nav { gap: 12px; }
  .plan-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .landing-header-inner { flex-direction: column; align-items: flex-start; gap: 12px; }
  .landing-nav { width: 100%; justify-content: space-between; }
  .landing-features { grid-template-columns: 1fr; }
  .landing-cta-row { flex-direction: column; align-items: stretch; }
  .landing-cta-row .btn { width: 100%; }
}
