:root {
  --color-primary: #2b241f;
  --color-white: #ffffff;
  --color-cream: #e6decc;
  --color-blush: #d2c6b9;
  --color-accent: #7047eb;
  --color-accent-soft: #ece6fb;
  --color-danger: #b3503f;
  --color-platin: #948b81;
  --color-bronze: #958769;
  --surface: #ffffff;
  --border: #e3dacb;
  --fg: var(--color-primary);
  --fg-muted: #7a6f5f;
  --bg: #e6decc;
  --radius: 10px;
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Jost', system-ui, -apple-system, sans-serif;
  --cols: 4;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--color-white);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
}

h1, h2 { font-family: var(--font-display); font-weight: 600; margin: 0; }

button, input, select { font-family: inherit; }

.app-shell {
  display: flex;
  align-items: flex-start;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 280px;
  flex: 0 0 280px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.sidebar-logo { display: flex; justify-content: center; }
.sidebar-logo img { width: 160px; height: auto; }

.area-switch {
  display: flex;
  gap: 4px;
  background: color-mix(in srgb, var(--color-cream) 30%, transparent);
  border-radius: 999px;
  padding: 4px;
  border: 1.5px solid var(--color-accent);
}
.area-btn {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--color-accent);
  padding: 8px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
}
.area-btn.active { background: var(--color-accent); color: #fff; }

.view-nav { display: flex; flex-direction: column; gap: 4px; }
.view-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: none;
  background: color-mix(in srgb, var(--color-cream) 30%, transparent);
  color: var(--fg);
  text-align: left;
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.view-btn.active { background: var(--color-cream); font-weight: 600; }
.badge {
  min-width: 35px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-cream);
  color: var(--fg-muted);
  font-size: 10px;
  font-weight: 600;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.view-btn.active .badge { background: var(--color-accent); color: #fff; min-width: auto; }

.sidebar-section { display: flex; flex-direction: column; gap: 16px; }
.sidebar-section h2 {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--color-bronze); }
.field select, .field input[type=search], .field input[type=text] {
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  background-color: var(--bg);
  color: var(--fg);
  width: 100%;
}
.field select { padding-right: 34px; }

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a6f5f' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 12px;
}
.field-row { display: flex; gap: 10px; }
.field-row > .field { flex: 1; min-width: 0; }
.field-row > .fav-toggle-field { flex: 0 0 auto; }
.fav-toggle-btn {
  width: 40px; height: 40px;
  padding: 4px;
  border: none;
  border-radius: 10px;
  background: var(--bg);
  color: var(--color-platin);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.fav-toggle-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.fav-toggle-btn[aria-pressed="true"] { background: var(--color-accent); color: #fff; }
.fav-toggle-btn[aria-pressed="true"] svg { fill: #fff; stroke: #fff; }

.field-details summary {
  font-size: 13px;
  font-weight: 500;
  color: var(--fg);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
}
.field-details summary::-webkit-details-marker { display: none; }
.field-details summary .chevron {
  width: 14px; height: 14px;
  flex: 0 0 auto;
  fill: none;
  stroke: var(--fg-muted);
  stroke-width: 1.8;
  transition: transform .15s ease;
}
.field-details[open] summary .chevron { transform: rotate(180deg); }
.chip-col, .chip-row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: none;
  background: var(--bg);
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  color: var(--fg);
}
.chip.checked { background: var(--color-accent); color: #fff; font-weight: 500; }

.col-control { display: flex; gap: 4px; }
.col-control button {
  flex: 1;
  padding: 8px 0;
  border-radius: 8px;
  border: none;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  font-weight: 500;
}
.col-control button.active { background: var(--color-accent); color: #fff; }

.search-wrap { position: relative; display: flex; }
.search-wrap input { padding-right: 34px; }
.search-wrap svg {
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  fill: none;
  stroke: var(--fg-muted);
  stroke-width: 1.8;
  pointer-events: none;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
.btn-primary:hover { filter: brightness(1.08); }

.sidebar-bottom {
  margin-top: auto;
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.result-count { font-size: 11px; color: var(--fg-muted); }
.upload-fab {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  border-radius: 16px;
  border: none;
  background: var(--color-blush);
  color: var(--fg);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.upload-fab:hover { filter: brightness(0.97); }
.upload-fab svg { width: 16px; height: 16px; }

/* ---------- Main / Grid ---------- */
main { flex: 1; min-width: 0; padding: 22px 26px 60px; }

.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  gap: 16px;
}

.card {
  position: relative;
  background: rgba(230, 222, 204, 0.3);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.card-img-wrap { position: relative; }
.card-img {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  cursor: zoom-in;
}
.card-img-inner {
  width: 100%;
  height: 100%;
  max-width: 55%;
  max-height: 55%;
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.card-img-inner .placeholder-icon { width: 40%; height: 40%; fill: none; stroke: var(--fg-muted); stroke-width: 1.4; }
.card-img img { display: none; max-width: 100%; max-height: 100%; object-fit: contain; }
.card-img.has-image { padding: 10px; }
.card-img.has-image .card-img-inner { display: none; }
.card-img.has-image img { display: block; }

.fav-btn {
  position: absolute;
  top: 12px; right: 12px;
  z-index: 2;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.9);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.fav-btn .star { width: 16px; height: 16px; fill: none; stroke: var(--color-platin); stroke-width: 1.8; stroke-linejoin: round; }
.fav-btn[aria-pressed="true"] { background: var(--color-accent); }
.fav-btn[aria-pressed="true"] .star { fill: #fff; stroke: #fff; }

.card-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.card-name {
  font-family: var(--font-body);
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--fg);
  padding: 2px 0;
  width: 100%;
}
.card-name:hover, .card-name:focus { border-bottom-color: var(--border); outline: none; }
.card-id { font-size: 11px; color: var(--fg-muted); font-variant-numeric: tabular-nums; margin-top: -6px; }
.field-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; color: var(--color-bronze); margin-top: 4px; }
.card-field-row { display: flex; gap: 10px; }
.card-field-row > div { flex: 1; min-width: 0; }
.card-kollektion, .card-kategorie, .card-zielgruppe {
  font: inherit;
  padding: 10px 34px 10px 12px;
  border-radius: 10px;
  border: none;
  background-color: var(--bg);
  color: var(--fg);
  width: 100%;
}
.mk-seite, .mk-verwendungszweck, .md-seite {
  font: inherit;
  font-size: 12.5px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  background-color: var(--bg);
  color: var(--fg);
}
.mk-verwendungszweck { padding-right: 34px; }
.card-notiz, .mk-notiz, .md-notiz {
  font: inherit;
  font-size: 12.5px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--fg);
  resize: vertical;
}
.price-row { display: flex; align-items: center; gap: 6px; }
.card-preis {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  background: var(--bg);
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}
.currency { color: var(--fg-muted); }

.card-footer { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 32px; height: 32px;
  flex: 0 0 auto;
  border-radius: 8px;
  border: none;
  background: var(--bg);
  color: var(--color-platin);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { filter: brightness(0.95); }
.icon-btn svg { width: 16px; height: 16px; fill: currentColor; }
.icon-btn.archive-btn { margin-left: auto; }

.move-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(20,16,10,0.18);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 200;
  min-width: 190px;
}
.move-menu button {
  text-align: left;
  border: none;
  background: transparent;
  padding: 9px 10px;
  border-radius: 7px;
  font: inherit;
  font-size: 13px;
  color: var(--fg);
  cursor: pointer;
}
.move-menu button:hover { background: var(--bg); }
.info-box {
  font-size: 11px;
  color: var(--fg-muted);
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  word-break: break-word;
}

.card.is-archived { opacity: 0.75; }
.card.is-new {
  animation: card-highlight 2.4s ease-out 1;
}
@keyframes card-highlight {
  0% { box-shadow: 0 0 0 3px var(--color-accent); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.empty-hint, .hint { color: var(--fg-muted); font-size: 13px; padding: 20px 4px; }

/* ---------- Rank list ---------- */
.rank-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-width: 760px; }
.rank-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
}
.rank-row.dragging { opacity: .4; }
.drag-handle { color: var(--fg-muted); cursor: grab; font-size: 16px; line-height: 1; }
.rank-number { font-family: var(--font-display); font-weight: 600; font-size: 18px; width: 26px; text-align: center; color: var(--color-accent); }
.rank-thumb { width: 48px; height: 48px; object-fit: contain; background: #fff; border-radius: 6px; border: 1px solid var(--border); }
.rank-info { flex: 1; min-width: 0; }
.rank-id { font-size: 13px; font-weight: 600; }
.rank-meta { font-size: 11px; color: var(--fg-muted); }
.rank-preis { font-size: 13px; font-variant-numeric: tabular-nums; color: var(--fg-muted); min-width: 60px; text-align: right; }
.rank-actions { display: flex; gap: 4px; }
.rank-actions button { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--fg); cursor: pointer; }
.rank-remove { color: var(--color-danger); }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(20, 16, 10, 0.92);
  display: flex; align-items: center; justify-content: center;
  padding: 40px 20px;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; background: #fff; border-radius: 8px; }
.lightbox-close {
  position: absolute; top: 16px; right: 20px;
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: rgba(255,255,255,0.15); color: #fff;
  font-size: 22px; cursor: pointer;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 110;
  background: rgba(20, 16, 10, 0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal-box {
  position: relative;
  background: var(--surface);
  border-radius: 14px;
  padding: 26px 24px;
  max-width: 420px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-close {
  position: absolute; top: 12px; right: 12px;
  width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--border); background: none; color: var(--fg);
  font-size: 18px; cursor: pointer;
}
.radio-row { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.upload-hint { font-size: 11px; color: var(--fg-muted); margin: 0; }
.upload-status { font-size: 12px; color: var(--fg-muted); min-height: 16px; }

.toast {
  position: fixed;
  bottom: 18px; left: 50%;
  transform: translateX(-50%);
  background: var(--color-primary);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 12px;
  z-index: 120;
}

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar { position: relative; width: 100%; flex: none; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  main { padding: 18px 16px 50px; }
}
