:root {
  --bg: #202023;
  --panel: #2b2b30;
  --panel-alt: #35353b;
  --border: #43434a;
  --text: #ececed;
  --muted: #a3a3ab;
  --accent: #e8792c;
  --accent-dark: #c4611c;
  --danger: #b3413d;
  --radius: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header h1 { font-size: 1.2rem; margin: 0; }

#auth-box { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; color: var(--muted); }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
}
button:hover { background: var(--accent-dark); }
button.danger { background: var(--danger); }
button.secondary { background: #8b93a1; }

nav#tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: none;
  color: var(--muted);
  border-radius: 0;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid transparent;
}
.tab-btn:hover { background: none; color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 1.5rem; max-width: 1200px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-grid { display: grid; grid-template-columns: 320px 1fr; gap: 1.25rem; align-items: start; }
.panel-list-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.panel-list, .panel-detail {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

/* Nur das linke Item-Listen-Panel: bleibt beim Scrollen stehen, Liste scrollt für sich */
.panel-grid > .panel-list {
  position: sticky;
  top: 1rem;
  height: calc(100vh - 9rem);
  max-height: calc(100vh - 9rem);
  display: flex;
  flex-direction: column;
}
#item-list { overflow-y: auto; min-height: 0; }

.search-clear-wrap { position: relative; }
.search-clear-wrap input {
  width: 100%; padding: 0.4rem; padding-right: 1.9rem; box-sizing: border-box;
  border: 1px solid var(--border); border-radius: var(--radius);
}
.search-clear-btn {
  position: absolute; right: 0.35rem; top: 50%; transform: translateY(-50%);
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.4rem; height: 1.4rem; padding: 0;
  background: none; border: none; color: var(--muted); font-size: 1rem; line-height: 1;
  cursor: pointer; border-radius: 3px;
}
.search-clear-btn:hover { color: var(--text); background: var(--panel-alt); }
.search-clear-wrap input:placeholder-shown + .search-clear-btn { display: none; }

.list-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: var(--radius);
  cursor: pointer;
}
.list-row:hover { background: var(--bg); }
.list-row img { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; background: var(--panel-alt); }
.list-row .name { font-weight: 500; }
.list-row .tags { font-size: 0.75rem; color: var(--muted); }

.empty-hint { color: var(--muted); }

.tag-chip {
  display: inline-block;
  background: rgba(232, 121, 44, 0.16);
  color: var(--accent);
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  margin: 0.1rem;
}

table { width: 100%; border-collapse: collapse; margin: 0.5rem 0; }
.panel-list table { table-layout: fixed; }
.panel-list table th:first-child { width: 150px; }
th, td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 600; }

.price-box { display: flex; gap: 1rem; margin: 0.75rem 0; }
.price-card { flex: 1; background: var(--bg); border-radius: var(--radius); padding: 0.75rem; }
.price-card .label { font-size: 0.75rem; color: var(--muted); }
.price-card .value { font-size: 1.3rem; font-weight: 600; }

.inline-form { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.inline-form input { flex: 1; padding: 0.4rem; border: 1px solid var(--border); border-radius: var(--radius); }

.calc-form { display: flex; gap: 1rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1rem; }
.calc-form label { display: flex; flex-direction: column; font-size: 0.85rem; color: var(--muted); gap: 0.25rem; }
.calc-form select, .calc-form input { padding: 0.4rem; border: 1px solid var(--border); border-radius: var(--radius); }

.result-tree { list-style: none; padding-left: 1.25rem; border-left: 2px solid var(--border); }
.result-tree li { margin: 0.4rem 0; }
.result-node { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem 0.75rem; display: inline-block; }
.source-lokal { border-left: 4px solid #4a8f5c; }
.source-global { border-left: 4px solid #b58a2e; }
.source-craft { border-left: 4px solid var(--accent); }
.source-unavailable { border-left: 4px solid var(--danger); color: var(--danger); }

.admin-section {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1.5rem;
}
.admin-section h2 { margin-top: 0; }
.admin-section h3 { margin-bottom: 0.5rem; }
.two-col-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.tax-list-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tax-list-row > div { flex: 1; min-width: 240px; }

.full-bleed {
  width: 94vw;
  max-width: 1600px;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  box-sizing: border-box;
}

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: var(--panel); border-radius: var(--radius); padding: 1.5rem;
  width: 480px; max-width: 90vw; max-height: 85vh; overflow-y: auto;
}
.modal h3 { margin-top: 0; }
.modal label { display: block; margin-bottom: 0.75rem; font-size: 0.9rem; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 0.45rem; border: 1px solid var(--border); border-radius: var(--radius); margin-top: 0.25rem;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

.form-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.form-row > label { margin-bottom: 0.75rem; min-width: 0; }

.ingredient-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; align-items: center; }
.ingredient-row .combo { flex: 2; }
.ingredient-row input { flex: 1; }

.volume-field-wrap {
  display: flex; align-items: center; gap: 0.3rem;
  padding: 0.3rem 0.5rem;
  margin-left: 0.25rem;
  background: var(--panel-alt);
  border-left: 2px solid var(--border);
  border-radius: var(--radius);
  flex: 0 0 90px;
}
.volume-field-wrap input {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.3rem; background: var(--bg); color: var(--text);
}
.volume-field-wrap input[readonly] { opacity: 0.75; cursor: default; }

.craft-tree-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
}
.craft-tree-wrap svg { display: block; }
.tree-node text { user-select: none; }

.item-icon { object-fit: cover; border-radius: 4px; flex-shrink: 0; background: var(--panel-alt); }
.icon-placeholder {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 4px; color: #fff; font-weight: 700; flex-shrink: 0;
}

.offer-detail h4 { margin: 1.25rem 0 0.5rem; }
.offer-detail h4:first-child { margin-top: 0; }
.offer-status-select {
  padding: 0.3rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); font-size: 0.85rem; font-weight: 600;
}
.offer-positions-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 0.75rem; }

