* {
    box-sizing: border-box;
}

:root {
    /* Set dashboard scale here: 1 = 100%, 0.8 = 80% */
    --dashboard-zoom: 0.8;

    --bg: #101112;
    --card: #1b1c1e;
    --text: #f5f5f6;
    --muted: #96999f;
    --accent: #ff6247;
    --border: #303134;
    --link: #9daaff;
}

body.light-mode {
    --bg: #f1f2f4;
    --card: #fff;
    --text: #202126;
    --muted: #666b75;
    --accent: #df5039;
    --border: #dedfe4;
    --link: #5969cf;
}

/* Global dashboard scale is controlled by --dashboard-zoom above. */
body {
    zoom: var(--dashboard-zoom);
    margin: 0;
    padding: 20px;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, sans-serif;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

/* HEADER */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 24px;
}

h1,
.page-title,
.filter-header h3,
.chart-section h3,
.news-panel h4 {
    color: var(--accent);
}

h1 {
    margin: 0 0 8px;
}

.subtitle {
    color: var(--muted);
    margin: 0;
}

.theme-toggle,
.clear-button {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 11px 16px;
}

/* NAVIGATION */
.category-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.category-button {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 13px 24px;
    font-weight: bold;
}

.category-button.active {
    background: var(--accent);
    color: #171717;
    border-color: var(--accent);
}

.page-title {
    margin: 0 0 18px;
    font-size: 23px;
}

/* GLOBAL MARKET COUNTDOWN */
.market-clock-section {
    margin-bottom: 24px;
}

.market-clock-title {
    color: var(--accent);
    font-size: 21px;
    margin: 0 0 8px;
}

.market-clock-subtitle {
    color: var(--muted);
    font-size: 13px;
    margin: 0 0 16px;
}

.market-clock-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.market-clock-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    min-width: 0;
}

.market-clock-name {
    color: var(--text);
    font-size: 17px;
    font-weight: bold;
    margin-bottom: 5px;
}

.market-clock-exchange {
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 14px;
}

.market-clock-status {
    font-size: 13px;
    font-weight: bold;
    margin-bottom: 10px;
}

.market-clock-status.open {
    color: #4ade80;
}

.market-clock-status.closed {
    color: var(--muted);
}

.market-clock-countdown {
    color: var(--accent);
    font-size: clamp(22px, 2.3vw, 32px);
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    margin-bottom: 12px;
}

.market-clock-next {
    color: var(--text);
    font-size: 12px;
    line-height: 1.6;
}

.market-clock-local {
    color: var(--muted);
    font-size: 12px;
    margin-top: 7px;
}

/* DYNAMIC SLICERS AND DISPLAY OPTIONS */
.filter-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    margin-bottom: 18px;
}

.filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
}

.filter-header h3 {
    margin: 0 0 6px;
}

.filter-description {
    color: var(--muted);
    font-size: 13px;
    margin: 0;
}

.filter-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
}

.filter-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 13px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

.filter-option:has(input:checked) {
    border-color: var(--accent);
    color: var(--accent);
}

.filter-option input {
    accent-color: var(--accent);
}

.results-info {
    color: var(--muted);
    font-size: 14px;
    margin: 14px 0 18px;
}

/* CHARTS AND GOOGLE SEARCH BUTTONS */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(var(--chart-columns, 1), minmax(0, 1fr));
    gap: 26px;
}

.chart-section {
    min-width: 0;
}

.chart-section h3 {
    font-size: 19px;
    margin: 0 0 12px;
}

.chart-heading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

.chart-heading-row h3 {
    margin: 0;
}

.google-search-button {
    display: inline-block;
    padding: 10px 15px;
    background: var(--accent);
    color: #171717;
    border-radius: 8px;
    text-decoration: none;
    font-weight: bold;
    font-size: 14px;
}

.google-search-button:hover {
    opacity: 0.85;
}

.google-search-button:focus-visible {
    outline: 2px solid var(--link);
    outline-offset: 3px;
}

.chart-container {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    height: 650px;
    min-width: 0;
    overflow: hidden;
}

