:root {
    --brand-blue: #004478;
    --brand-dark-blue: #164374;
    --brand-yellow: #ffcb05;
    --brand-yellow-hover: #ffc400;
    --brand-light-blue: #97d1e8;
    --brand-bg: #ecf0f1;
    --brand-white: #ffffff;
    --text-main: #333333;
    --text-muted: #666666;
    --border-color: #dcdcdc;
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 24px rgba(0, 0, 0, 0.12);
}

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

html {
    height: 100%;
    overflow-x: hidden;   /* nothing escapes the viewport width */
}

body {
    height: 100%;
    max-width: 100vw;
    overflow-x: hidden;
    font-family: 'Open Sans', sans-serif;
    background-color: var(--brand-bg);
    color: var(--text-main);
    line-height: 1.6;
}

h1, h2, h3, h4, h5 {
    font-family: 'Montserrat', sans-serif;
}

.hidden {
    display: none !important;
}

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

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
    font-family: 'Montserrat', sans-serif;
    font-weight: 600;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.btn-primary {
    background-color: var(--brand-blue);
    color: var(--brand-white);
}
.btn-primary:hover { background-color: var(--brand-dark-blue); }

.btn-text {
    background: transparent;
    color: var(--brand-blue);
    padding: 0.4rem 0.8rem;
}
.btn-text:hover { background-color: rgba(0, 68, 120, 0.06); }

.btn-text-sm {
    font-size: 0.75rem;
    padding: 0.25rem 0.6rem;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Loading & Error Panels ───────────────────────────────────────── */
.loading-panel,
.error-panel {
    position: fixed;
    inset: 0;
    background: var(--brand-blue);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.loading-inner,
.error-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    text-align: center;
    padding: 2rem;
    max-width: 400px;
    width: 90%;
}

.loading-logo {
    height: 56px;
    width: auto;
    border-radius: 8px;
    background: var(--brand-white);
    padding: 4px;
}

.loading-inner h1,
.error-inner h1 {
    font-size: 1.4rem;
    color: var(--brand-white);
    margin: 0;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.25);
    border-top-color: var(--brand-yellow);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-top: 0.5rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text  { color: var(--brand-light-blue); font-size: 0.95rem; margin: 0; }
.error-icon    { font-size: 2.5rem; color: var(--brand-yellow); margin-top: 0.5rem; }
.error-inner h2 { color: var(--brand-white); font-size: 1.2rem; margin: 0; }
.error-message { color: var(--brand-light-blue); font-size: 0.875rem; word-break: break-word; margin: 0; }

/* ── App layout ───────────────────────────────────────────────────── */
/* App-shell: the page itself never scrolls. Header, notice and footer are
   fixed bands and the table pane owns both scroll axes — that is what lets
   the header row and first column stay locked while the data scrolls. */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
}

/* ── Header ───────────────────────────────────────────────────────── */
.app-header {
    background: var(--brand-blue);
    color: var(--brand-white);
    padding: 0.6rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-shrink: 0;
    z-index: 30;
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;    /* desktop: never shrink */
    min-width: 0;
}

.header-logo-img {
    height: 40px;
    width: auto;
    border-radius: 6px;
    background: var(--brand-white);
    padding: 3px;
}

.header-logo h1 {
    font-size: 1.2rem;
    margin: 0;
    color: var(--brand-white);
    white-space: nowrap;
}

.header-logo p {
    color: var(--brand-light-blue);
    margin: 0;
    font-size: 0.75rem;
}

.header-search {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 6px;
    padding: 0.45rem 0.9rem;
    max-width: 420px;
    transition: background 0.2s, border-color 0.2s;
}
.header-search:focus-within {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}
.header-search i { color: rgba(255, 255, 255, 0.6); font-size: 0.85rem; flex-shrink: 0; }
.header-search input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--brand-white);
    font-family: 'Open Sans', sans-serif;
    font-size: 0.875rem;
}
.header-search input::placeholder { color: rgba(255, 255, 255, 0.5); }

.header-stats {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
}

.stat-box {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.35rem 1rem;
    border-radius: 6px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
    white-space: nowrap;
}

.stat-number {
    display: inline;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'Montserrat', sans-serif;
    color: var(--brand-yellow);
    margin-right: 0.3rem;
}

.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.75);
}

/* Reset button lives in the header stats row */
.btn-reset {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    background: rgba(255,255,255,0.12);
    color: var(--brand-white);
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 6px;
    padding: 0.3rem 0.75rem;
    font-family: 'Open Sans', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.2s;
}
.btn-reset:hover { background: rgba(255,255,255,0.22); }

