/* ==========================================
   ПЕРЕМЕННЫЕ И БАЗОВЫЕ СТИЛИ
   ========================================== */

:root {
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --bg-card: rgba(30, 41, 59, 0.7);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;

    --accent-purple: #6366f1;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --accent-orange: #f59e0b;

    --border-color: rgba(255, 255, 255, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

html {
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    color: var(--text-main);
    background: var(--bg-gradient);
}

/* ==========================================
   ОСНОВНОЙ КАРКАС
   ========================================== */

.dashboard-container {
    display: flex;
    min-height: 100vh;
}

/* ==========================================
   БОКОВОЕ МЕНЮ
   ========================================== */

.sidebar {
    display: flex;
    flex-direction: column;
    width: 280px;
    padding: 2.5rem 1.5rem;
    background: rgba(15, 23, 42, 0.6);
    border-right: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
}

.logo h2 {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 2.5rem;
    color: #ffffff;
    font-size: 1.5rem;
    font-weight: 700;
}

.logo i {
    color: var(--accent-purple);
    filter: drop-shadow(0 0 8px rgba(99, 102, 241, 0.6));
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 0.6rem;
    padding: 0.9rem 1.2rem;
    color: var(--text-muted);
    border-radius: 10px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-links a:hover,
.nav-links a.active {
    color: #ffffff;
    background: rgba(99, 102, 241, 0.15);
    box-shadow: inset 0 0 0 1px rgba(99, 102, 241, 0.4);
}

.nav-links a.active {
    background: var(--accent-purple);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.3);
}

/* ==========================================
   ОСНОВНАЯ ОБЛАСТЬ
   ========================================== */

.main-content {
    flex: 1;
    min-width: 0;
    padding: 2.5rem;
    overflow-y: auto;
}

/* ==========================================
   ВКЛАДКИ
   ========================================== */

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ==========================================
   ВЕРХНЯЯ ПАНЕЛЬ
   ========================================== */

.top-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2.5rem;
    gap: 1rem;
}

.top-header h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.subtitle {
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.refresh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px 24px;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    cursor: pointer;
    backdrop-filter: blur(8px);
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.refresh-btn:hover {
    background: var(--accent-purple);
    border-color: var(--accent-purple);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.refresh-btn:active {
    transform: scale(0.97);
}

/* ==========================================
   КАРТОЧКИ СТАТИСТИКИ
   ========================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 1.8rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(16px);
    transition: transform 0.3s ease, border-color 0.3s ease;
}

.stat-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
    transform: translateY(-4px);
}

.stat-icon,
.stat-icon-rub {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    flex-shrink: 0;
    border-radius: 14px;
    font-size: 1.6rem;
}

.stat-icon-rub {
    color: #38bdf8;
    background: rgba(14, 165, 233, 0.15);
}

.stat-icon.purple {
    color: #818cf8;
    background: rgba(99, 102, 241, 0.15);
}

.stat-icon.green {
    color: #34d399;
    background: rgba(16, 185, 129, 0.15);
}

.stat-icon.orange {
    color: #fbbf24;
    background: rgba(245, 158, 11, 0.15);
}

.stat-icon.gold {
    color: #facc15;
    background: rgba(250, 204, 21, 0.15);
}

.stat-icon.silver {
    color: #cbd5e1;
    background: rgba(148, 163, 184, 0.15);
}

.stat-icon.platinum {
    color: #2dd4bf;
    background: rgba(45, 212, 191, 0.15);
}

.stat-icon.palladium {
    color: #c084fc;
    background: rgba(168, 85, 247, 0.15);
}

.stat-info h3 {
    margin-bottom: 4px;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.crypto-trend {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 8px;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
}

.crypto-trend.up {
    color: #34d399;
    background: rgba(16, 185, 129, 0.12);
}

.crypto-trend.down {
    color: #f87171;
    background: rgba(239, 68, 68, 0.12);
}

.crypto-trend.stable {
    color: #94a3b8;
    background: rgba(148, 163, 184, 0.1);
}

/* ==========================================
   ОБЩИЕ КОНТЕЙНЕРЫ ГРАФИКОВ
   ========================================== */

.charts-grid-full {
    display: grid;
    grid-template-columns: 1fr;
    margin-bottom: 2.5rem;
}

.chart-container {
    padding: 2rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(16px);
}

.chart-container h3 {
    margin-bottom: 1.5rem;
    font-size: 1.2rem;
    font-weight: 600;
}

/* ==========================================
   ГРАФИК ВАЛЮТ
   ========================================== */

.css-chart {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    gap: 20px;
    height: 260px;
    margin-top: 1rem;
    padding: 20px 10px 10px;
    border-bottom: 2px solid var(--border-color);
}

.chart-bar-wrapper {
    display: flex;
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
}

.chart-bar {
    position: relative;
    width: 100%;
    max-width: 80px;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    transition: height 1s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s ease;
}

.chart-bar:hover {
    filter: brightness(1.1);
    transform: scaleX(1.05);
}

.chart-bar.ruble {
    background: linear-gradient(to top, #0284c7, #38bdf8);
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.3);
}

.chart-bar.purple {
    background: linear-gradient(to top, #4f46e5, #818cf8);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.3);
}

.chart-bar.green {
    background: linear-gradient(to top, #059669, #34d399);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.3);
}

.chart-bar.orange {
    background: linear-gradient(to top, #d97706, #fbbf24);
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.3);
}

.chart-bar-value {
    margin-bottom: 8px;
    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0.9;
}

.chart-bar-label {
    margin-top: 12px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
}

/* ==========================================
   ТАБЛИЦЫ
   ========================================== */

.currency-table-container {
    padding: 1.5rem;
    overflow: hidden;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
}

.currency-table {
    width: 100%;
    min-width: 700px;
    border-collapse: collapse;
    color: var(--text-main);
    font-size: 0.95rem;
    text-align: left;
}

.currency-table th {
    padding: 12px 16px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    white-space: nowrap;
}

.currency-table td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 500;
    white-space: nowrap;
}

.currency-table tr:last-child td {
    border-bottom: none;
}

.currency-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.currency-name {
    color: #818cf8 !important;
    font-weight: 700 !important;
}

.td-trend.up {
    color: #34d399 !important;
}

.td-trend.down {
    color: #f87171 !important;
}

/* ==========================================
   ВКЛАДКА «ТРЕНДЫ»
   ========================================== */

#tab-trends > * + * {
    margin-top: 2rem;
}

#tab-trends .top-header {
    margin-bottom: 0;
}

.leader-banner {
    padding: 2rem;
    background: linear-gradient(
        135deg,
        rgba(245, 158, 11, 0.1) 0%,
        rgba(30, 41, 59, 0.7) 100%
    );
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-radius: 16px;
}

.leader-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 1rem;
    padding: 4px 10px;
    color: #111827;
    background: var(--accent-orange);
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
}

.leader-banner h2 {
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.leader-name {
    color: var(--accent-green);
}

.leader-banner p {
    color: var(--text-muted);
    line-height: 1.6;
}

.block-title {
    margin: 0;
    padding-top: 0.5rem;
    color: var(--text-main);
    font-size: 1.15rem;
    font-weight: 700;
}

.block-title i {
    margin-right: 0.5rem;
    color: var(--accent-purple);
}

/* Граница перед разделами после первого */
#tab-trends .block-title:not(:first-of-type) {
    padding-top: 2rem;
    border-top: 1px solid var(--border-color);
}

/* Убираем лишние отступы внутренних разделов */
#tab-trends .charts-grid-full,
#tab-trends .metals-stats-grid,
#tab-trends .metal-chart-section {
    margin-bottom: 0;
}