.tradingview-widget-container {
    width: 100%;
    height: 100%;
}

.tradingview-widget-container__widget {
    width: 100%;
    height: calc(100% - 32px);
}

.empty-message {
    padding: 35px 20px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--muted);
    text-align: center;
}

.disclaimer {
    color: var(--muted);
    font-size: 12px;
    margin-top: 24px;
    line-height: 1.5;
}

button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

/* Each category has independent chart layout controls. */
.display-options {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 9px;
    margin: 0 0 18px;
}

.display-options-label {
    color: var(--muted);
    font-size: 14px;
    margin-right: 4px;
}

.layout-button {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 13px;
}

.layout-button.active {
    background: var(--accent);
    color: #171717;
    border-color: var(--accent);
    font-weight: bold;
}

@media (max-width: 1100px) {
    .charts-grid {
        grid-template-columns: repeat(min(var(--chart-columns, 1), 2), minmax(0, 1fr));
    }

}

@media (max-width: 700px), (orientation: landscape) and (hover: none) and (pointer: coarse) and (max-width: 1000px) and (max-height: 700px) {
    .charts-grid {
        grid-template-columns: 1fr;
    }

}

/* RESPONSIVE */
@media (max-width: 1100px) {
    .market-clock-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

}

@media (max-width: 900px) {
    body {
        padding: 12px;
    }

    .chart-container {
        height: 550px;
    }

    .category-button {
        flex: 1;
        padding: 12px;
    }

}

@media (max-width: 600px) {
    .market-clock-grid {
        grid-template-columns: 1fr;
    }

}

/* LIVE TAVEX PRICE TABLE IN THE HEADER */
.gold-header-panel {
    width: min(740px, 100%);
    margin-left: auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
}

.gold-header-title {
    color: var(--accent);
    font-weight: bold;
    font-size: 15px;
    margin-bottom: 7px;
}

.gold-price-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.gold-price-table th,
.gold-price-table td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}

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

.gold-price-table th {
    color: var(--muted);
    font-weight: 600;
}

.gold-price-table th:last-child,
.gold-price-table td:last-child {
    text-align: right;
    white-space: nowrap;
}

.gold-price-table td:last-child {
    color: var(--accent);
    font-weight: bold;
}

.gold-price-status {
    color: var(--muted);
    font-size: 11px;
    margin-top: 5px;
}

@media (max-width: 950px) {
    .gold-header-panel {
        order: 3;
        width: 100%;
        margin-left: 0;
    }

}

/* Premium dashboard redesign inspired by supplied reference */
body {
    padding: 28px 30px 40px 264px;
    min-height: 100vh;
    font-family: Inter,ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif;
    background: var(--bg);
    font-size: 14px;
}

body:before {
    content: "";
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 228px;
    background: #191a1c;
    border-right: 1px solid #2b2c2e;
    z-index: -1;
}

.header {
    min-height: 88px;
    padding: 8px 0 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 26px;
    align-items: flex-start;
}

h1 {
    font-size: 25px;
    letter-spacing: -.8px;
    color: var(--text);
    margin-bottom: 5px;
}

.subtitle {
    font-size: 12px;
}

.category-nav {
    position: fixed;
    left: 15px;
    top: 88px;
    width: 198px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 7px;
    border: 0;
    padding: 0;
    margin: 0;
    z-index: 10;
}

.category-nav:before {
    content: "◆  NAVIGATE  ◆";
    position: fixed;
    left: 49px;
    top: 34px;
    color: #fff;
    font-size: 14px;
    font-weight: 800;
    letter-spacing: .6px;
}

.category-button {
    text-align: left;
    border: 0;
    background: transparent;
    border-radius: 9px;
    padding: 15px 18px;
    color: #c2c3c6;
    font-size: 13px;
    font-weight: 600;
}

.category-button.active {
    background: #332522;
    color: #ff7058;
    border: 0;
}

.category-button:hover:not(.active) {
    background: #27282b;
}

.market-clock-title,
.page-title,
.filter-header h3,
.chart-section h3,
.gold-header-title {
    color: var(--text);
}

