/* ── Reset & Base ────────────────────────────────── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-primary: #4f46e5;
    --color-primary-light: #eef2ff;
    --color-primary-hover: #4338ca;
    --color-accent: #06b6d4;
    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-text-muted: #94a3b8;
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-border-hover: #cbd5e1;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.08);
    --transition: 0.2s ease;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-bg);
    min-height: 100vh;
    color: var(--color-text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ── Layout Container ───────────────────────────── */
.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--color-surface);
    min-height: 100vh;
    border-left: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
}

/* ── Header ─────────────────────────────────────── */
header {
    padding: 32px 40px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
}

header h1 {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--color-text);
    letter-spacing: -0.02em;
}

.subtitle {
    color: var(--color-text-secondary);
    font-size: 0.95em;
    margin-top: 4px;
    font-weight: 400;
}

/* ── Industry Selection Step ────────────────────── */
.industry-selection {
    padding: 40px;
}

.industry-selection-header {
    text-align: center;
    margin-bottom: 36px;
}

.industry-selection-header h2 {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 8px;
    letter-spacing: -0.02em;
}

.industry-selection-header p {
    color: var(--color-text-secondary);
    font-size: 0.95em;
    max-width: 520px;
    margin: 0 auto 24px;
    line-height: 1.6;
}

.industry-search-container {
    max-width: 380px;
    margin: 0 auto;
    position: relative;
}

.industry-search {
    width: 100%;
    padding: 10px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 0.9em;
    font-family: inherit;
    outline: none;
    background: var(--color-bg);
    color: var(--color-text);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.industry-search::placeholder {
    color: var(--color-text-muted);
}

.industry-search:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
    background: var(--color-surface);
}

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

.industry-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 20px;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    flex-direction: column;
}

.industry-card:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.industry-card-icon {
    font-size: 1.8em;
    margin-bottom: 8px;
    line-height: 1;
}

.industry-card-name {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 6px;
    line-height: 1.35;
}

.industry-card-desc {
    font-size: 0.8em;
    color: var(--color-text-secondary);
    line-height: 1.5;
    flex-grow: 1;
}

.industry-card-code {
    font-size: 0.7em;
    color: var(--color-text-muted);
    margin-top: 10px;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-weight: 500;
}

.no-results {
    text-align: center;
    color: var(--color-text-secondary);
    padding: 48px 20px;
    font-size: 0.95em;
}

/* ── Comparison View Navigation ─────────────────── */
.comparison-view-nav {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 40px;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
}

.back-btn {
    padding: 6px 14px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.85em;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--color-text-secondary);
}

.back-btn:hover {
    border-color: var(--color-border-hover);
    color: var(--color-text);
    background: var(--color-surface);
}

.selected-industry-label {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--color-text);
}

/* ── Controls ───────────────────────────────────── */
.controls {
    padding: 24px 40px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.province-selector,
.category-selector {
    margin-bottom: 20px;
}

.province-selector:last-child,
.category-selector:last-child {
    margin-bottom: 0;
}

.province-selector h3,
.category-selector h3 {
    margin-bottom: 12px;
    color: var(--color-text);
    font-size: 0.85em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
}

.province-checkbox {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.province-checkbox:hover {
    border-color: var(--color-border-hover);
    background: var(--color-surface);
}

.province-checkbox input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
}

.province-checkbox label {
    cursor: pointer;
    font-weight: 500;
    font-size: 0.88em;
    user-select: none;
    color: var(--color-text);
}

.button-group {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* ── Category tabs (underline style) ────────────────────── */
.category-tabs {
    display: flex;
    border-bottom: 2px solid var(--color-border);
    margin-bottom: 16px;
    gap: 0;
}

.category-btn {
    padding: 8px 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    border-radius: 0;
    font-size: 0.85em;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    color: var(--color-text-secondary);
    transition: color var(--transition), border-color var(--transition);
    white-space: nowrap;
}

.category-btn:hover {
    color: var(--color-text);
    border-bottom-color: var(--color-border-hover);
}

.category-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
    font-weight: 600;
}

/* ── Visualization Section ──────────────────────── */
.visualization-section {
    padding: 32px 40px;
    background: var(--color-bg);
}

.chart-container {
    background: var(--color-surface);
    padding: 24px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    border: 1px solid var(--color-border);
}

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

.chart-container canvas {
    max-height: 360px;
}

.comparison-table-container {
    background: var(--color-surface);
    padding: 24px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    overflow-x: auto;
}

.comparison-table-container h3 {
    margin-bottom: 16px;
    color: var(--color-text);
    font-size: 0.95em;
    font-weight: 600;
}

/* ── Comparison Table ───────────────────────────── */
.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88em;
}

.comparison-table th {
    background: var(--color-bg);
    color: var(--color-text);
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 2px solid var(--color-border);
}

.comparison-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
    vertical-align: top;
}

.comparison-table tr:last-child td {
    border-bottom: none;
}

.comparison-table tr:hover td {
    background: var(--color-primary-light);
}

/* ── Info Cards ─────────────────────────────────── */
.info-cards {
    padding: 32px 40px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
}

