/* =====================================================================
   Kuwed Hunter — Professional UI
   Color palette derived from the Kuwed logo (purple + black)
   ===================================================================== */
:root {
  --primary: #6C5CE7;
  --primary-600: #5A4BD1;
  --primary-700: #4834D4;
  --primary-50: #F1EEFF;
  --primary-100: #E3DCFF;

  --ink: #14122A;
  --ink-2: #2A2740;
  --muted: #6B6A82;
  --line: #E7E5F0;
  --line-2: #F0EEF7;

  --bg: #F7F6FB;
  --surface: #FFFFFF;
  --surface-2: #FBFAFE;

  --success: #1FB58F;
  --success-50: #E6F7F1;
  --warning: #F59E0B;
  --danger: #E14C5A;
  --danger-50: #FDECEE;

  --shadow-sm: 0 1px 2px rgba(20, 18, 42, 0.06);
  --shadow:    0 6px 20px rgba(20, 18, 42, 0.08);
  --shadow-lg: 0 18px 40px rgba(20, 18, 42, 0.12);

  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 18px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at -10% -20%, rgba(108,92,231,0.10), transparent 60%),
    radial-gradient(900px 500px at 110% 0%, rgba(108,92,231,0.06), transparent 55%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column;
}

a { color: inherit; text-decoration: none; }
code { background: var(--primary-50); color: var(--primary-700); padding: 1px 6px; border-radius: 6px; font-size: 0.85em; }

/* ---------- Header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,0.85);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.header-inner {
  max-width: 1280px; margin: 0 auto;
  display: grid; grid-template-columns: auto 1fr auto;
  align-items: center; gap: 24px;
  padding: 12px 24px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { height: 38px; width: auto; display: block; }
.brand-name {
  font-weight: 700; font-size: 1rem; letter-spacing: 0.5px;
  color: var(--ink-2); padding: 4px 10px;
  background: var(--primary-50); border-radius: 8px;
}
.tabs { display: flex; gap: 4px; justify-content: center; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px;
  color: var(--muted); font-weight: 600; font-size: 0.92rem;
  transition: background .15s, color .15s;
}
.tab:hover { background: var(--primary-50); color: var(--primary-700); }
.tab.active {
  background: var(--ink); color: #fff;
  box-shadow: 0 6px 16px rgba(20,18,42,0.18);
}
.tab.active .tab-ico { fill: var(--primary); }
.tab-ico { width: 18px; height: 18px; fill: currentColor; }

.header-right { display: flex; align-items: center; gap: 8px; }
.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 999px;
  font-size: 0.85rem; color: var(--ink-2); font-weight: 600;
}
.user-ico { width: 16px; height: 16px; fill: var(--primary); }
.btn-ghost {
  background: transparent; border: 1px solid var(--line);
  border-radius: 999px; width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .15s, border-color .15s;
}
.btn-ghost:hover { background: var(--primary-50); border-color: var(--primary-100); }

/* ---------- Layout ---------- */
.app-main {
  flex: 1;
  max-width: 1280px; width: 100%;
  margin: 0 auto; padding: 28px 24px 48px;
}
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  flex-wrap: wrap; gap: 16px; margin-bottom: 24px;
}
.page-title { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.01em; }
.page-sub { color: var(--muted); margin-top: 4px; font-size: 0.95rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px;
}
.panel + .panel { margin-top: 20px; }
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.panel-head h2 { font-size: 1.05rem; font-weight: 700; }