.market-clock-title {
    font-size: 17px;
}

.market-clock-subtitle {
    font-size: 12px;
}

.market-clock-grid {
    gap: 14px;
}

.market-clock-card,
.filter-panel,
.chart-container,
.gold-header-panel {
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--card);
    box-shadow: 0 5px 20px #0000000c;
}

.market-clock-card {
    padding: 20px;
}

.market-clock-name {
    font-size: 14px;
}

.market-clock-countdown {
    font-size: clamp(19px,2vw,29px);
    color: var(--text);
    letter-spacing: -.6px;
}

.market-clock-status.open {
    color: #5cc9a0;
}

.market-clock-status.closed {
    color: #ff806e;
}

.gold-header-panel {
    width: min(540px,100%);
    margin-left: auto;
}

.gold-header-title {
    font-size: 13px;
}

.gold-price-table {
    font-size: 11px;
}

.theme-toggle,
.clear-button,
.layout-button {
    border-radius: 9px;
    background: #292a2d;
    color: var(--text);
    padding: 10px 14px;
}

.filter-panel {
    padding: 20px;
}

.filter-option {
    border-radius: 9px;
    background: var(--bg);
}

.filter-option:has(input:checked) {
    background: #392622;
}

.google-search-button {
    background: #ff6247;
    color: #fff;
    border-radius: 8px;
    font-size: 12px;
}

.layout-button.active {
    background: #ff6247;
    color: #fff;
}

.chart-container {
    height: 520px;
    padding: 12px;
}

.charts-grid {
    gap: 18px;
}

.chart-section {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 17px;
    border-radius: 14px;
}

.chart-section .chart-container {
    border: 0;
    padding: 0;
    box-shadow: none;
}

.chart-section h3 {
    font-size: 15px;
}

.page-title {
    font-size: 19px;
}

.results-info {
    font-size: 12px;
}

@media (max-width:1050px) {
    body {
        padding-left: 215px;
    }

    body:before {
        width: 190px;
    }

    .category-nav {
        width: 165px;
    }

    .gold-header-panel {
        width: 100%;
        order: 3;
    }

}

@media (max-width: 700px), (orientation: landscape) and (hover: none) and (pointer: coarse) and (max-width: 1000px) and (max-height: 700px) {
    body {
        padding: 85px 14px 30px;
    }

    body:before {
        height: 65px;
        width: 100%;
        bottom: auto;
        z-index: 2;
    }

    .category-nav {
        position: relative;
        left: auto;
        top: auto;
        width: 100%;
        flex-direction: row;
        overflow: auto;
        margin-bottom: 18px;
    }

    .category-nav:before {
        top: 23px;
        left: 20px;
        z-index: 3;
    }

    .category-button {
        flex: 1;
        text-align: center;
        padding: 11px 8px;
    }

    .header {
        margin-bottom: 15px;
    }

    .market-clock-grid {
        grid-template-columns: repeat(2,minmax(0,1fr));
    }

    .chart-container {
        height: 410px;
    }

}

@media (max-width:420px) {
    .market-clock-grid {
        grid-template-columns: 1fr;
    }

}

/* Light-mode contrast fixes: sidebar navigation and dashboard controls. */
body.light-mode .theme-toggle,
body.light-mode .clear-button,
body.light-mode .layout-button {
    background: #ffffff;
    color: #202126;
    border: 1px solid #b9bec8;
}

body.light-mode .theme-toggle:hover,
body.light-mode .clear-button:hover,
body.light-mode .layout-button:hover:not(.active) {
    background: #e8ebf0;
}

body.light-mode .layout-button.active {
    background: #df5039;
    color: #ffffff;
    border-color: #df5039;
}

/* The sidebar remains dark in both themes, so keep its labels legible. */
body.light-mode .category-button {
    color: #e5e7eb;
}

body.light-mode .category-button.active {
    color: #ff806b;
}

body.light-mode .category-button:hover:not(.active) {
    color: #ffffff;
}

