/* F1 Analytics — Core Design System
   Tokens + Bootstrap 5 overrides + Pill Active sidebar + baskomponenter.
   Ladda EFTER bootstrap.min.css, FÖRE sidspecifik CSS. */

/* Breakpoints: 480px (sm), 768px (md), 900px (lg/sidebar), 1024px (xl) */

/* ─── Design Tokens ─── */
:root {
    /* Surfaces */
    --bg-abyss:    #08080c;
    --bg-carbon:   #0e0e14;
    --bg-panel:    #14141c;
    --bg-card:     #1a1a24;
    --bg-elevated: #24242e;
    --bg-hover:    #2e2e3a;
    --bg-surface:  var(--bg-panel);

    /* Brand */
    --f1-red:       #e10600;
    --f1-red-glow:  rgba(225, 6, 0, 0.25);
    --f1-red-dim:   rgba(225, 6, 0, 0.12);
    --f1-orange:    #ff8700;
    --f1-orange-dim: rgba(255, 135, 0, 0.14);
    --f1-cyan:      #00d4ff;
    --f1-cyan-dim:  rgba(0, 212, 255, 0.08);
    --f1-green:     #00d26a;
    --f1-green-dim: rgba(0, 210, 106, 0.10);
    --f1-purple:    #9b59ff;
    --f1-yellow:    #ffe000;
    --accent-orange: var(--f1-orange);
    --accent-cyan:   var(--f1-cyan);

    /* Text */
    --text-bright:    #f5f5fb;
    --text-primary:   #dcdce6;
    --text-secondary: #b0b0be;
    --text-muted:     #8a8a9c;
    --text-dim:       #7e7e90;

    /* Borders */
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-medium: rgba(255, 255, 255, 0.14);
    --border-accent: rgba(225, 6, 0, 0.30);

    /* Glass */
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);

    /* Typography */
    --font-display: 'Titillium Web', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-data:    'JetBrains Mono', 'SF Mono', 'Cascadia Code', monospace;
    --font-mono:    var(--font-data);

    /* Fluid typography */
    --fs-body:     clamp(0.875rem, 0.82rem + 0.25vw, 1rem);
    --fs-small:    clamp(0.8rem, 0.75rem + 0.2vw, 0.875rem);
    --fs-xs:       clamp(0.75rem, 0.7rem + 0.2vw, 0.82rem);
    --fs-h3:       clamp(0.875rem, 0.8rem + 0.3vw, 1.1rem);
    --fs-table-th: clamp(0.82rem, 0.76rem + 0.25vw, 0.92rem);
    --fs-table-td: clamp(0.84rem, 0.78rem + 0.3vw, 0.94rem);
    --fs-caption:  clamp(0.7rem, 0.65rem + 0.2vw, 0.78rem);
    --fs-label:    clamp(0.78rem, 0.73rem + 0.2vw, 0.88rem);
    --fs-hero:     clamp(1.8rem, 1.5rem + 1vw, 2.5rem);
    --fs-stat:     clamp(1.2rem, 1rem + 0.8vw, 1.8rem);

    /* Geometry */
    --radius-xs: 3px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius:    var(--radius-md);
    --sidebar-w: 240px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.5);
    --shadow-glow-red: 0 0 40px rgba(225, 6, 0, 0.12);
    --shadow-glow-cyan: 0 0 30px rgba(0, 212, 255, 0.08);

    /* Spacing */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;
    --space-8: 64px;

    /* Positions */
    --pos-1: #ffd700;
    --pos-2: #c0c0c0;
    --pos-3: #cd7f32;

    /* Tyre compounds */
    --compound-soft:   #ff3333;
    --compound-medium: #fff200;
    --compound-hard:   #ebebeb;
    --compound-inter:  #43b02a;
    --compound-wet:    #0067ad;

    /* Status */
    --status-dnf:      var(--f1-red);
    --status-finished: var(--f1-green);

    /* Motion */
    --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --dur-fast: 120ms;
    --dur-med: 250ms;
    --dur-slow: 500ms;

    /* z-index */
    --z-base: 1;
    --z-dropdown: 10;
    --z-sticky: 20;
    --z-tooltip: 30;
    --z-sidebar: 100;
    --z-overlay: 140;
    --z-hamburger: 200;
    --z-modal: 300;

    /* Bootstrap overrides */
    --bs-body-bg:           var(--bg-abyss);
    --bs-body-color:        var(--text-primary);
    --bs-body-font-family:  var(--font-display);
    --bs-border-color:      var(--border-subtle);
    --bs-card-bg:           var(--bg-card);
    --bs-card-border-color: var(--border-subtle);
    --bs-primary:           var(--f1-red);
    --bs-primary-rgb:       225, 6, 0;
    --bs-secondary-rgb:     34, 34, 44;
    --bs-link-color:        var(--f1-cyan);
    --bs-link-hover-color:  #33dfff;
}

