/* Belegbucher-Webapp - Farbschema wie Android-App (GeMax-Orange + Petrol) */
:root {
  --orange: #f39200;
  --orange-strong: #c97700;
  --orange-soft: #ffe0b2;
  --petrol: #0b5d5a;
  --petrol-soft: #cdeae6;
  --bg: #f6f7f6;
  --surface: #ffffff;
  --surface-2: #f0f1ef;
  --text: #1a1c1c;
  --muted: #5f6866;
  --border: #dfe2df;
  --ok: #2e7d32;
  --ok-soft: #e3f2e4;
  --warn: #9a5b00;
  --warn-soft: #fff1d6;
  --err: #ba1a1a;
  --err-soft: #fde7e7;
  --info: #1f5f9e;
  --info-soft: #e3eefa;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 14px rgba(0, 0, 0, 0.05);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --orange: #ffab40;
    --orange-strong: #ffc274;
    --orange-soft: #4a3310;
    --petrol: #8fd6cf;
    --petrol-soft: #16403d;
    --bg: #121414;
    --surface: #1b1e1e;
    --surface-2: #242828;
    --text: #e6e9e8;
    --muted: #a1aaa8;
    --border: #333938;
    --ok: #7bc47f;
    --ok-soft: #1c3320;
    --warn: #ffc56b;
    --warn-soft: #3a2b10;
    --err: #ff8a80;
    --err-soft: #3d1a1a;
    --info: #8ab8ea;
    --info-soft: #172a3d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--petrol); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 13px; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.25; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

/* ---------- Header ---------- */
header.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; white-space: nowrap; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 7px; background: var(--petrol);
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px;
  box-shadow: inset 0 -4px 0 var(--orange);
}
.brand small { color: var(--muted); font-weight: 400; }
nav.tabs { display: flex; gap: 2px; overflow-x: auto; }
nav.tabs button {
  border: 0; background: none; padding: 17px 12px 15px; cursor: pointer; color: var(--muted);
  border-bottom: 3px solid transparent; white-space: nowrap;
}
nav.tabs button:hover { color: var(--text); }
nav.tabs button.active { color: var(--text); border-bottom-color: var(--orange); font-weight: 600; }
nav.tabs .sep { width: 1px; background: var(--border); margin: 14px 6px; }
.usermenu { position: relative; }
.usermenu > button { border: 1px solid var(--border); background: var(--surface); border-radius: 20px; padding: 5px 12px; cursor: pointer; white-space: nowrap; }
.usermenu .menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 6px;
}
.usermenu .menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.usermenu .menu button:hover { background: var(--surface-2); }

@media (max-width: 760px) {
  header.topbar { flex-wrap: wrap; height: auto; padding: 8px 16px 0; gap: 8px; }
  nav.tabs { order: 3; width: 100%; }
  nav.tabs button { padding: 10px 10px 9px; }
  .usermenu > button { max-width: 60vw; overflow: hidden; text-overflow: ellipsis; }
}
main { max-width: 1280px; margin: 0 auto; padding: 22px 20px 60px; }

/* ---------- Karten, Buttons, Formulare ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); padding: 7px 14px; border-radius: 7px; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #1a1100; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--orange-strong); border-color: var(--orange-strong); }
.btn.secondary { background: var(--petrol); border-color: var(--petrol); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.secondary { color: #0b1b1a; } }
.btn.danger { color: var(--err); border-color: var(--err); background: transparent; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.link { border: 0; background: none; padding: 0; color: var(--petrol); text-decoration: underline; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="password"], input[type="number"], input[type="search"], input[type="url"], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface);
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--orange); outline-offset: 1px; }
textarea { resize: vertical; min-height: 38px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
@media (max-width: 800px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.hint { font-size: 13px; color: var(--muted); margin: 4px 0 0; }
.checkbox { display: flex; gap: 8px; align-items: center; cursor: pointer; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.alert.err { background: var(--err-soft); border-color: var(--err); color: var(--err); }
.alert.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.alert.ok { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.alert.info { background: var(--info-soft); border-color: var(--info); color: var(--info); }
.alert pre { white-space: pre-wrap; word-break: break-word; margin: 6px 0 0; font-size: 12px; color: var(--text); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { justify-content: center; margin-bottom: 18px; font-size: 18px; }

/* ---------- Drop-Zone ---------- */
.dropzone {
  border: 2px dashed var(--border); border-radius: 14px; padding: 34px 20px; text-align: center;
  background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--orange); background: var(--orange-soft); }
