/* ── Design Tokens ───────────────────────────────────────────────────────────── */
:root {
  --bg-0:      #090c12;
  --bg-1:      #0f1623;
  --bg-2:      #161e2e;
  --bg-3:      #1d2740;
  --bg-4:      #243050;

  --border:         #1e2d45;
  --border-strong:  #2a3e5e;

  --text-1: #e2eaf4;
  --text-2: #8fa3bc;
  --text-3: #566b85;

  --teal-300: #5eead4;
  --teal-400: #2dd4bf;
  --teal-500: #14b8a6;
  --teal-600: #0d9488;
  --teal-glow: rgba(45, 212, 191, 0.10);
  --teal-glow-strong: rgba(45, 212, 191, 0.18);

  --success:    #22c55e;
  --success-bg: rgba(34, 197, 94, 0.10);
  --danger:     #f43f5e;
  --danger-bg:  rgba(244, 63, 94, 0.10);
  --warning:    #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.10);
  --info:       #60a5fa;
  --info-bg:    rgba(96, 165, 250, 0.10);

  --radius-sm: 5px;
  --radius:    8px;
  --radius-lg: 12px;
  --radius-xl: 18px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow:    0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.6);

  --sidebar-w: 220px;
  --transition: 150ms ease;
}

/* ── Reset ───────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-1);
  background: var(--bg-0);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--teal-400); text-decoration: none; }
a:hover { color: var(--teal-300); }
img { max-width: 100%; display: block; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, select, textarea { font: inherit; }

/* ── Auth Layout (login / setup) ─────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 60% 50% at 50% 0%, rgba(20,184,166,0.08) 0%, transparent 70%),
    var(--bg-0);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.auth-logo .logo-icon {
  width: 40px;
  height: 40px;
  background: var(--teal-glow-strong);
  border: 1px solid var(--teal-500);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.auth-logo h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.3px;
}

.auth-logo span {
  color: var(--teal-400);
}

.auth-subtitle {
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 28px;
  line-height: 1.6;
}

.auth-error {
  background: var(--danger-bg);
  border: 1px solid rgba(244, 63, 94, 0.25);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.auth-error.visible { display: block; }

/* ── Dashboard Layout ────────────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo .logo-icon {
  width: 32px;
  height: 32px;
  background: var(--teal-glow-strong);
  border: 1px solid rgba(45,212,191,0.3);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-logo .logo-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.3px;
}
.sidebar-logo .logo-name span { color: var(--teal-400); }

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  user-select: none;
}

.nav-item:hover {
  background: var(--bg-3);
  color: var(--text-1);
}

.nav-item.active {
  background: var(--teal-glow-strong);
  color: var(--teal-300);
  border-left: 2px solid var(--teal-400);
  padding-left: 8px;
}

.nav-item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.8;
}
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
}

/* ── Main content ────────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.page-header {
  padding: 20px 28px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-1);
  letter-spacing: -0.3px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 2px;
}

.page-body {
  padding: 20px 28px 32px;
  flex: 1;
}

/* ── Section visibility ──────────────────────────────────────────────────────── */
.section { display: none; }
.section.active { display: block; }

/* ── Stats Grid ──────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--teal-600), var(--teal-400));
  opacity: 0;
  transition: opacity var(--transition);
}

.stat-card:hover { border-color: var(--border-strong); }
.stat-card:hover::before { opacity: 1; }

.stat-icon {
  width: 32px; height: 32px;
  background: var(--teal-glow);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  font-size: 16px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--teal-300);
  letter-spacing: -0.5px;
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 16px;
}

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

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
}

.card-body { padding: 16px 20px; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--transition), color var(--transition), border-color var(--transition), opacity var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--teal-500);
  color: #fff;
  border: 1px solid var(--teal-500);
}
.btn-primary:hover:not(:disabled) { background: var(--teal-600); border-color: var(--teal-600); }

.btn-secondary {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-3); color: var(--text-1); }

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border: 1px solid transparent;
  padding: 6px 10px;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg-3); color: var(--text-1); }

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(244,63,94,0.2);
}
.btn-danger:hover:not(:disabled) { background: rgba(244,63,94,0.2); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

.btn-full { width: 100%; justify-content: center; padding: 10px 14px; font-size: 14px; }

/* ── Forms ───────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}

.form-input,
.form-select {
  width: 100%;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-1);
  padding: 9px 12px;
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  appearance: none;
}

.form-input::placeholder { color: var(--text-3); }

.form-input:focus,
.form-select:focus {
  border-color: var(--teal-500);
  box-shadow: 0 0 0 3px var(--teal-glow);
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23566b85' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.form-hint {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 4px;
}

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

/* ── Toggle Switch ───────────────────────────────────────────────────────────── */
.toggle {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle input { display: none; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg-4);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: var(--text-3);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
}

