/* China AEC Playbook — Slate & Emerald palette, chart + WFOE step UI */

body {
    font-family: 'Inter', sans-serif;
    background-color: #f8fafc;
    color: #0f172a;
    overflow-x: hidden;
}

/* Minimal top bar: no heavy shadow; relies on border + blur */
.site-nav {
    box-shadow: none;
}

.chart-container {
    position: relative;
    width: 100%;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    height: 350px;
    max-height: 400px;
}

.chart-container-tall {
    position: relative;
    width: 100%;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    height: 720px;
    /* Taller for ~24 horizontal bars */
}

@media (min-width: 768px) {
    .chart-container {
        height: 400px;
    }

    .chart-container-tall {
        height: 920px;
    }
}

.step-active {
    border-bottom-color: #0f172a !important;
    color: #0f172a !important;
}

.badge-gba {
    background-color: #0ea5e9;
    color: white;
}

.badge-east {
    background-color: #8b5cf6;
    color: white;
}

.badge-north {
    background-color: #f59e0b;
    color: white;
}

.badge-inland {
    background-color: #10b981;
    color: white;
}

.badge-hainan {
    background-color: #0e7490;
    color: white;
}

.badge-southwest {
    background-color: #047857;
    color: white;
}

/* ============================================================
   Setup process — horizontal flow rail + compact step rows
   ============================================================ */

