:root {
  --bg: #14171a;
  --panel: #1d2226;
  --panel-2: #262c31;
  --line: #333b42;
  --text: #e8ecef;
  --muted: #97a3ad;
  --accent: #5fbf6b;
  --accent-ink: #0d1f10;
  --warn: #e0a84a;
  --danger: #e2685f;
  --radius: 8px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f1;
    --panel: #ffffff;
    --panel-2: #eceee9;
    --line: #d6dad2;
    --text: #1b2023;
    --muted: #5f6b73;
    --accent: #2f8f3e;
    --accent-ink: #ffffff;
    --warn: #a86a00;
    --danger: #c0392f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* Layout */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.topbar nav { display: flex; gap: 14px; flex: 1; }
.topbar .who { display: flex; align-items: center; gap: 10px; }
main { max-width: 1150px; margin: 0 auto; padding: 20px 16px 60px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 16px; }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}

/* Formulare */
input, textarea, select, button { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=search], textarea, select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 10px; width: 100%;
}
textarea { min-height: 150px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 0.8rem; white-space: pre; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.field { flex: 1; min-width: 180px; }

button {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 12px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--danger); }
button.tiny { padding: 3px 8px; font-size: 0.8rem; }
button.active { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: 0.5; cursor: default; }

/* Login */
.login { max-width: 340px; margin: 12vh auto 0; }
.login h1 { margin-bottom: 16px; }
.error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; }

/* Listenkarten */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card { display: block; color: inherit; }
.card:hover { text-decoration: none; border-color: var(--muted); }
.card h3 { margin: 0 0 4px; font-size: 1.05rem; overflow-wrap: anywhere; }
.card .bar { margin: 10px 0 4px; }

.bar { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; min-width: 70px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.partial > i { background: var(--warn); }

.chip {
  display: inline-block; padding: 1px 8px; border-radius: 99px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 0.8rem; margin: 1px 4px 1px 0;
}
.chip.me { border-color: var(--accent); color: var(--accent); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.tabs button { border: 0; background: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 14px; color: var(--muted); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

/* Tabellen */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 0.8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
th.num { text-align: right; }
th button.sort {
  background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer;
}
th button.sort:hover, th button.sort.active { color: var(--text); }
th button.sort .arrow { margin-left: 4px; opacity: 0.45; }
th button.sort.active .arrow { opacity: 1; color: var(--accent); }
tr.done td { opacity: 0.55; }
tr.done td.item::before { content: "✓ "; color: var(--accent); }
td.item { font-weight: 600; }
tr.ignored td.item { opacity: 0.55; text-decoration: line-through; }
tr.ignored .icon { filter: grayscale(1); }
td.add { white-space: nowrap; text-align: right; }
.name { display: inline-flex; align-items: center; gap: 8px; }
.icon { width: 28px; height: 28px; flex: none; object-fit: contain; image-rendering: pixelated; }
.sub { display: block; font-size: 0.75rem; color: var(--muted); font-weight: 400; }
.minus { color: var(--danger); }
[data-tip] { cursor: help; }

/* Namen als Knopf (öffnet das Rezept) */
button.link {
  background: none; border: 0; padding: 0; font-weight: inherit; color: inherit;
  text-align: left; white-space: normal; text-decoration: underline dotted; text-underline-offset: 3px;
}
button.link:hover { color: var(--accent); }
a.chip { color: inherit; }
a.chip:hover { border-color: var(--accent); text-decoration: none; }
section h2 { margin: 0; }
section h2 a { color: inherit; }
main > h2 { margin: 28px 0 0; }
select { cursor: pointer; }

/* Rezept-Baum */
dialog.wide { width: min(560px, calc(100vw - 32px)); }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { margin-left: 13px; padding-left: 14px; border-left: 1px solid var(--line); }
.tree li { padding-top: 8px; }
.rnode { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.rline { margin: 2px 0 0 36px; }

.logfilter select { width: auto; }
.qty { width: 110px; }
button.missing { margin: 0 6px 6px 0; }

/* Wiki-Links */
a.wiki { color: inherit; text-decoration: underline dotted; text-underline-offset: 3px; }
a.wiki:hover { color: var(--accent); }
button.link.plain, a.wiki.plain { text-decoration: none; }
a.btn {
  display: inline-block; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 12px; color: inherit; white-space: nowrap;
}
a.btn:hover { border-color: var(--muted); text-decoration: none; }
.chip .role { color: var(--muted); }

/* Verlauf */
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .curve { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); opacity: 0.12; }
.chart .dot { fill: var(--accent); stroke: var(--panel); stroke-width: 2; }
.chart .hit { fill: var(--text); opacity: 0; cursor: default; }
.chart .hit:hover { opacity: 0.06; }
.share { height: 8px; min-width: 120px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.share > i { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.sharecell { width: 30%; }

/* Rezept-Baum (alle Rezepte) */
.graph-wrap { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.graph { display: block; width: 100%; height: 72vh; cursor: grab; touch-action: none; user-select: none; }
.graph:active { cursor: grabbing; }
.graph .edges path { fill: none; stroke: var(--muted); stroke-width: 1; opacity: 0.28; }
.graph .node { cursor: pointer; }
.graph .node rect { fill: var(--panel-2); stroke: var(--line); stroke-width: 1; }
.graph .node.raw rect { fill: var(--bg); }
.graph .node text { fill: var(--text); font-size: 12px; pointer-events: none; }
.graph .node:hover rect { stroke: var(--text); }
.graph.has-sel .node { opacity: 0.22; }
.graph.has-sel .edges path { opacity: 0.06; }
.graph.has-sel .node.sel, .graph.has-sel .node.up, .graph.has-sel .node.down { opacity: 1; }
.graph .node.sel rect { stroke: var(--text); stroke-width: 2; }
.graph .node.up rect { stroke: var(--accent); stroke-width: 2; }
.graph .node.down rect { stroke: var(--warn); stroke-width: 2; }
.graph.has-sel .edges path.up { stroke: var(--accent); stroke-width: 2; opacity: 0.9; }
.graph.has-sel .edges path.down { stroke: var(--warn); stroke-width: 2; opacity: 0.9; }

/* Team */
.team select { width: auto; padding: 3px 8px; }
.team { margin-top: 10px; }
.chip .x { border: 0; background: none; padding: 0 0 0 6px; color: var(--muted); line-height: 1; }
.chip .x:hover { color: var(--danger); }

/* Menü zum Eintragen */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; width: min(440px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog h2 { margin: 0; overflow-wrap: anywhere; }
dialog .error { margin: 0; }
.amounts .field { min-width: 90px; }
input[type=number] {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 10px; width: 100%;
}
.row.end { justify-content: flex-end; }

#tip {
  position: fixed; z-index: 10; left: 0; top: 0; visibility: hidden; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 4px 10px; border-radius: 6px;
  font-size: 0.85rem; white-space: nowrap;
}
#tip.show { visibility: visible; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 6px;
  opacity: 0; pointer-events: none; transition: opacity 0.2s; max-width: 90vw;
}
#toast.show { opacity: 1; }
#toast.bad { background: var(--danger); color: #fff; }

@media (max-width: 700px) {
  .hide-narrow { display: none; }
  th, td { padding: 6px; }
}

[hidden] { display: none !important; }
