/* Steuer-KI — Base CSS (Mobile-First) v3 — Apple-HIG-Tokens */
:root {
  /* Brand */
  --primary:       #2563eb;
  --primary-hover: #1d4ed8;
  --primary-dark:  #1e40af;
  --primary-soft:  #eff6ff;
  --accent:        #06b6d4;

  /* Semantik */
  --success:       #10b981;
  --warning:       #f59e0b;
  --error:         #ef4444;

  /* Neutralskala */
  --bg:            #f8fafc;
  --card:          #ffffff;
  --surface:       #f8fafc;
  --surface-2:     #f1f5f9;
  --border:        #e2e8f0;
  --border-strong: #cbd5e1;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --text-soft:     #94a3b8;

  /* Spacing-Rhythmus (4-pt-Grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* Typografie-Stufen */
  --fs-h1:    22px;
  --fs-h2:    17px;
  --fs-h3:    15px;
  --fs-body:  14px;
  --fs-meta:  12px;
  --fs-micro: 11px;

  /* Form */
  --radius-sm:   6px;
  --radius:      8px;
  --radius-lg:   12px;
  --radius-pill: 999px;

  /* Elevation */
  --shadow-sm:   0 1px 2px rgba(15,23,42,.05);
  --shadow-md:   0 4px 12px rgba(15,23,42,.06);
  --shadow-lg:   0 16px 48px rgba(15,23,42,.18);

  /* Status-Farben (semantisch, NICHT pro DB-Status) */
  --status-pending-bg:  #f1f5f9; --status-pending-fg:  #475569;
  --status-progress-bg: #dbeafe; --status-progress-fg: #1e40af;
  --status-review-bg:   #fef3c7; --status-review-fg:   #92400e;
  --status-ready-bg:    #d1fae5; --status-ready-fg:    #065f46;
  --status-error-bg:    #fee2e2; --status-error-fg:    #991b1b;

  /* Interaktion */
  --tap:           44px;
  --focus-ring:    0 0 0 3px rgba(37,99,235,.25);
  --t-fast:        .12s cubic-bezier(.2,.8,.2,1);
  --t-med:         .2s  cubic-bezier(.2,.8,.2,1);
}

*,*::before,*::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; max-width: 100vw; overflow-x: hidden; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =====================================================================
   LAYOUT
   ===================================================================== */
.app-layout {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 56px 1fr;
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
}

/* Topbar — Mobile: Mandant links, User+Logout+Burger rechts */
.topbar {
  grid-column: 1 / -1;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  padding-right: max(14px, env(safe-area-inset-right));
  padding-left:  max(14px, env(safe-area-inset-left));
  gap: 8px;
  position: sticky; top: 0; z-index: 50;
}

/* Mandant-Switcher: nimmt verfuegbaren Platz links */
.topbar .mandant-switch {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
}
.topbar .mandant-switch select {
  width: 100%;
  max-width: 240px;
  padding: 8px 10px;
  font-size: 14px;
  height: 38px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}

/* Rechte Seite: User-Initial + Logout-Icon + Burger */
.topbar .user-info {
  display: flex; align-items: center; gap: 4px;
  flex: 0 0 auto;
}
.topbar .user-info .user-name {
  display: none;
  font-size: 13px;
  color: var(--text-muted);
  margin-right: 6px;
  white-space: nowrap;
}
.topbar .icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  border: none; background: transparent;
  cursor: pointer; padding: 0;
  color: var(--text-muted);
  border-radius: var(--radius);
  text-decoration: none;
}
.topbar .icon-btn:hover { background: #f1f5f9; color: var(--text); text-decoration: none; }
.topbar .icon-btn svg { width: 20px; height: 20px; display: block; }

.topbar .user-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: #dbeafe; color: var(--primary);
  font-size: 13px; font-weight: 600;
  flex: 0 0 auto;
}

