:root {
  --red: #7a1620;
  --red-dark: #5c1018;
  --red-light: #fbeceb;
  --ink: #1c1f23;
  --ink-soft: #666e76;
  --ink-faint: #9aa1a8;
  --border: #e7e4e1;
  --bg: #f3f1ee;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --green: #1f7a4d;
  --green-light: #eaf6ef;
  --amber: #9a6b12;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow: 0 1px 2px rgba(20,16,14,0.04), 0 4px 14px rgba(20,16,14,0.05);
  --shadow-md: 0 2px 6px rgba(20,16,14,0.06), 0 10px 24px rgba(20,16,14,0.08);
  --shadow-lg: 0 12px 40px rgba(20,16,14,0.20);
  --ease: cubic-bezier(0.2, 0.7, 0.3, 1);
}

* { box-sizing: border-box; }

/* Stellt sicher, dass das hidden-Attribut IMMER gewinnt, auch gegen
   Klassen wie .overlay/.pos-layout, die display:flex fest setzen.
   Ohne diese Regel bleiben per JS "geschlossene" Popups/Bereiche sichtbar. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  /* Verhindert die ~300ms Tap-Verzoegerung / doppeltes Tippen-zum-Zoomen
     auf Touchscreens, wodurch Taps auf Buttons sonst ab und zu verloren
     gehen oder verzoegert ankommen (:active-Animation "manchmal"). */
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

button, .btn, .type-btn, .product-btn, .picker-card, .tab-btn, .list-row, [role="button"] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  font-family: inherit;
}

h1, h2, h3, h4 { letter-spacing: -0.015em; margin: 0; }
.icon { display: inline-block; vertical-align: -4px; flex-shrink: 0; }

