/* Fonts loaded via <link> in base.html for parallel loading */

:root {
    --primary: #009BFB;
    --primary-dark: #0080d4;
    --primary-light: rgba(0,155,251,0.1);
    --success: #16A563;
    --success-light: #7BD389;
    --danger: #E04545;
    --warning: #E5A336;
    --bg: #f5f6f8;
    --bg-card: #ffffff;
    --text: #242325;
    --text-secondary: #5C6066;
    --border: #e2e5e9;
    --sidebar-bg: #242325;
    --sidebar-text: #b0b7c3;
    --sidebar-active: #009BFB;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-hover: 0 4px 16px rgba(0,0,0,0.1);
}

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

body {
    font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 20px 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    z-index: 100;
}

.sidebar-brand {
    padding: 0 20px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 10px;
}

.sidebar-brand img {
    width: 140px;
    height: auto;
    margin-bottom: 6px;
}

.sidebar-brand h2 {
    font-size: 15px;
    font-weight: 600;
    color: rgba(255,255,255,0.7);
    letter-spacing: 0.3px;
}

.sidebar-brand small {
    color: rgba(255,255,255,0.35);
    font-size: 11px;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    padding: 10px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.2s;
    gap: 10px;
}

.sidebar nav a:hover {
    background: rgba(255,255,255,0.08);
}

.sidebar nav a.active {
    background: rgba(0,155,251,0.15);
    color: var(--sidebar-active);
    font-weight: 600;
    border-right: 3px solid var(--sidebar-active);
}

.sidebar nav .section-label {
    padding: 15px 20px 5px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255,255,255,0.4);
}

/* Main content */
.main-content {
    margin-left: 240px;
    flex: 1;
    padding: 24px 32px;
    min-height: 100vh;
    min-width: 0; /* prevent flex child blowout */
    overflow-x: auto;
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 600;
}

/* Date picker bar (legacy) */
.date-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.date-controls input[type="date"] {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
}

