/* CX3 Data Monitor — Dashboard Styles V6 (Mobile-First) */

:root {
    --color-critical: #dc2626;
    --color-critical-bg: #fef2f2;
    --color-warning: #d97706;
    --color-warning-bg: #fffbeb;
    --color-watch: #ca8a04;
    --color-watch-bg: #fefce8;
    --color-healthy: #16a34a;
    --color-healthy-bg: #f0fdf4;
    --color-silent: #7c3aed;
    --color-silent-bg: #f5f3ff;
    --color-nodata: #6b7280;
    --color-nodata-bg: #f9fafb;

    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-text-light: #94a3b8;
    --color-primary: #2563eb;
    --color-revenue: #0891b2;

    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
}

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

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-text-size-adjust: 100%;
}

/* ── Header ── */
.header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 10px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text);
    white-space: nowrap;
}

/* Hamburger */
.hamburger {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
}

.hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--color-text);
    border-radius: 2px;
    transition: transform 0.2s, opacity 0.2s;
}

.hamburger.active span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hamburger.active span:nth-child(2) { opacity: 0; }
.hamburger.active span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.header-right-mobile {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Nav links — hidden on mobile by default */
.nav-links {
    display: none;
    flex-direction: column;
    gap: 2px;
    padding: 8px 0;
    border-top: 1px solid var(--color-border);
    margin-top: 8px;
}

.nav-links.open {
    display: flex;
}

.nav-link {
    padding: 10px 12px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--color-text-muted);
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.nav-link:hover, .nav-link:active {
    background: var(--color-bg);
    color: var(--color-text);
}

.nav-admin {
    font-size: 0.85rem;
    color: var(--color-text-light);
}

/* Header meta (last updated, refresh) */
.header-meta {
    display: none;
    align-items: center;
    gap: 12px;
    padding-top: 8px;
    border-top: 1px solid var(--color-border);
    margin-top: 8px;
    flex-wrap: wrap;
}

.nav-links.open ~ .header-meta {
    display: flex;
}

.last-updated, .webhook-status {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.api-status-badges {
    display: flex;
    gap: 6px;
    align-items: center;
}

.api-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.api-badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

.api-badge-live {
    background: var(--color-healthy-bg);
    color: var(--color-healthy);
}

.api-badge-live .api-badge-dot {
    background: var(--color-healthy);
    animation: pulse-dot 2s infinite;
}

.api-badge-cached {
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.api-badge-cached .api-badge-dot {
    background: var(--color-warning);
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.user-info {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text);
    margin-left: auto;
}

.logout-form {
    display: inline;
    margin: 0;
    padding: 0;
}

.btn-logout {
    padding: 4px 12px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-logout:hover {
    border-color: var(--color-critical);
    color: var(--color-critical);
    background: var(--color-critical-bg);
}

.webhook-status.stale {
    color: var(--color-warning);
    font-weight: 600;
}

.next-refresh {
    font-size: 0.75rem;
    color: var(--color-text-light);
}

/* Buttons */
.btn {
    border: none;
    border-radius: var(--radius);
    padding: 10px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    min-height: 44px;
}

.btn:active { transform: scale(0.97); }

.btn-refresh {
    background: var(--color-primary);
    color: white;
}

.btn-refresh:hover { background: #1d4ed8; }
.btn-refresh:disabled { background: var(--color-text-light); cursor: not-allowed; }

.btn-refresh-desktop { display: none; }
.btn-refresh-sm { padding: 8px 12px; font-size: 0.8rem; min-height: 36px; }

.btn-back {
    background: #64748b;
    color: white;
    margin-bottom: 12px;
}

.btn-sm {
    padding: 6px 10px;
    font-size: 0.78rem;
    min-height: 30px;
}

.btn-secondary {
    background: #475569;
    color: white;
}

.btn-secondary:hover { background: #334155; }
.btn-secondary:disabled { background: var(--color-text-light); cursor: not-allowed; }

/* Main content */
.main-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 16px;
}

/* Page headers */
.page-header {
    margin-bottom: 20px;
}

.page-header h2 {
    font-size: 1.2rem;
    font-weight: 700;
}

.page-subtitle, .chart-subtitle {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-top: 4px;
    margin-bottom: 12px;
}

/* Alert Banners */
.alert-banner {
    background: var(--color-critical-bg);
    border: 2px solid var(--color-critical);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
}

.alert-banner .alert-item {
    padding: 4px 0;
    color: var(--color-critical);
    font-weight: 500;
    font-size: 0.85rem;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.alert-banner .alert-icon { flex-shrink: 0; font-size: 1rem; }

.stale-banner, .outage-banner {
    padding: 10px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-weight: 500;
    font-size: 0.85rem;
}

.stale-banner {
    background: var(--color-warning-bg);
    border: 2px solid var(--color-warning);
    color: var(--color-warning);
}

.outage-banner {
    background: var(--color-silent-bg);
    border: 2px solid var(--color-silent);
    color: var(--color-silent);
}

/* Stat Pills — mobile: 2 per row */
.stat-pills {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 20px;
}

.stat-pill {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.stat-number {
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 2px;
    text-align: center;
}

.stat-healthy .stat-number { color: var(--color-healthy); }
.stat-warning .stat-number { color: var(--color-warning); }
.stat-critical .stat-number { color: var(--color-critical); }
.stat-critical.has-alerts { background: var(--color-critical-bg); border-color: var(--color-critical); }
.stat-revenue .stat-number { color: var(--color-revenue); }

/* Card Grid — mobile: 1 column */
.card-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 24px;
}

.source-card, .site-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px;
    cursor: pointer;
    transition: box-shadow 0.2s, border-color 0.2s;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.source-card:hover, .site-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary);
}

.site-card:hover { border-color: var(--color-revenue); }

.source-card.status-critical { border-left: 4px solid var(--color-critical); }
.source-card.status-silent { border-left: 4px solid var(--color-silent); }
.source-card.status-warning { border-left: 4px solid var(--color-warning); }
.source-card.status-watch { border-left: 4px solid var(--color-watch); }
.source-card.status-healthy { border-left: 4px solid var(--color-healthy); }

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-source-label { font-weight: 600; font-size: 0.9rem; }

/* Status Badge */
.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    min-height: 24px;
    line-height: 16px;
}

.status-badge.critical { background: var(--color-critical); color: white; }
.status-badge.silent { background: var(--color-silent); color: white; }
.status-badge.warning { background: var(--color-warning); color: white; }
.status-badge.watch { background: var(--color-watch); color: white; }
.status-badge.healthy { background: var(--color-healthy); color: white; }
.status-badge.new, .status-badge.no_data { background: var(--color-nodata); color: white; }
.status-badge.pending { background: var(--color-nodata); color: white; }
.status-badge.active { background: var(--color-healthy); color: white; }
.status-badge.complete { background: var(--color-primary); color: white; }
.status-badge.flagged { background: var(--color-warning); color: white; }

.card-volume {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

.card-baseline {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.card-deviation {
    font-size: 0.85rem;
    font-weight: 600;
}

.card-deviation.negative { color: var(--color-critical); }
.card-deviation.moderate { color: var(--color-warning); }
.card-deviation.positive { color: var(--color-healthy); }

.card-sparkline { height: 40px; }

.card-last-seen {
    font-size: 0.75rem;
    color: var(--color-text-light);
}

.loading-message {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 16px;
    color: var(--color-text-muted);
}

/* Site Card extras */
.site-name { font-weight: 700; font-size: 0.95rem; }
.site-revenue { font-size: 1.5rem; font-weight: 700; color: var(--color-revenue); }
.site-detail { font-size: 0.8rem; color: var(--color-text-muted); }
.site-pct { font-size: 0.85rem; font-weight: 600; color: var(--color-text); }
.site-bar { height: 6px; border-radius: 3px; background: var(--color-border); overflow: hidden; margin-top: 4px; }
.site-bar-fill { height: 100%; border-radius: 3px; background: var(--color-revenue); }

/* Table Section */
.table-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}

.table-section h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 10px;
}

/* Connector form */
.connector-form .form-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.connector-form .form-row > * { flex: 1; min-width: 0; }

.connector-form .form-group { margin-bottom: 10px; }

.connector-form .form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 4px;
}

.connector-form input,
.connector-form select,
.connector-form textarea {
    width: 100%;
    padding: 7px 10px;
    font-size: 0.82rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
    box-sizing: border-box;
}

.connector-form textarea { font-family: monospace; resize: vertical; }

.connector-form input:focus,
.connector-form select:focus,
.connector-form textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.mapping-row { align-items: center; }
.mapping-row input, .mapping-row select { font-size: 0.78rem; padding: 5px 8px; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
}
.badge-rest_api { background: #dbeafe; color: #1d4ed8; }
.badge-ftp { background: #fef3c7; color: #92400e; }
.badge-sftp { background: #ede9fe; color: #5b21b6; }
.badge-active { background: var(--color-healthy-bg); color: var(--color-healthy); }
.badge-inactive { background: var(--color-nodata-bg); color: var(--color-nodata); }

.connector-actions { display: flex; gap: 4px; }
.connector-actions button { font-size: 0.72rem; padding: 3px 8px; }

/* KPI Strip */
.kpi-strip {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.kpi-card {
    flex: 1;
    min-width: 90px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 12px 10px;
    text-align: center;
    box-shadow: var(--shadow-sm);
}

.kpi-value {
    display: block;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 2px;
}

.kpi-label {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Funnel */
.funnel-container { padding: 8px 0; }

.funnel-stage {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.funnel-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-radius: var(--radius);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 500;
    min-height: 38px;
    transition: width 0.5s ease;
}

.funnel-label { font-weight: 600; }
.funnel-value { font-weight: 400; opacity: 0.9; }
.funnel-rate { font-size: 0.78rem; font-weight: 600; color: var(--color-text-muted); min-width: 50px; }

/* Sortable table */
.sortable-table th[data-sort]:hover { color: var(--color-primary); }

/* Domain search */
.domain-search-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.domain-search-input {
    flex: 1;
    min-width: 200px;
    padding: 9px 14px;
    font-size: 0.9rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    color: var(--color-text);
}

.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text);
    cursor: pointer;
    white-space: nowrap;
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    transition: all 0.15s ease;
}

.toggle-label:has(input:checked) {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.toggle-label input { margin: 0; cursor: pointer; }

.domain-search-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.table-header {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.table-header h2, .table-header h3 {
    margin-bottom: 0;
    font-size: 1rem;
}

.filter-input {
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    width: 100%;
    min-height: 44px;
}

.filter-sm {
    max-width: 200px;
}

.filter-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

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

.filter-group select {
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    background: white;
    min-height: 44px;
}

.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -14px;
    padding: 0 14px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 500px;
}

.data-table th, .data-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.8rem;
    white-space: nowrap;
}

.data-table th {
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    font-size: 0.65rem;
    letter-spacing: 0.05em;
    cursor: pointer;
    user-select: none;
    position: sticky;
    top: 0;
    background: var(--color-surface);
}

.data-table th:hover { color: var(--color-primary); }

.data-table tbody tr {
    cursor: pointer;
    transition: background 0.15s;
}

.data-table tbody tr:hover { background: var(--color-bg); }

.data-table .number {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Payload display */
.payload-preview {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: monospace;
    font-size: 0.7rem;
    color: var(--color-text-muted);
    cursor: pointer;
}

.payload-expanded {
    white-space: pre-wrap;
    word-break: break-all;
    max-width: 100%;
    font-family: monospace;
    font-size: 0.7rem;
    background: var(--color-bg);
    padding: 8px;
    border-radius: 4px;
}

/* Source Detail Page */
.detail-header { margin-bottom: 20px; }

.back-link {
    display: inline-flex;
    align-items: center;
    color: var(--color-primary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 8px;
    min-height: 44px;
}

.back-link:hover { text-decoration: underline; }

.detail-title {
    font-size: 1.2rem;
    font-weight: 700;
    display: block;
    margin-bottom: 8px;
}

.detail-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow-sm);
}

.meta-item {
    display: flex;
    flex-direction: column;
}

.meta-label {
    font-size: 0.65rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.meta-value {
    font-size: 0.95rem;
    font-weight: 600;
    margin-top: 2px;
}

/* Chart Container */
.chart-container {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.chart-container h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.chart-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 8px;
}

.chart-header-row h3 { margin-bottom: 2px; }

.filter-select {
    padding: 5px 10px;
    font-size: 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.filter-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.export-btn {
    padding: 5px 14px;
    font-size: 0.78rem;
    font-weight: 500;
    border: 1px solid var(--color-primary);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-primary);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.export-btn:hover {
    background: var(--color-primary);
    color: #fff;
}

.dow-day-filters {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.dow-day-btn {
    padding: 4px 12px;
    font-size: 0.78rem;
    font-weight: 500;
    border: 1px solid var(--color-border);
    border-radius: 20px;
    background: var(--color-surface);
    color: var(--color-text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.dow-day-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.dow-day-btn.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.chart-container canvas {
    max-height: 250px;
}

/* Conversion Section (side-by-side charts) */
.conversion-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
}

.conversion-section .chart-container {
    flex: 1;
    min-width: 0;
}

/* Comparison Card */
.comparison-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-sm);
}

.comparison-card.above { border-left: 4px solid var(--color-healthy); }
.comparison-card.below { border-left: 4px solid var(--color-warning); }

/* Form Section */
.form-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}

.form-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 14px;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 14px;
}

.form-group {
    flex: 1;
}

.form-group label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.form-group input, .form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    min-height: 44px;
}

.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.save-status {
    display: block;
    margin-top: 8px;
    font-size: 0.85rem;
    font-weight: 500;
}

.save-status.success { color: var(--color-healthy); }
.save-status.error { color: var(--color-critical); }

/* Risk Labels */
.risk-label {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.risk-label.low { background: var(--color-healthy-bg); color: var(--color-healthy); }
.risk-label.moderate { background: var(--color-watch-bg); color: var(--color-watch); }
.risk-label.high { background: var(--color-warning-bg); color: var(--color-warning); }
.risk-label.critical { background: var(--color-critical-bg); color: var(--color-critical); }

/* Footer */
.footer {
    text-align: center;
    padding: 20px 16px;
    color: var(--color-text-light);
    font-size: 0.75rem;
}

/* ══════════════════════════════════════════
   RESPONSIVE — TABLET (481px+)
   ══════════════════════════════════════════ */
@media (min-width: 481px) {
    .main-content { padding: 20px; }

    .stat-pills {
        grid-template-columns: repeat(3, 1fr);
        gap: 10px;
    }

    .stat-number { font-size: 1.5rem; }

    .card-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .detail-meta {
        grid-template-columns: repeat(3, 1fr);
    }

    .chart-container canvas { max-height: 300px; }

    .table-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .filter-input { width: 220px; }
    .filter-sm { width: 160px; }

    .form-row {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .form-group { min-width: 180px; }
}

/* ══════════════════════════════════════════
   RESPONSIVE — DESKTOP (769px+)
   ══════════════════════════════════════════ */
@media (min-width: 769px) {
    .header {
        padding: 0 24px;
        flex-direction: row;
        align-items: center;
    }

    .header-top {
        padding: 12px 0;
    }

    /* Hide hamburger, show nav inline */
    .hamburger { display: none; }
    .header-right-mobile .btn-refresh-sm { display: none; }

    .nav-links {
        display: flex !important;
        flex-direction: row;
        gap: 4px;
        padding: 0;
        border: none;
        margin: 0;
        margin-left: 24px;
    }

    .nav-link {
        padding: 8px 12px;
        font-size: 0.85rem;
        min-height: auto;
    }

    .header-meta {
        display: flex !important;
        padding: 0;
        border: none;
        margin: 0;
        margin-left: auto;
    }

    .btn-refresh-desktop { display: inline-flex; align-items: center; }

    .header {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }

    .main-content { padding: 24px; }

    .stat-pills {
        grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
        gap: 12px;
    }

    .stat-number { font-size: 1.75rem; }

    .card-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 16px;
    }

    .card-volume { font-size: 1.6rem; }
    .site-revenue { font-size: 1.8rem; }

    .conversion-section {
        flex-direction: row;
    }

    .detail-meta {
        display: flex;
        gap: 24px;
        flex-wrap: wrap;
    }

    .meta-item { min-width: 110px; }
    .meta-value { font-size: 1.05rem; }

    .detail-title {
        font-size: 1.4rem;
        display: inline-block;
        margin-right: 12px;
        margin-bottom: 0;
    }

    .chart-container canvas { max-height: 350px; }
    .chart-container { padding: 20px; }
    .table-section { padding: 20px; }

    .data-table th, .data-table td {
        padding: 10px 12px;
        font-size: 0.85rem;
    }

    .data-table th { font-size: 0.7rem; }

    .payload-preview { max-width: 300px; }

    .table-wrapper {
        margin: 0;
        padding: 0;
    }
}

/* ══════════════════════════════════════════
   RESPONSIVE — LARGE DESKTOP (1200px+)
   ══════════════════════════════════════════ */
@media (min-width: 1200px) {
    .card-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    }

    .stat-pills {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* ══════════════════════════════════════════
   DATA INTELLIGENCE — Provider Bars
   ══════════════════════════════════════════ */
.provider-bar {
    display: flex;
    height: 16px;
    border-radius: 4px;
    overflow: hidden;
    background: var(--color-border);
    margin-bottom: 4px;
}

.provider-bar-segment {
    height: 100%;
    transition: width 0.3s ease;
    min-width: 2px;
}

.provider-bar-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 0.68rem;
    color: var(--color-text-muted);
}

.provider-legend-item {
    display: flex;
    align-items: center;
    gap: 3px;
    white-space: nowrap;
}

.provider-legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 2px;
    flex-shrink: 0;
}

/* ══════════════════════════════════════════
   ALERT CONFIG — Form Styles
   ══════════════════════════════════════════ */
.alert-config-form {
    padding: 4px 0;
}

.alert-config-form .form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.alert-config-form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.78rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

.alert-config-form label input,
.alert-config-form label select {
    font-size: 0.85rem;
}

/* ═══════════════════════════════════════════════ */
/* Dashboard V11 — Tabs, Filters, Side Panel        */
/* ═══════════════════════════════════════════════ */

/* ── Sub stat pills (smaller variant inside tabs) ── */
.stat-pills-sub {
    margin: 12px 0 16px;
}
.stat-pills-sub .stat-pill {
    padding: 10px 12px;
}
.stat-pills-sub .stat-number {
    font-size: 1.1rem;
}
.stat-pills-sub .stat-label {
    font-size: 0.7rem;
}

/* ── Collapsible alert banner ── */
.alert-collapsible {
    background: var(--color-critical-bg);
    border: 1px solid var(--color-critical);
    border-radius: var(--radius);
    margin: 12px 0;
    overflow: hidden;
}
.alert-toggle {
    width: 100%;
    background: transparent;
    border: none;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-critical);
    text-align: left;
}
.alert-toggle:hover {
    background: rgba(220, 38, 38, 0.06);
}
.alert-toggle-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.alert-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--color-critical);
    box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.2);
    animation: alertPulse 2s ease-in-out infinite;
}
@keyframes alertPulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.2); }
    50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0.05); }
}
.alert-toggle-right {
    font-size: 0.8rem;
    font-weight: 500;
}
.alert-list {
    border-top: 1px solid var(--color-critical);
    background: var(--color-surface);
    max-height: 400px;
    overflow-y: auto;
}
.alert-item {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 10px;
    padding: 10px 16px;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.85rem;
}
.alert-item:last-child {
    border-bottom: none;
}
.alert-item .status-badge {
    font-size: 0.65rem;
    padding: 2px 6px;
}
.alert-item .alert-source {
    font-weight: 600;
    color: var(--color-text);
}
.alert-item .alert-msg {
    color: var(--color-text-muted);
    font-size: 0.8rem;
}
.alert-item .alert-meta {
    color: var(--color-text-light);
    font-size: 0.75rem;
    white-space: nowrap;
}
.alert-item .alert-link {
    color: var(--color-primary);
    text-decoration: none;
    font-size: 0.8rem;
    white-space: nowrap;
}
.alert-show-more {
    display: block;
    width: 100%;
    background: transparent;
    border: none;
    padding: 10px;
    color: var(--color-primary);
    font-size: 0.85rem;
    cursor: pointer;
    border-top: 1px solid var(--color-border);
}
.alert-show-more:hover {
    background: var(--color-bg);
}

