/* Aura AI Max Mini-App — Full Redesign */
:root {
  --bg: #08080f;
  --bg2: #0d0d18;
  --surface: #12121e;
  --surface2: #1a1a2e;
  --surface-solid: #12121e;
  --accent: #7c3aed;
  --accent2: #a855f7;
  --accent3: #ec4899;
  --gradient: linear-gradient(135deg, #7c3aed, #a855f7, #ec4899);
  --gradient-btn: linear-gradient(135deg, #7c3aed 0%, #9333ea 50%, #a855f7 100%);
  --text: #ececf4;
  --text2: #9999b0;
  --text3: #6a6a88;
  --border: rgba(124, 58, 237, 0.2);
  --border2: rgba(255,255,255,0.08);
  --success: #4ade80;
  --error: #f87171;
  --warn: #fbbf24;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.app-container {
  max-width: 520px; margin: 0 auto;
  min-height: 100vh; display: flex; flex-direction: column;
}

/* ==================== HEADER ==================== */
.app-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; position: sticky; top: 0; z-index: 50;
  background: #08080f;
  border-bottom: 1px solid var(--border2);
}
.header-logo { display: flex; align-items: center; gap: 8px; }
.header-title { font-size: 18px; font-weight: 700; background: var(--gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.header-balance {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 5px 12px;
}
.balance-item { display: flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 600; }
.balance-icon { font-size: 10px; }
.balance-icon.free { color: var(--success); }
.balance-icon.paid { color: var(--accent2); }
.balance-sep { width: 1px; height: 14px; background: var(--border2); }

/* ==================== SCREENS ==================== */
.screens-wrapper { flex: 1; padding: 12px 16px 90px; }
.screen { display: none; }
.screen.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ==================== LOADING ==================== */
.loading-container {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 60vh; gap: 20px;
}
.loader-ring { display: inline-block; position: relative; width: 48px; height: 48px; }
.loader-ring.large { width: 72px; height: 72px; }
.loader-ring div {
  box-sizing: border-box; display: block; position: absolute;
  width: 100%; height: 100%; border-radius: 50%;
  border: 4px solid rgba(124,58,237,0.2);
  animation: ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
}
.loader-ring div:nth-child(1) { border-top-color: #7c3aed; animation-delay: -0.45s; }
.loader-ring div:nth-child(2) { border-top-color: #a855f7; animation-delay: -0.3s; }
.loader-ring div:nth-child(3) { border-top-color: #ec4899; animation-delay: -0.15s; }
@keyframes ring {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
.loading-text { font-size: 16px; color: var(--text); }

/* ==================== CARDS ==================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card h3 { font-size: 15px; margin-bottom: 12px; color: var(--text); }

/* ==================== FORM ELEMENTS ==================== */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.form-group textarea {
  width: 100%; background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px; color: var(--text);
  font-size: 15px; resize: none; min-height: 100px; font-family: inherit;
  transition: border-color 0.2s;
}
.form-group textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124,58,237,0.15); }
.form-row { display: flex; gap: 12px; }
.form-group.half { flex: 1; }

/* Chips */
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--bg2); border: 1px solid var(--border2); border-radius: 20px;
  padding: 7px 14px; color: var(--text2); font-size: 13px; cursor: pointer;
  transition: all 0.2s; font-family: inherit; white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 2px 12px rgba(124,58,237,0.3); }
.chip.sm { padding: 5px 10px; font-size: 12px; }

/* Buttons */
.btn-primary {
  width: 100%; background: var(--gradient-btn); border: none; border-radius: var(--radius);
  padding: 14px; color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
  transition: all 0.2s; position: relative; overflow: hidden; font-family: inherit;
}
.btn-primary::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, transparent, rgba(255,255,255,0.1), transparent);
  transform: translateX(-100%); transition: transform 0.4s;
}
.btn-primary:hover::before { transform: translateX(100%); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }
.btn-generate { margin-top: 4px; }
.btn-text { display: inline; }
.btn-spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: ring 0.6s linear infinite; vertical-align: middle; }

.btn-secondary {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; color: var(--text);
  font-size: 14px; cursor: pointer; font-family: inherit; transition: border-color 0.2s;
}
.btn-secondary:hover { border-color: var(--accent); }

.btn-small {
  background: var(--accent); border: none; border-radius: var(--radius-xs);
  padding: 8px 16px; color: #fff; font-size: 13px; cursor: pointer;
  white-space: nowrap; font-family: inherit; transition: opacity 0.2s;
}
.btn-small:active { opacity: 0.8; }

/* Upload area */
.upload-area {
  border: 2px dashed var(--border2); border-radius: var(--radius);
  padding: 20px; text-align: center; color: var(--text3); font-size: 13px;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 8px;
  transition: all 0.2s;
}
.upload-area:hover { border-color: var(--accent); color: var(--text2); }
.upload-area.has-files { border-color: var(--accent); color: var(--accent2); background: rgba(124,58,237,0.05); }

