:root {
    --bg-top: #f6f3e8;
    --bg-bottom: #e5e8ec;
    --surface: #ffffff;
    --surface-muted: #f4f6fa;
    --surface-strong: #0f2232;
    --text: #102133;
    --text-muted: #5f7388;
    --line: #d4dde5;
    --accent: #0b8f87;
    --accent-soft: #d8f2ef;
    --green: #1f9d55;
    --amber: #d8890f;
    --red: #c93828;
    --danger-soft: #ffe9e6;
    --success-soft: #e4f7ec;
    --shadow: 0 16px 42px rgba(16, 33, 51, 0.12);
    --radius: 14px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text);
    font-family: 'Public Sans', sans-serif;
    background: linear-gradient(155deg, var(--bg-top), var(--bg-bottom));
    min-height: 100vh;
}

.page-bg {
    position: fixed;
    inset: 0;
    pointer-events: none;
    background: radial-gradient(circle at 5% 0%, rgba(11, 143, 135, 0.2), transparent 35%),
        radial-gradient(circle at 90% 10%, rgba(201, 56, 40, 0.12), transparent 42%);
}

h1,
h2,
h3 {
    margin: 0;
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 700;
    letter-spacing: 0.02em;
}

h1 {
    font-size: clamp(2rem, 4vw, 2.8rem);
}

h2 {
    font-size: 1.5rem;
}

p {
    margin: 0;
}

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
    background: rgba(255, 255, 255, 0.84);
    border-bottom: 1px solid rgba(212, 221, 229, 0.75);
}

.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.9rem 1.2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 1.6rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.main-nav {
    display: flex;
    gap: 0.7rem;
    margin-left: 1.2rem;
}

.main-nav a,
.top-link {
    border-radius: 999px;
    padding: 0.4rem 0.85rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.main-nav a:hover,
.top-link:hover {
    color: var(--text);
    background: rgba(15, 34, 50, 0.06);
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
}

.page-shell {
    position: relative;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.3rem 1.2rem 2rem;
    display: grid;
    gap: 1rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--accent);
    font-size: 0.73rem;
    font-weight: 700;
    margin-bottom: 0.35rem;
}

.muted {
    color: var(--text-muted);
    margin-top: 0.3rem;
}

.panel {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.filter-panel {
    padding: 1rem;
}

/* Shared inline filter row + results gap */
.se-controls { padding: 0.75rem 1rem; }
.se-filter-row {
    display: flex;
    gap: 0.75rem;
    align-items: end;
    flex-wrap: wrap;
}
.se-filter-row label { flex: 1; min-width: 120px; }
.se-filter-row .filter-actions { flex: none; }
.se-results { display: grid; gap: 1rem; }

.import-panel {
    padding: 1rem;
    display: grid;
    gap: 0.75rem;
}

.import-panel-head h2 {
    margin-top: 0.15rem;
}

.import-form {
    display: grid;
    gap: 0.65rem;
}

.import-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.import-status {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.65rem 0.8rem;
    font-family: 'Public Sans', sans-serif;
    font-size: 0.86rem;
    line-height: 1.35;
    white-space: pre-wrap;
}

.import-status-processing {
    background: #e7f4ff;
    border-color: #bbddff;
}

.import-status-done {
    background: var(--success-soft);
    border-color: #b4e7c8;
}

.import-status-error {
    background: var(--danger-soft);
    border-color: #f2b4ad;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
    gap: 0.85rem;
    align-items: end;
}

label {
    display: grid;
    gap: 0.35rem;
    font-size: 0.82rem;
    font-weight: 600;
}

input,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    min-height: 2.35rem;
    padding: 0.45rem 0.6rem;
    font-family: 'Public Sans', sans-serif;
    font-size: 0.94rem;
    color: var(--text);
    background: #fff;
}

input:focus,
select:focus {
    outline: 2px solid var(--accent-soft);
    border-color: var(--accent);
}

.filter-actions {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.btn {
    border: 0;
    border-radius: 10px;
    padding: 0.6rem 0.95rem;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: var(--surface-strong);
    color: #fff;
    box-shadow: 0 10px 22px rgba(15, 34, 50, 0.25);
}

.btn-ghost {
    background: var(--surface-muted);
    color: var(--text-muted);
}

.btn-link {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text-muted);
}

.btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none;
}