/* ---------- Buttons ---------- */
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-700));
  color: #fff; border: none; padding: 11px 20px;
  border-radius: var(--radius-sm); font-weight: 600; font-size: 0.95rem;
  cursor: pointer; transition: transform .08s, box-shadow .15s, opacity .15s;
  box-shadow: 0 4px 14px rgba(108,92,231,0.32);
}
.btn-primary:hover { box-shadow: 0 6px 20px rgba(108,92,231,0.45); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn-primary.block { display: block; width: 100%; padding: 13px; }
.btn-success {
  background: linear-gradient(135deg, #2ec99f, var(--success));
  color: #fff; border: none; padding: 12px 22px;
  border-radius: var(--radius-sm); font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 14px rgba(31,181,143,0.32);
}
.btn-success:hover { box-shadow: 0 6px 20px rgba(31,181,143,0.45); }
.btn-link {
  background: transparent; border: none; color: var(--primary-700);
  font-weight: 600; cursor: pointer; padding: 6px 8px; border-radius: 6px;
}
.btn-link:hover { background: var(--primary-50); }

/* ---------- KPI cards ---------- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.kpi-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: linear-gradient(180deg, var(--primary), var(--primary-700));
}
.kpi-label { color: var(--muted); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.kpi-value { font-size: 2rem; font-weight: 800; margin-top: 6px; color: var(--ink); }
.kpi-trend { color: var(--muted); font-size: 0.8rem; margin-top: 4px; }
.kpi-trend.up { color: var(--success); }

/* ---------- Recent + quick actions ---------- */
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 20px; }
.recent-list { display: flex; flex-direction: column; gap: 10px; }
.recent-item {
  display: grid; grid-template-columns: 1fr auto auto; align-items: center;
  gap: 12px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--line-2);
}
.recent-item .name { font-weight: 600; color: var(--ink); }
.recent-item .meta { color: var(--muted); font-size: 0.82rem; }
.recent-item .pill {
  background: var(--primary-50); color: var(--primary-700);
  font-weight: 700; font-size: 0.78rem; padding: 4px 10px; border-radius: 999px;
}
.empty-state { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty-state .empty-ico { font-size: 2.4rem; margin-bottom: 8px; }
.empty-state p { margin-bottom: 14px; }

.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick-action {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--surface-2); border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); padding: 12px 14px; cursor: pointer;
  transition: border-color .15s, transform .08s, background .15s;
}
.quick-action:hover { border-color: var(--primary); background: var(--primary-50); }
.quick-action:active { transform: translateY(1px); }
.qa-ico { font-size: 1.4rem; }
.qa-text { display: flex; flex-direction: column; line-height: 1.2; }
.qa-text small { color: var(--muted); font-weight: 500; }

/* ---------- Search box (compare) ---------- */
.search-box { display: flex; gap: 10px; margin-bottom: 16px; }
.search-box input {
  flex: 1; padding: 13px 16px; border: 1.5px solid var(--line);
  border-radius: var(--radius-sm); font-size: 0.98rem; outline: none;
  background: var(--surface-2); transition: border-color .15s, background .15s;
}
.search-box input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 4px rgba(108,92,231,0.12); }

/* ---------- Loading ---------- */
.loading { text-align: center; padding: 28px; display: none; color: var(--muted); }
.loading.active { display: block; }
.spinner {
  width: 38px; height: 38px;
  border: 3px solid var(--line);
  border-top: 3px solid var(--primary);
  border-radius: 50%; animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Alerts ---------- */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); display: none; margin-bottom: 12px; font-size: 0.92rem; }
.alert.active { display: block; }
.alert-error { background: var(--danger-50); border: 1px solid #f7c5cc; color: #b3303d; }

/* ---------- Results cards ---------- */
.results-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 8px; }
@media (max-width: 760px) { .results-grid { grid-template-columns: 1fr; } }

