/* ── Variables ────────────────────────────────────────────── */
:root {
  --blue:     #007AFF;
  --blue-lt:  rgba(0,122,255,0.12);
  --green:    #34C759;
  --green-lt: rgba(52,199,89,0.12);
  --red:      #FF3B30;
  --red-lt:   rgba(255,59,48,0.12);
  --orange:   #FF9500;
  --orange-lt:rgba(255,149,0,0.12);
  --purple:   #AF52DE;
  --gray1:    #1C1C1E;
  --gray2:    #3A3A3C;
  --gray3:    #636366;
  --gray4:    #8E8E93;
  --gray5:    #AEAEB2;
  --gray6:    #C7C7CC;
  --gray7:    #D1D1D6;
  --gray8:    #E5E5EA;
  --gray9:    #F2F2F7;
  --white:    #FFFFFF;
  --sep:      rgba(60,60,67,0.12);
  --bg:       #F2F2F7;
  --top-h:    56px;
  --nav-h:    80px;
  --r-sm:     10px;
  --r-md:     14px;
  --r-lg:     20px;
  --r-xl:     28px;
  --glass-bg: rgba(255,255,255,0.72);
  --glass-border: rgba(255,255,255,0.9);
  --glass-shadow: 0 4px 24px rgba(0,0,0,0.06), 0 1px 4px rgba(0,0,0,0.04), inset 0 1px 0 rgba(255,255,255,0.85);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Nunito', 'Helvetica Neue', sans-serif;
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; border: none; background: none; color: inherit; font-family: inherit; font-size: inherit; }
input, textarea, select { font-family: var(--font); }
.hidden { display: none !important; }

/* ── Body & mesh bg ───────────────────────────────────────── */
body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--gray1);
  background:
    radial-gradient(ellipse at 15% 20%, rgba(0,122,255,0.18) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 15%, rgba(175,82,222,0.12) 0%, transparent 45%),
    radial-gradient(ellipse at 75% 85%, rgba(52,199,89,0.10) 0%, transparent 45%),
    radial-gradient(ellipse at 20% 80%, rgba(255,149,0,0.08) 0%, transparent 40%),
    var(--bg);
  background-attachment: fixed;
}

/* ── Splash ───────────────────────────────────────────────── */
#splash {
  position: fixed; inset: 0; z-index: 999;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(145deg, #1a73e8 0%, #6a1be8 60%, #0ea5e9 100%);
  transition: opacity .4s ease .1s, visibility .4s ease .1s;
}
#splash.fade-out { opacity: 0; visibility: hidden; }
.splash-inner { text-align: center; }
.splash-icon {
  width: 100px; height: 100px; border-radius: 28px;
  background: rgba(255,255,255,0.2);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.35);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.4);
  animation: iconBounce .6s cubic-bezier(.34,1.56,.64,1) .1s both;
}
@keyframes iconBounce { from { transform: scale(0.4); opacity: 0; } }
.splash-title { font-size: 32px; font-weight: 800; color: white; letter-spacing: -0.5px; }
.splash-sub { font-size: 15px; color: rgba(255,255,255,0.75); margin-top: 6px; }

/* ── Layout ───────────────────────────────────────────────── */
#app-root { display: flex; flex-direction: column; height: 100%; }

/* ── Topbar ───────────────────────────────────────────────── */
#topbar {
  height: var(--top-h); padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--glass-bg);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border-bottom: 1px solid var(--sep);
  flex-shrink: 0;
  position: relative; z-index: 20;
}
.topbar-title { font-size: 17px; font-weight: 700; flex: 1; text-align: center; }
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--blue);
  transition: background .15s;
}
.icon-btn:active { background: var(--blue-lt); }
#topbar-right { display: flex; gap: 4px; }

/* ── Screen ───────────────────────────────────────────────── */
#screen {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-h) + 12px);
  scroll-behavior: smooth;
}
#screen::-webkit-scrollbar { display: none; }

/* ── Bottom nav ───────────────────────────────────────────── */
#bottom-nav {
  height: var(--nav-h);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--glass-bg);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border-top: 1px solid var(--sep);
  display: flex; flex-shrink: 0;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; color: var(--gray4); transition: color .2s;
  font-size: 10px; font-weight: 600; letter-spacing: 0.2px;
  padding-top: 4px;
}
.tab svg { transition: transform .2s; }
.tab.active { color: var(--blue); }
.tab.active svg { transform: scale(1.1); }
.tab span { font-size: 10px; }

/* ── Screen animations ────────────────────────────────────── */
.screen-in { animation: scrIn .3s cubic-bezier(.25,.46,.45,.94) both; }
@keyframes scrIn { from { opacity: 0; transform: translateY(12px); } }

