/* =============================================================================
   Susewind — Rechnungs-Tool · Design-System
   Ruhig, professionell, Handwerks-/Business. Kein generischer AI-Look.
   Eine zurueckhaltende Primaerfarbe (tiefes Petrol/Indigo), neutrale Graustufen,
   ein Akzent (warmes Bernstein fuer Hervorhebungen). System-Font-Stack.
   ========================================================================== */

:root {
  /* ── Primaer (tiefes Petrol-Indigo) ───────────────────────────────────── */
  --c-primary:        #1f3a5f;
  --c-primary-600:    #284b78;
  --c-primary-700:    #182d49;
  --c-primary-50:     #eef2f8;
  --c-primary-100:    #dce5f0;

  /* ── Akzent (warmes Bernstein, sparsam) ───────────────────────────────── */
  --c-accent:         #b06a2c;
  --c-accent-50:      #fbf2e9;

  /* ── Neutrale Graustufen ──────────────────────────────────────────────── */
  --c-ink:            #1b2430;   /* Haupttext */
  --c-ink-soft:       #46505c;   /* Sekundaertext */
  --c-muted:          #6b7682;   /* Tertiaer / Labels */
  --c-line:           #e3e7ec;   /* Linien / Rahmen */
  --c-line-strong:    #ccd2da;
  --c-surface:        #ffffff;   /* Karten */
  --c-surface-2:      #f7f9fb;   /* Zebra / dezenter Hintergrund */
  --c-bg:             #f1f4f7;   /* App-Hintergrund */

  /* ── Status (Badges) ──────────────────────────────────────────────────── */
  --c-draft-bg:       #eef0f3;  --c-draft-fg:       #515c69;
  --c-issued-bg:      #e6efe9;  --c-issued-fg:      #2f6b46;
  --c-paid-bg:        #e7eef7;  --c-paid-fg:        #245a93;
  --c-cancelled-bg:   #f9e9e7;  --c-cancelled-fg:   #9a3a2e;

  --c-danger:         #b3392b;
  --c-danger-50:      #f9eceb;
  --c-ok:             #2f6b46;

  /* ── Spacing-Skala (4 / 8 px) ─────────────────────────────────────────── */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px; --s-12: 48px; --s-16: 64px;

  /* ── Radius / Schatten ────────────────────────────────────────────────── */
  --r-sm: 6px;  --r: 8px;  --r-lg: 10px;  --r-pill: 999px;
  --sh-1: 0 1px 2px rgba(20,30,45,.06), 0 1px 1px rgba(20,30,45,.04);
  --sh-2: 0 2px 8px rgba(20,30,45,.07), 0 1px 2px rgba(20,30,45,.05);
  --sh-pop: 0 8px 28px rgba(20,30,45,.14);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", sans-serif;
  --font-num: "SF Mono", ui-monospace, "Roboto Mono", "Cascadia Code", Menlo, monospace;

  --content-max: 1100px;
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--c-ink);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p, ul, ol { margin: 0; }
a { color: var(--c-primary-600); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--c-primary-600); outline-offset: 2px; border-radius: 4px; }

/* ── Layout: App-Shell ─────────────────────────────────────────────────── */
.app-header {
  background: var(--c-primary);
  color: #fff;
  border-bottom: 1px solid var(--c-primary-700);
}
.app-header__inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s-3) var(--s-5);
  display: flex;
  align-items: center;
  gap: var(--s-5);
}
.brand {
  display: flex; align-items: center; gap: var(--s-2);
  font-weight: 650; font-size: 16px; letter-spacing: .2px; color: #fff;
}
.brand:hover { text-decoration: none; }
.brand__mark {
  width: 28px; height: 28px; border-radius: var(--r-sm);
  background: linear-gradient(135deg, #2c5688, var(--c-accent));
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 14px;
  flex: none;
}
.nav { display: flex; align-items: center; gap: var(--s-1); margin-left: var(--s-4); flex: 1; }
.nav a {
  color: rgba(255,255,255,.82);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-sm);
  font-size: 14px; font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.10); color: #fff; text-decoration: none; }
.nav a.is-active { background: rgba(255,255,255,.16); color: #fff; }
.nav__sep { flex: 1; }                 /* schiebt User/Abmelden nach rechts (Desktop) */
.nav__user { font-size: 13px; color: rgba(255,255,255,.78); white-space: nowrap; }
.nav__logout { color: rgba(255,255,255,.85) !important; }
.app-header__spacer { flex: 1; }
.app-header__user { font-size: 13px; color: rgba(255,255,255,.78); }
/* Hamburger-Button: nur mobil sichtbar (siehe Media-Query) */
.nav-toggle { display: none; }

.main {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s-8) var(--s-5) var(--s-16);
}