body.light-mode .filter-option:has(input:checked) {
    background: #fff0eb;
    color: #b83c29;
}

/* Slicers live in the left sidebar, beneath the category navigation. */
.sidebar-slicers {
    position: fixed;
    top: 340px;
    bottom: 22px;
    left: 15px;
    width: 198px;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 10;
    scrollbar-width: thin;
    scrollbar-color: #52545a transparent;
}

.sidebar-slicers .filter-panel {
    margin: 0;
    padding: 12px 9px;
    border: 1px solid var(--border);
    background: #1b1c1e;
    box-shadow: none;
}

.sidebar-slicers .filter-header {
    align-items: stretch;
    gap: 10px;
}

.sidebar-slicers .filter-header h3 {
    font-size: 13px;
    margin-bottom: 5px;
}

.sidebar-slicers .filter-description {
    font-size: 11px;
    line-height: 1.45;
}

.sidebar-slicers .clear-button {
    width: 100%;
    font-size: 11px;
    padding: 8px;
}

.sidebar-slicers .filter-options {
    flex-direction: column;
    align-items: stretch;
    gap: 7px;
    margin-top: 12px;
}

.sidebar-slicers .filter-option {
    width: 100%;
    padding: 9px 7px;
    font-size: 11px;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.sidebar-slicers .filter-option input {
    flex-shrink: 0;
}

.sidebar-slicers .filter-panel[hidden] {
    display: none !important;
}

body.light-mode .sidebar-slicers .filter-panel {
    background: #252629;
    border-color: #3a3c40;
    color: #f5f5f6;
}

body.light-mode .sidebar-slicers .filter-header h3 {
    color: #fff;
}

body.light-mode .sidebar-slicers .filter-description {
    color: #b9bbc2;
}

body.light-mode .sidebar-slicers .filter-option {
    background: #191a1c;
    border-color: #3b3d41;
    color: #f5f5f6;
}

body.light-mode .sidebar-slicers .filter-option:has(input:checked) {
    background: #49302b;
    color: #ff9b89;
}

body.light-mode .sidebar-slicers .clear-button {
    background: #34363a;
    color: #fff;
    border-color: #505258;
}

@media (max-width: 1050px) {
    .sidebar-slicers {
        width: 165px;
    }

}

@media (max-width: 700px), (orientation: landscape) and (hover: none) and (pointer: coarse) and (max-width: 1000px) and (max-height: 700px) {
    .sidebar-slicers {
        position: static;
        width: 100%;
        max-height: 270px;
        margin-bottom: 18px;
        overflow-y: auto;
    }

    .sidebar-slicers .filter-options {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .sidebar-slicers .filter-option {
        width: auto;
    }

}

/* Category heading, display layout and count beneath the sidebar slicer. */
.sidebar-page-controls[hidden] {
    display: none !important;
}

.sidebar-page-controls .page-title {
    color: #f5f5f6;
    font-size: 14px;
    margin: 18px 2px 10px;
    line-height: 1.35;
}

.sidebar-page-controls .display-options {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 7px;
    margin: 0 0 12px;
}

.sidebar-page-controls .display-options-label {
    color: #b9bbc2;
    font-size: 11px;
    margin: 0 0 2px 2px;
}

.sidebar-page-controls .layout-button {
    width: 100%;
    text-align: left;
    padding: 10px 11px;
    font-size: 11px;
    background: #292a2d;
    color: #f5f5f6;
    border: 1px solid #414349;
}

.sidebar-page-controls .layout-button.active {
    background: #ff6247;
    border-color: #ff6247;
    color: #fff;
}

.sidebar-page-controls .results-info {
    color: #b9bbc2;
    font-size: 11px;
    line-height: 1.5;
    margin: 0 2px 12px;
}

body.light-mode .sidebar-page-controls .page-title {
    color: #fff;
}

body.light-mode .sidebar-page-controls .layout-button:not(.active) {
    background: #34363a;
    color: #fff;
    border-color: #505258;
}

@media (max-width: 700px), (orientation: landscape) and (hover: none) and (pointer: coarse) and (max-width: 1000px) and (max-height: 700px) {
    .sidebar-page-controls .display-options {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .sidebar-page-controls .layout-button {
        width: auto;
    }

}

/* Three-panel desktop overview: market clocks, BG gold, market quotes. */
.overview-row {
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr) minmax(0, 1.08fr);
    gap: 18px;
    align-items: stretch;
    margin: -8px 0 16px;
}

.overview-row .market-clock-section {
    margin: 0;
    min-width: 0;
}

.overview-row .market-clock-title,
.overview-row .market-clock-subtitle {
    display: none;
}

.overview-row .market-clock-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 9px;
    height: 100%;
}

.overview-row .market-clock-card {
    padding: 11px 14px;
    min-height: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.overview-row .market-clock-name {
    font-size: 12px;
    margin-bottom: 2px;
}

.overview-row .market-clock-exchange {
    font-size: 10px;
    margin-bottom: 5px;
}

.overview-row .market-clock-status {
    font-size: 10px;
    margin-bottom: 4px;
}

.overview-row .market-clock-countdown {
    font-size: clamp(17px, 1.45vw, 23px);
    margin-bottom: 4px;
}

.overview-row .market-clock-next,
.overview-row .market-clock-local {
    font-size: 10px;
    line-height: 1.35;
}

.overview-row .market-clock-local {
    margin-top: 2px;
}

.overview-row .gold-header-panel {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 16px 19px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-width: 0;
}

.overview-row .gold-header-title {
    font-size: 14px;
    margin-bottom: 12px;
}

.overview-row .gold-price-table {
    font-size: 12px;
}

.overview-row .gold-price-table th,
.overview-row .gold-price-table td {
    padding: 9px 7px;
}

.overview-row .gold-price-status {
    margin-top: 12px;
}

/* Desktop TradingView Market Quotes widget. */
.overview-row .market-quotes-panel {
    min-width: 0;
    height: 100%;
    min-height: 340px;
    overflow: hidden;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 5px 20px #0000000c;
}
.overview-row .market-quotes-widget,
.overview-row .market-quotes-widget .tradingview-widget-container,
.overview-row .market-quotes-widget .tradingview-widget-container__widget {
    width: 100%;
    height: 100%;
    min-height: 340px;
}

/* Keep the controls, remove redundant sidebar headings and helper labels. */
.sidebar-slicers .filter-header > div,
.sidebar-page-controls > .page-title,
.sidebar-page-controls .display-options-label {
    display: none;
}

.sidebar-slicers .filter-header {
    display: block;
}

.sidebar-page-controls .display-options {
    margin-top: 13px;
}

@media (max-width: 1100px) {
    .overview-row {
        grid-template-columns: 1fr;
    }

    .overview-row .market-clock-grid {
        min-height: 220px;
    }

    .overview-row .gold-header-panel {
        min-height: 160px;
    }

}

@media (max-width: 700px), (orientation: landscape) and (hover: none) and (pointer: coarse) and (max-width: 1000px) and (max-height: 700px) {
    .overview-row .market-clock-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

}

@media (max-width: 430px) {
    .overview-row .market-clock-grid {
        grid-template-columns: 1fr;
    }

}


/* ===========================================================
   DESKTOP CHART FOCUS MODE
   Existing chart stays in its original DOM position.
   =========================================================== */
.chart-heading-row .chart-focus-button {
    margin-left: auto;
    flex-shrink: 0;
}
.chart-focus-button {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    cursor: pointer;
}
.chart-focus-button:hover { border-color: var(--accent); color: var(--accent); }
.chart-focus-overlay[hidden], .chart-focus-close[hidden] { display: none !important; }
.chart-focus-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(0, 0, 0, .45);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}
.chart-section.chart-focused {
    position: fixed;
    top: 50%;
    left: 50%;
    right: auto;
    bottom: auto;
    transform: translate(-50%, -50%);
    z-index: 9999;
    width: calc(90vw / var(--dashboard-zoom));
    height: calc(90dvh / var(--dashboard-zoom));
    max-width: none;
    max-height: none;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin: 0;
    box-shadow: 0 25px 80px rgba(0, 0, 0, .5);
}
.chart-section.chart-focused .chart-container {
    flex: 1;
    height: auto;
    min-height: 0;
}
.chart-focus-close {
    position: fixed;
    top: calc(2vh / var(--dashboard-zoom));
    right: calc(2vw / var(--dashboard-zoom));
    z-index: 10000;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 9px;
    width: 40px;
    height: 40px;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;

    display: flex;
    align-items: center;
    justify-content: center;
}
body.chart-focus-active { overflow: hidden; }

/* ===========================================================
   MOBILE-ONLY VIEW: desktop rules above are unchanged.
   Bottom category navigation; slicer above full-width charts.
   BG Gold opens the existing live D1 table in the mobile menu.
   =========================================================== */
.mobile-gold-button { display: none; }

@media (max-width: 700px), (orientation: landscape) and (hover: none) and (pointer: coarse) and (max-width: 1000px) and (max-height: 700px) {
    :root { --dashboard-zoom: 1; }
    body {
        zoom: 1;
        padding: 14px 10px 84px;
        min-width: 0;
        overflow-x: hidden;
    }
    body::before { display: none; }
    .header {
        min-height: 0;
        padding: 3px 0 12px;
        margin-bottom: 12px;
        border-bottom: 1px solid var(--border);
    }
    .header h1 { font-size: 17px; letter-spacing: -.35px; }
    .header .subtitle { font-size: 10px; }
    .theme-toggle { display: none !important; }

    /* Persistent, minimal bottom navigation */
    .category-nav {
        position: fixed;
        z-index: 100;
        left: 0;
        right: 0;
        top: auto;
        bottom: 0;
        width: 100%;
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 3px;
        padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
        margin: 0;
        overflow: visible;
        border: 0;
        border-top: 1px solid var(--border);
        background: #191a1c;
    }
    .category-nav::before { display: none; }
    .category-button, .mobile-gold-button {
        display: block;
        width: 100%;
        min-width: 0;
        padding: 11px 2px;
        font-size: 11px;
        text-align: center;
        border-radius: 8px;
        white-space: nowrap;
    }
    .category-button.active { background: #332522; color: #ff806b; }

    /* Market overview is available through the BG Gold menu on mobile. */
    .overview-row { display: none; }
    .overview-row .market-quotes-panel { display: none !important; }

    /* Mobile only: slicer directly below the headline, full-width charts below. */
    main { margin: 0; min-width: 0; }
    .sidebar-slicers {
        position: relative;
        z-index: 5;
        top: auto;
        right: auto;
        bottom: auto;
        left: auto;
        width: 100%;
        max-height: 132px;
        margin: 0 0 10px;
        overflow-y: auto;
        overflow-x: hidden;
        scrollbar-width: thin;
    }
    .sidebar-slicers .filter-panel { padding: 8px; }
    .sidebar-slicers .filter-header { display: flex; justify-content: flex-start; align-items: center; }
    .sidebar-slicers .filter-header .clear-button { order: -1; flex-shrink: 0; }
    .sidebar-slicers .clear-button { width: auto; padding: 6px 10px; font-size: 10px; }
    .sidebar-slicers .filter-options {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 5px;
        margin-top: 7px;
    }
    .sidebar-slicers .filter-option {
        width: auto;
        max-width: 100%;
        padding: 6px 8px;
        gap: 5px;
        font-size: 11px;
        line-height: 1.25;
        overflow-wrap: anywhere;
    }
    .sidebar-slicers .filter-option input { width: 14px; height: 14px; margin: 0; }
    .sidebar-page-controls .display-options,
    .sidebar-page-controls .results-info { display: none; }

    .charts-grid { grid-template-columns: minmax(0, 1fr) !important; gap: 12px; }
    .chart-section { padding: 8px; min-width: 0; border-radius: 10px; }
    .chart-heading-row { gap: 6px; margin-bottom: 7px; }
    .chart-heading-row h3 { font-size: 12px; overflow-wrap: anywhere; }
    .google-search-button { font-size: 10px; padding: 6px 7px; }
    .chart-focus-button, .chart-focus-overlay, .chart-focus-close { display: none !important; }
    /* Fill the available viewport between slicer and fixed bottom nav.
       A floor keeps TradingView usable on shorter landscape screens. */
    .chart-container {
        height: max(260px, calc(100dvh - 255px - env(safe-area-inset-bottom)));
        min-width: 0;
        padding: 0;
    }
    .tradingview-widget-container { min-width: 0; }
    .disclaimer { font-size: 10px; margin-left: 0; }

    /* Gold menu: use the existing live table and existing API polling. */
    body.mobile-gold-view main,
    body.mobile-gold-view .sidebar-slicers,
    body.mobile-gold-view .disclaimer { display: none !important; }
    body.mobile-gold-view .overview-row {
        display: block;
        margin: 0;
    }
    body.mobile-gold-view .market-clock-section { display: none; }
    body.mobile-gold-view .gold-header-panel {
        display: block;
        width: 100%;
        height: auto;
        min-height: 0;
        padding: 12px 9px;
    }
    .gold-price-table { table-layout: auto; width: 100%; }
    body.mobile-gold-view .gold-price-table { font-size: 10px; }
    body.mobile-gold-view .gold-price-table th,
    body.mobile-gold-view .gold-price-table td {
        padding: 9px 4px;
        overflow-wrap: anywhere;
    }
    body.mobile-gold-view .gold-price-table th:last-child,
    body.mobile-gold-view .gold-price-table td:last-child { white-space: nowrap; }
}


/* =====================================================
   FINANCIAL GLOBE - FULLSCREEN VIEW
   ===================================================== */

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.globe-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;

  padding: 10px 16px;

  border: 1px solid var(--accent);
  border-radius: 10px;

  background: var(--card);
  color: var(--text);

  font-size: 13px;
  font-weight: 700;

  white-space: nowrap;
  cursor: pointer;
}

.globe-toggle:hover {
  border-color: var(--link);
}

.globe-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.globe-toggle-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: currentColor;
}

