/* Rechnungen – ruhige Arbeitsoberfläche; die Firmenfarbe (--brand) zeigt immer, für wen man gerade arbeitet */
:root {
  --ink: #1E2433;
  --muted: #5F6874;
  --canvas: #EEF1F0;
  --paper: #FFFFFF;
  --line: #D3D9D7;
  --paid: #2E7D4F;
  --danger: #B3261E;
  --brand: #2F5D8C;
  --radius: 6px;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--canvas);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; display: flex; }
a { color: var(--brand); }
h1 { font-size: 1.75rem; line-height: 1.2; letter-spacing: -0.015em; margin: 0; font-weight: 700; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- Seitenleiste */
.side {
  width: 230px; flex-shrink: 0; background: var(--paper); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.tenant {
  background: var(--brand); color: #fff; padding: 22px 18px 20px; min-height: 96px;
  display: flex; align-items: flex-end;
}
.tenant strong, .tenant select {
  font-size: 1.15rem; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; color: #fff;
}
.tenant select {
  width: 100%; background: transparent; border: 0; border-bottom: 1px solid rgba(255,255,255,.5);
  padding: 2px 18px 4px 0; appearance: none; cursor: pointer; font-family: inherit;
  background-image: linear-gradient(45deg, transparent 50%, #fff 50%), linear-gradient(135deg, #fff 50%, transparent 50%);
  background-position: right 6px center, right 1px center; background-size: 5px 5px; background-repeat: no-repeat;
}
.tenant select option { color: var(--ink); }
.side nav { display: flex; flex-direction: column; padding: 14px 10px; gap: 2px; }
.side nav a {
  text-decoration: none; color: var(--ink); padding: 8px 10px; border-radius: var(--radius);
  border-left: 3px solid transparent;
}
.side nav a:hover { background: var(--canvas); }
.side nav a.on { border-left-color: var(--brand); background: var(--canvas); font-weight: 600; }
.nav-group { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 16px 10px 4px; }
.me { margin-top: auto; padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; font-size: .9rem; }
.me a { color: var(--ink); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me a.on, .me a:hover { text-decoration: underline; }
.me .logout { color: var(--muted); flex-shrink: 0; }
.company-checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; margin-bottom: 14px; }
.company-checks label { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; }
.company-checks label:has(input:checked) { border-color: var(--ink); }
.company-checks input { width: auto; }
.admin-note { padding: 10px 12px; background: var(--canvas); border-radius: 4px; margin: 0 0 14px; }
[data-admin-hides][hidden] { display: none; }
.role { font-size: .8rem; font-weight: 600; }
tr.inactive td { color: var(--muted); }

/* ---------- Inhalt */
.main { flex: 1; padding: 32px 40px 64px; max-width: 1180px; min-width: 0; }
.bare { flex: 1; display: grid; place-items: center; padding: 24px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.head > div:first-child { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.head-actions form { margin: 0; }
.search input { width: 260px; }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 18px; background: var(--paper); border-left: 4px solid var(--paid); }
.flash-error { border-left-color: var(--danger); }

.summary { margin: -8px 0 18px; color: var(--muted); }
.summary strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.summary .overdue { color: var(--danger); }

/* ---------- Tabellen */
.table-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
.list th, .list td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.list th { font-size: .82rem; font-weight: 600; color: var(--muted); background: #F7F8F8; }
.list tbody tr:last-child td { border-bottom: 0; }
.list tbody tr:hover { background: #FAFBFB; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.actions { text-align: right; white-space: nowrap; }
.actions > * { margin-left: 12px; display: inline; }
.actions form { display: inline; }
.mono-ish { font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 8px; vertical-align: 1px; }
.tag { font-size: .75rem; border: 1px solid var(--brand); color: var(--brand); padding: 0 6px; border-radius: 3px; margin-left: 6px; }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 999px; }
.tabs a:hover { color: var(--ink); }
.tabs a.on { background: var(--ink); color: #fff; }

.status { display: inline-block; font-size: .8rem; padding: 1px 9px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.status-sent { border-color: var(--brand); color: var(--brand); }
.status-overdue { background: var(--danger); border-color: var(--danger); color: #fff; }
.status-paid { background: var(--paid); border-color: var(--paid); color: #fff; }
.status-cancelled { text-decoration: line-through; }

.empty { background: var(--paper); border: 1px dashed var(--line); border-radius: var(--radius); padding: 40px; text-align: center; }
.empty p { margin: 0 0 16px; color: var(--muted); }

/* ---------- Buttons */
.btn {
  display: inline-block; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  padding: 8px 16px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--paper); color: var(--ink);
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(.92); }
.btn.paid { border-color: var(--paid); color: var(--paid); }
.btn.small { padding: 5px 12px; font-size: .9rem; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; text-decoration: underline; }
.danger { color: var(--danger) !important; }

/* ---------- Formulare */
.form fieldset { border: 0; margin: 0 0 20px; padding: 20px 22px 8px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.form legend { font-weight: 700; font-size: 1.05rem; padding: 0; float: left; width: 100%; margin-bottom: 4px; }
.form legend + * { clear: both; }
.legend-note { clear: both; margin: 0 0 12px; color: var(--muted); font-size: .9rem; max-width: 70ch; }
.grid { clear: both; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 16px; }
.span-2 { grid-column: span 2; } .span-3 { grid-column: span 3; } .span-4 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; margin-bottom: 14px; min-width: 0; }
.field label, .field .label { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.field small { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.field.check { justify-content: center; }
.field.check label { color: var(--ink); font-size: 1rem; display: flex; gap: 8px; align-items: center; }
.err, .field small.err { color: var(--danger); }
.has-error input, .has-error select { border-color: var(--danger); }
input, select, textarea {
  font: inherit; color: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 4px; background: #fff; width: 100%;
}
input[type=color] { padding: 2px; height: 38px; }
input[type=checkbox] { width: auto; accent-color: var(--brand); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
textarea { resize: vertical; }
.ref { padding: 7px 0; font-variant-numeric: tabular-nums; letter-spacing: .03em; }
.form-actions { display: flex; gap: 10px; }
.secondary-actions { display: flex; gap: 24px; margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); }
.secondary-actions form { margin: 0; }

/* Positionen */
.items th { font-size: .82rem; color: var(--muted); font-weight: 600; text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.items td { padding: 6px; vertical-align: top; border-bottom: 1px solid #EDF0EF; }
.items td[data-line] { padding-top: 13px; }
.items textarea { min-height: 38px; overflow: hidden; resize: none; }
.items input[data-f=quantity], .items input[data-f=unit_price] { text-align: right; }
.items [data-remove] { font-size: 1.3rem; line-height: 1; text-decoration: none; padding: 8px 4px; }
.w-desc { width: 44%; } .w-qty { width: 9%; } .w-unit { width: 9%; } .w-price { width: 12%; } .w-vat { width: 10%; } .w-line { width: 12%; }
.fieldset-note { color: var(--muted); }
[data-add-item] { margin: 12px 0 4px; }
.totals {
  display: grid; grid-template-columns: auto auto; justify-content: end; gap: 4px 28px;
  margin: 8px 0 14px; font-variant-numeric: tabular-nums;
}
.totals dt { color: var(--muted); text-align: right; }
.totals dd { margin: 0; text-align: right; min-width: 110px; }
.totals .grand { font-size: 1.3rem; font-weight: 700; color: var(--ink); padding-top: 6px; border-top: 2px solid var(--brand); }

/* Wer hat was gemacht */
.byline { width: 100%; margin: 4px 0 0; color: var(--muted); font-size: .88rem; }
.byline strong { color: var(--ink); font-weight: 600; }
td.by { font-size: .92rem; }
.history { margin-top: 28px; }
.history h2 { font-size: 1.05rem; margin: 0 0 10px; }
.history ol, .log-list { list-style: none; margin: 0; padding: 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); }
.history li, .log-list li {
  display: grid; grid-template-columns: 130px 120px 130px 1fr; gap: 12px; align-items: baseline;
  padding: 9px 14px; border-bottom: 1px solid #EDF0EF; font-size: .92rem;
}
.history li:last-child, .log-list li:last-child { border-bottom: 0; }
.history time, .log-list time { color: var(--muted); font-variant-numeric: tabular-nums; }
.who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.what { font-weight: 600; }
.log-created { color: var(--paid); } .log-deleted { color: var(--danger); } .log-status { color: var(--brand); }
.details { color: var(--ink); }
.log-list .inv { grid-column: 4; }
.log-filter { display: flex; gap: 8px; align-items: center; }
.log-filter select { width: auto; }
@media (max-width: 820px) {
  .history li, .log-list li { grid-template-columns: 1fr 1fr; }
  .history .details, .log-list .details { grid-column: 1 / -1; }
}

/* Anmeldung */
.logo-field { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.logo-preview { width: 180px; height: 70px; border: 1px dashed var(--line); border-radius: 4px; display: grid; place-items: center; padding: 6px; }
.logo-preview img { max-width: 100%; max-height: 100%; }
.logo-field .field { flex: 1; min-width: 220px; }
.field .check-inline { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: var(--ink); font-size: .95rem; }
input[type=file] { padding: 5px; }
.login { width: 100%; max-width: 380px; background: var(--paper); padding: 32px; border-radius: var(--radius); border-top: 4px solid var(--brand); }
.login h1 { margin-bottom: 12px; }
.login .btn { width: 100%; margin-top: 6px; }

/* ---------- Schmale Bildschirme */
@media (max-width: 820px) {
  body { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: stretch; }
  .tenant { width: 100%; min-height: 0; padding: 14px 18px; }
  .side nav { flex-direction: row; padding: 6px; }
  .side nav a { border-left: 0; border-bottom: 3px solid transparent; }
  .side nav a.on { border-bottom-color: var(--brand); }
  .nav-group { display: none; }
  .me { margin: 0 0 0 auto; border-top: 0; padding: 14px 16px; }
  .main { padding: 20px 16px 48px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-3 { grid-column: 1 / -1; }
  .search input { width: 100%; }
}

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