/* ── Seiten-Kopf ───────────────────────────────────────────────────────── */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--s-4); margin-bottom: var(--s-6); flex-wrap: wrap;
}
.page-head h1 { font-size: 24px; font-weight: 680; letter-spacing: -.2px; }
.page-head p { color: var(--c-muted); font-size: 14px; margin-top: var(--s-1); }

/* ── Karten ────────────────────────────────────────────────────────────── */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card__head {
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--c-line);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
}
.card__head h2 { font-size: 16px; font-weight: 640; }
.card__body { padding: var(--s-5); }
.card + .card { margin-top: var(--s-6); }
.card__hint { color: var(--c-muted); font-size: 13px; margin-top: 2px; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  font: inherit; font-weight: 560; font-size: 14px; line-height: 1;
  padding: 10px 16px; min-height: 40px;
  border-radius: var(--r); border: 1px solid transparent;
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, box-shadow .12s;
  text-decoration: none;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn--primary { background: var(--c-primary); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--c-primary-600); text-decoration: none; }
.btn--secondary { background: #fff; color: var(--c-primary-700); border-color: var(--c-line-strong); }
.btn--secondary:hover { background: var(--c-surface-2); text-decoration: none; }
.btn--ghost { background: transparent; color: var(--c-ink-soft); }
.btn--ghost:hover { background: var(--c-surface-2); text-decoration: none; }
.btn--danger { background: #fff; color: var(--c-danger); border-color: #e6c5c1; }
.btn--danger:hover { background: var(--c-danger-50); text-decoration: none; }
.btn--sm { min-height: 32px; padding: 6px 12px; font-size: 13px; }
.btn--block { width: 100%; }
.btn-row { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; }

/* ── Formulare ─────────────────────────────────────────────────────────── */
.field { margin-bottom: var(--s-4); }
.field > label, .label {
  display: block; font-size: 13px; font-weight: 560; color: var(--c-ink-soft);
  margin-bottom: var(--s-2);
}
.input, .select, .textarea {
  width: 100%; font: inherit; font-size: 14px; color: var(--c-ink);
  padding: 9px 12px; min-height: 40px;
  background: #fff; border: 1px solid var(--c-line-strong); border-radius: var(--r);
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--c-primary-600);
  box-shadow: 0 0 0 3px var(--c-primary-100);
  outline: none;
}
.textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
.input.num { text-align: right; font-family: var(--font-num); }
.field__hint { font-size: 12px; color: var(--c-muted); margin-top: var(--s-2); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3) var(--s-4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-3) var(--s-4); }
fieldset { border: none; padding: 0; margin: 0; }