/* Burger ganz rechts */
.burger {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border: none; background: transparent;
  cursor: pointer; padding: 0;
  color: var(--text);
  border-radius: var(--radius);
}
.burger:hover { background: #f1f5f9; }
.burger svg { width: 22px; height: 22px; display: block; }

/* Sidebar als Drawer von rechts (passt zu Burger rechts) */
.sidebar {
  background: var(--card);
  border-left: 1px solid var(--border);
  padding: 12px 8px;
  position: fixed;
  top: 56px; bottom: 0; right: 0;
  width: 260px;
  z-index: 40;
  transform: translateX(100%);
  transition: transform .2s ease;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.sidebar.open { transform: translateX(0); }
.sidebar-backdrop {
  position: fixed; inset: 56px 0 0 0;
  background: rgba(15,23,42,.4);
  z-index: 35;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
.sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

.sidebar nav a {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  min-height: var(--tap);
  border-radius: var(--radius);
  color: var(--text);
  font-size: var(--fs-h3);
  transition: background var(--t-fast), color var(--t-fast);
}
.sidebar nav a:hover    { background: var(--surface-2); text-decoration: none; }
.sidebar nav a.active   { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar nav a.active::before {
  content: ""; position: absolute; left: 0; top: 6px; bottom: 6px;
  width: 3px; border-radius: 0 3px 3px 0;
  background: var(--primary);
}
.sidebar nav a.disabled { opacity: .38; pointer-events: none; }
.sidebar .nav-section {
  padding: var(--space-4) var(--space-4) var(--space-1);
  font-size: var(--fs-micro); text-transform: uppercase;
  color: var(--text-soft); letter-spacing: .06em; font-weight: 600;
}

/* Content */
.content {
  padding: 14px 16px 48px;
  /* iOS Safe-Area + min. 16px Rand */
  padding-right: max(16px, env(safe-area-inset-right));
  padding-left:  max(16px, env(safe-area-inset-left));
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
}

/* =====================================================================
   CARDS / HEADINGS / FORMS
   ===================================================================== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  max-width: 100%;
  overflow: hidden;
}
h1 { font-size: var(--fs-h1); margin: 0 0 var(--space-2); font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: var(--fs-h2); margin: 0 0 var(--space-3); font-weight: 600; }
h3 { font-size: var(--fs-h3); margin: 0 0 var(--space-2); font-weight: 600; }
.small  { color: var(--text-muted); font-size: var(--fs-meta); }
.meta   { color: var(--text-muted); font-size: var(--fs-meta); }
.micro  { color: var(--text-soft);  font-size: var(--fs-micro); }
.muted  { color: var(--text-muted); }
.mono   { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

label {
  display: block; font-size: 13px;
  color: var(--text-muted);
  margin: 10px 0 4px;
}
input[type=text], input[type=email], input[type=password],
input[type=date], input[type=number], input[type=tel], input[type=url],
select, textarea {
  width: 100%;
  max-width: 100%;
  padding: 11px 12px;
  min-height: var(--tap);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font: inherit;
  font-size: 16px;
  background: #fff;
}
textarea { min-height: 80px; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary); outline-offset: -1px;
  border-color: var(--primary);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  min-height: var(--tap);
  border-radius: var(--radius);
  border: none;
  background: var(--primary); color: #fff;
  font: inherit; font-size: 15px; font-weight: 600;
  cursor: pointer;
  transition: background .12s ease;
  text-decoration: none;
  max-width: 100%;
}
.btn:hover  { background: var(--primary-hover); text-decoration: none; color:#fff; }
.btn:active { transform: scale(.98); }
.btn:focus-visible { box-shadow: var(--focus-ring); outline: none; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }
.btn-danger  { background: var(--error); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }
.btn-ghost   { background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 7px 12px; min-height: 34px; font-size: var(--fs-meta); border-radius: var(--radius-sm); }
.btn-full { width: 100%; }
.btn-group { display: inline-flex; gap: var(--space-2); flex-wrap: wrap; }

.alert { padding: 12px 16px; border-radius: var(--radius); margin: 12px 0; }
.alert-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* Auth-Pages */
.auth-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 16px;
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow-md);
}
.auth-card h1 { color: var(--primary); }
.auth-meta { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-muted); }

/* =====================================================================
   TABELLEN
   ===================================================================== */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td {
  padding: 8px 10px; text-align: left;
  border-bottom: 1px solid var(--border);
}
th { font-weight: 600; color: var(--text-muted); font-size: 12px; }

/* Spalten-Visibility-Helper */
.hide-mobile { /* auf Mobile ausgeblendet */ }
.mobile-only { /* nur auf Mobile sichtbar */ display: none; }
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
  tr.mobile-only { display: table-row; }
  td.mobile-only, th.mobile-only, span.mobile-only, div.mobile-only { display: revert; }
}

