@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600&family=IBM+Plex+Mono:wght@500;600&display=swap');

:root {
    --bg: #12181c;
    --panel: #1a2226;
    --panel-alt: #1f292e;
    --border: #2b363b;
    --text: #edf1f2;
    --text-muted: #8b9aa1;
    --accent-gold: #e8a33d;
    --accent-gold-dim: #6b551f;
    --accent-teal: #4fb286;
    --accent-teal-dim: #234d3c;
    --accent-red: #d9705f;
    --accent-red-dim: #4d2b26;
    --radius: 10px;
    --font-display: 'Space Grotesk', sans-serif;
    --font-body: 'Inter', sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    background-image:
        radial-gradient(circle at 15% 0%, rgba(232, 163, 61, 0.06), transparent 40%),
        radial-gradient(circle at 85% 10%, rgba(79, 178, 134, 0.05), transparent 35%);
    color: var(--text);
    font-family: var(--font-body);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

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

.topbar h1 {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    margin: 0;
    letter-spacing: 0.01em;
}

.topbar h1 .accent { color: var(--accent-gold); }

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

.topbar-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.topbar-actions {
    display: flex;
    gap: 8px;
}

.scan-limit {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-body);
}

.scan-limit input {
    width: 68px;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 7px;
    padding: 8px 8px;
    font-size: 13px;
    font-family: var(--font-mono);
}

.action-btn {
    background: var(--accent-gold);
    color: #12181c;
    border: 1px solid transparent;
    border-radius: 7px;
    padding: 8px 14px;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: filter 0.15s, opacity 0.15s;
}

.action-btn.secondary {
    background: var(--panel-alt);
    color: var(--text);
    border-color: var(--border);
}

/* wariant „danger" — operacje kasujące dane (wyczyść katalog / importy) */
.action-btn.danger {
    background: transparent;
    color: var(--accent-red);
    border-color: var(--accent-red-dim);
}
.action-btn.danger:hover:not(:disabled) {
    background: var(--accent-red-dim);
    color: var(--accent-red);
    filter: none;
}

.action-btn:hover:not(:disabled) { filter: brightness(1.15); }
.action-btn:disabled { opacity: 0.45; cursor: default; }

.run-status {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    text-align: right;
    max-width: 480px;
}

.run-status .dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent-teal);
    margin-right: 6px;
    box-shadow: 0 0 6px var(--accent-teal);
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 32px 64px;
}

.scan-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 16px;
}

.scan-options {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.scan-options .chk {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}

.tracked-box { border-top: 1px solid var(--border); padding-top: 12px; }

.tracked-add { display: flex; gap: 8px; margin-bottom: 10px; }

.tracked-add input {
    flex: 1;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 7px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: var(--font-body);
}

.action-btn.small { padding: 8px 12px; font-size: 12px; white-space: nowrap; }

.tracked-list { display: flex; flex-wrap: wrap; gap: 8px; }

.tracked-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 5px 6px 5px 12px;
    font-size: 12px;
    max-width: 340px;
}
.tracked-chip .name {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tracked-chip .rm {
    border: none;
    background: var(--accent-red-dim);
    color: var(--accent-red);
    border-radius: 50%;
    width: 18px; height: 18px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}
.tracked-chip .rm:hover { filter: brightness(1.3); }
.tracked-empty { color: var(--text-muted); font-size: 12px; }

.scan-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.progress-bar {
    flex: 1;
    height: 10px;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    width: 0;
    background: var(--accent-gold);
    transition: width 0.3s ease;
}
.progress-label {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.log-panel {
    background: #0d1215;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
    overflow: hidden;
}

.log-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-display);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.log-head-actions { display: flex; align-items: center; gap: 12px; }

.log-autoscroll {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.log-toggle {
    background: var(--panel-alt);
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
}
.log-toggle:hover { color: var(--text); border-color: var(--accent-gold); }

.log-body {
    margin: 0;
    padding: 14px;
    max-height: 320px;
    overflow-y: auto;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.55;
    color: #b8c4c9;
    white-space: pre-wrap;
    word-break: break-word;
}

.log-body .err { color: var(--accent-red); }
.log-body .hint { color: var(--accent-gold); }
.log-body .ok { color: var(--accent-teal); }

.log-panel.collapsed .log-body { display: none; }

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

.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.stat-card .label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.stat-card .value {
    font-family: var(--font-mono);
    font-size: 26px;
    font-weight: 600;
    margin-top: 6px;
}

.stat-card.gold .value { color: var(--accent-gold); }
.stat-card.teal .value { color: var(--accent-teal); }

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 18px;
}

.filters input[type="text"],
.filters select {
    background: var(--panel-alt);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 7px;
    padding: 8px 10px;
    font-size: 13px;
    font-family: var(--font-body);
}

.filters input[type="text"] { min-width: 220px; }

.filters label {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

thead th {
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    background: var(--panel-alt);
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    white-space: nowrap;
}

thead th.sorted { color: var(--accent-gold); }

tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-alt); cursor: pointer; }

.prod-name { display: flex; align-items: center; gap: 10px; max-width: 340px; }
.prod-name img {
    width: 32px; height: 32px; object-fit: contain;
    background: #fff; border-radius: 5px; flex-shrink: 0;
}
/* Wrapper tekstu musi móc się kurczyć (min-width:0), inaczej ellipsis nie działa
   i długa nazwa rozpycha kolumnę, nachodząc na cenę. */