.metals-stats-grid {
    margin-top: 0;
}

.metal-chart-section {
    padding: 0;
}

/* ==========================================
   ОБЩИЙ SVG-ГРАФИК МЕТАЛЛОВ
   ========================================== */

.metal-trend-box {
    width: 100%;
    padding: 1.75rem;
}

.metal-chart-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metal-chart-row h3 {
    margin: 0;
}

.metal-chart-description {
    margin: 6px 0 0;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.metal-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px 14px;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    font-size: 0.78rem;
    white-space: nowrap;
}

.legend-item i {
    display: block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-gold i {
    background: #f59e0b;
}

.legend-silver i {
    background: #a8b2bf;
}

.legend-platinum i {
    background: #06b6d4;
}

.legend-palladium i {
    background: #a855f7;
}

.svg-viewport {
    width: 100%;
    padding: 10px 5px;
    overflow-x: auto;
}

.metal-svg-canvas {
    display: block;
    width: 100%;
    min-width: 600px;
    height: 250px;
    overflow: visible;
}

.svg-grid-dash {
    stroke: var(--border-color);
    stroke-width: 1;
    stroke-dasharray: 4 4;
}

.svg-axis {
    stroke: rgba(148, 163, 184, 0.45);
    stroke-width: 1.5;
}

.metal-path-line {
    fill: none;
    stroke-width: 4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.metal-line-gold {
    stroke: #f59e0b;
}

.metal-line-silver {
    stroke: #a8b2bf;
}

.metal-line-platinum {
    stroke: #06b6d4;
}

.metal-line-palladium {
    stroke: #a855f7;
}

.metal-node-dot {
    stroke: #ffffff;
    stroke-width: 2px;
}

.node-gold {
    fill: #f59e0b;
}

.node-silver {
    fill: #a8b2bf;
}

.node-platinum {
    fill: #06b6d4;
}

.node-palladium {
    fill: #a855f7;
}

.svg-timeline-labels {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    min-width: 600px;
    margin-top: 12px;
    padding: 0 5px;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-align: center;
}

/* ==========================================
   НАСТРОЙКИ
   ========================================== */

.settings-box {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.setting-item:last-child {
    padding-bottom: 0;
    border-bottom: none;
}

.setting-info h3 {
    margin-bottom: 4px;
    font-size: 1.1rem;
}

.setting-info p {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
    flex-shrink: 0;
}

.switch input {
    width: 0;
    height: 0;
    opacity: 0;
}

.slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background-color: #475569;
    border-radius: 34px;
    transition: 0.4s;
}

.slider::before {
    position: absolute;
    bottom: 4px;
    left: 4px;
    width: 18px;
    height: 18px;
    content: "";
    background-color: #ffffff;
    border-radius: 50%;
    transition: 0.4s;
}

input:checked + .slider {
    background-color: var(--accent-green);
}

input:checked + .slider::before {
    transform: translateX(24px);
}

/* ==========================================
   СВЕТЛАЯ ТЕМА
   ========================================== */

body.light-theme {
    --bg-gradient: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
    --bg-card: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: rgba(15, 23, 42, 0.08);
}

body.light-theme .sidebar {
    background: #f8fafc;
}

body.light-theme .logo h2 {
    color: #0f172a;
}

body.light-theme .nav-links a {
    color: #475569;
}

body.light-theme .nav-links a:hover {
    color: var(--accent-purple);
    background: rgba(99, 102, 241, 0.08);
}

body.light-theme .nav-links a.active {
    color: #ffffff;
    background: var(--accent-purple);
}

body.light-theme .refresh-btn {
    color: #0f172a;
    background: #ffffff;
    border-color: #cbd5e1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

body.light-theme .refresh-btn:hover {
    color: #ffffff;
    background: var(--accent-purple);
    border-color: var(--accent-purple);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

body.light-theme .chart-bar-value {
    color: #0f172a;
}

body.light-theme .currency-table tr:hover td {
    background: rgba(15, 23, 42, 0.02);
}

body.light-theme .currency-name {
    color: #4f46e5 !important;
}

body.light-theme .td-trend.up {
    color: #059669 !important;
}

body.light-theme .td-trend.down {
    color: #dc2626 !important;
}

body.light-theme .leader-banner {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15) 0%, #ffffff 100%);
    border-color: rgba(245, 158, 11, 0.3);
}

body.light-theme .leader-banner h2 {
    color: #0f172a;
}

body.light-theme .leader-name {
    color: #059669;
}

body.light-theme .leader-banner p {
    color: #334155;
    font-weight: 500;
}

/* ==========================================
   АДАПТИВНОСТЬ
   ========================================== */

@media (max-width: 1024px) {
    .dashboard-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        padding: 1.5rem;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .logo h2 {
        margin-bottom: 0;
    }

    .nav-links {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        margin-top: 15px;
    }

    .nav-links a {
        margin-bottom: 0;
    }

    .main-content {
        padding: 1.5rem;
    }

    .top-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .refresh-btn {
        width: 100%;
    }
}

@media (max-width: 800px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .metal-chart-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .metal-legend {
        justify-content: flex-start;
    }
}

@media (max-width: 600px) {
    .main-content {
        padding: 1rem;
    }

    .top-header h1 {
        font-size: 1.55rem;
    }

    .chart-container {
        padding: 1rem;
    }

    .stat-card {
        padding: 1.25rem;
    }

    .css-chart {
        gap: 10px;
        height: 220px;
        padding-right: 0;
        padding-left: 0;
    }

    .chart-bar {
        max-width: 54px;
    }

    .chart-bar-value {
        font-size: 0.72rem;
    }

    .chart-bar-label {
        font-size: 0.7rem;
    }

    .setting-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .setting-item .refresh-btn {
        width: 100%;
    }

    #tab-trends > * + * {
        margin-top: 1.5rem;
    }

    #tab-trends .block-title:not(:first-of-type) {
        padding-top: 1.5rem;
    }

    .metal-trend-box {
        padding: 1rem;
    }
}