/* ==========================================================================
   BC Post — production-fixes.css
   Loaded LAST in base.html. Cross-page design-glitch fixes:
   1. Unified container width (header/footer/content alignment)
   2. Header action buttons restored (dark-mode toggle, staff dashboard)
   3. Working dark mode for [data-bs-theme="dark"]
   4. Production polish (focus states, heading wrap, form consistency, print)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. LAYOUT — one container width everywhere.
   Header/footer use 1360px, but home was 1500px, article detail and city
   pages 1560px, premium events 1440px, so page edges never lined up.
   -------------------------------------------------------------------------- */
:root {
    --site-container: 1360px;
    --bcpost-container: var(--site-container);
    --cn-container: var(--site-container);
}

.bcpost-container {
    width: min(calc(100% - 32px), var(--site-container));
    max-width: var(--site-container);
}

.bc-page-shell {
    width: min(calc(100% - 32px), var(--site-container));
    max-width: var(--site-container);
}

.city-news-page .cn-container,
.city-news-page .container-xxl {
    --cn-container: var(--site-container);
    max-width: var(--site-container);
}

.bc-events-page-premium .bc-events-shell {
    width: min(calc(100% - 32px), var(--site-container));
    max-width: var(--site-container);
}

/* --------------------------------------------------------------------------
   2. HEADER — restore action icon buttons.
   The inline critical CSS hides `.cn-header-actions .cn-icon-button` and no
   later rule re-shows it, so the dark-mode toggle and the staff dashboard
   shortcut were invisible on every viewport.
   -------------------------------------------------------------------------- */
.cn-header-actions .cn-icon-button {
    display: inline-grid;
}

/* --------------------------------------------------------------------------
   3. DARK MODE — [data-bs-theme="dark"] (set by theme-toggle.js).
   The loaded theme had no dark styles at all; toggling produced a broken
   half-dark page. Variables first, then hardcoded surfaces per page.
   -------------------------------------------------------------------------- */
[data-bs-theme="dark"] {
    color-scheme: dark;

    /* cannews-theme tokens */
    --cn-bg: #0b1220;
    --cn-bg-soft: #0f172a;
    --cn-surface: #111a2b;
    --cn-surface-soft: #0f1623;
    --cn-surface-strong: #1c2740;
    --cn-text: #e5e7eb;
    --cn-text-soft: #cbd5e1;
    --cn-text-muted: #94a3b8;
    --cn-primary: #f1f5f9;
    --cn-primary-soft: #e2e8f0;
    --cn-primary-muted: #cbd5e1;
    --cn-accent-soft: #2b1417;
    --cn-blue-soft: #10263a;
    --cn-green-soft: #0e2a1f;
    --cn-yellow-soft: #2c2410;
    --cn-border: #263349;
    --cn-border-strong: #364a68;
    --cn-shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.45);
    --cn-shadow-md: 0 12px 28px rgba(0, 0, 0, 0.5);
    --cn-shadow-lg: 0 22px 60px rgba(0, 0, 0, 0.55);

    /* bcpost-overhaul tokens */
    --bcpost-ink: #e5e7eb;
    --bcpost-muted: #9aa7b8;
    --bcpost-soft: #0b1220;
    --bcpost-paper: #111a2b;
    --bcpost-line: #263349;
    --bcpost-navy: #04070d;
    --bcpost-card-shadow: 0 18px 45px rgba(0, 0, 0, 0.5);
}

/* Global surfaces (body gradient + app shell are hardcoded light) */
[data-bs-theme="dark"] body {
    background: var(--cn-bg);
    color: var(--cn-text);
}

[data-bs-theme="dark"] .bcpost-app {
    background: var(--cn-bg);
}

[data-bs-theme="dark"] .bcpost-home-shell {
    background:
        radial-gradient(circle at top right, rgba(225, 29, 29, 0.07), transparent 30rem),
        linear-gradient(180deg, #0b1220 0%, #0e1626 46%, #0b1220 100%);
}

/* Header */
[data-bs-theme="dark"] .bcpost-sticky-header {
    background: rgba(13, 20, 34, 0.94);
}

[data-bs-theme="dark"] .cn-site-header,
[data-bs-theme="dark"] .cn-brand-row,
[data-bs-theme="dark"] .cn-primary-nav {
    background: #0e1626;
    border-color: var(--cn-border);
}

[data-bs-theme="dark"] .cn-primary-nav {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* Navy/red logo art is invisible on dark surfaces — give it a plate */
[data-bs-theme="dark"] .cn-brand img,
[data-bs-theme="dark"] .cn-mobile-brand img {
    background: #ffffff;
    padding: 5px 9px;
}

[data-bs-theme="dark"] .cn-dropdown-panel,
[data-bs-theme="dark"] .cn-city-mega-panel,
[data-bs-theme="dark"] .cn-mobile-menu-panel {
    background: var(--cn-surface);
    border-color: var(--cn-border);
}

/* Search + generic form controls */
[data-bs-theme="dark"] .cn-site-search-input,
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select,
[data-bs-theme="dark"] input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]),
[data-bs-theme="dark"] select,
[data-bs-theme="dark"] textarea {
    background-color: var(--cn-surface-soft);
    border-color: var(--cn-border);
    color: var(--cn-text);
}

[data-bs-theme="dark"] ::placeholder {
    color: var(--cn-text-muted);
    opacity: 1;
}