/* ── Tab bar ── */
.tab-bar {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--color-border);
    margin: 20px 0 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.tab-btn {
    background: transparent;
    border: none;
    padding: 10px 18px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover {
    color: var(--color-text);
}
.tab-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}
.tab-count {
    background: var(--color-bg);
    color: var(--color-text-muted);
    font-size: 0.7rem;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 500;
}
.tab-btn.active .tab-count {
    background: var(--color-primary);
    color: white;
}

/* ── Tab panels ── */
.tab-panel {
    display: none;
}
.tab-panel.active {
    display: block;
    animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Filter bar ── */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
}
.filter-bar .filter-input,
.filter-bar .filter-select {
    flex: 1 1 auto;
    min-width: 140px;
    padding: 8px 12px;
    font-size: 0.85rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
}
.filter-bar .filter-input:focus,
.filter-bar .filter-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* ── View toggle (Cards / Table) ── */
.view-toggle {
    display: inline-flex;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 2px;
}
.view-btn {
    background: transparent;
    border: none;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s;
}
.view-btn.active {
    background: var(--color-surface);
    color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

/* ── Date range presets ── */
.date-range-presets {
    display: inline-flex;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 2px;
}
.preset-btn {
    background: transparent;
    border: none;
    padding: 6px 10px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
    border-radius: 6px;
    white-space: nowrap;
}
.preset-btn:hover {
    color: var(--color-text);
}
.preset-btn.active {
    background: var(--color-primary);
    color: white;
}

.date-range-custom {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.date-range-custom .filter-input {
    flex: 0 0 auto;
    min-width: 130px;
    max-width: 150px;
}
.date-sep {
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

/* ── Multi-select dropdown ── */
.multi-select {
    position: relative;
    display: inline-block;
    min-width: 180px;
}
.multi-select-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--color-text);
    gap: 8px;
}
.multi-select-toggle:hover {
    border-color: var(--color-primary);
}
.multi-select .caret {
    font-size: 0.6rem;
    color: var(--color-text-muted);
}
.multi-select-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    min-width: 240px;
    max-height: 320px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    z-index: 50;
    overflow: hidden;
    display: none;
}
.multi-select.open .multi-select-menu {
    display: block;
}
.multi-select-search {
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.85rem;
    outline: none;
}
.multi-select-options {
    max-height: 240px;
    overflow-y: auto;
}
.multi-select-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--color-text);
}
.multi-select-option:hover {
    background: var(--color-bg);
}
.multi-select-option input[type="checkbox"] {
    margin: 0;
}
.multi-select-option .opt-meta {
    margin-left: auto;
    color: var(--color-text-light);
    font-size: 0.75rem;
}

