/* Dashboard des eBay-Repricers.
   Dieselbe Farb- und Schriftwelt wie das Architekturdokument, damit Spezifikation
   und Produkt zusammengehoeren. Kein Framework, kein Bauschritt. */

:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-2: #ebefea;
  --ink: #15201b;
  --ink-2: #3d4a44;
  --muted: #6b7a73;
  --rule: #d6ded7;
  --accent: #1c6b54;
  --accent-ink: #0f4536;
  --accent-soft: #e0eee7;
  --danger: #a8372a;
  --danger-soft: #f7e4e1;
  --warn: #8a6410;
  --warn-soft: #f6edd9;
  --info: #2b5a7a;
  --info-soft: #e2edf4;
  --shadow: 0 1px 2px rgba(21, 32, 27, .05), 0 8px 24px -18px rgba(21, 32, 27, .3);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1412;
    --surface: #151d1a;
    --surface-2: #1c2622;
    --ink: #e6ede8;
    --ink-2: #c1cdc6;
    --muted: #8d9e96;
    --rule: #26332e;
    --accent: #5fc7a2;
    --accent-ink: #93dec2;
    --accent-soft: #17302a;
    --danger: #e9866f;
    --danger-soft: #37201c;
    --warn: #d9ae5a;
    --warn-soft: #312716;
    --info: #8ec2e0;
    --info-soft: #16262f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -18px rgba(0, 0, 0, .8);
  }
}

:root[data-theme="dark"] {
  --bg: #0e1412;
  --surface: #151d1a;
  --surface-2: #1c2622;
  --ink: #e6ede8;
  --ink-2: #c1cdc6;
  --muted: #8d9e96;
  --rule: #26332e;
  --accent: #5fc7a2;
  --accent-ink: #93dec2;
  --accent-soft: #17302a;
  --danger: #e9866f;
  --danger-soft: #37201c;
  --warn: #d9ae5a;
  --warn-soft: #312716;
  --info: #8ec2e0;
  --info-soft: #16262f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -18px rgba(0, 0, 0, .8);
}

* { box-sizing: border-box; }

/* Das hidden-Attribut muss auch dann greifen, wenn eine ID-Regel ein display
   setzt - sonst bleibt die Anmeldemaske hinter dem Dashboard sichtbar. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Archivo, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

code, .mono, input[type="text"].mono {
  font-family: "IBM Plex Mono", ui-monospace, Menlo, monospace;
}

a { color: var(--accent-ink); text-underline-offset: 2px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

h1, h2, h3 { margin: 0; letter-spacing: -.015em; text-wrap: balance; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
p { margin: 8px 0 0; max-width: 68ch; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Grundgeruest ---------- */

#shell { display: grid; grid-template-rows: auto 1fr; min-height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--surface);
  border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 20;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 8px; font-weight: 700; letter-spacing: -.02em; }
.brand .v { font-size: 11px; font-weight: 500; color: var(--muted); }
.topbar .spacer { flex: 1 1 auto; }
.mode-chips { display: flex; gap: 6px; flex-wrap: wrap; }

.layout { display: grid; grid-template-columns: 1fr; }
@media (min-width: 900px) { .layout { grid-template-columns: 208px minmax(0, 1fr); } }

nav.side { border-right: 1px solid var(--rule); background: var(--surface); padding: 14px 10px; }
@media (min-width: 900px) { nav.side { min-height: calc(100vh - 53px); } }
nav.side ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 4px; flex-wrap: wrap; }
@media (min-width: 900px) { nav.side ul { flex-direction: column; } }
nav.side a {
  display: block; padding: 7px 12px; border-radius: 7px; text-decoration: none;
  color: var(--ink-2); font-size: 14px; font-weight: 500;
}
nav.side a:hover { background: var(--surface-2); color: var(--ink); }
nav.side a.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

main { padding: 22px 20px 80px; min-width: 0; }
.view { max-width: 1080px; display: flex; flex-direction: column; gap: 22px; }
.view-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.view-head .spacer { flex: 1 1 auto; }

/* ---------- Bausteine ---------- */