/* ─── Bootstrap Component Overrides ─── */

body {
    background: var(--bg-abyss);
    color: var(--text-primary);
    font-family: var(--font-display);
    overflow-x: hidden;
}
.f1-app {
    overflow-x: hidden;
    max-width: 100vw;
}

/* Card */
.card {
    background: var(--bg-card);
    border-color: var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
}
.card-header {
    background: transparent;
    border-color: var(--border-subtle);
    color: var(--text-bright);
    padding: 14px 18px;
}
.card-body { padding: 16px 18px; }

/* Table */
.table { color: var(--text-primary); --bs-table-bg: transparent; }
.table > :not(caption) > * > * {
    background: transparent;
    border-color: var(--border-subtle);
    padding: 10px 14px;
}
.table > thead { border-bottom: 2px solid var(--border-medium); }
.table > thead th {
    color: var(--text-muted);
    font-family: var(--font-data);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.table-hover > tbody > tr:hover > * {
    background: var(--bg-hover);
    --bs-table-hover-bg: var(--bg-hover);
}

/* Button */
.btn { border-radius: var(--radius-sm); font-weight: 600; font-size: 0.85rem; }
.btn-primary {
    --bs-btn-bg: var(--f1-red);
    --bs-btn-border-color: var(--f1-red);
    --bs-btn-hover-bg: #c10500;
    --bs-btn-hover-border-color: #c10500;
    --bs-btn-active-bg: #a00400;
}
.btn-secondary {
    --bs-btn-bg: var(--bg-elevated);
    --bs-btn-border-color: var(--border-medium);
    --bs-btn-color: var(--text-primary);
    --bs-btn-hover-bg: var(--bg-hover);
    --bs-btn-hover-color: var(--text-bright);
}
.btn-danger {
    --bs-btn-bg: #b91c1c;
    --bs-btn-border-color: #b91c1c;
}
.btn-sm { font-size: 0.8rem; padding: 5px 12px; }

/* Form */
.form-control, .form-select {
    background: var(--bg-elevated);
    border-color: var(--border-medium);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
}
.form-control:focus, .form-select:focus {
    background: var(--bg-elevated);
    border-color: var(--f1-red);
    color: var(--text-primary);
    box-shadow: 0 0 0 0.2rem var(--f1-red-glow);
}
.form-label { color: var(--text-secondary); font-size: 0.85rem; font-weight: 600; }
.form-text { color: var(--text-muted); font-size: 0.78rem; }

/* Badge */
.badge { font-family: var(--font-data); font-weight: 600; font-size: 0.7rem; }
.bg-success { --bs-success-rgb: 0, 210, 106; }
.bg-danger { --bs-danger-rgb: 225, 6, 0; }
.bg-warning { --bs-warning-rgb: 255, 224, 0; }

/* Modal */
.modal-content {
    background: var(--bg-card);
    border-color: var(--border-medium);
    color: var(--text-primary);
}
.modal-header { border-color: var(--border-subtle); }
.modal-footer { border-color: var(--border-subtle); }

/* ─── Stat Card ─── */
.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-bright);
    font-family: var(--font-data);
}
.stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* ─── Flash messages ─── */
.flash {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.85rem;
}
.flash-success { background: rgba(0, 210, 106, 0.1); color: var(--f1-green); border: 1px solid rgba(0, 210, 106, 0.2); }
.flash-error   { background: rgba(225, 6, 0, 0.1);   color: var(--f1-red);   border: 1px solid rgba(225, 6, 0, 0.2); }

/* ─── Pill Active Sidebar ─── */
.f1-sidebar {
    width: var(--sidebar-w);
    background: var(--bg-carbon);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    z-index: var(--z-sidebar);
    overflow-y: auto;
    transition: transform var(--dur-slow) var(--ease-out);
}
.f1-sidebar__logo {
    padding: 18px 16px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 8px;
}
.f1-sidebar__mark {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--f1-red);
    font-family: var(--font-data);
}
.f1-sidebar__title {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.f1-sidebar__nav {
    flex: 1;
    padding: 10px 8px;
    overflow-y: auto;
}
.f1-sidebar__group {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    padding: 14px 10px 4px;
    font-family: var(--font-data);
}
.f1-sidebar__item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    margin: 1px 0;
    border-radius: 8px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 400;
    transition: all 0.15s ease;
    cursor: pointer;
}
.f1-sidebar__item:hover {
    background: var(--bg-elevated);
    color: var(--text-bright);
    text-decoration: none;
}
.f1-sidebar__item.active {
    background: var(--bg-elevated);
    color: var(--text-bright);
    font-weight: 600;
    box-shadow: 0 0 0 1px var(--border-medium);
}
.f1-sidebar__item i {
    font-size: 1rem;
    width: 20px;
    text-align: center;
    opacity: 0.6;
}
.f1-sidebar__item:hover i,
.f1-sidebar__item.active i { opacity: 1; }
.f1-sidebar__badge {
    margin-left: auto;
    background: var(--f1-red);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    font-family: var(--font-data);
}
.f1-sidebar__footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-subtle);
}
.f1-sidebar__footer a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    gap: 6px;
}
.f1-sidebar__footer a:hover { color: var(--text-secondary); }

