/* ═══════════════════════════════════════════
   Compel TR — Vendor Analytics Dashboard
   Aesthetic: Dark industrial / Pro-audio console
   ═══════════════════════════════════════════ */

:root {
    /* Surface */
    --bg-root: #0b0c0f;
    --bg-surface: #12141a;
    --bg-raised: #181b23;
    --bg-overlay: #1e2130;
    --bg-hover: #252839;

    /* Borders */
    --border: #2a2d3a;
    --border-subtle: #1f2230;
    --border-focus: #4a6cf7;

    /* Text */
    --text-primary: #e8eaf0;
    --text-secondary: #8b8fa4;
    --text-muted: #5c6078;
    --text-inverse: #0b0c0f;

    /* Accents */
    --accent: #4a6cf7;
    --accent-hover: #5d7cf9;
    --green: #22c55e;
    --green-dim: #16a34a;
    --green-bg: rgba(34,197,94,0.08);
    --red: #ef4444;
    --red-dim: #dc2626;
    --red-bg: rgba(239,68,68,0.08);
    --amber: #f59e0b;
    --amber-dim: #d97706;
    --amber-bg: rgba(245,158,11,0.08);
    --blue: #3b82f6;
    --blue-bg: rgba(59,130,246,0.08);

    /* Type */
    --font-body: 'DM Sans', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Radius */
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;

    /* Shadows */
    --shadow-card: 0 1px 3px rgba(0,0,0,.4), 0 0 0 1px var(--border-subtle);
    --shadow-modal: 0 24px 64px rgba(0,0,0,.6);
}

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

html { font-size: 14px; }

body {
    font-family: var(--font-body);
    background: var(--bg-root);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Subtle grid texture */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(74,108,247,0.015) 1px, transparent 1px),
        linear-gradient(90deg, rgba(74,108,247,0.015) 1px, transparent 1px);
    background-size: 64px 64px;
    pointer-events: none;
    z-index: 0;
}

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

/* ─── Top Bar ─── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 24px;
    background: rgba(11,12,15,.85);
    backdrop-filter: blur(16px) saturate(140%);
    border-bottom: 1px solid var(--border-subtle);
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }

.logo { display: flex; align-items: center; gap: 10px; }
.logo-mark { font-size: 18px; color: var(--accent); }
.logo-text { font-weight: 700; font-size: 15px; letter-spacing: -0.02em; }
.logo-divider { width: 1px; height: 18px; background: var(--border); }
.logo-sub { color: var(--text-muted); font-size: 13px; font-weight: 400; }

/* Tabs */
.tab-nav { display: flex; gap: 2px; }
.tab-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--r-sm);
    transition: all .15s;
}
.tab-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.tab-btn.active {
    color: var(--text-primary);
    background: var(--bg-raised);
    box-shadow: var(--shadow-card);
}

/* Sync indicator */
.sync-indicator { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.sync-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted); }
.sync-indicator.running .sync-dot { background: var(--amber); animation: pulse 1s infinite; }
.sync-indicator.success .sync-dot { background: var(--green); }
.sync-indicator.error .sync-dot { background: var(--red); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.btn-icon {
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border);
    background: var(--bg-raised);
    color: var(--text-secondary);
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: all .15s;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--accent); }

/* ─── Filter Bar ─── */
.filter-bar {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    flex-wrap: wrap;
}

.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 500; }
.filter-search { flex: 1; min-width: 180px; }

.filter-bar select,
.filter-bar input[type="date"],
.filter-bar input[type="text"] {
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--bg-raised);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 13px;
    outline: none;
    transition: border-color .15s;
    min-width: 120px;
}
.filter-bar input[type="text"] { min-width: 180px; }
.filter-bar select:focus,
.filter-bar input:focus { border-color: var(--border-focus); }

.btn-primary {
    height: 36px;
    padding: 0 20px;
    border: none;
    border-radius: var(--r-sm);
    background: var(--accent);
    color: #fff;
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
    height: 36px;
    padding: 0 16px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all .15s;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-sm { height: 30px; padding: 0 14px; font-size: 12px; }
.btn-sm.btn-primary { border: none; }

.select-sm {
    height: 30px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--bg-raised);
    color: var(--text-primary);
    font-size: 12px;
    font-family: var(--font-body);
    outline: none;
}

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

/* ─── Main ─── */
.main {
    position: relative;
    z-index: 1;
    padding: 24px;
    max-width: 1480px;
    margin: 0 auto;
}

