:root {
    --primary: #1a365d;
    --primary-light: #2a4a7f;
    --accent: #e53e3e;
    --bg: #f7fafc;
    --card-bg: #ffffff;
    --text: #2d3748;
    --text-light: #718096;
    --border: #e2e8f0;
    --success: #38a169;
    --warning: #d69e2e;
    --danger: #e53e3e;
    --info: #3182ce;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

header {
    background: #213d78;
    color: white;
    padding: 0;
    box-shadow: var(--shadow-lg);
}

header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 88px;
}

header h1 { font-size: 1.5rem; font-weight: 700; display: flex; align-items: center; gap: 12px; margin: 0; }
header h1 img { height: 100%; display: block; }
header h1 a { display: flex; height: 100%; }
header h1 .site-title { font-family: 'Dancing Script', cursive; font-size: 1.2rem; font-weight: 700; color: white; line-height: 1.2; }
header h1 span { color: var(--accent); }

header nav a {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    margin-left: 24px;
    font-size: 0.9rem;
    font-weight: 500;
}
header nav a:hover { color: white; }

/* Stats bar */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    padding: 24px 0;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    text-align: center;
}

.stat-card .value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-card .label {
    font-size: 0.8rem;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* Last checks bar */
.last-checks {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 16px;
    padding: 8px 16px;
    font-size: 0.78rem;
    color: var(--text-light);
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 12px;
}

.last-checks:empty { display: none; }

.last-checks .check-label {
    font-weight: 600;
    color: var(--text);
}

.last-checks .check-item {
    white-space: nowrap;
}

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

.filters input, .filters select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    background: white;
}

.filters input[type="text"] { flex: 1; min-width: 200px; }

/* Ad grid */
.ad-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
    padding-bottom: 40px;
}

.ad-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: box-shadow 0.2s;
}

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

.ad-card .media {
    background: #edf2f7;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ad-card .media img, .ad-card .media video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ad-card .media .no-media {
    color: var(--text-light);
    font-size: 0.9rem;
}

/* Generated preview card for ads without native creative */
.ad-card .media .generated-card {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, var(--primary) 0%, #2a4a7f 100%);
    color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 20px 24px;
}

.generated-card .gc-source {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    opacity: 0.7;
    margin-bottom: 8px;
    font-weight: 600;
}

.generated-card .gc-name {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 16px;
}

.generated-card .gc-stats {
    display: flex;
    gap: 24px;
}

.generated-card .gc-stats > div {
    display: flex;
    flex-direction: column;
}

.generated-card .gc-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.7;
}

.generated-card .gc-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
}

.view-original {
    color: var(--info);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.8rem;
}
.view-original:hover { text-decoration: underline; }

/* Video thumbnail with play overlay */
.video-thumb {
    position: relative;
    width: 100%;
    height: 100%;
}

.video-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.3);
    font-size: 3rem;
    color: white;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
    transition: background 0.2s;
}

.ad-card:hover .play-overlay {
    background: rgba(0,0,0,0.15);
}

.ad-card .body { padding: 16px; }

.ad-card .committee {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 6px;
    color: var(--primary);
}

.ad-card .creative-text {
    font-size: 0.85rem;
    color: var(--text);
    margin-bottom: 10px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.ad-card .meta-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-light);
    margin-bottom: 4px;
}

.ad-card .source-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.source-meta { background: #ebf4ff; color: #2b6cb0; }
.source-google { background: #fefcbf; color: #975a16; }
.source-snapchat { background: #fefce8; color: #854d0e; }

.ad-card .spend {
    font-weight: 700;
    color: var(--accent);
    font-size: 0.95rem;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 20px 0 40px;
}

.pagination button {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card-bg);
    cursor: pointer;
    font-size: 0.9rem;
}

.pagination button.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.pagination button:disabled { opacity: 0.5; cursor: default; }

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--primary); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 4px 10px; font-size: 0.75rem; }

/* Admin styles */
.login-form {
    max-width: 360px;
    margin: 80px auto;
    background: var(--card-bg);
    padding: 32px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.login-form h2 { margin-bottom: 20px; text-align: center; }

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 4px;
}
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
}

/* Admin sections */
.admin-nav {
    display: flex;
    gap: 4px;
    padding: 16px 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}

.admin-nav button {
    padding: 8px 16px;
    border: none;
    background: transparent;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: 6px 6px 0 0;
    color: var(--text-light);
}