/* ── Pill filter (RFTP / RT / LFTP) ── */
.pill-filter {
    display: inline-flex;
    gap: 4px;
    flex-wrap: wrap;
}
.pill-btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.pill-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-text);
}
.pill-btn.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}

/* ── Load more button ── */
.load-more-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px 0;
}
.btn-load-more {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    padding: 8px 18px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-primary);
    cursor: pointer;
    transition: all 0.15s;
}
.btn-load-more:hover {
    border-color: var(--color-primary);
    background: rgba(37, 99, 235, 0.04);
}
.load-more-meta {
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

/* ── Pagination ── */
.pagination-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 4px;
    flex-wrap: wrap;
}
.pagination-buttons {
    display: inline-flex;
    gap: 4px;
}
.page-btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    min-width: 32px;
}
.page-btn:hover:not(:disabled) {
    border-color: var(--color-primary);
}
.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.page-btn.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}
.page-info {
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

.meta-text {
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

/* ── Side panel (drill-down) ── */
.side-panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}
.side-panel-overlay.open {
    opacity: 1;
    pointer-events: auto;
}
.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(480px, 90vw);
    background: var(--color-surface);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.1);
    z-index: 201;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(.4, 0, .2, 1);
}
.side-panel.open {
    transform: translateX(0);
}
.side-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}
.side-panel-header h3 {
    font-size: 1rem;
    margin: 0;
}
.side-panel-close {
    background: transparent;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--color-text-muted);
    line-height: 1;
    padding: 4px 8px;
}
.side-panel-close:hover {
    color: var(--color-text);
}
.side-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}
.side-panel-footer {
    border-top: 1px solid var(--color-border);
    padding: 12px 20px;
    background: var(--color-bg);
}
.btn-link {
    color: var(--color-primary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
}
.btn-link:hover {
    text-decoration: underline;
}
.sp-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 16px;
}
.sp-meta-item {
    background: var(--color-bg);
    border-radius: var(--radius);
    padding: 10px;
}
.sp-meta-label {
    display: block;
    font-size: 0.7rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
}
.sp-meta-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
}
.sp-mini-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    margin-top: 8px;
}
.sp-mini-table th,
.sp-mini-table td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--color-border);
}
.sp-mini-table th {
    color: var(--color-text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.7rem;
}
.sp-mini-table td.number {
    text-align: right;
}

/* ── Daily Report (V13) ── */
.dr-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}
.dr-controls .filter-input {
    flex: 0 0 auto;
    min-width: 150px;
}
.dr-footer {
    padding: 8px 4px;
    color: var(--color-text-muted);
    font-size: 0.8rem;
}
#dailyReportTable input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}
#dailyReportTable input[type="text"].dr-notes {
    width: 100%;
    min-width: 160px;
    border: 1px solid transparent;
    background: transparent;
    padding: 4px 6px;
    font-size: 0.8rem;
    border-radius: 4px;
    color: var(--color-text);
}
#dailyReportTable input[type="text"].dr-notes:hover {
    border-color: var(--color-border);
    background: var(--color-bg);
}
#dailyReportTable input[type="text"].dr-notes:focus {
    outline: none;
    border-color: var(--color-primary);
    background: var(--color-surface);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
