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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--tg-theme-bg-color, #fff);
  color: var(--tg-theme-text-color, #000);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
}

input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* ── Page container ───────────────────────────────────────────────── */
.page {
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Main page ────────────────────────────────────────────────────── */
.greeting {
  font-size: 15px;
  color: var(--tg-theme-hint-color, #999);
  margin-bottom: 4px;
}

.balance-block {
  text-align: center;
  padding: 24px 0 20px;
}

.balance-label {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #999);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.balance-value {
  font-size: 40px;
  font-weight: 700;
  line-height: 1.1;
}

.balance-today {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #999);
  margin-top: 6px;
}

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
  background: var(--tg-theme-secondary-bg-color, #f5f5f5);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card:active {
  opacity: 0.7;
}

.card-left {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
}

.card-subtitle {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #999);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-arrow {
  font-size: 18px;
  color: var(--tg-theme-hint-color, #999);
  margin-left: 8px;
  flex-shrink: 0;
}

/* ── Action buttons row ───────────────────────────────────────────── */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 16px 0;
}

.action-btn {
  background: var(--tg-theme-button-color, #3390ec);
  color: var(--tg-theme-button-text-color, #fff);
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  text-align: center;
}

.action-btn:active { opacity: 0.7; }

.action-btn.secondary {
  background: var(--tg-theme-secondary-bg-color, #f5f5f5);
  color: var(--tg-theme-text-color, #000);
}

/* ── Toggle row ───────────────────────────────────────────────────── */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--tg-theme-secondary-bg-color, #f5f5f5);
  border-radius: 12px;
  margin-bottom: 10px;
}

.toggle-row-label {
  font-size: 15px;
}

.toggle {
  position: relative;
  width: 50px;
  height: 28px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--tg-theme-hint-color, #ccc);
  border-radius: 14px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--tg-theme-button-color, #3390ec);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* ── Section heading ──────────────────────────────────────────────── */
.section-heading {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #999);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 20px 0 8px;
  padding: 0 4px;
}

/* ── Model list ───────────────────────────────────────────────────── */
.model-card {
  background: var(--tg-theme-secondary-bg-color, #f5f5f5);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  gap: 12px;
}

.model-card:active { opacity: 0.7; }

.model-card.active {
  outline: 2px solid var(--tg-theme-button-color, #3390ec);
}

.model-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
  color: #fff;
}

.model-icon.gemini { background: #4285f4; }
.model-icon.openai { background: #10a37f; }

.model-info {
  flex: 1;
  min-width: 0;
}

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

.model-price {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #999);
}

.model-check {
  font-size: 20px;
  color: var(--tg-theme-button-color, #3390ec);
  flex-shrink: 0;
}

/* ── Conversation list ────────────────────────────────────────────── */
.conv-card {
  background: var(--tg-theme-secondary-bg-color, #f5f5f5);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: opacity 0.15s;
}

.conv-card:active { opacity: 0.7; }

.conv-info {
  flex: 1;
  min-width: 0;
}

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

.conv-meta {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #999);
}

.conv-active {
  outline: 2px solid var(--tg-theme-button-color, #3390ec);
}

.conv-pinned .conv-model::before {
  content: '📌 ';
}

/* ── Context menu (long-press) ───────────────────────────────────── */
.ctx-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: ctxFadeIn 0.15s ease;
}

@keyframes ctxFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.ctx-menu {
  background: var(--tg-theme-bg-color, #fff);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 480px;
  padding: 8px 0;
  padding-bottom: env(safe-area-inset-bottom, 8px);
  animation: ctxSlideUp 0.2s ease;
}

@keyframes ctxSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.ctx-menu-item {
  display: block;
  width: 100%;
  padding: 16px 24px;
  border: none;
  background: none;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
  color: var(--tg-theme-text-color, #000);
  transition: background 0.15s;
}

.ctx-menu-item:active {
  background: var(--tg-theme-secondary-bg-color, #f5f5f5);
}

.ctx-menu-danger {
  color: var(--tg-theme-destructive-text-color, #e53935);
}

/* ── Topup packages ───────────────────────────────────────────────── */
.package-card {
  background: var(--tg-theme-secondary-bg-color, #f5f5f5);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.package-card:active { opacity: 0.7; }

.package-card.package-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.package-usd {
  font-size: 20px;
  font-weight: 700;
}

.package-stars {
  font-size: 15px;
  color: var(--tg-theme-hint-color, #999);
}

/* ── Chat detail ──────────────────────────────────────────────────── */
.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.bubble-user {
  align-self: flex-end;
  background: var(--tg-theme-button-color, #3390ec);
  color: var(--tg-theme-button-text-color, #fff);
  border-bottom-right-radius: 4px;
}

.bubble-assistant-full {
  width: 100%;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
  color: var(--tg-theme-text-color, #000);
  padding: 4px 0;
}

.bubble-text { margin: 0; }

.bubble-image {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 6px;
  display: block;
}

/* ── Transactions ─────────────────────────────────────────────────── */
.tx-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--tg-theme-secondary-bg-color, #eee);
}

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

.tx-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  flex-shrink: 0;
}

.tx-icon.tx-negative {
  background: rgba(229, 57, 53, 0.12);
  color: var(--tg-theme-destructive-text-color, #e53935);
}

.tx-icon.tx-positive {
  background: rgba(46, 174, 52, 0.12);
  color: #2eae34;
}

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

.tx-title {
  font-size: 15px;
  font-weight: 600;
}

.tx-detail {
  font-size: 12px;
  color: var(--tg-theme-hint-color, #999);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-right {
  text-align: right;
  flex-shrink: 0;
}

.tx-amount {
  font-size: 15px;
  font-weight: 700;
}

.tx-amount.tx-positive { color: #2eae34; }
.tx-amount.tx-negative { color: var(--tg-theme-destructive-text-color, #e53935); }

.tx-time {
  font-size: 12px;
  color: var(--tg-theme-hint-color, #999);
}

/* ── Chart ────────────────────────────────────────────────────────── */
.chart-container {
  display: flex;
  gap: 6px;
  align-items: flex-end;
  height: 100px;
  padding: 8px 0;
}

.chart-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
}

.chart-bars {
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 2px;
}

.chart-bar {
  width: 100%;
  max-width: 28px;
  border-radius: 4px;
  min-height: 2px;
}

.bar-spent {
  background: var(--tg-theme-destructive-text-color, #e53935);
  opacity: 0.75;
}

.bar-topup {
  background: #2eae34;
  opacity: 0.75;
}

.bar-empty {
  background: var(--tg-theme-secondary-bg-color, #eee);
}

.chart-label {
  font-size: 11px;
  color: var(--tg-theme-hint-color, #999);
  margin-top: 4px;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 4px 0 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--tg-theme-hint-color, #999);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot-spent { background: var(--tg-theme-destructive-text-color, #e53935); }
.dot-topup { background: #2eae34; }

/* ── Filter chips ────────────────────────────────────────────────── */
.filter-chips {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.filter-chip {
  background: var(--tg-theme-secondary-bg-color, #f5f5f5);
  color: var(--tg-theme-text-color, #000);
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.filter-chip:active { opacity: 0.7; }

.filter-chip.filter-active {
  background: var(--tg-theme-button-color, #3390ec);
  color: var(--tg-theme-button-text-color, #fff);
}

/* ── Search box ──────────────────────────────────────────────────── */
.search-box {
  margin-bottom: 12px;
}

.search-input {
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: 12px;
  background: var(--tg-theme-secondary-bg-color, #f5f5f5);
  color: var(--tg-theme-text-color, #000);
  font-size: 15px;
  outline: none;
  -webkit-appearance: none;
}

.search-input::placeholder {
  color: var(--tg-theme-hint-color, #999);
}

/* ── TTS settings ────────────────────────────────────────────────── */
.tts-textarea {
  resize: vertical;
  min-height: 60px;
  line-height: 1.4;
  font-family: inherit;
}

.slider-row {
  padding: 4px 4px 12px;
}

.tts-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--tg-theme-secondary-bg-color, #e0e0e0);
  outline: none;
}

.tts-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--tg-theme-button-color, #3390ec);
  cursor: pointer;
}

.tts-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--tg-theme-button-color, #3390ec);
  border: none;
  cursor: pointer;
}

/* ── Empty state ──────────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--tg-theme-hint-color, #999);
  font-size: 15px;
}

/* ── Loading ──────────────────────────────────────────────────────── */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--tg-theme-hint-color, #999);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--tg-theme-secondary-bg-color, #eee);
  border-top-color: var(--tg-theme-button-color, #3390ec);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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