.toggle input:checked + .toggle-track {
  background: var(--teal-glow-strong);
  border-color: var(--teal-500);
}
.toggle input:checked + .toggle-track::after {
  background: var(--teal-400);
  transform: translateX(16px);
}

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger   { background: var(--danger-bg);  color: var(--danger); }
.badge-warning  { background: var(--warning-bg); color: var(--warning); }
.badge-info     { background: var(--info-bg);    color: var(--info); }
.badge-neutral  { background: var(--bg-4);       color: var(--text-2); }

/* ── Tables ──────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-3); }

td {
  padding: 11px 14px;
  color: var(--text-1);
  vertical-align: middle;
}

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

/* ── Shop cards ──────────────────────────────────────────────────────────────── */
.shop-list { display: flex; flex-direction: column; gap: 12px; }

.shop-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--transition);
}
.shop-card:hover { border-color: var(--border-strong); }

.shop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  cursor: pointer;
}

.shop-header-left { display: flex; align-items: center; gap: 10px; }

.shop-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
}

.shop-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }

.shop-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.shop-chevron {
  width: 16px; height: 16px;
  color: var(--text-3);
  transition: transform var(--transition);
}
.shop-card.expanded .shop-chevron { transform: rotate(180deg); }

.url-list {
  border-top: 1px solid var(--border);
  display: none;
}
.shop-card.expanded .url-list { display: block; }

.url-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.url-item:last-child { border-bottom: none; }

.url-info { flex: 1; min-width: 0; }

.url-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
  margin-bottom: 3px;
}

.url-address {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 340px;
}

.url-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.url-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.shop-add-url {
  padding: 10px 18px;
  border-top: 1px solid var(--border);
}

/* ── Product image ───────────────────────────────────────────────────────────── */
.product-img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
}

.product-img-placeholder {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 18px;
}

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  transform: scale(0.96) translateY(8px);
  transition: transform var(--transition);
}

.modal-overlay.open .modal { transform: scale(1) translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-1);
}

.modal-close {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-3);
  transition: background var(--transition), color var(--transition);
}
.modal-close:hover { background: var(--bg-3); color: var(--text-1); }

.modal-body { padding: 18px 22px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 22px 18px;
  border-top: 1px solid var(--border);
}

/* ── Toast ───────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 11px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: all;
  animation: toast-in 200ms ease forwards;
  min-width: 240px;
  max-width: 360px;
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-danger  { border-left: 3px solid var(--danger); }
.toast.toast-warning { border-left: 3px solid var(--warning); }
.toast.toast-info    { border-left: 3px solid var(--info); }

.toast-out { animation: toast-out 180ms ease forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(16px); }
}

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

.empty-state-icon {
  font-size: 36px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state-text {
  font-size: 14px;
  color: var(--text-2);
  margin-bottom: 4px;
}

.empty-state-hint {
  font-size: 12px;
  color: var(--text-3);
}

/* ── Loading skeleton ────────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-3) 25%, var(--bg-4) 50%, var(--bg-3) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.4s infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}

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

/* ── Utility ─────────────────────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.ml-auto { margin-left: auto; }
.text-muted { color: var(--text-3); }
.text-sm { font-size: 12px; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Section header row ──────────────────────────────────────────────────────── */
.section-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-filter {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Settings sections ───────────────────────────────────────────────────────── */
.settings-group {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  margin-bottom: 16px;
}

.settings-group-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 16px;
}

/* ── Spinning loader ─────────────────────────────────────────────────────────── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--bg-4);
  border-top-color: var(--teal-400);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Scan status dot ─────────────────────────────────────────────────────────── */
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.ok      { background: var(--success); box-shadow: 0 0 4px var(--success); }
.status-dot.error   { background: var(--danger); }
.status-dot.pending { background: var(--text-3); }
