/* ============================================================
   Turntom — App Stylesheet
   Premium dark theme, mobile-first
   ============================================================ */

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

:root {
  --ink:        #0A0C10;
  --ink2:       #141720;
  --ink3:       #1E2128;
  --ink4:       #2A2D38;
  --gold:       #C8A96E;
  --gold-dark:  #A8893E;
  --gold-dim:   rgba(200,169,110,0.12);
  --gold-border:rgba(200,169,110,0.22);
  --cream:      #F0EEE8;
  --ash:        #8A8C94;
  --ash2:       #5A5D67;
  --ash3:       #3A3D47;
  --jade:       #3A7D5A;
  --jade-dim:   rgba(58,125,90,0.15);
  --danger:     #C0392B;
  --danger-dim: rgba(192,57,43,0.12);
  --border:     #22252E;
  --radius:     18px;
  --radius-sm:  12px;
  --radius-xs:  8px;
  --nav-h:      68px;
  --top-h:      56px;
  --font:       'Plus Jakarta Sans', -apple-system, sans-serif;
  --safe-area-btm: env(safe-area-inset-bottom, 0px);
}

html { height: 100%; }

body {
  font-family: var(--font);
  background: var(--ink);
  color: var(--cream);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

input, button, select { font-family: var(--font); }
button { cursor: pointer; border: none; background: none; }
a { color: var(--gold); text-decoration: none; }

/* ── Utility ─────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── App Loader ───────────────────────────────────────────── */
.app-loader {
  position: fixed; inset: 0;
  background: var(--ink);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 28px; z-index: 9999;
  transition: opacity 0.15s ease;
}
.app-loader.fade-out { opacity: 0; pointer-events: none; }

.loader-logo {
  font-size: 32px; font-weight: 800;
  color: var(--gold); letter-spacing: -1px;
}
.loader-logo span { color: var(--ash2); }

.loader-spinner {
  width: 28px; height: 28px;
  border: 2.5px solid var(--ink3);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px);
  left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--cream); color: var(--ink);
  padding: 12px 20px; border-radius: 12px;
  font-size: 13px; font-weight: 700;
  white-space: nowrap; z-index: 8000;
  opacity: 0; transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
  border: 1px solid var(--gold-border);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.toast.show {
  opacity: 1; transform: translateX(-50%) translateY(0);
}

/* ── App shell ────────────────────────────────────────────── */
#app { height: 100vh; }

/* ── Auth wrapper ─────────────────────────────────────────── */
.auth-wrapper {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 20px;
  overflow-y: auto;
}
.auth-page { width: 100%; max-width: 420px; }
.auth-inner { width: 100%; }

.auth-logo { text-align: center; margin-bottom: 36px; }
.auth-title { text-align: center; margin-bottom: 36px; }
.auth-title h1 {
  font-size: 30px; font-weight: 800;
  color: var(--gold); letter-spacing: -1px;
}
.logo-icon {
  width: 60px; height: 60px;
  background: var(--gold-dim);
  border: 1px solid var(--gold-border);
  border-radius: 18px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  overflow: hidden;
}
.logo-icon img {
  width: 100%; height: 100%; object-fit: contain;
}
.logo-text {
  font-size: 30px; font-weight: 800;
  color: var(--gold); letter-spacing: -1px;
}
.logo-text span { color: var(--ash2); }
.logo-sub { font-size: 13px; color: var(--ash2); margin-top: 6px; font-weight: 500; }

/* ── Main wrapper ─────────────────────────────────────────── */
.main-wrapper {
  height: 100vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* ── Top bar ──────────────────────────────────────────────── */
.topbar {
  height: var(--top-h);
  background: rgba(10,12,16,0.95);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  backdrop-filter: blur(12px);
  z-index: 100;
}
.topbar-logo {
  font-size: 20px; font-weight: 800;
  color: var(--gold); letter-spacing: -0.8px;
}
.topbar-logo span { color: var(--ash3); }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--ash);
}
.user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--gold-dim);
  border: 1px solid var(--gold-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: var(--gold);
}

/* ── Main content ─────────────────────────────────────────── */
.main-content {
  flex: 1; overflow-y: auto;
  padding-bottom: calc(var(--nav-h) + 16px + var(--safe-area-btm));
  -webkit-overflow-scrolling: touch;
}
.main-content::-webkit-scrollbar { display: none; }

