/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: #fff;
}

.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-outline:hover { background: var(--bg-hover); }

.btn-gold {
  background: var(--gold);
  color: var(--bg);
}

.btn-block { width: 100%; }

.btn-lg { padding: 14px 24px; font-size: 15px; border-radius: var(--radius-lg); }

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform var(--transition);
  cursor: pointer;
}

.card:hover { transform: translateY(-4px); }

.card-cover {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  object-fit: cover;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  overflow: hidden;
}

.card-body { padding: 10px 12px; }
.card-title { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.card-category { font-size: 10px; color: var(--text-muted); margin-bottom: 2px; }
.card-subtitle { font-size: 11px; color: var(--text-muted); }

.card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
}

.card-type { font-size: 11px; }
.card-type-photo { color: var(--accent); }
.card-type-video { color: var(--pink); }
.card-price { font-size: 11px; color: var(--gold); font-weight: 600; }

/* Reference grid */
.ref-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.ref-item {
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color var(--transition);
}

.ref-item.selected { border-color: var(--primary); }

.ref-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Model selector */
.model-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.model-chip {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.model-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Prompt input */
.prompt-area {
  width: 100%;
  min-height: 80px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  resize: vertical;
}

.prompt-area:focus {
  outline: none;
  border-color: var(--primary);
}

/* Skeleton loader */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--bg-card);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Balance card */
.balance-card {
  background: linear-gradient(135deg, var(--bg-card), #2d2d3a);
  border: 1px solid rgba(99,102,241,0.3);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.balance-amount {
  font-size: 28px;
  font-weight: 800;
  color: var(--gold);
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.back-btn {
  font-size: 18px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
}

.page-title { font-size: 16px; font-weight: 700; }
.page-subtitle { font-size: 12px; color: var(--text-muted); }

/* Profile page */
.profile-page { max-width: 480px; margin: 0 auto; padding-bottom: 80px; }

.profile-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
}

.profile-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}

.profile-info { flex: 1; min-width: 0; }
.profile-name { font-size: 15px; font-weight: 700; }
.profile-provider { font-size: 12px; color: var(--text-muted); }

.profile-logout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition);
}
.profile-logout-btn:hover { border-color: var(--danger); color: var(--danger); }

.profile-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.card-icon { font-size: 18px; }
.card-title { font-size: 15px; font-weight: 700; flex: 1; }

.card-badge {
  font-size: 14px;
  font-weight: 700;
  color: var(--gold);
  background: rgba(255,209,70,0.1);
  padding: 4px 10px;
  border-radius: 8px;
}

.active-badge {
  color: var(--accent);
  background: rgba(108,229,177,0.1);
}

/* Topup */
.topup-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.chip-btn {
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-hover);
  color: var(--text);
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.chip-btn:hover { border-color: var(--primary); }
.chip-btn.active {
  background: rgba(99,102,241,0.15);
  border-color: var(--primary);
  color: var(--primary-hover);
}

.topup-custom-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.topup-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
}
.topup-input:focus { outline: none; border-color: var(--primary); }
.topup-input::placeholder { color: var(--text-muted); }