/* Fullscreen globe container */

.globe-page {
  position: fixed;
  inset: 0;

  width: 100%;
  height: 100%;

  margin: 0;
  padding: 0;

  border: 0;
  background: #101112;

  z-index: 9999;
  overflow: hidden;
}

.globe-page iframe {
  display: block;

  width: 100%;
  height: 100%;

  margin: 0;
  padding: 0;

  border: 0;
  border-radius: 0;

  background: #101112;
}

/* Globe view state */

body.globe-view-active {
  zoom: 1;
  padding: 0;
  margin: 0;
  overflow: hidden;
}

body.globe-view-active::before {
  display: none;
}

body.globe-view-active .category-nav,
body.globe-view-active .sidebar-slicers,
body.globe-view-active .sidebar-page-controls,
body.globe-view-active .overview-row,
body.globe-view-active main,
body.globe-view-active .disclaimer {
  display: none;
}

body.globe-view-active .header {
  position: fixed;
  top: 12px;
  right: 18px;

  z-index: 10001;

  width: auto;
  min-height: 0;

  margin: 0;
  padding: 0;

  border: 0;
  background: transparent;
}

body.globe-view-active .header > :not(.header-actions) {
  display: none;
}

body.globe-view-active .header-actions {
  margin: 0;
}

body.globe-view-active .theme-toggle {
  display: none;
}