/* ── Pages ────────────────────────────────────────────────── */
.page { padding: 20px 20px 12px; max-width: 600px; margin: 0 auto; }

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

.page-title {
  font-size: 24px; font-weight: 800;
  color: var(--cream); letter-spacing: -0.6px;
  line-height: 1.15;
}
.page-sub { font-size: 13px; color: var(--ash2); margin-top: 3px; }

.greeting { font-size: 12px; color: var(--ash2); font-weight: 500; }
.user-name { font-size: 20px; font-weight: 800; color: var(--cream); letter-spacing: -0.4px; }

.icon-btn {
  width: 36px; height: 36px;
  background: var(--ink2);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--ash);
  transition: border-color 0.2s;
}
.icon-btn:hover { border-color: var(--gold-border); }

/* ── Section label ────────────────────────────────────────── */
.section-label {
  font-size: 10px; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase;
  color: var(--ash3);
  margin: 20px 0 10px;
}

/* ── Hero card ────────────────────────────────────────────── */
.hero-card {
  background: var(--ink2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-top: 18px;
  position: relative; overflow: hidden;
}
.hero-card::after {
  content: '';
  position: absolute; top: -40px; right: -40px;
  width: 160px; height: 160px; border-radius: 50%;
  background: var(--gold-dim);
  pointer-events: none;
}
.hero-label {
  font-size: 10px; font-weight: 700;
  letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--ash3); margin-bottom: 8px;
}
.hero-amount {
  font-size: 40px; font-weight: 800;
  color: var(--gold); letter-spacing: -1.5px;
  line-height: 1;
}
.hero-meta {
  display: flex; align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  font-size: 11px; color: var(--ash2); font-weight: 500;
}
.badge-green {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--jade-dim); color: var(--jade);
  border: 1px solid rgba(58,125,90,0.25);
  padding: 3px 9px; border-radius: 20px;
  font-size: 10px; font-weight: 700;
}

/* ── Stats grid ───────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px; margin-top: 12px;
}
.stat-card {
  background: var(--ink2);
  border: 1px solid var(--border);
  border-radius: 16px; padding: 16px;
}
.stat-icon { font-size: 14px; margin-bottom: 8px; opacity: 0.7; }
.stat-value {
  font-size: 20px; font-weight: 800;
  color: var(--cream); letter-spacing: -0.5px;
}
.stat-label { font-size: 11px; color: var(--ash2); margin-top: 4px; font-weight: 500; }

/* ── Card ─────────────────────────────────────────────────── */
.card {
  background: var(--ink2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 10px;
}

/* ── Forms ────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.8px; text-transform: uppercase;
  color: var(--ash3); margin-bottom: 6px;
}
.form-group input, .form-group select {
  width: 100%; padding: 13px 15px;
  background: var(--ink3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--cream); font-size: 15px;
  font-weight: 500; outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.form-group input:focus, .form-group select:focus {
  border-color: var(--gold-border);
}
.form-group input::placeholder { color: var(--ash3); font-weight: 400; }

.input-wrap { position: relative; }
.input-wrap input { padding-right: 48px; }
.eye-btn {
  position: absolute; right: 14px; top: 50%;
  transform: translateY(-50%);
  color: var(--ash3); display: flex;
  align-items: center; padding: 4px;
  transition: color 0.2s;
}
.eye-btn:hover { color: var(--ash); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  width: 100%; padding: 15px;
  background: var(--gold); color: var(--ink);
  border-radius: 14px; font-size: 15px;
  font-weight: 800; letter-spacing: 0.2px;
  transition: all 0.15s; display: block;
  margin-top: 18px;
}
.btn-primary:hover { background: var(--gold-dark); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled {
  opacity: 0.35; cursor: not-allowed;
  transform: none !important;
}
.btn-outline {
  width: 100%; padding: 15px;
  background: transparent; color: var(--ash);
  border: 1px solid var(--border);
  border-radius: 14px; font-size: 15px;
  font-weight: 700; transition: all 0.15s; display: block;
}
.btn-outline:hover { background: var(--ink2); }
.btn-outline:active { transform: scale(0.97); }
.btn-danger {
  width: 100%; padding: 15px;
  background: transparent; color: var(--danger);
  border: 1px solid rgba(192,57,43,0.3);
  border-radius: 14px; font-size: 15px;
  font-weight: 700; transition: all 0.15s;
  margin-top: 4px; display: block;
}
.btn-danger:hover { background: var(--danger-dim); }
.link-btn {
  font-size: 13px; font-weight: 700; color: var(--gold);
  width: 100%; text-align: center; padding: 8px 0; display: block;
}
.back-link {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 13px; font-weight: 600; color: var(--ash2);
  transition: color 0.2s;
}
.back-link:hover { color: var(--gold); }

/* ── Alerts ───────────────────────────────────────────────── */
.alert {
  padding: 11px 14px; border-radius: 10px;
  font-size: 13px; font-weight: 600;
  margin-bottom: 12px;
}
.alert-error {
  background: var(--danger-dim);
  border: 1px solid rgba(192,57,43,0.25);
  color: #E57368;
}

/* ── Auth extras ──────────────────────────────────────────── */
.auth-divider {
  text-align: center; margin: 6px 0;
  position: relative; color: var(--ash3);
  font-size: 11px; font-weight: 600; letter-spacing: 0.5px;
}
.auth-switch {
  text-align: center; font-size: 13px;
  color: var(--ash2); margin-top: 14px;
}
.auth-switch a { font-weight: 700; }

/* ── Calc result ──────────────────────────────────────────── */
.calc-result {
  background: var(--ink2);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-sm);
  padding: 16px; margin-top: 14px;
}
.calc-item { }
.calc-label {
  font-size: 10px; font-weight: 700;
  letter-spacing: 0.8px; text-transform: uppercase;
  color: var(--ash3); margin-bottom: 4px;
}
.calc-value {
  font-size: 22px; font-weight: 800;
  color: var(--gold); letter-spacing: -0.5px;
}
.calc-divider { height: 1px; background: var(--border); margin: 12px 0; }
.calc-note {
  font-size: 10px; color: var(--ash3);
  font-weight: 600; letter-spacing: 0.3px;
  text-align: center; margin-top: 2px;
}
.calc-row-inner {
  display: flex; justify-content: space-between;
}

