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

:root {
  --tg-theme-bg-color: #fff;
  --tg-theme-text-color: #000;
  --tg-theme-hint-color: #999;
  --tg-theme-link-color: #2481cc;
  --tg-theme-button-color: #2481cc;
  --tg-theme-button-text-color: #fff;
  --tg-theme-secondary-bg-color: #f0f0f0;
  --radius: 14px;
  --shadow: 0 2px 8px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --card-bg: var(--tg-theme-secondary-bg-color);
  --accent-gradient: linear-gradient(135deg, var(--tg-theme-button-color), #1a6bb5);
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-med: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --shadow: 0 2px 8px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.2);
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  line-height: 1.5;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--tg-theme-hint-color); border-radius: 2px; }

.hidden { display: none !important; }

.page { padding: 16px; padding-bottom: 80px; animation: fadeIn 0.25s var(--transition-med); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.page-title { font-size: 20px; font-weight: 700; margin-bottom: 16px; letter-spacing: -0.02em; }

/* ─── Home ─────────────────────────────────────────────────────────────────── */
.home-header {
  text-align: center; padding: 28px 16px 24px;
  background: linear-gradient(180deg, rgba(36,129,204,0.06) 0%, transparent 100%);
  border-radius: 0 0 24px 24px;
  margin: -16px -16px 16px;
  padding-left: 32px; padding-right: 32px;
}
.home-logo {
  font-size: 56px; margin-bottom: 10px;
  filter: drop-shadow(0 4px 12px rgba(36,129,204,0.2));
  display: inline-block;
}
.home-header h1 { font-size: 24px; font-weight: 800; letter-spacing: -0.03em; }
.home-greeting { color: var(--tg-theme-hint-color); margin-top: 6px; font-size: 15px; line-height: 1.4; }

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 4px;
}
.action-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 20px 8px;
  background: var(--card-bg);
  border: 1px solid rgba(128,128,128,0.08);
  border-radius: var(--radius);
  color: var(--tg-theme-text-color);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  min-height: 84px;
  box-shadow: var(--shadow);
}
.action-btn:active { transform: scale(0.95); box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.action-icon { font-size: 28px; }

/* ─── Store ────────────────────────────────────────────────────────────────── */
.store-cards { display: flex; flex-direction: column; gap: 12px; }

.plan-card {
  background: var(--card-bg);
  border-radius: var(--radius); padding: 18px;
  position: relative; overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid rgba(128,128,128,0.06);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.plan-card:active { transform: scale(0.99); }
.plan-card.featured {
  border: 2px solid var(--tg-theme-button-color);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(36,129,204,0.1);
  background: linear-gradient(135deg, rgba(36,129,204,0.04) 0%, var(--card-bg) 100%);
}
.plan-badge {
  position: absolute; top: 0; right: 0;
  background: var(--accent-gradient); color: var(--tg-theme-button-text-color);
  font-size: 11px; font-weight: 700; padding: 5px 14px;
  border-radius: 0 0 0 var(--radius);
  text-transform: uppercase; letter-spacing: 0.05em;
}
.plan-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; letter-spacing: -0.01em; }
.plan-price { font-size: 26px; font-weight: 800; color: var(--tg-theme-link-color); letter-spacing: -0.02em; }
.plan-period { font-size: 13px; color: var(--tg-theme-hint-color); }
.plan-features { font-size: 13px; color: var(--tg-theme-hint-color); margin: 10px 0 14px; line-height: 1.6; }
.plan-buy-btn {
  width: 100%; padding: 13px; border: none; border-radius: 10px;
  background: var(--accent-gradient); color: var(--tg-theme-button-text-color);
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: transform var(--transition-fast), opacity var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: 0 2px 8px rgba(36,129,204,0.2);
}
.plan-buy-btn:active { transform: scale(0.97); opacity: 0.9; box-shadow: 0 1px 4px rgba(36,129,204,0.15); }

/* ─── Account ──────────────────────────────────────────────────────────────── */
.balance-card {
  display: flex; flex-direction: column; align-items: center;
  background: linear-gradient(135deg, rgba(36,129,204,0.06) 0%, var(--card-bg) 100%);
  border-radius: var(--radius); padding: 28px 24px; margin-bottom: 12px;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--tg-theme-button-color);
  position: relative; overflow: hidden;
}
.balance-label { font-size: 12px; color: var(--tg-theme-hint-color); text-transform: uppercase; letter-spacing: 1.5px; font-weight: 600; }
.balance-amount { font-size: 40px; font-weight: 800; margin-top: 6px; letter-spacing: -0.03em; }