/* Switch (§19-Schalter) */
.switch { display: inline-flex; align-items: center; gap: var(--s-3); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track {
  width: 44px; height: 26px; border-radius: var(--r-pill);
  background: var(--c-line-strong); position: relative; transition: background .15s; flex: none;
}
.switch__track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  background: #fff; border-radius: 50%; box-shadow: var(--sh-1); transition: transform .15s;
}
.switch input:checked + .switch__track { background: var(--c-primary); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { box-shadow: 0 0 0 3px var(--c-primary-100); }
.switch__label { font-size: 14px; }

/* ── Tabellen (Zebra) ──────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data thead th {
  text-align: left; font-size: 12px; font-weight: 620; text-transform: uppercase;
  letter-spacing: .4px; color: var(--c-muted);
  padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--c-line); white-space: nowrap;
}
table.data tbody td {
  padding: var(--s-3) var(--s-4); border-bottom: 1px solid var(--c-line); vertical-align: middle;
}
table.data tbody tr:nth-child(even) { background: var(--c-surface-2); }
table.data tbody tr:hover { background: var(--c-primary-50); }
table.data tbody tr.is-clickable { cursor: pointer; }
table.data .num { text-align: right; font-family: var(--font-num); white-space: nowrap; }
table.data .muted { color: var(--c-muted); }
table.data tfoot td { font-weight: 600; }

/* ── Status-Badges ─────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; line-height: 1;
  padding: 5px 10px; border-radius: var(--r-pill); white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge--draft     { background: var(--c-draft-bg);     color: var(--c-draft-fg); }
.badge--issued    { background: var(--c-issued-bg);    color: var(--c-issued-fg); }
.badge--paid      { background: var(--c-paid-bg);      color: var(--c-paid-fg); }
.badge--cancelled { background: var(--c-cancelled-bg); color: var(--c-cancelled-fg); }

.tag {
  display: inline-flex; align-items: center; font-size: 11px; font-weight: 600;
  padding: 3px 8px; border-radius: var(--r-sm); background: var(--c-primary-50); color: var(--c-primary-700);
}
.tag--b2b { background: var(--c-primary-50); color: var(--c-primary-700); }
.tag--b2c { background: var(--c-accent-50); color: var(--c-accent); }

/* ── Filter-Leiste ─────────────────────────────────────────────────────── */
.toolbar { display: flex; gap: var(--s-2); flex-wrap: wrap; align-items: center; margin-bottom: var(--s-4); }
.seg { display: inline-flex; background: #fff; border: 1px solid var(--c-line-strong); border-radius: var(--r); overflow: hidden; }
.seg button {
  font: inherit; font-size: 13px; font-weight: 540; border: none; background: transparent;
  padding: 8px 14px; cursor: pointer; color: var(--c-ink-soft); border-right: 1px solid var(--c-line);
}
.seg button:last-child { border-right: none; }
.seg button.is-active { background: var(--c-primary); color: #fff; }
.search { flex: 1; min-width: 180px; }

/* ── Alerts / Flash ────────────────────────────────────────────────────── */
.alert {
  border-radius: var(--r); padding: var(--s-3) var(--s-4); font-size: 14px;
  border: 1px solid; margin-bottom: var(--s-4); display: flex; gap: var(--s-2);
}
.alert--error { background: var(--c-danger-50); border-color: #e6c5c1; color: #7e261c; }
.alert--ok    { background: var(--c-issued-bg); border-color: #bcd8c6; color: #235338; }
.alert--info  { background: var(--c-primary-50); border-color: var(--c-primary-100); color: var(--c-primary-700); }

/* ── Empty State ───────────────────────────────────────────────────────── */
.empty { text-align: center; padding: var(--s-12) var(--s-5); color: var(--c-muted); }
.empty h3 { color: var(--c-ink); font-size: 17px; margin-bottom: var(--s-2); }

/* ── Rechnungs-Editor: Positions-Tabelle ───────────────────────────────── */
.lines { width: 100%; border-collapse: collapse; }
.lines th {
  font-size: 12px; font-weight: 620; text-transform: uppercase; letter-spacing: .4px;
  color: var(--c-muted); text-align: left; padding: 0 var(--s-2) var(--s-2);
}
.lines th.num, .lines td.num { text-align: right; }
.lines td { padding: var(--s-1) var(--s-2); vertical-align: top; }
.lines .input { min-height: 38px; padding: 8px 10px; }
.lines tr.line-row td { border-top: 1px solid var(--c-line); padding-top: var(--s-3); padding-bottom: var(--s-3); }
.lines .col-pos { width: 34px; color: var(--c-muted); font-family: var(--font-num); text-align: center; padding-top: 16px; }
.lines .col-qty  { width: 92px; }
.lines .col-unit { width: 78px; }
.lines .col-price{ width: 120px; }
.lines .col-tax  { width: 90px; }
.lines .col-sum  { width: 120px; padding-top: 16px; font-family: var(--font-num); white-space: nowrap; }
.lines .col-del  { width: 40px; }
.line-kind { font-size: 11px; font-weight: 600; color: var(--c-accent); margin-bottom: 2px; }
.btn-del {
  border: none; background: transparent; color: var(--c-muted); cursor: pointer;
  width: 32px; height: 32px; border-radius: var(--r-sm); font-size: 18px; line-height: 1;
}
.btn-del:hover { background: var(--c-danger-50); color: var(--c-danger); }

/* Summenblock im Editor */
.totals-box {
  margin-left: auto; margin-top: var(--s-5); max-width: 360px;
  background: var(--c-surface-2); border: 1px solid var(--c-line); border-radius: var(--r); padding: var(--s-4) var(--s-5);
}
.totals-box .row { display: flex; justify-content: space-between; padding: var(--s-1) 0; font-size: 14px; }
.totals-box .row .val { font-family: var(--font-num); }
.totals-box .row.grand {
  border-top: 1px solid var(--c-line-strong); margin-top: var(--s-2); padding-top: var(--s-3);
  font-weight: 700; font-size: 18px; color: var(--c-primary-700);
}
.totals-box .muted { color: var(--c-muted); }

/* Baustein-Chips */
.chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chip {
  font: inherit; font-size: 13px; border: 1px dashed var(--c-line-strong); background: #fff;
  border-radius: var(--r-pill); padding: 6px 12px; cursor: pointer; color: var(--c-ink-soft); display: inline-flex; gap: 6px; align-items: center;
}
.chip:hover { border-color: var(--c-primary-600); color: var(--c-primary-700); background: var(--c-primary-50); border-style: solid; }
.chip .price { font-family: var(--font-num); color: var(--c-muted); font-size: 12px; }

/* ── Detail-Ansicht (readonly) ─────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-6); }
.def { display: grid; grid-template-columns: 130px 1fr; gap: var(--s-2) var(--s-3); font-size: 14px; }
.def dt { color: var(--c-muted); }
.def dd { margin: 0; color: var(--c-ink); }

/* ── Modal / Sheet ─────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20,30,45,.42); backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: var(--s-4); z-index: 50;
}
.modal {
  background: #fff; border-radius: var(--r-lg); box-shadow: var(--sh-pop);
  width: 100%; max-width: 520px; max-height: 90vh; overflow: auto;
}
.modal__head { padding: var(--s-5); border-bottom: 1px solid var(--c-line); display: flex; justify-content: space-between; align-items: center; }
.modal__head h3 { font-size: 17px; font-weight: 640; }
.modal__body { padding: var(--s-5); }
.modal__foot { padding: var(--s-4) var(--s-5); border-top: 1px solid var(--c-line); display: flex; justify-content: flex-end; gap: var(--s-2); }

/* ── Login ─────────────────────────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--s-5); background: var(--c-bg); }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .card__body { padding: var(--s-8); }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: var(--s-3); margin-bottom: var(--s-6); }
.auth-brand .brand__mark { width: 44px; height: 44px; font-size: 20px; }
.auth-brand h1 { font-size: 20px; font-weight: 680; color: var(--c-ink); }
.auth-brand p { color: var(--c-muted); font-size: 13px; }

/* ── Logo-Vorschau (Settings) ──────────────────────────────────────────── */
.logo-preview {
  border: 1px dashed var(--c-line-strong); border-radius: var(--r); padding: var(--s-4);
  background: var(--c-surface-2); display: grid; place-items: center; min-height: 96px;
}
.logo-preview img { max-height: 72px; max-width: 100%; }
.logo-preview .ph { color: var(--c-muted); font-size: 13px; }

/* ── Utilities ─────────────────────────────────────────────────────────── */
.muted { color: var(--c-muted); }
.small { font-size: 13px; }
.mono { font-family: var(--font-num); }
.right { text-align: right; }
.mt-0 { margin-top: 0; } .mt-2 { margin-top: var(--s-2); } .mt-4 { margin-top: var(--s-4); } .mt-6 { margin-top: var(--s-6); }
.flex { display: flex; } .flex-between { display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); }
.gap-2 { gap: var(--s-2); } .wrap { flex-wrap: wrap; }
.nowrap { white-space: nowrap; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  .grid-2, .grid-3, .detail-grid { grid-template-columns: 1fr; }
  .main { padding: var(--s-5) var(--s-4) var(--s-12); }

  /* ── Mobile-Navigation: Hamburger statt versteckter Leiste ────────────── */
  .app-header__inner { flex-wrap: wrap; }
  .nav-toggle {
    display: flex; flex-direction: column; gap: 4px;
    justify-content: center; align-items: center;
    width: 42px; height: 42px; margin-left: auto; flex: none;
    border: 1px solid rgba(255,255,255,.3); border-radius: var(--r-sm);
    background: transparent; cursor: pointer;
  }
  .nav-toggle span { width: 18px; height: 2px; background: #fff; border-radius: 2px; }
  .nav {
    display: none; order: 3; flex-basis: 100%; flex: 0 0 100%;
    flex-direction: column; align-items: stretch; gap: 2px; margin: var(--s-2) 0 0;
  }
  .nav.is-open { display: flex; }
  .nav a { padding: var(--s-3); font-size: 15px; }
  .nav__sep { display: none; }
  .nav__user { padding: var(--s-2) var(--s-3); border-top: 1px solid rgba(255,255,255,.15); margin-top: var(--s-2); }
  .nav form { width: 100%; }
  .nav__logout { width: 100%; justify-content: flex-start; }

  /* ── Positions-Tabelle → Karten ───────────────────────────────────────── */
  .lines thead { display: none; }
  .lines, .lines tbody, .lines tr, .lines td { display: block; width: 100%; }
  .lines tr.line-row { border: 1px solid var(--c-line); border-radius: var(--r); padding: var(--s-3); margin-bottom: var(--s-3); }
  .lines tr.line-row td { border: none; padding: 4px 0; }
  .lines td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--c-muted); text-transform: uppercase; letter-spacing: .4px; margin-bottom: 2px; }
  .lines .col-pos { display: none; }
  .lines .col-sum { text-align: left; padding-top: 8px; font-weight: 600; }
  .totals-box { max-width: none; }

  /* ── iOS: Felder >=16px verhindern Auto-Zoom beim Fokus; groessere Targets ─ */
  .input, .select, .textarea, .lines .input { font-size: 16px; }
  .btn { min-height: 44px; }
}

/* Alpine: Elemente bis Init verstecken (kein FOUC). */
[x-cloak] { display: none !important; }