/* ── Column filter dropdown ───────────────────────────────────────── */
/* Fixed-position so it escapes the table's scroll container clipping. */
.col-dropdown {
    position: fixed;
    width: 260px;
    max-width: calc(100vw - 16px);
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.16);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.cd-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem;
    background: var(--brand-blue);
    color: var(--brand-white);
}
.cd-title {
    font-family: 'Montserrat', sans-serif;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cd-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.75);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0 0.15rem;
    line-height: 1;
}
.cd-close:hover { color: #fff; }

.cd-search-wrap {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
}
.cd-search-wrap i { color: var(--text-muted); font-size: 0.78rem; flex-shrink: 0; }
.cd-search {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    font-family: 'Open Sans', sans-serif;
    font-size: 0.82rem;
    color: var(--text-main);
    background: transparent;
}

.cd-actions {
    display: flex;
    gap: 0.75rem;
    padding: 0.4rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    background: #f7f9fa;
}
.cd-action {
    background: none;
    border: none;
    padding: 0;
    font-family: 'Open Sans', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--brand-blue);
    cursor: pointer;
}
.cd-action:hover { text-decoration: underline; }

.cd-list {
    overflow-y: auto;
    max-height: 260px;
    padding: 0.3rem 0;
}

.cd-option {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.42rem 0.75rem;
    font-size: 0.85rem;
    color: var(--text-main);
    cursor: pointer;
    user-select: none;
    transition: background 0.12s;
}
.cd-option:hover { background: #f0f7fb; }

.cd-option input[type="checkbox"] {
    accent-color: var(--brand-blue);
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    cursor: pointer;
}

.cd-empty {
    padding: 0.75rem;
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* ── Results limit notice ──────────────────────────────────────────── */
.results-limit-notice {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem 0.5rem;
    background: #fff8e1;
    border-bottom: 1px solid #ffe082;
    padding: 0.45rem 1.5rem;
    font-size: 0.82rem;
    color: #5d4037;
    flex-shrink: 0;
    width: 100%;
    box-sizing: border-box;
    line-height: 1.5;
}
.results-limit-notice i { color: #f9a825; font-size: 0.85rem; flex-shrink: 0; }

/* ── Main content ─────────────────────────────────────────────────── */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #f7f9fa;
    min-width: 0;     /* prevent flex child from expanding past its container */
    min-height: 0;    /* critical: lets the table pane shrink and scroll itself */
    width: 100%;
}

/* ── Footer ───────────────────────────────────────────────────────── */
.app-footer {
    background: var(--brand-blue);
    color: var(--brand-light-blue);
    text-align: center;
    padding: 0.75rem 2rem;
    font-size: 0.85rem;
    flex-shrink: 0;
}

/* ── Table ────────────────────────────────────────────────────────── */
.table-responsive {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 1.5rem 1.5rem 1.5rem;
    width: 100%;
    box-sizing: border-box;
}

/* The one element that scrolls: sticky offsets inside the table resolve
   against this box, so top:0 / left:0 lock against its own edges. */
.table-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--brand-white);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
}

.strategies-table {
    width: 100%;
    /* `separate` is required — collapsed borders don't travel with sticky cells */
    border-collapse: separate;
    border-spacing: 0;
    min-width: 2000px;
    background: var(--brand-white);
}

/* Locked header row */
.strategies-table thead th {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #f7f9fa;
}