.info-card {
  background: var(--card-bg);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(128,128,128,0.06);
}
.info-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
.info-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0; border-bottom: 1px solid rgba(128,128,128,0.08);
}
.info-row:last-of-type { border-bottom: none; }
.info-label { font-size: 13px; color: var(--tg-theme-hint-color); }
.info-value { font-size: 14px; font-weight: 500; text-align: right; max-width: 60%; word-break: break-all; }
.small-text { font-size: 11px; }
.copyable { cursor: pointer; color: var(--tg-theme-link-color); transition: opacity var(--transition-fast); }
.copyable:active { opacity: 0.6; }
.copyable::after { content: ' 📋'; font-size: 12px; }

.tonkeeper-btn {
  display: block; text-align: center; padding: 13px;
  background: linear-gradient(135deg, #0098EA, #0080cc); color: #fff; border-radius: 10px;
  text-decoration: none; font-weight: 600; font-size: 15px;
  margin-top: 12px; transition: transform var(--transition-fast), opacity var(--transition-fast);
  box-shadow: 0 2px 8px rgba(0,152,234,0.2);
}
.tonkeeper-btn:active { opacity: 0.9; transform: scale(0.97); }
.hint-text { font-size: 12px; color: var(--tg-theme-hint-color); margin-top: 10px; text-align: center; line-height: 1.4; }

/* ─── Licenses ─────────────────────────────────────────────────────────────── */
.license-card {
  background: var(--card-bg);
  border-radius: var(--radius); padding: 14px 14px 14px 18px; margin-bottom: 10px;
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: var(--shadow);
  border-left: 3px solid rgba(128,128,128,0.15);
  border-top: 1px solid rgba(128,128,128,0.06);
  border-right: 1px solid rgba(128,128,128,0.06);
  border-bottom: 1px solid rgba(128,128,128,0.06);
}
.license-card:active { transform: scale(0.98); box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.license-card:has(.status-active) { border-left-color: #28a745; }
.license-card:has(.status-expired) { border-left-color: #dc3545; }
.license-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.tier-badge {
  display: inline-block; padding: 3px 10px; border-radius: 6px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
}
.tier-trial { background: #FFF3CD; color: #856404; }
.tier-pro { background: #D4EDDA; color: #155724; }
.tier-business { background: #CCE5FF; color: #004085; }
.status-badge { font-size: 12px; font-weight: 700; }
.status-active { color: #28a745; }
.status-expired { color: #dc3545; }
.license-detail { font-size: 13px; color: var(--tg-theme-hint-color); margin-top: 2px; line-height: 1.4; }

/* ─── History ──────────────────────────────────────────────────────────────── */
.tx-row {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; margin-bottom: 6px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(128,128,128,0.06);
  transition: transform var(--transition-fast);
}
.tx-row:active { transform: scale(0.99); }
.tx-row:nth-child(even) { background: rgba(128,128,128,0.02); }
.tx-icon { font-size: 22px; flex-shrink: 0; width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; }
.tx-info { flex: 1; min-width: 0; }
.tx-desc { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-date { font-size: 12px; color: var(--tg-theme-hint-color); margin-top: 2px; }
.tx-amount { font-size: 15px; font-weight: 700; flex-shrink: 0; letter-spacing: -0.01em; }
.tx-credit { color: #28a745; }
.tx-debit { color: #dc3545; }

/* ─── Empty / Error / Loading ──────────────────────────────────────────────── */
.empty-state, .error-state {
  text-align: center; padding: 48px 20px;
  color: var(--tg-theme-hint-color); font-size: 15px; line-height: 1.5;
}
.retry-btn, .load-more-btn {
  display: inline-block; margin-top: 12px; padding: 11px 28px;
  background: var(--accent-gradient); color: var(--tg-theme-button-text-color);
  border: none; border-radius: 10px; font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition-fast), opacity var(--transition-fast);
  box-shadow: 0 2px 8px rgba(36,129,204,0.15);
}
.retry-btn:active, .load-more-btn:active { transform: scale(0.97); opacity: 0.9; }
.load-more-btn { display: block; width: 100%; margin-top: 8px; }

/* ─── Skeletons ────────────────────────────────────────────────────────────── */
.skeleton-card {
  background: linear-gradient(90deg, var(--card-bg) 25%, rgba(128,128,128,0.08) 50%, var(--card-bg) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius); height: 80px; margin-bottom: 10px;
  animation: shimmer 1.5s infinite ease-in-out;
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.8; }
}

/* ─── Toast ────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--tg-theme-text-color); color: var(--tg-theme-bg-color);
  padding: 10px 22px; border-radius: 22px; font-size: 13px; font-weight: 500;
  z-index: 999; animation: toastIn 0.3s var(--transition-med);
  white-space: nowrap;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-lg);
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ─── License detail modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 100; animation: fadeIn 0.2s ease;
}
.modal-sheet {
  background: var(--tg-theme-bg-color); width: 100%;
  max-height: 80vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 8px 16px 32px;
  animation: slideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
}
.modal-sheet::before {
  content: ''; display: block; width: 36px; height: 4px;
  background: rgba(128,128,128,0.3); border-radius: 2px;
  margin: 8px auto 16px;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-sheet h3 { font-size: 18px; font-weight: 700; margin-bottom: 16px; }
.modal-close {
  display: block; width: 100%; padding: 13px; margin-top: 16px;
  background: var(--card-bg); color: var(--tg-theme-text-color);
  border: none; border-radius: 10px; font-size: 15px; cursor: pointer;
  font-weight: 500;
  transition: transform var(--transition-fast), background var(--transition-fast);
}
.modal-close:active { transform: scale(0.97); }



/* ─── Responsive Action Grid ──────────────────────────────────────────────── */
@media (min-width: 400px) {
  .action-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ─── Bottom Navigation ──────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: var(--tg-theme-bg-color);
  border-top: 1px solid rgba(128,128,128,0.12);
  padding: 6px 0;
  padding-bottom: max(6px, env(safe-area-inset-bottom, 6px));
  z-index: 50;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.04);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--tg-theme-hint-color);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition-fast), transform var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
  min-width: 56px;
}

.nav-item:active {
  transform: scale(0.9);
}

.nav-item.active {
  color: var(--tg-theme-button-color);
}

.nav-icon {
  font-size: 22px;
  line-height: 1;
}

.nav-label {
  font-size: 10px;
  line-height: 1.2;
}

/* ─── Deposit Code Card ──────────────────────────────────────────────────── */
.deposit-code-card {
  background: linear-gradient(135deg, rgba(40,167,69,0.06), var(--card-bg));
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  text-align: center;
  border: 1px dashed rgba(40,167,69,0.3);
}

.deposit-code-label {
  font-size: 11px;
  color: var(--tg-theme-hint-color);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
  display: block;
  margin-bottom: 8px;
}

.deposit-code-value {
  cursor: pointer;
  padding: 12px 16px;
  background: var(--tg-theme-bg-color);
  border-radius: 10px;
  display: inline-block;
  min-width: 200px;
  transition: transform var(--transition-fast), background var(--transition-fast);
  box-shadow: var(--shadow);
}

.deposit-code-value:active {
  transform: scale(0.97);
  background: rgba(40,167,69,0.06);
}

.deposit-code-text {
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--tg-theme-text-color);
  display: block;
}

.deposit-code-copy {
  font-size: 12px;
  color: var(--tg-theme-link-color);
  display: block;
  margin-top: 4px;
}

.deposit-code-hint {
  font-size: 12px;
  color: var(--tg-theme-hint-color);
  display: block;
  margin-top: 10px;
  line-height: 1.4;
}













/* ─── Upgrade Page ────────────────────────────────────────────────────────── */
.upgrade-cards { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }

/* ─── Subscription Action Buttons ─────────────────────────────────────────── */
.sub-actions {
  display: flex; gap: 8px; margin-top: 14px; padding-top: 12px;
  border-top: 1px solid rgba(128,128,128,0.1);
}
.sub-action-btn {
  flex: 1; padding: 11px 8px; border: none; border-radius: 10px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: transform var(--transition-fast), opacity var(--transition-fast);
}
.sub-action-btn:active { transform: scale(0.97); opacity: 0.9; }
.sub-upgrade-btn {
  background: var(--accent-gradient); color: var(--tg-theme-button-text-color);
  box-shadow: 0 2px 8px rgba(36,129,204,0.2);
}
.sub-cancel-btn {
  background: rgba(220,53,69,0.1); color: #dc3545;
}
.sub-reactivate-btn {
  background: rgba(40,167,69,0.1); color: #28a745;
}

/* ─── License Detail: Device Management ──────────────────────────────────── */
.detail-section {
  margin-top: 16px;
}

.detail-section-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
}

.device-list {
  margin-bottom: 10px;
}

.device-list-loading,
.device-empty {
  text-align: center;
  padding: 16px;
  font-size: 13px;
  color: var(--tg-theme-hint-color);
}

.device-count {
  font-size: 12px;
  color: var(--tg-theme-hint-color);
  margin-bottom: 8px;
  text-align: right;
}

.device-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--card-bg);
  border-radius: 10px;
  margin-bottom: 6px;
  border: 1px solid rgba(128,128,128,0.08);
}

.device-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.device-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-id {
  font-size: 11px;
  color: var(--tg-theme-hint-color);
  font-family: 'SF Mono', 'Menlo', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.device-remove-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(220,53,69,0.1);
  color: #dc3545;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-fast), background var(--transition-fast);
  margin-left: 10px;
}

.device-remove-btn:active {
  transform: scale(0.9);
  background: rgba(220,53,69,0.2);
}

/* ─── License Detail: Action Buttons ─────────────────────────────────────── */
.detail-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.detail-action-btn {
  flex: 1;
  padding: 11px 14px;
  border: none;
  border-radius: 10px;
  background: var(--card-bg);
  color: var(--tg-theme-text-color);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition-fast), background var(--transition-fast);
  box-shadow: var(--shadow);
  border: 1px solid rgba(128,128,128,0.08);
}

.detail-action-btn:active {
  transform: scale(0.97);
}

.detail-action-danger {
  color: #dc3545;
  border-color: rgba(220,53,69,0.2);
  background: rgba(220,53,69,0.04);
}

.detail-action-danger:active {
  background: rgba(220,53,69,0.1);
}



/* ─── License Detail: New Key ─────────────────────────────────────────────── */
.new-key-card {
  margin-top: 16px;
}

.new-key-card h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
}

.new-key-value {
  font-family: 'SF Mono', 'Menlo', monospace;
  font-size: 13px;
  font-weight: 600;
  padding: 12px;
  background: var(--tg-theme-bg-color);
  border-radius: 8px;
  word-break: break-all;
  cursor: pointer;
  color: var(--tg-theme-link-color);
  transition: background var(--transition-fast);
  border: 1px solid rgba(128,128,128,0.08);
}

.new-key-value:active {
  background: rgba(36,129,204,0.06);
}