/* ════════════════════════════════════════════════════════════════════════════
   main.css — Adhikari Store v8
   Design system: tokens, reset, typography, utilities, components
   Mobile-first. Sora + Inter. Green palette.
   ════════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@400;500;600;700;800&family=Inter:wght@400;500;600&display=swap');

/* ── Tokens ─────────────────────────────────────────────────────────────────── */
:root {
  /* Palette */
  --bg:          #F7F7F5;
  --bg2:         #EFEDE8;
  --surface:     #FFFFFF;
  --border:      #E8E6E1;
  --border2:     #D8D4CD;
  --fg:          #1A1A18;
  --fg2:         #6B6860;
  --fg3:         #A8A49E;
  --accent:      #2D6A4F;
  --accent-lt:   #D8EDDF;
  --accent-dk:   #1B4332;
  --accent-mid:  #52B788;
  --warn:        #E07C39;
  --warn-lt:     #FDE8D4;
  --danger:      #C0392B;
  --danger-lt:   #FDECEA;
  --success:     #27AE60;
  --info:        #3B5BDB;
  --info-lt:     #EEF2FF;
  --tag-bg:      #EEECEA;
  --tag-bg2:     #E4E2DC;

  /* Typography */
  --font-head:   'Sora', system-ui, sans-serif;
  --font-body:   'Inter', system-ui, sans-serif;

  /* Radii */
  --r-xs:   4px;
  --r-sm:   8px;
  --r-md:  14px;
  --r-lg:  20px;
  --r-xl:  28px;
  --r-full: 999px;

  /* Shadows */
  --shadow-xs:  0 1px 2px rgba(0,0,0,.06);
  --shadow-sm:  0 1px 4px rgba(0,0,0,.08);
  --shadow-md:  0 4px 16px rgba(0,0,0,.10);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.13);
  --shadow-xl:  0 16px 56px rgba(0,0,0,.18);

  /* Transitions */
  --ease:       cubic-bezier(.4,0,.2,1);
  --dur-fast:   120ms;
  --dur-normal: 200ms;
  --dur-slow:   350ms;

  /* Z-index */
  --z-nav:      100;
  --z-modal:    200;
  --z-toast:    300;
  --z-overlay:  400;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #111210;
    --bg2:       #181917;
    --surface:   #1C1D1A;
    --border:    #2E2F2B;
    --border2:   #3A3B37;
    --fg:        #F0EDE8;
    --fg2:       #9A9690;
    --fg3:       #5A5753;
    --accent:    #52B788;
    --accent-lt: #1B3A2E;
    --accent-dk: #74C69D;
    --accent-mid:#2D6A4F;
    --warn:      #E98C4A;
    --warn-lt:   #3A2010;
    --danger:    #E05C4E;
    --danger-lt: #3A1210;
    --info:      #748FFC;
    --info-lt:   #1A1F3A;
    --tag-bg:    #252622;
    --tag-bg2:   #2E2F2B;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg:        #111210;
  --bg2:       #181917;
  --surface:   #1C1D1A;
  --border:    #2E2F2B;
  --border2:   #3A3B37;
  --fg:        #F0EDE8;
  --fg2:       #9A9690;
  --fg3:       #5A5753;
  --accent:    #52B788;
  --accent-lt: #1B3A2E;
  --accent-dk: #74C69D;
  --accent-mid:#2D6A4F;
  --warn:      #E98C4A;
  --warn-lt:   #3A2010;
  --danger:    #E05C4E;
  --danger-lt: #3A1210;
  --info:      #748FFC;
  --info-lt:   #1A1F3A;
  --tag-bg:    #252622;
  --tag-bg2:   #2E2F2B;
  color-scheme: dark;
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  background:  var(--bg);
  color:       var(--fg);
  font-family: var(--font-body);
  font-size:   15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
  /* safe area for notched phones */
  padding-left:   env(safe-area-inset-left, 0);
  padding-right:  env(safe-area-inset-right, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }
button { cursor: pointer; border: none; background: none; }
input, textarea { outline: none; }

/* ── Typography ─────────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5 {
  font-family: var(--font-head);
  text-wrap: balance;
  line-height: 1.25;
}
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 600; }

.label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--fg3);
  font-family: var(--font-head);
}

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.page-wrap {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
  background: var(--bg);
}

/* Screen that slides in/out */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(64px + env(safe-area-inset-bottom, 0));
}
.screen.active { display: flex; }

