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

:root {
  --bg-primary:    #1b2635;
  --bg-secondary:  #17212f;
  --bg-card:       #233044;
  --bg-card-hover: #29374d;
  --bg-input:      #1d2938;
  --border:        rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.15);
  --text-primary:  #e8eaf0;
  --text-secondary:#a8b0c0;
  --text-muted:    #525870;
  --accent:        #466fe9;
  --accent-hover:  #6b91ff;
  --accent-alpha:  rgba(79,124,255,.18);
  --green:         #22c55e;
  --green-bg:      rgba(34,197,94,.12);
  --red:           #ef4444;
  --red-bg:        rgba(239,68,68,.12);
  --shadow-sm:     0 1px 3px rgba(0,0,0,.4);
  --shadow-lg:     0 8px 32px rgba(0,0,0,.6);
}

body {
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────── */
.header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.header-icon {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 16px;
}
.header h1 { font-size: 1rem; font-weight: 600; }
.header p  { font-size: .8rem; color: var(--text-secondary); }

/* ── Main layout ─────────────────────────────────────── */
.main {
  flex: 1;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 0;
  min-height: 0;
}

/* ── Sidebar ─────────────────────────────────────────── */
.sidebar {
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}

.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-label {
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-secondary);
}
.form-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: .9rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-alpha);
}
.form-input::placeholder { color: var(--text-muted); }

/* ── Template selector ───────────────────────────────── */
.template-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.template-card {
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-card);
}
.template-card:hover { border-color: var(--border-strong); background: var(--bg-card-hover); }
.template-card.active { border-color: var(--accent); background: var(--accent-alpha); }
.template-thumb {
  width: 100%;
  aspect-ratio: 4/3;
  border-radius: 6px;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .65rem;
  color: var(--text-muted);
  overflow: hidden;
}
.template-thumb svg { width: 100%; height: 100%; }
.template-name { font-size: .78rem; font-weight: 600; }
.template-desc { font-size: .7rem; color: var(--text-secondary); }

/* ── Button ──────────────────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 8px;
  border: none;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s, opacity .15s;
  width: 100%;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-card-hover); }

.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ── Spinner ─────────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Alert ───────────────────────────────────────────── */
.alert {
  padding: 12px 14px;
  border-radius: 8px;
  font-size: .83rem;
  line-height: 1.5;
  display: none;
}
.alert.show { display: block; }
.alert-error  { background: var(--red-bg);   border: 1px solid rgba(239,68,68,.25);  color: #f87171; }
.alert-success{ background: var(--green-bg); border: 1px solid rgba(34,197,94,.25);  color: #4ade80; }

/* ── Product info card (post-scrape) ─────────────────── */
.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: none;
  gap: 12px;
}
.product-card.show { display: flex; }
.product-thumb {
  width: 56px; height: 56px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-input);
}
.product-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.product-title { font-size: .85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.product-price { font-size: .8rem; color: var(--accent); font-weight: 700; }
.product-meta  { font-size: .72rem; color: var(--text-secondary); }

/* ── Preview area ────────────────────────────────────── */
.preview-area {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  overflow: hidden;
}
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.preview-label { font-size: .78rem; font-weight: 600; color: var(--text-secondary); }
.preview-actions { display: flex; gap: 8px; }
.preview-actions .btn { width: auto; padding: 7px 14px; font-size: .8rem; }

.preview-frame-wrap {
  flex: 1;
  padding: 20px;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.preview-frame-wrap iframe {
  width: 100%;
  max-width: 960px;
  min-height: 600px;
  border: none;
  border-radius: var(--radius, 10px);
  background: #fff;
  box-shadow: var(--shadow-lg);
  display: block;
}

/* ── Empty state ─────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
}
.empty-state svg { width: 48px; height: 48px; opacity: .4; }
.empty-state h3 { font-size: 1rem; color: var(--text-secondary); }
.empty-state p  { font-size: .85rem; max-width: 280px; line-height: 1.6; }

/* ── Divider ─────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}

/* ── Success button ──────────────────────────────────────── */
.btn-success { background: #16a34a; color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }

/* ── AI button ───────────────────────────────────────────── */
.btn-ai {
  background: linear-gradient(135deg, #6d28d9, #4f46e5);
  color: #fff;
  border: none;
}
.btn-ai:hover:not(:disabled) { background: linear-gradient(135deg, #7c3aed, #6366f1); }
.btn-ai:disabled { opacity: .5; }

/* ── Options checkboxes ──────────────────────────────────── */
.options-row { display: flex; gap: 16px; }
.opt-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
.opt-check input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Icon picker ─────────────────────────────────────────── */
.icon-picker-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.icon-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.icon-picker-count {
  font-size: .68rem;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 8px;
}
.ipf-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ipf-name {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ipf-badge-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ipf-badge-label {
  font-size: .68rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.ipf-badge {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-secondary);
  outline: none;
  transition: border-color .15s;
}
.ipf-badge:focus { border-color: var(--accent); }
.ipf-icons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.ipf-icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
  flex-shrink: 0;
  padding: 0;
}
.ipf-icon-btn svg {
  width: 14px;
  height: 14px;
  pointer-events: none;
}
.ipf-icon-btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
  color: var(--text-primary);
}
.ipf-icon-btn.selected {
  border-color: var(--accent);
  background: var(--accent-alpha);
  color: var(--accent);
}
.ipf-del-btn {
  align-self: flex-start;
  margin-top: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: border-color .15s, background .15s, color .15s;
}
.ipf-del-btn:hover {
  border-color: var(--red);
  background: var(--red-bg);
  color: var(--red);
}

@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .preview-frame-wrap iframe { min-height: 500px; }
}