body.globe-view-active .globe-toggle {
  background: rgba(20, 23, 28, 0.94);
  color: #ffffff;

  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 9px;

  padding: 11px 17px;

  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.35);
}

/* Responsive fullscreen globe */

@media (max-width: 700px) {
  .header-actions {
    gap: 6px;
  }

  .globe-toggle {
    padding: 8px 10px;
    font-size: 11px;
  }

  .globe-toggle-icon {
    width: 20px;
    height: 20px;
  }

  body.globe-view-active .header {
    top: 10px;
    right: 10px;
  }

  body.globe-view-active .globe-toggle {
    padding: 9px 12px;
    font-size: 12px;
  }
}


#instrumentDialog { width:min(680px,94vw); max-height:85vh; overflow:auto; background:var(--card); color:var(--text); border:1px solid var(--border); border-radius:14px; padding:24px; }
#instrumentDialog::backdrop { background:#0009; }
.instrument-top { display:flex; justify-content:space-between; align-items:center; gap:12px; }
#instrumentDialog label { display:block; margin:12px 0 5px; }
#instrumentDialog input,#instrumentDialog select,#instrumentDialog button { background:var(--bg); color:var(--text); border:1px solid var(--border); border-radius:6px; padding:10px; font:inherit; }
#instrumentDialog input,#instrumentDialog select { width:100%; }
.instrument-result { display:block; width:100%; text-align:left; margin:6px 0; }
.instrument-result:hover { border-color:var(--accent)!important; }
#manualInstrument { display:grid; gap:8px; margin-top:10px; }
#addInstrument { border-color:var(--accent); color:var(--accent); }
.category-nav { flex-wrap:wrap; }
body.globe-view-active #instrumentDialog { display:none; }

