*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #00C853;
  --accent-dark: #009624;
  --accent-dim: rgba(0,200,83,0.12);
  --red: #FF3B30;
  --red-dim: rgba(255,59,48,0.12);
  --orange: #FF9F0A;
  --orange-dim: rgba(255,159,10,0.12);
  --blue: #0A84FF;
  --blue-dim: rgba(10,132,255,0.12);
  --purple: #BF5AF2;
  --bg: #0A0A0A;
  --bg2: #141414;
  --bg3: #1C1C1C;
  --surface: #1C1C1E;
  --surface2: #2C2C2E;
  --border: rgba(255,255,255,0.08);
  --border2: rgba(255,255,255,0.04);
  --text: #FFFFFF;
  --text2: rgba(255,255,255,0.85);
  --text3: rgba(255,255,255,0.45);
  --text4: rgba(255,255,255,0.2);
  --font: -apple-system, 'SF Pro Display', 'Helvetica Neue', Arial, sans-serif;
  --radius: 12px;
  --radius-lg: 16px;
  --tab-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* ===================== SPLASH ===================== */
#splash {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease, transform 0.5s ease;
  gap: 20px;
}
#splash.hide {
  opacity: 0;
  transform: scale(1.05);
  pointer-events: none;
}
.splash-logo {
  width: 96px;
  height: 96px;
  background: var(--accent);
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 60px rgba(0,200,83,0.35);
}
.splash-logo svg { width: 52px; height: 52px; color: #fff; }
.splash-name {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.8px;
  color: var(--text);
}
.splash-tagline {
  font-size: 14px;
  color: var(--text3);
  letter-spacing: 0.2px;
}
.splash-loader {
  margin-top: 48px;
  width: 36px;
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  overflow: hidden;
}
.splash-loader-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  animation: loadBar 1.2s cubic-bezier(0.4,0,0.2,1) forwards;
}
@keyframes loadBar { to { width: 100%; } }

/* ===================== APP SHELL ===================== */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.3s ease 0.1s;
}
#app.visible { opacity: 1; }

/* ===================== TOPBAR ===================== */
.topbar {
  background: rgba(10,10,10,0.9);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid var(--border);
  padding: calc(var(--safe-t) + 14px) 16px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  min-height: 56px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-left { display: flex; flex-direction: column; gap: 1px; }
.topbar-title { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.topbar-sub { font-size: 12px; color: var(--text3); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-btn {
  background: var(--surface);
  border: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 14px;
  border-radius: 20px;
  font-family: var(--font);
  display: flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.1s;
}
.topbar-btn:active { opacity: 0.6; }
.topbar-btn svg { width: 14px; height: 14px; }

/* ===================== SCROLL ===================== */
.page-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: calc(var(--tab-h) + var(--safe-b) + 80px);
}

/* ===================== TABBAR ===================== */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(20,20,20,0.95);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-b);
  z-index: 100;
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px 4px 8px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text3);
  font-family: var(--font);
  min-height: var(--tab-h);
  position: relative;
  transition: color 0.15s;
  gap: 4px;
}
.tab-btn svg { width: 22px; height: 22px; }
.tab-btn span { font-size: 10px; font-weight: 500; letter-spacing: 0.1px; }
.tab-btn.active { color: var(--accent); }
.tab-btn.active svg { filter: drop-shadow(0 0 6px rgba(0,200,83,0.4)); }
.tab-badge {
  position: absolute;
  top: 7px;
  right: calc(50% - 16px);
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ===================== PAGES ===================== */
.page { display: none; height: 100%; flex-direction: column; }
.page.active { display: flex; }

/* ===================== STATS GRID ===================== */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 16px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  border: 1px solid var(--border2);
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 60px; height: 60px;
  border-radius: 0 var(--radius-lg) 0 60px;
  opacity: 0.06;
}
.stat-card.c-green::after { background: var(--accent); }
.stat-card.c-red::after { background: var(--red); }
.stat-card.c-orange::after { background: var(--orange); }
.stat-card.c-blue::after { background: var(--blue); }

.stat-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.stat-icon svg { width: 16px; height: 16px; }
.si-green { background: var(--accent-dim); color: var(--accent); }
.si-red { background: var(--red-dim); color: var(--red); }
.si-orange { background: var(--orange-dim); color: var(--orange); }
.si-blue { background: var(--blue-dim); color: var(--blue); }