/* Publisher row grouping */
#dailyReportTable tr.dr-pub-start td {
    border-top: 2px solid var(--color-border);
    padding-top: 12px;
}
#dailyReportTable tr.dr-pub-start:first-child td {
    border-top: none;
}
#dailyReportTable tr.dr-pub-cont td:nth-child(1),
#dailyReportTable tr.dr-pub-cont td:nth-child(2) {
    color: var(--color-text-light);
    font-size: 0.78rem;
}
#dailyReportTable .dr-pub-cont-mark {
    color: var(--color-text-light);
    font-size: 1rem;
    margin-left: 8px;
}
#dailyReportTable .dr-offer {
    color: var(--color-text-muted);
    font-size: 0.78rem;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dr-saving {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-primary);
    margin-left: 6px;
    animation: drPulse 0.8s ease-in-out infinite;
}
@keyframes drPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

/* ── Floating click-report modal (V13) ── */
/* Multiple modals can be open at once, dragged independently, stacked by z-index */
.cm-modal {
    position: fixed;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.25);
    width: 880px;
    max-width: 95vw;
    height: 580px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    user-select: none;
}
.cm-modal.cm-active {
    box-shadow: 0 16px 48px rgba(37, 99, 235, 0.25), 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.cm-header {
    flex: 0 0 auto;
    background: linear-gradient(180deg, #1e293b, #0f172a);
    color: #f1f5f9;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: grab;
    border-bottom: 1px solid #334155;
}
.cm-header:active { cursor: grabbing; }
.cm-title {
    font-size: 0.9rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cm-title .cm-pub-name { color: #e2e8f0; }
.cm-title .cm-meta {
    color: #94a3b8;
    font-size: 0.75rem;
    font-weight: 400;
}
.cm-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.cm-btn {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: #e2e8f0;
    width: 28px;
    height: 28px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.cm-btn:hover { background: rgba(255, 255, 255, 0.18); }
.cm-btn.cm-close:hover { background: var(--color-critical); }

.cm-body {
    flex: 1;
    overflow: auto;
    user-select: text;
}
.cm-toolbar {
    flex: 0 0 auto;
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--color-bg);
    font-size: 0.8rem;
}
.cm-toolbar .filter-input {
    flex: 1;
    padding: 6px 10px;
    font-size: 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
}
.cm-toolbar .cm-stat {
    color: var(--color-text-muted);
    font-size: 0.75rem;
    white-space: nowrap;
}
.cm-table-wrap {
    overflow: auto;
    max-height: 100%;
}
.cm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}
.cm-table th, .cm-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
    text-align: left;
}
.cm-table th {
    position: sticky;
    top: 0;
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.65rem;
    letter-spacing: 0.04em;
    z-index: 2;
    border-bottom: 2px solid var(--color-border);
}
.cm-table .number { text-align: right; }
.cm-table tbody tr:hover { background: var(--color-bg); }
.cm-table .cm-disp-clicked { color: var(--color-healthy); }
.cm-table .cm-disp-rejected { color: var(--color-critical); }
.cm-table .cm-disp-redirect { color: var(--color-text); }
.cm-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--color-text-light);
    font-size: 0.85rem;
}
.cm-loading {
    padding: 40px 20px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

/* Resize handle (bottom-right corner) */
.cm-resize {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 16px;
    height: 16px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 0%, transparent 50%, var(--color-border) 50%, var(--color-border) 100%);
}

