* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f5f5f5;
    color: #333;
}

.container { max-width: 1200px; margin: 0 auto; padding: 20px; }

header { text-align: center; margin-bottom: 30px; }
header h1 { font-size: 28px; color: #1a1a1a; }
.subtitle { color: #666; margin-top: 5px; }

.controls {
    display: flex; align-items: center; gap: 15px;
    margin-bottom: 20px; flex-wrap: wrap;
}

button {
    padding: 8px 16px; border: none; border-radius: 6px;
    cursor: pointer; font-size: 14px; font-weight: 500;
    transition: background 0.2s;
}

#scrape-btn { background: #2563eb; color: white; }
#scrape-btn:hover { background: #1d4ed8; }
#scrape-btn:disabled { background: #93c5fd; cursor: not-allowed; }

#menu-btn { background: #eef2ff; color: #3730a3; }
#menu-btn:hover { background: #e0e7ff; }

#stop-btn { background: #dc2626; color: white; }
#stop-btn:hover { background: #b91c1c; }
#stop-btn.hidden { display: none; }

#scrape-list { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; max-height: 320px; overflow-y: auto; }
.scrape-row { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 6px; }
.scrape-row:hover { background: #f8fafc; }
.scrape-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: #2563eb; }
.scrape-label { flex: 1; font-size: 13px; }

.auto-update {
    display: flex; align-items: center; gap: 8px; margin-left: auto;
}
.auto-label { font-size: 13px; color: #666; }
#auto-interval { font-weight: 600; }

.toggle {
    position: relative; display: inline-block; width: 40px; height: 22px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: #cbd5e1; border-radius: 22px; cursor: pointer;
    transition: 0.3s;
}
.toggle-slider::before {
    content: ""; position: absolute; height: 16px; width: 16px;
    left: 3px; bottom: 3px; background: white; border-radius: 50%;
    transition: 0.3s;
}
.toggle input:checked + .toggle-slider { background: #2563eb; }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

.status-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 16px; background: #fffbeb;
    border: 1px solid #fbbf24; border-radius: 6px;
    font-size: 14px; color: #92400e;
}
.status-bar.hidden { display: none; }
.status-bar.done { background: #f0fdf4; border-color: #22c55e; color: #166534; }
.status-bar.error { background: #fef2f2; border-color: #ef4444; color: #991b1b; }

.spinner {
    width: 16px; height: 16px; border: 2px solid #fbbf24;
    border-top-color: transparent; border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.status-bar.done .spinner, .status-bar.error .spinner { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

.tyre-tabs {
    display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap;
}

.tab {
    padding: 8px 12px; border: 2px solid #e2e8f0; border-radius: 8px;
    background: white; color: #475569; font-size: 14px; font-weight: 500;
    cursor: pointer; transition: all 0.2s;
    display: flex; align-items: center; gap: 6px;
}
.tab:hover { border-color: #2563eb; color: #2563eb; }
.tab.active { background: #2563eb; border-color: #2563eb; color: white; }

.tab .badge {
    background: #e2e8f0; color: #475569; border-radius: 10px;
    padding: 1px 8px; font-size: 12px; font-weight: 600;
}
.tab.active .badge { background: rgba(255,255,255,0.25); color: white; }

.tab-scrape {
    background: none; border: none; color: inherit; padding: 2px 6px;
    font-size: 11px; cursor: pointer; opacity: 0.6; border-radius: 4px;
}
.tab-scrape:hover { opacity: 1; background: rgba(0,0,0,0.1); }

.empty-state {
    text-align: center; padding: 60px 20px; color: #94a3b8;
    background: white; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    font-size: 16px;
}
.empty-state.hidden { display: none; }

.hidden-table { display: none; }

table {
    width: 100%; border-collapse: collapse; background: white;
    border-radius: 8px; overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
thead { background: #f8fafc; }
th {
    padding: 12px 16px; text-align: left; font-weight: 600;
    font-size: 13px; color: #475569; text-transform: uppercase;
    letter-spacing: 0.5px; border-bottom: 2px solid #e2e8f0;
}
th.sortable { cursor: pointer; user-select: none; transition: color 0.2s; }
th.sortable:hover { color: #2563eb; }
th.sortable.active-sort { color: #2563eb; }
.sort-arrow { font-size: 11px; margin-left: 4px; color: #2563eb; }

td { padding: 12px 16px; border-bottom: 1px solid #f1f5f9; font-size: 14px; }
tr:hover { background: #f8fafc; }
.tyre-name { font-weight: 500; }
.tyre-size { font-size: 12px; color: #666; margin-top: 2px; }
.store-name { font-weight: 500; }
.price { font-weight: 700; font-size: 16px; color: #16a34a; }
.currency { font-size: 12px; color: #666; }
.muted { color: #999; }

.stock-dot {
    display: inline-block; width: 10px; height: 10px; border-radius: 50%;
}
.stock-dot.in-stock { background: #16a34a; }
.stock-dot.out-of-stock { background: #dc2626; }

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

.empty { text-align: center; color: #999; padding: 40px !important; }

.summary {
    margin-top: 20px; padding: 15px; background: white;
    border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    font-size: 14px; color: #555; display: none;
}
.summary.visible { display: block; }

.charts-section {
    margin-top: 30px; padding: 20px; background: white;
    border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.charts-section h2 {
    font-size: 18px; color: #1a1a1a; margin-bottom: 15px;
}
.chart-wrapper {
    max-height: 400px; overflow-y: auto;
    position: relative;
}
.chart-wrapper::-webkit-scrollbar { width: 6px; }
.chart-wrapper::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 3px; }
.chart-wrapper::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.history-section {
    margin-top: 20px; padding: 20px; background: white;
    border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    max-height: 500px; overflow-y: auto;
}
.history-section::-webkit-scrollbar { width: 6px; }
.history-section::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 3px; }
.history-section::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.history-section h2 {
    font-size: 18px; color: #1a1a1a; margin-bottom: 15px;
}
.history-item {
    display: flex; gap: 16px; align-items: center; padding: 8px 0;
    border-bottom: 1px solid #f1f5f9; font-size: 13px;
}
.history-brand { font-weight: 600; min-width: 80px; color: #2563eb; }
.history-store { flex: 1; color: #475569; }
.history-price { font-weight: 600; color: #16a34a; min-width: 100px; }
.history-date { color: #94a3b8; min-width: 140px; }

.tab-add {
    background: #e2e8f0; color: #475569; font-weight: 700; font-size: 18px;
    min-width: 36px; padding: 6px 12px; border-radius: 6px;
}
.tab-add:hover { background: #cbd5e1; }

.tab-delete {
    background: none; border: none; color: #94a3b8; font-size: 12px;
    padding: 2px 4px; cursor: pointer; margin-left: 4px; line-height: 1;
}
.tab-delete:hover { color: #dc2626; }

.add-panel {
    background: white; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    padding: 16px 20px; margin-bottom: 16px;
}
.add-panel.hidden { display: none; }
.add-panel-header {
    display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px;
}
.add-panel-header h3 { font-size: 16px; color: #1a1a1a; }
.btn-close {
    background: none; border: none; font-size: 18px; color: #94a3b8; cursor: pointer;
    padding: 4px 8px; border-radius: 4px;
}
.btn-close:hover { background: #f1f5f9; color: #475569; }
.add-panel-row {
    display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap;
}
.add-panel .form-group { margin-bottom: 0; flex: 1; min-width: 140px; }
.add-panel .form-group label {
    display: block; font-size: 12px; font-weight: 500; color: #475569; margin-bottom: 4px;
}
.add-panel select {
    width: 100%; padding: 8px 10px; border: 1px solid #e2e8f0; border-radius: 6px;
    font-size: 13px; background: white; color: #333; outline: none; transition: border 0.2s;
}
.add-panel select:focus { border-color: #2563eb; }
.add-panel .form-actions { flex: 0 0 auto; min-width: auto; }
.btn-add {
    background: #2563eb; color: white; padding: 8px 20px; border-radius: 6px;
    font-size: 13px; font-weight: 500; border: none; cursor: pointer;
}
.btn-add:hover { background: #1d4ed8; }
.add-panel-msg {
    font-size: 12px; margin-top: 8px; min-height: 16px;
}
.add-panel-msg.success { color: #16a34a; }
.add-panel-msg.error { color: #dc2626; }

/* ---- Manual tyre picker (card grid) ---- */
.section-title { font-size: 18px; color: #1a1a1a; margin-bottom: 12px; }
.picker-toolbar {
    display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
}
#tyre-search {
    flex: 1; max-width: 340px; padding: 8px 12px;
    border: 1px solid #e2e8f0; border-radius: 6px; font-size: 14px;
    outline: none; background: white;
}
#tyre-search:focus { border-color: #2563eb; }
.tyre-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px; margin-bottom: 20px;
}
.tyre-card {
    position: relative; display: flex; flex-direction: column; gap: 2px;
    padding: 12px 14px; background: white; border: 2px solid #e2e8f0;
    border-radius: 10px; cursor: pointer; text-align: left;
    font-size: 14px; color: #1a1a1a; transition: border-color 0.2s, box-shadow 0.2s;
}
.tyre-card:hover { border-color: #93c5fd; }
.tyre-card.selected { border-color: #2563eb; box-shadow: 0 0 0 1px #2563eb; background: #eff6ff; }
.tyre-card:focus-visible { outline: 2px solid #2563eb; outline-offset: 2px; }
.card-brand { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; color: #2563eb; }
.card-model { font-weight: 600; font-size: 14px; }
.card-meta { font-size: 12px; color: #16a34a; }
.card-skip { font-size: 11px; color: #b45309; }
.card-icons { position: absolute; top: 6px; right: 8px; display: flex; gap: 6px; }
.card-icon { font-size: 12px; color: #94a3b8; cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.card-icon:hover { color: #2563eb; background: #e0e7ff; }
.card-icon.card-del:hover { color: #dc2626; background: #fee2e2; }

/* ---- Grouped compare table ---- */
.table-caption { caption-side: top; text-align: left; font-size: 13px; color: #475569; padding: 10px 16px 0; background: white; }
thead th { position: sticky; top: 0; background: #f8fafc; z-index: 1; }
tr.group-row td {
    background: #eff6ff; font-size: 14px; padding: 10px 16px;
    position: sticky; top: 45px; z-index: 1;
}
tr.best-row td:first-child { box-shadow: inset 3px 0 0 #16a34a; }

/* ---- Footer ---- */
.site-footer {
    margin: 24px 0 10px; padding: 14px 4px 0; border-top: 1px solid #e2e8f0;
    font-size: 12px; color: #666; display: flex; gap: 12px; flex-wrap: wrap;
}

/* ---- Responsive ---- */
@media (max-width: 720px) {
    .tyre-grid { grid-template-columns: 1fr; }
    .container { padding: 12px; }
    header h1 { font-size: 22px; }
    table { display: block; overflow-x: auto; }
    .controls { gap: 8px; }
}
