:root {
  --paper: #f6f4ee;
  --card: #ffffff;
  --soft: #faf8f2;
  --red: #eb3924;
  --ink: #1b1b1b;
  --line: #e7e2d5;
  --amber: #f5b301;
  --sbahn: #034ea2;
  --good: #1f7a3f;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  min-height: 100vh;
}
.muted { color: #666; }
.small { font-size: 11px; }

/* --- Auth --- */
.auth-bootstrap {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #666; background: var(--paper);
  z-index: 9999;
}
.auth-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper);
}
.auth-card {
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  box-shadow: 4px 4px 0 var(--ink);
  padding: 30px 34px;
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 14px;
}
.auth-card h1 {
  margin: 0; font-size: 22px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 1.2px;
}
.auth-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: #444; }
.auth-card input {
  padding: 10px 12px; font-size: 14px; font-family: inherit;
  border: 1.5px solid var(--ink); border-radius: 6px;
  background: var(--card); outline: none;
}
.auth-card input:focus { background: #fffef5; box-shadow: 2px 2px 0 var(--ink); }
.auth-submit {
  background: var(--ink) !important; color: #fff !important;
  padding: 11px 14px; font-weight: 700; font-size: 13px;
  text-transform: uppercase; letter-spacing: 0.8px;
  border: 1.5px solid var(--ink); border-radius: 6px;
  box-shadow: 2px 2px 0 var(--amber);
  cursor: pointer; margin-top: 6px;
}
.auth-submit:hover:not(:disabled) {
  transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--amber);
}
.auth-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.auth-err {
  margin: 4px 0 0; padding: 8px 10px;
  background: #ffe5e0; color: #a82a17;
  border: 1.5px solid #f0a89a; border-radius: 6px;
  font-size: 12px;
}

/* --- Topbar --- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1.5px solid var(--ink);
}
.brand {
  font-size: 17px; font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.tabs { display: flex; gap: 4px; }
.tabs button {
  background: var(--card); color: var(--ink);
  border: 1.5px solid var(--ink); border-radius: 6px;
  padding: 6px 14px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.4px;
  cursor: pointer;
}
.tabs button:hover { background: #fff9e6; }
.tabs button.active {
  background: var(--ink); color: #fff;
  box-shadow: 2px 2px 0 var(--amber);
}
.tabs button .badge {
  background: var(--red); color: #fff;
  border-radius: 99px; padding: 0 6px; margin-left: 6px;
  font-size: 10px; font-weight: 700;
}
.topbar-info { flex: 1; font-size: 13px; }
.topbar-info b { color: var(--ink); }
.meta { display: flex; align-items: center; gap: 8px; }
.auth-userchip {
  font-size: 11px; font-weight: 600;
  padding: 4px 8px;
  border: 1px solid var(--ink);
  border-radius: 4px;
  background: var(--card);
}
.auth-logout {
  background: var(--card); border: 1px solid var(--ink);
  padding: 4px 9px; font-size: 13px;
  border-radius: 4px; cursor: pointer;
}
.auth-logout:hover { background: #ffeae5; }

/* --- Main Dashboard --- */
.main-dash {
  padding: 24px 28px;
  max-width: 1200px; margin: 0 auto;
}
.phase-banner {
  background: #fff9e6;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  box-shadow: 4px 4px 0 var(--ink);
  padding: 18px 22px;
  margin-bottom: 20px;
}
.phase-banner h1 { margin: 0 0 6px; font-size: 17px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; }
.phase-banner p { margin: 0; font-size: 13px; }

.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
.card {
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  box-shadow: 3px 3px 0 var(--ink);
  padding: 16px 18px;
}
.card h2 {
  margin: 0 0 12px;
  font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.6px;
}
.big-stat { font-size: 36px; font-weight: 800; line-height: 1; }
.big-stat .muted { font-size: 14px; font-weight: 400; }
.prod-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.prod-table th { text-align: left; border-bottom: 1.5px solid var(--ink); padding: 5px 4px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; }
.prod-table td { padding: 6px 4px; border-bottom: 1px dashed var(--line); }
.prod-table .num { text-align: right; font-variant-numeric: tabular-nums; }

