/* ============= Full Responsive Overhaul ============= */

/* Ultra-wide screens (2K, 4K, ultrawide monitors) */
@media (min-width: 1921px) {
    .container { padding: 24px 48px; }
    .global-header { padding: 12px 48px; }
    .dashboard-section { padding: 24px; }
    /* h1 sizing controlled by tokens */
    .ci-hud-table { font-size: var(--text-sm); }
    .ci-hud-table thead th { padding: 14px 16px; font-size: var(--text-xs); }
    .status-badge { font-size: var(--text-sm); padding: 6px 12px; }
    .tab-button { font-size: var(--text-md); padding: 12px 24px; }
}

@media (min-width: 2560px) {
    .container { padding: 32px 64px; }
    .global-header { padding: 14px 64px; }
    .tab-button { font-size: var(--text-base); padding: 14px 28px; }
    .ci-hud-table { font-size: var(--text-md); }
}

/* Mobile: ensure all tables scroll horizontally */
@media (max-width: 768px) {
    .table-container,
    .horizontal-scroll {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        max-width: 100vw;
    }

    .ci-hud-table,
    .status-table,
    .pytorch-table,
    .issues-table {
        min-width: 600px;
    }

    /* Mobile sticky strategy: keep only SHA + PR frozen (100px) so the bulk of
       a ~390px screen is free for the CI data. Message/Author/Time un-stick and
       scroll with the grid. SHA/PR widths + offsets are recomputed to match
       (the old rules shrank only header widths and kept desktop left offsets,
       overflowing to ~530px with header/body misalignment). */
    .ci-hud-table thead th.col-sha,
    .ci-hud-table tbody td.col-sha  { left: 0;    width: 60px; min-width: 60px; max-width: 60px; }
    .ci-hud-table thead th.col-pr,
    .ci-hud-table tbody td.col-pr   { left: 60px; width: 40px; min-width: 40px; max-width: 40px; }
    /* Un-stick the rest so they scroll instead of eating the viewport. */
    .ci-hud-table thead th.col-msg,
    .ci-hud-table tbody td.col-msg  { position: static; left: auto; min-width: 160px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
    .ci-hud-table thead th.col-auth,
    .ci-hud-table tbody td.col-auth { position: static; left: auto; min-width: 70px; max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
    .ci-hud-table thead th.col-time,
    .ci-hud-table tbody td.col-time { position: static; left: auto; min-width: 60px; }
    .author-avatar { display: none; }

    .col-cat-header { font-size: 0.6rem !important; padding: 6px 4px !important; }
    .cat-badge { font-size: 0.65rem; padding: 2px 5px; }

    .col-job-header { min-width: 26px !important; max-width: 28px !important; width: 27px !important; }
    .col-job-cell { min-width: 26px !important; max-width: 28px !important; width: 27px !important; }
    .job-dot { width: 18px; height: 18px; font-size: 0.6rem; }
    .ci-hud-job-header-row th.col-job-header { height: 90px; }
    .ci-hud-job-header-row th.col-job-header .job-header-text { font-size: 0.55rem; max-height: 85px; }

    .ci-hud-expanded-grid { grid-template-columns: 1fr !important; }
    .expanded-section { padding: 8px !important; }
    .expanded-items { gap: 4px !important; }
    .expanded-item { font-size: 0.7rem !important; padding: 3px 6px !important; }
}

/* Small phones */
@media (max-width: 480px) {
    .tab-navigation { gap: 4px; padding: 6px; }
    .tab-button { padding: 6px 8px; font-size: 0.65rem; }
    .container { padding: 6px 8px; }
    .dashboard-section { padding: 8px; margin-bottom: 12px; }
    .ci-hud-table { font-size: 0.7rem; }
    .ci-hud-table thead th { padding: 6px 4px; font-size: 0.6rem; }

    .issues-filters,
    .ci-hud-filters { flex-direction: column; gap: 8px; }
    .filter-group { width: 100%; }
    .filter-group select,
    .filter-group input { width: 100%; min-width: 0; }

    .ci-hud-pagination-btns { flex-wrap: wrap; gap: 4px; }
    .ci-hud-page-btn { font-size: 0.7rem; padding: 6px 10px; }
    .ci-hud-page-nums { gap: 2px; }
}

/* Tablet landscape */
@media (min-width: 769px) and (max-width: 1024px) {
    .container { padding: 16px 20px; }
    .ci-hud-table td.col-msg { max-width: 200px; }
}

/* ========================================
   Issues Pivot (Arch × Torch/JAX version)
   ======================================== */

#issues-pivot-section .section-subtle {
    font-size: 0.85rem;
    color: var(--text-secondary, #888);
    font-weight: normal;
    margin-left: 4px;
}

.pivot-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    margin: 8px 0 14px 0;
}

.pivot-ecosystem-switch {
    display: inline-flex;
    border: 1px solid rgba(139, 92, 246, 0.35);
    border-radius: 8px;
    overflow: hidden;
}

.pivot-eco-btn {
    background: transparent;
    border: none;
    color: inherit;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.pivot-eco-btn + .pivot-eco-btn {
    border-left: 1px solid rgba(139, 92, 246, 0.25);
}

.pivot-eco-btn:hover {
    background: rgba(99, 102, 241, 0.12);
}

.pivot-eco-btn.active {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: #fff;
}

.pivot-state-toggle,
.pivot-platform-filter {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
}

.pivot-state-toggle label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}

.pivot-platform-filter select {
    background: rgba(79, 70, 229, 0.08);
    border: 1px solid rgba(139, 92, 246, 0.25);
    color: inherit;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.88rem;
}

.pivot-hint {
    color: var(--text-secondary, #888);
    font-size: 0.8rem;
    margin-left: auto;
    font-style: italic;
}

/* Pivot table */
.pivot-table {
    width: auto;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.pivot-table thead th {
    background: var(--table-header-bg, #1a1a2e);
    color: var(--table-header-text, #fff);
    padding: 10px 14px;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    text-align: center;
    white-space: nowrap;
}

.pivot-table thead .pivot-corner,
.pivot-table tbody .pivot-row-label,
.pivot-table .sticky-left {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--table-header-bg, #1a1a2e);
    color: var(--table-header-text, #fff);
    text-align: left !important;
    padding-right: 18px !important;
    white-space: nowrap;
}

.pivot-table tbody .pivot-row-label {
    font-weight: 600;
    background: rgba(79, 70, 229, 0.1);
}

.pivot-col-total {
    margin-top: 2px;
    font-size: 0.7rem;
    opacity: 0.75;
    font-weight: 400;
}

.pivot-table td.pivot-cell {
    text-align: center;
    padding: 0;
    vertical-align: middle;
    border-bottom: 1px solid rgba(127, 127, 127, 0.1);
}

.pivot-table td.pivot-empty {
    color: var(--text-secondary, #888);
    opacity: 0.4;
    padding: 10px 14px;
}

.pivot-cell-btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-width: 44px;
    min-height: 34px;
    padding: 6px 12px;
    border: 1px solid rgba(99, 102, 241, 0.4);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2) 0%, rgba(139, 92, 246, 0.2) 100%);
    color: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    border-radius: 6px;
    cursor: pointer;
    transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease;
}

.pivot-cell-btn:hover {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.35) 0%, rgba(139, 92, 246, 0.35) 100%);
    border-color: rgba(139, 92, 246, 0.7);
    transform: translateY(-1px);
}

.pivot-cell-btn.ghost {
    background: transparent;
    border-color: rgba(127, 127, 127, 0.3);
    opacity: 0.8;
}

.pivot-cell-btn.ghost:hover {
    background: rgba(127, 127, 127, 0.1);
    opacity: 1;
}

.pivot-table .pivot-unknown .pivot-cell-btn {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.18) 0%, rgba(245, 158, 11, 0.08) 100%);
    border-color: rgba(245, 158, 11, 0.4);
}

