/* Telegram Web App Theme Variables */
:root {
    --tg-theme-bg-color: #ffffff;
    --tg-theme-text-color: #000000;
    --tg-theme-hint-color: #999999;
    --tg-theme-link-color: #2481cc;
    --tg-theme-button-color: #2481cc;
    --tg-theme-button-text-color: #ffffff;
    --tg-theme-secondary-bg-color: #f1f1f1;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--tg-theme-bg-color);
    color: var(--tg-theme-text-color);
    line-height: 1.5;
    min-height: 100vh;
}

.container {
    max-width: 100%;
    padding: 16px;
    padding-bottom: 80px;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 20px;
}

.header h1 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.subtitle {
    color: var(--tg-theme-hint-color);
    font-size: 14px;
}

/* Period Selector */
.period-selector {
    display: flex;
    gap: 6px;
    justify-content: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.period-btn {
    padding: 10px 16px;
    border: none;
    border-radius: 20px;
    background: var(--tg-theme-secondary-bg-color);
    color: var(--tg-theme-text-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 50px;
}

.period-btn.active {
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
}

.period-btn:active {
    transform: scale(0.95);
}

/* Stats Info */
.stats-info {
    text-align: center;
    padding: 8px 16px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    margin-bottom: 16px;
    font-size: 12px;
    color: var(--tg-theme-hint-color);
}

.stats-info p {
    margin: 0;
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--tg-theme-secondary-bg-color);
    border-top-color: var(--tg-theme-button-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading p {
    margin-top: 16px;
    color: var(--tg-theme-hint-color);
}

/* Error */
.error {
    text-align: center;
    padding: 40px 20px;
}

.error p {
    font-size: 16px;
    margin-bottom: 16px;
}

.retry-btn {
    padding: 12px 24px;
    background: var(--tg-theme-button-color);
    color: var(--tg-theme-button-text-color);
    border: none;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}

/* Coins List */
.coins-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.coin-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    color: inherit;
}

.coin-item:active {
    transform: scale(0.98);
    opacity: 0.9;
}

.coin-rank {
    width: 32px;
    font-size: 14px;
    font-weight: 600;
    color: var(--tg-theme-hint-color);
}

.coin-rank.top-3 {
    font-size: 18px;
}

.coin-main {
    flex: 1;
    min-width: 0;
}

.coin-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.coin-symbol-small {
    font-size: 12px;
    color: var(--tg-theme-hint-color);
}

.coin-right {
    text-align: right;
}

.coin-price-small {
    font-size: 14px;
    font-weight: 500;
}

.coin-change {
    font-size: 14px;
    font-weight: 600;
}

.coin-change.positive {
    color: #00c853;
}

.coin-change.negative {
    color: #ff1744;
}

/* Back Button */
.back-btn {
    display: inline-block;
    padding: 8px 0;
    color: var(--tg-theme-link-color);
    text-decoration: none;
    font-size: 14px;
    margin-bottom: 16px;
}

/* Coin Detail Page */
.coin-detail {
    padding-top: 8px;
}

.coin-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
}

.coin-info h1 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
}

.coin-symbol {
    display: inline-block;
    padding: 4px 10px;
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    margin-right: 8px;
}

.coin-rank {
    font-size: 12px;
    color: var(--tg-theme-hint-color);
}

.coin-price {
    text-align: right;
}

.coin-price .price {
    display: block;
    font-size: 20px;
    font-weight: 700;
}

.coin-price .change {
    font-size: 14px;
    font-weight: 600;
}

.coin-price .change.positive {
    color: #00c853;
}

.coin-price .change.negative {
    color: #ff1744;
}

/* Chart */
.chart-container {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 16px;
    padding: 16px;
    margin-bottom: 20px;
}

.chart-container h3 {
    font-size: 14px;
    margin-bottom: 12px;
}

.chart-container canvas {
    width: 100% !important;
    height: 200px !important;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 12px;
    padding: 14px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 12px;
    color: var(--tg-theme-hint-color);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 18px;
    font-weight: 700;
}

.stat-value.positive {
    color: #00c853;
}

.stat-value.negative {
    color: #ff1744;
}

/* Info Section */
.info-section {
    background: var(--tg-theme-secondary-bg-color);
    border-radius: 16px;
    padding: 16px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--tg-theme-hint-color);
    font-size: 14px;
}

.info-value {
    font-weight: 600;
    font-size: 14px;
}

/* Telegram Theme Adaptation */
@media (prefers-color-scheme: dark) {
    :root {
        --tg-theme-bg-color: #212121;
        --tg-theme-text-color: #ffffff;
        --tg-theme-hint-color: #aaaaaa;
        --tg-theme-secondary-bg-color: #2c2c2c;
    }
    
    .info-row {
        border-bottom-color: rgba(255,255,255,0.05);
    }
}
