:root {
  --bg: #14121a;
  --panel: #1e1b26;
  --panel2: #272332;
  --line: #3a3448;
  --text: #e9e6ef;
  --dim: #a098b0;
  --accent: #c4a7e7;
  --warn: #f2a03d;
  --bad: #e8604c;
  --ok: #7fd18a;
  --radius: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Kopfleiste ─────────────────────────────────────────────────────────── */
.top {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .75rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.logo { font-weight: 700; letter-spacing: .02em; color: var(--text); }
.top nav { display: flex; gap: .25rem; flex-wrap: wrap; }
.top nav a {
  padding: .35rem .7rem; border-radius: var(--radius);
  color: var(--dim); font-size: 14px;
}
.top nav a:hover { background: var(--panel2); text-decoration: none; color: var(--text); }
.top nav a.on { background: var(--accent); color: #191524; font-weight: 600; }

main { padding: 1.25rem; max-width: 1400px; margin: 0 auto; }

/* ── Bausteine ──────────────────────────────────────────────────────────── */
h1 { font-size: 1.35rem; margin: 0 0 1rem; font-weight: 650; }
h2 { font-size: 1.05rem; margin: 1.75rem 0 .6rem; font-weight: 600; }
h3 { font-size: .95rem; margin: 1.1rem 0 .4rem; font-weight: 600; color: var(--dim); }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem;
}
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 160px; }
.row .narrow { flex: 0 1 110px; }
.row .wide { flex: 3 1 320px; }
.bar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.spacer { flex: 1; }
.dim { color: var(--dim); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ── Formulare ──────────────────────────────────────────────────────────── */
label { display: block; font-size: 12px; color: var(--dim); margin-bottom: .2rem; }
input, select, textarea, button {
  font: inherit; color: var(--text);
  background: var(--panel2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .4rem .55rem; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; min-height: 4.5em; line-height: 1.35; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[readonly] { color: var(--dim); }

button, .btn {
  background: var(--panel2); border: 1px solid var(--line); cursor: pointer;
  padding: .4rem .8rem; width: auto; white-space: nowrap; display: inline-block;
  color: var(--text); border-radius: var(--radius); font-size: 14px;
}
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); color: #191524; border-color: var(--accent); font-weight: 600; }
.btn-danger:hover { border-color: var(--bad); color: var(--bad); }
.btn-sm { padding: .2rem .5rem; font-size: 13px; }

/* ── Tabellen ───────────────────────────────────────────────────────────── */
table { width: 100%; border-collapse: collapse; }
th, td { padding: .45rem .5rem; text-align: left; vertical-align: top; }
thead th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--dim); border-bottom: 1px solid var(--line); font-weight: 600;
}
tbody tr { border-bottom: 1px solid var(--line); }
tbody tr:hover { background: var(--panel2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Hinweise ───────────────────────────────────────────────────────────── */
.flash {
  background: var(--accent); color: #191524; padding: .6rem 1.25rem;
  font-size: 14px; font-weight: 500;
}
.tag {
  display: inline-block; font-size: 11px; padding: .1rem .4rem; border-radius: 3px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--dim);
  margin-right: .2rem;
}
.tag.on { background: var(--accent); color: #191524; border-color: var(--accent); }
.pill { font-size: 11px; padding: .12rem .45rem; border-radius: 999px; border: 1px solid var(--line); }
.pill.entwurf { color: var(--dim); }
.pill.offen { color: var(--warn); border-color: var(--warn); }
.pill.angenommen { color: var(--ok); border-color: var(--ok); }
.pill.abgelehnt, .pill.storniert { color: var(--bad); border-color: var(--bad); }
.hint { font-size: 12px; color: var(--dim); margin-top: .3rem; }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.ok { color: var(--ok); }

/* ── Login ──────────────────────────────────────────────────────────────── */
.login { max-width: 340px; margin: 18vh auto; }
.login h1 { text-align: center; }

/* ── Beleg-Editor ───────────────────────────────────────────────────────── */
.lines td { padding: .3rem .35rem; }
.lines input, .lines select, .lines textarea { padding: .25rem .4rem; font-size: 14px; }
.lines .drag { cursor: grab; color: var(--dim); user-select: none; width: 1.4rem; text-align: center; }
.lines tr.dragging { opacity: .4; }
.lines .overridden input.price { border-color: var(--warn); color: var(--warn); }
.totals { max-width: 420px; margin-left: auto; }
.totals td { padding: .3rem .4rem; }
.totals tr.grand td { font-size: 1.15rem; font-weight: 700; border-top: 1px solid var(--line); padding-top: .6rem; }
.sticky-bar {
  position: sticky; bottom: .5rem; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 -4px 16px rgba(0,0,0,.35);
  padding: .6rem 1rem; margin: 1rem 0; display: flex; gap: .5rem;
  align-items: center; flex-wrap: wrap; z-index: 10;
}

details > summary { cursor: pointer; color: var(--dim); font-size: 13px; padding: .2rem 0; }
details[open] > summary { color: var(--text); }

@media (max-width: 760px) {
  main { padding: .75rem; }
  table.responsive thead { display: none; }
  table.responsive tbody tr { display: block; padding: .5rem 0; }
  table.responsive td { display: block; padding: .2rem .3rem; }
}

/* Hinweisleiste blendet sich aus */
.flash { transition: opacity .55s ease, max-height .55s ease; max-height: 5rem; cursor: pointer; }
.flash.fade { opacity: 0; max-height: 0; padding-top: 0; padding-bottom: 0; }

/* Zuordnungen je Zeile nur bei Bedarf */
.inline-tags > summary { font-size: 11px; color: var(--dim); list-style: none; }
.inline-tags > summary::-webkit-details-marker { display: none; }
.inline-tags > summary::before { content: '# '; }
.inline-tags[open] > summary { color: var(--text); }

/* Zustand der Hintergrundspeicherung */
#autosave { min-width: 13rem; }

/* Häkchen im Raster, Spalten bündig */
.tag-grid { display: grid; grid-template-columns: repeat(2, max-content); column-gap: 1rem; row-gap: .15rem; margin-top: .35rem; }
.tag-grid label { display: flex; align-items: center; gap: .35rem; margin: 0; color: var(--text); font-size: 13px; }

/* ── Heller Modus ─────────────────────────────────────────────────────── */
body.theme-light {
  --bg: #f4f2f7;
  --panel: #ffffff;
  --panel2: #f0edf5;
  --line: #dcd6e5;
  --text: #1e1a27;
  --dim: #6b6479;
  --warn: #b5650d;
  --bad: #c0392b;
  --ok: #2e8540;
}
/* Akzent als Text ist auf Hell zu blass — Links und Hervorhebungen dunkler */
body.theme-light a { color: #1e1a27; text-decoration: underline; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: 2px; }
body.theme-light a.btn, body.theme-light .top nav a { text-decoration: none; }
body.theme-light .top nav a.on, body.theme-light .btn-primary, body.theme-light .flash, body.theme-light .tag.on { color: #1e1a27; }
body.theme-light .sticky-bar { box-shadow: 0 -4px 16px rgba(40,30,60,.10); }
body.theme-light input:focus, body.theme-light select:focus, body.theme-light textarea:focus { outline-color: var(--accent); }

/* Farbfelder in den Einstellungen */
.swatches { display: flex; gap: .5rem; flex-wrap: wrap; }
.swatch { display: flex; align-items: center; gap: .4rem; padding: .35rem .6rem; border: 1px solid var(--line);
          border-radius: var(--radius); cursor: pointer; font-size: 13px; color: var(--text); }
.swatch input { width: auto; }
.swatch i { display: inline-block; width: 1.1rem; height: 1.1rem; border-radius: 50%; border: 1px solid rgba(0,0,0,.2); }

/* Unterbaustein im Editor */
.lines td.is-sub { padding-left: 1.8rem; border-left: 2px solid var(--accent); }
.lines td.is-sub input[name$="[title]"] { font-weight: 400; }
.lines td:not(.is-sub) input[name$="[title]"] { font-weight: 600; }
.subtoggle { display: inline-flex; align-items: center; gap: .3rem; font-size: 11px; color: var(--dim); margin: 0 0 .2rem; cursor: pointer; }
.subtoggle input { width: auto; }