/* ── Glass card ───────────────────────────────────────────── */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  box-shadow: var(--glass-shadow);
  overflow: hidden;
}

/* ── Section header ───────────────────────────────────────── */
.sec-label {
  font-size: 13px; font-weight: 600; color: var(--gray4);
  padding: 20px 20px 8px; letter-spacing: 0.2px;
  text-transform: uppercase; font-size: 11px;
}
.sec-label:first-child { padding-top: 20px; }

/* ── List rows ────────────────────────────────────────────── */
.row {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--sep);
  cursor: pointer; transition: background .12s; position: relative;
}
.row:last-child { border-bottom: none; }
.row:active { background: rgba(0,0,0,0.04); }
.row-icon {
  width: 40px; height: 40px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.row-icon.blue   { background: var(--blue-lt);   color: var(--blue); }
.row-icon.green  { background: var(--green-lt);  color: var(--green); }
.row-icon.red    { background: var(--red-lt);    color: var(--red); }
.row-icon.orange { background: var(--orange-lt); color: var(--orange); }
.row-icon.purple { background: rgba(175,82,222,0.12); color: var(--purple); }
.row-icon.gray   { background: var(--gray9); color: var(--gray3); }
.row-body { flex: 1; min-width: 0; }
.row-title { font-size: 15px; font-weight: 500; color: var(--gray1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub   { font-size: 13px; color: var(--gray4); margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.row-chevron { color: var(--gray6); flex-shrink: 0; }

/* ── Stat cards ───────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; }
.stat {
  background: var(--glass-bg);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-lg);
  box-shadow: var(--glass-shadow);
  padding: 16px; display: flex; flex-direction: column; gap: 8px;
}
.stat-icon { width: 34px; height: 34px; border-radius: var(--r-sm); display: flex; align-items: center; justify-content: center; }
.stat-val { font-size: 26px; font-weight: 800; letter-spacing: -0.5px; line-height: 1; }
.stat-lbl { font-size: 12px; color: var(--gray4); font-weight: 500; }

/* ── Badges ───────────────────────────────────────────────── */
.pill { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.pill.green  { background: var(--green-lt);  color: #1a7a36; }
.pill.red    { background: var(--red-lt);    color: #c0392b; }
.pill.orange { background: var(--orange-lt); color: #b06a00; }
.pill.blue   { background: var(--blue-lt);   color: #0055b3; }
.pill.gray   { background: var(--gray8);     color: var(--gray3); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 15px 20px; border-radius: var(--r-lg);
  font-size: 16px; font-weight: 700; letter-spacing: 0.1px;
  transition: all .15s; cursor: pointer; border: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary   { background: var(--blue);  color: white; }
.btn-green     { background: var(--green); color: white; }
.btn-danger    { background: var(--red-lt); color: var(--red); }
.btn-secondary { background: var(--gray8); color: var(--gray1); }
.btn-ghost     { background: transparent; color: var(--blue); }
.btn-sm        { padding: 9px 18px; font-size: 14px; width: auto; border-radius: var(--r-md); }

/* ── FAB ──────────────────────────────────────────────────── */
.fab {
  position: fixed; right: 20px; bottom: calc(var(--nav-h) + 16px);
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--blue); color: white;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(0,122,255,0.4), 0 2px 8px rgba(0,0,0,0.1);
  transition: transform .2s, box-shadow .2s; z-index: 15; border: none; cursor: pointer;
}
.fab:active { transform: scale(0.92); box-shadow: 0 2px 10px rgba(0,122,255,0.3); }
[dir="rtl"] .fab { right: auto; left: 20px; }

/* ── Forms ────────────────────────────────────────────────── */
.form-body  { padding: 0 20px 8px; }
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--gray3); margin-bottom: 6px; }
.form-input {
  width: 100%; padding: 13px 14px;
  background: rgba(255,255,255,0.85);
  border: 1.5px solid var(--gray7);
  border-radius: var(--r-md);
  font-size: 15px; color: var(--gray1);
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}
.form-input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,122,255,0.12); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-hint { font-size: 12px; color: var(--gray4); margin-top: 5px; }
select.form-input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238E8E93' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
[dir="rtl"] select.form-input { background-position: left 14px center; padding-right: 14px; padding-left: 36px; }

/* ── Search ───────────────────────────────────────────────── */
.search-bar {
  padding: 10px 16px 4px;
  position: relative;
}
.search-input {
  width: 100%; padding: 11px 16px 11px 40px;
  background: rgba(255,255,255,0.85);
  border: 1.5px solid var(--gray7);
  border-radius: var(--r-lg);
  font-size: 15px; color: var(--gray1);
  outline: none; transition: border-color .2s;
}
.search-input:focus { border-color: var(--blue); }
.search-icon { position: absolute; left: 28px; top: 50%; transform: translateY(-50%); color: var(--gray5); pointer-events: none; }
[dir="rtl"] .search-input { padding: 11px 40px 11px 16px; }
[dir="rtl"] .search-icon { left: auto; right: 28px; }

/* ── Alert banner ─────────────────────────────────────────── */
.alert-card { margin: 0 16px 0; border-radius: var(--r-lg); overflow: hidden; border: 1.5px solid; }
.alert-row  { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid; }
.alert-row:last-child { border-bottom: none; }
.alert-dot  { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ── Empty state ──────────────────────────────────────────── */
.empty { display: flex; flex-direction: column; align-items: center; padding: 60px 24px; text-align: center; gap: 10px; }
.empty-icon { width: 72px; height: 72px; border-radius: var(--r-xl); background: var(--gray8); display: flex; align-items: center; justify-content: center; color: var(--gray5); margin-bottom: 4px; }
.empty-title { font-size: 17px; font-weight: 700; color: var(--gray2); }
.empty-sub   { font-size: 14px; color: var(--gray4); line-height: 1.5; max-width: 240px; }

/* ── Progress bar ─────────────────────────────────────────── */
.prog-wrap { padding: 6px 16px 12px; }
.prog-row  { display: flex; justify-content: space-between; font-size: 12px; color: var(--gray4); margin-bottom: 6px; }
.prog-track { height: 4px; background: var(--gray7); border-radius: 2px; overflow: hidden; }
.prog-fill  { height: 100%; background: var(--blue); border-radius: 2px; transition: width .5s; }
.prog-fill.warn { background: var(--orange); }
.prog-fill.danger { background: var(--red); }

/* ── Sheet ────────────────────────────────────────────────── */
#sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
  animation: fadein .25s;
}
@keyframes fadein { from { opacity: 0; } }
#sheet {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 51;
  background: rgba(242,242,247,0.95);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid rgba(255,255,255,0.8);
  max-height: 92vh; overflow-y: auto;
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 16px);
  animation: sheetUp .3s cubic-bezier(.32,.72,0,1);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.12);
}
@keyframes sheetUp { from { transform: translateY(100%); } }
#sheet-handle { width: 36px; height: 4px; background: var(--gray6); border-radius: 2px; margin: 10px auto 0; }
#sheet-body   { padding: 16px 0 8px; }
.sheet-title  { font-size: 17px; font-weight: 700; padding: 4px 20px 16px; }

/* ── Toast ────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%; transform: translateX(-50%);
  background: rgba(50,50,54,0.92);
  backdrop-filter: blur(20px);
  color: white; padding: 11px 20px; border-radius: var(--r-xl);
  font-size: 14px; font-weight: 500; white-space: nowrap;
  opacity: 0; transition: opacity .2s, transform .2s;
  pointer-events: none; z-index: 200;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ── Auth screens ─────────────────────────────────────────── */
#auth-root {
  position: fixed; inset: 0; z-index: 30; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 15% 20%, rgba(0,122,255,0.2) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 80%, rgba(175,82,222,0.15) 0%, transparent 50%),
    #F2F2F7;
  min-height: 100%;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--glass-bg);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid var(--glass-border);
  border-radius: var(--r-xl);
  box-shadow: var(--glass-shadow);
  padding: 32px 28px;
}
.auth-logo { width: 72px; height: 72px; border-radius: 20px; background: linear-gradient(135deg,#007AFF,#5856D6); display: flex; align-items: center; justify-content: center; margin: 0 auto 20px; box-shadow: 0 4px 20px rgba(0,122,255,0.35); }
.auth-title { font-size: 26px; font-weight: 800; text-align: center; margin-bottom: 6px; }
.auth-sub   { font-size: 14px; color: var(--gray4); text-align: center; margin-bottom: 28px; }
.or-divider { display: flex; align-items: center; gap: 12px; margin: 16px 0; color: var(--gray4); font-size: 13px; }
.or-divider::before, .or-divider::after { content: ''; flex: 1; height: 1px; background: var(--sep); }
.auth-link  { text-align: center; font-size: 14px; color: var(--gray4); margin-top: 16px; }
.auth-link a { color: var(--blue); font-weight: 600; text-decoration: none; }
.error-box  { background: var(--red-lt); border: 1px solid rgba(255,59,48,0.2); border-radius: var(--r-md); padding: 12px 14px; font-size: 14px; color: var(--red); margin-bottom: 16px; }

/* ── Settings rows ────────────────────────────────────────── */
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; border-bottom: 1px solid var(--sep); cursor: pointer; transition: background .12s; }
.settings-row:last-child { border-bottom: none; }
.settings-row:active { background: rgba(0,0,0,0.04); }
.settings-row-left { display: flex; align-items: center; gap: 12px; }
.settings-row-label { font-size: 15px; color: var(--gray1); }
.settings-row-sub   { font-size: 12px; color: var(--gray4); margin-top: 1px; }
.settings-row-value { font-size: 14px; color: var(--gray4); display: flex; align-items: center; gap: 6px; }

/* ── Toggle ───────────────────────────────────────────────── */
.toggle { width: 50px; height: 28px; background: var(--gray6); border-radius: 14px; position: relative; cursor: pointer; transition: background .2s; flex-shrink: 0; }
.toggle.on { background: var(--green); }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; background: white; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 4px rgba(0,0,0,0.2); }
.toggle.on::after { transform: translateX(22px); }