/* Screen header (Cart, Orders, Profile titles) */
.screen-header {
  padding: 20px 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.screen-title {
  font-family: var(--font-head);
  font-size: 24px;
  font-weight: 800;
  color: var(--fg);
  letter-spacing: -.02em;
  margin: 0;
}

/* ── Top Nav ─────────────────────────────────────────────────────────────────── */
.top-nav {
  position: sticky;
  top: 0;
  z-index: var(--z-nav);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.store-logo {
  font-family: var(--font-head);
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -.03em;
  line-height: 1;
  display: flex;
  align-items: center;
  gap: 6px;
}
.store-logo svg { flex-shrink: 0; }

.nav-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--r-full);
  background: var(--tag-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg2);
  transition: background var(--dur-fast) var(--ease),
              color var(--dur-fast) var(--ease);
  position: relative;
  flex-shrink: 0;
}
.nav-btn:active { background: var(--border2); }
.nav-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cart-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  font-family: var(--font-head);
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--surface);
}
.cart-badge[hidden] { display: none !important; }

/* ── Bottom Nav ──────────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: var(--z-nav);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bnav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 4px 8px;
  color: var(--fg3);
  font-size: 10px;
  font-weight: 600;
  font-family: var(--font-head);
  letter-spacing: .02em;
  transition: color var(--dur-fast) var(--ease);
  position: relative;
}
.bnav-item.active { color: var(--accent); }
.bnav-item svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke-width var(--dur-fast) var(--ease);
}
.bnav-item.active svg { stroke-width: 2.4; }
.bnav-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  background: var(--accent);
  color: #fff;
  font-size: 8px;
  font-weight: 800;
  font-family: var(--font-head);
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
  border: 2px solid var(--surface);
}
.bnav-badge[hidden] { display: none !important; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 20px;
  border-radius: var(--r-md);
  font-family: var(--font-head);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .01em;
  transition: opacity var(--dur-fast) var(--ease),
              transform var(--dur-fast) var(--ease);
  white-space: nowrap;
  user-select: none;
}
.btn:active { opacity: .85; transform: scale(.98); }
.btn:disabled { opacity: .45; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 14px rgba(45,106,79,.28);
}
.btn-secondary {
  background: var(--tag-bg);
  color: var(--fg);
  border: 1.5px solid var(--border);
}
.btn-danger {
  background: var(--danger-lt);
  color: var(--danger);
  border: 1.5px solid var(--danger);
}
.btn-full { width: 100%; }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: var(--r-sm); }

/* ── Inputs ──────────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--fg2);
  font-family: var(--font-head);
}
.field-input {
  width: 100%;
  background: var(--tag-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 13px 14px;
  font-size: 15px;
  font-family: var(--font-body);
  color: var(--fg);
  transition: border-color var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}
.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-lt);
  background: var(--surface);
}
.field-input::placeholder { color: var(--fg3); }
.field-input.error { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-lt); }

.field-row {
  display: flex;
  align-items: stretch;
  background: var(--tag-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.field-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-lt);
  background: var(--surface);
}
.field-row.error { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-lt); }
.field-prefix {
  padding: 13px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg2);
  border-right: 1.5px solid var(--border);
  white-space: nowrap;
  display: flex;
  align-items: center;
  background: var(--tag-bg2);
}
.field-row .field-input {
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
}
.field-row .field-input:focus { box-shadow: none; background: transparent; }

/* PIN input row */
.pin-row {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.pin-digit {
  width: 56px;
  height: 60px;
  text-align: center;
  font-size: 24px;
  font-weight: 700;
  font-family: var(--font-head);
  background: var(--tag-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  caret-color: var(--accent);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  -webkit-appearance: none;
  appearance: none;
  color: var(--fg);
}
.pin-digit:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-lt);
  background: var(--surface);
}
.pin-digit.filled { border-color: var(--accent); }

/* OTP input */
.otp-row { display: flex; gap: 8px; justify-content: center; }
.otp-digit {
  width: 44px;
  height: 52px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  font-family: var(--font-head);
  background: var(--tag-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  caret-color: var(--accent);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  -webkit-appearance: none;
  appearance: none;
  color: var(--fg);
}
.otp-digit:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-lt);
  background: var(--surface);
}

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