.info-card {
    background: var(--color-bg);
    padding: 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.info-card h4 {
    color: var(--color-text);
    margin-bottom: 8px;
    font-size: 0.95em;
    font-weight: 600;
}

.info-card p {
    color: var(--color-text-secondary);
    line-height: 1.6;
    font-size: 0.88em;
}

.info-card ul {
    margin-top: 8px;
    padding-left: 18px;
}

.info-card li {
    margin: 4px 0;
    color: var(--color-text);
    font-size: 0.88em;
}

/* ── Footer ─────────────────────────────────────── */
footer {
    background: var(--color-bg);
    border-top: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    padding: 20px 40px;
    font-size: 0.82em;
}

footer p {
    margin: 3px 0;
}

footer strong {
    color: var(--color-text);
    font-weight: 600;
}

.data-note {
    font-size: 0.9em;
    color: var(--color-text-muted);
}

/* ── Utility ────────────────────────────────────── */
.highlight-value {
    font-weight: 600;
    color: var(--color-primary);
}

.source-link {
    display: block;
    font-size: 0.75em;
    color: var(--color-text-muted);
    text-decoration: none;
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
    transition: color var(--transition);
}

.source-link:hover {
    color: var(--color-primary);
}

/* ── Source status chips (inline in comparison table) ───────*/
.source-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    margin-left: 0.35rem;
    white-space: nowrap;
    vertical-align: middle;
    cursor: default;
    letter-spacing: 0.01em;
    line-height: 1.6;
}
.chip-ok      { background: #f0fdf4; color: #15803d; }
.chip-changed { background: #fff7ed; color: #c2410c; }
.chip-error   { background: #fef2f2; color: #dc2626; }
.chip-new     { background: #f1f5f9; color: #64748b; }

/* ── Accessibility helper ───────────────────────────────── */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── App bar (sticky top bar in comparison view) ─────────── */
.app-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    min-height: 53px;
}

/* Hide the page header when comparison view is active */
body.comparison-active header {
    display: none;
}

/* ── Comparison layout ───────────────────────────────────── */
.comparison-layout {
    display: flex;
    align-items: flex-start;
}

/* ── Province sidebar ────────────────────────────────────── */
.province-sidebar {
    width: 200px;
    flex-shrink: 0;
    position: sticky;
    top: 53px;
    max-height: calc(100vh - 53px);
    overflow-y: auto;
    border-right: 1px solid var(--color-border);
    background: var(--color-bg);
    padding: 16px 0;
}

.sidebar-heading {
    font-size: 0.68em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--color-text-muted);
    padding: 0 16px 10px;
}

/* ── Province toggle items ───────────────────────────────── */
.province-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 16px;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background var(--transition), border-color var(--transition);
    user-select: none;
}

.province-toggle:hover {
    background: var(--color-surface);
}

.province-toggle.selected {
    border-left-color: var(--color-primary);
    background: var(--color-primary-light);
}

.toggle-dot {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: 2px solid var(--color-border-hover);
    flex-shrink: 0;
    transition: background var(--transition), border-color var(--transition);
}

.province-toggle.selected .toggle-dot {
    background: var(--color-primary);
    border-color: var(--color-primary);
}

.toggle-labels {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.toggle-code {
    font-size: 0.8em;
    font-weight: 700;
    color: var(--color-text);
    line-height: 1.2;
}

.province-toggle.selected .toggle-code {
    color: var(--color-primary);
}

.toggle-name {
    font-size: 0.68em;
    color: var(--color-text-muted);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 130px;
}

/* ── Comparison main area ────────────────────────────────── */
.comparison-main {
    flex: 1;
    min-width: 0;
    padding: 20px;
}

/* ── Chart section ───────────────────────────────────────── */
.chart-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 16px;
}

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

.chart-section canvas {
    max-height: 280px;
}

/* ── Table section ───────────────────────────────────────── */
.table-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 16px;
    overflow-x: auto;
}

.table-section h3 {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 14px;
}

/* Info cards within main (remove top border override) */
.comparison-main .info-cards {
    padding: 0;
    border-top: none;
    margin-bottom: 8px;
}

/* ── Responsive ─────────────────────────────────── */
@media (max-width: 768px) {
    header {
        padding: 24px 20px;
    }

    header h1 {
        font-size: 1.25em;
    }

    .industry-selection {
        padding: 24px 16px;
    }

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

    .industry-selection-header h2 {
        font-size: 1.25em;
    }

    .controls {
        padding: 20px 16px;
    }

    .checkbox-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .button-group {
        flex-direction: column;
    }

    .category-btn {
        width: 100%;
    }

    .visualization-section {
        padding: 20px 16px;
    }

    .info-cards {
        grid-template-columns: 1fr;
        padding: 20px 16px;
    }

    footer {
        padding: 16px 20px;
    }

    /* Comparison layout: stack vertically on mobile */
    .comparison-layout {
        flex-direction: column;
    }

    .province-sidebar {
        width: 100%;
        position: static;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        padding: 12px 0;
        display: flex;
        flex-wrap: wrap;
        gap: 0;
    }

    .sidebar-heading {
        width: 100%;
        padding: 0 16px 8px;
    }

    .province-toggle {
        width: auto;
        flex-direction: row;
        padding: 6px 12px;
        border-left: none;
        border-bottom: 3px solid transparent;
    }

    .province-toggle.selected {
        border-left: none;
        border-bottom-color: var(--color-primary);
    }

    .toggle-name {
        display: none;
    }

    .comparison-main {
        padding: 12px;
    }

    .category-btn {
        padding: 7px 10px;
        font-size: 0.8em;
    }
}