.step-flow-layout {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.step-flow-rail {
    display: flex;
    align-items: center;
    gap: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    scroll-padding-inline: 1rem;
    padding: 0.375rem 0.25rem 0.5rem;
    margin: 0 -0.25rem;
    scrollbar-width: thin;
    scrollbar-color: #a7f3d0 transparent;
}

.step-flow-rail::-webkit-scrollbar {
    height: 4px;
}

.step-flow-rail::-webkit-scrollbar-thumb {
    background: #a7f3d0;
    border-radius: 9999px;
}

.step-flow-node {
    flex: 0 0 auto;
    scroll-snap-align: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 9999px;
    border: 2px solid #34d399;
    background: #fff;
    color: #047857;
    font-size: 0.6875rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.step-flow-node:hover {
    background: #ecfdf5;
    transform: translateY(-1px);
}

.step-flow-node.is-active {
    background: #059669;
    border-color: #059669;
    color: #fff;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25);
}

.step-flow-connector {
    flex: 0 0 0.75rem;
    height: 2px;
    background: linear-gradient(90deg, #6ee7b7, #a7f3d0);
    margin: 0 -1px;
}

@media (min-width: 768px) {
    .step-flow-node {
        width: 2rem;
        height: 2rem;
        font-size: 0.75rem;
    }

    .step-flow-connector {
        flex-basis: 1.25rem;
    }
}

.step-flow-header {
    display: none;
    grid-template-columns: 2.5rem minmax(0, 1fr) minmax(11rem, 17.5rem);
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    font-size: 0.625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #64748b;
    border: 1px solid #e2e8f0;
    border-bottom: none;
    background: #f8fafc;
    border-radius: 0.625rem 0.625rem 0 0;
}

@media (min-width: 768px) {
    .step-flow-header {
        display: grid;
    }
}

.step-flow-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid #e2e8f0;
    border-radius: 0.625rem;
    overflow: hidden;
    background: #fff;
}

.step-flow-header + .step-flow-list {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.step-flow-row:not(:last-child) {
    border-bottom: 1px solid #f1f5f9;
}

.step-flow-row--flash {
    animation: step-flow-flash 1.2s ease;
}

@keyframes step-flow-flash {
    0%, 100% { background-color: transparent; }
    15%, 45% { background-color: #ecfdf5; }
}

.step-flow-row-inner {
    display: grid;
    grid-template-columns: 1.75rem minmax(0, 1fr);
    grid-template-rows: auto auto;
    gap: 0.375rem 0.625rem;
    padding: 0.625rem 0.75rem;
    align-items: start;
}

.step-flow-num {
    grid-row: 1 / span 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 9999px;
    background: #059669;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.step-flow-body {
    min-width: 0;
    grid-column: 2;
}

.step-flow-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.45;
    margin: 0;
}

.step-flow-money {
    grid-column: 2;
    padding: 0.375rem 0.5rem;
    background: #f0fdf4;
    border-radius: 0.375rem;
    border: 1px solid #d1fae5;
}

.step-flow-money-text {
    font-size: 0.75rem;
    color: #334155;
    line-height: 1.45;
    margin: 0;
}

@media (min-width: 768px) {
    .step-flow-row-inner {
        grid-template-columns: 2.5rem minmax(0, 1fr) minmax(11rem, 17.5rem);
        grid-template-rows: auto;
        gap: 0.75rem;
        padding: 0.625rem 1rem;
    }

    .step-flow-num {
        width: 2rem;
        height: 2rem;
        font-size: 0.8125rem;
        grid-row: 1;
    }

    .step-flow-title {
        font-size: 0.875rem;
    }

    .step-flow-money {
        grid-column: 3;
        grid-row: 1;
        align-self: stretch;
        display: flex;
        align-items: flex-start;
        padding: 0.375rem 0.625rem;
        background: linear-gradient(135deg, #f0fdf4 0%, #ffffff 100%);
        border: none;
        border-left: 1px solid #d1fae5;
        border-radius: 0;
    }

    .step-flow-money-text {
        font-size: 0.8125rem;
    }
}

details.wfoe-details>summary {
    list-style: none;
}

details.wfoe-details>summary::-webkit-details-marker {
    display: none;
}

/* Chevron via CSS only — avoids Tailwind-preflight SVG blow-up in flex/grid */
details.wfoe-details>summary.step-flow-more {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.25rem;
    width: fit-content;
    max-width: 100%;
    padding: 0.125rem 0.375rem 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-size: 0.6875rem;
    font-weight: 500;
    line-height: 1.2;
    color: #047857;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

details.wfoe-details>summary.step-flow-more::before {
    content: "";
    display: inline-block;
    width: 0.35rem;
    height: 0.35rem;
    flex: 0 0 0.35rem;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
    margin-top: -0.1rem;
    transition: transform 0.2s ease;
}

details.wfoe-details[open]>summary.step-flow-more::before {
    transform: rotate(-135deg);
    margin-top: 0.1rem;
}

details.wfoe-details>summary.step-flow-more:hover {
    color: #059669;
    background: #ecfdf5;
}

details.wfoe-details>summary.step-flow-more:focus-visible {
    outline: 2px solid #10b981;
    outline-offset: 2px;
}

details.wfoe-details .step-flow-more-label {
    line-height: 1.2;
}

/* Regional hub snapshots (under each hubs h3) */
details.hub-region-details>summary {
    list-style: none;
}

details.hub-region-details>summary::-webkit-details-marker {
    display: none;
}

details.hub-region-details .hub-region-chevron {
    transition: transform 0.2s ease;
}

details.hub-region-details[open] .hub-region-chevron {
    transform: rotate(180deg);
}

/* ============================================================
   Phase 1: usability additions — skip-link, mobile menu states,
   FX status badge, focus-visible. Order matters: keep these
   AFTER the existing rules so Tailwind utilities still win where
   intended; we only add new selectors / states.
   ============================================================ */

/* Skip-to-content link: invisible until keyboard-focused */
.skip-to-content:focus {
    position: fixed;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 60;
    background: #0f172a;
    color: #ffffff;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.25);
}

/* Restore visible focus where Tailwind defaults / inline classes turned outline off */
:focus-visible {
    outline: 2px solid #10b981;
    outline-offset: 2px;
    border-radius: 4px;
}
.site-nav a:focus-visible,
.site-nav button:focus-visible {
    outline-offset: 3px;
}

/* Mobile menu open/close icon swap, driven by aria-expanded on the toggle */
#nav-menu-toggle[aria-expanded="true"] .nav-menu-icon-open { display: none; }
#nav-menu-toggle[aria-expanded="true"] .nav-menu-icon-close { display: block; }

/* Section anchor offset so the fixed nav doesn't cover headings */
main section[id] { scroll-margin-top: 5rem; }

/* FX info trigger + hover tooltip (replaces inline rate/status labels) */
.fx-info-trigger {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    padding: 0;
    border: none;
    border-radius: 9999px;
    color: #94a3b8;
    background: transparent;
    cursor: help;
    flex-shrink: 0;
}
.fx-info-trigger:hover,
.fx-info-trigger:focus-visible {
    color: #64748b;
}
.fx-info-icon {
    width: 0.875rem;
    height: 0.875rem;
}
.fx-info-trigger::after {
    content: "";
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 5px;
    height: 5px;
    border-radius: 9999px;
    border: 1px solid #f8fafc;
    background: #94a3b8;
}
.fx-info-trigger.fx-live::after {
    background: #10b981;
}
.fx-info-trigger.fx-fallback::after {
    background: #f59e0b;
}
.fx-info-trigger.fx-pending::after {
    background: #94a3b8;
}

/* Compact status chip beside (i) — restores live/fallback/pending color semantics */
.fx-status-chip {
    display: inline-block;
    font-size: 0.625rem;
    font-weight: 600;
    line-height: 1.2;
    padding: 0.125rem 0.375rem;
    border-radius: 9999px;
    white-space: nowrap;
    letter-spacing: normal;
    text-transform: none;
}
.fx-status-chip.fx-live {
    color: #047857;
    background: #d1fae5;
}
.fx-status-chip.fx-fallback {
    color: #b45309;
    background: #fef3c7;
}
.fx-status-chip.fx-pending {
    color: #64748b;
    background: #f1f5f9;
}

.fx-info-tooltip-line {
    display: block;
}
.fx-info-status {
    display: block;
    margin-top: 0.25rem;
    font-weight: 600;
}
.fx-info-status.fx-live {
    color: #34d399;
}
.fx-info-status.fx-fallback {
    color: #fbbf24;
}
.fx-info-status.fx-pending {
    color: #94a3b8;
}

.fx-info-tooltip {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: 16rem;
    padding: 0.5rem 0.625rem;
    font-size: 0.6875rem;
    font-weight: 500;
    line-height: 1.45;
    white-space: pre-line;
    text-align: left;
    text-transform: none;
    letter-spacing: normal;
    color: #f8fafc;
    background: #1e293b;
    border-radius: 0.375rem;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.2);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease, visibility 0.15s ease;
    z-index: 30;
}
.fx-info-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #1e293b;
}
.fx-info-trigger:hover .fx-info-tooltip,
.fx-info-trigger:focus-visible .fx-info-tooltip {
    opacity: 1;
    visibility: visible;
}

/* ============================================================
   Phase 1.3 — Print styles. Goal: make the page printable as a
   readable reference. Constraints from review:
     - never display:none main subtree
     - keep all step bodies open so content is not silently hidden
     - only collapse decoration (fixed nav, mobile menu, charts)
   ============================================================ */
@media print {
    /* Strip fixed/sticky chrome that overlaps content or wastes space */
    .site-nav {
        position: static !important;
        background: #ffffff !important;
        border-bottom: 1px solid #cbd5e1 !important;
        backdrop-filter: none !important;
    }
    #nav-menu-toggle,
    #mobile-menu,
    #lang-toggle,
    .skip-to-content { display: none !important; }

    /* The header is decorative spacing in print; tighten it */
    header.pt-28 { padding-top: 1rem !important; padding-bottom: 1rem !important; }

    /* Force every progressive-disclosure block open so all step text prints */
    details { page-break-inside: avoid; }
    details.wfoe-details > summary,
    details.hub-region-details > summary { color: #334155 !important; }
    details.wfoe-details > summary > svg,
    details.hub-region-details > summary > svg { display: none !important; }

    /* Avoid awkward cuts inside step rows and city tiles */
    .step-flow-row,
    .grid > div { page-break-inside: avoid; }

    .step-flow-rail { display: none !important; }

    /* Charts are interactive; replace with the printable data table siblings. */
    .chart-container,
    .chart-container-tall { display: none !important; }

    /* Make sticky doughnut column flow inline for print */
    .sticky { position: static !important; top: auto !important; }

    /* Reset page background to plain white for ink */
    body { background: #ffffff !important; color: #0f172a !important; }
    main, section, .bg-slate-50, .bg-emerald-50\/90 { background: #ffffff !important; }

    /* Hide the slate footer (decorative); the disclaimer is in the methodology section already */
    footer.bg-slate-900 { background: #ffffff !important; color: #475569 !important; border-top: 1px solid #cbd5e1 !important; }
    footer.bg-slate-900 .text-slate-300 { color: #334155 !important; }

    /* Hide the mobile-only menu toggle which can leave a small empty bordered box */
    #nav-menu-toggle, .skip-to-content { display: none !important; }
}

/* Force-open helpers used by the "expand all" button and by print pre-pass */
details.is-force-open { /* utility class; behavior controlled by JS adding the open attribute */ }

/* ============================================================
   Dark mode — html.dark class toggle (see index.html theme
   bootstrap script + #theme-toggle button, and china-business.js
   toggleTheme()). Approach: rather than adding `dark:` variants
   to every one of the ~50 hardcoded slate/white/emerald/sky/amber
   utility classes across index.html + the JS-rendered step cards
   (steps-render.js) + i18n strings (i18n-china-business.js), this
   overrides the SAME class names globally under html.dark with
   !important. This keeps light-mode markup untouched (zero risk
   of light-mode regressions) and automatically covers classes
   that JS adds/removes at runtime (classList.add('bg-white', ...)
   etc. in china-business.js) since the override is class-based,
   not element-based. Mirrors the pattern used by china-housing
   and pharm-companies demos in this repo.
   ============================================================ */

html.dark {
    color-scheme: dark;
}

html.dark body {
    background-color: #0b1220;
    color: #e2e8f0;
}

/* Surfaces: white/near-white backgrounds -> dark slate surfaces */
html.dark .bg-white,
html.dark .bg-white\/85,
html.dark .bg-white\/95 {
    background-color: #131d30 !important;
}

html.dark .bg-slate-50,
html.dark .bg-slate-50\/60,
html.dark .bg-slate-50\/80 {
    background-color: #0f1a2e !important;
}

html.dark .bg-slate-200 {
    background-color: #1e293b !important;
}

html.dark .bg-slate-900 {
    background-color: #05070d !important;
}

html.dark .bg-sky-50 {
    background-color: rgba(56, 189, 248, 0.08) !important;
}

html.dark .bg-amber-50,
html.dark .bg-amber-50\/60 {
    background-color: rgba(251, 191, 36, 0.1) !important;
}

html.dark .bg-cyan-50\/80 {
    background-color: rgba(34, 211, 238, 0.08) !important;
}

/* Borders */
html.dark .border-slate-100,
html.dark .border-slate-200,
html.dark .border-slate-200\/90,
html.dark .border-slate-300 {
    border-color: #29394f !important;
}

html.dark .border-slate-800 {
    border-color: #1e293b !important;
}

html.dark .border-sky-400,
html.dark .border-sky-500 {
    border-color: #38bdf8 !important;
}

html.dark .border-amber-300,
html.dark .border-amber-400,
html.dark .border-amber-500 {
    border-color: #fbbf24 !important;
}

html.dark .border-emerald-400,
html.dark .border-emerald-500 {
    border-color: #34d399 !important;
}

html.dark .border-cyan-100\/80,
html.dark .border-cyan-200,
html.dark .border-cyan-400 {
    border-color: #22d3ee !important;
}

/* Text */
html.dark .text-slate-900 {
    color: #f1f5f9 !important;
}

html.dark .text-slate-800 {
    color: #e2e8f0 !important;
}

html.dark .text-slate-700 {
    color: #cbd5e1 !important;
}

html.dark .text-slate-600 {
    color: #94a3b8 !important;
}

html.dark .text-slate-500 {
    color: #94a3b8 !important;
}

html.dark .text-slate-400,
html.dark .text-slate-300 {
    color: #64748b !important;
}

html.dark .text-emerald-600,
html.dark .text-emerald-700 {
    color: #34d399 !important;
}

html.dark .text-sky-500,
html.dark .text-sky-700,
html.dark .text-sky-800 {
    color: #38bdf8 !important;
}

html.dark .text-amber-500,
html.dark .text-amber-700,
html.dark .text-amber-800 {
    color: #fbbf24 !important;
}

html.dark .text-cyan-800,
html.dark .text-cyan-900 {
    color: #22d3ee !important;
}

/* Hover states use the same slate-800/900 hover targets in light mode;
   in dark mode route them to a lighter tone so hover is still visible
   against the now-dark surface. */
html.dark .hover\:text-slate-800:hover,
html.dark .hover\:text-slate-900:hover {
    color: #f1f5f9 !important;
}

html.dark .hover\:bg-slate-50:hover {
    background-color: #1e293b !important;
}

/* Custom (non-Tailwind) hardcoded-hex components below need their own
   dark overrides since they don't use Tailwind utility classes. */
html.dark .site-nav {
    background-color: rgba(11, 18, 32, 0.9);
}

html.dark .badge-gba,
html.dark .badge-east,
html.dark .badge-north,
html.dark .badge-inland,
html.dark .badge-hainan,
html.dark .badge-southwest {
    /* Badges already use white text on saturated backgrounds; keep as-is
       for contrast, just slightly dim the backgrounds so they don't glow. */
    filter: brightness(0.9);
}

html.dark .step-flow-node {
    background: #0f1a2e;
    border-color: #059669;
    color: #6ee7b7;
}

html.dark .step-flow-node:hover {
    background: #10331f;
}

html.dark .step-flow-header {
    color: #94a3b8;
    border-color: #29394f;
    background: #0f1a2e;
}

html.dark .step-flow-list {
    border-color: #29394f;
    background: #131d30;
}

html.dark .step-flow-row:not(:last-child) {
    border-bottom-color: #1e293b;
}

html.dark .step-flow-title {
    color: #e2e8f0;
}

html.dark .step-flow-money {
    background: rgba(16, 185, 129, 0.08);
    border-color: rgba(16, 185, 129, 0.25);
}

html.dark .step-flow-money-text {
    color: #cbd5e1;
}

@media (min-width: 768px) {
    html.dark .step-flow-money {
        background: linear-gradient(135deg, rgba(16, 185, 129, 0.12) 0%, rgba(19, 29, 48, 0) 100%);
        border-left-color: rgba(16, 185, 129, 0.25);
    }
}

html.dark details.wfoe-details > summary.step-flow-more {
    color: #6ee7b7;
}

html.dark details.wfoe-details > summary.step-flow-more:hover {
    color: #34d399;
    background: rgba(16, 185, 129, 0.12);
}

html.dark .fx-info-trigger {
    color: #64748b;
}

html.dark .fx-info-trigger:hover,
html.dark .fx-info-trigger:focus-visible {
    color: #94a3b8;
}

html.dark .fx-info-trigger::after {
    border-color: #0b1220;
}

html.dark .fx-status-chip.fx-live {
    color: #6ee7b7;
    background: rgba(16, 185, 129, 0.15);
}

html.dark .fx-status-chip.fx-fallback {
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.15);
}

html.dark .fx-status-chip.fx-pending {
    color: #94a3b8;
    background: rgba(148, 163, 184, 0.15);
}

/* Theme-toggle icon swap: moon shown in light mode (click to go dark),
   sun shown in dark mode (click to go light) — animated SVG, unified with QROST home. */
#theme-toggle .sun-icon,
#theme-toggle .moon-icon { transition: opacity 0.25s, transform 0.3s; }
html.dark #theme-toggle .sun-icon  { opacity: 1; transform: rotate(0deg) scale(1); }
html.dark #theme-toggle .moon-icon { opacity: 0; transform: rotate(-90deg) scale(0.6); }
#theme-toggle .sun-icon  { opacity: 0; transform: rotate(90deg) scale(0.6); }
#theme-toggle .moon-icon { opacity: 1; transform: rotate(0deg) scale(1); }