.pivot-table .pivot-unknown .pivot-cell-btn:hover {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.3) 0%, rgba(245, 158, 11, 0.15) 100%);
    border-color: rgba(245, 158, 11, 0.6);
}

.pivot-table td.pivot-row-total {
    text-align: center;
    padding: 8px 12px;
    font-weight: 600;
    color: var(--text-secondary, #888);
    background: rgba(127, 127, 127, 0.05);
}

.pivot-table .pivot-totals-row th,
.pivot-table .pivot-totals-row td {
    background: rgba(79, 70, 229, 0.12) !important;
    border-top: 2px solid rgba(139, 92, 246, 0.4);
    font-weight: 600;
    padding: 10px 14px;
}

.pivot-table .pivot-grand-total {
    color: #8b5cf6;
    font-size: 1.05rem;
    text-align: center;
}

/* Drilldown panel */
.pivot-drilldown {
    margin-top: 16px;
    border: 1px solid rgba(139, 92, 246, 0.35);
    border-radius: 10px;
    background: rgba(79, 70, 229, 0.05);
    overflow: hidden;
}

.pivot-drilldown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15) 0%, rgba(139, 92, 246, 0.15) 100%);
    border-bottom: 1px solid rgba(139, 92, 246, 0.25);
}

.pivot-drilldown-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.pivot-drilldown-count {
    font-weight: 400;
    opacity: 0.7;
    margin-left: 6px;
    font-size: 0.9rem;
}

