:root {
    --bg-main: #F4F5F7;
    --bg-gradient-end: #E2E5EC;
    --bg-card: #FFFFFF;
    --border: #DCDFE6;
    --text-main: #1F2329;
    --text-muted: #606266;
    --text-header: #111111;
    --accent: #D93838;
    --accent-hover: #B82323;
    --emerald: #0D8A58;
    --emerald-hover: #086B43;
}

body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: linear-gradient(180deg, var(--bg-main) 0%, var(--bg-gradient-end) 100%);
    background-attachment: fixed;
    color: var(--text-main);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    font-size: 0.95rem;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

header {
    border-bottom: 1px solid var(--border);
    padding: 1.2rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 50;
}

.logo {
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.logo span {
    color: #FFFFFF !important;
    background-color: var(--text-header);
    padding: 0.15rem 0.4rem;
    border-radius: 0.25rem;
    margin-right: 0.3rem;
    font-size: 0.95rem;
}

.logo a {
    text-decoration: none;
    color: var(--accent) !important;
}

.nav-buttons {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.back-btn-nav {
    display: none !important;
}

.index-buttons-nav {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.nav-link-analysis {
    color: var(--accent);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border: 1px dashed rgba(217, 56, 56, 0.4);
    border-radius: 0.375rem;
    transition: all 0.2s;
}

.nav-link-analysis:hover {
    background-color: rgba(217, 56, 56, 0.05);
    box-shadow: 0 0 8px rgba(217, 56, 56, 0.15);
}

.tooltip-wrapper {
    position: relative;
    display: inline-block;
}

.btn {
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background-color: var(--emerald);
    color: white;
    border: none;
}

.btn-primary:hover {
    background-color: var(--emerald-hover);
    box-shadow: 0 0 12px rgba(13, 138, 88, 0.3);
}

.tooltip-card {
    visibility: hidden;
    opacity: 0;
    width: 260px;
    background-color: #222222;
    color: #EFEFEF;
    text-align: left;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    position: absolute;
    z-index: 100;
    right: 0;
    top: 125%;
    font-size: 0.8rem;
    line-height: 1.4;
    font-weight: 400;
    border: 1px solid #444444;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    transition: opacity 0.2s ease, visibility 0.2s ease;
    white-space: normal;
}

.tooltip-card strong {
    color: #00A86B;
    display: block;
    margin-bottom: 0.25rem;
    font-size: 0.85rem;
}

.tooltip-wrapper:hover .tooltip-card {
    visibility: visible;
    opacity: 1;
}

main {
    max-width: 1140px;
    margin: 1.5rem auto;
    padding: 0 1.5rem;
}

.hero {
    text-align: center;
    margin-bottom: 1.5rem;
}

.hero h1 {
    font-size: 2.75rem;
    font-weight: 800;
    margin-bottom: 1rem;
    letter-spacing: -0.025em;
}

.hero p {
    color: var(--text-muted);
    font-size: 1.15rem;
    max-width: 850px;
    margin: 0 auto 1.5rem auto;
    line-height: 1.6;
}

.hero p strong {
    color: #000000;
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
    max-width: 750px;
    margin-left: auto;
    margin-right: auto;
}

.kpi-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    padding: 1rem;
    border-radius: 0.75rem;
    text-align: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.kpi-value {
    font-size: 1.85rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 0.25rem;
}

.kpi-label {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
}

.macro-chart-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    padding: 1.25rem;
    border-radius: 0.75rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    position: relative;
}

.chart-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
    flex-wrap: wrap;
}

.chart-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-header);
    letter-spacing: -0.02em;
}

.live-rate-badge {
    background-color: rgba(217, 56, 56, 0.1);
    color: var(--accent);
    font-weight: 700;
    font-size: 0.85rem;
    padding: 0.25rem 0.7rem;
    border-radius: 2rem;
    border: 1px solid rgba(217, 56, 56, 0.15);
    margin-left: auto;
}

.chart-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.chart-subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.4;
}

.timeframe-filters {
    display: flex;
    gap: 0.35rem;
}

