:root {
    /* Palette grounded in the UB Media logo: warm charcoal ink on warm neutrals —
       ink is the accent (active tabs, primary buttons, links), no framework blue. */
    --primary: #262220;        /* logo ink */
    --primary-dark: #0f0d0c;   /* hover */
    --bg: #f5f4f1;             /* warm off-white ground */
    --card-bg: #ffffff;
    --text: #262220;
    --text-muted: #726c66;     /* warm grey */
    --border: #e7e3de;         /* warm hairline */
    --success: #2f9e73;
    --warning: #c9862f;
    --danger: #cf4b52;
    --purple: #7c6f9f;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

/* Login */
.login-container {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: linear-gradient(135deg, #f2f0ec 0%, #f8fafc 55%, #ece9e4 100%);
}
.login-card {
    background: var(--card-bg); border-radius: 11px; padding: 48px;
    text-align: center; max-width: 600px; width: 90%;
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.12); border: 1px solid var(--border);
}
.login-card img.login-logo { height: 64px; width: auto; margin-bottom: 16px; }
.login-card h1 { color: var(--primary); margin-bottom: 8px; font-size: 1.8rem; }
.login-card p { color: var(--text-muted); margin-bottom: 32px; }
.rep-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}
.rep-btn {
    padding: 14px 16px; border: 2px solid var(--border); border-radius: 10px;
    background: var(--card-bg); cursor: pointer; font-size: 0.95rem;
    font-weight: 500; transition: all 0.15s; color: var(--text);
}
.rep-btn:hover {
    border-color: var(--primary); background: #f1efec; transform: translateY(-1px);
}
.login-form { display: flex; flex-direction: column; gap: 12px; max-width: 320px; margin: 0 auto; text-align: left; }
.login-form input {
    padding: 11px 14px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 0.95rem; width: 100%;
}
.login-form input:focus { outline: none; border-color: var(--primary); }
.login-form button { padding: 11px 16px; font-size: 0.95rem; }
.login-error { color: var(--danger); font-size: 0.85rem; min-height: 1.1em; text-align: center; }

/* Navigation — white theme */
.top-nav {
    display: flex; align-items: center; gap: 24px;
    background: #ffffff; color: var(--text); padding: 0 24px; height: 60px;
    position: sticky; top: 0; z-index: 100;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}