/* Locked first column */
.sticky-col {
    position: sticky !important;
    left: 0;
    z-index: 10;
    background-color: var(--brand-white);
    border-right: 1px solid var(--border-color);
}
/* Top-left cell sits above both */
.strategies-table thead th.sticky-col {
    z-index: 30;
    background-color: #f7f9fa;
}
.strategies-table tbody tr:nth-child(even) .sticky-col { background-color: #fcfdfe; }
.strategies-table tbody tr:hover .sticky-col { background-color: #f0f7fb; transition: background-color 0.2s; }

/* Shadows that make the locked edges read as pinned once scrolled under */
.strategies-table thead th { box-shadow: inset 0 -2px 0 var(--border-color); }
.sticky-col { box-shadow: 2px 0 4px -2px rgba(0,0,0,0.12); }
.strategies-table thead th.sticky-col { box-shadow: inset 0 -2px 0 var(--border-color), 2px 0 4px -2px rgba(0,0,0,0.12); }

.strategies-table th.width-wide,
.strategies-table td.width-wide { width: 260px; min-width: 220px; max-width: 260px; }
/* Only the body cells wrap — the header label stays on one line */
.strategies-table td.width-wide { white-space: normal !important; }

.strategies-table th {
    font-family: 'Montserrat', sans-serif;
    color: var(--brand-dark-blue);
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 0.65rem 0.5rem 0.65rem 0.75rem;
    text-align: left;
    vertical-align: middle;
    /* Headers never wrap — the column widens to fit the label instead */
    white-space: nowrap;
}

/* ── Header cell: sort on the left, filter on the right ───────────── */
.th-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    white-space: nowrap;
}

.th-sort {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex: 0 0 auto;   /* never shrink below the label's natural width */
    background: none;
    border: none;
    padding: 0.15rem 0;
    font: inherit;
    color: inherit;
    text-align: left;
    text-transform: inherit;
    letter-spacing: inherit;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    border-radius: 4px;
    transition: color 0.15s;
}
.th-sort:hover { color: var(--brand-blue); }

.th-label { line-height: 1.3; white-space: nowrap; }

.sort-icon { font-size: 0.72rem; color: #aaa; flex-shrink: 0; transition: color 0.15s; }
.th-sort:hover .sort-icon { color: var(--brand-blue); }
.col-head.sort-active .sort-icon { color: var(--brand-yellow); }
.col-head.sort-active .th-label { color: var(--brand-blue); }

.th-filter {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    flex-shrink: 0;
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 0.2rem 0.3rem;
    color: #aaa;
    font-size: 0.72rem;
    cursor: pointer;
    transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.th-filter:hover {
    color: var(--brand-blue);
    background: rgba(0,68,120,0.08);
}
.col-head.filter-open .th-filter {
    color: var(--brand-blue);
    border-color: var(--brand-blue);
    background: rgba(0,68,120,0.08);
}
.col-head.has-filter .th-filter {
    color: var(--brand-white);
    background: var(--brand-blue);
    border-color: var(--brand-blue);
}

.th-filter-count {
    font-family: 'Open Sans', sans-serif;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 1;
}

.strategies-table td {
    padding: 0.7rem 0.75rem;
    white-space: nowrap;   /* short categorical values stay on one line too */
    border-bottom: 1px solid #f0f0f0;
    color: var(--text-main);
    font-size: 0.875rem;
    vertical-align: middle;
}

.strategies-table tbody tr:nth-child(even) { background-color: #fcfdfe; }
.strategies-table tbody tr:hover { background-color: #f0f7fb; transition: background-color 0.2s; }

.strategy-title-cell {
    font-weight: 600;
    color: var(--brand-dark-blue);
    line-height: 1.4;
}

/* ── Status badges ────────────────────────────────────────────────── */
.status-badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 12px;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-green  { background: #e8f5e9; color: #2e7d32; }
.badge-red    { background: #ffebee; color: #c62828; }
.badge-blue   { background: #e3f2fd; color: #1565c0; }
.badge-purple { background: #f3e5f5; color: #6a1b9a; }
.badge-gray   { background: #f5f5f5; color: #616161; }

/* ── No-results state ─────────────────────────────────────────────── */
/* Rendered as a full-width row so the header row — and therefore the
   filters — stay on screen when nothing matches. */
.no-results-cell {
    padding: 4rem 2rem !important;
    color: var(--text-muted);
}
/* Sticky inner block keeps the message on screen at any horizontal offset */
.no-results-inner {
    position: sticky;
    left: 0;
    display: block;
    width: 100%;
    max-width: min(100%, 560px);
    margin: 0 auto;
    text-align: center;
}
.no-results-inner i  { font-size: 3rem; color: #ddd; margin-bottom: 1rem; display: block; }
.no-results-inner h3 { font-size: 1.35rem; color: var(--text-main); margin-bottom: 0.5rem; }
.no-results-inner p  { margin-bottom: 1.5rem; }
.strategies-table tbody tr:hover .no-results-cell { background: transparent; }

/* ════════════════════════════════════════════════════════════════════
   TABLET + PHONE  ≤ 1023 px
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 1023px) {
    /* ── Header: row 1 = logo + stats, row 2 = search ── */
    .app-header {
        flex-wrap: wrap;
        align-items: center;
        padding: 0.55rem 1rem;
        gap: 0.5rem;
    }

    /* Logo fills remaining space on row 1, truncates if needed */
    .header-logo {
        flex: 1 1 auto;
        min-width: 0;          /* allow shrinking */
        flex-shrink: 1;
    }

    .header-logo h1 {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Stats stay on row 1 to the right */
    .header-stats {
        flex: 0 0 auto;
    }

    /* Search becomes its own full-width row 2 */
    .header-search {
        order: 10;
        flex: 1 1 100%;
        max-width: 100%;
    }

    /* Bigger touch target on the header filter icons */
    .th-filter { padding: 0.35rem 0.4rem; font-size: 0.8rem; }

    .table-responsive { padding: 0.75rem; }
}

/* ════════════════════════════════════════════════════════════════════
   PHONE  < 600 px
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 599px) {
    .app-header {
        padding: 0.5rem 0.75rem;
    }

    .header-logo-img { height: 30px; }

    .header-logo h1 {
        font-size: 0.92rem;
    }

    /* Hide subtitle on phone */
    .header-logo p { display: none; }

    /* Compact stat boxes — show number only on very small screens */
    .stat-box      { padding: 0.25rem 0.6rem; }
    .stat-number   { font-size: 0.9rem; }
    .stat-label    { font-size: 0.62rem; letter-spacing: 0; }

    .col-dropdown { width: 230px; }

    /* Table full-bleed */
    .table-responsive { padding: 0; }
    .table-scroll     { border-radius: 0; }

    .results-limit-notice { padding: 0.4rem 0.75rem; font-size: 0.76rem; }

    .no-results-cell     { padding: 3rem 1.25rem !important; }
    .no-results-inner i  { font-size: 2.8rem; }
    .no-results-inner h3 { font-size: 1.15rem; }
}

/* ── Reduced motion ───────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .th-sort, .th-filter, .btn { transition: none !important; }
}