.store-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column;
  transition: border-color .2s, box-shadow .2s;
}
.store-card.winner {
  border-color: var(--success);
  box-shadow: 0 0 0 3px var(--success-50), var(--shadow);
}
.store-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.store-name { font-weight: 700; font-size: 1.05rem; }
.winner-badge { background: var(--success); color: #fff; font-size: 0.72rem; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.winner-badge[hidden] { display: none; }

.store-card img {
  width: 100%; max-height: 200px; object-fit: contain;
  background: var(--surface-2); border-radius: var(--radius-sm);
  padding: 12px; margin: 8px 0;
}
.item-title {
  font-size: 0.94rem; line-height: 1.45; color: var(--ink-2);
  margin-bottom: 10px; min-height: 2.7em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.item-price { font-size: 1.55rem; font-weight: 800; color: var(--success); margin-bottom: 12px; letter-spacing: -0.01em; }
.item-link {
  display: inline-block; padding: 9px 16px;
  background: var(--ink); color: #fff;
  border-radius: var(--radius-sm); font-weight: 600; font-size: 0.86rem;
  text-align: center; transition: background .15s;
}
.item-link:hover { background: var(--primary-700); }
.no-result { color: var(--muted); font-size: 0.92rem; padding: 20px 0; text-align: center; }

/* ---------- File upload ---------- */
.file-upload-area {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 28px; text-align: center; cursor: pointer;
  margin: 14px 0; transition: border-color .15s, background .15s;
  background: var(--surface-2);
}
.file-upload-area:hover { border-color: var(--primary); background: var(--primary-50); }
.file-upload-area.has-file { border-color: var(--success); background: var(--success-50); }
.file-upload-area input[type="file"] { display: none; }
.file-upload-icon { font-size: 1.8rem; margin-bottom: 6px; }
.file-upload-name { color: var(--success); font-weight: 700; margin-top: 4px; }

.bulk-info {
  background: var(--primary-50); border: 1px solid var(--primary-100);
  color: var(--primary-700); border-radius: var(--radius-sm);
  padding: 12px; margin: 14px 0; text-align: center; display: none;
}
.bulk-info.active { display: block; }
.bulk-loading { text-align: center; padding: 20px; display: none; }
.bulk-loading.active { display: block; }
.progress-bar-container {
  width: 100%; height: 26px; background: var(--line-2);
  border-radius: 999px; margin-top: 12px; overflow: hidden; position: relative;
}
.progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--primary-700));
  border-radius: 999px; transition: width .8s linear;
}
.progress-bar-text {
  position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; font-size: 0.78rem; font-weight: 700; color: var(--ink);
}
.countdown-timer { font-size: 1.4rem; font-weight: 800; margin-top: 12px; font-variant-numeric: tabular-nums; color: var(--ink); }
.download-section { text-align: center; margin-top: 16px; display: none; }
.download-section.active { display: block; }

/* ---------- Utility ---------- */
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.bold { font-weight: 700; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }

/* ---------- Auto Collect ---------- */
.auto-progress .progress-bar {
  width: 100%; height: 14px; background: var(--line-2);
  border-radius: 999px; overflow: hidden; position: relative; margin: 0;
}
.auto-progress .progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--primary-700));
  border-radius: 999px; transition: width .6s ease;
}
.auto-stats { display: flex; gap: .5rem; align-items: center; font-size: .92rem; }
.auto-jobs-list { display: flex; flex-direction: column; gap: 10px; }
.auto-job {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; display: grid; grid-template-columns: 1fr auto;
  gap: 8px 12px; align-items: center; background: var(--surface);
}
.auto-job-meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.auto-job-label { font-weight: 700; word-break: break-word; }
.auto-job-sub { font-size: .82rem; color: var(--muted); }
.auto-job-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.auto-job .badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
}
.auto-job .badge.running   { background: #fff7d6; color: #8b6e00; }
.auto-job .badge.done      { background: #e1f7ec; color: #0f7a4a; }
.auto-job .badge.error     { background: #fde2e2; color: #a01a1a; }
.auto-job .badge.cancelled { background: var(--line-2); color: var(--muted); }

/* ---------- Auto Collect: marketplace cards ---------- */
.auto-mp-panel .mp-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.mp-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 22px 14px;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .15s, transform .15s, box-shadow .15s, background .15s;
  font: inherit; color: inherit;
}
.mp-card:hover {
  border-color: var(--primary);
  background: var(--primary-50);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.mp-card.active {
  border-color: var(--primary);
  background: linear-gradient(180deg, var(--primary-50), #fff);
  box-shadow: 0 0 0 4px rgba(99, 102, 241, .12);
}
.mp-card-ico { font-size: 2rem; line-height: 1; }
.mp-card-title { font-weight: 800; font-size: 1.05rem; }
.mp-card-sub { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.auto-actions {
  display: flex; gap: .8rem; align-items: center; flex-wrap: wrap;
  padding-top: 6px; border-top: 1px dashed var(--line); margin-top: 6px;
}
.btn-lg { padding: 12px 22px; font-size: 1rem; font-weight: 700; border-radius: var(--radius); }

/* ---------- Footer ---------- */
.app-footer {
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,0.6);
  text-align: center; padding: 14px;
  color: var(--muted); font-size: 0.82rem;
}

/* ---------- Login page ---------- */
.login-shell {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 36px 32px; width: 100%; max-width: 420px;
}
.login-logo { display: flex; justify-content: center; margin-bottom: 18px; }
.login-logo img { height: 56px; }
.login-title { text-align: center; font-size: 1.4rem; font-weight: 800; }
.login-sub { text-align: center; color: var(--muted); margin: 6px 0 22px; font-size: 0.92rem; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.85rem; color: var(--ink-2); }
.form-group input {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line);
  border-radius: var(--radius-sm); font-size: 0.98rem; outline: none;
  background: var(--surface-2);
}
.form-group input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 4px rgba(108,92,231,0.12); }

/* ---------- Collect Data: cascading + status ---------- */
.btn-ghost-pill {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 16px;
  font-weight: 600; color: var(--ink-2); cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-ghost-pill:hover { background: var(--primary-50); border-color: var(--primary-100); color: var(--primary-700); }

.status-strip {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  margin-bottom: 16px;
}
.status-pill {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 14px;
  box-shadow: var(--shadow-sm);
}
.status-pill b { font-weight: 700; }
.status-pill small { color: var(--muted); font-size: 0.85rem; }
.status-pill .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted); flex: 0 0 10px;
  box-shadow: 0 0 0 3px rgba(107,106,130,0.18);
}
.status-pill[data-status="idle"] .dot          { background: var(--success); box-shadow: 0 0 0 3px rgba(31,181,143,0.18); }
.status-pill[data-status="working"] .dot       { background: var(--warning); box-shadow: 0 0 0 3px rgba(245,158,11,0.22);
  animation: pulse 1.4s ease-in-out infinite; }
.status-pill[data-status="error"] .dot         { background: var(--danger);  box-shadow: 0 0 0 3px rgba(225,76,90,0.18); }
@keyframes pulse { 50% { transform: scale(1.25); opacity: .75; } }

.subtabs {
  display: inline-flex; background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px; margin-bottom: 16px; gap: 4px;
}
.subtab {
  background: transparent; border: 0; padding: 8px 16px;
  border-radius: 999px; font-weight: 600; color: var(--muted);
  cursor: pointer; font-size: 0.9rem;
}
.subtab:hover { color: var(--ink-2); }
.subtab.active { background: var(--ink); color: #fff; }

.cascade-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px;
}
.cascade-step { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.step-label {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; font-size: 0.92rem; color: var(--ink-2);
}
.step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 0.78rem; font-weight: 700;
}
.select {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line);
  border-radius: var(--radius-sm); font-size: 0.95rem; outline: none;
  background: var(--surface-2); color: var(--ink-2);
  transition: border-color .15s, background .15s;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%236B6A82' d='M6 8.5L1.5 4h9z'/></svg>");
  background-repeat: no-repeat; background-position: right 14px center;
  padding-right: 38px;
}
.select:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 4px rgba(108,92,231,0.12); }
.select:disabled { opacity: .55; cursor: not-allowed; }
.hint { color: var(--muted); font-size: 0.8rem; min-height: 1em; }

.seg-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.seg-opt {
  background: var(--surface-2); border: 1.5px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px;
  font-weight: 600; color: var(--ink-2); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: border-color .15s, background .15s, color .15s;
}
.seg-opt:hover { border-color: var(--primary); background: var(--primary-50); }
.seg-opt.active {
  border-color: var(--primary); background: var(--ink); color: #fff;
  box-shadow: 0 4px 14px rgba(108,92,231,0.30);
}
.seg-ico { font-size: 1.1rem; }

.mt-2 { margin-top: 12px; }

@media (max-width: 1300px) {
  .cascade-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 900px) {
  .cascade-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .cascade-grid { grid-template-columns: 1fr; }
  .status-strip { grid-template-columns: 1fr; }
}

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .quick-actions { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .header-inner { grid-template-columns: 1fr auto; row-gap: 8px; }
  .tabs { grid-column: 1 / -1; justify-content: flex-start; overflow-x: auto; }
  .brand-name { display: none; }
  .page-title { font-size: 1.35rem; }
}
