/* Secondhand Assistant — Resale-Werkbank, mobil zuerst */
:root {
  color-scheme: light;
  --paper: #F3EDDF;
  --paper-2: #FFF9EB;
  --card: #FFFDF6;
  --ink: #191713;
  --ink-soft: #353129;
  --muted: #6F6659;
  --line: #D8CCB8;
  --accent: #E9552E;
  --accent-dark: #C9411F;
  --highlight: #F6C744;
  --ok: #2E7D5B;
  --ok-bg: #DDF0E6;
  --info: #305BC7;
  --info-bg: #E1E8FA;
  --danger: #C83B32;
  --danger-bg: #F7DEDA;
  --warn-bg: #F9EBC0;
  --radius: 16px;
  --radius-lg: 20px;
  --nav-h: 64px;
  --shadow-hard: 4px 4px 0 var(--ink);
  --shadow-soft: 0 10px 24px rgba(25, 23, 19, 0.16);
  --font-body: system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body {
  margin: 0;
  font-family: var(--font-body);
  background:
    radial-gradient(circle at 88% 4%, rgba(246, 199, 68, 0.16), transparent 24rem),
    linear-gradient(rgba(25, 23, 19, 0.024) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 28px 28px, auto;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }
.view {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 20px calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 30px);
}

h1 {
  font-size: 1.65rem;
  font-weight: 900;
  margin: 4px 0 8px;
  letter-spacing: -0.045em;
  line-height: 0.98;
}
h2 { font-size: 1.25rem; font-weight: 900; margin: 0; letter-spacing: -0.025em; }
.hint { color: var(--muted); font-size: 0.9rem; line-height: 1.4; }
.msg { min-height: 1.2em; font-size: 0.88rem; color: var(--muted); line-height: 1.35; }

/* ---------- Auth ---------- */
#view-auth { padding-top: 24px; }
#view-auth h1 {
  max-width: 100%;
  font-size: clamp(2.4rem, 10.8vw, 3.5rem);
  font-weight: 900;
  line-height: 0.98;
  letter-spacing: -0.055em;
  margin: 22px 0 16px;
}
#view-auth h1 .accent {
  display: inline-block;
  white-space: nowrap;
  color: var(--ink);
  background: linear-gradient(to top, transparent 54%, var(--highlight) 54%, var(--highlight) 84%, transparent 84%);
  padding: 0 0.08em;
}
#view-auth > .hint {
  max-width: 34ch;
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 0.96rem;
}
#view-auth::before {
  content: "Secondhand Assistant";
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 13px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper-2);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
#view-auth::after {
  content: "#01\A LISTING";
  white-space: pre;
  position: absolute;
  top: 22px;
  right: max(20px, calc(50vw - 260px));
  width: 82px;
  padding: 11px 10px 10px 27px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background:
    radial-gradient(circle at 14px 50%, var(--paper) 0 5px, var(--ink) 5px 7px, transparent 7px),
    var(--accent);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  transform: rotate(5deg);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1.25;
}
#view-auth form:first-of-type { margin-top: 0; }

form {
  position: relative;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-hard);
  padding: 20px;
  margin-bottom: 18px;
  display: grid;
  gap: 14px;
}
form h2 { margin-top: 2px; }
label {
  display: grid;
  gap: 7px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}
input, textarea {
  width: 100%;
  font: inherit;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  padding: 12px 14px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--paper-2);
  color: var(--ink);
  box-shadow: none;
}
textarea { line-height: 1.42; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.82; }
input:focus, textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px var(--highlight);
}

/* ---------- Buttons ---------- */
button {
  font: inherit;
  font-weight: 800;
  min-height: 44px;
  padding: 12px 18px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--ink);
  color: var(--paper-2);
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--accent);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.15s ease;
}
button:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--accent);
}
button.primary { width: 100%; font-size: 1rem; }
button.ghost {
  background: var(--card);
  color: var(--ink);
  box-shadow: none;
  font-weight: 700;
}
button.copy {
  background: var(--highlight);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 999px;
  box-shadow: none;
  min-height: 30px;
  padding: 4px 11px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}
.field-row .row-head .copy + .copy {
  background: var(--card);
  color: var(--muted);
}
:focus-visible { outline: 3px solid var(--highlight); outline-offset: 2px; }

/* ---------- App-Header ---------- */
.app-header {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 3px 12px;
  margin-bottom: 14px;
}
.app-header::before {
  content: "Listing-Werkbank";
  grid-column: 1 / -1;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}
.app-header h1 { margin: 0; }
#btn-logout {
  min-height: 30px;
  padding: 5px 13px;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 999px;
}

/* ---------- Schrittfolge ---------- */
.steps {
  list-style: none;
  display: flex;
  gap: 6px;
  padding: 0;
  margin: 0 0 14px;
}
.steps li {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 5px 9px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.57rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}
.steps li.active { background: var(--highlight); box-shadow: 2px 2px 0 var(--ink); }

/* ---------- Upload ---------- */
.dropzone {
  position: relative;
  display: grid;
  place-items: center;
  gap: 7px;
  min-height: 180px;
  padding: 24px 20px 30px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  background: var(--paper-2);
  box-shadow: var(--shadow-hard);
  cursor: pointer;
  text-align: center;
  font-family: var(--font-body);
  font-size: 1.1rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  text-transform: none;
  color: var(--ink);
}
.dropzone .drop-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: var(--accent);
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
}
.dropzone .drop-icon svg { width: 34px; height: 34px; }
.dropzone small {
  font-family: var(--font-body);
  font-weight: 500;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: none;
}
.dropzone::after {
  content: "";
  width: 76px;
  height: 15px;
  margin-top: 3px;
  background: repeating-linear-gradient(90deg, var(--accent) 0 2px, transparent 2px 5px, var(--accent) 5px 8px, transparent 8px 11px);
}

.preview-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0 4px; align-items: center; }
.preview-item {
  position: relative;
  padding: 5px 5px 15px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: var(--card);
  box-shadow: 3px 3px 0 var(--ink);
  transform: rotate(-2deg);
}
.preview-item:nth-child(2n) { transform: rotate(2deg); }
.preview-item::after {
  content: "FOTO";
  position: absolute;
  left: 7px;
  bottom: 2px;
  font-family: var(--font-mono);
  font-size: 0.52rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.preview-row img {
  display: block;
  width: 58px;
  height: 52px;
  object-fit: cover;
  border-radius: 4px;
  border: 0;
  background: var(--line);
}
.preview-item .remove-img {
  position: absolute;
  top: -9px;
  right: -9px;
  width: 24px;
  height: 24px;
  min-height: 0;
  padding: 0;
  border-radius: 999px;
  background: var(--danger);
  color: var(--card);
  font-size: 0.68rem;
  font-weight: 900;
  display: grid;
  place-items: center;
  border: 2px solid var(--ink);
  box-shadow: none;
}
#image-count {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  margin: 2px 0 14px auto;
  padding: 3px 10px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--highlight);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
#input-notes { min-height: 108px; }

.platforms {
  border: none;
  padding: 0;
  margin: 12px 0 0;
  background: transparent;
  display: grid;
  gap: 8px;
}
.platforms legend {
  padding: 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}
.seg {
  display: flex;
  gap: 0;
  padding: 4px;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 14px;
  box-shadow: 3px 3px 0 var(--ink);
}
.seg label {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--muted);
  cursor: pointer;
}
.seg input[type="radio"] {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}
.seg label:has(input:checked) { background: var(--accent); color: var(--ink); font-weight: 800; }
.seg label:has(input:focus-visible) { outline: 3px solid var(--highlight); outline-offset: 2px; }

.cta-bar {
  position: sticky;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 14px);
  padding: 10px 0 6px;
  margin-top: 14px;
  background: linear-gradient(to top, var(--paper) 72%, transparent);
  z-index: 5;
}
.cta-bar .msg { text-align: center; margin: 5px 0 0; }

/* ---------- Bottom-Nav ---------- */
.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  width: min(100% - 32px, 420px);
  display: flex;
  gap: 5px;
  padding: 6px;
  background: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 9px 22px rgba(25, 23, 19, 0.3);
  z-index: 40;
}
.nav-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--paper-2);
  box-shadow: none;
  font-size: 0.9rem;
  font-weight: 700;
}
.nav-item .nav-icon { font-size: 1.05rem; font-weight: 900; }
.nav-item.active { background: var(--accent); color: var(--ink); font-weight: 900; }

/* ---------- Produktliste ---------- */
.product-list { list-style: none; margin: 0; padding: 4px 0 0; display: grid; gap: 16px; }
.product-item {
  position: relative;
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 18px;
  box-shadow: var(--shadow-hard);
  padding: 14px 12px 14px 29px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  overflow: hidden;
}
.product-item::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 50%;
  width: 13px;
  height: 13px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  transform: translateY(-50%);
}
.product-item::after {
  content: "";
  position: absolute;
  right: 15px;
  bottom: 13px;
  width: 54px;
  height: 14px;
  background: repeating-linear-gradient(90deg, var(--ink) 0 2px, transparent 2px 4px, var(--ink) 4px 7px, transparent 7px 10px);
  opacity: 0.9;
}
.product-item:hover { background: var(--paper-2); }
.product-item > img {
  width: 58px;
  height: 64px;
  object-fit: cover;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: var(--line);
  box-shadow: 2px 2px 0 var(--ink);
}
.product-item .prod-meta { flex: 1; display: grid; gap: 5px; min-width: 0; padding-bottom: 13px; }
.product-item .prod-title {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 0.98rem;
  font-weight: 900;
  line-height: 1.12;
  letter-spacing: -0.015em;
}
.product-item .prod-sub { font-size: 0.76rem; color: var(--muted); line-height: 1.25; }

