/* ==========================================================================
   Rechnungsgenerator – Dark Mode UI + Invoice Preview + Print
   ========================================================================== */

:root {
  --bg: #0b0c0e;
  --surface: #141619;
  --surface-2: #1b1e23;
  --border: #26292f;
  --border-strong: #33373f;
  --text: #f4f5f6;
  --text-muted: #9aa0a8;
  --text-dim: #6b7078;
  --accent: #34d399;
  --accent-strong: #10b981;
  --accent-contrast: #06251a;
  --danger: #f87171;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.25);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   Header / Footer
   -------------------------------------------------------------------------- */

.app-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.app-header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.app-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--accent-strong);
  color: var(--accent-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 20px;
}

.app-title {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.app-subtitle {
  margin: 1px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

.app-footer {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 24px 40px;
}

.app-footer p {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-dim);
  max-width: 760px;
}

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */

.app-layout {
  max-width: 1440px;
  margin: 0 auto;
  padding: 28px 24px;
  display: grid;
  grid-template-columns: minmax(380px, 520px) 1fr;
  gap: 28px;
  align-items: start;
}

.form-column {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.preview-column {
  min-width: 0;
}

.preview-sticky {
  position: sticky;
  top: 24px;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.preview-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.preview-scale-wrap {
  border-radius: var(--radius);
  overflow: auto;
  max-height: calc(100vh - 110px);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  background: #3a3d42;
  padding: 24px;
}

/* --------------------------------------------------------------------------
   Cards & Fields
   -------------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

.card-title {
  margin: 0 0 16px;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.field-full {
  grid-column: 1 / -1;
}

.field label,
.radio-fieldset legend {
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text-muted);
}

.req {
  color: var(--accent);
}

.optional {
  color: var(--text-dim);
  font-weight: 400;
  font-size: 12px;
}

.field input[type="text"],
.field input[type="email"],
.field input[type="tel"],
.field input[type="date"],
.field input[type="number"],
.field select,
.field textarea {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 9px 11px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--text-dim);
}

.field input:focus-visible,
.field select:focus-visible,
.field textarea:focus-visible {
  outline: none;
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
}

.field input[type="date"] {
  color-scheme: dark;
}

.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa0a8' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.field textarea {
  resize: vertical;
  min-height: 40px;
}

.field input.invalid,
.field textarea.invalid {
  border-color: var(--danger);
}

.field-error {
  margin: 0;
  font-size: 12px;
  color: var(--danger);
  display: none;
}

.field-error.visible {
  display: block;
}

.field-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
}

/* Radio groups */

.radio-fieldset {
  border: 0;
  padding: 0;
  margin: 0;
}

.radio-fieldset legend {
  padding: 0;
  margin-bottom: 6px;
}

.radio-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13.5px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.radio-option:hover {
  border-color: var(--text-dim);
}

.radio-option:has(input:checked) {
  border-color: var(--accent-strong);
  background: rgba(16, 185, 129, 0.08);
}

.radio-option input {
  accent-color: var(--accent-strong);
  margin: 0;
}

/* Tax mode selector */

.tax-mode-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tax-mode-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.tax-mode-option:hover {
  border-color: var(--text-dim);
}

.tax-mode-option:has(input:checked) {
  border-color: var(--accent-strong);
  background: rgba(16, 185, 129, 0.07);
}

.tax-mode-option input {
  accent-color: var(--accent-strong);
  margin-top: 3px;
  flex-shrink: 0;
}

.tax-mode-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tax-mode-body strong {
  font-size: 13.5px;
  font-weight: 600;
}

.tax-mode-body small {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
}

/* File input */

.logo-upload-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.file-input {
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
}

.file-input::file-selector-button {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 7px 12px;
  margin-right: 10px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.file-input::file-selector-button:hover {
  border-color: var(--text-dim);
}

/* --------------------------------------------------------------------------
   Line items
   -------------------------------------------------------------------------- */

.items-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 14px;
}

.item-row {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 14px;
  animation: item-in 0.18s ease;
}

@keyframes item-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.item-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 10px;
  align-items: end;
}

.item-desc { grid-column: span 12; }
.item-qty { grid-column: span 3; }
.item-unit { grid-column: span 3; }
.item-price { grid-column: span 3; }
.item-discount { grid-column: span 3; }
.item-vat { grid-column: span 3; }

.item-actions {
  grid-column: span 9;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding-bottom: 4px;
}

.item-row .field input,
.item-row .field select {
  background: var(--surface);
  padding: 8px 10px;
  font-size: 13.5px;
}

.item-row .field label {
  font-size: 11.5px;
}

.item-total {
  font-variant-numeric: tabular-nums;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--accent);
}

.btn-remove {
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.btn-remove:hover {
  color: var(--danger);
  border-color: var(--danger);
}

.btn-remove:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn-primary,
.btn-secondary,
.btn-ghost {
  font-family: var(--font);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn-primary {
  background: var(--accent-strong);
  color: var(--accent-contrast);
  border: none;
  font-size: 15px;
  font-weight: 650;
  padding: 14px 24px;
  width: 100%;
}

.btn-primary:hover {
  background: var(--accent);
}

.btn-primary:active {
  transform: scale(0.99);
}

.btn-primary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.btn-secondary {
  background: transparent;
  border: 1px dashed var(--border-strong);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 550;
  padding: 10px 16px;
  width: 100%;
}

.btn-secondary:hover {
  border-color: var(--accent-strong);
  color: var(--accent);
}

.btn-secondary:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-size: 13px;
  padding: 6px 12px;
}

.btn-ghost:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.btn-ghost:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.btn-small {
  font-size: 12.5px;
  padding: 5px 11px;
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.e-rechnung-notice {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
}

/* ==========================================================================
   Invoice sheet (preview) — always light, like real paper
   ========================================================================== */

.invoice-sheet {
  background: #ffffff;
  color: #1a1c1e;
  width: 794px; /* A4 @ 96dpi */
  min-height: 1123px;
  margin: 0 auto;
  padding: 64px 64px 150px;
  font-size: 13px;
  line-height: 1.5;
  position: relative;
  font-family: var(--font);
}

.inv-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 44px;
}

.inv-brand img {
  max-height: 64px;
  max-width: 220px;
  display: block;
}

.inv-brand-name {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #111;
}

.inv-contact {
  text-align: right;
  font-size: 11px;
  color: #555;
  line-height: 1.6;
}

.inv-contact strong {
  color: #111;
  font-size: 12px;
}

.inv-addr-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 32px;
  margin-bottom: 40px;
}

.inv-sender-line {
  font-size: 9px;
  color: #888;
  border-bottom: 1px solid #ddd;
  padding-bottom: 3px;
  margin-bottom: 10px;
}

.inv-recipient-block {
  min-width: 250px;
  max-width: 320px;
}

.inv-recipient {
  font-size: 13px;
  line-height: 1.55;
}

.inv-recipient strong {
  font-weight: 650;
}

.inv-meta {
  font-size: 12px;
  min-width: 220px;
}

.inv-meta table {
  border-collapse: collapse;
  width: 100%;
}

.inv-meta td {
  padding: 2px 0;
  vertical-align: top;
}

.inv-meta td:first-child {
  color: #666;
  padding-right: 18px;
  white-space: nowrap;
}

.inv-meta td:last-child {
  text-align: right;
  font-weight: 550;
  color: #111;
}

.inv-title {
  font-size: 26px;
  font-weight: 750;
  letter-spacing: 0.06em;
  margin: 0 0 18px;
  color: #111;
}

.inv-items {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 22px;
  font-size: 12.5px;
}

.inv-items th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #666;
  border-bottom: 1.5px solid #222;
  padding: 0 8px 7px;
  font-weight: 650;
}