/* ── Trip rows ────────────────────────────────────────────── */
.trip-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  background: var(--ink2);
  border: 1px solid var(--border);
  border-radius: 14px; padding: 14px 16px;
  margin-bottom: 8px;
  transition: border-color 0.2s;
  cursor: pointer;
}
.trip-row:hover { border-color: var(--gold-border); }
.trip-date-badge {
  min-width: 44px; height: 52px;
  background: var(--gold-dim);
  border: 1px solid var(--gold-border);
  border-radius: 10px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  margin-right: 12px; flex-shrink: 0;
}
.trip-date-day {
  font-size: 17px; font-weight: 800; color: var(--gold);
  line-height: 1;
}
.trip-date-mon {
  font-size: 8px; font-weight: 700; color: var(--gold-dark);
  letter-spacing: 0.5px; text-transform: uppercase;
}
.trip-info { flex: 1 1 0; min-width: 0; }
.trip-time { font-size: 11px; color: var(--ash2); font-weight: 500; margin-bottom: 3px; }
.trip-detail {
  font-size: 13px; font-weight: 600; color: var(--ash);
  overflow: hidden; text-overflow: ellipsis;
  white-space: normal; word-break: break-word;
}
.trip-earn {
  font-size: 16px; font-weight: 800;
  color: var(--gold); letter-spacing: -0.3px;
  flex-shrink: 0; margin-left: auto;
}
.trip-delete {
  background: none; border: none; color: var(--ash3);
  margin-left: 8px; padding: 4px; flex-shrink: 0;
  transition: color 0.2s;
}
.trip-delete:hover { color: var(--danger); }