:focus-visible { outline: 2.5px solid var(--red); outline-offset: 2px; border-radius: 4px; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d8d4cf; border-radius: 20px; }
::-webkit-scrollbar-thumb:hover { background: #c7c2bb; }

/* ===== HEADER ===== */
.offline-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--amber);
  color: white;
  font-weight: 700;
  font-size: 0.88em;
  padding: 9px 16px;
  text-align: center;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 rgba(20,16,14,0.02), 0 2px 10px rgba(20,16,14,0.03);
  padding: 12px 24px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { height: 44px; width: auto; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-title { font-size: 1.05em; font-weight: 800; color: var(--ink); letter-spacing: -0.01em; }
.brand-sub { font-size: 0.75em; color: var(--ink-soft); font-weight: 500; }

.tabs { display: flex; gap: 4px; flex: 1; background: var(--bg); padding: 4px; border-radius: 999px; }
.tab-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 18px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.92em;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
  flex: 1;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { background: var(--red); color: white; box-shadow: 0 2px 8px rgba(122,22,32,0.35); }

.active-event-pill {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  padding: 7px 18px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s var(--ease), background 0.1s var(--ease);
}
.active-event-pill:hover { border-color: var(--ink-faint); }
.active-event-pill:active { background: var(--bg); }
.aep-label { font-size: 0.73em; color: var(--ink-faint); font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.aep-name { font-size: 0.99em; font-weight: 700; color: var(--ink); }
.active-event-pill.empty { border-color: var(--amber); background: #fff8ea; }
.active-event-pill.empty .aep-name { color: var(--amber); }

.tab-content { display: none; padding: 24px 24px 48px; max-width: 1400px; margin: 0 auto; animation: fade-in 0.18s var(--ease); }
.tab-content.active { display: block; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.empty-state {
  background: var(--surface);
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 34px 20px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.96em;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.empty-state-lg { padding: 76px 20px; }
.empty-state strong { color: var(--ink); font-size: 1.05em; }
.empty-state .icon { color: var(--ink-faint); }
.empty-state button { margin-top: 4px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.06s ease, background 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.btn:active { transform: scale(0.97); }
.btn-block { width: 100%; }
.btn-primary { background: var(--red); color: white; box-shadow: 0 2px 8px rgba(122,22,32,0.28); }
.btn-primary:hover { background: #8a1a25; }
.btn-primary:active { background: var(--red-dark); }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--bg); color: var(--ink); }
.btn-ghost:active { background: var(--bg); }
.btn-outline { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-outline:hover { border-color: var(--ink-faint); }
.btn-outline:active { background: var(--bg); }
.btn-danger-text { color: #b3261e; }
.btn-icon { padding: 8px; }
.btn-sm { padding: 7px 11px; font-size: 0.85em; }

/* ===== POS ===== */
.pos-layout { display: flex; gap: 20px; align-items: flex-start; }
.pos-main { flex: 5; min-width: 0; }
.pos-cart {
  flex: 3;
  min-width: 400px;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  position: sticky;
  top: 92px;
  box-shadow: var(--shadow-md);
}
.pos-cart h3 { display: flex; align-items: center; gap: 8px; font-size: 1.2em; font-weight: 800; }
.pos-cart h4 { margin-bottom: 10px; margin-top: 22px; color: var(--ink-soft); font-size: 0.8em; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }

.order-type-switch { display: flex; gap: 8px; margin: 18px 0 16px; }
.type-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  font-size: 1em;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--ink-soft);
  cursor: pointer;
  font-weight: 700;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}
.type-btn:hover { border-color: var(--ink-faint); }
.type-btn.active { background: var(--red); color: white; border-color: var(--red); box-shadow: 0 2px 8px rgba(122,22,32,0.28); }

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 12px;
}
.product-btn {
  padding: 20px 12px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 1em;
  text-align: center;
  min-height: 88px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  font-weight: 600;
  color: var(--ink);
  transition: transform 0.12s var(--ease), box-shadow 0.12s var(--ease), border-color 0.12s var(--ease), background 0.12s var(--ease);
}
.product-btn:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: #ddd7ce; }
.product-btn:active { background: var(--red-light); border-color: var(--red); transform: scale(0.97); }
.product-btn .price { font-weight: 700; color: var(--red); font-size: 0.9em; }
.product-btn .category { font-weight: 600; font-size: 0.68em; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.05em; }

.cart-items { max-height: 320px; overflow-y: auto; margin-bottom: 8px; }
.cart-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.cart-item .name { flex: 1; font-size: 0.94em; font-weight: 500; }
.type-tag {
  display: inline-block;
  margin-left: 7px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.68em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  vertical-align: middle;
}
.type-tag-kunde { background: var(--red-light); color: var(--red); }
.type-tag-personal { background: var(--bg); color: var(--ink-soft); }
.cart-breakdown {
  display: flex; justify-content: space-between;
  font-size: 0.85em; color: var(--ink-soft); font-weight: 600;
  padding: 8px 10px; margin-top: 4px;
  background: var(--surface-2); border-radius: var(--radius-sm);
}
.cart-item .qty-controls { display: flex; align-items: center; gap: 4px; }
.cart-item button.qty-btn {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  color: var(--ink);
  transition: background 0.12s var(--ease);
}
.cart-item button.qty-btn:hover { background: var(--bg); }
.cart-item button.remove-btn {
  display: flex; align-items: center; justify-content: center;
  color: var(--ink-faint);
  background: transparent;
  border: none;
  width: 28px; height: 28px;
  cursor: pointer;
  border-radius: 8px;
  transition: background 0.12s var(--ease), color 0.12s var(--ease);
}
.cart-item button.remove-btn:hover { background: var(--red-light); color: var(--red); }
.cart-item .line-sum { font-size: 0.9em; font-weight: 700; min-width: 62px; text-align: right; }
.cart-total {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 1.3em; font-weight: 800; margin: 12px 0 16px;
  padding-top: 12px;
  border-top: 1.5px solid var(--ink);
}

.badge {
  background: var(--bg);
  color: var(--ink-soft);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.66em;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-left: 4px;
  vertical-align: middle;
}
.badge.badge-red { background: var(--red-light); color: var(--red); }

.recent-orders { max-height: 320px; overflow-y: auto; }
.recent-order {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.87em;
  transition: opacity 0.15s ease, background 0.12s var(--ease);
}
.recent-order:hover { background: var(--surface-2); }
.recent-order.pending { opacity: 0.35; }
.recent-order.voided { opacity: 0.4; text-decoration: line-through; }
.recent-order .meta { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); }
.row-actions { display: flex; gap: 6px; }

/* ===== ADMIN ===== */
.admin-layout { display: flex; gap: 20px; flex-wrap: wrap; }
.admin-col {
  flex: 1; min-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-md);
}
.admin-col h3 { margin-top: 0; display: flex; align-items: center; font-size: 1.05em; font-weight: 800; margin-bottom: 14px; }
.inline-form { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.inline-form input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex: 1; min-width: 110px;
  font-size: 0.92em;
  background: var(--surface-2);
  transition: background 0.12s var(--ease), border-color 0.12s var(--ease);
}
.inline-form input:focus { outline: 2px solid var(--red); outline-offset: -1px; background: var(--surface); }
.list-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 11px;
  border-bottom: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: opacity 0.15s ease, background 0.12s var(--ease);
}
.list-row:hover { background: var(--surface-2); }
.list-row.inactive { opacity: 0.45; }
.list-row.pending { opacity: 0.3; pointer-events: none; }
.list-row.selected { background: var(--red-light); }
.list-row .label { flex: 1; font-weight: 600; font-size: 0.93em; }
.list-row .label small { color: var(--ink-soft); font-weight: 400; margin-left: 6px; }
.list-row .price-inline { width: 78px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 7px; font-size: 0.9em; background: var(--surface-2); }
.list-row .row-actions { display: flex; gap: 6px; }
.list { display: flex; flex-direction: column; gap: 2px; }

/* ===== REPORT ===== */
.report-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.report-header h3 { font-size: 1.3em; font-weight: 800; }
.report-actions { display: flex; gap: 8px; }
.report-summary { display: flex; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.report-summary .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 22px;
  box-shadow: var(--shadow);
  min-width: 150px;
}
.report-summary .card .label { font-size: 0.74em; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; font-weight: 700; }
.report-summary .card .value { font-size: 1.5em; font-weight: 800; color: var(--ink); margin-top: 2px; }
.report-summary .card.accent { background: var(--red); }
.report-summary .card.accent .label { color: rgba(255,255,255,0.75); }
.report-summary .card.accent .value { color: white; }

.report-tables { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.report-table-block { flex: 1; min-width: 320px; }
.report-table-block h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-size: 1em; font-weight: 800; }
.report-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius-lg); overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow); }
.report-table th, .report-table td { padding: 12px 14px; text-align: right; border-bottom: 1px solid var(--border); font-size: 0.92em; }
.report-table th:first-child, .report-table td:first-child { text-align: left; }
.report-table thead th { background: var(--ink); color: white; font-weight: 600; font-size: 0.78em; text-transform: uppercase; letter-spacing: 0.04em; }
.report-table tfoot td { font-weight: 800; background: var(--surface-2); }

/* ===== EVENT PICKER OVERLAY ===== */
.overlay {
  position: fixed; inset: 0;
  background: rgba(20,16,14,0.55);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: overlay-in 0.15s var(--ease);
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

.overlay-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: panel-in 0.18s var(--ease);
}
@keyframes panel-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

.overlay-header { display: flex; justify-content: space-between; align-items: center; }
.overlay-header h2 { font-size: 1.3em; font-weight: 800; }
.overlay-hint { color: var(--ink-soft); font-size: 0.9em; margin: 8px 0 18px; line-height: 1.5; }
.overlay-quick-form { margin-top: 18px; margin-bottom: 0; padding-top: 18px; border-top: 1px solid var(--border); }

.picker-list { display: flex; flex-direction: column; gap: 8px; }
.picker-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  background: var(--surface);
  transition: border-color 0.12s var(--ease), background 0.12s var(--ease);
}
.picker-card:hover { border-color: var(--ink-faint); }
.picker-card:active { background: var(--bg); }
.picker-card.current { border-color: var(--red); background: var(--red-light); }
.picker-card .pc-icon { color: var(--ink-faint); }
.picker-card.current .pc-icon { color: var(--red); }
.picker-card .pc-info { flex: 1; }
.picker-card .pc-name { font-weight: 700; font-size: 1em; }
.picker-card .pc-date { font-size: 0.82em; color: var(--ink-soft); margin-top: 2px; }
.picker-card.inactive { opacity: 0.5; }

/* ===== Kleinere Popups (Bearbeiten / Bestell-Details) ===== */
.overlay-panel-sm { max-width: 420px; }
.stacked-form { display: flex; flex-direction: column; gap: 14px; margin-top: 4px; }
.stacked-form label { display: flex; flex-direction: column; gap: 5px; font-size: 0.86em; font-weight: 600; color: var(--ink-soft); }
.stacked-form input, .stacked-form select {
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.98em;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 500;
  transition: background 0.12s var(--ease), border-color 0.12s var(--ease);
}
.stacked-form input:focus, .stacked-form select:focus { outline: 2px solid var(--red); outline-offset: -1px; background: var(--surface); }

.order-detail-list { display: flex; flex-direction: column; gap: 2px; margin-bottom: 6px; }
.order-detail-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 0.92em; }
.order-detail-row .name { flex: 1; font-weight: 500; }
.order-detail-row .qty { color: var(--ink-soft); }
.order-detail-row .line-sum { font-weight: 700; min-width: 64px; text-align: right; }

.order-edit-list { display: flex; flex-direction: column; gap: 2px; max-height: 300px; overflow-y: auto; }
.order-edit-list .cart-item { padding: 8px 0; }
.type-tag-btn { border: none; cursor: pointer; }
.order-type-switch-sm { margin: 2px 0 4px; }
.order-type-switch-sm .type-btn { padding: 9px; font-size: 0.85em; }
#order-edit-add-product { flex: 2; padding: 10px 11px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); font-size: 0.92em; }

/* ===== TOASTS ===== */
.toast-container {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  width: 100%;
  max-width: 420px;
  padding: 0 16px;
  align-items: stretch;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--ink);
  color: white;
  padding: 13px 15px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.9em;
  animation: toast-in 0.2s var(--ease);
}
.toast.toast-out { animation: toast-out 0.18s ease-in forwards; }
.toast.toast-error { background: #7a2320; }
.toast.toast-success { background: var(--green); }
.toast span:first-child { flex: 1; }
.toast-action {
  background: rgba(255,255,255,0.18);
  border: none;
  color: white;
  padding: 6px 11px;
  border-radius: 7px;
  font-weight: 700;
  font-size: 0.9em;
  cursor: pointer;
  white-space: nowrap;
}
.toast-close {
  background: none; border: none; color: rgba(255,255,255,0.7);
  cursor: pointer; display: flex; padding: 2px;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateY(8px); } }

@media (max-width: 860px) {
  .pos-layout { flex-direction: column; }
  .pos-cart { position: static; width: 100%; max-width: none; }
  .topbar { flex-direction: column; align-items: stretch; }
  .tabs { justify-content: space-between; }
}

