/* Krafti AI Mini App — Glass, Telegram theme, 14 langs */
:root {
    --tg-bg: var(--tg-theme-bg-color, #0b141b);
    --tg-text: var(--tg-theme-text-color, #edf6fb);
    --tg-hint: var(--tg-theme-hint-color, #8ea3b0);
    --tg-link: var(--tg-theme-link-color, #2dc2d6);
    --tg-btn: var(--tg-theme-button-color, #1ba9cf);
    --tg-btn-text: var(--tg-theme-button-text-color, #ffffff);
    --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #101f29);
    --tg-section-bg: var(--tg-theme-section-bg-color, #152734);
    --tg-accent: var(--tg-theme-accent-text-color, #39c7de);
    --tg-subtitle: var(--tg-theme-subtitle-text-color, #8ea3b0);
    --tg-separator: var(--tg-theme-section-separator-color, rgba(255,255,255,0.06));
    --glass-bg: rgba(255, 255, 255, 0.04);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-blur: 20px;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 24px;
    --radius-full: 100px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --nav-height: 72px;
    --header-height: 64px;
    --grad-primary: linear-gradient(135deg, #18a8d2 0%, #1fc488 100%);
    --grad-secondary: linear-gradient(135deg, #ff9c4a 0%, #ff5f6d 100%);
    --grad-partner: linear-gradient(135deg, #41d5ff 0%, #2fd08e 100%);
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--tg-bg);
    color: var(--tg-text);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

#app {
    position: relative;
    min-height: 100vh;
}

.hidden { display: none !important; }

.bg-gradient { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.bg-orb { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.28; animation: orbFloat 20s ease-in-out infinite; }
.bg-orb-1 { width: 320px; height: 320px; top: -90px; left: -70px; background: #1ba9cf; animation-duration: 18s; }
.bg-orb-2 { width: 250px; height: 250px; bottom: 18%; right: -40px; background: #ff7f4d; animation-duration: 22s; animation-delay: -5s; }
.bg-orb-3 { width: 220px; height: 220px; top: 42%; left: 28%; background: #22c18f; animation-duration: 25s; animation-delay: -10s; }

@keyframes orbFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -40px) scale(1.1); }
    50% { transform: translate(-20px, 20px) scale(0.9); }
    75% { transform: translate(10px, 30px) scale(1.05); }
}

.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    transition: transform 0.2s;
}
.glass-card:active { transform: scale(0.98); }

.glass-panel {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border: 1px solid var(--glass-border);
}

.glass-chip {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-full);
}

.glass-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--tg-text);
    font-family: inherit;
    outline: none;
}
.glass-input:focus { border-color: var(--tg-btn); box-shadow: 0 0 0 3px rgba(27, 169, 207, 0.2); }

.glass-badge {
    background: rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-full);
}

.loader-screen {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    background: var(--tg-bg);
}
.loader-content { text-align: center; }
.loader-logo {
    position: relative; width: 80px; height: 80px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px;
}
.logo-ring {
    position: absolute; inset: 0;
    border: 3px solid rgba(27, 169, 207, 0.2);
    border-top-color: var(--tg-btn);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
.logo-text {
    font-size: 28px; font-weight: 800;
    background: var(--grad-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.loader-label { font-size: 16px; font-weight: 600; color: var(--tg-hint); }
@keyframes spin { to { transform: rotate(360deg); } }

.app-header {
    position: sticky; top: 0; z-index: 50;
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px;
    padding-top: calc(12px + var(--safe-top));
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    border-top: none;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.header-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--grad-primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.header-name {
    font-size: 16px; font-weight: 700;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px;
}
.header-id { font-size: 11px; color: var(--tg-hint); }
.header-balance {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 14px; font-weight: 600; font-size: 14px;
}
.balance-icon { font-size: 16px; }

.main-content {
    position: relative; z-index: 1;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
}
.tab-content { padding: 16px; animation: fadeSlideUp 0.3s ease; }

.header-name,
.page-title,
.hero-title {
    font-family: 'Sora', 'Manrope', sans-serif;
    letter-spacing: -0.02em;
}

@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

.hero-card {
    position: relative;
    overflow: hidden;
    padding: 18px 16px;
    margin-bottom: 14px;
    background: linear-gradient(140deg, rgba(24, 168, 210, 0.18), rgba(34, 193, 143, 0.1));
    border-color: rgba(24, 168, 210, 0.25);
}

.hero-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.hero-pill {
    display: inline-flex;
    align-items: center;
    padding: 5px 10px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.14);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.hero-status {
    font-size: 12px;
    color: #8de9bd;
    font-weight: 600;
}

.hero-title {
    font-size: 20px;
    line-height: 1.25;
    margin-bottom: 8px;
}

.hero-sub {
    font-size: 13px;
    color: var(--tg-hint);
    line-height: 1.45;
    margin-bottom: 12px;
}

.hero-points {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.hero-point {
    display: inline-flex;
    align-items: center;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 600;
}

.balance-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.balance-card { position: relative; overflow: hidden; padding: 18px 16px; }
.balance-card-header { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.balance-card-icon { font-size: 16px; }
.balance-card-label { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.8; }
.balance-card-value { font-size: 28px; font-weight: 800; line-height: 1.1; }
.balance-card-sub { font-size: 11px; opacity: 0.6; margin-top: 4px; }

.gradient-primary { background: linear-gradient(135deg, rgba(24,168,210,0.2), rgba(31,196,136,0.14)); border-color: rgba(24,168,210,0.24); }
.gradient-secondary { background: linear-gradient(135deg, rgba(255,156,74,0.17), rgba(255,95,109,0.1)); border-color: rgba(255,156,74,0.2); }
.gradient-partner { background: linear-gradient(135deg, rgba(65,213,255,0.2), rgba(47,208,142,0.1)); border-color: rgba(65,213,255,0.2); }

.card-glow {
    position: absolute; width: 120px; height: 120px;
    border-radius: 50%; filter: blur(40px); opacity: 0.15;
    pointer-events: none; top: -30px; right: -30px;
}
.gradient-primary .card-glow { background: #18a8d2; }
.gradient-secondary .card-glow { background: #ff8d52; }
.gradient-partner .card-glow { background: #41d5ff; }

.stats-row {
    display: flex; gap: 8px; margin-bottom: 20px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; padding-bottom: 2px;
}
.stats-row::-webkit-scrollbar { display: none; }
.stat-chip { display: flex; flex-direction: column; align-items: center; padding: 10px 18px; flex-shrink: 0; gap: 2px; }
.stat-chip-value { font-size: 18px; font-weight: 700; color: var(--tg-accent); }
.stat-chip-label { font-size: 10px; color: var(--tg-hint); white-space: nowrap; }

.actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 24px; }
.action-card {
    display: flex; align-items: center; gap: 10px; padding: 14px;
    cursor: pointer; border: 1px solid var(--glass-border);
    background: var(--glass-bg); color: var(--tg-text);
    text-align: left; font-family: inherit;
}
.action-icon-wrap {
    width: 36px; height: 36px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; flex-shrink: 0;
}
.gradient-action-1 { background: linear-gradient(135deg, rgba(24,168,210,0.3), rgba(47,208,142,0.2)); }
.gradient-action-2 { background: linear-gradient(135deg, rgba(65,213,255,0.3), rgba(24,168,210,0.2)); }
.gradient-action-3 { background: linear-gradient(135deg, rgba(255,156,74,0.3), rgba(255,95,109,0.22)); }
.gradient-action-4 { background: linear-gradient(135deg, rgba(47,208,142,0.32), rgba(65,213,255,0.2)); }
.action-label { flex: 1; font-size: 12px; font-weight: 600; line-height: 1.3; }
.action-arrow { font-size: 14px; color: var(--tg-hint); opacity: 0.5; }

.section-block { margin-bottom: 20px; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-header h3 { font-size: 16px; font-weight: 700; }
.link-btn { background: none; border: none; color: var(--tg-link); font-size: 13px; font-weight: 500; cursor: pointer; font-family: inherit; }
.page-title { font-size: 22px; font-weight: 800; margin-bottom: 16px; }

.recent-list, .history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
    display: flex; align-items: center; gap: 12px; padding: 14px;
    border-radius: var(--radius-md);
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    animation: fadeSlideUp 0.3s ease;
}
.history-item-icon {
    width: 40px; height: 40px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0; background: rgba(255,255,255,0.04);
}
.history-item-body { flex: 1; min-width: 0; }
.history-item-prompt { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item-meta { font-size: 12px; color: var(--tg-hint); margin-top: 3px; display: flex; gap: 8px; }
.history-item-tokens { color: var(--tg-accent); font-weight: 600; }

.filter-chips {
    display: flex; gap: 8px; margin-bottom: 16px;
    overflow-x: auto; scrollbar-width: none; padding-bottom: 2px;
}
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
    padding: 8px 16px; border-radius: var(--radius-full);
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    color: var(--tg-hint); font-size: 13px; font-weight: 500;
    cursor: pointer; white-space: nowrap; font-family: inherit;
    transition: all 0.2s;
}
.chip-active, .chip:active { background: var(--tg-btn); color: var(--tg-btn-text); border-color: var(--tg-btn); }

.partner-earnings { position: relative; overflow: hidden; padding: 20px; margin-bottom: 16px; text-align: center; }
.partner-earnings-top { display: flex; flex-direction: column; align-items: center; margin-bottom: 14px; }
.partner-earnings-top span:first-child { font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; opacity: 0.7; margin-bottom: 4px; }
.partner-amount { font-size: 36px; font-weight: 800; }

.ref-link-block { padding: 16px; margin-bottom: 12px; }
.ref-label { font-size: 12px; color: var(--tg-hint); margin-bottom: 8px; display: block; }
.ref-input-row { display: flex; gap: 8px; }
.ref-input { flex: 1; padding: 12px 14px; font-size: 13px; min-width: 0; }

.levels-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.level-card { display: flex; flex-direction: column; align-items: center; padding: 14px 10px; gap: 4px; }
.level-badge {
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 800; color: #fff;
}
.level-badge.l1 { background: var(--grad-primary); }
.level-badge.l2 { background: var(--grad-secondary); }
.level-badge.l3 { background: var(--grad-partner); }
.level-value { font-size: 20px; font-weight: 700; }
.level-pct { font-size: 11px; color: var(--tg-hint); }

.ref-level-tabs {
    display: flex; gap: 8px; margin-bottom: 16px;
}
.ref-level-tabs .ref-tab {
    padding: 8px 16px; border-radius: var(--radius-full);
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    color: var(--tg-hint); font-size: 13px; font-weight: 500;
    cursor: pointer; font-family: inherit;
}
.ref-level-tabs .ref-tab.active { background: var(--tg-btn); color: var(--tg-btn-text); border-color: var(--tg-btn); }

.referrals-list { display: flex; flex-direction: column; gap: 6px; }
.referral-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; border-radius: var(--radius-md);
    background: var(--glass-bg); border: 1px solid var(--glass-border);
}
.referral-name { font-size: 14px; font-weight: 500; }
.referral-level-badge {
    font-size: 11px; font-weight: 700; padding: 3px 10px;
    border-radius: var(--radius-full);
    background: rgba(27, 169, 207, 0.2); color: var(--tg-accent);
}

.promo-block { padding: 24px 20px; text-align: center; }
.promo-illustration { font-size: 56px; margin-bottom: 12px; }
.promo-description { font-size: 14px; color: var(--tg-hint); margin-bottom: 20px; line-height: 1.5; }
.promo-input-wrap { margin-bottom: 16px; }
.promo-input {
    width: 100%; padding: 16px; font-size: 18px;
    text-align: center; letter-spacing: 3px;
    font-weight: 700; text-transform: uppercase;
}
.promo-result {
    margin-top: 14px; padding: 12px; border-radius: var(--radius-md);
    font-size: 14px; font-weight: 500; animation: fadeSlideUp 0.3s ease;
}
.promo-result.success { background: rgba(47, 208, 142, 0.15); color: #2fd08e; border: 1px solid rgba(47, 208, 142, 0.22); }
.promo-result.error { background: rgba(245, 87, 108, 0.12); color: #f5576c; border: 1px solid rgba(245, 87, 108, 0.2); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: none; border-radius: var(--radius-md);
    padding: 14px 24px; font-size: 15px; font-weight: 600;
    cursor: pointer; font-family: inherit;
    transition: all 0.2s; position: relative; overflow: hidden;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--tg-btn); color: var(--tg-btn-text); box-shadow: 0 4px 16px rgba(27, 169, 207, 0.32); }
.btn-light { background: rgba(255,255,255,0.15); color: #fff; }
.btn-glass { background: var(--glass-bg); color: var(--tg-text); border: 1px solid var(--glass-border); backdrop-filter: blur(12px); }
.btn-block { width: 100%; }
.btn-sm { padding: 10px 18px; font-size: 13px; }
.btn-icon-glass {
    width: 44px; height: 44px; padding: 0;
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    border-radius: var(--radius-md); color: var(--tg-text);
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.2s; flex-shrink: 0; font-family: inherit;
}
.btn-icon-glass:active { background: rgba(255,255,255,0.1); }

.btn-shine {
    position: absolute; top: 0; left: -100%;
    width: 60%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    animation: btnShine 3s ease-in-out infinite;
}
@keyframes btnShine { 0%, 100% { left: -100%; } 50% { left: 150%; } }

.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    display: flex; align-items: stretch;
    height: var(--nav-height); padding-bottom: var(--safe-bottom);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0; border-bottom: none;
}
.nav-item {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 3px;
    padding: 8px 4px; background: none; border: none;
    color: var(--tg-hint); cursor: pointer; font-family: inherit;
    transition: color 0.2s; position: relative;
}
.nav-item.active { color: var(--tg-btn); }
.nav-icon { width: 22px; height: 22px; stroke-width: 2; transition: transform 0.2s; }
.nav-item.active .nav-icon { transform: scale(1.1); }
.nav-label { font-size: 10px; font-weight: 500; }
.nav-indicator {
    position: absolute; top: 4px; left: 50%;
    transform: translateX(-50%) scaleX(0);
    width: 20px; height: 3px;
    background: var(--tg-btn); border-radius: 2px;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.nav-item.active .nav-indicator { transform: translateX(-50%) scaleX(1); }

.toast-container {
    position: fixed; top: calc(20px + var(--safe-top));
    left: 16px; right: 16px; z-index: 200;
    display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
    padding: 14px 18px; border-radius: var(--radius-md);
    font-size: 14px; font-weight: 500;
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
    pointer-events: auto;
}
.toast-success { background: rgba(47, 208, 142, 0.15); border: 1px solid rgba(47, 208, 142, 0.22); color: #2fd08e; }
.toast-error { background: rgba(245, 87, 108, 0.15); border: 1px solid rgba(245, 87, 108, 0.2); color: #f5576c; }
.toast-info { background: rgba(27, 169, 207, 0.16); border: 1px solid rgba(27, 169, 207, 0.22); color: var(--tg-accent); }

@keyframes toastIn { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-20px); } }

.empty-state { display: flex; flex-direction: column; align-items: center; padding: 48px 24px; text-align: center; }
.empty-illustration { font-size: 64px; margin-bottom: 16px; }
.empty-title { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.empty-sub { font-size: 14px; color: var(--tg-hint); margin-bottom: 20px; }
.empty-mini {
    padding: 24px 16px; text-align: center; font-size: 14px; color: var(--tg-hint);
    border-radius: var(--radius-md); background: var(--glass-bg); border: 1px solid var(--glass-border);
}

.error-content {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    padding: 40px 32px; text-align: center; width: calc(100% - 48px); max-width: 340px;
}
.error-icon { font-size: 48px; margin-bottom: 16px; }
.error-text { font-size: 15px; color: var(--tg-hint); margin-bottom: 20px; line-height: 1.5; }

.inline-loader { display: flex; justify-content: center; padding: 20px; }
.dot-pulse {
    position: relative; width: 8px; height: 8px; border-radius: 50%;
    background: var(--tg-btn); animation: dotPulse 1.5s infinite;
}
.dot-pulse::before, .dot-pulse::after {
    content: ''; position: absolute; top: 0;
    width: 8px; height: 8px; border-radius: 50%; background: var(--tg-btn);
}
.dot-pulse::before { left: -16px; animation: dotPulse 1.5s infinite 0.2s; }
.dot-pulse::after { left: 16px; animation: dotPulse 1.5s infinite 0.4s; }

@keyframes dotPulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1.2); }
}

/* Skeleton placeholders */
.skeleton {
    position: relative;
    color: transparent !important;
    background: linear-gradient(90deg, rgba(255,255,255,0.06), rgba(255,255,255,0.16), rgba(255,255,255,0.06));
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.2s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

@media (max-width: 390px) {
    .hero-title { font-size: 18px; }
    .balance-card-value { font-size: 24px; }
    .action-label { font-size: 11px; }
    .page-title { font-size: 20px; }
}

@media (min-width: 768px) {
    #app {
        max-width: 860px;
        margin: 0 auto;
    }

    .tab-content { padding: 20px; }
    .actions-grid { grid-template-columns: repeat(4, 1fr); }
    .balance-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .hero-title { font-size: 24px; }
    .page-title { font-size: 26px; }

    .bottom-nav,
    .toast-container {
        width: min(860px, calc(100vw - 24px));
        left: 50%;
        right: auto;
        transform: translateX(-50%);
    }
}