.summary-grid,
.squad-summary {
    display: grid;
    gap: 0.7rem;
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

/* Clickable table rows */
tr[data-href] { cursor: pointer; }
tr[data-href]:hover td { background: var(--surface-muted); }

.summary-card {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 0.85rem;
}

.summary-card p {
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.summary-card strong {
    font-size: 1.6rem;
    font-family: 'Barlow Condensed', sans-serif;
}

.total-card {
    background: var(--surface-strong);
    color: #fff;
}

.total-card p {
    color: rgba(255, 255, 255, 0.7);
}

.table-panel {
    padding: 0.4rem 0;
}

/* Risk detail sections */
.risk-section { padding: 0; }
.risk-section-head { padding: 0.85rem 0.9rem 0.5rem; }
.risk-section-head h2 { margin-bottom: 0.1rem; }
.risk-section-head .muted { font-size: 0.82rem; }

.table-scroll {
    overflow-x: auto;
}

.squad-table {
    width: 100%;
    border-collapse: collapse;
}

.squad-table th,
.squad-table td {
    text-align: left;
    border-bottom: 1px solid var(--line);
    padding: 0.78rem 0.9rem;
    vertical-align: middle;
}

.squad-table th {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    white-space: nowrap;
}

.squad-table td small {
    display: block;
    color: var(--text-muted);
    margin-top: 0.18rem;
}

.player-link {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
}

.avatar {
    width: 2.1rem;
    height: 2.1rem;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(15, 34, 50, 0.12);
}

.avatar-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-strong);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
}

.risk-pill,
.availability-pill {
    border-radius: 999px;
    padding: 0.24rem 0.58rem;
    font-size: 0.78rem;
    font-weight: 700;
    display: inline-block;
    white-space: nowrap;
}

.risk-green {
    color: var(--green);
    background: var(--success-soft);
}

.risk-amber {
    color: var(--amber);
    background: #fff3db;
}

.risk-red {
    color: var(--red);
    background: var(--danger-soft);
}

.risk-muted {
    color: var(--text-muted);
    background: var(--surface-muted);
}

.trend {
    font-size: 0.86rem;
    font-weight: 700;
}

.trend-up {
    color: var(--red);
}

.trend-down {
    color: var(--green);
}

.trend-neutral {
    color: var(--text-muted);
}

.driver-text {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.status-good,
.status-bad {
    font-weight: 700;
    font-size: 0.8rem;
}

.status-good {
    color: var(--green);
}

.status-bad {
    color: var(--red);
}

.avail-fit {
    background: var(--success-soft);
    color: var(--green);
}

.avail-mod,
.avail-rtp {
    background: #fff3db;
    color: var(--amber);
}

.avail-out {
    background: var(--danger-soft);
    color: var(--red);
}

.avail-none {
    background: var(--surface-muted);
    color: var(--text-muted);
}

/* MPI score badges */
.mpi-badge {
    font-family: 'Barlow Condensed', sans-serif;
    font-weight: 700;
    font-size: 1rem;
}
.mpi-peak { color: var(--green); }
.mpi-normal { color: var(--accent); }
.mpi-below { color: var(--amber); }
.mpi-low { color: var(--red); }
.mpi-none { color: var(--text-muted); }

.empty-state {
    padding: 1.2rem;
    text-align: center;
}

.empty-state h3 {
    margin-bottom: 0.35rem;
}

.tabs {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.4rem;
}

.tabs a {
    padding: 0.45rem 0.8rem;
    border-radius: 9px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9rem;
}

.tabs a.active {
    color: var(--text);
    background: var(--surface-muted);
}

.scaffold-panel {
    padding: 1rem;
}

.plan-list {
    margin: 0.7rem 0 0;
    padding-left: 1.1rem;
    color: var(--text-muted);
}

.monitor-actions {
    display: flex;
    gap: 0.5rem;
}

.monitor-player-actions {
    padding: 0.9rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.monitor-form {
    display: flex;
    align-items: end;
    gap: 0.6rem;
}

.monitor-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 0.85rem;
}

.monitor-main,
.monitor-alerts {
    padding: 0.8rem;
}

.monitor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.65rem;
}

.monitor-header span {
    color: var(--text-muted);
    font-size: 0.83rem;
}

.monitor-rows {
    display: grid;
    gap: 0.65rem;
}

.monitor-player-card {
    border: 1px solid var(--line);
    border-radius: 11px;
    padding: 0.7rem;
    background: #fff;
}

.monitor-player-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.55rem;
}

.metric-line {
    display: grid;
    grid-template-columns: 110px 1fr auto;
    gap: 0.55rem;
    align-items: center;
    margin-bottom: 0.35rem;
}

