/* Knox Insights — page-specific styles. Inherits design tokens from styles.css (v3). */

/* Insights body is scrollable, unlike the main dashboard */
body { overflow: auto; }

/* Freshness pill (topbar right) */
.freshness-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    background: var(--panel-2);
    border: 1px solid var(--border-2);
    border-radius: var(--r-md);
    color: var(--text-3);
    font-size: var(--fs-xs);
}
.freshness-pill .dot {
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--good);
    box-shadow: 0 0 0 3px var(--good-bg);
}
.freshness-pill.stale .dot {
    background: var(--warn);
    box-shadow: 0 0 0 3px var(--warn-bg);
}

/* Legacy icon class (kept for compatibility with insights.js inline SVG) */
.icon {
    width: 14px; height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

/* ---------- Layout ---------- */
.page {
    padding: 20px 24px 60px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 1700px;
    margin: 0 auto;
}

.section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-3);
    margin: 0 0 12px;
    font-weight: 600;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 18px 20px;
}

.error-banner {
    padding: 14px 18px;
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.4);
    border-radius: 6px;
    color: var(--warn);
    font-size: 12px;
    display: none;
}
.error-banner.show { display: block; }

.loading {
    color: var(--text-3);
    font-size: 12px;
    padding: 8px 0;
}

/* ---------- Gauges row ---------- */
.gauges {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}
.gauge-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 18px;
    min-height: 110px;
}
.gauge-card .ring {
    position: relative;
    width: 100px;
    height: 100px;
    flex-shrink: 0;
}
.gauge-card .ring canvas {
    width: 100% !important;
    height: 100% !important;
}
.gauge-card .ring .center {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    pointer-events: none;
}
.gauge-card .ring .center .pct {
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.3px;
}
.gauge-card .meta {
    flex: 1;
    min-width: 0;
}
.gauge-card .meta .label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-3);
    margin-bottom: 6px;
}
.gauge-card .meta .num {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}
.gauge-card .meta .total {
    font-size: 11px;
    color: var(--text-3);
}

/* ---------- Map + matrix two-up ---------- */
.two-up {
    display: grid;
    grid-template-columns: minmax(540px, 1fr) minmax(540px, 1fr);
    gap: 14px;
}
@media (max-width: 1280px) {
    .two-up { grid-template-columns: 1fr; }
}

/* Map */
.map-card .map-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 12px;
    color: var(--text-3);
}
.map-card .map-controls .toggle-group {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.map-card .map-controls .toggle-group button {
    background: var(--panel-2);
    color: var(--text-3);
    border: 0;
    padding: 5px 10px;
    font-size: 11px;
    cursor: pointer;
    font-family: inherit;
    transition: background 120ms, color 120ms;
}
.map-card .map-controls .toggle-group button.active {
    background: var(--accent-bg-2);
    color: var(--text);
}
.map-card .map-controls .toggle-group button:hover:not(.active) { color: var(--text); }
.map-card .map-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 960 / 580;
    background: var(--panel-2);
    border-radius: 4px;
    overflow: hidden;
}
.map-card svg {
    width: 100%;
    height: 100%;
    display: block;
}
.map-card svg path.state {
    fill: var(--panel);
    stroke: var(--border);
    stroke-width: 0.6;
    cursor: pointer;
    transition: fill 120ms, stroke 120ms;
}
.map-card svg path.state:hover {
    stroke: var(--accent);
    stroke-width: 1.2;
}
.map-card svg path.state.empty {
    fill: #11161d;
}
.map-tooltip {
    position: absolute;
    pointer-events: none;
    background: rgba(14, 17, 22, 0.95);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 12px;
    color: var(--text);
    min-width: 140px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    opacity: 0;
    transition: opacity 80ms;
    z-index: 5;
}
.map-tooltip.show { opacity: 1; }
.map-tooltip .name {
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--accent);
}
.map-tooltip .row {
    color: var(--text-3);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 11px;
    line-height: 1.6;
}
.map-tooltip .row b { color: var(--text); font-weight: 600; }

.legend {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    font-size: 11px;
    color: var(--text-3);
}
.legend .scale {
    flex: 1;
    height: 10px;
    border-radius: 2px;
    background: linear-gradient(to right, #11161d, var(--accent));
    max-width: 240px;
}

/* ---------- Coverage matrix ---------- */
.matrix-card .matrix-scroll {
    max-height: 520px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
}
table.matrix {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
table.matrix thead {
    position: sticky;
    top: 0;
    background: var(--panel-2);
    z-index: 1;
}
table.matrix thead th {
    text-align: right;
    padding: 9px 10px;
    color: var(--text-3);
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
table.matrix thead th:first-child { text-align: left; }
table.matrix thead th:hover { color: var(--text); }
table.matrix thead th .arr { color: var(--accent); margin-left: 4px; font-size: 10px; }
table.matrix tbody td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    text-align: right;
    white-space: nowrap;
    position: relative;
    line-height: 1.4;
}
table.matrix tbody td:first-child {
    text-align: left;
    color: var(--text);
    font-weight: 600;
}
table.matrix tbody td .pct {
    color: var(--text-3);
    font-size: 10px;
    margin-left: 6px;
}
table.matrix tbody tr:hover td { background: var(--panel-2); }
table.matrix tbody td a {
    color: inherit;
}
.cell-bg {
    position: absolute;
    inset: 0;
    background: var(--accent);
    opacity: 0;
    pointer-events: none;
}
table.matrix tbody td .cell-content {
    position: relative;
    z-index: 1;
}

/* ---------- Firms leaderboard ---------- */
.firms-card .firms-scroll {
    max-height: 540px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 4px;
}
table.firms {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
table.firms thead {
    position: sticky;
    top: 0;
    background: var(--panel-2);
    z-index: 1;
}
table.firms thead th {
    text-align: left;
    padding: 9px 12px;
    color: var(--text-3);
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
table.firms thead th:hover { color: var(--text); }
table.firms thead th.num { text-align: right; }
table.firms thead th .arr { color: var(--accent); margin-left: 4px; font-size: 10px; }
table.firms tbody td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
table.firms tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.firms tbody tr {
    cursor: pointer;
    transition: background 120ms;
}
table.firms tbody tr:hover {
    background: var(--panel-2);
}
table.firms .rank {
    color: var(--text-3);
    font-variant-numeric: tabular-nums;
    width: 38px;
}
table.firms .firm-name {
    color: var(--text);
    font-weight: 600;
}
table.firms .firm-state {
    color: var(--text-3);
    font-size: 11px;
}
table.firms .bar-cell {
    width: 120px;
}
table.firms .bar {
    height: 6px;
    background: var(--panel-2);
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}
table.firms .bar > div {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
}

/* ---------- Source contribution chart ---------- */
.source-card .chart-wrap {
    position: relative;
    height: 360px;
}

/* responsiveness */
@media (max-width: 880px) {
    .gauges { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 540px) {
    .gauges { grid-template-columns: 1fr; }
    .page { padding: 16px; }
}
