/* Rechnungs-Generator CH - app.css */
:root {
  --blue: #1e40af;
  --blue-dark: #1e3a8a;
  --blue-700: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;

  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #d8dee9;
  --text: #0f172a;
  --text-muted: #5b6678;
  --field-bg: #ffffff;
  --field-border: #cbd5e1;
  --accent: var(--blue);
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 6px 18px rgba(15, 23, 42, .06);
  --radius: 14px;
  --radius-sm: 9px;
  --focus: 0 0 0 3px rgba(30, 64, 175, .35);
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #131c2e;
  --surface-2: #18233a;
  --border: #2a3650;
  --text: #e7ecf5;
  --text-muted: #9aa7bd;
  --field-bg: #0f1828;
  --field-border: #324063;
  --accent: #60a5fa;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  --focus: 0 0 0 3px rgba(96, 165, 250, .45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3 { margin: 0; line-height: 1.2; }

.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;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--blue);
  color: #fff;
  padding: 10px 16px;
  z-index: 100;
  border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  color: #fff;
  padding: 14px clamp(14px, 4vw, 28px);
  padding-top: calc(14px + env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { border-radius: 9px; flex: none; }
.app-header h1 { font-size: clamp(1.05rem, 3.6vw, 1.4rem); }
.tagline { margin: 2px 0 0; font-size: .78rem; opacity: .85; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--field-border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  transition: transform .08s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
  line-height: 1.1;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn-sm { padding: 8px 12px; font-size: .85rem; }
.btn-primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-700); border-color: var(--blue-700); }
.btn-ghost { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.4); }
.btn-ghost:hover { background: rgba(255,255,255,.24); border-color: #fff; }
.btn-icon {
  background: rgba(255,255,255,.14);
  border-color: rgba(255,255,255,.4);
  color: #fff;
  width: 42px; height: 42px;
  padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.15rem;
}
.btn-icon:hover { background: rgba(255,255,255,.24); }
.btn-danger-ghost { color: var(--red); border-color: var(--red); background: transparent; }
.btn-danger-ghost:hover { background: rgba(220,38,38,.1); }
.btn-add {
  width: 100%;
  border-style: dashed;
  color: var(--accent);
  margin-top: 10px;
  background: var(--surface-2);
}
.btn-add:hover { background: var(--surface); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: clamp(14px, 2.4vw, 26px);
  padding: clamp(14px, 3vw, 28px);
  max-width: 1400px;
  margin: 0 auto;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.editor { min-width: 0; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

/* ---------- Cards / form ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 0 0 16px;
}
.card legend {
  font-weight: 700;
  color: var(--accent);
  padding: 0 6px;
  font-size: .95rem;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: .8rem; color: var(--text-muted); font-weight: 600; }
.field.span-2 { grid-column: 1 / -1; }
.field.checkbox { flex-direction: row; align-items: center; gap: 9px; }
.field.checkbox > span { font-size: .9rem; color: var(--text); }
.field.checkbox input { width: 18px; height: 18px; accent-color: var(--blue); }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--field-bg);
  border: 1px solid var(--field-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 100%;
  min-width: 0;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: .7; }

.hint {
  font-size: .78rem;
  color: var(--text-muted);
  margin: 10px 0 0;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

/* ---------- Items ---------- */
.items-head, .item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px 110px 110px 40px;
  gap: 8px;
  align-items: center;
}
.items-head {
  font-size: .74rem;
  color: var(--text-muted);
  font-weight: 700;
  padding: 0 2px 8px;
  border-bottom: 1px solid var(--border);
}
.items-head .num, .item-row .num { text-align: right; }
.items-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.item-row { padding: 4px 0; }
.item-row input { padding: 9px 10px; }
.item-row .item-sum {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  padding: 9px 4px;
  color: var(--text);
}
.item-del {
  width: 36px; height: 36px;
  border-radius: 8px;
  border: 1px solid var(--field-border);
  background: var(--surface-2);
  color: var(--red);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
}
.item-del:hover { background: rgba(220,38,38,.1); border-color: var(--red); }
.item-del:focus-visible { outline: none; box-shadow: var(--focus); }

@media (max-width: 560px) {
  .items-head { display: none; }
  .item-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
  }
  .item-row .item-desc { grid-column: 1 / -1; }
  .item-row .num { text-align: left; }
  .item-row .item-sum {
    grid-column: 1 / -1;
    text-align: right;
    border-top: 1px dashed var(--border);
    padding-top: 8px;
  }
  .item-del { justify-self: end; }
  .field-wrap-label { font-size: .72rem; color: var(--text-muted); display: block; margin-bottom: 3px; }
}

/* ---------- Invoice document (preview + print) ---------- */
.preview-wrap { min-width: 0; }
.preview-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 10px;
}
.preview-bar h2 { font-size: 1.05rem; color: var(--text); }

