/* Runnex Logistics Sales Scraper — v2 */

:root, [data-theme="dark"] {
  --bg: #0b1220;
  --bg2: #111a2e;
  --surface: #151f35;
  --surface2: #1a2744;
  --border: #2a3a5c;
  --text: #eef2ff;
  --muted: #8b9cc0;
  --accent: #4d9fff;
  --accent2: #2e86de;
  --green: #3ecf8e;
  --red: #ff6b6b;
  --yellow: #f0c040;
  --purple: #b794f6;
  --cyan: #38d9f5;
  --shadow: 0 8px 32px rgba(0,0,0,.35);
  --radius: 14px;
  --tap: 48px;
  --font: 'DM Sans', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --header-bg: rgba(21, 31, 53, .92);
}

[data-theme="light"] {
  --bg: #f4f7fc;
  --bg2: #e8eef8;
  --surface: #ffffff;
  --surface2: #f8fafd;
  --border: #d4deef;
  --text: #1a2744;
  --muted: #5a6d8a;
  --accent: #1a6fd4;
  --accent2: #1256a8;
  --green: #1a9d5c;
  --red: #d93030;
  --yellow: #c48400;
  --purple: #7c4dff;
  --cyan: #0891b2;
  --shadow: 0 8px 32px rgba(26,39,68,.08);
  --header-bg: rgba(255,255,255,.92);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: background .25s, color .25s;
}

.hidden { display: none !important; }

/* ── Login ── */
.login-screen {
  position: relative;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(46,134,222,.25), transparent),
    var(--bg);
}

.login-theme-toggle {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  z-index: 10;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 36px 28px;
  box-shadow: var(--shadow);
}

.login-brand { text-align: center; margin-bottom: 28px; }
.logo-img {
  width: 56px; height: 56px;
  margin: 0 auto 14px;
  display: block;
  border-radius: 14px;
  object-fit: contain;
}
.header-logo {
  width: 42px; height: 42px;
  margin: 0;
  border-radius: 11px;
  flex-shrink: 0;
}
.login-brand h1 { font-size: 22px; font-weight: 700; }
.login-brand p { color: var(--muted); font-size: 14px; margin-top: 4px; }

.login-card label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}

.login-card input,
.panel input[type="password"],
.panel input[type="search"],
textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  padding: 12px 14px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}

.password-field {
  position: relative;
  display: flex;
  align-items: center;
}
.password-field input {
  width: 100%;
  padding-right: 46px;
}
.pw-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color .15s, background .15s;
}
.pw-toggle:hover { color: var(--text); background: var(--surface2); }
.pw-toggle svg { width: 20px; height: 20px; }
.pw-toggle.visible .icon-eye { display: none; }
.pw-toggle.visible .icon-eye-off { display: block !important; }
.pw-toggle .icon-eye-off.hidden { display: none; }
.login-card input:focus,
.panel input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-foot { text-align: center; font-size: 12px; color: var(--muted); margin-top: 20px; }

.form-error { color: var(--red); font-size: 13px; }
.form-msg { font-size: 13px; margin: 8px 0; }
.form-msg.ok { color: var(--green); }
.form-msg.err { color: var(--red); }

/* ── Header ── */
.app-header {
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 200;
}

.logo {
  width: 42px; height: 42px; flex-shrink: 0;
  background: linear-gradient(135deg, #1F4E79, var(--accent2));
  border-radius: 11px;
  display: grid; place-items: center;
  font-size: 20px;
}

.btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
  flex-shrink: 0;
}
.btn-logout:hover {
  background: color-mix(in srgb, var(--red) 12%, var(--surface2));
  border-color: color-mix(in srgb, var(--red) 40%, var(--border));
  color: var(--red);
}
.btn-logout:active { transform: scale(.97); }
.btn-logout:disabled { opacity: .5; cursor: not-allowed; }
.btn-logout svg { flex-shrink: 0; }

.title-wrap { flex: 1; min-width: 0; }
.title-wrap h1 { font-size: clamp(14px, 3.8vw, 17px); font-weight: 700; line-height: 1.2; }
.subtitle { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

.header-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
  display: grid; place-items: center;
  transition: background .15s, transform .1s;
}
.icon-btn:hover { background: var(--border); }
.icon-btn:active { transform: scale(.95); }