.badge {
  align-self: flex-start;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 5px 11px;
  border: 2px solid currentColor;
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--muted);
  white-space: nowrap;
}
.badge.pending { background: var(--warn-bg); color: var(--muted); }
.badge.running { background: var(--info-bg); color: var(--info); }
.badge.done { background: var(--ok-bg); color: var(--ok); }
.badge.failed { background: var(--danger-bg); color: var(--danger); }
#detail-status { justify-self: start; }
#products-empty {
  margin-top: 18px;
  padding: 24px 18px;
  border: 2px solid var(--ink);
  border-radius: 18px;
  background: var(--card);
  box-shadow: var(--shadow-hard);
  text-align: center;
  color: var(--ink-soft);
}

/* ---------- Skeleton ---------- */
.product-item.skeleton { pointer-events: none; min-height: 82px; }
.skeleton .sk-block {
  border-radius: 8px;
  background: linear-gradient(90deg, var(--line) 25%, var(--paper-2) 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
.skeleton .sk-thumb { width: 52px; height: 52px; border-radius: 12px; }
.skeleton .sk-line { height: 12px; }
.skeleton .sk-line.w1 { width: 60%; }
.skeleton .sk-line.w2 { width: 35%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Detail-Sheet ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(53, 49, 41, 0.58);
  display: grid;
  place-items: end center;
  z-index: 50;
  overscroll-behavior: contain;
}
.sheet {
  background: var(--paper);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: 28px 28px 0 0;
  border: 2px solid var(--ink);
  border-bottom: none;
  box-shadow: 0 -12px 30px rgba(25, 23, 19, 0.3);
  padding: 8px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  display: grid;
  gap: 14px;
}
.sheet::before {
  content: "";
  width: 46px;
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  margin: 4px auto 0;
}
.overlay header, .sheet header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.sheet header h2 {
  flex: 1;
  font-size: 1.45rem;
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.035em;
}
#btn-close {
  min-height: 30px;
  padding: 5px 12px;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 999px;
}
.detail-images { display: flex; gap: 11px; overflow-x: auto; padding: 4px 2px 7px; }
.detail-images img {
  width: 70px;
  height: 76px;
  object-fit: cover;
  padding: 5px 5px 15px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background: var(--card);
  box-shadow: 3px 3px 0 var(--ink);
}
.detail-images img:nth-child(odd) { transform: rotate(-1.5deg); }
.detail-images img:nth-child(even) { transform: rotate(1.5deg); }
#detail-fields { display: grid; gap: 12px; }

.field-row {
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 15px;
  box-shadow: 3px 3px 0 var(--ink);
  padding: 12px;
  display: grid;
  gap: 9px;
}
.field-row .row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 7px;
}
.field-row .key {
  flex: 1;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.64rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}
.field-row textarea {
  width: 100%;
  min-height: 66px;
  max-height: 240px;
  font-size: 0.91rem;
  border-radius: 10px;
  field-sizing: content;
}

/* ---------- Chat ---------- */
#chat-box {
  background: var(--ink);
  color: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: 16px;
  box-shadow: 3px 3px 0 var(--accent);
  padding: 0;
  overflow: hidden;
}
#chat-box summary {
  list-style: none;
  padding: 15px 16px;
  font-size: 0.98rem;
  font-weight: 900;
  color: var(--paper-2);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#chat-box summary::-webkit-details-marker { display: none; }
#chat-box summary::after { content: "›"; color: var(--highlight); font-size: 1.25rem; font-weight: 900; }
#chat-box[open] { background: var(--card); color: var(--ink); box-shadow: 3px 3px 0 var(--ink); }
#chat-box[open] summary { color: var(--ink); border-bottom: 2px solid var(--line); }
#chat-box[open] summary::after { content: "⌄"; color: var(--accent); }
.chat-log { display: grid; gap: 10px; max-height: 280px; overflow-y: auto; margin: 0; padding: 14px; }
.chat-msg {
  padding: 10px 12px;
  border: 2px solid var(--ink);
  border-radius: 13px;
  box-shadow: 2px 2px 0 var(--ink);
  max-width: 82%;
  font-size: 0.86rem;
  line-height: 1.35;
}
.chat-msg.user { background: var(--accent); color: var(--ink); justify-self: end; font-weight: 700; }
.chat-msg.assistant { background: var(--paper-2); color: var(--ink); justify-self: start; }
#form-chat {
  display: flex;
  gap: 8px;
  padding: 0 14px 14px;
  border: none;
  background: transparent;
  box-shadow: none;
  margin: 0;
}
#form-chat input { flex: 1; border-radius: 999px; }
#form-chat button {
  width: 46px;
  min-width: 46px;
  border-radius: 999px;
  padding: 0;
  font-size: 1.15rem;
  font-weight: 900;
  box-shadow: none;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 20px);
  transform: translateX(-50%);
  background: var(--ink);
  border: 2px solid var(--ink);
  color: var(--paper-2);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 700;
  z-index: 60;
  box-shadow: 0 8px 20px rgba(25, 23, 19, 0.28);
}

@media (min-width: 560px) {
  .view { padding-left: 0; padding-right: 0; }
  .sheet { max-width: 540px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}