/* V4: one scrollable sidebar, with controls in normal document flow. */
#addInstrument { background:var(--accent); color:#171717; border:1px solid var(--accent); border-radius:9px; padding:11px 16px; font-weight:700; }
body.globe-view-active #addInstrument { display:none; }
@media (min-width:701px) {
.watchlist-sidebar { position:fixed; top:88px; bottom:16px; left:15px; width:198px; overflow:auto; z-index:10; scrollbar-width:thin; }
.watchlist-sidebar .category-nav { position:static; width:100%; flex-wrap:nowrap; gap:3px; }
.watchlist-sidebar .category-button { padding:10px 12px; }
.watchlist-sidebar .sidebar-slicers { position:static; width:100%; margin-top:12px; overflow:visible; }
}
@media (min-width:701px) and (max-width:1050px) { .watchlist-sidebar { width:165px; } }
@media (max-width:700px), (orientation:landscape) and (hover:none) and (pointer:coarse) and (max-width:1000px) and (max-height:700px) {
.watchlist-sidebar { position:static; width:100%; overflow:visible; }
.watchlist-sidebar .category-nav { position:fixed; width:100%; display:grid; grid-template-columns:repeat(5,minmax(0,1fr)); }
.watchlist-sidebar .sidebar-slicers { position:relative; width:100%; margin-top:0; overflow:auto; }
.watchlist-sidebar .category-button { padding:10px 2px; font-size:10px; }
}
body.globe-view-active .watchlist-sidebar { display:none; }