.inv-items td {
  padding: 9px 8px;
  border-bottom: 1px solid #e5e5e5;
  vertical-align: top;
}

.inv-items .num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.inv-items .center {
  text-align: center;
  white-space: nowrap;
}

.inv-items .pos {
  color: #888;
  width: 28px;
}

.inv-item-discount {
  display: block;
  font-size: 11px;
  color: #777;
  margin-top: 1px;
}

.inv-totals {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 34px;
}

.inv-totals table {
  border-collapse: collapse;
  min-width: 280px;
  font-size: 13px;
}

.inv-totals td {
  padding: 4px 0;
}

.inv-totals td:first-child {
  color: #555;
  padding-right: 40px;
}

.inv-totals td:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.inv-totals .inv-grand td {
  border-top: 2px solid #222;
  padding-top: 8px;
  font-weight: 700;
  font-size: 14.5px;
  color: #111;
}

.inv-tax-note {
  font-size: 12px;
  color: #444;
  margin: 0 0 26px;
  padding: 10px 14px;
  background: #f6f6f4;
  border-left: 3px solid #999;
}

.inv-block {
  margin-bottom: 22px;
}

.inv-block h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #888;
  margin: 0 0 6px;
  font-weight: 650;
}

.inv-block p {
  margin: 0;
  font-size: 12.5px;
  color: #333;
  white-space: pre-line;
}