.stats-grid { display: flex; gap: 0.75rem; flex-wrap: nowrap; }
.stats-grid > div { flex: 1; min-width: 0; }
.offer-position-card {
  display: flex; align-items: center; gap: 0.6rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
}

.calc-todo-overlay {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 50%; overflow-y: auto;
  background: var(--panel);
  border-top: 2px solid var(--accent);
  box-shadow: 0 -4px 12px rgba(0,0,0,0.35);
  padding: 0.5rem;
  border-radius: 0 0 var(--radius) var(--radius);
}

.error-text { color: var(--danger); font-size: 0.85rem; margin-top: 0.5rem; }
.tag-checkboxes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.35rem 0.75rem;
  max-height: 260px;
  overflow-y: auto;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-sizing: border-box;
}
.tag-checkboxes label {
  display: flex; align-items: flex-start; gap: 0.3rem; font-weight: normal;
}
.tag-checkboxes label input[type="checkbox"] {
  width: 16px; height: 16px; min-width: 16px;
  margin: 0.15rem 0 0 0; padding: 0; flex-shrink: 0;
}

/* Durchsuchbare Auswahl ("Combo") */
.combo { position: relative; flex: 1; }
.combo-input { width: 100%; padding: 0.4rem; border: 1px solid var(--border); border-radius: var(--radius); }
.combo-portal-dropdown {
  position: fixed; z-index: 500;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-y: auto; box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}
.combo-option { padding: 0.4rem 0.6rem; cursor: pointer; font-size: 0.9rem; display: flex; align-items: center; gap: 0.4rem; }
.combo-option:hover { background: var(--bg); }
.combo-option.combo-empty { color: var(--muted); cursor: default; }
.combo-option.combo-empty:hover { background: none; }

.combo-clearable .combo-input { padding-right: 1.9rem; }
.combo-clearable .combo-input:placeholder-shown + .combo-clear-btn { display: none; }

/* Fehlende-Daten-Indikator */
.missing-flag {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; min-width: 16px; border-radius: 50%;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  margin-right: 0.4rem; cursor: help;
}

/* Breites Modal für Tabellen-Ansichten */
.modal.modal-wide { width: 900px; max-width: 95vw; }

/* Bulk-Bearbeitung */
.bulk-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.bulk-toolbar input { flex: 1; min-width: 200px; padding: 0.4rem; border: 1px solid var(--border); border-radius: var(--radius); }
.bulk-filters { display: flex; gap: 0.4rem; }
.bulk-filter-btn.active { background: var(--accent); color: #fff; }
.bulk-table-wrap { max-height: 60vh; overflow-y: auto; }
.bulk-icon { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; background: var(--panel-alt); }
#bulk-table .bulk-name { width: 100%; padding: 0.3rem; border: 1px solid var(--border); border-radius: var(--radius); }
#bulk-table .bulk-volume { width: 80px; padding: 0.3rem; border: 1px solid var(--border); border-radius: var(--radius); }

.icon-upload-row { display: flex; align-items: center; gap: 0.75rem; }
.icon-upload-row img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); background: var(--panel-alt); }
.icon-upload-row input[type="file"] { flex: 1; font-size: 0.85rem; }