/* Status-Badges (semantisch) */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-micro);
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
.badge-grey,  .s-pending  { background: var(--status-pending-bg);  color: var(--status-pending-fg); }
.badge-blue,  .s-progress { background: var(--status-progress-bg); color: var(--status-progress-fg); }
.badge-green, .s-ready    { background: var(--status-ready-bg);    color: var(--status-ready-fg); }
.badge-yellow,.s-review   { background: var(--status-review-bg);   color: var(--status-review-fg); }
.badge-red,   .s-error    { background: var(--status-error-bg);    color: var(--status-error-fg); }

/* Animierter Dot fuer "in Verarbeitung" */
.s-progress::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: .7;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity:.3 } 50% { opacity:1 } }

/* =====================================================================
   DATA-TABLE — zentrale Tabellen-Komponente
   ===================================================================== */
.data-tbl {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-body);
}
.data-tbl thead th {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: var(--fs-micro);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-tbl tbody td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-tbl tbody tr { transition: background var(--t-fast); }
.data-tbl tbody tr:hover { background: var(--surface); }
.data-tbl .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
.data-tbl .actions { text-align: right; white-space: nowrap; }
.data-tbl tr.group-row td {
  background: var(--surface-2);
  font-weight: 700;
  color: var(--text);
  padding: var(--space-3);
  border-top: 2px solid var(--border-strong);
}
.data-tbl tr.subgroup-row td {
  background: var(--surface);
  font-weight: 600;
  color: var(--text-muted);
  font-size: var(--fs-meta);
  padding: var(--space-2) var(--space-3);
}
.data-tbl tr.total-row td {
  background: var(--surface-2);
  font-weight: 700;
  border-top: 2px solid var(--border-strong);
}
.data-tbl--compact tbody td { padding: var(--space-2) var(--space-3); }

/* Bookkeeping-Modifier: Soll/Haben Doppel-Spalten dezent eingefaerbt */
.data-tbl--book th.haben,
.data-tbl--book td.haben { background: rgba(16,185,129,.06); }
.data-tbl--book th.soll,
.data-tbl--book td.soll  { background: rgba(37,99,235,.05); }
.data-tbl--book th.haben { color: var(--status-ready-fg); }
.data-tbl--book th.soll  { color: var(--primary-dark); }

/* Quick-Filter-Pills (in Filterleisten) */
.pill-bar {
  display: inline-flex; flex-wrap: wrap; gap: var(--space-2);
  margin-left: var(--space-2);
}
.pill-bar .pill {
  display: inline-flex; align-items: center;
  padding: 5px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  font-size: var(--fs-meta);
  color: var(--text);
  background: var(--card);
  text-decoration: none;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.pill-bar .pill:hover {
  background: var(--primary-soft); border-color: var(--primary); color: var(--primary);
  text-decoration: none;
}
.pill-bar .pill.active {
  background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600;
}

/* Read-only Filter-Inputs (z.B. Mandant-Name) */
.input-readonly,
input[readonly] {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: default;
}

/* Filter-Bar Layout */
.filter-bar {
  display: flex; gap: var(--space-3); align-items: end; flex-wrap: wrap;
}
.filter-bar > div { min-width: 0; }
.filter-bar label { margin: 0 0 var(--space-1); font-size: var(--fs-meta); }

/* Icon-Button (klein, fuer Action-Spalten) */
.icon-action {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.icon-action:hover { background: var(--surface-2); color: var(--text); }
.icon-action.is-success:hover { color: var(--status-ready-fg);  background: var(--status-ready-bg); }
.icon-action.is-danger:hover  { color: var(--status-error-fg);  background: var(--status-error-bg); }
.icon-action.is-primary:hover { color: var(--primary);          background: var(--primary-soft); }
.icon-action svg { width: 16px; height: 16px; display: block; }

/* Saldo-Akzente (positiv gruen, negativ rot, dezent) */
.saldo-pos { color: var(--status-ready-fg); font-weight: 600; font-variant-numeric: tabular-nums; }
.saldo-neg { color: var(--status-error-fg); font-weight: 600; font-variant-numeric: tabular-nums; }

/* Candidate-Liste (Modal in transaktionen.php / beleg-detail.php) */
.cand-list { display: flex; flex-direction: column; }
.cand-row {
  display: flex; gap: var(--space-3);
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--t-fast);
}
.cand-row:hover { background: var(--surface); }
.cand-row.is-exact { background: var(--status-ready-bg); }
.cand-row.is-exact:hover { background: var(--status-ready-bg); filter: brightness(0.96); }
.cand-row:last-child { border-bottom: none; }

/* Modal */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.55);
  z-index: 1000;
  display: flex; align-items: flex-start; justify-content: center;
  overflow-y: auto;
  padding: 30px 12px;
}
.modal-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  max-width: 980px; width: 100%;
  padding: var(--space-5) var(--space-6);
  box-shadow: var(--shadow-lg);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-3);
}
.modal-head h2 { margin: 0; }
.modal-close {
  background: transparent; border: none;
  font-size: 22px; cursor: pointer; color: var(--text-muted);
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  transition: background var(--t-fast);
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

/* Empty-State */
.empty-state {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--text-muted);
  font-size: var(--fs-meta);
}
.empty-state .title {
  font-size: var(--fs-h3); color: var(--text);
  margin-bottom: var(--space-2); font-weight: 600;
}

