/* ==========================================================================
   5. ANALYTICS DASHBOARD, KPI CARDS, BREAKDOWNS & SHORT LINKS TABLE
   ========================================================================== */
/* ==========================================================================
   ANALYTICS & LINK MANAGEMENT TAB STYLES
   ========================================================================== */
.analytics-view { display: none; flex-direction: column; gap: 18px; }
.analytics-controls-card { padding: 16px 20px; }
.analytics-controls-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: nowrap;
}
.analytics-header-actions { display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0; }
.analytics-jump-btn,
.analytics-refresh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    height: 36px;
    gap: 5px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 11.5px;
    font-weight: 700;
    line-height: 1.1;
    white-space: nowrap;
    box-sizing: border-box;
    cursor: pointer;
    transition: var(--transition);
}
.analytics-jump-btn { background: rgba(96, 165, 250, 0.10); border: 1px solid rgba(96, 165, 250, 0.28); color: var(--accent); }
.analytics-jump-btn:hover { background: rgba(96, 165, 250, 0.18); border-color: var(--accent); color: #f8fafc; }
.analytics-controls-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
}
.analytics-filters-left {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    flex: 1;
}
.short-links-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.short-links-header-top { display: contents; }
.short-links-card-header .card-title { order: 1; }
.short-links-header-tools {
    order: 2;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex: 1;
    min-width: 260px;
}
#jumpToAnalyticsTopBtn { order: 3; }
.short-links-search-input {
    max-width: 260px;
    min-height: 36px;
    height: 36px;
    padding: 6px 12px;
    box-sizing: border-box;
}
.short-links-group-select { min-height: 36px; height: 36px; padding: 6px 12px; box-sizing: border-box; }
.kpi-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
@media (max-width: 820px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .kpi-card:nth-child(5) { grid-column: 1 / -1; }
}
.kpi-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    container-type: inline-size;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 10px 28px -10px rgba(0, 0, 0, 0.45);
}
.kpi-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}
.kpi-value {
    font-family: 'Outfit', sans-serif;
    font-size: clamp(18px, 13cqi, 26px);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
    letter-spacing: -0.02em;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.kpi-sub { font-size: 11px; font-variant-numeric: tabular-nums; color: var(--text-dim); }
.breakdown-grid { display: grid; grid-template-columns: 1.18fr 1.12fr 1.18fr; gap: 14px; align-items: stretch; }
@media (max-width: 960px) {
    .breakdown-grid { gap: 10px; }
    .mini-breakdown-card { padding: 12px; }
}
@media (max-width: 780px) {
    .breakdown-grid { grid-template-columns: 1fr; align-items: start; }
}
.mini-breakdown-card {
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    min-width: 0;
    container-type: inline-size;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 10px 28px -10px rgba(0, 0, 0, 0.45);
}
.mini-breakdown-card:not([open]) { padding-top: 0; padding-bottom: 0; }
.mini-breakdown-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    list-style: none;
}
.mini-breakdown-card:not([open]) > .mini-breakdown-summary { min-height: 44px; padding: 12px 0; box-sizing: border-box; }
.mini-breakdown-summary::-webkit-details-marker { display: none; }
.mini-breakdown-summary::marker { content: ""; }
.mini-breakdown-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.mini-breakdown-summary .mini-breakdown-title { margin-bottom: 0; }
.breakdown-chevron-icon { flex-shrink: 0; color: var(--text-muted); transition: transform 0.18s ease; transform: rotate(-90deg); }
.mini-breakdown-card[open] > .mini-breakdown-summary .breakdown-chevron-icon { transform: rotate(0deg); }
.mini-breakdown-card[open] > .breakdown-list { margin-top: 8px; }
@media (min-width: 781px) {
    .mini-breakdown-card { display: flex; flex-direction: column; }
    .mini-breakdown-summary { cursor: default; pointer-events: none; }
    .breakdown-chevron-icon { display: none; }
    .mini-breakdown-card[open] > .breakdown-list { flex: 1; display: flex; flex-direction: column; }
}
.breakdown-list { display: flex; flex-direction: column; gap: 8px; font-size: 12px; }
.breakdown-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    gap: 4px 10px;
    color: var(--text-main);
}
.breakdown-row span.val {
    font-family: monospace;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
    margin-left: auto;
    text-align: right;
    white-space: nowrap;
}
.share-pct { font-size: 10.5px; font-weight: 600; color: var(--text-muted); }
/* Card 1 & Card 3: Performance by Brand & Traffic Sources Tabular Mini-Tables */
.brand-breakdown-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 12px; }
.brand-breakdown-table th {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    padding: 0 6px 6px 6px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.14);
    text-align: right;
    white-space: nowrap;
}
.brand-breakdown-table th:first-child { text-align: left; padding-left: 0; }
.brand-breakdown-table th:last-child { padding-right: 0; }
.brand-breakdown-table td {
    padding: 7px 6px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
    text-align: right;
    vertical-align: middle;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.brand-breakdown-table td:first-child { text-align: left; padding-left: 0; font-weight: 700; color: var(--text-main); }
.brand-breakdown-table td:last-child { padding-right: 0; }
.brand-breakdown-table tbody tr:last-child td { border-bottom-color: transparent; }
.brand-cell-inner { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.brand-mini-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}
.brand-breakdown-table td.num-muted { font-family: monospace; font-weight: 600; color: var(--text-muted); }
.brand-breakdown-table td.num-val { font-family: monospace; font-weight: 700; color: var(--text-main); }
.brand-ctr-pill {
    display: inline-block;
    font-family: monospace;
    font-size: 11px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    padding: 2px 6px;
    border-radius: 9999px;
    background: rgba(16, 185, 129, 0.14);
    color: var(--success-text);
    border: 1px solid rgba(16, 185, 129, 0.28);
    white-space: nowrap;
}
/* Card 2: Visitor Devices & OS 2-Column Split */
.device-os-split-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.device-os-col { display: flex; flex-direction: column; gap: 0; min-width: 0; }
.device-os-col + .device-os-col { border-left: 1px solid rgba(148, 163, 184, 0.14); padding-left: 16px; }
.device-os-subhead {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    padding: 0 0 6px 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.14);
    white-space: nowrap;
}
.device-os-list { display: flex; flex-direction: column; gap: 0; }
.device-os-row {
    padding: 7px 0;
    min-height: 34px;
    box-sizing: border-box;
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
    gap: 2px 6px;
}
.device-os-row:last-child { border-bottom-color: transparent; }
.device-os-label,
.source-label { font-weight: 600; color: var(--text-main); white-space: nowrap; }
/* Card 3: Traffic Sources Table + Compact Creation Method Footer */
.traffic-card-body { display: flex; flex-direction: column; flex: 1; justify-content: space-between; gap: 6px; }
.creation-method-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 7px;
    margin-top: auto;
    border-top: 1px solid rgba(148, 163, 184, 0.12);
    font-size: 11px;
    line-height: 1.2;
    white-space: nowrap;
}
.creation-method-label {
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    flex-shrink: 0;
}
.creation-method-values {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.creation-method-name { color: var(--text-muted); font-weight: 500; }
.creation-method-count { font-family: monospace; font-weight: 700; color: var(--text-main); }
.creation-method-sep { color: var(--text-dim); }
@container (max-width: 340px) {
    .brand-breakdown-table { font-size: 10.5px; }
    .brand-breakdown-table th { font-size: 9px; padding: 0 2px 5px 2px; }
    .brand-breakdown-table td { padding: 6px 2px; }
    .brand-breakdown-table td.num-muted,
    .brand-breakdown-table td.num-val { letter-spacing: -0.02em; }
    .brand-cell-inner { gap: 4px; }
    .brand-mini-dot { width: 6px; height: 6px; }
    .brand-ctr-pill { font-size: 9.5px; padding: 1px 4px; }
    .device-os-split-grid { gap: 8px; }
    .device-os-col + .device-os-col { padding-left: 8px; }
    .device-os-subhead { font-size: 9px; padding-bottom: 5px; }
    .device-os-row { font-size: 10.5px; padding: 6px 0; min-height: 29px; }
    .share-pct { font-size: 9px; }
    .creation-method-footer { font-size: 10px; padding-top: 5px; gap: 4px; }
    .creation-method-label { font-size: 8.5px; }
    .creation-method-values { gap: 3px; }
}
@container (max-width: 265px) {
    .device-os-row .share-pct { display: none; }
}
@container (max-width: 210px) {
    .device-os-split-grid { grid-template-columns: 1fr; }
    .device-os-col + .device-os-col { border-left: none; padding-left: 0; border-top: 1px solid rgba(148, 163, 184, 0.12); padding-top: 8px; }
}
/* Grouped Links Management Table & Link Detail Modal */
.table-responsive { width: 100%; overflow-x: hidden; }
.links-groups-stack { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.links-empty-state { text-align: center; color: var(--text-muted); padding: 28px 16px; font-size: 13px; }
.links-flat-table-wrap { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); overflow: hidden; }
.links-group-section { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); overflow: hidden; }
.links-group-header {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    min-height: 42px;
    background: var(--surface-3);
    cursor: pointer;
    user-select: none;
    transition: var(--transition);
}
.links-group-header::-webkit-details-marker { display: none; }
.links-group-header:hover { background: rgba(45, 60, 88, 0.85); }
.links-group-section[open] > .links-group-header { border-bottom: 1px solid rgba(148, 163, 184, 0.14); }
.group-chevron-icon { flex-shrink: 0; color: var(--text-muted); transition: transform 0.18s ease; transform: rotate(-90deg); }
.links-group-section[open] > .links-group-header .group-chevron-icon { transform: rotate(0deg); color: var(--accent); }
.links-group-header-left {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
    flex: 1;
}
.links-group-title {
    font-family: 'Outfit', sans-serif;
    font-size: 13.5px;
    font-weight: 700;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.links-group-domain {
    font-family: monospace;
    font-size: 11px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.group-count-pill { flex-shrink: 0; font-size: 10.5px; padding: 1px 7px; white-space: nowrap; }
.links-group-header-metrics {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}
.group-metric-col {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    gap: 2px;
    line-height: 1.1;
    white-space: nowrap;
}
.group-metric-col + .group-metric-col { border-left: 1px solid rgba(148, 163, 184, 0.14); padding-left: 8px; }
.group-metric-lbl {
    font-family: 'Inter', sans-serif;
    font-size: 8.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    line-height: 1;
}
.group-metric-val {
    font-family: monospace;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--text-main);
    font-variant-numeric: tabular-nums;
    line-height: 1.15;
}
.group-metric-col-ctr .brand-ctr-pill { font-size: 10.5px; padding: 1px 6px; line-height: 1.15; }
.links-compact-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    font-size: 12.5px;
}
.links-compact-table th {
    padding: 7px 12px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    background: rgba(8, 12, 22, 0.55);
    border-bottom: 1px solid rgba(148, 163, 184, 0.12);
    white-space: nowrap;
}
.links-compact-table th.col-slashtag,
.links-compact-table td.col-slashtag { text-align: left; width: auto; }
.links-compact-table th.col-metric,
.links-compact-table td.col-metric {
    text-align: right;
    width: 86px;
    font-family: monospace;
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
}
.links-compact-table th.col-ctr,
.links-compact-table td.col-ctr { text-align: right; width: 84px; white-space: nowrap; }
.link-compact-row { cursor: pointer; transition: background-color 0.14s ease; }
.link-compact-row td { padding: 8px 12px; border-bottom: 1px solid rgba(148, 163, 184, 0.08); vertical-align: middle; }
.link-compact-row:last-child td { border-bottom: none; }
.link-compact-row:hover td,
.link-compact-row:focus-visible td { background: rgba(96, 165, 250, 0.08); }
.link-compact-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.compact-slug-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}
.status-dot.active { background: var(--success-text); }
.status-dot.inactive { background: var(--danger-text); }
.compact-slug-text {
    font-family: monospace;
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.compact-brand-tag {
    font-size: 9.5px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(148, 163, 184, 0.14);
    color: var(--text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}
.compact-title-line {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
    padding-left: 13px;
}
.compact-ctr-wrap { display: inline-flex; align-items: center; justify-content: flex-end; gap: 5px; }
.row-detail-chevron { font-size: 15px; line-height: 1; font-weight: 700; color: var(--text-dim); }
.link-compact-row:hover .row-detail-chevron { color: var(--accent); }
/* External Dashboard API Panel */
.api-endpoint-box {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
}
.api-endpoint-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-family: monospace;
    font-size: 12px;
    color: #cbd5e1;
    background: var(--surface-2);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.12);
    word-break: break-all;
}
@media (max-width: 768px) {
    .analytics-view { gap: 8px; }
    .analytics-controls-card { padding: 10px 12px; }
    .analytics-controls-header { margin-bottom: 8px; gap: 6px; }
    .analytics-controls-header .card-title { font-size: 13.5px; gap: 6px; white-space: nowrap; }
    .analytics-controls-header .card-step-badge { width: 20px; height: 20px; font-size: 11px; }
    .analytics-header-actions { gap: 6px; }
    .analytics-jump-btn,
    .analytics-refresh-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 36px;
        height: 36px;
        padding: 6px 10px;
        font-size: 11.5px;
        gap: 5px;
        border-radius: 8px;
        white-space: nowrap;
        box-sizing: border-box;
    }
    .analytics-controls-bar { gap: 8px; }
    .analytics-filters-left { display: grid; grid-template-columns: 1.25fr 1fr; gap: 8px; width: 100%; }
    .analytics-filters-left .filter-select {
        width: 100%;
        min-width: 0;
        padding: 6px 8px;
        min-height: 36px;
        height: 36px;
        text-overflow: ellipsis;
    }
    .kpi-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
    .kpi-card:nth-child(1),
    .kpi-card:nth-child(2),
    .kpi-card:nth-child(3) { grid-column: span 2; }
    .kpi-card:nth-child(4),
    .kpi-card:nth-child(5) { grid-column: span 3; }
    .kpi-card { padding: 7px 6px; gap: 2px; border-radius: 10px; }
    .kpi-label {
        font-size: 9px;
        letter-spacing: 0.1px;
        line-height: 1.15;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .kpi-value { font-size: clamp(14px, 4.1vw, 17px); line-height: 1.15; }
    .kpi-sub { display: none; }
    .breakdown-grid { gap: 8px; }
    .mini-breakdown-card { padding: 10px 12px; }
    .mini-breakdown-card:not([open]) { padding-top: 0; padding-bottom: 0; }
    .mini-breakdown-card:not([open]) > .mini-breakdown-summary { min-height: 36px; padding: 8px 0; box-sizing: border-box; }
    .mini-breakdown-title { font-size: 11px; margin-bottom: 6px; }
    .mini-breakdown-summary .mini-breakdown-title { margin-bottom: 0; }
    .mini-breakdown-card[open] > .breakdown-list { margin-top: 6px; }
    .brand-breakdown-table th { padding-bottom: 4px; }
    .brand-breakdown-table td { padding: 5px 2px; }
    .device-os-subhead { padding-bottom: 4px; }
    .device-os-row { padding: 5px 0; min-height: 28px; }
    .short-links-card { padding: 12px; }
    .short-links-card-header { flex-direction: column; align-items: stretch; gap: 8px; margin-bottom: 10px; }
    .short-links-header-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        width: 100%;
    }
    .short-links-card-header .card-title { order: 0; font-size: 14px; gap: 6px; }
    #jumpToAnalyticsTopBtn { order: 0; }
    .short-links-header-tools {
        order: 0;
        width: 100%;
        display: grid;
        grid-template-columns: minmax(0, 1fr) 142px;
        gap: 8px;
        min-width: 0;
    }
    .short-links-search-input {
        width: 100%;
        max-width: none;
        min-width: 0;
        padding: 6px 10px;
        min-height: 36px;
        height: 36px;
    }
    .short-links-group-select {
        width: 100%;
        min-width: 0;
        padding: 6px 8px;
        min-height: 36px;
        height: 36px;
        text-overflow: ellipsis;
    }
    .links-groups-stack { gap: 8px; }
    .links-group-header { flex-wrap: wrap; padding: 6px 6px; min-height: 40px; gap: 3px 4px; }
    .links-group-header-left { gap: 4px; flex: 1 1 auto; min-width: max-content; max-width: 100%; }
    .links-group-title { font-size: 12px; }
    .links-group-domain { display: none; }
    .group-count-pill { font-size: 9px; padding: 1px 4px; }
    .links-group-header-metrics { gap: 4px; margin-left: auto; }
    .group-metric-col { gap: 1px; }
    .group-metric-col + .group-metric-col { padding-left: 4px; }
    .group-metric-lbl { font-size: 8px; letter-spacing: 0.3px; }
    .group-metric-val { font-size: 10.5px; }
    .group-metric-col-ctr .brand-ctr-pill { font-size: 9.5px; padding: 1px 4px; }
    .links-compact-table { font-size: 11.5px; }
    .links-compact-table th { padding: 5px 8px; font-size: 9px; letter-spacing: 0.3px; }
    .link-compact-row td { padding: 8px 8px; }
    .links-compact-table th.col-metric,
    .links-compact-table td.col-metric {
        width: 66px;
        font-size: 10.5px;
        letter-spacing: -0.02em;
        padding-left: 4px;
        padding-right: 4px;
    }
    .links-compact-table th.col-ctr,
    .links-compact-table td.col-ctr { width: 68px; padding-left: 4px; padding-right: 6px; }
    .compact-slug-text { font-size: 12px; }
    .compact-title-line { font-size: 10.5px; margin-top: 1px; }
    .compact-ctr-wrap { gap: 3px; }
    .compact-ctr-wrap .brand-ctr-pill { font-size: 10px; padding: 1px 5px; }
}