/* ── Empty state ──────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 36px 20px;
  background: var(--ink2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.empty-icon { font-size: 36px; margin-bottom: 12px; }
.empty-state p { font-size: 13px; color: var(--ash2); }

/* ── Tab bar ──────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  background: var(--ink2);
  border: 1px solid var(--border);
  border-radius: 30px; padding: 3px;
}
.tab-btn {
  flex: 1; padding: 8px 0;
  border-radius: 24px; font-size: 12px;
  font-weight: 700; color: var(--ash3);
  background: transparent;
  transition: all 0.2s; letter-spacing: 0.2px;
}
.tab-btn.active {
  background: var(--ink3); color: var(--cream);
  border: 1px solid var(--border);
}
.tab-panel { }

/* ── Bar chart ────────────────────────────────────────────── */
.bar-chart { padding: 4px 0 0; }
.bar-chart-inner {
  display: flex; align-items: flex-end;
  gap: 6px; height: 100px;
  padding: 0 2px;
}
.bar-col {
  flex: 1; height: 100%;
  display: flex; align-items: flex-end;
}
.bar-body {
  width: 100%; background: var(--ink3);
  border-radius: 5px 5px 0 0;
  min-height: 4px;
  transition: height 0.7s cubic-bezier(0.34,1.4,0.64,1);
}
.bar-body.active { background: var(--gold); }
.bar-days {
  display: flex; justify-content: space-between;
  padding: 6px 2px 0;
  font-size: 9px; font-weight: 700;
  color: var(--ash3); letter-spacing: 0.3px;
}

/* ── Settings ─────────────────────────────────────────────── */
.profile-row {
  display: flex; align-items: center; gap: 14px;
}
.profile-avatar {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--gold-dim);
  border: 1.5px solid var(--gold-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800; color: var(--gold);
  flex-shrink: 0;
}
.profile-name { font-size: 15px; font-weight: 800; color: var(--cream); }
.profile-email { font-size: 12px; color: var(--ash2); margin-top: 2px; }

.unit-toggle {
  display: flex; gap: 8px; margin-bottom: 10px;
}
.unit-btn {
  flex: 1; padding: 12px 0;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--ink2); color: var(--ash2);
  font-size: 13px; font-weight: 700;
  transition: all 0.2s; text-align: center;
}
.unit-btn.active {
  background: var(--gold); color: var(--ink);
  border-color: var(--gold);
}

.currency-row {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background 0.15s;
  font-size: 14px; font-weight: 500; color: var(--ash);
}
.currency-row.last { border-bottom: none; }
.currency-row:hover { background: var(--ink3); }
.currency-row .check { opacity: 0; transition: opacity 0.15s; }
.currency-row.active { color: var(--gold); }
.currency-row.active .check { opacity: 1; }

/* ── Bottom nav ───────────────────────────────────────────── */
.bottom-nav {
  height: var(--nav-h);
  background: rgba(10,12,16,0.97);
  border-top: 1px solid var(--border);
  display: flex; align-items: center;
  justify-content: space-around;
  padding: 0 4px calc(8px + var(--safe-area-btm));
  flex-shrink: 0;
  z-index: 100;
  backdrop-filter: blur(16px);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
}
.nav-item {
  display: flex; flex-direction: column;
  align-items: center; gap: 3px;
  padding: 6px 12px;
  color: var(--ash3);
  border-radius: 10px;
  transition: color 0.2s;
  font-size: 9px; font-weight: 700;
  letter-spacing: 0.5px; text-transform: uppercase;
  min-width: 52px;
}
.nav-item.active { color: var(--gold); }
.nav-item svg { transition: transform 0.15s; }
.nav-item:active svg { transform: scale(0.85); }

/* ── Loader in btn ────────────────────────────────────────── */
.btn-loading {
  display: flex; align-items: center;
  justify-content: center; gap: 8px;
}
.btn-spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(10,12,16,0.3);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Desktop max-width centering ──────────────────────────── */
@media (min-width: 640px) {
  .auth-wrapper { padding: 40px 24px; }
  .page { padding: 28px 28px 16px; }
  .hero-amount { font-size: 44px; }
}

@media (min-width: 900px) {
  .main-wrapper { max-width: 640px; margin: 0 auto; box-shadow: 0 0 0 1px var(--border); }
}

/* Mobile fixes: disable heavy backdrop filters and force simple compositing on history page
   to avoid device-specific rendering artifacts that look like screen damage. */
@media (max-width: 480px) {
  .topbar, .bottom-nav { backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
  #page-history { -webkit-backface-visibility: hidden; backface-visibility: hidden; transform: translateZ(0); }
  .trip-row, .trip-date-badge, .trip-earn { -webkit-transform: translateZ(0); transform: translateZ(0); }
}