/* Sidebar toggle (hamburger) */
.f1-sidebar-toggle {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: var(--z-hamburger);
    background: var(--bg-card);
    border: 1px solid var(--border-medium);
    border-radius: 6px;
    color: var(--text-bright);
    font-size: 1.4rem;
    width: 40px;
    height: 40px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

/* Sidebar overlay (mobil) */
.f1-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-overlay);
}
.f1-sidebar-overlay.active { display: block; }

/* Main content area */
.f1-main {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    padding: 28px 32px;
    overflow-x: hidden;
    max-width: 100vw;
}

/* All cards with data-tables: scrollable */
.card { overflow: hidden; }
.card .data-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ─── Page Layout Helpers ─── */
.page-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-bright);
    margin-bottom: 20px;
}
.page-title .accent { color: var(--f1-red); }
.text-muted { color: var(--text-muted) !important; }
.text-red { color: var(--f1-red); }
.text-green { color: var(--f1-green); }
.text-mono { font-family: var(--font-data); }

/* ─── Admin Components (from old layout.php inline CSS) ─── */

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 20px;
}

/* Data table wrap — responsive scroll */
.data-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
}
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.data-table th {
    padding: 10px 14px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    font-family: var(--font-data);
    border-bottom: 2px solid var(--border-medium);
    text-align: left;
}
.data-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
}
.data-table tbody tr:hover td {
    background: var(--bg-hover);
}

/* Form components */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}
.form-group { margin-bottom: 16px; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* Tabs */
.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 20px;
    overflow-x: auto;
}
.f1-tab {
    padding: 10px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 600;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    white-space: nowrap;
}
.f1-tab:hover { color: var(--text-bright); }
.f1-tab.active { color: var(--f1-red); border-bottom-color: var(--f1-red); }

/* Color input */
.color-input-wrap { display: flex; align-items: center; gap: 8px; }
.color-input-wrap input[type="color"] {
    width: 40px; height: 36px;
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    background: var(--bg-panel);
    cursor: pointer;
    padding: 2px;
}
.color-input-wrap input[type="text"] { flex: 1; }

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: var(--z-modal);
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-body { padding: 20px; }
.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Utilities */
.text-right { text-align: right; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.hidden { display: none; }

/* ─── Accessibility ─── */
:focus-visible {
    outline: 2px solid var(--f1-cyan);
    outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
.sort-header:focus-visible {
    outline: 2px solid var(--f1-cyan);
    outline-offset: 2px;
}

/* Touch targets */
@media (pointer: coarse) {
    .sort-header {
        min-height: 44px;
    }
    .source-list__item,
    .entity-list__item {
        min-height: 44px;
    }
    #trend-zoom-btns .btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* ─── Mobile Responsive ─── */
@media (max-width: 900px) {
    /* Sidebar */
    .f1-sidebar-toggle { display: flex; }
    .f1-sidebar {
        transform: translateX(-100%);
        z-index: 150;
        box-shadow: none;
    }
    .f1-sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
    }
    .f1-main {
        margin-left: 0;
        padding: 56px 16px 20px;
    }

    /* Tables: always scrollable */
    .table-responsive, .data-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Stats: 2 cols on mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .stat-card { padding: 14px; }
    .stat-value { font-size: 1.3rem; }

    /* Cards: reduce padding */
    .card-header { padding: 12px 14px; }
    .card-body { padding: 12px 14px; }

    /* Tables: smaller font, tighter padding */
    .data-table th, .data-table td,
    .table > :not(caption) > * > * {
        padding: 8px 10px;
        font-size: 0.78rem;
    }

    /* Grid overrides: stack cols on small screens */
    .row > [class*="col-lg-"],
    .row > [class*="col-md-"] {
        /* Bootstrap handles this, but ensure 3-col grids stack */
    }

    /* Form row: single column */
    .form-row { grid-template-columns: 1fr; }

    /* Page title smaller */
    .page-title { font-size: 1.1rem; }

    /* Sentiment inline grids: override to stack */
    [style*="grid-template-columns: repeat(3"] {
        grid-template-columns: 1fr !important;
    }
    [style*="grid-template-columns: repeat(4"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    [style*="grid-template-columns:repeat(3"] {
        grid-template-columns: 1fr !important;
    }
    [style*="grid-template-columns:repeat(4"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}
