/* ── Reset & Design Tokens ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #f2f2f7;
  --card:     #ffffff;
  --text1:    #1c1c1e;
  --text2:    #3a3a3c;
  --text3:    #8e8e93;
  --border:   #e5e5ea;
  --blue:     #007aff;
  --green:    #34c759;
  --red:      #ff3b30;
  --orange:   #ff9f0a;
  --purple:   #af52de;
  --indigo:   #5856d6;
  --nav-h:    56px;
  --radius:   12px;
  --shadow:   0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md:0 4px 16px rgba(0,0,0,.08);
  --shadow-lg:0 12px 40px rgba(0,0,0,.12);
}

html, body {
  height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  background: var(--bg); color: var(--text1); font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }

/* ── Nav ───────────────────────────────────────────────────────────────────── */
.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 200;
  height: var(--nav-h);
  background: rgba(255,255,255,.92); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; gap: 6px;
}
.nav-brand {
  font-size: 15px; font-weight: 800; letter-spacing: -.4px;
  color: var(--text1); flex-shrink: 0; margin-right: 8px;
}
.nav-dot { color: var(--text3); font-weight: 400; }
.nav-links { display: flex; gap: 2px; flex: 1; }
.nav-btn {
  background: none; border: none; cursor: pointer; padding: 6px 12px; border-radius: 8px;
  font-size: 13.5px; font-weight: 500; color: var(--text3); transition: all .15s; font-family: inherit;
}
.nav-btn:hover  { background: var(--bg); color: var(--text1); }
.nav-btn.active { background: var(--blue); color: #fff; }

.nav-actions { display: flex; gap: 6px; margin: 0 8px; }
.nav-action-btn {
  background: var(--blue); color: #fff; border: none; border-radius: 8px;
  padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: opacity .15s; font-family: inherit;
  box-shadow: 0 1px 4px rgba(0,122,255,.3);
}
.nav-action-btn:hover { opacity: .85; }
.nav-action-btn.green { background: var(--green); box-shadow: 0 1px 4px rgba(52,199,89,.3); }

.nav-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; margin-left: auto; }
.nav-user  { font-size: 13px; color: var(--text3); }
.nav-logout {
  background: none; border: 1.5px solid var(--border); border-radius: 8px;
  padding: 5px 12px; font-size: 13px; cursor: pointer; color: var(--text2);
  transition: background .15s; font-family: inherit;
}
.nav-logout:hover { background: var(--bg); }

.nav-hamburger {
  display: none; flex-direction: column; justify-content: center; align-items: center;
  gap: 5px; width: 36px; height: 36px; background: none; border: none; cursor: pointer; margin-left: auto;
}
.nav-hamburger span { display: block; width: 22px; height: 2px; background: var(--text1); border-radius: 2px; transition: transform .22s, opacity .22s; transform-origin: center; }
.nav-hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-hamburger.open span:nth-child(2) { opacity: 0; }
.nav-hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.mobile-menu {
  display: none; position: fixed; top: var(--nav-h); left: 0; right: 0; z-index: 190;
  background: rgba(255,255,255,.97); backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border); padding: 10px 14px 14px;
  flex-direction: column; gap: 3px; box-shadow: 0 8px 24px rgba(0,0,0,.1);
}
.mobile-menu.open { display: flex; }
.mobile-menu .nav-btn { text-align: left; padding: 10px 14px; border-radius: 10px; font-size: 15px; }
.mob-actions { display: flex; gap: 8px; margin: 6px 0 2px; }
.mob-actions .nav-action-btn { flex: 1; text-align: center; padding: 10px; font-size: 14px; border-radius: 10px; }
.mobile-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; padding-top: 12px; border-top: 1px solid var(--border); }

@media (max-width: 680px) {
  .nav-links { display: none; }
  .nav-right  { display: none; }
  .nav-actions { display: none; }
  .nav-hamburger { display: flex; }
}