.btn-action {
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: #fff;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-action:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(99,102,241,0.3); }
.btn-action:disabled { opacity: 0.5; transform: none; }
.btn-action.full-width { width: 100%; }

.card-hint {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 4px;
}

/* Subscription */
.sub-details { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.sub-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.sub-row:last-child { border-bottom: none; }
.sub-row span { color: var(--text-muted); }
.sub-row strong { color: var(--text); }

.sub-promo {
  background: linear-gradient(135deg, rgba(99,102,241,0.1), rgba(159,122,234,0.1));
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  margin-bottom: 12px;
}
.sub-promo-price { font-size: 22px; font-weight: 800; color: var(--text); }
.sub-promo-price span { font-size: 14px; font-weight: 400; color: var(--text-muted); }
.sub-promo-benefit { font-size: 13px; color: var(--accent); margin-top: 4px; }
.sub-promo-examples { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.sub-promo-examples s { color: var(--text-muted); opacity: 0.5; }

.auto-renew-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  cursor: pointer;
}
.auto-renew-label input { accent-color: var(--primary); }

.btn-secondary-sm {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  background: var(--bg-hover);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.btn-secondary-sm:hover { border-color: var(--text-muted); color: var(--text); }
.btn-secondary-sm.full-width { width: 100%; }

/* Filters */
.filter-row {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
}

.filter-chip {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all var(--transition);
  white-space: nowrap;
}
.filter-chip:hover { border-color: var(--primary); }
.filter-chip.active {
  background: rgba(99,102,241,0.15);
  border-color: var(--primary);
  color: var(--primary-hover);
}

/* Payment list */
.pay-list { display: flex; flex-direction: column; }

.pay-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.pay-row:last-child { border-bottom: none; }

.pay-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.pay-info { flex: 1; min-width: 0; }
.pay-label { font-size: 13px; font-weight: 600; }
.pay-meta { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

.pay-amount { font-size: 14px; font-weight: 700; white-space: nowrap; }
.amount-plus { color: var(--accent); }
.amount-minus { color: var(--text-muted); }

.pay-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px 0;
}

/* History page */
.history-page { max-width: 600px; margin: 0 auto; }

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.history-title { font-size: 20px; font-weight: 800; }

.history-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.history-filter {
  padding: 7px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all var(--transition);
  white-space: nowrap;
}
.history-filter:hover { border-color: var(--primary); color: var(--text); }
.history-filter.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.history-filter.small {
  font-size: 11px;
  padding: 4px 10px;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

@media (min-width: 520px) {
  .history-grid { grid-template-columns: repeat(3, 1fr); }
}

.history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 20px;
  text-align: center;
}
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-text { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.empty-hint { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.empty-cta {
  padding: 10px 24px;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  transition: transform var(--transition);
}
.empty-cta:hover { transform: translateY(-2px); }

.history-error {
  text-align: center;
  color: var(--danger);
  padding: 40px 0;
  font-size: 14px;
  grid-column: 1 / -1;
}

/* History card */
.history-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--transition), opacity var(--transition);
  position: relative;
}
.history-card:hover { transform: translateY(-3px); }
.history-card:active { transform: scale(0.97); }

.history-card--failed { opacity: 0.6; }
.history-card--failed:hover { opacity: 0.85; }

.history-card--pending .hcard-visual { opacity: 0.7; }

.history-card--removing {
  animation: card-remove 0.3s ease forwards;
}
@keyframes card-remove {
  to { opacity: 0; transform: scale(0.85); }
}

.hcard-visual {
  position: relative;
  aspect-ratio: 1;
  background: var(--bg-hover);
  overflow: hidden;
}

.hcard-media {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity .3s;
}

.hcard-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
}

.spinner-ring {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

.hcard-play {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.hcard-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: var(--text-muted);
}
.hcard-placeholder.status-failed {
  background: linear-gradient(135deg, rgba(255,92,122,0.08), rgba(255,92,122,0.02));
  color: var(--danger);
}
.hcard-placeholder.status-processing,
.hcard-placeholder.status-queued {
  background: linear-gradient(135deg, rgba(99,102,241,0.08), rgba(99,102,241,0.02));
  color: var(--primary);
}

.hcard-video-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(4px);
  color: #fff;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hcard-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition);
}
.history-card:hover .hcard-delete { opacity: 1; }
.hcard-delete:hover { background: var(--danger); }

/* Touch: always show delete on touch devices */
@media (hover: none) {
  .hcard-delete { opacity: 0.7; }
}

.hcard-body { padding: 10px; }

.hcard-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.hcard-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.hcard-status {
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.hcard-status.status-done { color: var(--accent); }
.hcard-status.status-failed { color: var(--danger); }
.hcard-status.status-processing { color: var(--primary); }
.hcard-status.status-queued { color: var(--text-muted); }

.hcard-duration { font-size: 11px; color: var(--text-muted); }

.hcard-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}
.hcard-cost { margin-left: auto; color: var(--gold); font-weight: 600; }

.profile-skeleton {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.skeleton-block {
  height: 120px;
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-hover) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-lg);
}

/* Search bar */
.search-input {
  width: 100%;
  padding: 10px 14px 10px 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  transition: border-color var(--transition);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236b7280' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.656a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 12px center;
}
.search-input:focus {
  outline: none;
  border-color: var(--primary);
}
.search-input::placeholder { color: var(--text-muted); }

/* Category chips (smaller) */
.chips-secondary {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 12px;
  gap: 6px;
}

.chip-sm {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all var(--transition);
  white-space: nowrap;
}
.chip-sm:hover { border-color: var(--primary); }
.chip-sm.active {
  background: rgba(99,102,241,0.15);
  border-color: var(--primary);
  color: var(--primary-hover);
}

.btn-tg {
  background: #2AABEE;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-tg:hover {
  background: #229ED9;
}