.metric-line.compact {
    grid-template-columns: auto 1fr;
    margin-bottom: 0;
}

.metric-line span {
    font-size: 0.83rem;
    color: var(--text-muted);
}

.metric-line small {
    color: var(--text-muted);
    font-size: 0.75rem;
    white-space: nowrap;
}

.metric-bar {
    height: 8px;
    border-radius: 999px;
    background: var(--surface-muted);
    overflow: hidden;
}

.metric-bar span {
    display: block;
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent), #26baa3);
}

.metric-bar.metric-bar-positive span {
    background: linear-gradient(90deg, #d8890f, #f59e0b);
}

.metric-bar.metric-bar-negative span {
    background: linear-gradient(90deg, #5d6b7a, #94a3b8);
}

.metric-bar.metric-bar-secondary span {
    background: linear-gradient(90deg, #2b6cb0, #4f8fd6);
}

.chronology-cell {
    min-width: 160px;
}

.chronology-cell strong {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.88rem;
}

.alert-feed {
    display: grid;
    gap: 0.55rem;
    max-height: 620px;
    overflow-y: auto;
}

.alert-item {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55rem 0.6rem;
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 0.5rem;
}

.alert-item strong {
    display: block;
    font-size: 0.85rem;
}

.alert-item p {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

.alert-critical {
    background: var(--danger-soft);
}

.alert-warning {
    background: #fff3db;
}

.alert-info {
    background: #e7f4ff;
}

.alert-fatigue {
    background: #f1ecff;
}

.auth-wrap {
    min-height: calc(100vh - 180px);
    display: grid;
    place-items: center;
}

.auth-card {
    width: min(420px, 92vw);
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.2rem;
    display: grid;
    gap: 0.75rem;
}

.auth-form {
    display: grid;
    gap: 0.65rem;
}

.form-alert {
    background: var(--danger-soft);
    border: 1px solid #f2b4ad;
    color: #8b2419;
    border-radius: 10px;
    padding: 0.5rem 0.65rem;
    font-size: 0.85rem;
}

.message-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.message-list li {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.8);
    padding: 0.55rem 0.7rem;
}

/* Session type pills */
.session-pill { border-radius: 999px; padding: 0.24rem 0.58rem; font-size: 0.78rem; font-weight: 700; display: inline-block; white-space: nowrap; }
.session-match { color: var(--accent); background: var(--accent-soft); }
.session-train { color: var(--green); background: var(--success-soft); }
.session-recov { color: #6366f1; background: #f1ecff; }
.session-gym { color: var(--amber); background: #fff3db; }
.session-other { color: var(--text-muted); background: var(--surface-muted); }

/* Session type icons */
.session-icon { padding-left: 0.6rem !important; padding-right: 0 !important; width: 1.4rem; }
.sicon { font-size: 1rem; line-height: 1; }
.sicon-match { color: var(--accent); }
.sicon-train { color: var(--green); }
.sicon-recov { color: #6366f1; }
.sicon-gym { color: var(--amber); }
.sicon-other { color: var(--text-muted); }

/* Chart grid layout */
.session-charts-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 0.85rem; }
.chart-panel { padding: 1rem; }
.chart-panel h2 { margin-bottom: 0.65rem; }
.chart-panel canvas { width: 100% !important; min-height: 320px; }
.session-chart-wrap {
    position: relative;
    width: 100%;
    height: clamp(280px, 44vh, 440px);
}
.session-chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
}

/* Sortable column headers */
.squad-table th a { color: var(--text-muted); text-decoration: none; }
.squad-table th a:hover { color: var(--accent); }
.squad-table th a.sort-active { color: var(--text); }

@media (max-width: 980px) {
    .filter-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .summary-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .main-nav {
        display: none;
    }

    .monitor-grid {
        grid-template-columns: 1fr;
    }

    .session-charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 700px) {
    .page-shell {
        padding: 0.95rem 0.7rem 1.3rem;
    }

    .topbar-inner {
        padding: 0.7rem 0.7rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .filter-grid {
        grid-template-columns: 1fr 1fr;
    }

    .summary-grid {
        grid-template-columns: 1fr 1fr;
    }

    .squad-table th,
    .squad-table td {
        padding: 0.65rem 0.6rem;
    }
}

@media (max-width: 480px) {
    .filter-grid {
        grid-template-columns: 1fr;
    }

    .summary-grid {
        grid-template-columns: 1fr;
    }
}

/* ── Team Switcher (topbar) ─────────────────────────────────────────── */
.team-switcher {
    position: relative;
}

.team-switcher-btn {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    background: transparent;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.35rem 0.7rem;
    cursor: pointer;
    font-family: 'Public Sans', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    transition: background 0.15s, border-color 0.15s;
}

.team-switcher-btn:hover,
.team-switcher.open .team-switcher-btn {
    background: rgba(15, 34, 50, 0.06);
    border-color: rgba(15, 34, 50, 0.2);
}

.team-switcher-badge {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent);
}

.team-switcher-sep {
    width: 1px;
    height: 1rem;
    background: var(--line);
}

.team-switcher-name {
    white-space: nowrap;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-muted);
    font-weight: 500;
}

.team-switcher-caret {
    flex-shrink: 0;
    opacity: 0.45;
    transition: transform 0.2s ease;
}

.team-switcher.open .team-switcher-caret {
    transform: rotate(180deg);
}

.team-switcher-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 240px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.4rem;
    display: none;
    z-index: 200;
}

.team-switcher.open .team-switcher-dropdown {
    display: block;
}

.team-switcher-option {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.5rem 0.6rem;
    border-radius: 10px;
    transition: background 0.12s;
}

.team-switcher-option:hover {
    background: var(--surface-muted);
}

.team-switcher-option.active {
    background: var(--accent-soft);
}

.team-switcher-opt-badge {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent);
    min-width: 2rem;
}

.team-switcher-option strong {
    display: block;
    font-size: 0.88rem;
}

.team-switcher-option small {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 0.1rem;
}

/* ── Team Picker (landing page) ─────────────────────────────────────── */
.team-picker-wrap {
    min-height: calc(100vh - 200px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 0;
}

.team-picker-hero {
    text-align: center;
    margin-bottom: 1.5rem;
}

.team-picker-list {
    width: min(480px, 92vw);
}

.team-picker-list .team-option {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--line);
    transition: background 0.12s;
}

.team-picker-list .team-option:last-child {
    border-bottom: none;
}

.team-picker-list .team-option:hover {
    background: var(--surface-muted);
}

.team-option-badge {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent);
    min-width: 2.4rem;
}