/* Gen cost */
.gen-cost-row { text-align: center; margin-bottom: 10px; min-height: 28px; }
.cost-badge {
  display: inline-block; padding: 4px 14px; border-radius: 20px;
  font-size: 13px; font-weight: 600;
}
.cost-badge.free { background: rgba(74,222,128,0.15); color: var(--success); }
.cost-badge.paid { background: rgba(124,58,237,0.15); color: var(--accent2); }
.cost-badge.no-funds { background: rgba(248,113,113,0.15); color: var(--error); }

/* ==================== PROGRESS ==================== */
.progress-container {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 50vh; gap: 16px; text-align: center;
}
.progress-visual { position: relative; margin-bottom: 8px; }
.progress-timer {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-size: 16px; font-weight: 600; color: var(--accent2); font-variant-numeric: tabular-nums;
}
.progress-status { font-size: 14px; color: var(--text2); }
.progress-bar { width: 200px; height: 4px; background: var(--surface2); border-radius: 2px; overflow: hidden; }
.progress-fill {
  height: 100%; background: var(--gradient); border-radius: 2px; width: 0%;
  animation: progressPulse 3s ease-in-out infinite;
}
@keyframes progressPulse {
  0% { width: 15%; } 50% { width: 75%; } 100% { width: 15%; }
}

/* ==================== RESULT ==================== */
.result-gallery { display: flex; flex-direction: column; gap: 12px; }
.result-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow);
}
.result-card img {
  width: 100%; display: block; cursor: pointer; transition: transform 0.3s;
}
.result-card img:hover { transform: scale(1.02); }
.result-actions {
  display: flex; gap: 8px; padding: 10px;
}
.result-actions button {
  flex: 1; background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--radius-xs); padding: 10px; color: var(--text);
  font-size: 13px; cursor: pointer; font-family: inherit; transition: all 0.2s;
}
.result-actions button:hover { border-color: var(--accent); color: var(--accent2); }
.result-bottom { margin-top: 12px; }

/* ==================== CATALOG ==================== */
.catalog-tabs-row { display: flex; gap: 4px; margin-bottom: 12px; }
.catalog-tab {
  flex: 1; background: var(--surface); border: 1px solid var(--border2);
  border-radius: var(--radius-xs); padding: 10px; text-align: center;
  font-size: 13px; color: var(--text2); cursor: pointer; font-family: inherit;
  transition: all 0.2s; font-weight: 500;
}
.catalog-tab.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 2px 12px rgba(124,58,237,0.3);
}
.catalog-filters { margin-bottom: 12px; }
.tag-filter { margin-top: 8px; }
.catalog-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.catalog-card {
  background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; transition: all 0.25s; position: relative;
}
.catalog-card:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(124,58,237,0.15); }
.catalog-card:active { transform: scale(0.98); }
.catalog-preview { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.catalog-info { padding: 10px; }
.catalog-title { font-size: 13px; font-weight: 600; margin-bottom: 3px; line-height: 1.3; }
.catalog-tags { font-size: 11px; color: var(--text3); }
.catalog-desc { font-size: 12px; color: var(--text2); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.catalog-meta { font-size: 11px; color: var(--accent2); margin-top: 4px; }
.catalog-cost-badge {
  position: absolute; top: 8px; right: 8px;
  background: rgba(8,8,15,0.85);
  border-radius: 12px; padding: 3px 8px; font-size: 11px; font-weight: 600; color: var(--accent2);
}

/* ==================== PACKAGES ==================== */
.topup-header { text-align: center; margin-bottom: 16px; }
.topup-header h2 { font-size: 20px; margin-bottom: 4px; }
.topup-header p { font-size: 14px; color: var(--text2); }
.packages-grid { display: flex; flex-direction: column; gap: 10px; }

.package-card {
  background: var(--surface); border: 1px solid var(--border2); border-radius: var(--radius);
  padding: 16px; display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; transition: all 0.2s; position: relative; overflow: hidden;
}
.package-card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(124,58,237,0.15); }
.package-card.popular { border-color: var(--accent); }
.package-card.popular::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(124,58,237,0.08), rgba(236,72,153,0.05));
}
.pkg-info { position: relative; z-index: 1; }
.pkg-label { font-size: 15px; font-weight: 600; margin-bottom: 2px; display: flex; align-items: center; gap: 8px; }
.pkg-tag { font-size: 10px; background: var(--gradient); color: #fff; border-radius: 10px; padding: 2px 8px; font-weight: 600; }
.pkg-detail { font-size: 12px; color: var(--text2); }
.pkg-detail .bonus { color: var(--success); font-weight: 600; }
.pkg-per-coin { font-size: 11px; color: var(--text3); margin-top: 2px; }
.pkg-price {
  position: relative; z-index: 1;
  background: var(--gradient-btn); border-radius: var(--radius-xs);
  padding: 8px 16px; font-weight: 700; font-size: 15px; color: #fff;
  white-space: nowrap;
}

/* ==================== PROFILE ==================== */
.profile-card { text-align: center; padding: 24px 16px; }
.profile-avatar {
  width: 56px; height: 56px; border-radius: 50%; margin: 0 auto 10px;
  background: var(--gradient); display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700; color: #fff;
}
.profile-name { font-size: 18px; font-weight: 600; margin-bottom: 8px; }
.profile-balance-detail { display: flex; justify-content: center; gap: 16px; }
.bal-detail { font-size: 13px; color: var(--text2); display: flex; align-items: center; gap: 4px; }
.bal-detail span:not(.balance-icon) { color: var(--text); font-weight: 600; }

.ref-link-box { display: flex; gap: 8px; margin-bottom: 10px; }
.ref-link-box input {
  flex: 1; background: var(--bg2); border: 1px solid var(--border2);
  border-radius: var(--radius-xs); padding: 8px 10px; color: var(--text); font-size: 12px;
}
.ref-stats { font-size: 13px; color: var(--text2); }
.ref-stats b { color: var(--text); }

/* History */
.history-item { padding: 10px 0; border-bottom: 1px solid var(--border2); }
.history-item:last-child { border-bottom: none; }
.history-prompt { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px; }
.history-meta { font-size: 11px; color: var(--text3); }
.pagination { display: flex; gap: 6px; margin-top: 10px; justify-content: center; }
.btn-page {
  background: var(--bg2); border: 1px solid var(--border2); border-radius: 6px;
  padding: 6px 12px; color: var(--text2); font-size: 13px; cursor: pointer;
  font-family: inherit; transition: all 0.2s;
}
.btn-page.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ==================== BOTTOM NAV ==================== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  display: flex; max-width: 520px; margin: 0 auto;
  background: #08080f;
  border-top: 1px solid var(--border2); padding: 6px 8px 8px;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; color: var(--text3); font-size: 10px;
  cursor: pointer; padding: 6px 4px; border-radius: var(--radius-xs);
  transition: all 0.2s; font-family: inherit;
}
.nav-item:hover { color: var(--text2); }
.nav-item.active { color: var(--accent2); }
.nav-item.active svg { stroke: var(--accent2); }