/* ── Color swatches ───────────────────────────────────────── */
.swatches { display: flex; gap: 10px; flex-wrap: wrap; padding: 8px 0; }
.swatch   { width: 34px; height: 34px; border-radius: 50%; cursor: pointer; border: 3px solid transparent; transition: all .2s; }
.swatch.sel { border-color: white; box-shadow: 0 0 0 2px var(--blue); transform: scale(1.1); }

/* ── Product detail stats ─────────────────────────────────── */
.detail-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; padding: 16px 16px 0; }
.detail-stat  { background: var(--glass-bg); backdrop-filter: blur(40px); -webkit-backdrop-filter: blur(40px); border: 1px solid var(--glass-border); border-radius: var(--r-md); padding: 14px 12px; box-shadow: var(--glass-shadow); }
.detail-stat-val { font-size: 20px; font-weight: 800; }
.detail-stat-lbl { font-size: 11px; color: var(--gray4); margin-top: 2px; }

/* ── Adjust buttons ───────────────────────────────────────── */
.adj-btns { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; padding: 12px 16px 0; }
.adj-btn  { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 8px; border-radius: var(--r-md); font-size: 12px; font-weight: 600; border: 1.5px solid; cursor: pointer; transition: all .15s; }
.adj-btn:active { transform: scale(0.95); }
.adj-btn.green  { background: var(--green-lt);  border-color: rgba(52,199,89,.3);  color: #1a7a36; }
.adj-btn.red    { background: var(--red-lt);    border-color: rgba(255,59,48,.3);  color: #c0392b; }
.adj-btn.blue   { background: var(--blue-lt);   border-color: rgba(0,122,255,.3);  color: #0055b3; }

/* ── Lang switcher ────────────────────────────────────────── */
.lang-opts { display: flex; gap: 10px; padding: 8px 0; }
.lang-opt  { flex: 1; padding: 12px; border-radius: var(--r-md); border: 1.5px solid var(--gray7); background: white; font-size: 14px; font-weight: 600; text-align: center; cursor: pointer; transition: all .2s; color: var(--gray3); }
.lang-opt.sel { border-color: var(--blue); background: var(--blue-lt); color: var(--blue); }

/* ── Dashboard header ─────────────────────────────────────── */
.dash-header { padding: 18px 18px 4px; }
.dash-greeting { font-size: 13px; color: var(--gray4); }
.dash-name { font-size: 24px; font-weight: 800; letter-spacing: -0.3px; }

/* ── Txn colors ───────────────────────────────────────────── */
.txn-in   .row-icon { background: var(--green-lt); color: var(--green); }
.txn-out  .row-icon { background: var(--red-lt);   color: var(--red); }
.txn-adj  .row-icon { background: var(--blue-lt);  color: var(--blue); }
.txn-sale .row-icon { background: rgba(175,82,222,0.12); color: var(--purple); }

/* ── Spinner ──────────────────────────────────────────────── */
.spinner { width: 22px; height: 22px; border: 2.5px solid rgba(255,255,255,0.4); border-top-color: white; border-radius: 50%; animation: spin .7s linear infinite; }
.spinner.dark { border-color: var(--gray7); border-top-color: var(--blue); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── RTL support ──────────────────────────────────────────── */
[dir="rtl"] { font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif; }
[dir="rtl"] .row-chevron { transform: scaleX(-1); }
[dir="rtl"] select.form-input { background-position: left 14px center; padding: 13px 14px 13px 36px; }

/* ── Padding for content ──────────────────────────────────── */
.pad { padding: 0 16px; }
.pad-y { padding: 16px 0; }