.team-option-info {
    flex: 1;
}

.team-option-info strong {
    display: block;
    font-size: 0.95rem;
}

.team-option-info small {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-top: 0.12rem;
}

.team-option-arrow {
    color: var(--text-muted);
    font-size: 0.9rem;
    transition: transform 0.15s, color 0.15s;
}

.team-picker-list .team-option:hover .team-option-arrow {
    transform: translateX(3px);
    color: var(--accent);
}

@media (max-width: 700px) {
    .team-switcher-name {
        display: none;
    }
    .team-switcher-sep {
        display: none;
    }
}

/* ── Physical Profile ─────────────────────────────────────────────── */
.physical-filter-grid {
    display: grid;
    grid-template-columns: minmax(200px, 1fr);
    gap: 0.85rem;
    align-items: end;
}

.physical-radar-wrap {
    position: relative;
    width: 100%;
    height: clamp(280px, 46vh, 460px);
    margin-top: 0.6rem;
}

.physical-radar-wrap canvas {
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
}

.physical-chart-hint {
    margin-top: 0.65rem;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.physical-category-panel {
    padding: 1rem;
}

.physical-category-panel h2 {
    margin-bottom: 0.75rem;
}

.physical-metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.5rem;
}

.physical-metric-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid var(--line);
}

.physical-metric-label {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.metric-label-with-help {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
}

.metric-tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    padding: 0;
    border: 1px solid rgba(95, 115, 136, 0.35);
    border-radius: 999px;
    background: rgba(216, 242, 239, 0.55);
    color: var(--text-muted);
    cursor: help;
    appearance: none;
    -webkit-appearance: none;
}

.metric-tooltip:hover,
.metric-tooltip:focus-visible {
    border-color: rgba(11, 143, 135, 0.45);
    color: var(--accent);
    outline: none;
}

.metric-tooltip-trigger {
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1;
}

.metric-tooltip-bubble {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 0.55rem);
    z-index: 20;
    width: clamp(180px, 28vw, 280px);
    padding: 0.55rem 0.7rem;
    border-radius: 10px;
    background: var(--surface-strong);
    color: #f5f9fc;
    font-size: 0.76rem;
    font-weight: 500;
    line-height: 1.45;
    text-align: left;
    box-shadow: 0 10px 24px rgba(16, 33, 51, 0.22);
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(0.2rem);
    transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s ease;
    pointer-events: none;
}

.metric-tooltip-bubble::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 100%;
    width: 10px;
    height: 10px;
    background: var(--surface-strong);
    transform: translateX(-50%) rotate(45deg);
}

.metric-tooltip:hover .metric-tooltip-bubble,
.metric-tooltip:focus-visible .metric-tooltip-bubble {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.physical-metric-value {
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    white-space: nowrap;
}

.physical-delta {
    font-size: 0.78rem;
    font-weight: 700;
    margin-left: 0.35rem;
}

.delta-good {
    color: var(--green);
}

.delta-bad {
    color: var(--red);
}

.physical-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

@media (max-width: 700px) {
    .physical-metrics-grid {
        grid-template-columns: 1fr;
    }

    .metric-tooltip-bubble {
        left: 0;
        transform: translateX(0) translateY(0.2rem);
    }

    .metric-tooltip-bubble::after {
        left: 0.9rem;
        transform: rotate(45deg);
    }

    .metric-tooltip:hover .metric-tooltip-bubble,
    .metric-tooltip:focus-visible .metric-tooltip-bubble {
        transform: translateX(0) translateY(0);
    }
}

/* ── BI Builder ───────────────────────────────────────────────────── */
.bi-builder-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.85rem;
}

.bi-builder-grid select[multiple] {
    min-height: 220px;
}

.bi-preset-row {
    display: flex;
    gap: 0.45rem;
    align-items: center;
}

.bi-preset-row select,
.bi-preset-row input {
    flex: 1;
}

.bi-builder-grid .filter-actions {
    align-self: end;
}

.bi-help-text {
    margin-top: 0.75rem;
}

.bi-chart-panel {
    margin-top: 0.9rem;
}

.bi-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
}

.bi-chart-wrap {
    position: relative;
    width: 100%;
    height: clamp(320px, 52vh, 560px);
    margin-top: 0.55rem;
}

.bi-chart-wrap canvas {
    width: 100% !important;
    height: 100% !important;
    min-height: 0 !important;
}

.bi-error {
    margin-top: 0.8rem;
}

@media (max-width: 1280px) {
    .bi-builder-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 960px) {
    .bi-builder-grid {
        grid-template-columns: 1fr;
    }
}

/* ── SQL Lab ──────────────────────────────────────────────────────── */
.sql-lab-im-panel {
    padding: 1rem;
}

.sql-lab-im-header {
    margin-bottom: 0.75rem;
}

.sql-lab-im-grid {
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    gap: 0.85rem;
}

.sql-schema-browser-panel {
    display: grid;
    gap: 0.5rem;
}

.sql-schema-browser {
    max-height: 520px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55rem;
    background: rgba(255, 255, 255, 0.7);
}

.sql-table-item {
    border: 1px solid var(--line);
    border-radius: 10px;
    margin-bottom: 0.5rem;
    padding: 0.3rem 0.45rem;
    background: rgba(255, 255, 255, 0.9);
}

.sql-table-item summary {
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    font-family: 'Barlow Condensed', sans-serif;
    font-size: 1.02rem;
}

.sql-insert-btn {
    font-size: 0.78rem;
    padding: 0.15rem 0.45rem;
}

.sql-columns-wrap {
    margin-top: 0.45rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.sql-column-chip {
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 0.18rem 0.5rem;
    font-size: 0.75rem;
    background: #fff;
    cursor: pointer;
}

.sql-column-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.sql-mermaid-panel {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.9);
    padding: 0.55rem;
}

.sql-mermaid-toolbar {
    display: flex;
    justify-content: flex-end;
    gap: 0.35rem;
    margin-bottom: 0.45rem;
}

.sql-mermaid-diagram {
    position: relative;
    height: 520px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #ffffff;
    cursor: grab;
    touch-action: none;
}

.sql-mermaid-diagram.is-dragging {
    cursor: grabbing;
}

.sql-lab-workspace {
    margin-top: 0.9rem;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.85rem;
}

.sql-editor-panel,
.sql-results-panel {
    padding: 1rem;
}

.sql-editor-header,
.sql-results-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
}

.sql-editor-help {
    margin: 0.5rem 0;
}

.CodeMirror {
    border: 1px solid var(--line);
    border-radius: 10px;
    height: 420px;
    font-size: 0.9rem;
}

.sql-results-table {
    max-height: 480px;
}

@media (max-width: 1100px) {
    .sql-lab-im-grid {
        grid-template-columns: 1fr;
    }
    .sql-lab-workspace {
        grid-template-columns: 1fr;
    }
}