/* ── Views ─────────────────────────────────────────────────────────────────── */
.view { display: none; padding-top: var(--nav-h); min-height: 100vh; }
.view.active { display: block; }
.wrap        { max-width: 1120px; margin: 0 auto; padding: 28px 20px 60px; }
.wrap-narrow { max-width: 720px;  margin: 0 auto; padding: 28px 20px 60px; }

/* ── Page Header ───────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; flex-wrap: wrap; gap: 12px; }
.page-title  { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.header-actions { display: flex; gap: 8px; align-items: center; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: 10px; border: none; cursor: pointer;
  font-size: 14px; font-weight: 600; font-family: inherit;
  transition: opacity .15s, transform .08s; white-space: nowrap;
}
.btn:active   { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; box-shadow: 0 2px 8px rgba(0,122,255,.25); }
.btn-primary:hover { opacity: .9; }
.btn-green   { background: var(--green); color: #fff; }
.btn-ghost   { background: var(--card); color: var(--text2); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm      { padding: 6px 12px; font-size: 12px; border-radius: 8px; }
.btn-row     { display: flex; gap: 10px; flex-wrap: wrap; }
.mt-12       { margin-top: 12px; }

/* ── Stats pills ───────────────────────────────────────────────────────────── */
.stats-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-pill {
  flex: 1; min-width: 110px; background: var(--card); border-radius: var(--radius);
  padding: 16px 18px; border: 1px solid var(--border); box-shadow: var(--shadow);
}
.stat-pill .val { font-size: 22px; font-weight: 800; letter-spacing: -.5px; line-height: 1.1; }
.stat-pill .lbl { font-size: 11px; color: var(--text3); margin-top: 4px; font-weight: 500; }
.stat-pill.blue   .val { color: var(--blue); }
.stat-pill.green  .val { color: var(--green); }
.stat-pill.orange .val { color: var(--orange); }
.stat-pill.red    .val { color: var(--red); }

/* ── Table card ────────────────────────────────────────────────────────────── */
.table-card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table thead tr { border-bottom: 1.5px solid var(--border); }
.data-table th {
  padding: 11px 16px; text-align: left; font-size: 11px; font-weight: 700;
  color: var(--text3); text-transform: uppercase; letter-spacing: .06em; white-space: nowrap;
  background: var(--bg);
}
.data-table td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #f7f8ff; cursor: pointer; }
.td-num   { font-weight: 700; font-family: 'SF Mono','Menlo',monospace; font-size: 12px; white-space: nowrap; }
.td-amt   { font-weight: 700; white-space: nowrap; text-align: right; font-family: 'SF Mono','Menlo',monospace; }
.td-date  { white-space: nowrap; color: var(--text2); font-size: 12px; }
.td-name  { font-weight: 600; max-width: 200px; }
.td-actions { white-space: nowrap; text-align: right; }
.td-actions button { margin-left: 4px; }
.loading-cell { text-align: center; padding: 48px; color: var(--text3); font-size: 14px; }

/* ── Status badges ─────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-entwurf    { background: #f2f2f7; color: var(--text2); border: 1px solid var(--border); }
.badge-gesendet   { background: #e5f0ff; color: #005bd3; }
.badge-bezahlt    { background: #e3f9ea; color: #1a7f3a; }
.badge-storniert  { background: #fff0ef; color: #c0001a; }
.badge-angenommen { background: #e3f9ea; color: #1a7f3a; }
.badge-abgelaufen { background: #fff3e0; color: #c45900; }
.badge-verrechnet { background: #f0e8ff; color: #6a1aaf; }

/* ── Form cards ────────────────────────────────────────────────────────────── */
.form-card { background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); padding: 22px 24px; margin-bottom: 12px; }
.form-card-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text3); margin-bottom: 18px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.col-span-2  { grid-column: 1 / -1; }
.form-group  { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text2); }
.req { color: var(--red); }
.form-group input,
.form-group textarea,
.form-group select {
  padding: 10px 13px; border-radius: 9px; border: 1.5px solid var(--border);
  background: var(--bg); font-size: 14px; color: var(--text1); font-family: inherit;
  outline: none; transition: border-color .15s, background .15s; width: 100%;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus { border-color: var(--blue); background: #fff; }
.form-group input[readonly] { color: var(--text3); cursor: default; }
.form-group textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
.form-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text2); cursor: pointer; }
.form-check input { width: auto; }