.stat-val {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -1.5px;
  line-height: 1;
  margin-bottom: 4px;
}
.stat-val.green { color: var(--accent); }
.stat-val.red { color: var(--red); }
.stat-val.orange { color: var(--orange); }
.stat-val.blue { color: var(--blue); }
.stat-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* ===================== SECTION ===================== */
.section { padding: 8px 16px 6px; }
.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* ===================== LIST CARDS ===================== */
.list-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin: 6px 16px;
  border: 1px solid var(--border2);
}
.list-row {
  display: flex;
  align-items: center;
  padding: 13px 16px;
  gap: 13px;
  border-bottom: 1px solid var(--border2);
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}
.list-row:last-child { border-bottom: none; }
.list-row:active { background: var(--surface2); }

.row-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.row-icon svg { width: 18px; height: 18px; }
.ri-green { background: var(--accent-dim); color: var(--accent); }
.ri-red { background: var(--red-dim); color: var(--red); }
.ri-orange { background: var(--orange-dim); color: var(--orange); }
.ri-blue { background: var(--blue-dim); color: var(--blue); }
.ri-purple { background: rgba(191,90,242,0.12); color: var(--purple); }
.ri-gray { background: var(--surface2); color: var(--text3); }

.row-body { flex: 1; min-width: 0; }
.row-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 12px; color: var(--text3); margin-top: 2px; }

.row-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chevron { color: var(--text4); }
.chevron svg { width: 14px; height: 14px; }

/* ===================== QTY PILL ===================== */
.qty-pill {
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  min-width: 36px;
  text-align: center;
  letter-spacing: -0.3px;
}
.qty-pill.ok { background: var(--accent-dim); color: var(--accent); }
.qty-pill.low { background: var(--orange-dim); color: var(--orange); }
.qty-pill.out { background: var(--red-dim); color: var(--red); }

/* ===================== FAB ===================== */
.fab {
  position: fixed;
  bottom: calc(var(--tab-h) + var(--safe-b) + 20px);
  right: 20px;
  width: 54px; height: 54px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 24px rgba(0,200,83,0.4);
  z-index: 90;
  transition: transform 0.15s, box-shadow 0.15s;
}
.fab svg { width: 26px; height: 26px; }
.fab:active { transform: scale(0.92); box-shadow: 0 2px 12px rgba(0,200,83,0.25); }

/* ===================== SEARCH ===================== */
.search-wrap {
  padding: 10px 16px 8px;
  position: relative;
}
.search-wrap svg {
  position: absolute;
  left: 28px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--text3);
  pointer-events: none;
}
.search-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 10px 16px 10px 40px;
  font-size: 15px;
  color: var(--text);
  font-family: var(--font);
}
.search-input::placeholder { color: var(--text4); }
.search-input:focus { outline: 2px solid var(--accent); outline-offset: 0; }

/* ===================== FILTER PILLS ===================== */
.filter-bar {
  display: flex; gap: 8px;
  padding: 4px 16px 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.filter-bar::-webkit-scrollbar { display: none; }
.filter-pill {
  flex-shrink: 0;
  padding: 7px 16px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border2);
  color: var(--text3);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
}
.filter-pill.active { background: var(--accent); color: #000; border-color: var(--accent); }

/* ===================== LOG ROWS ===================== */
.log-row {
  display: flex; align-items: center;
  padding: 13px 16px; gap: 12px;
  border-bottom: 1px solid var(--border2);
}
.log-row:last-child { border-bottom: none; }
.log-icon {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.log-icon svg { width: 16px; height: 16px; }
.log-icon.add { background: var(--accent-dim); color: var(--accent); }
.log-icon.sell { background: var(--red-dim); color: var(--red); }
.log-body { flex: 1; min-width: 0; }
.log-title { font-size: 14px; font-weight: 600; }
.log-meta { font-size: 12px; color: var(--text3); margin-top: 2px; }
.log-qty { font-size: 15px; font-weight: 800; letter-spacing: -0.5px; }
.log-qty.add { color: var(--accent); }
.log-qty.sell { color: var(--red); }

/* ===================== SHEET ===================== */
.sheet-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(4px);
}
.sheet-overlay.hidden { display: none; }
.sheet {
  background: var(--bg2);
  border-radius: 24px 24px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 0 0 calc(var(--safe-b) + 20px);
  width: 100%; max-width: 560px;
  animation: sheetUp 0.3s cubic-bezier(0.34,1.56,0.64,1);
  max-height: 90dvh;
  overflow-y: auto;
}
@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.sheet-handle {
  width: 40px; height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  margin: 12px auto 20px;
}
.sheet-title {
  font-size: 20px; font-weight: 800;
  padding: 0 20px 20px;
  letter-spacing: -0.5px;
}
.sheet-body { padding: 0 16px; }

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 11px; font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
  padding-left: 2px;
}
.input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 16px;
  color: var(--text);
  font-family: var(--font);
  -webkit-appearance: none;
  transition: border-color 0.15s;
}
.input:focus { outline: none; border-color: var(--accent); }
select.input { cursor: pointer; }