.invoice-doc {
  background: #ffffff;
  color: #16202e;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(20px, 4vw, 40px);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.doc-head {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  border-bottom: 3px solid var(--blue);
  padding-bottom: 16px;
  margin-bottom: 22px;
}
.doc-from { min-width: 0; }
.doc-from-name { font-weight: 800; font-size: 1.15rem; color: var(--blue); }
.doc-muted { color: #64748b; font-size: .86rem; }

.doc-title-block { text-align: right; min-width: 180px; }
.doc-title {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--blue);
}
.doc-meta { margin-left: auto; border-collapse: collapse; font-size: .88rem; }
.doc-meta th { text-align: right; color: #64748b; font-weight: 600; padding: 2px 10px 2px 0; }
.doc-meta td { text-align: right; font-weight: 600; color: #16202e; }

.doc-to { margin-bottom: 22px; }
.doc-label {
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: .72rem;
  color: #64748b;
  font-weight: 700;
  margin-bottom: 4px;
}
.doc-to-name { font-weight: 700; }

.doc-items {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 18px;
}
.doc-items thead th {
  background: var(--blue);
  color: #fff;
  text-align: left;
  padding: 9px 10px;
  font-size: .82rem;
  font-weight: 700;
}
.doc-items thead th.c-num { text-align: right; }
.doc-items tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: top;
}
.doc-items tbody tr:nth-child(even) td { background: #f8fafc; }
.doc-items .c-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.doc-items .c-desc { width: 52%; }
.doc-empty td { color: #94a3b8; font-style: italic; text-align: center; }

.doc-totals { display: flex; justify-content: flex-end; }
.doc-totals table { border-collapse: collapse; min-width: 260px; }
.doc-totals th {
  text-align: left;
  padding: 6px 18px 6px 0;
  color: #475569;
  font-weight: 600;
}
.doc-totals td {
  text-align: right;
  padding: 6px 0;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.doc-grand th, .doc-grand td {
  border-top: 2px solid var(--blue);
  font-size: 1.12rem;
  color: var(--blue);
  font-weight: 800;
  padding-top: 10px;
}

.doc-notes {
  margin-top: 24px;
  padding-top: 14px;
  border-top: 1px solid #e2e8f0;
  color: #475569;
  font-size: .9rem;
  white-space: pre-wrap;
}
.doc-notes:empty { display: none; }

/* keep the document readable in dark mode (it stays a "paper") */
[data-theme="dark"] .invoice-doc { box-shadow: 0 8px 30px rgba(0,0,0,.55); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  background: var(--blue-dark);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,.3);
  font-weight: 600;
  z-index: 200;
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  max-width: min(90vw, 420px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { background: var(--red); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 13, 24, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 300;
}
.modal {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
  padding: 22px;
  max-width: 420px;
  width: 100%;
}
.modal h3 { color: var(--accent); margin-bottom: 8px; }
.modal p { margin: 0 0 18px; color: var(--text-muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Print ---------- */
@media print {
  @page { margin: 14mm; }
  body { background: #fff; padding: 0; }
  .no-print { display: none !important; }
  .layout {
    display: block;
    padding: 0;
    max-width: none;
  }
  .preview-wrap { width: 100%; }
  .invoice-doc {
    border: none;
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    background: #fff;
    color: #000;
    font-size: 12px;
  }
  .doc-items thead th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .doc-from-name, .doc-title, .doc-grand th, .doc-grand td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