@media (max-width: 580px) {
  .form-grid-2 { grid-template-columns: 1fr; }
  .col-span-2  { grid-column: 1; }
}

/* ── Items table ───────────────────────────────────────────────────────────── */
.items-header {
  display: grid; grid-template-columns: 1fr 76px 120px 52px 90px 34px;
  gap: 8px; padding: 0 0 10px; margin-bottom: 6px;
  border-bottom: 1.5px solid var(--border);
  font-size: 11px; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: .06em;
}
.item-row {
  display: grid; grid-template-columns: 1fr 76px 120px 52px 90px 34px;
  gap: 8px; align-items: center; margin-bottom: 8px;
}
.item-row input {
  padding: 9px 11px; border-radius: 8px; border: 1.5px solid var(--border);
  background: var(--bg); font-size: 13px; color: var(--text1); outline: none;
  width: 100%; transition: border-color .15s; font-family: inherit;
}
.item-row input:focus { border-color: var(--blue); background: #fff; }
.item-total-cell { font-size: 13px; font-weight: 700; text-align: right; white-space: nowrap; font-family: 'SF Mono','Menlo',monospace; }
.item-vat-cell   { font-size: 12px; color: var(--text3); text-align: center; }
.btn-remove-item {
  width: 32px; height: 32px; background: none; border: 1.5px solid var(--border);
  border-radius: 8px; cursor: pointer; color: var(--text3); font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s; flex-shrink: 0;
}
.btn-remove-item:hover { background: var(--red); color: #fff; border-color: var(--red); }

@media (max-width: 640px) {
  .items-header { display: none; }
  .item-row { grid-template-columns: 1fr 68px 88px 34px; }
  .item-vat-cell { display: none; }
  .item-total-cell { text-align: left; }
}

/* ── Totals ────────────────────────────────────────────────────────────────── */
.totals-box { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.total-row  { display: flex; gap: 48px; justify-content: flex-end; align-items: center; font-size: 14px; }
.total-row span:first-child { color: var(--text2); }
.total-row span:last-child  { font-weight: 600; min-width: 120px; text-align: right; font-family: 'SF Mono','Menlo',monospace; font-size: 13px; }
.total-row.total-gross { padding-top: 12px; margin-top: 6px; border-top: 2px solid var(--text1); }
.total-row.total-gross span { font-size: 18px; font-weight: 800; }

/* ── Form footer ───────────────────────────────────────────────────────────── */
.form-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; padding: 16px 0; }

/* ── Customer grid ─────────────────────────────────────────────────────────── */
.customer-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.customer-card {
  background: var(--card); border-radius: var(--radius); border: 1px solid var(--border);
  box-shadow: var(--shadow); padding: 18px; transition: box-shadow .15s, transform .1s;
}
.customer-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.cust-name    { font-size: 15px; font-weight: 700; margin-bottom: 3px; }
.cust-company { font-size: 13px; color: var(--text3); margin-bottom: 8px; }
.cust-detail  { font-size: 12px; color: var(--text2); margin-bottom: 3px; }
.cust-actions { margin-top: 14px; display: flex; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 500;
  background: rgba(0,0,0,.45); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal-card {
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; max-height: calc(100vh - 40px);
  overflow-y: auto; padding: 24px;
  animation: modalIn .22s cubic-bezier(.34,1.3,.64,1);
}
@keyframes modalIn {
  from { opacity:0; transform: scale(.94) translateY(12px); }
  to   { opacity:1; transform: scale(1) translateY(0); }
}
.modal-header  { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.modal-title   { font-size: 18px; font-weight: 800; letter-spacing: -.3px; }
.modal-close   {
  background: var(--bg); border: none; cursor: pointer; width: 32px; height: 32px; border-radius: 50%;
  font-size: 15px; color: var(--text3); display: flex; align-items: center; justify-content: center;
  transition: background .15s; flex-shrink: 0;
}
.modal-close:hover { background: var(--border); color: var(--text1); }
.modal-form    { display: flex; flex-direction: column; gap: 12px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: rgba(28,28,30,.9); backdrop-filter: blur(12px);
  color: #fff; padding: 11px 22px; border-radius: 22px;
  font-size: 14px; font-weight: 500; z-index: 9999;
  box-shadow: 0 4px 20px rgba(0,0,0,.25); animation: fadeUp .22s ease; pointer-events: none;
}
@keyframes fadeUp {
  from { opacity:0; transform: translateX(-50%) translateY(10px); }
  to   { opacity:1; transform: translateX(-50%) translateY(0); }
}

/* ── Empty & info states ───────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 56px 24px; }
.empty-icon  { font-size: 48px; margin-bottom: 14px; }
.empty-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; letter-spacing: -.3px; }
.empty-sub   { font-size: 14px; color: var(--text3); line-height: 1.5; }
.text-muted  { color: var(--text3); }
.c-green     { color: var(--green); }
.c-red       { color: var(--red); }

.info-box { border-radius: 10px; padding: 11px 14px; font-size: 13px; line-height: 1.5; }
.info-box.warn { background: #fff3e0; border: 1px solid #ffe0b2; color: #c45900; }

/* ── Prefill banner ────────────────────────────────────────────────────────── */
.prefill-banner {
  background: linear-gradient(135deg, #007aff, #5856d6); color: #fff;
  border-radius: 12px; padding: 14px 18px; margin-bottom: 14px;
  font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 10px;
}

/* ── Year select ───────────────────────────────────────────────────────────── */
.year-select {
  padding: 7px 12px; border-radius: 9px; border: 1.5px solid var(--border);
  background: var(--card); font-size: 13px; color: var(--text1);
  cursor: pointer; outline: none; font-family: inherit;
}

/* ── Tax grid ──────────────────────────────────────────────────────────────── */
.tax-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 820px) { .tax-grid { grid-template-columns: 1fr; } }

.tax-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tax-table td { padding: 6px 0; vertical-align: top; line-height: 1.5; }
.tax-table td:last-child { text-align: right; white-space: nowrap; font-family: 'SF Mono','Menlo',monospace; font-size: 12px; font-weight: 600; }
.tax-row-bold td { font-weight: 800; font-size: 14px; padding: 8px 0; }
.tax-sub   { display: block; font-size: 11px; color: var(--text3); font-weight: 400; }
.tax-val   { font-weight: 600; }

.tax-tip-box { margin-top: 16px; background: #fffbeb; border: 1px solid #fcd34d; border-radius: 10px; padding: 14px 16px; font-size: 13px; line-height: 1.6; }
.tax-tip-title { font-weight: 700; margin-bottom: 6px; }

.quarter-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.q-tab {
  flex: 1; padding: 8px; border-radius: 9px; border: 1.5px solid var(--border);
  background: var(--bg); font-size: 13px; font-weight: 600; cursor: pointer;
  color: var(--text2); transition: all .15s; font-family: inherit;
}
.q-tab:hover  { background: var(--border); }
.q-tab.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.ust-label    { font-size: 13px; font-weight: 700; color: var(--text2); }

.cat-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap;
}

/* ── Mobile ────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .wrap, .wrap-narrow { padding: 16px 12px 40px; }
  .page-title  { font-size: 22px; }
  .stats-row   { gap: 8px; }
  .stat-pill   { padding: 12px 14px; }
  .stat-pill .val { font-size: 18px; }
  .customer-grid { grid-template-columns: 1fr; }
  .modal-card  { padding: 18px; }
  .form-card   { padding: 16px; }
  .total-row   { gap: 24px; }
}