.card {
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card > header {
  padding: 14px 18px; border-bottom: 1px solid var(--rule);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.card > header .spacer { flex: 1 1 auto; }
.card > .body { padding: 18px; }
.card > .body > :first-child { margin-top: 0; }

.banner {
  border-left: 3px solid var(--accent); background: var(--accent-soft);
  padding: 14px 18px; border-radius: 0 var(--radius) var(--radius) 0;
}
.banner.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.banner.danger { border-left-color: var(--danger); background: var(--danger-soft); }
.banner.info { border-left-color: var(--info); background: var(--info-soft); }
.banner strong { display: block; margin-bottom: 2px; }
.banner p { margin: 4px 0 0; font-size: 14px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600; letter-spacing: .04em;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2);
}
.chip.ok { background: var(--accent-soft); color: var(--accent-ink); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

button, .btn {
  font: inherit; font-weight: 600; font-size: 14px;
  padding: 7px 14px; border-radius: 7px; border: 1px solid var(--rule);
  background: var(--surface); color: var(--ink); cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { background: var(--surface-2); }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] button.primary, :root[data-theme="dark"] .btn.primary,
:root:not([data-theme="light"]) button.primary { color: #06120e; }
button.primary:hover, .btn.primary:hover { filter: brightness(1.06); }
button.danger, .btn.danger { border-color: var(--danger); color: var(--danger); }
button.danger:hover, .btn.danger:hover { background: var(--danger-soft); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--surface-2); }
button.small { padding: 4px 9px; font-size: 12.5px; }
button[disabled] { opacity: .5; cursor: not-allowed; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea {
  font: inherit; font-size: 14px; padding: 6px 9px; border-radius: 6px;
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink);
  width: 100%; font-variant-numeric: tabular-nums;
}
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.row { display: grid; gap: 14px; }
/* Knopfleiste: nebeneinander, umbrechend auf schmalen Anzeigen. */
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0 4px; }
@media (min-width: 640px) { .row.two { grid-template-columns: 1fr 1fr; } }
@media (min-width: 860px) { .row.three { grid-template-columns: repeat(3, 1fr); } }

.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 14px; font-weight: 500; }
.switch input { width: auto; margin: 0; accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- Tabellen ---------- */

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
thead th {
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); background: var(--surface-2); white-space: nowrap; position: sticky; top: 0;
}
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--ink); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-family: "IBM Plex Mono", monospace; white-space: nowrap; }
td.na { color: var(--muted); }

/* ---------- Kennzahlen ---------- */

.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.kpi {
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 14px 16px; text-align: left; cursor: pointer; box-shadow: var(--shadow);
}
.kpi:hover { border-color: var(--accent); }
.kpi .n { font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.kpi .l { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kpi.alarm .n { color: var(--danger); }
.kpi.attention .n { color: var(--warn); }

/* ---------- Kosteneditor ---------- */

.cost-row td { padding: 10px 12px; }
.cost-row input { max-width: 130px; }
.cost-row .pair { display: flex; align-items: center; gap: 8px; }
.cost-row .pair span { font-size: 12px; color: var(--muted); }
.entered-mark { font-size: 11px; color: var(--accent-ink); font-weight: 600; }

/* ---------- Margenmodelle ---------- */

.models { display: grid; gap: 14px; }
@media (min-width: 860px) { .models { grid-template-columns: repeat(3, 1fr); } }
.model {
  border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px;
  background: var(--surface); display: flex; flex-direction: column; gap: 10px;
}
.model.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.model .formula {
  font-family: "IBM Plex Mono", monospace; font-size: 12.5px; color: var(--ink-2);
  background: var(--surface-2); padding: 8px 10px; border-radius: 6px;
}
.model .result { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.model .result.err { font-size: 13px; font-weight: 500; color: var(--danger); }
.model footer { margin-top: auto; }

/* ---------- Rechnung ---------- */

.breakdown td:first-child { color: var(--ink-2); }
.breakdown tr.sum td { font-weight: 700; border-top: 2px solid var(--rule); }
.breakdown tr.minus td.num::before { content: "− "; color: var(--muted); }

/* ---------- Anmeldung ---------- */

#login-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
#login-screen .card { width: 100%; max-width: 380px; }

/* ---------- Meldungen ---------- */

#toasts {
  position: fixed; right: 18px; bottom: 18px; z-index: 60;
  display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 36px));
}
.toast {
  background: var(--surface); border: 1px solid var(--rule); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 10px 14px; box-shadow: var(--shadow); font-size: 14px;
}
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }

.demo-banner {
  background: var(--warn-soft); color: var(--warn); text-align: center;
  padding: 6px 12px; font-size: 13px; font-weight: 600;
}

.loading { color: var(--muted); padding: 24px 0; }
.empty { color: var(--muted); padding: 28px 12px; text-align: center; }

details.history summary { cursor: pointer; font-size: 13px; color: var(--muted); font-weight: 600; }
details.history[open] summary { margin-bottom: 8px; }

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: slide-in .18s ease-out; }
  @keyframes slide-in { from { opacity: 0; transform: translateY(6px); } }
}