/* Unified dashboard toolbar; only the return control remains in globe view. */
body:not(.globe-view-active) .header-actions > button {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    box-sizing: border-box;
}
body:not(.globe-view-active) .header-actions > button:hover {
    border-color: var(--accent);
    color: var(--accent);
}
body.globe-view-active .header-actions > button:not(#globeToggle) {
    display: none !important;
}
.header-actions { flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 700px) {
    body:not(.globe-view-active) .header-actions > button {
        min-height: 36px;
        padding: 7px 10px;
        font-size: 11px;
    }
}
.header-actions > [hidden], body.globe-view-active #accountStatus { display:none !important; }
#accountStatus { font-size:12px; max-width:180px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
#accountLogin:disabled { opacity:.55; cursor:not-allowed; }

#accountDialog { background:var(--card); color:var(--text); border:1px solid var(--border); border-radius:12px; padding:24px; width:min(400px,90vw); }
#accountDialog label {display:block;margin:12px 0;} #accountDialog input {display:block;width:100%;box-sizing:border-box;padding:10px;background:var(--card);color:var(--text);border:1px solid var(--border);border-radius:8px;} .account-buttons {display:flex;gap:8px;flex-wrap:wrap;} .account-buttons button {background:var(--card);color:var(--text);border:1px solid var(--border);border-radius:10px;padding:10px 16px;cursor:pointer;font-weight:700;}