/* "Clicks" cells in tables that open the modal — make them feel clickable */
.cm-clickable {
    cursor: pointer;
    color: var(--color-primary);
    text-decoration: underline dotted;
    text-underline-offset: 2px;
}
.cm-clickable:hover {
    background: rgba(37, 99, 235, 0.06);
}

/* ── Sub-affiliate drill-down modal (Cake SubIDSummary) ── */
.sa-crumb {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    padding: 7px 14px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
    font-size: 0.78rem;
}
.sa-crumb-link {
    color: var(--color-primary);
    cursor: pointer;
    text-decoration: underline dotted;
    text-underline-offset: 2px;
}
.sa-crumb-link:hover { color: var(--color-primary-dark, #1d4ed8); }
.sa-crumb-cur { color: var(--color-text); font-weight: 600; }
.sa-crumb-sep { color: var(--color-text-light); }
.sa-table tbody tr.sa-drill,
.sa-table tbody tr.sa-drill-day { cursor: pointer; }
.sa-table tbody tr.sa-drill:hover,
.sa-table tbody tr.sa-drill-day:hover { background: rgba(37, 99, 235, 0.08); }

@media (max-width: 700px) {
    .cm-modal { width: 95vw; height: 80vh; }
    .sa-modal { width: 95vw !important; }
    .cm-table th, .cm-table td { padding: 5px 8px; font-size: 0.72rem; }
}

/* ── Mobile tweaks ── */
@media (max-width: 768px) {
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-bar .filter-input,
    .filter-bar .filter-select,
    .multi-select {
        width: 100%;
    }
    .date-range-presets,
    .date-range-custom,
    .pill-filter,
    .view-toggle {
        width: 100%;
        justify-content: stretch;
    }
    .preset-btn {
        flex: 1;
    }
    .tab-btn {
        padding: 10px 12px;
        font-size: 0.85rem;
    }
}

/* ═══════════════════════════════════════════════ */
/* Messages page (V15 — Telegram)                   */
/* ═══════════════════════════════════════════════ */

.setup-hint {
    background: var(--color-watch-bg);
    border: 1px solid var(--color-watch);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin: 12px 0;
}
.setup-hint h4 { margin: 0 0 8px; color: var(--color-text); }
.setup-hint ol { margin: 0 0 8px 22px; padding: 0; }
.setup-hint li { font-size: 0.85rem; line-height: 1.6; color: var(--color-text); }

.msg-page {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 14px;
    height: calc(100vh - 230px);
    min-height: 500px;
    margin-top: 14px;
}

/* Sidebar */
.msg-sidebar {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.msg-sidebar-header {
    padding: 10px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    gap: 8px;
}
.msg-sidebar-header .filter-input { flex: 1; min-width: 0; padding: 6px 10px; font-size: 0.85rem; }
.msg-chat-list { flex: 1; overflow-y: auto; }
.msg-empty {
    padding: 24px 14px;
    text-align: center;
    color: var(--color-text-light);
    font-size: 0.85rem;
}

.msg-chat-item {
    display: grid;
    grid-template-columns: 32px 1fr auto;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    transition: background 0.15s;
    align-items: center;
}
.msg-chat-item:hover { background: var(--color-bg); }
.msg-chat-item.active { background: rgba(37, 99, 235, 0.08); border-left: 3px solid var(--color-primary); padding-left: 9px; }
.msg-chat-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}
.msg-chat-main { min-width: 0; }
.msg-chat-title-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.msg-chat-title { font-weight: 600; font-size: 0.85rem; color: var(--color-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-chat-time { font-size: 0.7rem; flex-shrink: 0; }
.msg-chat-preview {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.msg-chat-unread {
    background: var(--color-critical);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 600;
    border-radius: 999px;
    padding: 2px 7px;
    min-width: 20px;
    text-align: center;
}

/* Thread (right pane) */
.msg-thread {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.msg-thread-header {
    padding: 10px 16px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--color-bg);
}
.msg-thread-header h3 { font-size: 0.95rem; margin: 0; }
.msg-thread-actions { display: flex; gap: 6px; }

.msg-thread-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.msg-date-sep {
    text-align: center;
    color: var(--color-text-light);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 12px 0 6px;
    position: relative;
}
.msg-date-sep span {
    background: var(--color-surface);
    padding: 0 10px;
    position: relative;
    z-index: 1;
}
.msg-date-sep::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0; right: 0;
    border-top: 1px solid var(--color-border);
    z-index: 0;
}

.msg-bubble {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.msg-in {
    background: var(--color-bg);
    color: var(--color-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.msg-out {
    background: var(--color-primary);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.msg-out .meta-text { color: rgba(255, 255, 255, 0.75); }
.msg-sender {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 2px;
}
.msg-text { font-size: 0.9rem; }
.msg-text .msg-media { color: var(--color-watch); font-weight: 600; }
.msg-time { font-size: 0.68rem; margin-top: 3px; text-align: right; }

/* Composer */
.msg-thread-composer {
    border-top: 1px solid var(--color-border);
    padding: 10px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--color-bg);
}
.msg-thread-composer textarea {
    flex: 1;
    min-height: 40px;
    max-height: 160px;
    resize: vertical;
    padding: 8px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.9rem;
    font-family: inherit;
}
.msg-thread-composer textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Add Conversation modal */
.msg-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    z-index: 200;
}
.msg-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 560px;
    max-width: 95vw;
    height: 540px;
    max-height: 80vh;
    background: var(--color-surface);
    border-radius: 10px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
    z-index: 201;
    display: flex;
    flex-direction: column;
    transform: translate(-50%, -50%) scale(0.96);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s, transform 0.18s;
}
.msg-modal.open {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
    pointer-events: auto;
}
.msg-modal-header {
    padding: 12px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--color-border);
}
.msg-modal-header h3 { margin: 0; font-size: 1rem; }
.msg-modal-toolbar {
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--color-border);
}
.msg-modal-toolbar .filter-input { flex: 1; padding: 8px 12px; font-size: 0.85rem; }
.msg-modal-body { flex: 1; overflow-y: auto; }
.msg-modal-footer {
    padding: 8px 14px;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg);
    font-size: 0.75rem;
}

.msg-add-row {
    display: grid;
    grid-template-columns: 32px 1fr auto;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border);
    align-items: center;
}
.msg-add-row:hover { background: var(--color-bg); }

/* Header nav badge */
.nav-badge {
    background: var(--color-critical);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    border-radius: 999px;
    padding: 1px 6px;
    margin-left: 4px;
    min-width: 18px;
    text-align: center;
    display: inline-block;
}

/* Mobile: stack the two panes */
@media (max-width: 900px) {
    .msg-page {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
        height: auto;
    }
    .msg-sidebar { max-height: 320px; }
    .msg-thread { min-height: 60vh; }
    .msg-bubble { max-width: 90%; }
}

/* ═══════════════════════════════════════════════ */
/* Floating Chat Widget (V15.1 — every-page)        */
/* ═══════════════════════════════════════════════ */

/* Launcher button — bottom-right corner, fixed */
.cx3w-launcher {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.35);
    cursor: pointer;
    z-index: 250;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.18s, box-shadow 0.18s;
}
.cx3w-launcher:hover {
    transform: scale(1.06);
    box-shadow: 0 8px 26px rgba(37, 99, 235, 0.45);
}
.cx3w-launcher:active { transform: scale(0.96); }
.cx3w-launcher.hidden { display: none; }
.cx3w-launcher-icon {
    font-size: 1.5rem;
    line-height: 1;
}
.cx3w-launcher-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    background: var(--color-critical);
    border: 2px solid var(--color-primary);
    color: #fff;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Floating panel */
.cx3w-panel {
    position: fixed;
    right: 22px;
    bottom: 90px;
    width: 380px;
    height: 560px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 110px);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 14px;
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.22);
    z-index: 251;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(0.96) translateY(8px);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.18s ease, opacity 0.18s ease;
}
.cx3w-panel.open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* Header (drag handle) */
.cx3w-header {
    flex: 0 0 auto;
    background: linear-gradient(180deg, #1e293b, #0f172a);
    color: #f1f5f9;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: grab;
    border-bottom: 1px solid #334155;
    user-select: none;
}
.cx3w-header:active { cursor: grabbing; }
.cx3w-back {
    background: transparent;
    border: none;
    color: #cbd5e1;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.cx3w-back:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.cx3w-title-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.cx3w-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cx3w-subtitle {
    font-size: 0.7rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cx3w-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.cx3w-btn {
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: #e2e8f0;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}
.cx3w-btn:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }

/* Views (list + thread share the body area) */
.cx3w-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* List view */
.cx3w-search-row {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--color-border);
}
.cx3w-search-input {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    font-size: 0.8rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
    color: var(--color-text);
}
.cx3w-search-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.cx3w-add-btn {
    background: var(--color-primary);
    color: #fff;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
}
.cx3w-add-btn:hover { background: #1d4ed8; }
.cx3w-chats { flex: 1; overflow-y: auto; }
.cx3w-empty {
    padding: 28px 14px;
    text-align: center;
    color: var(--color-text-light);
    font-size: 0.82rem;
}
.cx3w-chat-row {
    display: grid;
    grid-template-columns: 28px 1fr auto;
    gap: 8px;
    padding: 9px 12px;
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    transition: background 0.15s;
    align-items: center;
}
.cx3w-chat-row:hover { background: var(--color-bg); }
.cx3w-chat-row.active { background: rgba(37, 99, 235, 0.08); }
.cx3w-chat-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}
.cx3w-chat-main { min-width: 0; }
.cx3w-chat-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cx3w-chat-preview {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.cx3w-chat-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    flex-shrink: 0;
}
.cx3w-chat-time { font-size: 0.65rem; color: var(--color-text-light); }
.cx3w-chat-badge {
    background: var(--color-critical);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    border-radius: 999px;
    padding: 1px 6px;
    min-width: 18px;
    text-align: center;
    line-height: 1.4;
}

/* Thread view */
.cx3w-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.cx3w-msg {
    max-width: 85%;
    padding: 7px 10px;
    border-radius: 12px;
    font-size: 0.85rem;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.cx3w-msg-in {
    background: var(--color-bg);
    color: var(--color-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}
.cx3w-msg-out {
    background: var(--color-primary);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}
.cx3w-msg-sender {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 2px;
}
.cx3w-msg-time {
    font-size: 0.62rem;
    color: var(--color-text-light);
    margin-top: 3px;
    text-align: right;
}
.cx3w-msg-out .cx3w-msg-time { color: rgba(255, 255, 255, 0.75); }
.cx3w-date-sep {
    text-align: center;
    color: var(--color-text-light);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 0 4px;
}

/* Composer */
.cx3w-composer {
    border-top: 1px solid var(--color-border);
    padding: 8px;
    display: flex;
    gap: 6px;
    align-items: flex-end;
    background: var(--color-bg);
}
.cx3w-composer textarea {
    flex: 1;
    min-height: 34px;
    max-height: 120px;
    resize: none;
    padding: 7px 10px;
    border: 1px solid var(--color-border);
    border-radius: 18px;
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.85rem;
    font-family: inherit;
    line-height: 1.3;
}
.cx3w-composer textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.cx3w-send {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.cx3w-send:hover { background: #1d4ed8; }
.cx3w-send:disabled { background: var(--color-text-light); cursor: not-allowed; }

/* Resize handle */
.cx3w-resize {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 0%, transparent 55%, var(--color-border) 55%, var(--color-border) 100%);
    z-index: 1;
}

@media (max-width: 540px) {
    .cx3w-panel {
        right: 8px; left: 8px; bottom: 80px;
        width: auto;
        max-height: calc(100vh - 100px);
    }
    .cx3w-launcher { right: 14px; bottom: 14px; }
}

/* Settings view (V16 — per-user bot connection) */
.cx3w-settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    font-size: 0.85rem;
}
.cx3w-settings-body h4 {
    font-size: 0.9rem;
    margin: 0 0 8px;
}
.cx3w-settings-body p {
    margin: 0 0 12px;
    color: var(--color-text-muted);
    line-height: 1.5;
}
.cx3w-settings-body label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 14px 0 4px;
}
.cx3w-settings-body input[type=text],
.cx3w-settings-body input[type=password] {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
    font-size: 0.85rem;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    color: var(--color-text);
}
.cx3w-settings-body input[type=text]:focus,
.cx3w-settings-body input[type=password]:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.cx3w-settings-body .cx3w-btn-primary {
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 9px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 14px;
    width: 100%;
}
.cx3w-settings-body .cx3w-btn-primary:hover { background: #1d4ed8; }
.cx3w-settings-body .cx3w-btn-primary:disabled { background: var(--color-text-light); cursor: not-allowed; }
.cx3w-settings-body .cx3w-btn-danger {
    background: transparent;
    color: var(--color-critical);
    border: 1px solid var(--color-critical);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 10px;
}
.cx3w-settings-body .cx3w-btn-danger:hover {
    background: var(--color-critical-bg);
}
.cx3w-settings-body .cx3w-help {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 10px 12px;
    margin: 10px 0 14px;
    font-size: 0.78rem;
    color: var(--color-text-muted);
    line-height: 1.5;
}
.cx3w-settings-body .cx3w-help ol { margin: 6px 0 0 18px; padding: 0; }
.cx3w-settings-body .cx3w-help li { margin: 3px 0; }
.cx3w-settings-body .cx3w-bot-card {
    background: var(--color-healthy-bg);
    border: 1px solid var(--color-healthy);
    border-radius: 8px;
    padding: 10px 12px;
    margin: 10px 0;
}
.cx3w-settings-body .cx3w-bot-card strong { color: var(--color-healthy); }
.cx3w-settings-body .cx3w-error {
    background: var(--color-critical-bg);
    border: 1px solid var(--color-critical);
    color: var(--color-critical);
    border-radius: 8px;
    padding: 8px 12px;
    margin-top: 10px;
    font-size: 0.78rem;
}