/* Skeleton-Loader */
.skel {
  display: inline-block;
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: skel 1.4s ease-in-out infinite;
  height: 12px; min-width: 60px;
}
@keyframes skel { 0% { background-position: 200% 0 } 100% { background-position: -200% 0 } }

/* =====================================================================
   GRIDS (responsive)
   ===================================================================== */
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: 1fr; }

/* KPI-Cards: 2x2 auf Mobile, 4-spaltig auf Desktop */
.kpi-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, 1fr);
  margin: 12px 0;
}
.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 12px;
}
.kpi-card .kpi-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; }
.kpi-card .kpi-value { font-size: 22px; font-weight: 600; margin-top: 2px; line-height: 1.1; }
.kpi-card .kpi-sub   { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* =====================================================================
   DESKTOP (≥ 769px)
   ===================================================================== */
@media (min-width: 769px) {
  html, body { overflow-x: visible; }
  .app-layout { grid-template-columns: 240px 1fr; overflow-x: visible; }
  .topbar { padding: 0 20px; gap: 16px; }
  .burger { display: none; }
  .topbar .mandant-switch select { max-width: 280px; }
  .topbar .user-info .user-name { display: inline; }

  /* Sidebar fest auf Desktop, links */
  .sidebar {
    position: static; transform: none;
    width: auto;
    left: 0; right: auto;
    border-left: none;
    border-right: 1px solid var(--border);
    box-shadow: none;
    grid-row: 2;
    grid-column: 1;
    padding: 16px 8px;
  }
  .sidebar-backdrop { display: none; }

  .content {
    padding: 24px 28px;
    max-width: 1200px;
    grid-row: 2;
    grid-column: 2;
    overflow-x: visible;
  }
  /* Phase 8.BV (2026-08-18): Seiten mit breiten Tabellen (Belege, Transaktionen,
     Saldenabgleich) duerfen den ganzen Bildschirm nutzen. Die 1200px sind fuer
     Textseiten gedacht; die 18-spaltige Belegliste braucht rund 1300px und war
     dadurch selbst auf grossen Monitoren abgeschnitten. */
  .content--breit { max-width: none; }
  .card { padding: 24px; margin-bottom: 20px; }
  body { font-size: 15px; }

  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

  .kpi-grid { grid-template-columns: repeat(4, 1fr); gap: 16px; }
  .kpi-card { padding: 16px; }
  .kpi-card .kpi-value { font-size: 28px; }
}

/* =====================================================================
   PRINT
   ===================================================================== */
@media print {
  .sidebar, .topbar, .burger { display: none !important; }
  .content { padding: 0; max-width: 100%; }
}

/* Phase 8.BI (2026-08-04): Auswertungen drucken / als PDF speichern */
@media print {
  .no-print, .filter-bar { display: none !important; }
  .card { break-inside: avoid; box-shadow: none; border: 1px solid #ccc; }
  body { background: #fff; }
}