.pivot-drilldown-close {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 4px;
    line-height: 1;
}

.pivot-drilldown-close:hover {
    background: rgba(127, 127, 127, 0.2);
}

.pivot-drilldown-body {
    padding: 12px 18px;
    max-height: 520px;
    overflow-y: auto;
}

.pivot-drilldown-empty {
    text-align: center;
    padding: 30px;
    color: var(--text-secondary, #888);
}

.pivot-drilldown-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.pivot-drilldown-table th {
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary, #888);
    padding: 6px 8px;
    border-bottom: 1px solid rgba(127, 127, 127, 0.25);
}

.pivot-drilldown-table td {
    padding: 8px;
    border-bottom: 1px solid rgba(127, 127, 127, 0.12);
    vertical-align: middle;
}

.pivot-drilldown-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.05);
}

.pivot-issue-title {
    max-width: 520px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pivot-issue-title a {
    color: inherit;
    text-decoration: none;
}

.pivot-issue-title a:hover {
    text-decoration: underline;
    color: #8b5cf6;
}

.pivot-assignee-row {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

.pivot-assignee-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid rgba(127, 127, 127, 0.3);
    display: inline-block;
}

.pivot-assignee-more {
    font-size: 0.75rem;
    color: var(--text-secondary, #888);
    margin-left: 4px;
}

.pivot-assignee-none {
    color: var(--text-secondary, #888);
    opacity: 0.5;
}

/* Status pills */
.status-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.status-pill.closed         { background: rgba(127, 127, 127, 0.2); color: #9ca3af; }
.status-pill.triage         { background: rgba(88, 93, 215, 0.2);   color: #a5b4fc; }
.status-pill.assessed       { background: rgba(230, 216, 19, 0.2);  color: #fbbf24; }
.status-pill.fix-submitted  { background: rgba(117, 217, 126, 0.2); color: var(--status-pass); }
.status-pill.unlabeled      { background: rgba(239, 68, 68, 0.15);  color: #f87171; }

/* Light theme tweaks for pivot */
[data-theme="light"] .pivot-table thead th,
[data-theme="light"] .pivot-table .sticky-left {
    background: #eef2ff;
    color: #1e1b4b;
}

[data-theme="light"] .pivot-table tbody .pivot-row-label {
    background: #f5f3ff;
}

[data-theme="light"] .pivot-drilldown {
    background: #fafafa;
}