.filter-btn {
    background: #EFEFEF;
    border: 1px solid var(--border);
    padding: 0.25rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 0.25rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.15s ease;
}

.filter-btn.active, .filter-btn:hover {
    background-color: var(--text-header);
    color: #FFFFFF;
    border-color: var(--text-header);
}

.canvas-container {
    position: relative;
    width: 100%;
    height: 180px;
    background-color: rgba(0, 0, 0, 0.005);
    border-radius: 0.375rem;
}

.chart-loader-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 5;
    border-radius: 0.375rem;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.minimal-spinner {
    width: 24px;
    height: 24px;
    border: 2.5px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin-overlay 0.8s linear infinite;
}

@keyframes spin-overlay {
    to {
        transform: rotate(360deg);
    }
}

canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
    cursor: crosshair;
}

.chart-interactive-tooltip {
    position: absolute;
    background: #111111;
    color: #FFFFFF;
    padding: 0.4rem 0.65rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 0.25rem;
    pointer-events: none;
    opacity: 0;
    z-index: 10;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
    white-space: nowrap;
    transform: translate(-50%, -120%);
    transition: opacity 0.1s ease;
    border: 1px solid #444444;
}

.pulse-dot {
    width: 9px;
    height: 9px;
    background-color: var(--accent);
    border-radius: 50%;
    display: inline-block;
    animation: alert-pulse 1.8s infinite;
}

@keyframes alert-pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(217, 56, 56, 0.4);
    }
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 6px rgba(217, 56, 56, 0);
    }
    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(217, 56, 56, 0);
    }
}

.filter-section {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    padding: 1.25rem;
    border-radius: 0.75rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    width: 100%;
    box-sizing: border-box;
}

.filter-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.search-box {
    width: 100%;
    max-width: 400px;
    padding: 0.65rem 1rem;
    background-color: #FFFFFF;
    border: 1px solid var(--border);
    border-radius: 0.375rem;
    color: var(--text-main);
    font-size: 0.9rem;
    box-sizing: border-box;
}

.search-box:focus {
    outline: 1px solid var(--accent);
}

.table-container {
    background-color: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    overflow-x: auto;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    max-height: 700px;
    overflow-y: auto;
    width: 100%;
    box-sizing: border-box;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.95rem;
    table-layout: fixed;
}

th {
    position: sticky;
    top: 0;
    z-index: 20; /* Keeps the header above the scrolling rows */
    background-color: var(--bg-card); /* Solid background so text doesn't bleed through */
    padding: 1.25rem 1rem;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
    letter-spacing: 0.03em;
    user-select: none;
    box-shadow: 0 1px 0 var(--border); /* Ensures the bottom border stays visible while scrolling */
}

th:not(:last-child)::after {
    content: "";
    position: absolute;
    right: 0;
    top: 25%;
    height: 50%;
    width: 1px;
    background-color: rgba(0, 0, 0, 0.12);
}

.resizer {
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    cursor: col-resize;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    height: 100%;
    z-index: 10;
}

.resizer:hover, .resizer.resizing {
    border-right: 2px solid var(--accent);
}

th.sortable {
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

th.sortable:hover {
    color: var(--text-main);
    background-color: rgba(0, 0, 0, 0.05);
}

th.sortable-left-indicator {
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

th.sortable-left-indicator:hover {
    color: var(--text-main);
    background-color: rgba(0, 0, 0, 0.05);
}

.header-sort-flex {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    width: 100%;
    justify-content: flex-end;
}

th, td {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    box-sizing: border-box;
}

th.col-reason, td.col-reason {
    white-space: normal;
}

.company-name {
    font-weight: 600;
    color: var(--text-main);
}

/* Vertical stack inside Company column */
.company-cell-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
    line-height: 1.2;
}

.company-title-text {
    font-weight: 600;
    color: var(--text-main);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* Secondary Source Link below Company name */
.company-source-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.725rem;
    font-weight: 500;
    color: var(--accent);
    text-decoration: none;
    opacity: 0.85;
    transition: opacity 0.15s ease, text-decoration 0.15s ease;
}

.company-source-link:hover {
    opacity: 1;
    text-decoration: underline;
}

.company-source-link svg {
    flex-shrink: 0;
}

.reason-badge {
    background-color: rgba(217, 56, 56, 0.1);
    color: var(--accent);
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid rgba(217, 56, 56, 0.15);
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    box-sizing: border-box;
}

.text-right {
    text-align: right;
}

.section-divider {
    border: 0;
    height: 1px;
    background-color: var(--border);
    margin: 3rem 0 2rem 0;
}

.faq-section-wrapper {
    background-color: #FFFFFF;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 2rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.03);
    margin-bottom: 2.5rem;
}

.faq-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-header);
    margin-top: 0;
    margin-bottom: 1.5rem;
    letter-spacing: -0.02em;
}

.faq-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.faq-item {
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background-color: #FAFAFA;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.faq-item[open] {
    border-color: rgba(217, 56, 56, 0.4);
    background-color: #FFFFFF;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.faq-item summary {
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    color: var(--text-main);
    padding: 1rem 1.25rem;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

.faq-item summary::-webkit-details-marker {
    display: none;
}

.faq-item summary::after {
    content: "↓";
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-muted);
    transition: transform 0.2s ease, color 0.2s ease;
}

.faq-item[open] summary::after {
    transform: rotate(180deg);
    color: var(--accent);
}

.faq-answer {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
    padding: 0 1.25rem 1.25rem 1.25rem;
    margin: 0;
    border-top: 1px dashed #EFEFEF;
    padding-top: 0.75rem;
}

.faq-answer a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    margin-left: 0.25rem;
}

.faq-answer a:hover {
    text-decoration: underline;
}

/* Global Footer Styles */
footer {
    width: 100%;
    background-color: #FFFFFF;
    border-top: 1px solid var(--border);
    padding: 2rem 0;
    margin-top: 4rem;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.02);
}

.footer-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1.5rem;
    box-sizing: border-box;
}

.footer-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.4rem;
}

.footer-badge {
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-size: 0.85rem;
    font-weight: 700;
    color: #FFFFFF;
    background-color: var(--text-header);
    padding: 0.2rem 0.5rem;
    border-radius: 0.25rem;
}

.footer-domain {
    font-weight: 700;
    color: var(--text-header);
    font-size: 0.95rem;
}

.footer-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.4;
}

.footer-links {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 600;
    transition: color 0.15s ease;
}

.footer-links a:hover {
    color: var(--accent);
}

/* Apply modern font to the table and the exchange rate card */
.table-container,
.macro-chart-card {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* Make Company Name explicitly Bold and dark */
.company-title-text {
    font-weight: 700;
    color: #111827; /* Dark, crisp slate color */
    font-size: 0.95rem;
}

/* Optional: Make the table headers slightly more modern */
.table-container th {
    font-weight: 600;
    color: #4b5563;
}

/* ==========================================================================
   Layout Stability (Core Web Vitals - CLS Fixes)
   ========================================================================== */
#global-header {
    min-height: 50px; /* Reserves space for the dynamically injected navbar */
}

.table-container {
    min-height: 450px; /* Prevents the FAQ from jumping up before table rows render */
}

/* Ensure the chart container maintains space before the canvas initializes */
.canvas-container {
    min-height: 180px;
}

/* Responsive Rules */
@media (max-width: 600px) {
    /* 1. Global Scale Down & Aggressive Margins */
    html {
        font-size: 14px;
    }

    /* ADD THIS: Override the CLS reservation for smaller screens */
    #global-header {
       min-height: 30px;
    }

    main {
        margin: 1rem auto;
    }

    /* 2. Shrink Hero & Hide Paragraph for Vertical Space */
    .hero {
        margin-bottom: 1rem;
    }

    .hero h1 {
        font-size: 1.6rem;
        margin-bottom: 0.25rem;
    }

    .hero p {
        font-size: 0.825rem;
        line-height: 1.45;
        margin-top: 0.5rem;
    }

    .hero-desktop-more {
            display: none;
    }

    /* 3. Ultra-Compact Side-by-Side KPI Grid */
    .kpi-grid {
        display: flex;
        flex-direction: row;
        gap: 0.5rem;
        margin-bottom: 1rem;
    }

    .kpi-card {
        padding: 0.5rem;
        flex: 1;
    }

    .kpi-value {
        font-size: 1.25rem;
    }

    .kpi-label {
        font-size: 0.75rem;
    }

    /* 4. Compact the USD/JPY Card */
    .macro-chart-card {
        padding: 0.75rem;
        margin-bottom: 1rem;
    }

    .chart-header h2 {
        font-size: 0.95rem;
    }

    .canvas-container {
        height: 100px !important; /* Extremely flat chart for mobile */
        min-height: 100px; /* Overrides the 180px desktop reservation */
    }

    /* Override the 450px desktop table reservation for smaller mobile rows */
    .table-container {
       min-height: 200px;
    }

    .live-rate-badge {
        margin-left: 0;
        width: 100%;
        text-align: center;
        box-sizing: border-box;
    }

    .chart-controls {
        flex-direction: column;
        align-items: flex-start;
    }

    .timeframe-filters {
        width: 100%;
    }

    .filter-btn {
        flex: 1;
        text-align: center;
    }

    /* 5. Tighter Search Section */
    .filter-section {
        padding: 0.75rem;
        margin-bottom: 1rem;
    }

    .filter-title {
        margin-bottom: 0.25rem;
        font-size: 0.9rem;
    }

    /* 6. Table Column Adjustments */
    .col-desktop-only {
        display: none !important;
    }

    table {
        table-layout: fixed;
    }

    /* Allow headers to wrap into multiple lines to save horizontal space */
    th {
        white-space: normal !important;
        line-height: 1.2;
        padding: 0.6rem 0.4rem !important;
        font-size: 0.8rem;
    }

    /* Increase row height with taller vertical padding */
    td {
        padding: 1.1rem 0.4rem !important;
        font-size: 0.85rem;
    }

    tr {
        -webkit-tap-highlight-color: rgba(217, 56, 56, 0.1);
    }

    td:active, td.cell-active {
        background-color: rgba(0, 0, 0, 0.04);
    }

    /* Force specific narrow widths on mobile to fit 4 columns on a ~345px screen */
    th:nth-child(1), td:nth-child(1) { width: 95px !important; }  /* Company Name */
    th:nth-child(5), td:nth-child(5) { width: 75px !important; }  /* Current Headcount */
    th:nth-child(6), td:nth-child(6) { width: 90px !important; }  /* % Reduction */
    th:nth-child(7), td:nth-child(7) { width: 85px !important; }  /* Newly Impacted Roles */
    th:nth-child(8), td:nth-child(8) { width: 85px !important; }  /* Date (Scrolls off-screen) */

    /* 7. Compact FAQ & Footer */
    .faq-section-wrapper {
        padding: 1.25rem;
    }

    .faq-item summary {
        padding: 0.85rem 1rem;
        font-size: 0.875rem;
    }

    .faq-answer {
        padding: 0.75rem 1rem 1rem 1rem;
        font-size: 0.85rem;
    }

    footer {
        padding: 1.75rem 0;
    }

    .footer-container {
        flex-direction: column;
        align-items: flex-start;
        gap: 1.25rem;
    }

    .footer-links {
        width: 100%;
        border-top: 1px solid #EFEFEF;
        padding-top: 1rem;
        gap: 1.25rem;
    }
    /* 1. Maximize horizontal space in the header */
    header {
        padding: 0.75rem 0.5rem;
    }

    /* 2. Slightly shrink the logo to make room */
    .logo {
        font-size: 0.95rem;
    }

    .logo span {
        font-size: 0.85rem;
        padding: 0.1rem 0.3rem;
    }

    /* 3. Tightly group the buttons on the right */
    .index-buttons-nav, .nav-buttons {
        gap: 0.35rem;
    }

    /* 4. Aggressively shrink button padding and font size so they fit */
    .nav-link-analysis, .btn {
        padding: 0.35rem 0.4rem;
        font-size: 0.7rem;
        line-height: 1.2;
        text-align: center;
    }
}