.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ─── KPI Grid ─── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-md);
    padding: 20px;
    position: relative;
    overflow: hidden;
    transition: border-color .2s;
}
.kpi-card:hover { border-color: var(--border); }

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 2px;
    background: var(--border);
}
.kpi-card.accent-green::before { background: var(--green); }
.kpi-card.accent-red::before { background: var(--red); }
.kpi-card.accent-blue::before { background: var(--accent); }
.kpi-card.accent-amber::before { background: var(--amber); }

.kpi-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 8px;
}

.kpi-value {
    font-family: var(--font-mono);
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1.1;
    color: var(--text-primary);
}

.kpi-sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 6px;
}

.kpi-bar {
    margin-top: 10px;
    height: 4px;
    background: var(--bg-overlay);
    border-radius: 2px;
    overflow: hidden;
}
.kpi-bar-fill { height: 100%; border-radius: 2px; transition: width .6s ease; }
.accent-green .kpi-bar-fill { background: var(--green); }
.accent-amber .kpi-bar-fill { background: var(--amber); }

/* ─── Panels ─── */
.panel {
    background: var(--bg-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-md);
    margin-bottom: 20px;
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
    flex-wrap: wrap;
    gap: 8px;
}
.panel-header h3 { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.panel-desc { font-size: 12px; color: var(--text-muted); }
.panel-actions { display: flex; align-items: center; gap: 8px; }
.result-count { font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); }

.panel-sm { max-width: 520px; }

/* ─── Chart ─── */
.chart-container {
    padding: 20px;
    min-height: 280px;
    position: relative;
}

.chart-bar-group {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 200px;
    padding: 0 4px;
}

.chart-canvas {
    width: 100%;
    overflow-x: auto;
}

.chart-row {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    min-width: max-content;
    padding-bottom: 28px;
    position: relative;
}

.chart-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 32px;
}

.chart-bar-stack {
    width: 24px;
    display: flex;
    flex-direction: column-reverse;
    border-radius: 3px 3px 0 0;
    overflow: hidden;
}

.chart-bar-segment {
    width: 100%;
    transition: height .4s ease;
}
.chart-bar-segment.accepted { background: var(--green); }
.chart-bar-segment.rejected { background: var(--red); opacity: 0.8; }
.chart-bar-segment.unfulfilled { background: var(--amber); opacity: 0.6; }

.chart-label {
    font-size: 9px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    writing-mode: vertical-lr;
    transform: rotate(180deg);
    height: 52px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chart-legend {
    display: flex;
    gap: 16px;
    padding: 12px 20px 0;
    font-size: 11px;
    color: var(--text-secondary);
}
.chart-legend-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 2px;
    margin-right: 4px;
    vertical-align: middle;
}

.chart-y-axis {
    position: absolute;
    left: 0; top: 0; bottom: 28px;
    width: 44px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 0 4px;
    font-size: 9px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    text-align: right;
}

/* ─── Data Table ─── */
.table-wrap { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 10px 14px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: var(--bg-overlay);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    user-select: none;
}
.data-table thead th.num { text-align: right; }
.data-table thead th.sortable { cursor: pointer; }
.data-table thead th.sortable:hover { color: var(--text-primary); }
.data-table thead th.sort-active { color: var(--accent); }
.data-table thead th.sort-active::after { content: ' ▾'; }
.data-table thead th.sort-active.asc::after { content: ' ▴'; }

.data-table tbody tr {
    border-bottom: 1px solid var(--border-subtle);
    transition: background .1s;
}
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr.clickable { cursor: pointer; }

.data-table td {
    padding: 10px 14px;
    vertical-align: middle;
    white-space: nowrap;
}
.data-table td.num { text-align: right; font-family: var(--font-mono); font-size: 12px; }

.data-table td.asin-cell {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--accent);
    cursor: pointer;
}
.data-table td.asin-cell:hover { text-decoration: underline; }

.data-table td.title-cell {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
    font-size: 12px;
}