.admin-nav button.active {
    background: var(--primary);
    color: white;
}

.admin-section { display: none; }
.admin-section.active { display: block; }

/* Table */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

th, td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

th {
    background: var(--primary);
    color: white;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
}

tr:hover { background: #f8fafc; }

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
}

.status-pending { background: #fefcbf; color: #975a16; }
.status-approved { background: #c6f6d5; color: #276749; }
.status-rejected { background: #fed7d7; color: #9b2c2c; }
.status-paused { background: #e2e8f0; color: #4a5568; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-overlay.active { display: flex; }

.modal {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    max-height: 80vh;
    overflow-y: auto;
}

.modal h3 { margin-bottom: 16px; }

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: var(--radius);
    color: white;
    font-size: 0.9rem;
    z-index: 200;
    animation: slideIn 0.3s ease-out;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

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

/* Section headers */
.section-header {
    margin: 24px 0 12px;
    padding-bottom: 8px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    border-bottom: 2px solid var(--primary);
}

.section-header:first-of-type {
    margin-top: 16px;
}

.empty-section {
    grid-column: 1 / -1;
    padding: 24px;
    text-align: center;
    color: var(--text-light);
    font-style: italic;
}

/* Group headers */
.group-header {
    grid-column: 1 / -1;
    padding: 12px 16px;
    margin-top: 8px;
    font-weight: 400;
    color: var(--text);
    border-bottom: 2px solid var(--primary);
    background: var(--card-bg);
    border-radius: var(--radius) var(--radius) 0 0;
}

.group-header:first-child {
    margin-top: 0;
}

.gh-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
}

.gh-totals {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0;
    margin-top: 4px;
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text);
}

.gh-stat {
    margin-right: 8px;
}

.gh-stat + .gh-stat::before {
    content: " | ";
    margin-right: 8px;
    opacity: 0.4;
}

.gh-breakdown {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0;
    margin-top: 6px;
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-light);
}

.gh-candidate {
    margin-right: 8px;
}

.gh-candidate + .gh-candidate::before {
    content: " | ";
    margin-right: 8px;
    opacity: 0.4;
}

.gh-breakdown {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--text-light);
}

.gh-candidate {
    white-space: nowrap;
}

/* Run count badge */
.run-count-badge {
    display: inline-block;
    background: var(--primary);
    color: white;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
}

/* NEW badge */
.new-badge {
    display: inline-block;
    background: var(--accent);
    color: white;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-right: 6px;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* CA region tag */
.region-tag {
    display: inline-block;
    background: #c6f6d5;
    color: #276749;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    margin-left: 6px;
}

/* Banner toggle */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

.toggle-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Collapsible runs section */
.runs-section {
    margin-top: 8px;
    border-top: 1px solid var(--border);
    padding-top: 6px;
}

.runs-toggle {
    background: none;
    border: none;
    color: var(--info);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 0;
    width: 100%;
    text-align: left;
}

.runs-toggle:hover { text-decoration: underline; }

.runs-list {
    display: none;
    margin-top: 6px;
}

.runs-section.expanded .runs-list {
    display: block;
}

.runs-section.expanded .runs-toggle::before {
    content: "Hide";
}

/* When expanded, hide original text and show "Hide" */
.runs-section.expanded .runs-toggle {
    font-size: 0;
}

.runs-section.expanded .runs-toggle::before {
    font-size: 0.8rem;
}

.run-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text);
    cursor: pointer;
}

.run-row:last-child { border-bottom: none; }
.run-row:hover { background: #f8fafc; }

.run-spend {
    font-weight: 700;
    color: var(--accent);
    min-width: 70px;
}

.run-imp {
    color: var(--text-light);
    min-width: 80px;
}

.run-dates {
    color: var(--text-light);
    margin-left: auto;
    font-size: 0.75rem;
}

/* Delivery bars for ad detail */
.delivery-bars { margin-top: 16px; }
.delivery-bars h4 { font-size: 0.85rem; margin-bottom: 8px; color: var(--text); }

.bar-row {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
    font-size: 0.8rem;
}

.bar-label {
    width: 100px;
    text-align: right;
    padding-right: 10px;
    color: var(--text);
    font-weight: 500;
}

.bar-track {
    flex: 1;
    height: 18px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    min-width: 2px;
}

.bar-fill.ca { background: var(--accent); }

.bar-pct {
    width: 45px;
    padding-left: 8px;
    font-size: 0.75rem;
    color: var(--text-light);
}

/* Demographics summary */
.demo-summary { margin-top: 12px; }
.demo-summary h4 { font-size: 0.85rem; margin-bottom: 8px; color: var(--text); }
.demo-row {
    display: flex;
    align-items: center;
    margin-bottom: 3px;
    font-size: 0.78rem;
}
.demo-label {
    width: 90px;
    text-align: right;
    padding-right: 10px;
    color: var(--text);
}
.demo-bar-track {
    flex: 1;
    height: 14px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}
.demo-bar-fill {
    height: 100%;
    border-radius: 3px;
}
.demo-bar-fill.female { background: #ed64a6; }
.demo-bar-fill.male { background: #4299e1; }
.demo-pct {
    width: 40px;
    padding-left: 6px;
    font-size: 0.72rem;
    color: var(--text-light);
}

/* FCC Section */
.fcc-subtitle {
    font-size: 0.9rem;
    color: var(--text-light);
    margin-bottom: 8px;
}

.fcc-table-wrap {
    overflow-x: auto;
    margin-bottom: 20px;
}

#fcc-table tr:hover { background: #edf2f7; }
#fcc-table td { vertical-align: top; }
#fcc-table .text-muted { font-size: 0.75rem; color: var(--text-light); }

.source-fcc { background: #fed7e2; color: #97266d; }

/* Confidence badges */
.confidence-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
}

.confidence-high { background: #c6f6d5; color: #276749; }
.confidence-med { background: #fefcbf; color: #975a16; }
.confidence-low { background: #fed7d7; color: #9b2c2c; }

/* FCC top spenders */
.fcc-top-spenders {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.fcc-top-spenders h3 {
    font-size: 1rem;
    color: var(--primary);
    margin-bottom: 12px;
}

.spend-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.spend-row:last-child { border-bottom: none; }
.spend-name { flex: 1; font-weight: 500; }
.spend-amount { font-weight: 700; color: var(--accent); min-width: 80px; text-align: right; }
.spend-count { color: var(--text-light); font-size: 0.78rem; min-width: 70px; text-align: right; }

.fcc-spend-summary { margin-bottom: 8px; }

/* FCC Detail page */
.fcc-detail { margin-top: 16px; }

.fcc-detail-header {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.fcc-detail-header h2 {
    font-size: 1.2rem;
    color: var(--primary);
    margin-bottom: 12px;
    word-break: break-word;
}

.fcc-detail-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 24px;
    font-size: 0.85rem;
    color: var(--text);
}

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

.fcc-extraction h3 {
    font-size: 1.1rem;
    color: var(--primary);
    margin-bottom: 12px;
}

.fcc-extraction h4 {
    font-size: 0.9rem;
    color: var(--text);
    margin: 16px 0 8px;
}

.confidence-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}

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

.detail-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-light);
    font-weight: 600;
}

.detail-value {
    font-size: 0.95rem;
    color: var(--text);
}

.detail-value.spend {
    font-weight: 700;
    color: var(--accent);
    font-size: 1.1rem;
}

.daypart-table {
    width: 100%;
    max-width: 500px;
}

.daypart-table th {
    font-size: 0.75rem;
    padding: 6px 10px;
}

.daypart-table td {
    font-size: 0.85rem;
    padding: 6px 10px;
}

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

/* Responsive */
@media (max-width: 640px) {
    .ad-grid { grid-template-columns: 1fr; }
    .stats-bar { grid-template-columns: repeat(2, 1fr); }
    .filters { flex-direction: column; }
    header .container { flex-direction: column; gap: 8px; }
    .spend-banner { flex-direction: column; }
}

/* Spend banner — shared navigation across Digital / TV / Radio */
.spend-banner { display: flex; gap: 12px; margin-bottom: 16px; }
.spend-banner a { flex: 1; display: block; text-decoration: none; background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; transition: all 0.15s; }
.spend-banner a:hover { border-color: var(--primary); background: rgba(37,99,235,0.04); transform: translateY(-1px); }
.spend-banner a.active-section { border-color: var(--primary); border-width: 2px; background: rgba(37,99,235,0.06); }
.spend-banner .banner-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-light); margin-bottom: 4px; font-weight: 600; }
.spend-banner .banner-value { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