.primary-btn {
  display: block; width: 100%;
  background: var(--ink) !important; color: #fff !important;
  padding: 10px 14px; font-weight: 700; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.6px;
  border: 1.5px solid var(--ink); border-radius: 6px;
  cursor: pointer;
  margin-bottom: 8px;
  box-shadow: 2px 2px 0 var(--amber);
}
.primary-btn:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--amber); }
.primary-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.dev-block {
  margin-top: 30px;
  padding: 10px;
  background: var(--soft);
  border: 1px dashed #aaa;
  border-radius: 6px;
  font-size: 11px;
}
.dev-block summary { cursor: pointer; font-weight: 600; color: #555; }
.dev-block pre { margin: 8px 0 0; font-family: 'Menlo', monospace; font-size: 10.5px; max-height: 240px; overflow: auto; }

/* --- Country block + große Produkt-Tabelle (Phase 2) --- */
.country-block {
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  box-shadow: 4px 4px 0 var(--ink);
  margin-bottom: 22px;
  overflow: hidden;
}
.country-head {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
  background: #fff9e6;
  border-bottom: 1.5px solid var(--ink);
}
.country-head h2 {
  margin: 0; flex: 1;
  font-size: 15px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.country-meta { display: flex; align-items: center; gap: 10px; }
.refresh-btn {
  background: var(--ink); color: #fff;
  padding: 6px 12px; font-size: 12px; font-weight: 600;
  border: 1.5px solid var(--ink); border-radius: 5px;
  box-shadow: 2px 2px 0 var(--amber);
  cursor: pointer;
}
.refresh-btn:hover:not(:disabled) {
  transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--amber);
}
.refresh-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.big-table-wrap { overflow-x: auto; }
.big-prod-table {
  width: 100%; border-collapse: collapse;
  font-size: 14px;
}
.big-prod-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  background: var(--soft);
  border-bottom: 1.5px solid var(--ink);
}
.big-prod-table td {
  padding: 12px 16px;
  border-bottom: 1px dashed var(--line);
  vertical-align: middle;
}
.big-prod-table tr:hover { background: #fffaf0; }
.big-prod-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.big-prod-table .qty { font-size: 18px; font-weight: 800; }
.big-prod-table .empty {
  text-align: center; padding: 24px;
  color: #999; font-style: italic;
}

.age-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 11.5px; font-weight: 600;
  border: 1px solid currentColor;
}
.age-pill.age-fresh { color: #1f7a3f; background: #e8f5ec; border-color: #b3d9c4; }
.age-pill.age-warn  { color: #b14a00; background: #fff0d6; border-color: #f0c97f; }
.age-pill.age-old   { color: var(--red); background: #ffe5e0; border-color: #f0a89a; font-weight: 700; }

.prio { width: 180px; }
.prio-bar-wrap {
  position: relative;
  background: #f0ebe0;
  border: 1px solid var(--ink);
  border-radius: 4px;
  height: 22px;
  overflow: hidden;
}
.prio-bar {
  height: 100%;
  background: linear-gradient(90deg, #f5b301, var(--red));
  transition: width 0.3s;
}
.prio-num {
  position: absolute;
  top: 50%; right: 8px;
  transform: translateY(-50%);
  font-size: 11px; font-weight: 700; color: var(--ink);
  text-shadow: 0 0 3px rgba(255,255,255,0.7);
}

.dash-actions {
  display: flex; gap: 12px;
  margin-top: 24px;
}
.dash-actions .primary-btn { width: auto; min-width: 240px; }

/* --- Bestand-Input + Aktionen --- */
.bestand-input {
  width: 80px;
  padding: 6px 8px;
  font-size: 14px; font-weight: 600;
  font-family: inherit;
  text-align: right;
  border: 1.5px solid var(--ink);
  border-radius: 5px;
  background: var(--card);
  outline: none;
  font-variant-numeric: tabular-nums;
}
.bestand-input:focus {
  background: #fffef5;
  box-shadow: 2px 2px 0 var(--amber);
}
.bestand-input::-webkit-inner-spin-button { opacity: 1; }
.bestand-actions {
  display: flex; gap: 10px;
  padding: 12px 18px;
  background: var(--soft);
  border-top: 1.5px dashed var(--ink);
}
.quick-btn {
  background: var(--card); color: var(--ink);
  border: 1.5px solid var(--ink); border-radius: 5px;
  padding: 6px 12px; font-size: 12px; font-weight: 600;
  cursor: pointer;
}
.quick-btn:hover { background: #fff9e6; }

/* --- Match-Result --- */
.match-result {
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  box-shadow: 4px 4px 0 var(--ink);
  margin-top: 20px;
  overflow: hidden;
}
.match-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-bottom: 1.5px solid var(--ink);
}
.match-stat {
  padding: 18px 20px;
  border-right: 1px dashed var(--line);
  background: var(--soft);
}
.match-stat:last-child { border-right: none; }
.match-stat.ok { background: #e8f5ec; }
.match-stat.blocked { background: #fff0d6; }
.match-num {
  font-size: 32px; font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.match-label {
  font-size: 12px; font-weight: 600;
  margin-top: 6px;
  text-transform: uppercase; letter-spacing: 0.4px;
}

.match-details {
  border-bottom: 1px solid var(--line);
}
.match-details:last-child { border-bottom: none; }
.match-details summary {
  padding: 12px 18px;
  cursor: pointer; user-select: none;
  font-weight: 700; font-size: 13px;
  background: #fafaf5;
  border-bottom: 1px dashed var(--line);
}
.match-details summary:hover { background: #fff9e6; }
.match-table {
  width: 100%; border-collapse: collapse;
  font-size: 12.5px;
}
.match-table th {
  text-align: left;
  padding: 8px 14px;
  font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.4px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.match-table td {
  padding: 8px 14px;
  border-bottom: 1px dashed var(--line);
}
.match-table tr:hover { background: #fffaf0; }
.item-chip {
  display: inline-block;
  margin: 1px 3px 1px 0;
  padding: 1px 7px;
  font-size: 11px;
  background: #e8f5ec;
  border: 1px solid #b3d9c4;
  border-radius: 3px;
  white-space: nowrap;
}
.missing-chip {
  display: inline-block;
  margin: 1px 3px 1px 0;
  padding: 1px 7px;
  font-size: 11px;
  background: #ffe5e0;
  border: 1px solid #f0a89a;
  border-radius: 3px;
  white-space: nowrap;
  color: #a82a17;
  font-weight: 600;
}

/* === Bestand-Page === */
.bestand-header {
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  box-shadow: 4px 4px 0 var(--ink);
  padding: 16px 22px;
  margin-bottom: 16px;
}
.bestand-header h1 { margin: 0 0 4px; font-size: 18px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.8px; }
.bestand-header p { margin: 0; font-size: 13px; }

.sub-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.sub-tabs button {
  background: var(--card); color: var(--ink);
  border: 1.5px solid var(--ink); border-radius: 6px;
  padding: 8px 16px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.4px;
  cursor: pointer;
}
.sub-tabs button.active {
  background: var(--amber); border-color: var(--ink);
  box-shadow: 2px 2px 0 var(--ink);
}

.box-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.stock-box {
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  box-shadow: 2px 2px 0 var(--ink);
  padding: 10px;
  display: flex; flex-direction: column; align-items: center;
  text-align: center;
  position: relative;
}
.stock-box.stock-empty { opacity: 0.7; }
.stock-photo {
  width: 100%; aspect-ratio: 1 / 1;
  background: var(--soft);
  border: 1.5px dashed var(--ink);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 8px;
}
.stock-emoji { font-size: 42px; }
.stock-box.stock-rot .stock-photo { background: #ffe2dd; border-color: var(--red); }
.stock-box.stock-schwarz .stock-photo { background: #2a2a2a; border-color: #000; color: #fff; }
.stock-box.stock-weiss .stock-photo { background: #fff; border-color: var(--ink); }
.stock-box.stock-blau .stock-photo { background: #d6e8ff; border-color: var(--sbahn); }
.stock-box.stock-regenbogen .stock-photo {
  background: linear-gradient(135deg, #ff5b5b, #ffac33, #ffe933, #6ed44a, #4ab3ff, #b04dde);
  border-color: var(--ink);
}
.stock-box.stock-neutral .stock-photo { background: #f0ebe0; border-color: #888; }

.stock-name { font-size: 13px; font-weight: 700; line-height: 1.2; }
.stock-variant { font-size: 11px; color: #555; margin-top: 2px; }
.stock-qty {
  margin-top: 10px;
  width: 80%;
  padding: 8px;
  font-size: 18px; font-weight: 800;
  text-align: center; font-variant-numeric: tabular-nums;
  border: 1.5px solid var(--ink); border-radius: 5px;
  background: var(--card);
  font-family: inherit;
}
.stock-qty:focus {
  outline: none;
  box-shadow: 2px 2px 0 var(--amber);
}

.production-panel {
  background: #fff9e6;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  box-shadow: 3px 3px 0 var(--ink);
  padding: 16px 20px;
  margin-top: 24px;
}
.production-panel h2 { margin: 0 0 4px; font-size: 14px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; }
.production-panel p { margin: 0 0 12px; }
.prod-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.prod-select, .prod-qty-input {
  padding: 8px 10px; font-size: 14px;
  border: 1.5px solid var(--ink); border-radius: 5px;
  background: var(--card); font-family: inherit;
}
.prod-select { flex: 1; min-width: 220px; }
.prod-qty-input { width: 120px; font-variant-numeric: tabular-nums; }
.prod-msg { margin-top: 10px; font-size: 13px; padding: 8px; border-radius: 5px; }
.prod-msg.ok { background: #e8f5ec; color: #1f7a3f; border: 1px solid #b3d9c4; }
.prod-msg.err { background: #ffe5e0; color: #a82a17; border: 1px solid #f0a89a; }

/* === Versand-Page === */
.ship-actions { display: flex; gap: 10px; margin: 20px 0; align-items: center; }
.print-btn { width: auto !important; min-width: 320px; font-size: 14px !important; padding: 14px 22px !important; }

/* === Stock-Pill (im Dashboard) === */
.stock-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 11.5px; font-weight: 700;
  border: 1px solid currentColor;
  font-variant-numeric: tabular-nums;
}
.stock-pill.stock-ok { color: #1f7a3f; background: #e8f5ec; border-color: #b3d9c4; }
.stock-pill.stock-low { color: #b14a00; background: #fff0d6; border-color: #f0c97f; }
.stock-pill.stock-none { color: #888; background: #f0ebe0; border-color: #ccc; }

/* Buildable + BOM-Detail */
.stock-qty-wrap {
  width: 100%;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.stock-qty-lbl {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #888;
}
.stock-qty-wrap .stock-qty { margin-top: 0; }
.buildable-row {
  margin-top: 10px;
  font-size: 12.5px;
  font-weight: 700;
  color: #a06600;
  padding: 8px 10px;
  border: 1.5px solid #d8b85a;
  border-radius: 6px;
  background: #fff5d6;
  width: 100%;
  text-align: center;
  box-shadow: 1px 1px 0 #d8b85a;
}
.buildable-row b { font-size: 18px; font-weight: 800; }
.buildable-row.can-build {
  color: #1f7a3f; background: #d4f0dd;
  border-color: #4caf6d;
  box-shadow: 1px 1px 0 #4caf6d;
}
.limit-row {
  margin-top: 4px;
  font-size: 10.5px;
  color: #a82a17;
  text-align: center;
  font-style: italic;
  line-height: 1.2;
}
.bom-toggle {
  margin-top: 6px;
  background: transparent; border: none;
  font-size: 11px; color: var(--ink);
  cursor: pointer;
  font-family: inherit;
}
.bom-toggle:hover { text-decoration: underline; }
.bom-list {
  margin-top: 6px;
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 4px;
  display: flex; flex-direction: column; gap: 2px;
}
.bom-item {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  grid-template-areas: "emoji name have" ". tag tag";
  column-gap: 6px;
  row-gap: 2px;
  padding: 5px 7px;
  font-size: 11px;
  border-radius: 3px;
  background: var(--soft);
  text-align: left;
  align-items: center;
}
.bom-item.bom-tag-eigen { background: #fffaf0; border-left: 3px solid var(--amber); }
.bom-item.bom-tag-geteilt { background: #f0e8ff; border-left: 3px solid #8666c4; }
.bom-item.bom-tag-universal { background: #e8f5ec; border-left: 3px solid #b3d9c4; }
.bom-emoji { grid-area: emoji; font-size: 14px; line-height: 1; }
.bom-name { grid-area: name; line-height: 1.2; min-width: 0; word-break: break-word; }
.bom-tag {
  grid-area: tag;
  font-size: 9px; color: #666;
  text-transform: uppercase; letter-spacing: 0.4px;
  font-weight: 600;
}
.bom-have { grid-area: have; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bom-have.ok { color: #1f7a3f; }
.bom-have.low { color: var(--red); }
