/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --bg2:       #161b27;
  --bg3:       #1e2536;
  --border:    #2a3347;
  --text:      #e2e8f0;
  --text2:     #94a3b8;
  --accent:    #f97316;
  --accent2:   #3b82f6;
  --success:   #22c55e;
  --danger:    #ef4444;
  --warn:      #f59e0b;
  --radius:    8px;
  --topbar-h:  52px;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: 'Segoe UI', system-ui, sans-serif; font-size: 14px; }

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; outline: none; font-family: inherit; font-size: 13px; }
select, input { font-family: inherit; font-size: 13px; color: var(--text); }

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h);
  background: var(--bg2); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 32px; padding: 0 24px;
  z-index: 100;
}
.topbar-brand { font-size: 16px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.topbar-nav   { display: flex; gap: 4px; }
.nav-tab {
  padding: 6px 16px; border-radius: var(--radius); color: var(--text2);
  transition: all .15s;
}
.nav-tab:hover  { background: var(--bg3); color: var(--text); }
.nav-tab.active { background: var(--accent); color: #fff; font-weight: 600; }

/* ── Pages ────────────────────────────────────────────────────────────────── */
#app      { padding-top: var(--topbar-h); height: 100%; display: flex; flex-direction: column; }
.page     { display: none; padding: 20px; flex: 1; overflow: hidden; min-height: 0; }
.page.active { display: flex; flex-direction: column; }
/* Trend page needs vertical scroll for small screens */
#page-trend { overflow-y: auto; }
/* Monitor page also needs scroll */
#page-monitor { overflow-y: auto; }

/* ── Trend page layout ────────────────────────────────────────────────────── */
.trend-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
  flex: 1;
  min-height: 0;
}

/* ── Filter panel ─────────────────────────────────────────────────────────── */
.filter-panel {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  overflow-y: auto; display: flex; flex-direction: column; gap: 12px;
}
.filter-section { display: flex; flex-direction: column; gap: 6px; }
.filter-section.inline { flex-direction: row; align-items: center; gap: 16px; flex-wrap: wrap; }
.filter-label { font-size: 11px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; }
.hint { font-size: 11px; font-weight: 400; color: var(--text2); text-transform: none; }

.sel-base {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; color: var(--text); width: 100%;
}
.sel-base:focus { border-color: var(--accent2); outline: none; }

/* ── Product / Range buttons ──────────────────────────────────────────────── */
.product-btns, .range-btns { display: flex; flex-wrap: wrap; gap: 5px; }
.prod-btn, .range-btn {
  padding: 5px 10px; border-radius: 5px;
  background: var(--bg3); border: 1px solid var(--border); color: var(--text2);
  transition: all .15s; font-size: 12px;
}
.prod-btn:hover, .range-btn:hover { border-color: var(--accent2); color: var(--text); }
.prod-btn.active  { background: var(--accent);  border-color: var(--accent);  color: #fff; font-weight: 600; }
.range-btn.active { background: var(--accent2); border-color: var(--accent2); color: #fff; font-weight: 600; }

/* ── Compare list ─────────────────────────────────────────────────────────── */
.compare-list { display: flex; flex-direction: column; gap: 4px; }
.compare-item {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg3); border-radius: 5px; padding: 4px 8px; font-size: 12px;
}
.compare-item .rm { color: var(--danger); cursor: pointer; font-size: 14px; line-height: 1; }
.compare-item .rm:hover { opacity: .7; }

/* ── Latest prices ────────────────────────────────────────────────────────── */
.latest-row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.latest-row:last-child { border-bottom: none; }
.latest-price { color: var(--accent); font-weight: 600; }

/* ── Chart area ───────────────────────────────────────────────────────────── */
.chart-area {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  min-height: 0; overflow: hidden;
}
.chart-header { display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.chart-title  { font-size: 15px; font-weight: 600; color: var(--text); }
.echarts-box  { flex: 1; min-height: 0; }

/* ── Stat cards ───────────────────────────────────────────────────────────── */
.stat-cards { display: flex; gap: 12px; flex-wrap: nowrap; flex-shrink: 0; }
.stat-card  {
  flex: 1; min-width: 0;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px;
}
.stat-label { font-size: 11px; color: var(--text2); margin-bottom: 4px; }
.stat-value { font-size: 18px; font-weight: 700; color: var(--accent); }
.stat-sub   { font-size: 11px; color: var(--text2); margin-top: 2px; }

/* ── Map page ─────────────────────────────────────────────────────────────── */
.map-controls { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; flex-shrink: 0; margin-bottom: 12px; }
.map-table-wrap { display: none; }
.map-breadcrumb { font-size: 13px; margin-left: auto; }

/* Map body: chart + side panel — takes all remaining height in page */
.map-body {
  flex: 1; min-height: 0;
  display: flex; gap: 12px;
}

.map-chart-box { flex: 1; min-height: 0; min-width: 0; }
.map-side-panel {
  width: 280px; flex-shrink: 0;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.map-side-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--text1); flex-shrink: 0;
}
.map-side-close {
  cursor: pointer; color: var(--text2); font-size: 18px; line-height: 1; padding: 0 2px;
}
.map-side-close:hover { color: var(--text1); }
.map-side-body { overflow-y: auto; flex: 1; padding: 8px; }

/* ── Monitor page ─────────────────────────────────────────────────────────── */
.monitor-top {
  display: grid; grid-template-columns: 380px 1fr; gap: 16px; margin-bottom: 16px;
}
.monitor-mid {
  display: grid; grid-template-columns: 380px 1fr; gap: 16px; margin-bottom: 16px;
}

/* ── Overview cards ───────────────────────────────────────────────────────── */
.overview-cards { display: flex; flex-direction: row; gap: 12px; }
.ov-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px; flex: 1;
}
.ov-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }
.ov-value { font-size: 26px; font-weight: 700; color: var(--accent); }