/* Date picker with presets */
.date-picker-wrap {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.date-presets {
    display: flex;
    gap: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.date-preset-btn {
    padding: 7px 14px;
    font-size: 12px;
    font-weight: 500;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-right: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
}

.date-preset-btn:last-child { border-right: none; }
.date-preset-btn:hover { background: var(--bg); color: var(--text); }
.date-preset-btn.active { background: var(--primary); color: #fff; }
.date-preset-btn.active:hover { background: var(--primary-dark); }

.date-custom-row {
    display: flex;
    align-items: center;
    gap: 8px;
    animation: dateSlideDown 0.15s ease-out;
}

@keyframes dateSlideDown {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.date-custom-row input[type="date"] {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    background: var(--bg-card);
    color: var(--text);
}

.date-custom-row input[type="date"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0,155,251,0.2);
}

.date-sep { color: var(--text-secondary); font-size: 12px; }

.date-apply-btn {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
}

.date-apply-btn:hover { background: var(--primary-dark); }

/* KPI Cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s;
}

.kpi-card:hover {
    box-shadow: var(--shadow-hover);
}

.kpi-card .label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.kpi-card .value {
    font-size: 28px;
    font-weight: 700;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kpi-card .change {
    font-size: 13px;
    margin-top: 6px;
}

.kpi-card .change.positive { color: var(--success); }
.kpi-card .change.negative { color: var(--danger); }

/* Charts */
.chart-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(400px, 100%), 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.chart-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.chart-card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text);
}

.echart-container {
    width: 100%;
    height: 300px;
    min-height: 200px;
}

/* Tables */
.data-table-wrap {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
    overflow-y: hidden;
    margin-bottom: 24px;
}

/* Truncate long text cells (campaign names, ad groups, etc.) */
td.truncate-cell {
    max-width: 220px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.data-table-wrap h3 {
    padding: 16px 20px;
    font-size: 14px;
    font-weight: 600;
    border-bottom: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th, td {
    padding: 10px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--bg);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

th:hover { background: #ebedf0; }
th.sorted-asc::after { content: " \u25B2"; }
th.sorted-desc::after { content: " \u25BC"; }

tr:hover { background: #f7f8fa; }

td.number { text-align: right; font-variant-numeric: tabular-nums; }
th.number { text-align: right; }

/* Status badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.badge-enabled { background: #e6f4ea; color: var(--success); }
.badge-paused { background: #fef7e0; color: #b06000; }
.badge-removed { background: #fce8e6; color: var(--danger); }

/* Channel type badges */
.channel-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: 0.2px;
}

.channel-badge::before {
    display: inline-block;
    width: 16px;
    text-align: center;
    font-size: 12px;
    line-height: 1;
}

.channel-search              { background: #e8f0fe; color: #1a56db; }
.channel-search::before      { content: "\1F50D"; }

.channel-display             { background: #fef3e2; color: #b45309; }
.channel-display::before     { content: "\1F4F0"; }

.channel-shopping            { background: #ecfdf5; color: #047857; }
.channel-shopping::before    { content: "\1F6D2"; }

.channel-video               { background: #fce8e6; color: #c0392b; }
.channel-video::before       { content: "\25B6\FE0F"; }

.channel-performance-max     { background: #f0e6ff; color: #7c3aed; }
.channel-performance-max::before { content: "\26A1"; }

.channel-demand-gen          { background: #e0f7fa; color: #0e7490; }
.channel-demand-gen::before  { content: "\2728"; }

.channel-smart               { background: #fef9e7; color: #92400e; }
.channel-smart::before       { content: "\1F4A1"; }

.channel-hotel               { background: #fdf2f8; color: #9d174d; }
.channel-hotel::before       { content: "\1F3E8"; }

.channel-local               { background: #f0fdf4; color: #166534; }
.channel-local::before       { content: "\1F4CD"; }

.channel-local-services      { background: #f0fdf4; color: #166534; }
.channel-local-services::before { content: "\1F527"; }

.channel-multi-channel       { background: #eef2ff; color: #4338ca; }
.channel-multi-channel::before { content: "\1F4F1"; }

.channel-travel              { background: #ecfeff; color: #0e7490; }
.channel-travel::before      { content: "\2708\FE0F"; }

.channel-unknown             { background: #f3f4f6; color: #6b7280; }

/* Quality score colors */
.qs-low { color: var(--danger); font-weight: 700; }
.qs-mid { color: var(--warning); font-weight: 700; }
.qs-high { color: var(--success); font-weight: 700; }

/* Sentiment labels */
.sentiment-positive { color: var(--success); }
.sentiment-neutral { color: var(--text-secondary); }
.sentiment-negative { color: var(--danger); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background 0.2s;
    text-decoration: none;
}

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

.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--bg); }

.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Sidebar Sync Widget */
.sidebar-sync {
    padding: 12px 16px;
    margin-top: 8px;
    border-top: 1px solid rgba(255,255,255,0.08);
}
.sidebar-sync-info { margin-bottom: 8px; }
.sidebar-sync-label {
    font-size: 11px;
    color: rgba(255,255,255,0.40);
    line-height: 1.4;
    display: block;
}
.sidebar-sync-progress { margin-bottom: 10px; }
.sidebar-sync-phase {
    font-size: 12px;
    color: var(--primary);
    font-weight: 500;
    margin-bottom: 6px;
}
.sidebar-sync-bar-track {
    height: 4px;
    background: rgba(255,255,255,0.08);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 4px;
}
.sidebar-sync-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.4s ease;
}
.sidebar-sync-meta {
    font-size: 10px;
    color: rgba(255,255,255,0.35);
}
.sidebar-sync-error {
    font-size: 11px;
    color: #E04545;
    margin-bottom: 6px;
    line-height: 1.3;
}
.sidebar-sync-btn {
    width: 100%;
    padding: 9px 12px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s, opacity 0.15s;
    font-family: inherit;
}
.sidebar-sync-btn:hover:not(:disabled) { background: var(--primary-dark); }
.sidebar-sync-btn:disabled { cursor: not-allowed; }

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin: 20px 0;
    flex-wrap: wrap;
}

.page-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.15s;
}

.page-btn:hover {
    background: var(--bg);
    color: var(--text);
    border-color: var(--primary);
}

.page-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    cursor: default;
}

.page-dots {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 36px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* Setup wizard */
.setup-container {
    max-width: 700px;
    margin: 40px auto;
    padding: 0 20px;
}

.setup-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 32px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.setup-card h2 {
    font-size: 20px;
    margin-bottom: 16px;
}

.setup-card p {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 12px;
}

.setup-card code {
    background: #f1f3f4;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.setup-card pre {
    background: #242325;
    color: #e0e0e0;
    padding: 16px;
    border-radius: var(--radius);
    overflow-x: auto;
    font-size: 13px;
    margin: 12px 0;
}

.step-indicator {
    display: flex;
    gap: 0;
    margin-bottom: 32px;
}

.step {
    flex: 1;
    text-align: center;
    padding: 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 3px solid var(--border);
}

.step.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.step.done {
    color: var(--success);
    border-bottom-color: var(--success);
}

/* Form */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 4px;
}

.form-group input[type="text"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0,155,251,0.2);
}

/* Alert */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    font-size: 13px;
}

.alert-success { background: #e6f4ea; color: var(--success); border: 1px solid #ceead6; }
.alert-danger { background: #fce8e6; color: var(--danger); border: 1px solid #f5c6c2; }
.alert-info { background: rgba(0,155,251,0.08); color: var(--primary); border: 1px solid rgba(0,155,251,0.2); }

/* Ad preview card */
.ad-preview {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    max-width: 600px;
    margin-bottom: 20px;
}

.ad-preview .ad-url {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.ad-preview .ad-headline {
    font-size: 18px;
    color: #1a0dab;
    margin-bottom: 4px;
    cursor: pointer;
}

.ad-preview .ad-description {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* Copy analysis grid */
.analysis-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.analysis-panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.analysis-panel h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
}

/* Tab bar */
.tab-bar {
    display: flex;
    gap: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    width: fit-content;
}

.tab-btn {
    padding: 10px 20px;
    font-size: 13px;
    font-weight: 600;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    border-right: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.tab-btn:last-child { border-right: none; }
.tab-btn:hover { background: var(--bg); color: var(--text); }
.tab-btn.active { background: var(--primary); color: #fff; }
.tab-btn.active:hover { background: var(--primary-dark); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Filter bar */
.filter-bar {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 20px;
    padding: 16px 20px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.filter-group select,
.filter-group input[type="text"] {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    background: #fff;
    color: var(--text);
    min-width: 180px;
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0,155,251,0.2);
}

/* Inline filter bar (inside table header) */
.table-header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

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

.filter-bar-inline select,
.filter-bar-inline input[type="text"] {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    background: #fff;
    color: var(--text);
}

.filter-bar-inline select { min-width: 140px; }
.filter-bar-inline input[type="text"] { min-width: 140px; max-width: 180px; }

.filter-bar-inline select:focus,
.filter-bar-inline input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(0,155,251,0.2);
}

/* Match type badges */
.match-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.match-exact { background: #e8f0fe; color: #1a56db; }
.match-phrase { background: #f0e6ff; color: #7c3aed; }
.match-broad { background: #fef3e2; color: #b45309; }
.match-unknown { background: #f3f4f6; color: #6b7280; }

/* Keyword underperformance flag */
.kw-flag {
    display: inline-block;
    font-size: 11px;
    color: #d97706;
    cursor: help;
    opacity: 0.7;
    vertical-align: middle;
    position: relative;
}
.kw-flag:hover { opacity: 1; }
.kw-star {
    display: inline-block;
    font-size: 11px;
    color: #16a34a;
    cursor: help;
    opacity: 0.7;
    vertical-align: middle;
}
.kw-star:hover { opacity: 1; }

/* Waste styles */
.waste-row { background: #fef2f2 !important; }
.waste-row:hover { background: #fee2e2 !important; }

.waste-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: #fce8e6;
    color: var(--danger);
    white-space: nowrap;
}

.monitoring-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: #fef9e7;
    color: #92400e;
    white-space: nowrap;
}

/* Waste sub-tabs */
.waste-sub-content { display: none; }
.waste-sub-content.active { display: block; }

/* CPA percentage badges */
.waste-pct-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.pct-over { background: #fce8e6; color: var(--danger); }
.pct-warning { background: #fef9e7; color: #92400e; }
.pct-ok { background: #f3f4f6; color: var(--text-secondary); }

/* Relevance score badges */
.relevance-score {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
}

.score-very-low { background: #fce8e6; color: var(--danger); }
.score-low { background: #fef3e2; color: #b45309; }

/* Irrelevant flag badges */
.irrelevant-flag {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    margin-right: 3px;
    margin-bottom: 2px;
    white-space: nowrap;
}

.flag-informational { background: #e8f0fe; color: #1a56db; }
.flag-job_seeking { background: #fef3e2; color: #b45309; }
.flag-diy_free { background: #ecfdf5; color: #047857; }
.flag-research { background: #f0e6ff; color: #7c3aed; }
.flag-unrelated_intent { background: #fce8e6; color: var(--danger); }

/* ===== Mobile Menu Button ===== */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    background: var(--sidebar-bg);
    cursor: pointer;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    -webkit-tap-highlight-color: transparent;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), background 0.2s;
}

/* When sidebar is open, move X button to right edge of sidebar */
.mobile-menu-btn.active {
    left: 232px;
    background: transparent;
    box-shadow: none;
}

.mobile-menu-btn span {
    display: block;
    width: 20px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: all 0.25s;
}

.mobile-menu-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}
.mobile-menu-btn.active span:nth-child(2) {
    opacity: 0;
}
.mobile-menu-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.25s;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ===== RESPONSIVE: Tablet (≤1024px) ===== */
@media (max-width: 1024px) {
    .main-content {
        padding: 20px 20px;
    }

    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .chart-row {
        grid-template-columns: 1fr;
    }

    .analysis-grid {
        grid-template-columns: 1fr;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .date-picker-wrap {
        width: 100%;
    }

    .date-presets {
        flex-wrap: wrap;
    }

    /* Horizontal scroll for tables */
    .data-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 700px;
    }

    /* Filter bar stacking */
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .filter-group {
        width: 100%;
    }

    .filter-group select,
    .filter-group input[type="text"] {
        min-width: unset;
        width: 100%;
    }

    /* Inline filter bar: stack on tablet */
    .table-header-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    .filter-bar-inline {
        width: 100%;
    }

    .filter-bar-inline select,
    .filter-bar-inline input[type="text"] {
        min-width: unset;
        flex: 1;
    }

    /* Tab bars: scrollable on tablet */
    .tab-bar {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ===== RESPONSIVE: Phone (≤768px) ===== */
@media (max-width: 768px) {
    /* Show hamburger, hide sidebar */
    .mobile-menu-btn {
        display: flex;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        width: 280px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    body {
        overflow-x: hidden;
    }

    .main-content {
        margin-left: 0;
        padding: 60px 16px 16px; /* top padding for hamburger */
        padding-top: calc(60px + env(safe-area-inset-top, 0px));
        width: 100vw;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Prevent horizontal overflow */
    .page-header,
    .kpi-grid,
    .chart-row,
    .filter-bar,
    .tab-bar,
    .date-picker-wrap {
        max-width: 100%;
    }

    /* Page header */
    .page-header h1 {
        font-size: 20px;
    }

    /* KPI cards: smaller on phone */
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .kpi-card {
        padding: 14px;
        min-width: 0;
    }

    .kpi-card .value {
        font-size: 20px;
    }

    .kpi-card .label {
        font-size: 10px;
    }

    /* Charts: full width */
    .chart-row {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .chart-card {
        padding: 14px;
        min-width: 0;
    }

    .echart-container {
        height: 220px;
    }

    /* Tables: scroll with visible scroll indicator */
    .data-table-wrap {
        border-radius: 6px;
        margin-bottom: 16px;
        position: relative;
    }

    .data-table-wrap h3 {
        padding: 12px 14px;
        font-size: 13px;
    }

    table {
        min-width: 600px;
    }

    th, td {
        padding: 8px 10px;
        font-size: 12px;
    }

    /* Tab bar: horizontal scroll */
    .tab-bar {
        width: 100%;
        overflow-x: auto;
        border-radius: 6px;
    }

    .tab-btn {
        padding: 10px 14px;
        font-size: 12px;
    }

    /* Buttons: larger touch targets */
    .btn {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 44px;
    }

    /* Date picker: horizontal scroll on mobile */
    .date-presets {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 6px;
    }

    .date-preset-btn {
        padding: 8px 12px;
        font-size: 12px;
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .date-custom-row {
        flex-wrap: wrap;
    }

    .date-custom-row input[type="date"] {
        flex: 1;
        min-width: 120px;
    }

    /* Status filter pills on campaigns page */
    .page-header + div[style*="display:flex"] {
        flex-wrap: wrap !important;
    }

    /* Filter bars: ensure wrapping and proper sizing */
    .filter-bar {
        flex-wrap: wrap;
    }

    .filter-group select,
    .filter-group input[type="text"] {
        min-width: unset;
        width: 100%;
        max-width: 100%;
    }

    /* Freshness & controls bars: allow wrapping */
    .freshness-indicator {
        flex-wrap: wrap;
    }

    /* QS toggle on keywords page */
    #qsToggle {
        flex-shrink: 0;
    }

    /* Ad preview: full width */
    .ad-preview {
        max-width: 100%;
    }

    /* Setup wizard */
    .setup-container {
        margin: 16px auto;
        padding: 0 12px;
    }

    .setup-card {
        padding: 20px;
    }

    .step {
        font-size: 10px;
        padding: 8px 4px;
    }

    /* Filter bar: compact on phone */
    .filter-bar {
        padding: 12px;
        gap: 8px;
        margin-bottom: 12px;
    }

    .filter-bar label {
        font-size: 11px;
        margin-bottom: 2px;
    }

    .filter-bar select,
    .filter-bar input[type="text"] {
        padding: 8px 10px;
    }

    /* Alert */
    .alert {
        font-size: 12px;
        padding: 10px 12px;
    }

    /* Pagination: touch-friendly */
    .pagination {
        gap: 3px;
    }

    .page-btn {
        min-width: 40px;
        height: 40px;
        font-size: 13px;
    }
}

/* ===== RESPONSIVE: Small phone (≤480px) ===== */
@media (max-width: 480px) {
    .main-content {
        padding: 56px 10px 10px;
        padding-top: calc(56px + env(safe-area-inset-top, 0px));
    }

    .kpi-grid {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }

    .kpi-card {
        padding: 10px;
    }

    .kpi-card .value {
        font-size: 18px;
    }

    .page-header h1 {
        font-size: 18px;
    }

    table {
        min-width: 500px;
        font-size: 11px;
    }

    th, td {
        padding: 6px 8px;
    }

    .date-preset-btn {
        padding: 7px 8px;
        font-size: 11px;
    }

    /* Channel/match badges: compact */
    .channel-badge {
        padding: 2px 6px;
        font-size: 10px;
    }

    .match-badge {
        padding: 1px 5px;
        font-size: 9px;
    }

    .badge {
        padding: 1px 6px;
        font-size: 10px;
    }

    .waste-badge, .monitoring-badge {
        padding: 2px 7px;
        font-size: 10px;
    }

    .irrelevant-flag {
        font-size: 8px;
        padding: 1px 5px;
    }
}

/* ===== Safe areas for iPhone notch/home indicator ===== */
@supports (padding: env(safe-area-inset-bottom)) {
    .sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .main-content {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }

    .mobile-menu-btn {
        top: calc(12px + env(safe-area-inset-top));
        left: calc(12px + env(safe-area-inset-left));
    }

    .mobile-menu-btn.active {
        left: 232px;
    }
}

/* ===== Touch optimisations ===== */
@media (hover: none) and (pointer: coarse) {
    /* Larger tap targets */
    .sidebar nav a {
        padding: 14px 20px;
        min-height: 44px;
    }

    th {
        padding: 12px 10px;
    }

    /* Disable hover effects (prevents sticky hover on mobile) */
    th:hover { background: var(--bg); }
    tr:hover { background: transparent; }
    .kpi-card:hover { box-shadow: var(--shadow); }

    /* Improve scroll inertia */
    .data-table-wrap {
        -webkit-overflow-scrolling: touch;
    }

    /* Form inputs: minimum 16px font to prevent iOS zoom */
    select, input[type="text"], input[type="date"], textarea {
        font-size: 16px !important;
    }

    /* Scrollbar hide on mobile for cleaner look */
    .tab-bar::-webkit-scrollbar,
    .date-presets::-webkit-scrollbar,
    .data-table-wrap::-webkit-scrollbar {
        display: none;
    }

    .tab-bar, .date-presets, .data-table-wrap {
        scrollbar-width: none;
    }
}

/* Freshness + refresh (shared by My Clients & My Agency) */
.freshness-indicator {
    font-size: 11px;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.refresh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    color: var(--primary);
    background: transparent;
    text-decoration: none;
    transition: background 0.15s;
}
.refresh-btn:hover {
    background: var(--primary-light);
}
.refresh-btn.spinning svg {
    animation: spin 0.8s linear infinite;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Tooltip */
.tooltip { position: relative; }
.tooltip:hover::after {
    content: attr(data-tip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: #333;
    color: #fff;
    font-size: 11px;
    border-radius: 4px;
    white-space: nowrap;
}

/* ===== Login page — modern split design ===== */
.login-page {
    min-height: 100vh;
    display: flex;
}

/* Left branding panel */
.login-left {
    width: 420px;
    flex-shrink: 0;
    background: linear-gradient(155deg, #1a1a2e 0%, #242325 55%, #16213e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 48px;
    position: relative;
    overflow: hidden;
}

/* Decorative rings */
.login-left::before {
    content: '';
    position: absolute;
    width: 500px;
    height: 500px;
    border-radius: 50%;
    border: 1px solid rgba(0,155,251,0.1);
    top: -160px;
    right: -180px;
}
.login-left::after {
    content: '';
    position: absolute;
    width: 300px;
    height: 300px;
    border-radius: 50%;
    border: 1px solid rgba(99,102,241,0.08);
    bottom: -80px;
    left: -100px;
}

/* Soft light blob */
.login-left-glow {
    position: absolute;
    width: 360px;
    height: 360px;
    border-radius: 50%;
    background: radial-gradient(ellipse, rgba(0,155,251,0.12) 0%, transparent 70%);
    top: 15%;
    left: -80px;
    pointer-events: none;
}

.login-brand {
    position: relative;
    z-index: 1;
    max-width: 300px;
}

.login-brand-logo {
    width: 150px;
    height: auto;
    margin-bottom: 32px;
    display: block;
}

.login-brand h2 {
    font-size: 24px;
    font-weight: 800;
    color: #fff;
    margin: 0 0 10px;
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.login-brand-tagline {
    font-size: 14px;
    color: rgba(255,255,255,0.5);
    line-height: 1.7;
    margin: 0 0 36px;
}

.login-features {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-feature {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 13px;
    color: rgba(255,255,255,0.65);
    line-height: 1.5;
}

.login-feature-icon {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    background: rgba(0,155,251,0.14);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}

/* Right form panel */
.login-right {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 48px;
    background: #f5f6f8;
}

.login-form-box {
    width: 100%;
    max-width: 380px;
    animation: loginFadeUp 0.3s ease-out;
}

@keyframes loginFadeUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.login-card-logo {
    width: 150px;
    height: auto;
    display: block;
    margin-bottom: 32px;
}

.login-form-box h1 {
    font-size: 26px;
    font-weight: 800;
    color: var(--text);
    margin: 0 0 6px;
    letter-spacing: -0.3px;
}

.login-form-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 0 0 28px;
    line-height: 1.5;
}

.login-error-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(224,69,69,0.08);
    border: 1px solid rgba(224,69,69,0.2);
    color: var(--danger);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 20px;
}

/* Google Sign-in Button */
.google-sign-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    padding: 14px 24px;
    background: #fff;
    border: 1.5px solid #dadce0;
    border-radius: 10px;
    text-decoration: none;
    color: #3c4043;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    transition: box-shadow 0.2s, border-color 0.2s, transform 0.1s;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    min-height: 52px;
    -webkit-tap-highlight-color: transparent;
}

.google-sign-btn:hover {
    box-shadow: 0 2px 12px rgba(0,0,0,0.12);
    border-color: rgba(0,0,0,0.22);
}

.google-sign-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.login-footer-row {
    margin-top: 40px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
}

.login-footer-row a {
    color: var(--primary);
    text-decoration: none;
}
.login-footer-row a:hover { text-decoration: underline; }

/* Collapse brand panel at 900px */
@media (max-width: 900px) {
    .login-left {
        width: 340px;
        padding: 40px 32px;
    }
    .login-brand h2 { font-size: 21px; }
    .login-brand-tagline { margin-bottom: 28px; }
}

/* Mobile: single panel */
@media (max-width: 700px) {
    .login-page { flex-direction: column; }
    .login-left { display: none; }
    .login-right {
        min-height: 100vh;
        padding: 56px 24px 40px;
        padding-top: max(56px, calc(env(safe-area-inset-top, 0px) + 40px));
        background: #fff;
        align-items: flex-start;
    }
    .login-form-box { max-width: 100%; }
    .login-form-box h1 { font-size: 22px; }
    .login-card-logo { margin-bottom: 24px; }
    .google-sign-btn { font-size: 15px; }
}

@media (max-width: 400px) {
    .login-right { padding: 48px 20px 32px; }
    .login-form-box h1 { font-size: 20px; }
}

/* ===== CSV Export Toolbar ===== */
.export-toolbar {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width, 240px);
    right: 0;
    background: var(--bg);
    border-top: 2px solid var(--primary);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 100;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
}

.export-match-select {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
    background: var(--bg);
    color: var(--text);
}

.cb-col {
    width: 32px;
    text-align: center !important;
    padding: 8px 4px !important;
}

.term-cb, .select-all-cb {
    cursor: pointer;
    width: 15px;
    height: 15px;
    accent-color: var(--primary);
}

tr:has(.term-cb:checked) {
    background: rgba(37, 99, 235, 0.06) !important;
}

@media (max-width: 768px) {
    .export-toolbar {
        left: 0;
        padding: 10px 16px;
        gap: 8px;
    }
    .export-toolbar .btn { font-size: 11px; padding: 5px 10px; }
    .export-match-select { font-size: 11px; padding: 5px 8px; }
}
