* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    direction: rtl;
    background: radial-gradient(circle at top, #1d4ed8 0, #020617 45%, #000 100%);
    color: #e5e7eb;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* پس‌زمینه شیشه‌ای */
.bg-overlay {
    position: fixed;
    inset: 0;
    background-image:
        radial-gradient(circle at 10% 20%, rgba(56, 189, 248, 0.12) 0, transparent 50%),
        radial-gradient(circle at 90% 80%, rgba(52, 211, 153, 0.12) 0, transparent 50%);
    opacity: 0.7;
    pointer-events: none;
    z-index: -1;
}

.app-container {
    max-width: 1100px;
    margin: 20px auto 40px;
    padding: 20px;
    backdrop-filter: blur(18px);
    background: rgba(15, 23, 42, 0.88);
    border-radius: 24px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.6);
}

/* هدر */

.app-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 24px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.3);
    padding-bottom: 16px;
}

.title-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btc-icon {
    font-size: 32px;
    background: radial-gradient(circle, #f97316, #facc15);
    border-radius: 999px;
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(234, 179, 8, 0.5);
}

.app-header h1 {
    font-size: 1.4rem;
    margin-bottom: 4px;
}

.app-header p {
    font-size: 0.85rem;
    color: #9ca3af;
}

/* کنترل‌ها */

.controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

#refresh-btn {
    padding: 8px 16px;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: #022c22;
    box-shadow: 0 10px 20px rgba(34, 197, 94, 0.4);
    transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}

#refresh-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 28px rgba(34, 197, 94, 0.55);
    opacity: 0.95;
}

#refresh-btn:active {
    transform: translateY(1px) scale(0.98);
    box-shadow: 0 6px 14px rgba(34, 197, 94, 0.4);
}

.select-wrapper {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8rem;
}

.select-wrapper label {
    color: #9ca3af;
}

.select-wrapper select {
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.5);
    background: rgba(15, 23, 42, 0.9);
    color: #e5e7eb;
    font-size: 0.85rem;
    outline: none;
}

/* محتوای اصلی */

.main-content {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* کارت‌های آمار */

.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.stat-card {
    border-radius: 18px;
    padding: 14px 16px;
    background: linear-gradient(145deg, rgba(15, 23, 42, 0.95), rgba(30, 64, 175, 0.7));
    border: 1px solid rgba(148, 163, 184, 0.3);
    box-shadow: 0 18px 35px rgba(15, 23, 42, 0.9);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: "";
    position: absolute;
    inset: -40%;
    background: radial-gradient(circle at 10% 20%, rgba(56, 189, 248, 0.25) 0, transparent 55%);
    opacity: 0;
    transition: opacity 0.2s ease;
}

.stat-card:hover::before {
    opacity: 1;
}

.stat-card h3 {
    font-size: 0.9rem;
    color: #9ca3af;
    margin-bottom: 6px;
}

.stat-card .value {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.stat-card .label {
    font-size: 0.75rem;
    color: #a5b4fc;
}

/* رنگ خاص برای کارت‌ها */

#avg-card .value {
    color: #e5e7eb;
}

#min-card .value {
    color: #4ade80;
}

#max-card .value {
    color: #fb7185;
}

/* جدول */

.table-section {
    background: rgba(15, 23, 42, 0.9);
    border-radius: 18px;
    padding: 16px 16px 10px;
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 10px;
}

.section-header h2 {
    font-size: 1rem;
}

.section-header p {
    font-size: 0.8rem;
    color: #9ca3af;
}

.table-wrapper {
    width: 100%;
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid rgba(55, 65, 81, 0.9);
    background: #020617;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 520px;
}

thead {
    background: #0b1120;
}

th, td {
    padding: 10px 8px;
    text-align: center;
    border-bottom: 1px solid #1f2937;
    font-size: 0.85rem;
}

th {
    font-weight: 600;
    color: #9ca3af;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:nth-child(even) {
    background: rgba(15, 23, 42, 0.8);
}

tbody tr:nth-child(odd) {
    background: rgba(15, 23, 42, 0.5);
}

tbody tr.best {
    background: rgba(22, 163, 74, 0.22);
}

tbody tr.worst {
    background: rgba(220, 38, 38, 0.22);
}

.hint {
    margin-top: 8px;
    font-size: 0.75rem;
    color: #9ca3af;
}

/* تاریخچه */

.history-section {
    background: rgba(15, 23, 42, 0.9);
    border-radius: 18px;
    padding: 14px 16px;
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.history-section h2 {
    font-size: 0.95rem;
    margin-bottom: 8px;
}

#history-list {
    list-style: none;
    max-height: 150px;
    overflow-y: auto;
    font-size: 0.8rem;
}

#history-list li {
    padding: 4px 0;
    border-bottom: 1px dashed rgba(55, 65, 81, 0.7);
    color: #cbd5f5;
}

#history-list li:last-child {
    border-bottom: none;
}

/* فوتر */

.app-footer {
    text-align: center;
    color: #9ca3af;
    font-size: 0.75rem;
    padding-bottom: 16px;
}

/* ریسپانسیو */

@media (max-width: 900px) {
    .app-container {
        margin: 10px;
        padding: 14px;
    }

    .app-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .controls {
        width: 100%;
        justify-content: space-between;
    }
}

@media (max-width: 640px) {
    .app-container {
        margin: 8px;
        padding: 12px;
        border-radius: 16px;
    }

    .title-group {
        align-items: flex-start;
    }

    .btc-icon {
        width: 40px;
        height: 40px;
        font-size: 26px;
    }

    .app-header h1 {
        font-size: 1.1rem;
    }

    .app-header p {
        font-size: 0.75rem;
    }

    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    #refresh-btn {
        width: 100%;
        justify-content: center;
        display: inline-flex;
    }

    .select-wrapper {
        width: 100%;
    }

    .select-wrapper select {
        width: 100%;
    }

    th, td {
        padding: 8px 4px;
        font-size: 0.78rem;
    }

    table {
        min-width: 100%;
    }

    .stats-cards {
        grid-template-columns: 1fr;
    }
}

.chart-section {
    background: rgba(15, 23, 42, 0.9);
    border-radius: 18px;
    padding: 16px;
    border: 1px solid rgba(148, 163, 184, 0.3);
}

.chart-caption {
    font-size: 0.8rem;
    color: #9ca3af;
}

.chart-wrapper {
    margin-top: 12px;
    width: 100%;
    height: 260px;
    position: relative;
}

/* Chart.js خودش ریسپانسیو هست وقتی maintainAspectRatio = false باشه */

@media (max-width: 640px) {
    .chart-wrapper {
        height: 220px;
    }
}