/* ── Progress card ────────────────────────────────────────────────────────── */
.progress-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px;
  display: flex; flex-direction: column; gap: 12px;
}
.progress-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.progress-header span { font-size: 14px; font-weight: 600; }
.crawl-btns { display: flex; gap: 8px; }
.progress-bar-wrap { display: flex; align-items: center; gap: 10px; }
.progress-bar-bg   { flex: 1; height: 10px; background: var(--bg3); border-radius: 5px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--accent2); border-radius: 5px; transition: width .3s; width: 0%; }
.progress-pct      { font-size: 13px; font-weight: 600; color: var(--accent2); min-width: 36px; text-align: right; }
.progress-detail   { font-size: 12px; color: var(--text2); }

/* ── Product stats card ───────────────────────────────────────────────────── */
.product-stats-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.prod-bar-row { margin-bottom: 10px; }
.prod-bar-label { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.prod-bar-name  { color: var(--text); }
.prod-bar-count { color: var(--text2); }
.prod-bar-bg    { height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden; }
.prod-bar-fill  { height: 100%; border-radius: 4px; background: var(--accent2); transition: width .4s; }

/* ── Log card ─────────────────────────────────────────────────────────────── */
.log-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.log-header { display: flex; justify-content: space-between; align-items: center; }
.log-toggle { font-size: 12px; color: var(--text2); display: flex; align-items: center; gap: 4px; cursor: pointer; }
.log-window {
  background: #0a0d14; border: 1px solid var(--border);
  border-radius: 6px; padding: 10px;
  height: 280px; overflow-y: auto;
  font-family: 'Consolas', 'Courier New', monospace; font-size: 12px;
  line-height: 1.6;
}
.log-line        { color: var(--text2); }
.log-line.ok     { color: var(--success); }
.log-line.error  { color: var(--danger); }
.log-line.warn   { color: var(--warn); }
.log-line.info   { color: var(--accent2); }
.log-line.skip   { color: #64748b; }

/* ── History card ─────────────────────────────────────────────────────────── */
.history-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.card-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  background: var(--bg3); color: var(--text2);
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border);
}
.data-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); color: var(--text); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg3); }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-primary   { background: var(--accent);  color: #fff; border-radius: 6px; padding: 7px 14px; font-weight: 600; transition: opacity .15s; }
.btn-secondary { background: var(--accent2); color: #fff; border-radius: 6px; padding: 7px 14px; font-weight: 600; transition: opacity .15s; }
.btn-danger    { background: var(--danger);  color: #fff; border-radius: 6px; padding: 7px 14px; font-weight: 600; transition: opacity .15s; }
.btn-ghost     { background: transparent; color: var(--text2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; transition: all .15s; }
.btn-sm        { padding: 5px 10px; font-size: 12px; }
.btn-primary:hover, .btn-secondary:hover, .btn-danger:hover { opacity: .85; }
.btn-ghost:hover { border-color: var(--text2); color: var(--text); }

/* ── Status badges ────────────────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge-done     { background: rgba(34,197,94,.15);  color: var(--success); }
.badge-running  { background: rgba(59,130,246,.15); color: var(--accent2); }
.badge-stopped  { background: rgba(148,163,184,.1); color: var(--text2); }
.badge-error    { background: rgba(239,68,68,.15);  color: var(--danger); }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }
