/* NihonRates — institutional reference UI
   Palettes are full visual systems (paper + ink + accent), high-contrast:
   saturated or stark surfaces — not accent tints on cream. */

:root {
    --layout-max-width: 1800px;
    /* Homepage reference rails. Below --rails-breakpoint the three-column layout
       would squeeze the main column past readability, so the rails collapse. Keep
       this in step with RAILS_BREAKPOINT_PX in static/js/site.js. */
    --news-rail-width: 20.5rem;

    --radius-control: 6px;
    --radius-section: 8px;
    --control-height: 2rem;
    --font-size-h1: 2rem;
    --font-size-h2: 1.375rem;
    --font-size-h3: 1.0625rem;
    --font-size-body: 0.9375rem;
    --font-size-small: 0.8125rem;
    --font-size-label: 0.6875rem;
    --site-header-height: 72px;

    /* ── A — Kinari: institutional slate (cool concrete, not cream) ── */
    --background: #e4e7ec;
    --surface: #f7f8fa;
    --text-primary: #0a0b0d;
    --text-secondary: #3c4452;
    --border-color: #c5cad3;
    --shadow: 0 1px 2px 0 rgba(10, 11, 13, 0.06);
    --shadow-lg: 0 4px 14px -2px rgba(10, 11, 13, 0.12);
    --danger-color: #b91c1c;
    --warning-color: #b45309;
    --link-visited: #5b21b6;

    --accent-header: #0a0b0d;
    --accent-section: #0a0b0d;
    --accent-tibor: #0a0b0d;
    --accent-tona: #334155;
    --accent-link: #0a0b0d;
    --accent-nav: #0a0b0d;
    --accent-positive: #166534;
    --accent-tab: #0a0b0d;
    --accent-banks: #334155;

    --primary-color: var(--accent-link);
    --primary-dark: #0a0b0d;
    --secondary-color: var(--accent-positive);
    --link-color: var(--accent-link);
}

/* A dark — slate void */
[data-theme="dark"] {
    --background: #0f172a;
    --surface: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 4px 14px -2px rgba(0, 0, 0, 0.45);
    --danger-color: #f87171;
    --warning-color: #fbbf24;
    --link-visited: #c4b5fd;

    --accent-header: #e2e8f0;
    --accent-section: #f1f5f9;
    --accent-tibor: #f1f5f9;
    --accent-tona: #94a3b8;
    --accent-link: #e2e8f0;
    --accent-nav: #e2e8f0;
    --accent-positive: #4ade80;
    --accent-tab: #e2e8f0;
    --accent-banks: #cbd5e1;

    --primary-color: var(--accent-link);
    --primary-dark: #f1f5f9;
    --secondary-color: var(--accent-positive);
    --link-color: var(--accent-link);
}

/* ── B — Aka: vermillion paper + lacquer brand + teal counterpoint ── */
[data-palette="aka"] {
    --background: #ff7a68;
    --surface: #ffc4ba;
    --text-primary: #140003;
    --text-secondary: #5c0a14;
    --border-color: #140003;
    --shadow: 0 0 0 1px #140003;
    --shadow-lg: 0 0 0 2px #140003, 0 8px 0 0 #140003;
    --danger-color: #7f1d1d;
    --warning-color: #9a3412;
    --link-visited: #5b21b6;

    --accent-header: #e10600;
    --accent-section: #140003;
    --accent-tibor: #e10600;
    --accent-tona: #0f766e;
    --accent-link: #140003;
    --accent-nav: #140003;
    --accent-positive: #0f766e;
    --accent-tab: #e10600;
    --accent-banks: #0f766e;

    --primary-color: var(--accent-link);
    --primary-dark: #140003;
    --secondary-color: var(--accent-positive);
    --link-color: var(--accent-link);
}
[data-theme="dark"][data-palette="aka"] {
    --background: #140003;
    --surface: #2a0008;
    --text-primary: #ffe8e4;
    --text-secondary: #ff9a8b;
    --border-color: #e10600;
    --shadow: 0 0 0 1px #e10600;
    --shadow-lg: 0 0 0 2px #e10600, 0 8px 0 0 #e10600;
    --danger-color: #fb7185;
    --warning-color: #fb923c;
    --link-visited: #e9d5ff;

    --accent-header: #ff2d2d;
    --accent-section: #ffe8e4;
    --accent-tibor: #ff2d2d;
    --accent-tona: #2dd4bf;
    --accent-link: #ff6b6b;
    --accent-nav: #ff2d2d;
    --accent-positive: #2dd4bf;
    --accent-tab: #ff2d2d;
    --accent-banks: #2dd4bf;

    --primary-color: var(--accent-link);
    --primary-dark: #ffe8e4;
    --secondary-color: var(--accent-positive);
    --link-color: var(--accent-link);
}

/* ── C — Sumi: indigo wash + copper seal (cool paper, hot brand) ── */
[data-palette="sumi"] {
    --background: #8fa6e8;
    --surface: #d4dff8;
    --text-primary: #060a18;
    --text-secondary: #1a2754;
    --border-color: #060a18;
    --shadow: 0 0 0 1px #060a18;
    --shadow-lg: 0 0 0 2px #060a18, 0 8px 0 0 #060a18;
    --danger-color: #be123c;
    --warning-color: #c2410c;
    --link-visited: #5b21b6;

    --accent-header: #ea580c;
    --accent-section: #060a18;
    --accent-tibor: #060a18;
    --accent-tona: #ea580c;
    --accent-link: #060a18;
    --accent-nav: #060a18;
    --accent-positive: #0f766e;
    --accent-tab: #ea580c;
    --accent-banks: #ea580c;

    --primary-color: var(--accent-link);
    --primary-dark: #060a18;
    --secondary-color: var(--accent-positive);
    --link-color: var(--accent-link);
}
[data-theme="dark"][data-palette="sumi"] {
    --background: #060a18;
    --surface: #0f1733;
    --text-primary: #e8eeff;
    --text-secondary: #a8b8e8;
    --border-color: #ea580c;
    --shadow: 0 0 0 1px #ea580c;
    --shadow-lg: 0 0 0 2px #ea580c, 0 8px 0 0 #ea580c;
    --danger-color: #fb7185;
    --warning-color: #fb923c;
    --link-visited: #c4b5fd;

    --accent-header: #fb923c;
    --accent-section: #e8eeff;
    --accent-tibor: #e8eeff;
    --accent-tona: #fb923c;
    --accent-link: #fb923c;
    --accent-nav: #fb923c;
    --accent-positive: #2dd4bf;
    --accent-tab: #fb923c;
    --accent-banks: #fdba74;

    --primary-color: var(--accent-link);
    --primary-dark: #e8eeff;
    --secondary-color: var(--accent-positive);
    --link-color: var(--accent-link);
}

/* ── D — Matsu: STARK MONO + VOLT — pure B/W, acid-lime brand bar (arx D) ── */
[data-palette="matsu"] {
    --background: #ffffff;
    --surface: #ffffff;
    --text-primary: #000000;
    --text-secondary: #222222;
    --border-color: #000000;
    --shadow: 0 0 0 1px #000000;
    --shadow-lg: 0 0 0 2px #000000, 0 8px 0 0 #000000;
    --danger-color: #dc2626;
    --warning-color: #a3cc00;
    --link-visited: #444444;

    --accent-header: #ccff00;
    --accent-section: #000000;
    --accent-tibor: #000000;
    --accent-tona: #ccff00;
    --accent-link: #000000;
    --accent-nav: #000000;
    --accent-positive: #65a30d;
    --accent-tab: #000000;
    --accent-banks: #000000;

    --primary-color: var(--accent-link);
    --primary-dark: #000000;
    --secondary-color: var(--accent-positive);
    --link-color: var(--accent-link);
}
[data-theme="dark"][data-palette="matsu"] {
    --background: #000000;
    --surface: #0a0a0a;
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --border-color: #ccff00;
    --shadow: 0 0 0 1px #ccff00;
    --shadow-lg: 0 0 0 2px #ccff00, 0 8px 0 0 #ccff00;
    --danger-color: #ff4d4d;
    --warning-color: #ccff00;
    --link-visited: #a3e635;

    --accent-header: #ccff00;
    --accent-section: #ccff00;
    --accent-tibor: #ffffff;
    --accent-tona: #ccff00;
    --accent-link: #ccff00;
    --accent-nav: #ccff00;
    --accent-positive: #a3e635;
    --accent-tab: #ccff00;
    --accent-banks: #ccff00;

    --primary-color: var(--accent-link);
    --primary-dark: #ffffff;
    --secondary-color: var(--accent-positive);
    --link-color: var(--accent-link);
}

/* ── E — Kōhaku: festival red + pine on warm ivory (dual brand) ── */
[data-palette="kohaku"] {
    --background: #f0e6d4;
    --surface: #fffaf2;
    --text-primary: #0a0a0a;
    --text-secondary: #2a2a2a;
    --border-color: #0a0a0a;
    --shadow: 0 0 0 1px #0a0a0a;
    --shadow-lg: 0 0 0 2px #0a0a0a, 0 8px 0 0 #0a0a0a;
    --danger-color: #b91c1c;
    --warning-color: #a16207;
    --link-visited: #5b21b6;

    --accent-header: #c8102e;
    --accent-section: #0a0a0a;
    --accent-tibor: #1b7a3c;
    --accent-tona: #c8102e;
    --accent-link: #0a0a0a;
    --accent-nav: #1b7a3c;
    --accent-positive: #1b7a3c;
    --accent-tab: #1b7a3c;
    --accent-banks: #c8102e;

    --primary-color: var(--accent-link);
    --primary-dark: #0a0a0a;
    --secondary-color: var(--accent-positive);
    --link-color: var(--accent-link);
}
[data-theme="dark"][data-palette="kohaku"] {
    --background: #0a0a0a;
    --surface: #141414;
    --text-primary: #f5f0e8;
    --text-secondary: #c4b8a8;
    --border-color: #c8102e;
    --shadow: 0 0 0 1px #c8102e;
    --shadow-lg: 0 0 0 2px #c8102e, 0 8px 0 0 #1b7a3c;
    --danger-color: #fb7185;
    --warning-color: #fbbf24;
    --link-visited: #c4b5fd;

    --accent-header: #ff4d6d;
    --accent-section: #f5f0e8;
    --accent-tibor: #4ade80;
    --accent-tona: #ff4d6d;
    --accent-link: #f5f0e8;
    --accent-nav: #4ade80;
    --accent-positive: #4ade80;
    --accent-tab: #4ade80;
    --accent-banks: #ff4d6d;

    --primary-color: var(--accent-link);
    --primary-dark: #f5f0e8;
    --secondary-color: var(--accent-positive);
    --link-color: var(--accent-link);
}

/* Brand bars + selection — same hard commitment as A/D */
[data-palette="aka"] .site-header {
    border-bottom: 6px solid #e10600;
    box-shadow: inset 0 -10px 0 0 #0f766e;
}
[data-theme="dark"][data-palette="aka"] .site-header {
    box-shadow: inset 0 -10px 0 0 #2dd4bf;
}
[data-palette="sumi"] .site-header {
    border-bottom: 6px solid #ea580c;
    box-shadow: inset 0 -10px 0 0 #060a18;
}
[data-theme="dark"][data-palette="sumi"] .site-header {
    box-shadow: inset 0 -10px 0 0 #fb923c;
}
[data-palette="matsu"] .site-header {
    border-bottom: 6px solid #ccff00;
    box-shadow: inset 0 -10px 0 0 #000000;
}
[data-theme="dark"][data-palette="matsu"] .site-header {
    box-shadow: inset 0 -10px 0 0 #ccff00;
}
[data-palette="kohaku"] .site-header {
    border-bottom: none;
    box-shadow: inset 0 -5px 0 0 #c8102e, inset 0 -10px 0 0 #1b7a3c;
}
[data-theme="dark"][data-palette="kohaku"] .site-header {
    box-shadow: inset 0 -5px 0 0 #ff4d6d, inset 0 -10px 0 0 #4ade80;
}

[data-palette="aka"] ::selection {
    background: #e10600;
    color: #ffffff;
}
[data-palette="sumi"] ::selection {
    background: #ea580c;
    color: #ffffff;
}
[data-palette="matsu"] ::selection {
    background: #ccff00;
    color: #000000;
}
[data-palette="kohaku"] ::selection {
    background: #c8102e;
    color: #ffffff;
}

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

/* The horizontal-overflow guard belongs here and only here. Repeating it on
   `body` makes body a scroll container, and a scroll container that never
   scrolls: every `position: sticky` descendant then measures against body
   instead of the viewport and silently stops sticking. On `html` alone the
   value propagates to the viewport and sticky keeps working. */
html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    font-family: 'Vend Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: var(--font-size-body);
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.55;
    transition: background-color 0.3s ease, color 0.3s ease;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-variant-numeric: tabular-nums;
    padding-top: var(--site-header-height);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--link-color);
    text-decoration: none;
    font-weight: 500;
}

a:hover {
    text-decoration: underline;
}

[data-theme="dark"] a:visited {
    color: var(--link-visited);
}

/* Improved focus states for accessibility */
*:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Remove focus outline for mouse users, keep for keyboard */
*:focus:not(:focus-visible) {
    outline: none;
}

.container {
    max-width: var(--layout-max-width);
    margin: 0 auto;
    padding: 20px 24px;
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
}

.page-wrapper {
    flex: 1 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
}

/* Footer lives inside the wrapper, so the wrapper has to push it down when
   content is shorter than the viewport. Without this, flex growth on the
   wrapper leaves empty space under the footer. */
.page-wrapper > footer {
    margin-top: auto;
}

/* Homepage: let the updates section claim leftover height above the footer.
   Container / layout / main only stretch when the updates block is present,
   so other pages keep the plain sticky-footer behaviour. */
.page-wrapper > .container:has(.latest-updates) {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.page-main {
    width: 100%;
}

/* Fixed site header */
.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 100;
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--surface);
    border-bottom: 4px solid var(--accent-header);
    box-shadow: var(--shadow);
    color: var(--text-primary);
}

.site-header__inner {
    max-width: var(--layout-max-width);
    margin: 0 auto;
    padding: 10px 24px;
    padding-left: max(24px, env(safe-area-inset-left));
    padding-right: max(24px, env(safe-area-inset-right));
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    column-gap: 16px;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: inherit;
}

.header-brand:hover,
.header-brand:visited {
    text-decoration: none;
    color: var(--text-primary);
}

.header-brand .header-title {
    color: inherit;
}

.header-logo {
    height: 40px;
    width: 40px;
    flex-shrink: 0;
    object-fit: contain;
}

.header-content {
    min-width: 0;
    text-align: left;
}

.header-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 20px;
    margin-right: 4px;
}

.site-nav__link {
    color: var(--text-secondary);
    font-size: var(--font-size-small);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.site-nav__link:hover {
    color: var(--accent-nav);
    text-decoration: none;
}

.site-nav__link[aria-current="page"] {
    color: var(--accent-nav);
    font-weight: 700;
}

/* About dropdown: the label itself navigates, the chevron opens the menu. */
.site-nav__group {
    position: relative;
    display: flex;
    align-items: center;
    gap: 3px;
}

.site-nav__disclosure {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    font: inherit;
}

.site-nav__disclosure svg {
    width: 10px;
    height: 10px;
    transition: transform 0.18s ease;
}

.site-nav__disclosure:hover {
    color: var(--accent-nav);
}

.site-nav__disclosure[aria-expanded="true"] {
    color: var(--accent-nav);
}

.site-nav__disclosure[aria-expanded="true"] svg {
    transform: rotate(180deg);
}

.site-nav__menu {
    position: absolute;
    top: calc(100% + 12px);
    right: 0;
    z-index: 120;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 9rem;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    box-shadow: var(--shadow-lg);
    animation: nav-menu-in 0.16s ease;
}

.site-nav__menu[hidden] {
    display: none;
}

@keyframes nav-menu-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
}

.site-nav__menu-link {
    padding: 7px 10px;
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: var(--font-size-small);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.site-nav__menu-link:hover {
    background: var(--background);
    color: var(--accent-nav);
    text-decoration: none;
}

.site-nav__menu-link[aria-current="page"] {
    color: var(--accent-nav);
    font-weight: 700;
}

.header-title,
.header-content h1 {
    font-size: 1.375rem;
    font-weight: 700;
    margin: 0 0 2px;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.site-header .subtitle {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.subtitle {
    font-size: var(--font-size-small);
    color: var(--text-secondary);
    line-height: 1.4;
}

.btn-login {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: var(--control-height);
    padding: 0 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    background: var(--background);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--font-size-small);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.btn-login[hidden] {
    display: none !important;
}

@media (hover: hover) {
    .btn-login:hover {
        border-color: var(--primary-color);
        color: var(--primary-color);
        text-decoration: none;
    }
}

/* Theme toggle */
.theme-toggle {
    background-color: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    padding: 6px 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: border-color 0.2s ease, color 0.2s ease;
    color: var(--text-primary);
    font-size: var(--font-size-small);
    font-weight: 600;
    font-family: inherit;
}

.theme-toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
}

.theme-toggle-icon svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

@media (hover: hover) and (pointer: fine) {
    .theme-toggle:hover {
        border-color: var(--primary-color);
        color: var(--primary-color);
    }
}

/* Touch devices: prevent sticky :hover transforms after tap */
@media (hover: none), (pointer: coarse) {
    .theme-toggle,
    .theme-toggle .theme-toggle-icon {
        transform: none !important;
    }
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-control);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background-color: white;
    color: var(--primary-color);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-icon {
    font-size: 1.2rem;
    display: inline-block;
    transition: transform 0.3s;
}

.btn-primary:hover .btn-icon {
    transform: rotate(180deg);
}

/* Info Banner */
.info-banner {
    background-color: #dbeafe;
    border-left: 4px solid var(--primary-color);
    padding: 20px;
    margin-bottom: 30px;
    border-radius: 8px;
}

[data-theme="dark"] .info-banner {
    background-color: #1e3a5f;
    border-left-color: var(--primary-color);
    color: var(--text-primary);
}

.info-banner p {
    margin-bottom: 10px;
    color: var(--text-primary);
}

.info-banner p:last-child {
    margin-bottom: 0;
}

.info-note {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.info-banner a {
    color: var(--link-color);
    text-decoration: none;
    font-weight: 600;
}

.info-banner a:hover {
    text-decoration: underline;
}

/* Stats strip (embedded under current rates table) */
.stats-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 0;
    font-variant-numeric: tabular-nums;
}

.stats-strip-item {
    flex: 1 1 140px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: 10px 14px;
    min-width: 0;
}

.stats-strip-item--wide {
    flex: 2 1 200px;
}

.stats-strip-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
}

.stats-strip-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent-section);
    line-height: 1.2;
}

.stats-strip-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.2;
}

.stats-strip-divider {
    width: 1px;
    align-self: stretch;
    background: var(--border-color);
    flex-shrink: 0;
}

.stats-status-value {
    color: var(--accent-section);
    font-weight: 700;
}

.stats-status-value.is-active {
    color: var(--secondary-color);
}

.stats-status-value.is-error {
    color: var(--danger-color);
}

.stats-status-value.is-stopped {
    color: var(--text-secondary);
}

.footer-website-update {
    margin-top: 12px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.footer-website-update time {
    font-weight: 600;
    color: var(--text-primary);
}

/* Sections */
section,
.reference-banks-section {
    scroll-margin-top: calc(var(--site-header-height) + 12px);
}

section {
    background-color: var(--surface);
    padding: 24px;
    margin-bottom: 24px;
    border-radius: var(--radius-section);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    transition: background-color 0.3s ease;
}

section h2 {
    font-size: var(--font-size-h2);
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--accent-section);
    letter-spacing: -0.01em;
}

.banks-section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--accent-section);
}

.rate-date {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    font-weight: 500;
}

/* Current Rates: market table snapshot */
.current-rates-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px 16px;
    margin-bottom: 20px;
}

.current-rates-header h2 {
    margin-bottom: 0;
}

.rate-subsection {
    margin-top: 1.75rem;
    padding-left: 14px;
    border-left: 4px solid var(--accent-tibor);
}

.rate-subsection--tona {
    margin-top: 2.25rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
    border-left-color: var(--accent-tona);
}

.rate-subsection-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.rate-subsection-title {
    display: block;
    margin: 0 0 0.15rem;
    font-size: var(--font-size-h3);
    font-weight: 700;
    letter-spacing: 0.02em;
}

.rate-subsection--tibor .rate-subsection-title {
    color: var(--accent-tibor);
}

.rate-subsection--tona .rate-subsection-title {
    color: var(--accent-tona);
}

.rate-subsection-subtitle {
    margin: 0;
    font-size: var(--font-size-small);
    color: var(--text-secondary);
    font-weight: 400;
}

.rate-subsection-heading {
    min-width: 0;
    flex: 1 1 auto;
}

.rate-subsection-source {
    margin: 0.75rem 0 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.current-rates .rates-snapshot-wrap {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    overflow: hidden;
    background: var(--background);
}

.current-rates .rates-snapshot-table {
    width: 100%;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
    table-layout: fixed;
}

/* Shared column widths for TIBOR and TONA snapshot tables */
.current-rates .rates-snapshot-table col.col-label {
    width: 38%;
}

.current-rates .rates-snapshot-table col.col-rate {
    width: 34%;
}

.current-rates .rates-snapshot-table col.col-bps {
    width: 28%;
}

.current-rates .rates-snapshot-table th,
.current-rates .rates-snapshot-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.current-rates .rates-snapshot-table th {
    font-size: var(--font-size-label);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--background);
}

.rate-subsection--tibor .rates-snapshot-table th {
    color: var(--accent-tibor);
}

.rate-subsection--tona .rates-snapshot-table th {
    color: var(--accent-tona);
}

.current-rates .rates-snapshot-table tbody tr:last-child td {
    border-bottom: none;
}

.current-rates .current-rates-stats {
    border-top: 1px solid var(--border-color);
    background: var(--background);
}

.current-rates .rates-snapshot-table tbody tr:hover td {
    background: color-mix(in srgb, var(--primary-color) 4%, transparent);
}

.current-rates .snapshot-rate {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
}

.current-rates .snapshot-bps {
    font-size: 0.9rem;
    font-weight: 600;
}

.current-rates .snapshot-bps.positive { color: var(--accent-positive); }
.current-rates .snapshot-bps.negative { color: var(--danger-color); }
.current-rates .snapshot-bps.neutral { color: var(--text-secondary); }

.current-rates .snapshot-tenor {
    font-weight: 600;
    color: var(--text-primary);
}

/* Site-wide status (auto-updates) */
.site-meta-strip {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    font-size: var(--font-size-small);
    color: var(--text-secondary);
}

.site-meta-label {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: var(--font-size-label);
}

.site-meta-value {
    font-weight: 600;
    color: var(--text-primary);
}

.site-meta-value.is-active {
    color: var(--secondary-color);
}

.site-meta-value.is-error {
    color: var(--danger-color);
}

.site-meta-value.is-stopped {
    color: var(--text-secondary);
}

/* Historical chart controls — single-row toolbar */
.section-header--chart {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
}

.section-header--chart h2 {
    margin-bottom: 0;
    align-self: flex-start;
    text-align: left;
    width: 100%;
}

.chart-controls {
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    background: var(--background);
}

.chart-controls-row {
    display: flex;
    align-items: flex-end;
    flex-wrap: nowrap;
    gap: 1rem 1.25rem;
}

.chart-controls-item {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    min-width: 0;
    flex: 0 0 auto;
}

.chart-controls-item--filters {
    flex: 1 1 auto;
}

.chart-controls-item--period {
    flex: 0 0 auto;
    margin-left: auto;
}

.chart-filter-slot {
    min-width: 0;
}

.chart-filter-group[hidden] {
    display: none !important;
}

.chart-controls-label {
    font-size: var(--font-size-label);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
    white-space: nowrap;
}

.chart-segmented {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    border: none;
    background: transparent;
    box-shadow: none;
    overflow: visible;
}

/* Shared with .btn-copy-rates — secondary control buttons */
.chart-segmented-btn,
.chart-period-select {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: var(--control-height);
    min-height: var(--control-height);
    box-sizing: border-box;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    background: var(--background);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.chart-segmented-btn {
    padding: 0 14px;
    white-space: nowrap;
}

@media (hover: hover) {
    .chart-segmented-btn:hover:not(.is-active) {
        border-color: var(--primary-color);
        color: var(--primary-color);
    }
}

.chart-segmented-btn.is-active {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--background);
}

.chart-segmented-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    z-index: 1;
}

.chart-period-select {
    min-width: 9.5rem;
    padding: 0 2rem 0 0.65rem;
}

.analysis-hub-panel .section-header--chart {
    padding: 20px 24px 0;
    margin-bottom: 16px;
}

.analysis-hub-panel .section-header--chart .chart-controls {
    margin-top: 0;
}

/* Fixing date tabs — integrated above snapshot table */
.rates-fixing-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    margin: 10px 0 -1px 16px;
}

.rates-fixing-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    padding: 0.45rem 0.85rem;
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-secondary);
    background: color-mix(in srgb, var(--primary-color) 8%, var(--surface));
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: var(--radius-control) var(--radius-control) 0 0;
}

.rates-fixing-tab[hidden] {
    display: none !important;
}

.rates-fixing-tab--provisional {
    margin-left: -1px;
    color: #92400e;
    background: color-mix(in srgb, #f59e0b 12%, var(--surface));
    border-color: color-mix(in srgb, #f59e0b 35%, var(--border-color));
}

.rates-fixing-tab--provisional .rates-fixing-tab-label {
    color: #92400e;
}

.rates-fixing-tab-label {
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
}

.rates-fixing-tab-value {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.rates-snapshot-wrap:has(.rates-fixing-tab:not([hidden])) .rates-snapshot-table thead th,
.rates-snapshot-wrap:has(.rates-fixing-tabs .rates-fixing-tab:not([hidden])) .rates-snapshot-table thead th {
    border-top: 1px solid var(--border-color);
}

.current-rates-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.btn-copy-rates {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: var(--control-height);
    min-height: var(--control-height);
    padding: 0 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    box-sizing: border-box;
    background: var(--background);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

@media (hover: hover) {
    .btn-copy-rates:hover,
    .chart-period-select:hover {
        border-color: var(--primary-color);
        color: var(--primary-color);
    }
}

/* Latest updates */
.latest-updates {
    --updates-scroll-height: 20rem;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.latest-updates .updates-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    flex-shrink: 0;
}

.latest-updates .updates-header h2 {
    margin-bottom: 0;
}

.updates-scroll {
    max-height: var(--updates-scroll-height);
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    background: var(--background);
    padding: 4px 6px 4px 12px;
    scrollbar-gutter: stable;
}

/* Grow from the usual scroll height into any leftover space above the footer;
   section margin-bottom and container padding stay as they are. */
.latest-updates .updates-scroll {
    flex: 1 1 var(--updates-scroll-height);
    max-height: none;
    min-height: var(--updates-scroll-height);
}

.updates-scroll:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.updates-scroll::-webkit-scrollbar {
    width: 6px;
}

.updates-scroll::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--text-secondary) 45%, transparent);
    border-radius: 999px;
}

.updates-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.updates-live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--secondary-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--secondary-color) 35%, transparent);
    animation: updates-pulse 2s ease-in-out infinite;
}

@keyframes updates-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.updates-feed {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.update-item {
    display: grid;
    grid-template-columns: minmax(72px, 100px) 1fr;
    gap: 16px;
    padding: 18px 0;
    border-bottom: 1px solid var(--border-color);
}

.update-item:last-child {
    border-bottom: none;
}

.updates-scroll .update-item:last-child {
    padding-bottom: 18px;
}

.update-time {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1.4;
}

.update-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.update-text {
    font-size: 0.92rem;
    color: var(--text-secondary);
    line-height: 1.55;
    margin: 0;
}

.update-text p {
    margin: 0;
}

.update-text > p + .update-list,
.update-text > .update-list + p {
    margin-top: 0.75rem;
}

.update-list {
    margin: 0;
    padding-left: 1.25rem;
    list-style: disc;
    font-size: inherit;
    color: inherit;
    line-height: inherit;
}

.update-list li {
    margin-bottom: 0.35rem;
    font-size: inherit;
    color: inherit;
    line-height: inherit;
}

.update-list li:last-child {
    margin-bottom: 0;
}

.update-read-more {
    margin-top: 0.5rem;
}

.update-read-more[hidden] {
    display: none !important;
}

@media (min-width: 769px) {
    .update-read-more {
        display: none;
    }
}

@media (max-width: 480px) {
    .update-item {
        grid-template-columns: 1fr;
        gap: 6px;
    }

}

/* Legacy global .rates-grid (e.g. IFR) – keep grid when not inside .current-rates */
.rates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
}

.rate-card {
    background-color: var(--background);
    padding: 20px;
    border-radius: var(--radius-control);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: border-color 0.2s ease;
}

.rate-card:hover {
    transform: none;
    box-shadow: none;
    border-color: var(--primary-color);
}

.rate-tenor {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.rate-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: -0.02em;
}

/* Historical Section */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 30px;
}

.controls {
    display: flex;
    gap: 25px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Tenor Checkboxes */
.tenor-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: var(--radius-control);
    background-color: var(--background);
    border: 2px solid var(--border-color);
    transition: all 0.3s ease;
    user-select: none;
}

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

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.checkbox-label span {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.checkbox-label input[type="checkbox"]:checked + span {
    color: var(--primary-color);
    font-weight: 600;
}

.form-select {
    padding: 8px 15px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-control);
    font-size: 0.95rem;
    background-color: var(--surface);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.3s ease, color 0.3s ease;
}

.form-select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-select.chart-period-select {
    height: var(--control-height);
    min-height: var(--control-height);
    padding: 0 2rem 0 0.65rem;
    border: 1px solid var(--border-color);
    background: var(--background);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.2;
    transition: border-color 0.2s, color 0.2s;
}

#periodSelect {
    width: 150px;
}

.recent-rates-toolbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.recent-tenors-toggle {
    display: none;
    margin-top: 0.75rem;
}

.chart-container {
    position: relative;
    height: 400px;
    margin-bottom: 20px;
}

/* Table */
.table-container {
    overflow-x: auto;
}

.rates-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.rates-table thead {
    background-color: var(--background);
}

.rates-table th,
.rates-table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.rates-table th {
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.rates-table th.sortable-col {
    cursor: pointer;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.rates-table th .sort-icon {
    margin-left: 4px;
    opacity: 0.9;
    font-size: 1em;
}

.rates-table tbody tr {
    transition: background-color 0.2s;
}

.rates-table tbody tr:hover {
    background-color: color-mix(in srgb, var(--primary-color) 6%, var(--background));
}

.rates-table td:first-child {
    font-weight: 600;
    color: var(--text-primary);
}

.loading-cell {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px;
}

/* Reference Banks Section */
.reference-banks-section {
    background-color: var(--surface);
    border-radius: var(--radius-section);
    margin-bottom: 24px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    transition: background-color 0.3s ease;
    padding: 24px;
}

.banks-intro {
    margin-bottom: 20px;
    color: var(--text-secondary);
    line-height: 1.55;
    font-size: var(--font-size-small);
}

.banks-count {
    font-weight: 500;
    font-size: 0.85em;
    color: var(--text-secondary);
}

/* Reference banks: segment columns */
.banks-segments {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
}

.banks-segment-col {
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--background);
    min-width: 0;
}

.banks-segment-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent-banks);
    margin: 0 0 10px;
    line-height: 1.3;
}

.banks-segment-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.banks-segment-list li {
    font-size: 0.8rem;
    line-height: 1.35;
    padding: 6px 0;
    border-bottom: 1px solid var(--border-color);
}

.banks-segment-list li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.banks-segment-list a {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.banks-segment-list a:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

.banks-segment-list a:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Analysis hub: Historical chart, Recent rates, IFR calculator (tabbed) */
.analysis-hub {
    padding: 0;
    overflow: hidden;
}

.analysis-hub-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    padding: 0;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface);
}

.analysis-hub-tab {
    flex: 1 1 auto;
    min-width: 120px;
    padding: 12px 16px;
    border: none;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: var(--font-size-small);
    font-weight: 600;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s;
}

@media (hover: hover) {
    .analysis-hub-tab:hover {
        color: var(--text-primary);
    }
}

.analysis-hub-tab.is-active {
    border-bottom-color: var(--accent-tab);
    color: var(--accent-tab);
    background: transparent;
}

.analysis-hub-panel[hidden] {
    display: none !important;
}

.analysis-hub-panel .section-header {
    padding: 20px 24px 0;
    margin-bottom: 20px;
}

.analysis-hub-panel .section-header h2 {
    margin-bottom: 0;
}

.analysis-hub-panel .chart-container {
    padding: 0 24px 24px;
}

.analysis-panel-title {
    font-size: 1.75rem;
    margin: 0;
    padding: 20px 24px 0;
    color: var(--text-primary);
}

.recent-rates-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 20px 24px 0;
}

.recent-rates-title {
    padding: 0;
    align-self: flex-start;
    text-align: left;
}

.recent-rates-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.analysis-panel-body {
    padding: 16px 24px 24px;
}

.analysis-hub .ifr-tabs-container {
    margin-top: 0;
}

.section-header-collapsible {
    padding: 25px 30px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--surface);
    transition: background-color 0.2s ease;
    user-select: none;
}

.section-header-collapsible:hover {
    background-color: var(--background);
}

.section-header-collapsible h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.5rem;
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, padding 0.4s ease;
    padding: 0 30px;
}

.collapsible-content.expanded {
    max-height: 3000px;
    padding: 0 30px 30px 30px;
}

.ifr-controls {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 25px;
}

.ifr-control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 150px;
}

.btn-primary {
    padding: 10px 25px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-control);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background-color: var(--primary-dark);
}

.btn-primary:disabled {
    background-color: var(--text-secondary);
    cursor: not-allowed;
}

.error-message {
    padding: 15px;
    background-color: rgba(239, 68, 68, 0.1);
    border-left: 3px solid var(--danger-color);
    border-radius: 4px;
    color: var(--danger-color);
    margin-bottom: 20px;
}

.ifr-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.summary-card {
    background-color: var(--background);
    padding: 16px;
    border-radius: var(--radius-control);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.summary-value {
    font-size: 1.25rem;
    color: var(--text-primary);
    font-weight: 700;
}

.summary-label {
    font-size: var(--font-size-small);
    color: var(--text-secondary);
    font-weight: 600;
}

.ifr-table-container {
    margin-top: 30px;
}

.ifr-table-container h3 {
    margin-bottom: 15px;
    color: var(--text-primary);
}

/* IFR Mode Toggle */
.mode-toggle-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 25px;
    padding: 20px;
    background-color: var(--background);
    border-radius: 8px;
    border: 2px solid var(--border-color);
}

.mode-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.toggle-switch {
    position: relative;
    width: 280px;
    height: 44px;
}

.toggle-switch input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    position: absolute;
    width: 100%;
    height: 100%;
    background-color: var(--surface);
    border: 2px solid var(--primary-color);
    border-radius: 22px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    transition: all 0.3s ease;
}

.slider-text-left,
.slider-text-right {
    font-size: 0.95rem;
    font-weight: 600;
    z-index: 2;
    transition: color 0.3s ease;
}

.slider-text-left {
    color: white;
}

.slider-text-right {
    color: var(--text-secondary);
}

.slider-button {
    position: absolute;
    left: 4px;
    width: 130px;
    height: 36px;
    background-color: var(--primary-color);
    border-radius: 18px;
    transition: transform 0.3s ease;
    z-index: 1;
}

.toggle-switch input[type="checkbox"]:checked + .toggle-slider .slider-button {
    transform: translateX(140px);
}

.toggle-switch input[type="checkbox"]:checked + .toggle-slider .slider-text-left {
    color: var(--text-secondary);
}

.toggle-switch input[type="checkbox"]:checked + .toggle-slider .slider-text-right {
    color: white;
}

.mode-description {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 12px 0;
    font-style: normal;
}

/* IFR Tabs */
.ifr-tabs-container {
    margin: 25px 0;
    padding: 20px;
    background: var(--surface);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.ifr-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    border-bottom: 2px solid var(--border-color);
}

.ifr-tab {
    flex: 1;
    padding: 12px 20px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.ifr-tab:hover {
    color: var(--primary-color);
    background: var(--background);
}

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

/* Forward Rate Matrix & Heatmap */
.matrix-header {
    margin-bottom: 25px;
}

.matrix-header h3 {
    margin-bottom: 8px;
    color: var(--text-primary);
}

.matrix-description {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin: 0;
}

.heatmap-container {
    margin: 30px 0;
    padding: 20px;
    background: var(--surface);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.heatmap-legend {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    justify-content: center;
}

.legend-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.legend-gradient {
    width: 200px;
    height: 20px;
    background: linear-gradient(to right,
        #4CAF50,
        #8BC34A,
        #CDDC39,
        #FFEB3B,
        #FFC107,
        #FF9800,
        #FF5722
    );
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

[data-theme="dark"] .legend-gradient {
    background: linear-gradient(to right,
        #22c55e,
        #4ade80,
        #facc15,
        #fb923c,
        #f87171,
        #ef4444
    );
}

.legend-values {
    display: flex;
    gap: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

.heatmap-grid {
    display: grid;
    grid-template-columns: auto repeat(4, 1fr);
    gap: 2px;
    background: var(--border-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.heatmap-cell {
    background: var(--surface);
    padding: 15px 10px;
    text-align: center;
    transition: all 0.2s ease;
    min-height: 60px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.heatmap-cell.header {
    background: var(--background);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.heatmap-cell.empty {
    background: var(--background);
    opacity: 0.3;
}

.heatmap-cell:not(.header):not(.empty):hover {
    transform: scale(1.10);
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    cursor: default;
}

.cell-rate {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.cell-period {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 3px;
}

.matrix-table-container {
    margin-top: 30px;
}

.matrix-table-container h4 {
    margin-bottom: 15px;
    color: var(--text-primary);
}

/* Future Mode Results */
.current-rates-display {
    margin-bottom: 25px;
}

.current-rates-display h3 {
    margin-bottom: 15px;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.rates-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.rate-label {
    font-size: var(--font-size-small);
    color: var(--text-secondary);
    font-weight: 600;
}

.rate-value {
    font-size: 1.5rem;
    color: var(--text-primary);
    font-weight: 700;
}

.forward-rate-result {
    margin-bottom: 25px;
}

.forward-rate-result h3 {
    margin-bottom: 15px;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.forward-rate-card {
    background: var(--background);
    padding: 24px;
    border-radius: var(--radius-section);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: none;
}

.forward-rate-main {
    text-align: center;
    margin-bottom: 20px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.forward-rate-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
    display: block;
}

.forward-rate-details {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-top: 0;
    border-top: none;
}

.forward-rate-details p {
    margin: 0;
    font-size: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.forward-rate-details strong {
    font-weight: 600;
}

.interpretation-box {
    background-color: var(--background);
    padding: 25px;
    border-radius: 8px;
    border-left: 4px solid var(--secondary-color);
    box-shadow: var(--shadow);
}

.interpretation-box h4 {
    margin-top: 0;
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: 1rem;
}

.interpretation-box p {
    margin: 0;
    line-height: 1.7;
    color: var(--text-primary);
    font-size: 0.95rem;
}

/* IFR Table difference coloring */
.diff-close {
    color: var(--secondary-color);
    font-weight: 600;
}

.diff-moderate {
    color: var(--warning-color);
    font-weight: 600;
}

.diff-large {
    color: var(--danger-color);
    font-weight: 600;
}

/* Footer */
footer {
    background-color: var(--surface);
    padding: 32px 24px 16px;
    padding-left: max(30px, env(safe-area-inset-left));
    padding-right: max(30px, env(safe-area-inset-right));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
    transition: background-color 0.3s ease;
}

.footer-bottom {
    text-align: center;
    max-width: var(--layout-max-width);
    margin: 0 auto;
    font-size: var(--font-size-small);
}

.footer-note {
    margin-top: 10px;
    font-size: 0.85rem;
}

.footer-bottom a {
    color: var(--link-color);
    text-decoration: none;
    font-weight: 500;
}

.footer-bottom a:hover {
    text-decoration: underline;
}

/* Legal / disclaimer page */
.legal-page {
    width: 100%;
    margin-bottom: 24px;
}

.legal-page-title {
    font-size: var(--font-size-h2);
    margin-bottom: 12px;
    color: var(--text-primary);
}

.legal-page-intro {
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 32px;
}

.legal-section {
    margin-bottom: 28px;
}

.legal-section h3 {
    font-size: 1.1rem;
    margin-bottom: 10px;
    color: var(--accent-section);
    font-weight: 600;
}

.legal-section p,
.legal-section li {
    line-height: 1.7;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.legal-section ul {
    padding-left: 1.25rem;
    margin-top: 8px;
}

.legal-section a {
    color: var(--link-color);
    text-decoration: none;
    font-weight: 500;
}

.legal-section a:hover {
    text-decoration: underline;
}

.legal-last-updated {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.legal-back-link {
    margin-top: 36px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.legal-back-link a {
    color: var(--link-color);
    text-decoration: none;
    font-weight: 500;
}

.legal-back-link a:hover {
    text-decoration: underline;
}

/* Palette selector */
.palette-picker {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    box-shadow: var(--shadow-lg);
    font-size: var(--font-size-label);
    font-family: inherit;
}

.palette-picker[hidden] {
    display: none !important;
}

.palette-picker-label {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.palette-picker__seg {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.palette-picker__btn {
    min-width: 1.85rem;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    background: var(--background);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--font-size-label);
    font-weight: 700;
    cursor: pointer;
    transition: box-shadow 0.15s, border-color 0.15s;
}

/* Full-face swatches (paper over brand) — readable from across the room */
.palette-picker__btn[data-palette="kinari"] {
    background: linear-gradient(180deg, #e4e7ec 0 45%, #0a0b0d 45% 100%);
    color: #0a0b0d;
    border-color: #9aa3b2;
}
.palette-picker__btn[data-palette="aka"] {
    background: linear-gradient(180deg, #ff7a68 0 45%, #e10600 45% 100%);
    color: #140003;
    border-color: #140003;
}
.palette-picker__btn[data-palette="sumi"] {
    background: linear-gradient(180deg, #8fa6e8 0 45%, #ea580c 45% 100%);
    color: #060a18;
    border-color: #060a18;
}
.palette-picker__btn[data-palette="matsu"] {
    background: linear-gradient(180deg, #ffffff 0 45%, #ccff00 45% 100%);
    color: #000000;
    border-color: #000000;
}
.palette-picker__btn[data-palette="kohaku"] {
    background: linear-gradient(180deg, #f0e6d4 0 34%, #c8102e 34% 67%, #1b7a3c 67%);
    color: #0a0a0a;
    border-color: #0a0a0a;
}

.palette-picker__btn[aria-pressed="true"] {
    box-shadow: inset 0 0 0 2px var(--text-primary);
    outline: 2px solid var(--text-primary);
    outline-offset: 1px;
}

@media (hover: hover) {
    .palette-picker__btn:hover:not([aria-pressed="true"]) {
        box-shadow: inset 0 0 0 1px var(--text-primary);
    }
}

.breadcrumb {
    font-size: var(--font-size-small);
    color: var(--text-secondary);
    margin-bottom: 1.25rem;
}

.breadcrumb a {
    color: var(--text-secondary);
    font-weight: 500;
    text-decoration: none;
}

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

.breadcrumb [aria-current="page"] {
    font-weight: 600;
    color: var(--text-primary);
}

.breadcrumb-sep {
    margin: 0 0.35rem;
    color: var(--text-secondary);
}

.legal-site-link {
    color: inherit;
    text-decoration: none;
}

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

.ifr-disclaimer {
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.ifr-disclaimer a {
    color: var(--link-color);
    text-decoration: none;
    font-weight: 500;
}

.ifr-disclaimer a:hover {
    text-decoration: underline;
}

/* Loading State */
.rate-card.loading {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* Reference banks: segment columns — tablet */
@media (max-width: 1024px) {
    .banks-segments {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    :root {
        --site-header-height: 56px;
    }

    .container {
        padding: 15px;
        padding-left: max(15px, env(safe-area-inset-left));
        padding-right: max(15px, env(safe-area-inset-right));
    }

    section {
        padding: 18px;
        margin-bottom: 20px;
    }

    section h2,
    .analysis-panel-title {
        font-size: 1.35rem;
    }

    .latest-updates {
        --updates-scroll-height: 18rem;
    }

    .updates-scroll {
        padding-left: 10px;
        padding-right: 4px;
    }

    .rate-subsection-title {
        flex-direction: column;
        align-items: flex-start;
    }

    .rate-subsection-header {
        flex-wrap: nowrap;
        align-items: flex-start;
    }

    .rate-subsection-heading {
        flex: 1 1 auto;
        min-width: 0;
    }

    .current-rates-actions {
        flex: 0 0 auto;
        align-self: flex-start;
    }

    .update-item:not(.is-expanded) .update-text {
        max-height: 7rem;
        overflow: hidden;
    }

    .recent-tenors-toggle.is-visible {
        display: inline-flex;
    }

    #recentRatesTable.is-compact .recent-col-extra {
        display: none;
    }

    /* Consistent 15px horizontal padding for main content sections (chart, Recent Rates) */
    .analysis-hub-panel .section-header,
    .recent-rates-header,
    .analysis-panel-title,
    .analysis-panel-body,
    .analysis-hub-panel .chart-container {
        padding-left: 15px;
        padding-right: 15px;
    }

    .recent-rates-header {
        flex-wrap: nowrap;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .recent-rates-title {
        flex: 1 1 auto;
        min-width: 0;
    }

    .recent-rates-toolbar {
        flex: 0 0 auto;
        flex-wrap: nowrap;
    }

    .analysis-hub-tabs {
        padding: 12px 15px;
    }

    .analysis-hub-tab {
        min-width: 100%;
    }

    .current-rates .stats-strip-divider {
        display: none;
    }

    .current-rates .stats-strip-item {
        flex: 1 1 100%;
        border-bottom: 1px solid var(--border-color);
    }

    .current-rates .stats-strip-item:last-child {
        border-bottom: none;
    }

    .site-header .subtitle {
        display: none;
    }

    .site-nav {
        gap: 12px;
        margin-right: 0;
    }

    .site-nav__link {
        font-size: 0.75rem;
    }

    .site-header__inner {
        padding: 8px 16px;
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }

    .header-logo {
        height: 36px;
        width: 36px;
    }

    .header-title,
    .header-content h1 {
        font-size: 1.25rem;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .section-header--chart {
        align-items: center;
    }

    .section-header--chart h2 {
        align-self: flex-start;
        width: 100%;
    }

    .analysis-hub-panel .section-header--chart .chart-controls {
        position: sticky;
        top: var(--site-header-height);
        z-index: 50;
        align-self: center;
        width: fit-content;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
        background: var(--surface);
        box-shadow: 0 1px 0 var(--border-color);
    }

    .section-header--chart .chart-controls-row {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
        align-items: end;
        gap: 0.75rem;
    }

    .section-header--chart .chart-controls-item:first-child {
        grid-column: 1;
        grid-row: 1;
    }

    .chart-controls-item--period {
        grid-column: 2;
        grid-row: 1;
        margin-left: 0;
        width: auto;
    }

    .chart-controls-item--filters {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%;
        order: unset;
    }

    .chart-controls-item--period .chart-period-select {
        width: auto;
        min-width: 9.5rem;
    }

    .chart-controls-item--filters .chart-segmented {
        width: 100%;
    }

    .chart-segmented-btn {
        flex: 1 1 0;
        min-width: 0;
        padding-left: 0.35rem;
        padding-right: 0.35rem;
        font-size: 0.75rem;
    }
    
    .controls {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }
    
    .control-group {
        width: 100%;
    }
    
    .tenor-checkboxes {
        flex-direction: column;
    }
    
    .checkbox-label {
        width: 100%;
    }

    .form-select {
        width: 100%;
    }

    .chart-container {
        height: 300px;
    }

    .rates-table {
        font-size: 0.85rem;
    }

    .rates-table th,
    .rates-table td {
        padding: 10px;
    }

    /* Heatmap mobile: scrollable wrapper + 25% smaller font */
    .heatmap-grid-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -4px;
    }
    .heatmap-grid-wrapper .heatmap-grid {
        min-width: 320px;
    }
    .heatmap-grid-wrapper .heatmap-cell.header {
        font-size: 0.64rem;
    }
    .heatmap-grid-wrapper .cell-rate {
        font-size: 0.71rem;
    }
    .heatmap-grid-wrapper .cell-period {
        font-size: 0.56rem;
    }

    /* Heatmap legend: stack as column, High/max at top, Low/min at bottom */
    .heatmap-legend {
        flex-direction: column;
        align-items: center;
        gap: 10px;
    }
    .heatmap-legend .legend-values:first-of-type { order: 5; }
    .heatmap-legend .legend-label:first-of-type { order: 4; }
    .heatmap-legend .legend-gradient { order: 3; }
    .heatmap-legend .legend-label:last-of-type { order: 2; }
    .heatmap-legend .legend-values:last-of-type { order: 1; }

    /* Matrix table: wrapper scrolls; 25% smaller font */
    .matrix-table-container .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .matrix-table-container .rates-table {
        font-size: 0.64rem;
    }
    .matrix-table-container .rates-table th,
    .matrix-table-container .rates-table td {
        padding: 8px;
    }
    .matrix-table-container .rates-table th.sortable-col {
        font-size: 0.64rem;
    }

    /* Recent Rates table: compact columns by default on mobile */
    #analysis-panel-recent .rates-table {
        font-size: 0.8rem;
    }

    #analysis-panel-recent .rates-table th,
    #analysis-panel-recent .rates-table td {
        padding: 8px 10px;
    }

    /* IFR calculator: tighter mobile layout */
    #analysis-panel-ifr .analysis-panel-title {
        padding: 16px 15px 0;
    }

    #analysis-panel-ifr .analysis-panel-body {
        padding: 12px 15px 18px;
    }

    #analysis-panel-ifr .ifr-tabs-container {
        padding: 12px;
        margin: 0 0 12px;
    }

    #analysis-panel-ifr .ifr-controls {
        gap: 12px;
        margin-bottom: 16px;
    }

    #analysis-panel-ifr .ifr-control-group {
        gap: 6px;
    }

    #analysis-panel-ifr .mode-toggle-container {
        padding: 14px;
        margin-bottom: 16px;
    }

    #analysis-panel-ifr .summary-card {
        padding: 14px;
    }

    #analysis-panel-ifr .heatmap-container {
        padding: 12px;
        margin: 16px 0;
    }

    #analysis-panel-ifr .matrix-table-container {
        margin-top: 16px;
    }

    #analysis-panel-ifr .matrix-table-container .rates-table {
        font-size: 0.75rem;
    }

    #analysis-panel-ifr .matrix-table-container .rates-table th,
    #analysis-panel-ifr .matrix-table-container .rates-table td {
        padding: 6px;
    }

    #analysis-panel-ifr .forward-rate-card {
        padding: 24px 18px;
    }

    #analysis-panel-ifr .forward-rate-value {
        font-size: 2.25rem;
    }

    /* Touch targets: min 44px tap area */
    .theme-toggle {
        min-height: 44px;
        padding: 10px 18px;
    }
    .section-header-collapsible {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    .btn-primary {
        min-height: 44px;
    }

    /* IFR tabs: wrap with min-width (Option B) */
    .ifr-tabs {
        flex-wrap: wrap;
        gap: 8px;
    }
    .ifr-tab {
        min-width: 120px;
        min-height: 44px;
        padding: 12px 16px;
    }

    .banks-segments {
        grid-template-columns: 1fr;
    }

    /* Recent Rates Mobile */
    .section-header-collapsible {
        padding: 20px;
    }

    .section-header-collapsible h2 {
        font-size: 1.25rem;
    }

    .collapsible-content.expanded {
        padding: 0 15px 20px 15px;
    }

    /* IFR Calculator Mobile */
    .ifr-controls {
        flex-direction: column;
        gap: 15px;
    }

    .ifr-control-group {
        width: 100%;
    }

    .btn-primary {
        width: 100%;
    }

    .ifr-summary {
        grid-template-columns: 1fr;
    }
    
    /* Mode Toggle Mobile */
    .toggle-switch {
        width: 100%;
    }
    
    .slider-button {
        width: calc(50% - 8px);
    }
    
    .toggle-switch input[type="checkbox"]:checked + .toggle-slider .slider-button {
        transform: translateX(calc(100% - 4px));
    }
    
    /* Future Mode Mobile */
    .rates-grid {
        grid-template-columns: 1fr;
    }
    
    .forward-rate-value {
        font-size: 2.5rem;
    }
    
    .forward-rate-details {
        font-size: 0.9rem;
    }
    
    .forward-rate-details p {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }

    /* Footer Mobile */
    footer {
        padding: 30px 20px 15px 20px;
    }
}

/* ==============================================================================
   ADDITIONAL UI POLISH
   ============================================================================== */

/* Loading Animation */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

.loading {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.skeleton {
    background: linear-gradient(90deg, var(--background) 0%, var(--surface) 50%, var(--background) 100%);
    background-size: 1000px 100%;
    animation: shimmer 2s infinite;
}

/* Improved Button States */
button, .btn-primary {
    position: relative;
    overflow: hidden;
    transform: translateY(0);
    transition: all 0.2s ease;
}

button.btn-copy-rates,
button.chart-segmented-btn,
button.theme-toggle {
    overflow: visible;
    transform: none;
}

@media (hover: hover) and (pointer: fine) {
    button:hover, .btn-primary:hover {
        transform: translateY(-1px);
        box-shadow: var(--shadow-lg);
    }

    button.btn-copy-rates:hover,
    button.chart-segmented-btn:hover,
    button.theme-toggle:hover {
        box-shadow: none;
    }

    button.btn-copy-rates:hover,
    button.chart-segmented-btn:hover {
        transform: none;
    }
}

button:active, .btn-primary:active {
    transform: translateY(0);
}

button.theme-toggle:active {
    transform: none;
}

button.theme-toggle:active .theme-toggle-icon {
    transform: none;
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

/* Ripple Effect on Click */
button::after, .btn-primary::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

button:active::after, .btn-primary:active::after {
    width: 300px;
    height: 300px;
}

/* Improved Table Hover States */
.rates-table tbody tr {
    transition: background-color 0.2s ease;
}

.rates-table tbody tr:hover {
    background-color: color-mix(in srgb, var(--primary-color) 6%, var(--background));
}

/* Enhanced Card Shadows on Hover — disabled for de-cluttered UI */

/* Improved Select Dropdown */
select {
    appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg fill="%233b82f6" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7 10l5 5 5-5z"/></svg>');
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 20px;
    padding-right: 35px;
}

/* Tooltip Support */
[data-tooltip] {
    position: relative;
    cursor: help;
}

[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 12px;
    background-color: var(--text-primary);
    color: var(--surface);
    font-size: 0.85rem;
    white-space: nowrap;
    border-radius: 6px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1000;
    margin-bottom: 5px;
}

[data-tooltip]::after {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: var(--text-primary);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

[data-tooltip]:hover::before,
[data-tooltip]:hover::after {
    opacity: 1;
}

/* Scroll to Top Button (if added in future) */
.scroll-to-top {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background-color: var(--primary-color);
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
}

.scroll-to-top.visible {
    opacity: 1;
}

.scroll-to-top:hover {
    transform: translateY(-5px);
}

/* ==============================================================================
   EDITORIAL SURFACES
   Homepage lede, methodology note, Insights index, and issue bodies. These
   sections inherit the card treatment from the bare `section` rule above; what
   follows is the typography inside them.
   ============================================================================== */

.editorial-intro,
.insights-preview,
.insights-index,
.insights-basis {
    scroll-margin-top: calc(var(--site-header-height) + 12px);
}

.editorial-lede {
    font-size: 1.0625rem;
    line-height: 1.75;
    color: var(--text-primary);
    width: 100%;
    box-sizing: border-box;
    padding: 0 8px;
    margin-bottom: 16px;
}

.editorial-note {
    font-size: var(--font-size-small);
    line-height: 1.7;
    color: var(--text-secondary);
    max-width: 78ch;
    padding-left: 14px;
    border-left: 2px solid var(--border-color);
}

/* Insights list — shared by the homepage preview and the full index */

.insights-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 16px;
}

.insights-header h2 {
    margin-bottom: 0;
}

.insights-all-link {
    font-size: var(--font-size-small);
    font-weight: 600;
    color: var(--link-color);
    text-decoration: none;
    white-space: nowrap;
}

.insights-all-link:hover {
    text-decoration: underline;
}

.insights-empty {
    line-height: 1.75;
    color: var(--text-secondary);
    max-width: 74ch;
}

/* Homepage preview: three slots, filled newest first. An unfilled slot is drawn
   rather than collapsed, so the row keeps its shape while the first issues are
   still being written. */
.insights-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.insight-tile {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 18px;
    background-color: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-section);
    transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.insight-tile .insight-title {
    font-size: 1.0625rem;
}

.insight-tile .insight-teaser {
    flex: 1 1 auto;
    max-width: none;
}

.insight-tile--placeholder,
.insight-tile--empty {
    border-style: dashed;
    background-color: transparent;
}

.insight-tile--empty {
    min-height: 168px;
}

/* Set by site.js when the referenced article the reader is scrolled to falls
   inside this card's coverage window. */
.insight-tile--in-focus {
    border-color: var(--accent-header);
    border-style: solid;
    background-color: var(--surface);
    box-shadow: var(--shadow-lg);
}

@media (hover: hover) and (pointer: fine) {
    .insight-tile:not(.insight-tile--empty):hover {
        border-color: var(--accent-header);
        transform: translateY(-2px);
        box-shadow: var(--shadow-lg);
    }
}

.insights-grid + .insights-empty {
    margin-top: 16px;
    font-size: var(--font-size-small);
}

/* ==============================================================================
   HOMEPAGE REFERENCE RAILS
   Two curated reading lists flanking the main column: English on the left,
   Japanese on the right. Above 1440px both are visible and sticky. Below it they
   collapse under the main column and share a segmented switch, because two
   parallel feeds in a narrow viewport is two feeds nobody reads.
   ============================================================================== */

/* Both defaults describe the no-JavaScript case. site.js replaces them with a
   measured height once it can see the Insights and intro block. */
/* Three-column rail layout commented out with the homepage news feeds.
.home-layout {
    --rails-height: auto;
    --rails-scroll-max: calc(100vh - var(--site-header-height) - 180px);
    display: grid;
    grid-template-columns:
        minmax(0, var(--news-rail-width))
        minmax(0, 1fr)
        minmax(0, var(--news-rail-width));
    gap: 24px;
    align-items: start;
}

.home-layout > .news-rail--en {
    grid-column: 1;
    grid-row: 1;
}

.home-layout > .page-main {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
}

.home-layout > .news-rail--ja {
    grid-column: 3;
    grid-row: 1;
}
*/
.home-layout {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}

.home-layout > .page-main {
    min-width: 0;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Padding and heading metrics match the bare `section` rule so a rail and the
   Insights card opposite it share a top edge and a first baseline, not just a
   grid row. `--rails-height` is measured by site.js from the Insights and intro
   block; without JavaScript the rail sizes to its content. */
.news-rail {
    position: sticky;
    top: calc(var(--site-header-height) + 20px);
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: var(--rails-height);
    padding: 24px;
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-section);
    box-shadow: var(--shadow);
}

.news-rail__title {
    font-size: var(--font-size-h2);
    font-weight: 700;
    color: var(--accent-section);
    margin-bottom: 6px;
}

.news-rail__note,
.news-rail__empty {
    font-size: var(--font-size-small);
    line-height: 1.6;
    color: var(--text-secondary);
    margin-bottom: 14px;
}

.news-rail__empty {
    margin-bottom: 0;
}

/* Same scroll treatment as the updates feed: contained overscroll so the page
   does not run away under the cursor, and a visible focus ring because the
   region is keyboard-scrollable. `min-height: 0` is what actually lets a flex
   child shrink far enough to scroll. */
.news-rail__scroll {
    flex: 1 1 auto;
    min-height: 0;
    max-height: var(--rails-scroll-max);
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    background: var(--background);
    padding: 2px 6px 2px 12px;
    scrollbar-gutter: stable;
}

.news-rail__scroll:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.news-rail__scroll::-webkit-scrollbar {
    width: 6px;
}

.news-rail__scroll::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--text-secondary) 45%, transparent);
    border-radius: 999px;
}

.news-rail__scroll::-webkit-scrollbar-track {
    background: transparent;
}

.news-feed {
    list-style: none;
    margin: 0;
    padding: 0;
}

.news-item {
    padding: 14px 0;
    border-bottom: 1px solid var(--border-color);
    border-left: 2px solid transparent;
    padding-left: 10px;
    margin-left: -10px;
    transition: border-left-color 0.2s ease;
}

.news-item:last-child {
    border-bottom: none;
}

.news-item--active {
    border-left-color: var(--accent-header);
}

.news-item__meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 2px;
}

/* Which rate the item bears on. A controlled pair rather than free text, because
   these will become filters. */
.news-chip {
    display: inline-flex;
    align-items: center;
    padding: 1px 7px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    font-size: var(--font-size-label);
    font-weight: 700;
    letter-spacing: 0.03em;
    line-height: 1.6;
    color: var(--text-secondary);
}

.news-chip--tibor {
    border-color: color-mix(in srgb, var(--accent-tibor) 45%, transparent);
    color: var(--accent-tibor);
}

.news-chip--tona {
    border-color: color-mix(in srgb, var(--accent-tona) 55%, transparent);
    color: var(--accent-tona);
}

.news-feed__sentinel {
    height: 1px;
}

.news-months {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
}

.news-months__label {
    font-size: var(--font-size-small);
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.news-months__select {
    flex: 1 1 auto;
    min-width: 0;
    height: var(--control-height);
    padding: 0 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    background: var(--background);
    color: var(--text-primary);
    font: inherit;
    font-size: var(--font-size-small);
}

.news-item__date {
    display: block;
    font-size: var(--font-size-label);
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.news-item__outlet {
    font-size: var(--font-size-small);
    font-weight: 600;
    color: var(--text-primary);
    margin: 2px 0 4px;
}

.news-item__title {
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.45;
    margin-bottom: 4px;
}

.news-item__title a {
    color: var(--link-color);
    text-decoration: none;
}

.news-item__title a:hover {
    text-decoration: underline;
}

.news-item__note {
    font-size: var(--font-size-small);
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0;
}

/* System Japanese stack. No webfont origin is added, so the CSP is untouched. */
[lang="ja"] {
    font-family: 'Vend Sans', "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    line-height: 1.8;
}

.news-switch {
    display: none;
    gap: 6px;
    padding: 4px;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
}

/* Deliberately aria-pressed buttons rather than a tablist: above the breakpoint
   both panels are visible and these buttons are gone, so tab semantics would be
   describing a relationship that is not there. */
.news-switch__btn {
    flex: 1 1 0;
    min-height: var(--control-height);
    padding: 0 14px;
    border: none;
    border-radius: 4px;
    background: none;
    color: var(--text-secondary);
    font: inherit;
    font-size: var(--font-size-small);
    font-weight: 600;
    cursor: pointer;
}

.news-switch__btn[aria-pressed="true"] {
    background: var(--surface);
    color: var(--text-primary);
    box-shadow: var(--shadow);
}

@media (max-width: 1439px) {
    /* Stacked, so the measured height is meaningless: there is no adjacent
       Insights block to match. */
    .home-layout {
        --rails-height: auto;
        --rails-scroll-max: 24rem;
        display: flex;
        flex-direction: column;
        gap: 20px;
    }

    .home-layout > .page-main {
        order: 1;
    }

    /* The switch keeps its content width; the rails take the column. Both need
       saying, because `align-items: start` from the grid rule reads as
       `flex-start` here and would otherwise shrink the rails to their text. */
    .news-switch {
        order: 2;
        display: flex;
        align-self: start;
    }

    .news-rail {
        order: 3;
        position: static;
        align-self: stretch;
    }
}

.insights-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.insight-card {
    padding: 20px 0;
    border-bottom: 1px solid var(--border-color);
}

.insight-card:first-child {
    padding-top: 4px;
}

.insight-card:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.insight-meta {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
}

.insight-period {
    display: block;
    font-size: var(--font-size-label);
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent-header);
    margin-bottom: 6px;
}

.insight-published {
    font-size: var(--font-size-small);
    color: var(--text-secondary);
}

.insight-title {
    font-size: 1.125rem;
    line-height: 1.4;
    margin: 0 0 8px;
}

.insight-title a {
    color: var(--text-primary);
    text-decoration: none;
}

.insight-title a:hover {
    color: var(--link-color);
    text-decoration: underline;
}

.insight-teaser {
    line-height: 1.7;
    color: var(--text-secondary);
    max-width: 74ch;
    margin: 0 0 8px;
}

/* Gating state. Deliberately understated: a reader who cannot read the issue
   yet should see when it opens, not a sales interruption. */
.insight-gate-note,
.insight-open-note,
.insight-reviewers {
    font-size: var(--font-size-small);
    color: var(--text-secondary);
    margin: 0;
}

.insight-gate-note {
    font-weight: 600;
    color: var(--accent-header);
}

.insight-reviewers {
    margin-top: 6px;
    font-style: italic;
}

.insights-basis h3,
.insights-basis p {
    max-width: 78ch;
}

.insights-basis h3 {
    font-size: 1.05rem;
    margin-bottom: 10px;
    color: var(--accent-section);
}

.insights-basis p {
    font-size: var(--font-size-small);
    line-height: 1.7;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

/* ==============================================================================
   INSIGHTS ISSUE PAGE
   ============================================================================== */

.insight-issue {
    background-color: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-section);
    box-shadow: var(--shadow);
    padding: 28px;
    margin-bottom: 24px;
}

.insight-issue-header {
    padding-bottom: 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.insight-issue-title {
    font-size: var(--font-size-h2);
    line-height: 1.35;
    margin: 0 0 10px;
    color: var(--text-primary);
}

.insight-issue-meta {
    font-size: var(--font-size-small);
    color: var(--text-secondary);
    margin: 0;
}

.insight-teaser--lede {
    font-size: 1.0625rem;
    line-height: 1.75;
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 24px;
}

.insight-body {
    max-width: 74ch;
}

.insight-body h3 {
    font-size: 1.15rem;
    margin: 32px 0 12px;
    color: var(--accent-section);
}

.insight-body h4 {
    font-size: 1rem;
    margin: 24px 0 10px;
    color: var(--text-primary);
}

.insight-body h5 {
    font-size: 0.9375rem;
    margin: 20px 0 8px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.insight-body p,
.insight-body li {
    line-height: 1.8;
    color: var(--text-primary);
    margin-bottom: 14px;
}

.insight-body ul,
.insight-body ol {
    padding-left: 1.4rem;
    margin-bottom: 18px;
}

.insight-body a {
    color: var(--link-color);
    font-weight: 500;
}

.insight-body blockquote {
    margin: 20px 0;
    padding: 4px 0 4px 18px;
    border-left: 3px solid var(--accent-header);
    color: var(--text-secondary);
    font-style: italic;
}

.insight-body hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 32px 0;
}

.insight-body code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.875em;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    padding: 1px 5px;
}

/* Exhibits. Tables here carry derived statistics only — never fixing levels —
   so they are styled for reading rather than for scanning a grid. */
.insight-table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    font-size: var(--font-size-small);
    font-variant-numeric: tabular-nums;
}

.insight-table th,
.insight-table td {
    padding: 8px 12px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
}

.insight-table th:first-child,
.insight-table td:first-child {
    text-align: left;
}

.insight-table thead th {
    font-size: var(--font-size-label);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
}

.insight-table caption {
    caption-side: bottom;
    padding-top: 8px;
    font-size: var(--font-size-small);
    color: var(--text-secondary);
    text-align: left;
}

.insight-body figure {
    margin: 24px 0;
}

.insight-body img {
    display: block;
    max-width: 100%;
    height: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-control);
    background: var(--background);
}

.insight-body figcaption {
    margin-top: 8px;
    font-size: var(--font-size-small);
    line-height: 1.6;
    color: var(--text-secondary);
}

/* Subscriber gate */

.insight-gate {
    margin: 24px 0;
    padding: 24px;
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--accent-header);
    border-radius: var(--radius-control);
    background: var(--background);
}

.insight-gate h3 {
    font-size: 1.05rem;
    margin: 0 0 12px;
    color: var(--accent-section);
}

.insight-gate p {
    line-height: 1.75;
    color: var(--text-secondary);
    margin-bottom: 10px;
    max-width: 70ch;
}

.insight-gate-contact {
    font-size: var(--font-size-small);
}

.insight-issue-footer {
    margin-top: 36px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.insight-issue-footer h3 {
    font-size: 0.95rem;
    margin: 0 0 10px;
    color: var(--accent-section);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.insight-issue-footer h3:not(:first-child) {
    margin-top: 24px;
}

.insight-issue-footer p,
.insight-provenance li {
    font-size: var(--font-size-small);
    line-height: 1.7;
    color: var(--text-secondary);
    margin-bottom: 10px;
    max-width: 78ch;
}

.insight-provenance {
    list-style: none;
    padding: 0;
    margin: 0;
}

.insight-provenance code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.9em;
    word-break: break-word;
}

@media (max-width: 768px) {
    .insight-issue {
        padding: 20px 16px;
    }

    .insights-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .insight-body,
    .insight-teaser,
    .editorial-lede {
        max-width: none;
    }

    /* A stacked column of dashed empty boxes is noise, so reserved slots only
       hold their place where the row exists. */
    .insights-grid {
        grid-template-columns: 1fr;
    }

    .insight-tile--empty {
        display: none;
    }

    .insight-table {
        display: block;
        overflow-x: auto;
    }
}

/* ==============================================================================
   PRINT STYLES
   ============================================================================== */

@media print {
    /* Hide interactive elements */
    .site-header,
    .theme-toggle,
    .btn-login,
    .palette-picker,
    .analysis-hub-tabs,
    button,
    .toggle-icon,
    .section-header-collapsible {
        display: none !important;
    }
    
    body {
        padding-top: 0;
    }
    
    .analysis-hub-panel,
    .analysis-hub-panel[hidden] {
        display: block !important;
    }

    /* Expand all collapsible sections */
    .collapsible-content {
        display: block !important;
        max-height: none !important;
    }
    
    /* Remove shadows and transitions */
    * {
        box-shadow: none !important;
        transition: none !important;
        animation: none !important;
    }
    
    /* Optimize colors for print */
    body {
        background-color: white;
        color: black;
    }
    
    .container {
        max-width: 100%;
    }
    
    /* Page breaks */
    section {
        page-break-inside: avoid;
    }
    
    /* Ensure charts are visible */
    canvas {
        max-width: 100%;
        height: auto !important;
    }
    
    /* Footer at bottom */
    footer {
        page-break-before: always;
    }
    
    /* URLs for links */
    a[href]:after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
    
    /* Remove URL printing for internal links */
    a[href^="#"]:after,
    a[href^="javascript:"]:after {
        content: "";
    }
}

/* ==============================================================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================================================== */

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

/* Skip to main content link */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 10000;
}

.skip-to-main:focus {
    top: 0;
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #0000EE;
        --text-primary: #000000;
        --background: #FFFFFF;
        --border-color: #000000;
    }
    
    button, .btn-primary {
        border: 2px solid currentColor;
    }
}