.sheet-actions { display: flex; gap: 10px; padding: 20px 16px 0; }

/* ===================== BUTTONS ===================== */
.btn {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 15px;
  border-radius: var(--radius);
  border: none;
  font-size: 16px; font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  transition: opacity 0.1s, transform 0.1s;
  letter-spacing: -0.2px;
  text-decoration: none;
}
.btn svg { width: 18px; height: 18px; }
.btn:active { opacity: 0.75; transform: scale(0.98); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-green { background: var(--accent); color: #000; }
.btn-red { background: var(--red); color: #fff; }
.btn-ghost { background: var(--surface); color: var(--text2); border: 1px solid var(--border); }
.btn-blue { background: var(--blue); color: #fff; }

/* ===================== PROFILE ===================== */
.profile-hero {
  display: flex; flex-direction: column; align-items: center;
  padding: 36px 16px 28px; gap: 12px;
}
.profile-av {
  width: 84px; height: 84px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 800;
  color: #fff;
  box-shadow: 0 0 40px rgba(0,200,83,0.2);
}
.profile-name { font-size: 22px; font-weight: 800; letter-spacing: -0.6px; }
.profile-email { font-size: 13px; color: var(--text3); }

/* ===================== ROLE CHIP ===================== */
.role-chip {
  font-size: 11px; font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.role-chip.admin { background: var(--red-dim); color: var(--red); }
.role-chip.reseller { background: var(--blue-dim); color: var(--blue); }
.role-chip.shop { background: var(--accent-dim); color: var(--accent); }

/* ===================== DETAIL PAGE ===================== */
#page-detail {
  display: none;
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 150;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.detail-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 0 16px 16px;
}
.detail-stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 12px;
  border: 1px solid var(--border2);
  text-align: center;
}
.detail-stat-val { font-size: 22px; font-weight: 800; letter-spacing: -0.8px; }
.detail-stat-label { font-size: 11px; color: var(--text3); margin-top: 4px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.4px; }

/* ===================== EMPTY / LOADING ===================== */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 64px 24px; gap: 14px; color: var(--text3);
}
.empty-icon {
  width: 64px; height: 64px;
  background: var(--surface);
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
}
.empty-icon svg { width: 32px; height: 32px; color: var(--text3); }
.empty-state p { font-size: 15px; text-align: center; line-height: 1.5; }
.loading-state { display: flex; justify-content: center; padding: 48px; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== ALERT ===================== */
.alert {
  margin: 0 16px 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.alert svg { width: 16px; height: 16px; flex-shrink: 0; }
.alert-warn { background: var(--orange-dim); color: var(--orange); }
.alert-err { background: var(--red-dim); color: var(--red); }
.alert-ok { background: var(--accent-dim); color: var(--accent); }

/* ===================== SHOP SELECTOR ===================== */
.shop-sel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 7px 32px 7px 12px;
  font-size: 13px; font-weight: 600;
  color: var(--text2);
  font-family: var(--font);
  -webkit-appearance: none;
  cursor: pointer;
  max-width: 150px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23666' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* ===================== LOGIN ===================== */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100dvh; padding: 24px;
  background: var(--bg);
}
.login-box { width: 100%; max-width: 360px; }
.login-logo {
  width: 72px; height: 72px;
  background: var(--accent);
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 0 48px rgba(0,200,83,0.3);
}
.login-logo svg { width: 40px; height: 40px; color: #000; }
.login-title { text-align: center; font-size: 26px; font-weight: 800; letter-spacing: -0.8px; margin-bottom: 6px; }
.login-sub { text-align: center; font-size: 14px; color: var(--text3); margin-bottom: 36px; }

/* ===================== TOAST ===================== */
#toast {
  position: fixed;
  bottom: calc(var(--tab-h) + var(--safe-b) + 24px);
  left: 50%; transform: translateX(-50%);
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px; font-weight: 600;
  z-index: 999;
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
  white-space: nowrap;
  max-width: 88vw;
  transition: opacity 0.25s, transform 0.25s;
  color: #000;
  display: none;
}
#toast.show { display: block; }
#toast.hide { opacity: 0; transform: translateX(-50%) translateY(8px); }

/* ===================== SCROLLBAR ===================== */
::-webkit-scrollbar { width: 0; background: transparent; }
