:root {
  --bg: #0f172a;
  --bg-panel: #1e293b;
  --bg-elevated: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --border: #475569;
  --price: #dc2626;
  --product: #16a34a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; }

.badge {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.badge.ok { color: #4ade80; border-color: #166534; }
.badge.err { color: #f87171; border-color: #7f1d1d; }

.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--accent); background: rgba(59,130,246,.08); }

.drop-icon { font-size: 44px; }
.link { color: var(--accent); text-decoration: underline; }
small { color: var(--text-dim); }

.preview { max-width: 100%; max-height: 340px; border-radius: 8px; object-fit: contain; }

.hidden { display: none !important; }

.upload-actions { display: flex; gap: 12px; margin-top: 16px; }

.btn {
  flex: 1;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 15px;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-elevated); }

.spinner-wrap { text-align: center; padding: 48px 0; }
.spinner {
  width: 44px; height: 44px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.result-grid { display: grid; grid-template-columns: 1fr 320px; gap: 20px; }
@media (max-width: 1100px) { .result-grid { grid-template-columns: 1fr; } }

.result-image-wrap { margin: 0; }
#result-image { width: 100%; border-radius: 8px; border: 1px solid var(--border); }
figcaption { margin-top: 8px; color: var(--text-dim); font-size: 13px; }
.legend { margin-right: 16px; color: var(--text-dim); }

.result-info h2 { margin: 0 0 12px; font-size: 17px; }
.cards { display: flex; flex-direction: column; gap: 12px; }
.card { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--bg-elevated); }
.card-head { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 6px; }
.card-num {
  flex: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-sub { color: var(--text-dim); font-size: 14px; margin-top: 2px; }
.fields { margin: 0; }
.field { padding: 8px 0; border-bottom: 1px solid var(--border); }
.field:last-child { border-bottom: none; }
.field dt { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.field dd { margin: 4px 0 0; font-size: 15px; word-break: break-word; }
.mono { font-family: Consolas, monospace; font-size: 13px !important; }

.result-actions { display: flex; gap: 10px; margin-top: 16px; }

.error {
  background: rgba(220,38,38,.12);
  border: 1px solid #7f1d1d;
  color: #fca5a5;
  border-radius: 8px;
  padding: 12px 16px;
  margin-top: 16px;
  font-size: 14px;
}

.file-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.file-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 1;
}
.file-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-remove {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(15,23,42,.85);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.file-remove:hover { background: var(--price); }

.progress {
  margin-top: 14px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
}

.gallery {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: 80vh;
  overflow-y: auto;
  padding-right: 4px;
}
.gallery-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  background: var(--bg-panel);
}
.gallery-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.gallery-item-title { font-size: 15px; font-weight: 600; }
.gallery-item-actions { display: flex; gap: 8px; }
.btn-sm { flex: none; padding: 6px 12px; font-size: 13px; }
.gallery-item-body {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 16px;
}
@media (max-width: 1100px) { .gallery-item-body { grid-template-columns: 1fr; } }
.gallery-figure { margin: 0; }
.gallery-figure img { width: 100%; border-radius: 8px; border: 1px solid var(--border); }
.gallery-info h3 { margin: 0 0 12px; font-size: 16px; }
.gallery-error .gallery-item-error {
  color: #fca5a5;
  font-size: 14px;
}

.table-section { grid-column: 1 / -1; }
.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.table-head h2 { margin: 0; font-size: 17px; }
.csv-btn { flex: none; }
.table-scroll { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.data-table th,
.data-table td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th {
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.data-table tbody tr:hover { background: var(--bg-elevated); }