.nav-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; white-space: nowrap; color: var(--text); }
.nav-brand img { height: 36px; width: auto; display: block; }
.nav-links { display: flex; gap: 4px; flex: 1; }
.nav-link {
    color: var(--text-muted); text-decoration: none; padding: 8px 14px;
    border-radius: 7px; font-size: 0.9rem; font-weight: 500; transition: all 0.15s;
    position: relative; white-space: nowrap;
}
.nav-link:hover { color: var(--text); background: #f1f5f9; text-decoration: none; }
.nav-link.active { color: #fff; background: var(--primary); }
.badge {
    background: var(--danger); color: white; font-size: 0.7rem;
    padding: 1px 6px; border-radius: 10px; position: absolute; top: 2px; right: 2px;
}
.nav-user { display: flex; align-items: center; gap: 12px; white-space: nowrap; }
.nav-user span { color: var(--text-muted); font-size: 0.9rem; }
.rep-switcher { display: flex; align-items: center; gap: 8px; }
.rep-switcher-label {
    color: var(--text-muted); font-size: 0.72rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.rep-switcher select {
    padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border);
    background: #fff; color: var(--text); font-size: 0.85rem; cursor: pointer;
    min-width: 120px;
}
.rep-switcher select:hover { border-color: var(--primary); }
.muted { color: var(--text-muted); font-size: 0.8rem; }

/* Campaign Calendar (Gantt timeline) */
.cal-summary { margin-bottom: 12px; }
.cal-stats { display: flex; gap: 24px; padding: 12px 16px; background: var(--card-bg);
    border: 1px solid var(--border); border-radius: 10px; font-size: 0.9rem; }
.cal-stats div { color: var(--text-muted); }
.cal-stats strong { color: var(--text); font-size: 1rem; }

.cal-wrap { background: var(--card-bg); border: 1px solid var(--border);
    border-radius: 9px; padding: 16px; overflow-x: auto; }
.cal-timeline { min-width: 900px; }

.cal-header, .cal-row { display: flex; align-items: stretch; }
.cal-label, .cal-label-spacer {
    flex: 0 0 220px; width: 220px; padding: 6px 12px 6px 0;
    font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    border-right: 1px solid var(--border);
}
.cal-label a { color: var(--text); font-weight: 500; }
.cal-label a:hover { color: var(--primary); }

.cal-track { flex: 1; position: relative; min-height: 28px; }
.cal-track-header { border-bottom: 1px solid var(--border); height: 28px; margin-bottom: 4px; }
.cal-month-tick {
    position: absolute; top: 0; bottom: 0; border-left: 1px dashed #e2e8f0;
    padding-left: 4px; color: var(--text-muted); font-size: 0.7rem;
    text-transform: uppercase; letter-spacing: 0.5px; pointer-events: none;
}
.cal-month-tick span { position: relative; top: 6px; }
.cal-today {
    position: absolute; top: 0; bottom: 0; width: 2px; background: var(--danger);
    z-index: 5; pointer-events: none;
}

.cal-body { margin-top: 2px; }
.cal-row { border-bottom: 1px solid #f1f5f9; }
.cal-row:hover { background: #f8fafc; }
.cal-row .cal-track { padding: 6px 0; }

.cal-bar {
    position: absolute; top: 50%; transform: translateY(-50%);
    height: 18px; border-radius: 4px; display: flex; align-items: center;
    padding: 0 8px; font-size: 0.7rem; color: white; font-weight: 500;
    overflow: hidden; white-space: nowrap; cursor: help;
}
.cal-bar-label { opacity: 0.9; }
.cal-bar.net-cinema     { background: linear-gradient(135deg, #dc2626, #b91c1c); }
.cal-bar.net-campus     { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.cal-bar.net-residential { background: linear-gradient(135deg, #10b981, #047857); }
.cal-bar.net-restobar   { background: linear-gradient(135deg, #f59e0b, #b45309); }
.cal-bar.net-sh         { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.cal-bar.net-other      { background: linear-gradient(135deg, #64748b, #475569); }

/* Weekly summary card */
.weekly-summary { margin-bottom: 20px; }
.weekly-card {
    background: linear-gradient(135deg, #f2f0ec 0%, #ece9e4 100%);
    border: 1px solid #ddd8d2; border-radius: 9px; padding: 18px 22px;
}
.weekly-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.weekly-header h3 { font-size: 0.95rem; color: #262220; margin: 0; }
.weekly-stats { display: flex; gap: 28px; flex-wrap: wrap; font-size: 0.9rem; color: var(--text-muted); margin-bottom: 10px; }
.weekly-stats strong { color: var(--text); font-size: 1.05rem; }
.weekly-reps { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.weekly-deals { list-style: none; padding: 0; margin: 6px 0 0 0; font-size: 0.85rem; }
.weekly-deals li { padding: 4px 0; border-top: 1px solid #ddd8d2; }
.weekly-deals li .money { float: right; font-weight: 600; color: var(--text); }
.weekly-deals li a { font-weight: 500; }

.chat-badge {
    display: inline-block; margin-bottom: 12px;
    padding: 6px 14px; border-radius: 999px;
    background: #f2f0ec; color: #262220; font-size: 0.8rem; font-weight: 600;
    border: 1px solid #ddd8d2;
}
.btn-small {
    padding: 6px 14px; border-radius: 6px; border: 1px solid var(--border);
    background: #fff; color: var(--text); cursor: pointer; font-size: 0.8rem;
}
.btn-small:hover { background: #f1f5f9; border-color: var(--primary); }

/* Content */
.content-area {
    padding: 24px;
    max-width: 1400px;
    margin: 0 auto;
    overflow: hidden; /* prevent children from blowing out width */
}

/* Filter Bar */
.filter-bar {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: end;
    background: var(--card-bg); padding: 16px 20px; border-radius: 9px;
    border: 1px solid var(--border); margin-bottom: 20px;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-group label {
    font-size: 0.75rem; color: var(--text-muted); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.filter-group select, .filter-group input {
    padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 0.85rem; background: white; min-width: 140px; color: var(--text);
}
.filter-actions { display: flex; gap: 8px; align-items: end; margin-left: auto; }
.btn-primary {
    padding: 8px 20px; background: var(--primary); color: white; border: none;
    border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 0.85rem;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline {
    padding: 8px 16px; background: transparent; color: var(--text-muted);
    border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-size: 0.85rem;
}
.btn-outline:hover { background: #f8fafc; }

/* KPI Cards */
.kpi-grid {
    display: grid; grid-template-columns: repeat(4, 1fr);
    gap: 16px; margin-bottom: 20px;
}
.kpi-card {
    background: var(--card-bg); border-radius: 9px; padding: 20px;
    border: 1px solid var(--border);
}
.kpi-card .kpi-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-card .kpi-value { font-size: 1.8rem; font-weight: 700; color: var(--text); margin: 4px 0; }
.kpi-card .kpi-sub { font-size: 0.8rem; color: var(--text-muted); }

/* Chart Grid */
.chart-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}
.chart-card {
    background: var(--card-bg); border-radius: 9px; padding: 20px;
    border: 1px solid var(--border);
    min-width: 0;       /* KEY: prevent grid child from overflowing */
    overflow: hidden;    /* clip any overflow */
}
.chart-card h3 { font-size: 0.95rem; color: var(--text); margin-bottom: 16px; }
.chart-card canvas { max-height: 300px; width: 100% !important; }

/* Full-width chart row for heatmap + YoY */
.chart-grid-full {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}
.chart-grid-full .chart-card {
    min-width: 0;
    overflow: hidden;
}

/* Drill-down Modal */
.drill-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    display: flex; align-items: center; justify-content: center;
    z-index: 200; padding: 24px;
}
.drill-modal {
    background: var(--card-bg); border-radius: 11px; padding: 24px;
    max-width: 1100px; width: 100%; max-height: 85vh;
    display: flex; flex-direction: column;
    box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}
.drill-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    margin-bottom: 16px; flex-shrink: 0;
}
.drill-header h3 { font-size: 1.1rem; margin-bottom: 2px; }
.drill-modal .table-scroll { overflow: auto; flex: 1; min-height: 0; }
.heatmap td[onclick] { transition: opacity 0.15s; }
.heatmap td[onclick]:hover { opacity: 0.8; }

/* Data Table */
.table-card {
    background: var(--card-bg); border-radius: 9px; padding: 20px;
    border: 1px solid var(--border); margin-bottom: 20px;
    overflow: hidden;
}
.table-card h3 { font-size: 0.95rem; margin-bottom: 12px; }
.table-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 12px; flex-wrap: wrap; gap: 8px;
}
.table-header .search-input {
    padding: 8px 14px; border: 1px solid var(--border); border-radius: 6px;
    font-size: 0.85rem; width: 250px;
}

.table-scroll { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.data-table th {
    text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--border);
    color: var(--text-muted); font-weight: 600; font-size: 0.75rem;
    text-transform: uppercase; letter-spacing: 0.5px; cursor: pointer; white-space: nowrap;
}
table.data-table th:hover { color: var(--text); }
table.data-table td {
    padding: 10px 12px; border-bottom: 1px solid var(--border);
    max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
table.data-table tr:hover { background: #f8fafc; }
table.data-table tr.clickable { cursor: pointer; }
/* .text-right (specificity 0,1,0) loses to `table.data-table th` (0,1,2), which
   left-aligns headers while the body cells stay right-aligned — misaligning the
   numeric columns. Re-assert right alignment at matching specificity. */
table.data-table th.text-right, table.data-table td.text-right { text-align: right; }

/* Grouped key/definition legend under the CPM & Bonus Yield table */
dl.cpm-legend {
    margin: 0 0 12px; padding: 8px 12px; border-left: 2px solid var(--border);
    background: #faf8f5; border-radius: 0 4px 4px 0;
    font-size: 0.74rem; color: var(--text-muted); line-height: 1.5;
}
dl.cpm-legend > div { display: flex; gap: 6px; }
dl.cpm-legend > div + div { margin-top: 3px; }
dl.cpm-legend dt { font-weight: 600; color: var(--text); white-space: nowrap; }
dl.cpm-legend dt::after { content: "="; margin-left: 6px; font-weight: 400; color: var(--text-muted); }
dl.cpm-legend dd { margin: 0; }

.year-filter { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.year-filter .year-chip {
    padding: 5px 14px; border-radius: 999px; font-size: 0.85rem;
    border: 1px solid #ddd8d2; background: #fff; color: #262220; cursor: pointer;
}
.year-filter .year-chip:hover { background: #f2f0ec; }
.year-filter .year-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }

#prog-adv-chip:not(:empty) { margin-bottom: 12px; }
.filter-chip {
    display: inline-flex; align-items: center; gap: 8px;
    background: #f2f0ec; color: #262220; border: 1px solid #ddd8d2;
    border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 0.85rem;
}
.filter-chip .chip-x {
    border: none; background: #ddd8d2; color: #262220; cursor: pointer;
    width: 20px; height: 20px; border-radius: 50%; line-height: 1; font-size: 0.95rem;
}
.filter-chip .chip-x:hover { background: #a5b4fc; }
table.data-table tr.active-row { background: #f2f0ec; font-weight: 600; }
table.data-table tr.active-row:hover { background: #ece9e4; }

/* Consolidated contract rows: a caret to expand into the nested line items. */
.table-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.view-toggle { padding: 7px 12px; font-size: 0.8rem; white-space: nowrap; }
table.data-table th.expand-col, table.data-table td.expand-col { width: 26px; padding-right: 0; text-align: center; }
table.data-table tr.contract-row { cursor: pointer; }
table.data-table tr.contract-row:hover { background: #f8fafc; }
.caret { display: inline-block; width: 14px; color: var(--text-muted); font-size: 0.7rem; transition: transform .12s ease; }
.contract-no { font-size: 0.72rem; margin-top: 2px; }
.line-badge {
    display: inline-block; padding: 1px 8px; border-radius: 10px;
    background: #eef2f7; color: var(--text-muted); font-size: 0.72rem; font-weight: 600;
}
/* Nested line-item detail table inside an expanded contract row. */
tr.line-detail-row > td { padding: 0 12px 10px 12px; background: #fafbfc; border-bottom: 1px solid var(--border); }
table.line-detail { margin: 4px 0 4px 14px; width: calc(100% - 14px); font-size: 0.8rem; }
table.line-detail th { padding: 6px 10px; border-bottom: 1px solid var(--border); text-transform: none; letter-spacing: 0; cursor: default; }
table.line-detail th:hover { color: var(--text-muted); }
table.line-detail td { padding: 6px 10px; border-bottom: 1px solid #eef1f4; }
table.line-detail tr:hover { background: transparent; }

.pagination {
    display: flex; align-items: center; justify-content: space-between;
    margin-top: 12px; font-size: 0.85rem; color: var(--text-muted);
}
.pagination button {
    padding: 6px 14px; border: 1px solid var(--border); border-radius: 6px;
    background: white; cursor: pointer; font-size: 0.85rem; color: var(--text);
}
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Heatmap */
.heatmap-container { overflow-x: auto; }
.heatmap { border-collapse: collapse; width: 100%; font-size: 0.75rem; }
.heatmap th, .heatmap td { padding: 6px 8px; text-align: center; white-space: nowrap; }
.heatmap th { color: var(--text-muted); font-weight: 600; font-size: 0.7rem; }
.heatmap td { border-radius: 4px; }

/* Drag-to-reorder dashboard panels */
.dash-layout-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; margin-bottom: 20px; }
.dash-panel { position: relative; min-width: 0; }
.dash-panel--wide { grid-column: 1 / -1; }
.dash-panel > .chart-card, .dash-panel > .table-card { height: 100%; }
/* Scorecard stretches to match the height of whatever shares its row (grid is
   otherwise top-aligned); its inner card fills via the height:100% rule above. */
.dash-panel[data-panel="scorecard"] { align-self: stretch; }
.drag-handle {
    position: absolute; top: -10px; left: 50%; transform: translateX(-50%);
    background: var(--border, #e2e8f0); color: #475569;
    border-radius: 6px; padding: 2px 14px; line-height: 1;
    font-size: 0.7rem; letter-spacing: 3px; cursor: grab;
    z-index: 4; opacity: 0.45; transition: opacity 0.15s; user-select: none;
}
.dash-panel:hover .drag-handle { opacity: 1; }
.drag-handle:active { cursor: grabbing; }
.sortable-ghost { opacity: 0.35; }
.sortable-chosen .chart-card, .sortable-chosen .table-card,
.sortable-chosen .kpi-grid, .sortable-chosen .weekly-summary {
    outline: 2px dashed var(--accent, #262220); outline-offset: 2px; border-radius: 9px;
}
@media (max-width: 1100px) {
    .dash-grid { grid-template-columns: 1fr; }
    .dash-panel { grid-column: 1 / -1 !important; }
}

/* YoY */
.yoy-container { overflow-x: auto; }
.growth-positive { color: var(--success); font-weight: 600; }
.growth-negative { color: var(--danger); font-weight: 600; }

/* Chat */
.chat-container { display: flex; flex-direction: column; height: calc(100vh - 104px); }
.chat-messages {
    flex: 1; overflow-y: auto; padding: 20px; display: flex;
    flex-direction: column; gap: 16px;
}
.chat-msg {
    max-width: 80%; padding: 14px 18px; border-radius: 9px;
    font-size: 0.9rem; line-height: 1.6; word-wrap: break-word;
}
.chat-msg.user {
    align-self: flex-end; background: var(--primary); color: white;
    border-bottom-right-radius: 4px;
}
.chat-msg.assistant {
    align-self: flex-start; background: var(--card-bg); border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.chat-msg .sql-toggle { font-size: 0.75rem; color: var(--text-muted); cursor: pointer; margin-top: 8px; }
.chat-msg pre { background: #f8fafc; padding: 10px; border-radius: 6px; margin-top: 8px; font-size: 0.8rem; overflow-x: auto; }
.chat-msg table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 0.8rem; }
.chat-msg table th, .chat-msg table td { padding: 6px 10px; border: 1px solid var(--border); text-align: left; }
.chat-msg table th { background: #f8fafc; font-weight: 600; }
.chat-input-area {
    padding: 16px 20px; background: var(--card-bg); border-top: 1px solid var(--border);
    display: flex; gap: 10px;
}
.chat-input-area input {
    flex: 1; padding: 12px 16px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 0.9rem; color: var(--text);
}
.chat-input-area button {
    padding: 12px 24px; background: var(--primary); color: white;
    border: none; border-radius: 8px; cursor: pointer; font-weight: 600;
}
.suggested-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px 12px; }
.chip {
    padding: 6px 14px; background: #f2f0ec; border: 1px solid #ddd8d2;
    border-radius: 20px; font-size: 0.8rem; color: var(--primary); cursor: pointer;
}
.chip:hover { background: #ece9e4; }
.chat-thinking { color: var(--text-muted); font-style: italic; padding: 10px 18px; }

/* Notifications */
.notif-list { display: flex; flex-direction: column; gap: 12px; }
.notif-card {
    background: var(--card-bg); border-radius: 9px; padding: 16px 20px;
    border: 1px solid var(--border); display: flex; gap: 16px; align-items: flex-start;
}
.notif-card.unread { border-left: 4px solid var(--primary); }
.notif-icon {
    width: 40px; height: 40px; border-radius: 10px; display: flex;
    align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0;
}
.notif-icon.renewal { background: #dcfce7; }
.notif-icon.upsell { background: #fef3c7; }
.notif-icon.lapsed { background: #fee2e2; }
.notif-icon.campaign { background: #ece9e4; }
.notif-body { flex: 1; min-width: 0; }
.notif-body .notif-meta { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.notif-body .notif-title { font-weight: 600; font-size: 0.9rem; }
.rep-chip {
    display: inline-block; padding: 2px 10px; border-radius: 999px;
    background: #ece9e4; color: #262220; font-size: 0.72rem; font-weight: 600;
    letter-spacing: 0.3px;
}
.type-badge {
    display: inline-block; padding: 2px 10px; border-radius: 999px;
    font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px;
    background: #f1f5f9; color: var(--text-muted);
}
.type-badge.renewal { background: #dcfce7; color: #15803d; }
.type-badge.upsell { background: #fef3c7; color: #a16207; }
.type-badge.lapsed { background: #fee2e2; color: #b91c1c; }
.type-badge.campaign { background: #ece9e4; color: #262220; }
.notif-body .notif-text { font-size: 0.85rem; color: var(--text-muted); margin-top: 4px; }
.notif-body .notif-date { font-size: 0.75rem; color: var(--text-muted); margin-top: 6px; }
.notif-actions { flex-shrink: 0; }
.notif-actions button {
    padding: 6px 12px; border: 1px solid var(--border); border-radius: 6px;
    background: white; cursor: pointer; font-size: 0.8rem; color: var(--text);
}
.notif-actions button:hover { background: #f8fafc; }

/* Client 360 */
.client-header {
    background: var(--card-bg); border-radius: 9px; padding: 24px;
    border: 1px solid var(--border); margin-bottom: 20px;
}
.client-header h2 { font-size: 1.4rem; margin-bottom: 4px; }
.client-header .meta { color: var(--text-muted); font-size: 0.9rem; }
.client-stats {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px; margin-top: 16px;
}
.client-stat .stat-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; font-weight: 600; }
.client-stat .stat-value { font-size: 1.3rem; font-weight: 700; }

.section-card {
    background: var(--card-bg); border-radius: 9px; padding: 20px;
    border: 1px solid var(--border); margin-bottom: 20px;
    overflow: hidden;
}
.section-card h3 { font-size: 0.95rem; margin-bottom: 14px; }

.upsell-card {
    background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px;
    padding: 14px 18px; margin-bottom: 10px;
}
.upsell-card .upsell-title { font-weight: 600; font-size: 0.9rem; color: #92400e; }
.upsell-card .upsell-desc { font-size: 0.85rem; color: #78350f; margin-top: 4px; }
.upsell-card.high { border-color: #fca5a5; background: #fef2f2; }
.upsell-card.high .upsell-title { color: #991b1b; }
.upsell-card.high .upsell-desc { color: #7f1d1d; }

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
    padding: 4px 10px; background: #f1f5f9; border-radius: 6px;
    font-size: 0.8rem; color: var(--text-muted);
}
.tag.active { background: #ece9e5; color: var(--primary); }
.tag.missing { background: #fef2f2; color: var(--danger); border: 1px dashed #fca5a5; }

/* Agencies */
.agency-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
}
.agency-card {
    background: var(--card-bg); border-radius: 9px; padding: 20px;
    border: 1px solid var(--border); cursor: pointer; transition: all 0.15s;
}
.agency-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.agency-card .agency-name { font-weight: 700; font-size: 1rem; }
.agency-card .agency-revenue { font-size: 1.4rem; font-weight: 700; color: var(--primary); margin: 8px 0; }
.agency-card .agency-meta { font-size: 0.8rem; color: var(--text-muted); }

/* Upsell Widget */
.upsell-widget {
    background: linear-gradient(135deg, #fef3c7, #fffbeb);
    border: 1px solid #fde68a; border-radius: 9px; padding: 20px;
}
.upsell-widget h3 { color: #92400e; font-size: 0.95rem; margin-bottom: 12px; }

/* Utils */
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.fw-bold { font-weight: 700; }
.money { font-variant-numeric: tabular-nums; }
.empty-state {
    text-align: center; padding: 48px 20px; color: var(--text-muted);
}
.loading { text-align: center; padding: 40px; color: var(--text-muted); }

/* Responsive */
@media (max-width: 1024px) {
    .chart-grid { grid-template-columns: 1fr; }
    .chart-grid-full { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .top-nav { padding: 0 12px; gap: 8px; }
    .nav-links { overflow-x: auto; gap: 2px; }
    .nav-link { padding: 6px 10px; font-size: 0.8rem; }
    .nav-brand { font-size: 0.9rem; }
    .content-area { padding: 12px; }
    .filter-bar { flex-direction: column; }
    .filter-group { width: 100%; }
    .filter-group select { min-width: 100%; width: 100%; }
    .filter-actions { margin-left: 0; width: 100%; justify-content: stretch; }
    .filter-actions button { flex: 1; }
    .agency-grid { grid-template-columns: 1fr; }
}

/* TAG Dashboard tab */
.kpi-card.kpi-highlight { border-left: 3px solid var(--primary); background: linear-gradient(90deg, rgba(38,34,32,0.05), var(--card-bg)); }
.tag-pill { font-size: 0.68rem; font-weight: 700; padding: 1px 7px; border-radius: 10px; letter-spacing: 0.3px; vertical-align: middle; }
.tag-pill-new { background: #dcfce7; color: #166534; }
.tag-pill-csv { background: #e2e8f0; color: #475569; }
.tag-recent-list { display: flex; flex-direction: column; }
.tag-recent-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.tag-recent-row:last-child { border-bottom: none; }
.tag-recent-row.clickable { cursor: pointer; }
.tag-recent-row.clickable:hover { background: var(--hover-bg, rgba(37,99,235,0.04)); }
.tag-recent-meta { text-align: right; white-space: nowrap; }

/* Source banner on the reused Dashboard when it renders a non-CSV source (TAG). */
.source-banner {
    background: #f2f0ec; border: 1px solid #ddd8d2; color: #262220;
    padding: 8px 14px; border-radius: 8px; font-size: .85rem; margin-bottom: 12px;
}

/* Weekly Scorecard — click a week to drill; hovering a cell lights its whole column. */
.scorecard-table .sc-week { transition: background .1s; }
.scorecard-table .sc-week.sc-col-hl { background: rgba(37,99,235,0.12); }
/* One-time discoverability pulse on the newest week column (added by JS on first render). */
@keyframes scPulse { 0%, 100% { background: transparent; } 50% { background: rgba(37,99,235,0.18); } }
.scorecard-table .sc-week.sc-hint { animation: scPulse 1.1s ease-in-out 2; }

/* Data-freshness bar — persistent in the header, sticky under the top-nav, on every page. */
.data-health-bar {
    display:flex; flex-wrap:wrap; align-items:center; gap:16px;
    padding:5px 24px; background:#faf9f7; border-bottom:1px solid var(--border);
    font-size:.76rem; position:sticky; top:60px; z-index:90;
}
.data-health-bar:empty { display:none; }
.dh-item { display:inline-flex; align-items:center; gap:6px; }
.dh-dot { width:8px; height:8px; border-radius:50%; display:inline-block; }
.dh-ok { background:#10b981; } .dh-stale { background:#f59e0b; } .dh-none { background:#94a3b8; }
