:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --orange: #ea580c;
  --orange-light: #ffedd5;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.06);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.12), 0 8px 24px rgba(0,0,0,0.08);
  --radius: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Header ── */
header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 60%, #3b82f6 100%);
  color: white;
  padding: 0 24px;
  box-shadow: 0 4px 20px rgba(37,99,235,0.3);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  gap: 16px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-icon {
  width: 48px;
  height: 48px;
  background: rgba(255,255,255,0.2);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  backdrop-filter: blur(10px);
}

.header-icon svg {
  width: 28px;
  height: 28px;
  color: white;
}

header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: white;
}

header p {
  font-size: 13px;
  color: rgba(255,255,255,0.75);
  margin-top: 1px;
}

.btn-add {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1.5px solid rgba(255,255,255,0.35);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  backdrop-filter: blur(10px);
  white-space: nowrap;
}

.btn-add:hover {
  background: rgba(255,255,255,0.25);
  border-color: rgba(255,255,255,0.6);
  transform: translateY(-1px);
}

/* ── Main ── */
main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.filter-tabs {
  display: flex;
  gap: 6px;
  background: var(--surface);
  padding: 5px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  flex-wrap: wrap;
}

.filter-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.filter-tab:hover {
  background: var(--bg);
  color: var(--text);
}

.filter-tab.active {
  background: var(--primary);
  color: white;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot-green  { background: var(--success); }
.dot-amber  { background: var(--warning); }
.dot-orange { background: var(--orange); }
.dot-red    { background: var(--danger); }
.dot-blue   { background: var(--primary); }

.count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  background: rgba(0,0,0,0.08);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
}

.filter-tab.active .count {
  background: rgba(255,255,255,0.25);
}

.search-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 9px 14px;
  box-shadow: var(--shadow);
  min-width: 240px;
  transition: border-color 0.2s;
}

.search-filter:focus-within {
  border-color: var(--primary);
}

.search-filter svg { color: var(--text-light); flex-shrink: 0; }

.search-filter input {
  border: none;
  outline: none;
  font-size: 14px;
  width: 100%;
  color: var(--text);
  background: transparent;
}

.search-filter input::placeholder { color: var(--text-light); }

/* ── Grid ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.25s, transform 0.25s;
  border: 1.5px solid transparent;
  position: relative;
}

.card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.card.status-empty        { border-color: var(--danger); }
.card.status-wenig        { border-color: var(--orange); }
.card.status-mittelmaessig{ border-color: var(--warning); }
.card.status-restock      { border-color: var(--primary); }
/* empty always wins */
.card.status-empty.status-wenig,
.card.status-empty.status-mittelmaessig,
.card.status-empty.status-restock { border-color: var(--danger); }

.card-image {
  height: 150px;
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.card-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 8px;
}

.card-image-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-light);
  font-size: 12px;
}

.card-image-placeholder .pill-icon {
  font-size: 48px;
  line-height: 1;
}