/* ==================== MODAL ==================== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7);
  display: none; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal-overlay.visible { display: flex; }
.modal {
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: 20px 20px 0 0; width: 100%; max-width: 520px;
  max-height: 85vh; overflow-y: auto; animation: slideUp 0.3s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border2); position: sticky; top: 0;
  background: var(--surface-solid); z-index: 1;
}
.modal-header h3 { font-size: 16px; }
.modal-close {
  background: none; border: none; color: var(--text2); font-size: 24px;
  cursor: pointer; padding: 4px; line-height: 1;
}
.modal-body { padding: 16px 20px; }
.modal-footer { padding: 12px 20px 20px; }
.modal-preview { width: 100%; border-radius: var(--radius-sm); margin-bottom: 12px; }
.modal-prompt-text { font-size: 14px; color: var(--text2); line-height: 1.5; margin-bottom: 12px; white-space: pre-wrap; }
.modal-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.modal-tag { background: var(--bg2); border-radius: 12px; padding: 3px 10px; font-size: 12px; color: var(--text2); }
.modal-cost { text-align: center; margin-bottom: 8px; }

/* Upload modal */
.upload-modal-area {
  border: 2px dashed var(--border2); border-radius: var(--radius);
  padding: 32px; text-align: center; color: var(--text3); cursor: pointer;
  transition: all 0.2s; margin-bottom: 12px;
}
.upload-modal-area:hover { border-color: var(--accent); color: var(--text2); }
.upload-modal-area.has-files { border-color: var(--success); color: var(--success); }
.upload-modal-thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.upload-modal-thumb { width: 64px; height: 64px; border-radius: 8px; object-fit: cover; }

/* ==================== IMAGE VIEWER ==================== */
.viewer-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(0,0,0,0.92); display: none; align-items: center; justify-content: center;
  animation: fadeIn 0.2s ease;
}
.viewer-overlay.visible { display: flex; }
.viewer-overlay img { max-width: 95%; max-height: 90vh; border-radius: 8px; }
.viewer-close {
  position: absolute; top: 16px; right: 16px;
  background: rgba(255,255,255,0.1); border: none; color: #fff;
  font-size: 28px; width: 44px; height: 44px; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* ==================== TOAST ==================== */
.toast-container { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 400; display: flex; flex-direction: column; gap: 8px; pointer-events: none; max-width: 480px; width: calc(100% - 32px); }
.toast {
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px; font-size: 14px;
  box-shadow: var(--shadow); animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  pointer-events: auto;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--error); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-10px); } }

/* ==================== STATUS MSG ==================== */
.status-msg { text-align: center; padding: 24px; color: var(--text2); font-size: 14px; }
.status-msg.error { color: var(--error); }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 540px) {
  .app-header { padding: 10px 12px; }
  .screens-wrapper { padding: 10px 12px 86px; }
  .header-title { font-size: 16px; }
  .catalog-grid { gap: 8px; }
  .form-row { flex-direction: column; gap: 8px; }
  .form-group.half { flex: none; }
}
@media (max-width: 380px) {
  .chip { padding: 6px 10px; font-size: 12px; }
  .catalog-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .package-card { padding: 12px; }
  .pkg-price { padding: 6px 12px; font-size: 14px; }
  .bottom-nav { padding: 4px 4px 6px; }
  .nav-item { font-size: 9px; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