.inv-bank-table {
  border-collapse: collapse;
  font-size: 12.5px;
  margin-top: 4px;
}

.inv-bank-table td {
  padding: 1px 0;
}

.inv-bank-table td:first-child {
  color: #666;
  padding-right: 24px;
}

.inv-footer {
  position: absolute;
  left: 64px;
  right: 64px;
  bottom: 44px;
  border-top: 1px solid #ddd;
  padding-top: 12px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  font-size: 9.5px;
  color: #777;
  line-height: 1.6;
}

.inv-footer > div {
  flex: 1;
  min-width: 0;
}

.inv-footer .foot-right {
  text-align: right;
}

.inv-footer .foot-center {
  text-align: center;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 1180px) {
  .app-layout {
    grid-template-columns: 1fr;
  }

  .preview-sticky {
    position: static;
  }

  .preview-scale-wrap {
    max-height: none;
  }

  .invoice-sheet {
    width: 100%;
    min-height: auto;
    padding: 40px 32px 40px;
  }

  .inv-footer {
    position: static;
    margin-top: 32px;
  }
}

@media (max-width: 640px) {
  .field-grid {
    grid-template-columns: 1fr;
  }

  .item-qty, .item-unit, .item-price, .item-discount, .item-vat {
    grid-column: span 6;
  }

  .item-actions {
    grid-column: span 12;
  }

  .app-layout {
    padding: 20px 14px;
  }

  .preview-scale-wrap {
    padding: 10px;
  }

  .invoice-sheet {
    padding: 28px 20px;
    font-size: 12px;
  }

  .inv-head,
  .inv-addr-row {
    flex-direction: column;
  }

  .inv-contact {
    text-align: left;
  }

  .form-actions {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top, var(--bg) 75%, transparent);
    padding: 14px 0 10px;
    z-index: 5;
  }
}

/* --------------------------------------------------------------------------
   Print — show only the invoice, A4-friendly, light
   -------------------------------------------------------------------------- */

@media print {
  @page {
    size: A4;
    margin: 0;
  }

  html,
  body {
    background: #fff !important;
  }

  .app-header,
  .app-footer,
  .form-column,
  .preview-toolbar {
    display: none !important;
  }

  .app-layout {
    display: block;
    padding: 0;
    max-width: none;
  }

  .preview-sticky {
    position: static;
  }

  .preview-scale-wrap {
    max-height: none;
    overflow: visible;
    border: none;
    box-shadow: none;
    background: #fff;
    padding: 0;
    border-radius: 0;
  }

  .invoice-sheet {
    width: auto;
    min-height: auto;
    margin: 0;
    padding: 18mm 16mm 30mm;
    box-shadow: none;
  }

  .inv-footer {
    position: fixed;
    left: 16mm;
    right: 16mm;
    bottom: 10mm;
  }
}