.prod-name > div { min-width: 0; flex: 1; }
.prod-name .title {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 13px;
}
.prod-name .cat {
    font-size: 11px; color: var(--text-muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Kolumna "Produkt" nie może zjadać całej szerokości tabeli */
#productsTable th:first-child, #productsTable td:first-child { max-width: 360px; }
#productsTable td.mono { white-space: nowrap; }

.mono { font-family: var(--font-mono); }

.badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 20px;
    margin-right: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge.bestseller { background: var(--accent-gold-dim); color: var(--accent-gold); }
.badge.promo { background: var(--accent-teal-dim); color: var(--accent-teal); }
.badge.new { background: #2a3a4d; color: #7fb1e8; }
.badge.available { background: var(--accent-teal-dim); color: var(--accent-teal); }
.badge.unavailable { background: var(--accent-red-dim); color: var(--accent-red); }
.badge.delivery { background: #2a3a4d; color: #7fb1e8; text-transform: none; letter-spacing: 0; }

.score-cell { display: flex; align-items: center; gap: 8px; }
.score-bar {
    width: 60px; height: 6px; border-radius: 4px;
    background: var(--panel-alt); overflow: hidden;
}
.score-bar .fill { height: 100%; border-radius: 4px; }
.score-value { font-family: var(--font-mono); font-weight: 600; font-size: 13px; width: 34px; }

/* Pasek (fill) dostaje TŁO w kolorze poziomu... */
.fill.tier-high { background: var(--accent-gold); }
.fill.tier-mid  { background: var(--accent-teal); }
.fill.tier-low  { background: var(--text-muted); }
/* ...a liczba tylko KOLOR TEKSTU (bez tła, żeby była czytelna). */
.score-value.tier-high { color: var(--accent-gold); }
.score-value.tier-mid  { color: var(--accent-teal); }
.score-value.tier-low  { color: var(--text-muted); }

/* Wiersze kategorii priorytetowych (arbitraż Chiny→PL) — delikatne podświetlenie
   + złoty akcent z lewej strony, żeby rzucały się w oczy, ale pozostały czytelne. */
tr.priority-cat td { background: rgba(232, 163, 61, 0.07); }
tr.priority-cat:hover td { background: rgba(232, 163, 61, 0.14); }
tr.priority-cat td:first-child { box-shadow: inset 3px 0 0 var(--accent-gold); }

.pagination {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 18px;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-muted);
}
.pagination button {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
}
.pagination button:disabled { opacity: 0.4; cursor: default; }
.pagination button:hover:not(:disabled) { border-color: var(--accent-gold); }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

/* --- product.php --- */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 18px;
}
.back-link:hover { color: var(--accent-gold); }

.product-header {
    display: flex;
    gap: 20px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}
.product-header img {
    width: 90px; height: 90px; object-fit: contain;
    background: #fff; border-radius: 8px; flex-shrink: 0;
}
.product-header h2 { font-family: var(--font-display); margin: 0 0 6px; font-size: 19px; }
.product-header .meta { color: var(--text-muted); font-size: 13px; }

.score-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.score-grid .stat-card .value { font-size: 20px; }

.chart-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 20px;
}
.chart-panel h3 {
    font-family: var(--font-display);
    font-size: 14px;
    margin: 0 0 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* --- Historia skanów (tabela na stronie produktu) --- */
.scan-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin: -4px 0 14px;
}
.scan-table-wrap { overflow-x: auto; }
.scan-table { margin: 0; }
.scan-table tbody tr:hover { background: var(--panel-alt); cursor: default; }
.scan-table td { white-space: nowrap; }
.scan-table .muted { color: var(--text-muted); }

.delta {
    font-size: 11px;
    font-weight: 600;
    margin-left: 6px;
    white-space: nowrap;
}
.delta.up { color: var(--accent-teal); }
.delta.down { color: var(--accent-red); }

/* --- Akcja "Odśwież statystyki" na stronie produktu --- */
.product-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 18px;
    flex-wrap: wrap;
}
.btn-refresh {
    background: var(--accent-gold);
    color: #1a1f22;
    border: none;
    border-radius: 8px;
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}
.btn-refresh:hover:not(:disabled) { opacity: 0.88; }
.btn-refresh:disabled { opacity: 0.55; cursor: default; }
.refresh-msg { font-size: 12px; color: var(--text-muted); }
.refresh-msg.err { color: var(--accent-red); }

@media (max-width: 900px) {
    .stats-row, .score-grid { grid-template-columns: repeat(2, 1fr); }
    .container { padding: 16px; }
}

/* --- Panel oceny AI (karta produktu; Faza 3 placeholder → Faza 1 dane) --- */
.ai-panel-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.ai-panel-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 12px; }
.ai-agg { color: var(--accent-gold); font-weight: 600; }
.ai-panel-empty { border: 1px dashed var(--border); }
.ai-bars { display: grid; gap: 10px; }
.ai-row {
    display: grid; grid-template-columns: 190px 1fr 36px; align-items: center; gap: 12px;
}
.ai-row-label { font-size: 13px; color: var(--text-muted); cursor: help; }
.ai-bar-track {
    height: 8px; border-radius: 6px; background: var(--panel-alt); overflow: hidden;
}
.ai-bar-track[data-empty="1"] {
    background: repeating-linear-gradient(90deg, var(--panel-alt) 0 8px, transparent 8px 14px);
}
.ai-bar-fill { height: 100%; width: 0; border-radius: 6px; transition: width .3s ease; }
.ai-bar-val { font-size: 12px; color: var(--text); text-align: right; }
.ai-rationale { margin-top: 14px; font-size: 13px; line-height: 1.5; color: var(--text); }
.ai-rationale.muted { color: var(--text-muted); }
@media (max-width: 900px) {
    .ai-row { grid-template-columns: 130px 1fr 30px; gap: 8px; }
    .ai-row-label { font-size: 12px; }
}