/* News list / city pages (hardcoded whites in news.css) */
[data-bs-theme="dark"] .bc-city-page,
[data-bs-theme="dark"] .bc-news-datebar,
[data-bs-theme="dark"] .bc-news-side-card,
[data-bs-theme="dark"] .bc-news-priority-block .article_story_card,
[data-bs-theme="dark"] .bc-news-pagination span,
[data-bs-theme="dark"] .bc-news-event-list article > span,
[data-bs-theme="dark"] .bc-city-snapshot article,
[data-bs-theme="dark"] .bc-city-card-head > span,
[data-bs-theme="dark"] .bc-city-event-media time,
[data-bs-theme="dark"] .bc-city-traffic-status span,
[data-bs-theme="dark"] .city-traffic-card,
[data-bs-theme="dark"] .city-quick-chip,
[data-bs-theme="dark"] .bc-newsletter-box input,
[data-bs-theme="dark"] .bc-city-newsletter input {
    background: var(--cn-surface);
    border-color: var(--cn-border);
    color: var(--cn-text);
}

/* Article reading page */
[data-bs-theme="dark"] .bc-article-page,
[data-bs-theme="dark"] body.bc-article-detail-body .site-main {
    background: var(--cn-bg);
}

[data-bs-theme="dark"] .bc-author-card,
[data-bs-theme="dark"] .bc-share-btn,
[data-bs-theme="dark"] .bc-article-kicker-muted,
[data-bs-theme="dark"] .bc-listen-card .article-audio-button {
    background: var(--cn-surface);
    border-color: var(--cn-border);
    color: var(--cn-text);
}

/* Events */
[data-bs-theme="dark"] .bc-event-date-badge,
[data-bs-theme="dark"] .bc-events-date-input,
[data-bs-theme="dark"] .bc-events-date-link,
[data-bs-theme="dark"] .bc-events-lead-date,
[data-bs-theme="dark"] .bc-events-newsletter-input,
[data-bs-theme="dark"] .bc-events-page-current,
[data-bs-theme="dark"] .bc-events-page-premium .bc-events-empty,
[data-bs-theme="dark"] .bc-events-stat-card,
[data-bs-theme="dark"] .event_detail_page .event_date_badge,
[data-bs-theme="dark"] .event_map_link,
[data-bs-theme="dark"] .event_related_date,
[data-bs-theme="dark"] .event_sidebar_widget {
    background: var(--cn-surface);
    border-color: var(--cn-border);
    color: var(--cn-text);
}

/* Weather / sports / business */
[data-bs-theme="dark"] .bc-weather-city-pill,
[data-bs-theme="dark"] .bc-sports-newsletter-input,
[data-bs-theme="dark"] .bc-sports-page-current,
[data-bs-theme="dark"] .bc-sports-pill,
[data-bs-theme="dark"] .bc-sports-select,
[data-bs-theme="dark"] .bc-business-newsletter-input,
[data-bs-theme="dark"] .bc-business-page-current,
[data-bs-theme="dark"] .bc-business-pill,
[data-bs-theme="dark"] .bc-business-select,
[data-bs-theme="dark"] .bc-business-stat-card {
    background: var(--cn-surface);
    border-color: var(--cn-border);
    color: var(--cn-text);
}

/* Legal + static form pages */
[data-bs-theme="dark"] .bc-legal-content section,
[data-bs-theme="dark"] .bc-check,
[data-bs-theme="dark"] .bc-premium-form .form-select {
    background: var(--cn-surface);
    border-color: var(--cn-border);
    color: var(--cn-text);
}

/* Keep the footer logo plate white in dark mode (matches header treatment) */
[data-bs-theme="dark"] .bc-footer-logo-mark {
    background: #ffffff;
}

/* --------------------------------------------------------------------------
   4. PRODUCTION POLISH
   -------------------------------------------------------------------------- */

/* Consistent, visible keyboard focus without affecting mouse users */
:focus-visible {
    outline: 2px solid var(--cn-logo-blue, #0b56d9);
    outline-offset: 2px;
}

/* Prevent one-word orphan lines in headings and card titles */
h1, h2, h3,
.bcpost-story-card strong,
.cn-lead-story-content strong {
    text-wrap: balance;
    overflow-wrap: break-word;
}

/* Long URLs / unbroken strings must never blow out article layouts */
.cn-article-content,
.article-body {
    overflow-wrap: break-word;
}

/* Avoid layout shift when pages grow past the viewport */
html {
    scrollbar-gutter: stable;
}

/* Media inside articles should never overflow their column */
.cn-article-content img,
.cn-article-content iframe,
.article-body img,
.article-body iframe {
    max-width: 100%;
    height: auto;
}

.article-body iframe,
.cn-article-content iframe {
    aspect-ratio: 16 / 9;
    width: 100%;
    height: auto;
    border: 0;
}

/* Clean print output for articles */
@media print {
    .cn-site-header,
    .cn-topbar,
    .cn-primary-nav,
    .bcpost-breaking,
    .cn-breaking-strip,
    .bc-footer,
    .bc-share-btn,
    .bc-listen-card,
    .skip-link {
        display: none !important;
    }

    body {
        background: #fff !important;
        color: #000 !important;
    }

    .bc-page-shell,
    .bc-article-layout {
        width: 100% !important;
        max-width: none !important;
        display: block !important;
    }
}