.dropzone .big { font-size: 18px; font-weight: 600; margin: 8px 0 4px; }
.dropzone svg { width: 46px; height: 46px; color: var(--orange); }
.drop-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(11, 93, 90, 0.82); color: #fff;
  display: grid; place-items: center; font-size: 26px; font-weight: 600; pointer-events: none;
}
.drop-overlay div { border: 3px dashed #fff; border-radius: 20px; padding: 60px 80px; }

/* ---------- Staging (vor dem Senden) ---------- */
.staged { display: grid; gap: 10px; margin-top: 14px; }
.staged-item {
  display: grid; grid-template-columns: 72px 1fr; gap: 14px; align-items: start;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; background: var(--surface);
}
.staged-item .preview { width: 72px; height: 92px; border-radius: 6px; background: var(--surface-2); display: grid; place-items: center; overflow: hidden; border: 1px solid var(--border); }
.staged-item .preview img { width: 100%; height: 100%; object-fit: cover; }
.staged-item .fields { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; align-items: end; }
@media (max-width: 900px) { .staged-item .fields { grid-template-columns: 1fr; } }
.staged-item .name { font-weight: 600; word-break: break-all; }
.staged-item .state { font-size: 13px; }
.defaults { background: var(--surface-2); border-radius: var(--radius); padding: 12px; margin-top: 14px; }
.defaults .fields { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 8px; align-items: end; }
@media (max-width: 900px) { .defaults .fields { grid-template-columns: 1fr; } }
.pdf-icon { font-weight: 700; color: var(--err); font-size: 13px; border: 2px solid var(--err); border-radius: 4px; padding: 2px 5px; }

/* ---------- Combobox ---------- */
.combo { position: relative; }
.combo input { padding-right: 28px; }
.combo .clear { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; padding: 2px 4px; }
.combo ul {
  position: absolute; left: 0; right: 0; top: calc(100% + 2px); z-index: 30; max-height: 260px; overflow: auto;
  margin: 0; padding: 4px; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow);
}
.combo li { padding: 6px 8px; border-radius: 5px; cursor: pointer; }
.combo li.active, .combo li:hover { background: var(--orange-soft); }
.combo li small { color: var(--muted); margin-left: 6px; }
.combo li.empty { color: var(--muted); cursor: default; background: none; }

/* ---------- Belegliste ---------- */
.filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 20px; padding: 4px 12px; cursor: pointer; font-size: 13px; }
.chip.active { background: var(--petrol); color: #fff; border-color: var(--petrol); }
@media (prefers-color-scheme: dark) { .chip.active { color: #0b1b1a; } }
.chip .count { opacity: .75; margin-left: 4px; }

table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--border); }
table.list td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: var(--surface-2); }
.thumb { width: 44px; height: 56px; border-radius: 5px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); display: block; }
.thumb.placeholder { display: grid; place-items: center; font-size: 11px; color: var(--muted); }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.table-wrap { overflow-x: auto; }
@media (max-width: 760px) { .hide-sm { display: none; } }

.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 20px; padding: 2px 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.queued, .badge.processing { background: var(--info-soft); color: var(--info); }
.badge.processed { background: var(--ok-soft); color: var(--ok); }
.badge.needs_assignment { background: var(--warn-soft); color: var(--warn); }
.badge.failed { background: var(--err-soft); color: var(--err); }
.badge.discarded { background: var(--surface-2); color: var(--muted); }
.badge.processing::before { content: ""; width: 8px; height: 8px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; margin-left: 4px; }

.pager { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 10px; }

/* ---------- Detail-Drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(980px, 100vw); z-index: 51;
  background: var(--bg); box-shadow: -4px 0 24px rgba(0,0,0,.2); display: flex; flex-direction: column;
}
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 14px 18px; background: var(--surface); border-bottom: 1px solid var(--border); }
.drawer-head h3 { margin: 0; word-break: break-all; }
.drawer-body { flex: 1; overflow: auto; padding: 18px; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 18px; }
@media (max-width: 900px) { .drawer-body { grid-template-columns: 1fr; } }
.viewer { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-height: 480px; overflow: hidden; }
.viewer img { width: 100%; display: block; }
.viewer iframe { width: 100%; height: 75vh; border: 0; display: block; }
dl.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 13px; }
dl.kv dd { margin: 0; word-break: break-word; }
ol.steps { list-style: none; padding: 0; margin: 0; }
ol.steps li { display: grid; grid-template-columns: 18px 1fr auto; gap: 8px; padding: 4px 0; font-size: 13px; }
ol.steps li .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); margin-top: 5px; }
ol.steps li.bad .dot { background: var(--err); }

/* ---------- Admin ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 900px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .v { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 13px; }
.secret-state { font-size: 12px; margin-left: 6px; }
.token-box { background: var(--surface-2); border: 1px dashed var(--orange); border-radius: 8px; padding: 10px; word-break: break-all; }
details.ref summary { cursor: pointer; color: var(--petrol); }
details.ref pre { white-space: pre-wrap; background: var(--surface-2); padding: 10px; border-radius: 8px; font-size: 12px; }
.settings-nav { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 460px; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: grid; gap: 8px; max-width: 420px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; }
.toast.err { background: var(--err); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

@media (max-width: 760px) { main { padding: 16px 16px 60px; } .card { padding: 14px; } }