.highlight-col { background: rgba(74,108,247,0.04); }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    font-family: var(--font-mono);
}
.badge-brand {
    background: var(--bg-overlay);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.badge-new {
    background: rgba(59,130,246,0.15);
    color: #60a5fa;
    border: 1px solid rgba(59,130,246,0.3);
}
.badge-ack {
    background: rgba(245,158,11,0.12);
    color: #fbbf24;
    border: 1px solid rgba(245,158,11,0.3);
}
.badge-closed {
    background: rgba(34,197,94,0.1);
    color: #4ade80;
    border: 1px solid rgba(34,197,94,0.25);
}

.fill-bar {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}
.fill-bar-track {
    flex: 1;
    height: 4px;
    background: var(--bg-overlay);
    border-radius: 2px;
    overflow: hidden;
    min-width: 40px;
}
.fill-bar-value {
    height: 100%;
    border-radius: 2px;
    transition: width .4s ease;
}
.fill-bar-label {
    font-family: var(--font-mono);
    font-size: 12px;
    min-width: 40px;
    text-align: right;
}
.fill-good .fill-bar-value { background: var(--green); }
.fill-good .fill-bar-label { color: var(--green); }
.fill-warn .fill-bar-value { background: var(--amber); }
.fill-warn .fill-bar-label { color: var(--amber); }
.fill-bad .fill-bar-value { background: var(--red); }
.fill-bad .fill-bar-label { color: var(--red); }

.text-red { color: var(--red); }
.text-green { color: var(--green); }
.text-amber { color: var(--amber); }
.text-muted { color: var(--text-muted); }

/* ─── Pagination ─── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 14px;
}
.pagination button {
    min-width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--bg-raised);
    color: var(--text-secondary);
    font-size: 12px;
    font-family: var(--font-mono);
    cursor: pointer;
    transition: all .15s;
}
.pagination button:hover { background: var(--bg-hover); color: var(--text-primary); }
.pagination button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pagination button:disabled { opacity: .3; cursor: default; }

/* ─── Brands Grid ─── */
.brands-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 14px;
}

.brand-card {
    background: var(--bg-raised);
    border: 1px solid var(--border-subtle);
    border-radius: var(--r-md);
    padding: 20px;
    transition: border-color .2s;
}
.brand-card:hover { border-color: var(--border); }

.brand-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}
.brand-card-name {
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.02em;
}
.brand-card-badge {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-overlay);
    padding: 3px 8px;
    border-radius: 4px;
}

.brand-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.brand-stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.brand-stat-value { font-family: var(--font-mono); font-size: 16px; font-weight: 600; margin-top: 2px; }

/* ─── Sync Status ─── */
.sync-stats { padding: 16px 20px; }
.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
    border-bottom: 1px solid var(--border-subtle);
}
.stat-row:last-child { border-bottom: none; }
.stat-row span:first-child { color: var(--text-secondary); }
.stat-row span:last-child { font-family: var(--font-mono); font-weight: 500; }

.sync-log {
    padding: 0 20px 16px;
    max-height: 200px;
    overflow-y: auto;
}
.sync-log-entry {
    font-size: 11px;
    font-family: var(--font-mono);
    padding: 4px 0;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-subtle);
}
.sync-log-entry .status-completed { color: var(--green); }
.sync-log-entry .status-failed { color: var(--red); }
.sync-log-entry .status-running { color: var(--amber); }

/* ─── Modal ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    width: 100%;
    max-width: 800px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-modal);
    animation: modalIn .2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: scale(1); } }

.modal-close {
    position: absolute;
    top: 16px; right: 16px;
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--bg-overlay);
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    transition: all .15s;
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.modal-header {
    padding: 24px 24px 0;
    position: relative;
}
.modal-header h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; padding-right: 40px; }
.modal-asin { font-family: var(--font-mono); font-size: 13px; color: var(--accent); display: block; margin-top: 4px; }

.modal-body { padding: 20px 24px 24px; }

.modal-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.modal-kpi { background: var(--bg-overlay); border-radius: var(--r-sm); padding: 12px; }
.modal-kpi-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.modal-kpi-value { font-family: var(--font-mono); font-size: 18px; font-weight: 600; margin-top: 4px; }

/* ─── Toast ─── */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 12px 18px;
    border-radius: var(--r-sm);
    font-size: 13px;
    font-weight: 500;
    animation: toastIn .3s ease;
    box-shadow: var(--shadow-modal);
}
.toast-success { background: var(--green-dim); color: #fff; }
.toast-error { background: var(--red-dim); color: #fff; }
.toast-info { background: var(--accent); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Empty State ─── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
    text-align: center;
}
.empty-state-icon { font-size: 40px; margin-bottom: 12px; opacity: .4; }
.empty-state-text { font-size: 14px; }
.empty-state-sub { font-size: 12px; margin-top: 4px; }

/* ─── Loading ─── */
.loading-spinner {
    display: inline-block;
    width: 20px; height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
    background: linear-gradient(90deg, var(--bg-overlay) 25%, var(--bg-hover) 50%, var(--bg-overlay) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .topbar { padding: 0 12px; }
    .topbar-center { display: none; }
    .filter-bar { padding: 12px; }
    .main { padding: 12px; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .kpi-value { font-size: 22px; }

    /* Mobile tab bar */
    .tab-nav-mobile {
        display: flex;
        overflow-x: auto;
        padding: 8px 12px;
        gap: 4px;
        border-bottom: 1px solid var(--border-subtle);
        background: var(--bg-surface);
    }
}
