/* CashFlow Web App — темы Telegram */
:root {
    --bg: var(--tg-theme-bg-color, #1c1c1e);
    --bg-secondary: var(--tg-theme-secondary-bg-color, #2c2c2e);
    --text: var(--tg-theme-text-color, #ffffff);
    --text-hint: var(--tg-theme-hint-color, #8e8e93);
    --accent: var(--tg-theme-button-color, #0a84ff);
    --accent-text: var(--tg-theme-button-text-color, #ffffff);
    --link: var(--tg-theme-link-color, #0a84ff);
    --separator: var(--tg-theme-section-separator-color, rgba(255,255,255,0.08));
    --positive: #34c759;
    --negative: #ff3b30;
    --radius: 16px;
    --radius-sm: 12px;
    --safe-top: env(safe-area-inset-top, 0);
    --safe-bottom: env(safe-area-inset-bottom, 0);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: var(--safe-top) 16px calc(24px + var(--safe-bottom));
    -webkit-font-smoothing: antialiased;
}

#app {
    max-width: 420px;
    margin: 0 auto;
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding: 8px 0;
}

.header-user {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.header-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.header-id {
    font-size: 13px;
    color: var(--text-hint);
}

.header-refresh {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--bg-secondary);
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, background 0.15s;
}

.header-refresh:active {
    transform: scale(0.92);
}

.header-refresh.loading {
    animation: spin 0.8s linear infinite;
}

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

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    padding: 4px;
    border: 1px solid var(--separator);
}
.tab {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-hint);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.tab.is-active {
    background: var(--accent);
    color: var(--accent-text);
}
.tab:active { opacity: 0.9; }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* Balance card */
.balance {
    background: linear-gradient(145deg, var(--accent) 0%, #0051d5 100%);
    border-radius: var(--radius);
    padding: 24px 20px;
    margin-bottom: 24px;
    color: var(--accent-text);
    position: relative;
    overflow: hidden;
}

.balance::after {
    content: "";
    position: absolute;
    right: -40px;
    bottom: -40px;
    width: 140px;
    height: 140px;
    background: rgba(255,255,255,0.08);
    border-radius: 50%;
}

.balance-label {
    font-size: 13px;
    opacity: 0.9;
    margin-bottom: 6px;
    letter-spacing: 0.5px;
}

.balance-rub {
    font-size: 36px;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.balance-usdt {
    font-size: 15px;
    opacity: 0.85;
    margin-top: 6px;
}

/* Actions grid */
.actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 28px;
}

.action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--separator);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.action:active {
    transform: scale(0.96);
}

.action-icon {
    font-size: 24px;
}

.action-label {
    text-align: center;
    line-height: 1.2;
}

/* Block (section) */
.block {
    margin-bottom: 24px;
}

.block-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding: 0 2px;
}

.block-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
}

.block-link {
    font-size: 15px;
    color: var(--accent);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 0;
}

.block-meta {
    font-size: 13px;
    color: var(--text-hint);
}

/* History list */
.history-list,
.rates-list {
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--separator);
}

.tx-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--separator);
    gap: 12px;
}

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

.tx-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.tx-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: rgba(10, 132, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.tx-info {
    min-width: 0;
}

.tx-amount {
    font-weight: 600;
    font-size: 16px;
}

.tx-amount.positive {
    color: var(--positive);
}

.tx-amount.negative {
    color: var(--negative);
}

.tx-date {
    font-size: 13px;
    color: var(--text-hint);
    margin-top: 2px;
}

/* Rate item */
.rate-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--separator);
}

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

.rate-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.rate-symbol {
    font-size: 18px;
}

.rate-name {
    font-weight: 600;
    font-size: 15px;
}

.rate-sub {
    font-size: 12px;
    color: var(--text-hint);
    margin-top: 1px;
}

.rate-value {
    font-weight: 600;
    font-size: 15px;
}

/* States */
.state {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-hint);
    font-size: 15px;
}

.state-error {
    color: var(--negative);
}

/* Footer */
.footer {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.footer-btn {
    flex: 1;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--separator);
    background: var(--bg-secondary);
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.footer-btn:active {
    background: var(--separator);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 0;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}

.modal.is-open {
    opacity: 1;
    visibility: visible;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
}

.modal-panel {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-height: 80vh;
    background: var(--bg);
    border-radius: var(--radius) var(--radius) 0 0;
    display: flex;
    flex-direction: column;
    padding-bottom: var(--safe-bottom);
    transform: translateY(20px);
    transition: transform 0.25s ease-out;
}

.modal.is-open .modal-panel {
    transform: translateY(0);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--separator);
}

.modal-head h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--bg-secondary);
    color: var(--text);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    overflow-y: auto;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
}

.modal-body .tx-item {
    padding: 14px 20px;
}

/* Toast */
.toast {
    position: fixed;
    left: 20px;
    right: 20px;
    bottom: calc(24px + var(--safe-bottom));
    padding: 14px 20px;
    background: var(--bg-secondary);
    color: var(--text);
    font-size: 15px;
    text-align: center;
    border-radius: 14px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    z-index: 2000;
    transform: translateY(100px);
    opacity: 0;
    transition: transform 0.25s, opacity 0.25s;
}

.toast.is-visible {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    background: var(--positive);
    color: #fff;
}

/* Screens (Pay, Gifts, Earn) */
.screen {
    display: none;
    margin-top: 0;
}
.screen.is-active {
    display: block;
}
.screen-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding: 4px 0;
}
.screen-back {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 16px;
    cursor: pointer;
    padding: 8px 0;
}
.screen-title {
    font-size: 20px;
    font-weight: 600;
}
.screen-body {
    padding: 0 0 24px;
}
.screen-desc {
    color: var(--text-hint);
    font-size: 15px;
    margin-bottom: 20px;
    line-height: 1.4;
}
.btn-primary {
    width: 100%;
    padding: 16px 20px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 16px;
}
.btn-primary:active {
    opacity: 0.9;
}
.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.pay-result {
    min-height: 24px;
    font-size: 15px;
    color: var(--text);
    margin-top: 12px;
}
.pay-result.success { color: var(--positive); }
.pay-result.error { color: var(--negative); }
.gifts-block {
    margin-bottom: 24px;
}
.gifts-block h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-hint);
    margin-bottom: 8px;
}
.gifts-list {
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--separator);
    overflow: hidden;
}
.gift-item {
    padding: 14px 16px;
    border-bottom: 1px solid var(--separator);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.gift-item:last-child { border-bottom: none; }
.gift-amount { font-weight: 600; }
.gift-meta { font-size: 13px; color: var(--text-hint); margin-top: 2px; }
.earn-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 20px;
}
.earn-stat {
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    padding: 14px;
    text-align: center;
    border: 1px solid var(--separator);
}
.earn-stat-value { font-size: 18px; font-weight: 700; }
.earn-stat-label { font-size: 12px; color: var(--text-hint); margin-top: 4px; }
.earn-link-box { display: flex; flex-direction: column; gap: 10px; }
.earn-link-input {
    width: 100%;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--separator);
    background: var(--bg-secondary);
    color: var(--text);
    font-size: 14px;
}