/* ── Badges ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: var(--r-full);
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-head);
  letter-spacing: .03em;
  white-space: nowrap;
}
.badge-in      { background: var(--accent-lt); color: var(--accent); }
.badge-out     { background: var(--danger-lt); color: var(--danger); }
.badge-low     { background: var(--warn-lt);   color: var(--warn);   }
.badge-warn    { background: var(--warn-lt);   color: var(--warn);   }
.badge-info    { background: var(--info-lt);   color: var(--info);   }
.badge-neutral { background: var(--tag-bg);    color: var(--fg2);    }

/* Order status badges */
.badge-received  { background: var(--warn-lt);   color: var(--warn);    }
.badge-preparing { background: var(--info-lt);   color: var(--info);    }
.badge-ready     { background: var(--accent-lt); color: var(--accent);  }
.badge-delivered { background: #E8F5E9;           color: var(--success); }
.badge-returned  { background: var(--tag-bg);    color: var(--fg2);     }
.badge-refunded  { background: var(--danger-lt); color: var(--danger);  }

/* ── Dividers ────────────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 0;
}
.section-gap { height: 8px; background: var(--bg2); }

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 32px;
  text-align: center;
}
.empty-state-icon {
  font-size: 52px;
  line-height: 1;
  opacity: .6;
}
.empty-state-title {
  font-family: var(--font-head);
  font-size: 17px;
  font-weight: 700;
  color: var(--fg);
}
.empty-state-sub { font-size: 14px; color: var(--fg2); line-height: 1.6; }

/* ── Toast / Snackbar ────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: calc(72px + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 440px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--fg);
  color: var(--bg);
  padding: 13px 16px;
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in var(--dur-normal) var(--ease) forwards;
  pointer-events: auto;
}
.toast.out { animation: toast-out var(--dur-normal) var(--ease) forwards; }
.toast-icon { font-size: 16px; flex-shrink: 0; }
.toast.success { background: var(--accent); color: #fff; }
.toast.error   { background: var(--danger); color: #fff; }
.toast.warn    { background: var(--warn);   color: #fff; }

@keyframes toast-in {
  from { opacity:0; transform: translateY(12px) scale(.95); }
  to   { opacity:1; transform: translateY(0)    scale(1);   }
}
@keyframes toast-out {
  from { opacity:1; transform: translateY(0)    scale(1);   }
  to   { opacity:0; transform: translateY(8px)  scale(.96); }
}

/* ── Modal / Bottom Sheet ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity var(--dur-normal) var(--ease);
}
.modal-overlay.open { opacity: 1; }
.modal-overlay.open .modal-sheet { transform: translateY(0); }
.modal-overlay[hidden] { display: none !important; }

.modal-sheet {
  background: var(--surface);
  width: 100%;
  max-width: 480px;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 24px 20px calc(env(safe-area-inset-bottom, 0px) + 24px);
  max-height: 92dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform var(--dur-slow) var(--ease);
  position: relative;
}
.modal-handle {
  width: 40px;
  height: 4px;
  background: var(--border2);
  border-radius: 2px;
  margin: 12px auto 4px;
}
.modal-header {
  padding: 8px 16px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-family: var(--font-head);
  font-size: 17px;
  font-weight: 700;
}
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--tag-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg2);
  z-index: 1;
}
.modal-close svg {
  width: 16px; height: 16px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round;
}
.modal-body { padding: 16px; }
.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}

/* ── Spinner ─────────────────────────────────────────────────────────────────── */
.spinner {
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(var(--bg), .8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-overlay);
}

/* ── Page headers (back + title) ─────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.back-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--tag-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg);
  flex-shrink: 0;
}
.back-btn svg {
  width: 18px; height: 18px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.page-title { font-family: var(--font-head); font-size: 17px; font-weight: 700; }

/* ── Section heading inside screen ──────────────────────────────────────────── */
.section-head {
  padding: 14px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.section-head h3 { font-family: var(--font-head); font-size: 15px; font-weight: 700; }

/* ── Utilities ───────────────────────────────────────────────────────────────── */
.flex          { display: flex; }
.flex-col      { display: flex; flex-direction: column; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-4  { gap: 4px; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.p-16   { padding: 16px; }
.px-16  { padding-left: 16px; padding-right: 16px; }
.py-12  { padding-top: 12px; padding-bottom: 12px; }
.mt-8   { margin-top: 8px; }
.mt-12  { margin-top: 12px; }
.mt-16  { margin-top: 16px; }
.text-accent  { color: var(--accent); }
.text-danger  { color: var(--danger); }
.text-warn    { color: var(--warn); }
.text-success { color: var(--success); }
.text-muted   { color: var(--fg2); }
.text-sm      { font-size: 13px; }
.text-xs      { font-size: 11px; }
.font-bold    { font-weight: 700; }
.font-head    { font-family: var(--font-head); }
.truncate     { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Scroll areas ────────────────────────────────────────────────────────────── */
.scroll-x {
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.scroll-x::-webkit-scrollbar { display: none; }

/* ── Floating action button ──────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: calc(80px + env(safe-area-inset-bottom, 0));
  right: 16px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(45,106,79,.4);
  z-index: 50;
  transition: transform var(--dur-fast), box-shadow var(--dur-fast);
}
.fab:active { transform: scale(.94); box-shadow: 0 2px 8px rgba(45,106,79,.3); }
.fab svg {
  width: 24px; height: 24px;
  stroke: #fff; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ── Pull-to-refresh visual ──────────────────────────────────────────────────── */
.ptr-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  color: var(--fg3);
  font-size: 13px;
  gap: 8px;
  height: 0;
  overflow: hidden;
  transition: height var(--dur-normal);
}
.ptr-indicator.visible { height: 48px; }