/* ── Tabs ── */
.tab-nav {
  display: flex;
  gap: 4px;
  padding: 10px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab {
  flex-shrink: 0;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab:hover { color: var(--text); background: var(--surface); }
.tab.active { background: var(--accent); color: #fff; }

.tab-badge {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 20px;
  background: rgba(255,255,255,.2);
}
.tab:not(.active) .tab-badge { background: var(--surface2); color: var(--muted); }

/* ── Layout ── */
.main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.layout-grid {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 16px;
  align-items: start;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.panel-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .6px;
}
.panel-header.row-between { display: flex; justify-content: space-between; align-items: center; }

.panel-body { padding: 16px; }
.panel-body.flush { padding: 0; }

.notice {
  background: color-mix(in srgb, var(--yellow) 12%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--yellow) 35%, var(--border));
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--yellow);
  margin-bottom: 14px;
  line-height: 1.45;
}

textarea {
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.55;
  min-height: 150px;
  resize: vertical;
}

.mc-count { font-size: 12px; color: var(--muted); margin-top: 8px; }
.mc-count strong { color: var(--accent); }

.btn-row { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.btn {
  min-height: var(--tap);
  padding: 12px 18px;
  border-radius: 10px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background .15s, transform .1s, opacity .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-full { width: 100%; }
.btn-sm { min-height: 36px; padding: 8px 14px; font-size: 13px; }

.btn-primary { background: linear-gradient(135deg, #1a8f4a, var(--green)); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-stop { background: var(--red); color: #fff; }

.progress-wrap { margin-top: 14px; }
.progress-bar-bg { background: var(--bg2); border-radius: 6px; height: 8px; overflow: hidden; }
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  border-radius: 6px;
  transition: width .3s;
  width: 0;
}
.progress-text {
  font-size: 12px; color: var(--muted); margin-top: 6px;
  display: flex; justify-content: space-between;
}

.log-wrap {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  height: 110px;
  overflow-y: auto;
  padding: 10px;
  margin-top: 12px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
}
.log-ok { color: var(--green); }
.log-err { color: var(--red); }
.log-info { color: var(--muted); }
.log-skip { color: var(--yellow); }
.log-cache { color: var(--cyan); }

/* ── Stats ── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 10px;
  text-align: center;
}
.stat-card .num { font-size: clamp(20px, 4vw, 26px); font-weight: 700; line-height: 1.1; }
.stat-card .num.blue { color: var(--accent); }
.stat-card .num.green { color: var(--green); }
.stat-card .num.cyan { color: var(--cyan); }
.stat-card .num.purple { color: var(--purple); }
.stat-card .lbl { font-size: 10px; color: var(--muted); margin-top: 4px; text-transform: uppercase; letter-spacing: .4px; }

/* ── Results cards ── */
.results-list { display: flex; flex-direction: column; gap: 10px; padding: 12px; }

.result-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  transition: border-color .15s;
}
.result-card:hover { border-color: var(--accent); }
.result-card.is-cached { border-left: 3px solid var(--cyan); }
.result-card.is-error { border-left: 3px solid var(--red); }

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}
.card-name { font-weight: 700; font-size: 15px; line-height: 1.3; flex: 1; }
.card-meta { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.card-num { font-size: 11px; color: var(--muted); font-family: var(--mono); }

.cache-tag {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--cyan) 15%, transparent);
  color: var(--cyan);
  border: 1px solid color-mix(in srgb, var(--cyan) 40%, transparent);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 16px;
}
.card-field { font-size: 12px; }
.card-field .lbl { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .3px; margin-bottom: 2px; }
.card-field .val { word-break: break-word; }
.card-field .val.mono { font-family: var(--mono); color: var(--accent); }
.card-field .val.green { color: var(--green); }
.card-field .val.purple { color: var(--purple); }
.card-field.full { grid-column: 1 / -1; }

.status-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.status-auth { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); border: 1px solid color-mix(in srgb, var(--green) 40%, transparent); }
.status-not { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); border: 1px solid color-mix(in srgb, var(--red) 40%, transparent); }
.status-warn { background: color-mix(in srgb, var(--yellow) 15%, transparent); color: var(--yellow); border: 1px solid color-mix(in srgb, var(--yellow) 40%, transparent); }
.status-muted { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }

.empty-state { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty-state .icon { font-size: 36px; margin-bottom: 10px; }
.empty-state p { font-size: 14px; line-height: 1.5; }

/* ── History ── */
.search-bar { margin-bottom: 12px; }
.search-bar input { font-size: 15px; }

.filter-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
  align-items: end;
}
.filter-group { display: flex; flex-direction: column; gap: 5px; }
.filter-group label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.filter-group select,
.filter-group input[type="date"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  min-height: 42px;
}
.filter-group select:focus,
.filter-group input[type="date"]:focus {
  border-color: var(--accent);
}
#clearFiltersBtn { min-height: 42px; align-self: end; }

.history-meta { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.history-list .result-card { cursor: default; }

.pager {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.pager button {
  min-width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
}
.pager button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pager button:disabled { opacity: .4; cursor: not-allowed; }

/* ── Settings ── */
#passwordForm { display: flex; flex-direction: column; gap: 12px; }
#passwordForm label {
  font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px;
}

.settings-stats { display: flex; flex-direction: column; gap: 12px; }
.ss-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.ss-row:last-child { border-bottom: none; }
.ss-row strong { color: var(--accent); font-family: var(--mono); }

/* ── Responsive ── */
@media (max-width: 900px) {
  .layout-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .card-grid { grid-template-columns: 1fr; }
  .subtitle { display: none; }
  .main { padding: 12px; }
  .btn-logout span { display: none; }
  .btn-logout { width: 40px; padding: 0; justify-content: center; }
}