.card-body {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.card-quantity {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

.card-quantity svg { flex-shrink: 0; }

.card-notes {
  font-size: 12px;
  color: var(--text-light);
  font-style: italic;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.badge-genug        { background: var(--success-light); color: var(--success); }
.badge-mittelmaessig{ background: var(--warning-light); color: var(--warning); }
.badge-wenig        { background: var(--orange-light);  color: var(--orange); }
.badge-empty        { background: var(--danger-light);  color: var(--danger); }
.badge-restock      { background: var(--primary-light); color: var(--primary); }

.card-actions {
  padding: 12px 16px;
  display: flex;
  gap: 8px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.action-btn {
  flex: 1;
  min-width: 70px;
  padding: 7px 10px;
  border: none;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.action-btn:hover { transform: translateY(-1px); }

.action-btn.empty-btn {
  background: var(--danger-light);
  color: var(--danger);
}
.action-btn.empty-btn:hover { background: #fecaca; }
.action-btn.empty-btn.active-status {
  background: var(--danger);
  color: white;
}

.action-btn.restock-btn {
  background: var(--warning-light);
  color: var(--warning);
}
.action-btn.restock-btn:hover { background: #fde68a; }
.action-btn.restock-btn.active-status {
  background: var(--warning);
  color: white;
}

.action-btn.edit-btn {
  background: var(--primary-light);
  color: var(--primary);
}
.action-btn.edit-btn:hover { background: #bfdbfe; }

.action-btn.delete-btn {
  background: #f1f5f9;
  color: var(--text-muted);
  flex: 0;
  min-width: 36px;
  width: 36px;
  padding: 7px;
}
.action-btn.delete-btn:hover { background: var(--danger-light); color: var(--danger); }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  margin-bottom: 16px;
  color: var(--text-light);
}

.empty-state h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 14px;
  color: var(--text-muted);
}

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.5);
  z-index: 200;
  display: none;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

.modal-backdrop.open { display: block; }

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  width: min(540px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  z-index: 300;
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: slideIn 0.25s ease forwards;
}

.modal.open {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from { transform: translate(-50%, -48%) scale(0.95); opacity: 0; }
  to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg);
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.15s;
}

.modal-close:hover { background: var(--border); color: var(--text); }

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Form ── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.required { color: var(--danger); }

input[type="text"], textarea {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
  width: 100%;
  outline: none;
  font-family: inherit;
  resize: vertical;
}

input[type="text"]:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

input[readonly] {
  background: #f8fafc;
  color: var(--text-muted);
  cursor: default;
}

input[readonly].confirmed {
  background: var(--success-light);
  color: var(--success);
  border-color: #86efac;
  font-weight: 600;
}

/* ── Search / Autocomplete ── */
.search-wrapper { position: relative; }

.autocomplete-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  z-index: 400;
  max-height: 220px;
  overflow-y: auto;
  display: none;
}

.autocomplete-dropdown.open { display: block; }

.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.autocomplete-item:hover, .autocomplete-item.highlighted {
  background: var(--primary-light);
  color: var(--primary);
}

.autocomplete-item:first-child { border-radius: 10px 10px 0 0; }
.autocomplete-item:last-child { border-radius: 0 0 10px 10px; }
.autocomplete-item:only-child { border-radius: 10px; }

.autocomplete-empty {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-light);
  text-align: center;
}

.search-hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-light);
}

/* ── Image preview ── */
.image-preview-section {
  background: var(--bg);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.image-preview {
  width: 90px;
  height: 90px;
  border-radius: 10px;
  overflow: hidden;
  border: 1.5px solid var(--border);
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.image-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-light);
  font-size: 10px;
  text-align: center;
  padding: 8px;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  justify-content: center;
}

.image-status {
  font-size: 12px;
  color: var(--text-muted);
}

.image-status.loading { color: var(--primary); }
.image-status.found { color: var(--success); }
.image-status.not-found { color: var(--text-light); }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-family: inherit;
}

.link-btn:hover { color: var(--primary-dark); }

/* ── Buttons ── */
.btn-primary {
  padding: 10px 24px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
  padding: 10px 24px;
  background: var(--bg);
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover { background: var(--border); color: var(--text); }

.btn-danger {
  padding: 10px 24px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-danger:hover { background: #b91c1c; }

/* ── Confirm Modal ── */
.confirm-modal {
  width: min(420px, calc(100vw - 32px));
}

.confirm-modal .modal-body p {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ── Fill level selector ── */
.fill-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.fill-btn {
  flex: 1;
  min-width: 90px;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.fill-btn:hover { border-color: var(--text-light); color: var(--text); }

.fill-dots {
  display: flex;
  gap: 4px;
}

.fd {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  opacity: 0.4;
  transition: all 0.2s;
}

.fd-on {
  opacity: 1;
  background: currentColor;
}

/* per-level colours when active */
.fill-btn.fill-genug.active {
  border-color: var(--success);
  background: var(--success-light);
  color: var(--success);
}

.fill-btn.fill-mittelmaessig.active {
  border-color: var(--warning);
  background: var(--warning-light);
  color: var(--warning);
}

.fill-btn.fill-wenig.active {
  border-color: var(--orange);
  background: var(--orange-light);
  color: var(--orange);
}

/* ── Fill level on cards ── */
.card-fill {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
}

.fill-bar {
  display: flex;
  gap: 3px;
}

.fill-bar-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

/* ── Loading spinner ── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(37,99,235,0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  main { padding: 16px 12px 40px; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .search-filter { min-width: unset; }
  .header-inner { gap: 10px; }
  header h1 { font-size: 18px; }
  .btn-add span { display: none; }
  .grid { grid-template-columns: 1fr; }
}
