:root {
  --ink: #1B2B6B;
  --navy: #1B2B6B;
  --border: #E4E2F4;
  --muted: #888780;
  --paper: #F7F7FB;
  --blue: #0071E3;
  --blue-bg: #F0F3FF;
  --green: #1D9E75;
  --green-bg: #E8F8F3;
  --clay: #E24B4A;
  --clay-bg: #FFF0F0;
  --amber: #B8860B;
  --surface: #FFFFFF;
}
[data-theme="dark"] {
  --ink: #E7E9F5;
  --navy: #A9B8FF;
  --border: #2A2E45;
  --muted: #8A8EA8;
  --paper: #14151F;
  --blue: #5B9CFF;
  --blue-bg: #1B2540;
  --green: #3FCB9A;
  --green-bg: #14352B;
  --clay: #FF6B6B;
  --clay-bg: #3A1D1D;
  --amber: #E0B860;
  --surface: #1C1E2B;
}
body[data-theme="dark"] { background: var(--paper); color: var(--ink); }
[data-theme="dark"] .card,
[data-theme="dark"] .card-list,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .sidebar,
[data-theme="dark"] .app-topbar,
[data-theme="dark"] .navbar { background: var(--surface); border-color: var(--border); }
[data-theme="dark"] .text-input,
[data-theme="dark"] .btn-outline { background: var(--surface); border-color: var(--border); color: var(--ink); }
[data-theme="dark"] .balance-card { background: radial-gradient(circle at 100% 0%, var(--blue-bg) 0%, var(--surface) 55%); }
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
a { color: inherit; text-decoration: none; }
.container { max-width: 1100px; margin: 0 auto; padding: 0 24px; }

.card { background: #fff; border: 1px solid var(--border); border-radius: 18px; }
.card-list { background: #fff; border: 1px solid var(--border); border-radius: 18px; overflow: hidden; }
.card-list > * + * { border-top: 1px solid var(--border); }

.btn-primary { background: var(--navy); color: #fff; border: none; border-radius: 10px; padding: 13px 22px; font-weight: 700; font-size: 14px; cursor: pointer; display: inline-block; }
.btn-outline { background: #fff; color: var(--navy); border: 1px solid var(--border); border-radius: 10px; padding: 11px 18px; font-weight: 600; font-size: 13px; cursor: pointer; display: inline-block; }
.btn-get { background: var(--blue-bg); color: var(--blue); border: none; border-radius: 999px; padding: 8px 22px; font-weight: 700; font-size: 13.5px; cursor: pointer; display: inline-block; letter-spacing: 0.2px; }
.btn-danger-outline { background: #fff; color: var(--clay); border: 1px solid var(--border); border-radius: 10px; padding: 9px 16px; font-weight: 600; font-size: 12.5px; cursor: pointer; }

.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 1.6px; text-transform: uppercase; color: var(--blue); }
.field-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; display: block; }
.text-input { width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; outline: none; font-family: inherit; font-size: 14px; box-sizing: border-box; }
.text-input:focus { border-color: var(--blue); }
.text-input-strong { border: 1.5px solid var(--blue); }

.alert-error { background: var(--clay-bg); color: var(--clay); border-radius: 10px; padding: 10px 14px; font-size: 12.5px; margin-bottom: 16px; }
.alert-success { background: var(--green-bg); color: var(--green); border-radius: 10px; padding: 10px 14px; font-size: 12.5px; margin-bottom: 16px; }

/* ---------- Nav bar (public pages) ---------- */
.navbar { border-bottom: 1px solid var(--border); background: #fff; position: sticky; top: 0; z-index: 10; }
.navbar-inner { max-width: 1100px; margin: 0 auto; padding: 0 24px; height: 64px; display: flex; align-items: center; justify-content: space-between; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.logo-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--navy); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: 14px; }

/* ---------- App shell (dashboard/admin) ---------- */
.app-shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 224px; border-right: 1px solid var(--border); background: #fff; padding: 26px 18px; flex-shrink: 0; display: flex; flex-direction: column; height: 100vh; overflow-y: auto; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; margin-bottom: 30px; }
.sidebar-nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; border-left: 2px solid transparent; font-weight: 600; font-size: 13.5px; color: var(--muted); margin-bottom: 2px; }
.sidebar-nav a.active { background: var(--blue-bg); color: var(--blue); border-left: 2px solid var(--blue); }
.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); font-size: 11px; color: var(--muted); }

.app-main { flex: 1; min-width: 0; height: 100vh; overflow-y: auto; }
.app-topbar { border-bottom: 1px solid var(--border); padding: 0 44px; height: 62px; display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,0.8); backdrop-filter: blur(20px); position: sticky; top: 0; z-index: 10; }
.app-content { max-width: 900px; padding: 40px 44px 100px; }

/* ---------- Stat row with corner accent (matches React StatRow) ---------- */
.stat-row { display: grid; gap: 16px; }
.stat-card { position: relative; overflow: hidden; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 20px 22px; }
.stat-card::after { content: ""; position: absolute; top: 0; right: 0; width: 80px; height: 80px; border-radius: 0 0 0 100%; opacity: 0.08; }
.stat-card.c-navy::after { background: var(--navy); }
.stat-card.c-blue::after { background: var(--blue); }
.stat-card.c-green::after { background: var(--green); }
.stat-label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--navy); margin-top: 6px; }

/* ---------- Balance hero ---------- */
.balance-card { background: radial-gradient(circle at 100% 0%, var(--blue-bg) 0%, #fff 55%); border: 1px solid var(--border); border-radius: 20px; padding: 24px 26px; margin-bottom: 20px; }

/* ---------- Package / plan rows ---------- */
.row-item { display: grid; grid-template-columns: 52px 1fr auto; align-items: center; gap: 16px; padding: 18px 20px; }
.row-icon { width: 52px; height: 52px; border-radius: 13px; background: var(--blue-bg); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* ---------- Section labels ---------- */
.section-label { font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; margin: 30px 0 4px; }
.section-label:first-child { margin-top: 0; }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.product-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } }

/* ---------- Progress bar ---------- */
.progress-track { height: 4px; background: var(--paper); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--blue); border-radius: 999px; }

/* ---------- Two-column split layouts (Deposit/Withdraw, product detail) ---------- */
.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
/* FIX: this was previously only ever set inline on the blog-grid <div> in dashboard.php
   (grid-template-columns:1fr 300px). Because inline styles beat stylesheet rules,
   the mobile media query below that's supposed to collapse this to one column
   couldn't win — the 300px "People to follow" column stayed reserved (and empty,
   since .blog-rail is hidden on mobile), leaving a blank gap on the right of the feed.
   Defining the desktop layout here instead lets the mobile override actually apply. */
.blog-grid { display: grid; grid-template-columns: 1fr 300px; gap: 32px; }
.split-2-wide { display: grid; grid-template-columns: 1fr 1.2fr; gap: 32px; }

/* ---------- Hamburger + mobile sidebar (unused on mobile now — bottom nav takes over) ---------- */
.hamburger { display: none; background: none; border: none; color: var(--ink); cursor: pointer; padding: 4px; margin-right: 4px; }
.sidebar-backdrop { display: none; }

/* ---------- Bottom tab bar (mobile only) ---------- */
.bottom-nav { display: none; }
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 8px 0 6px; text-decoration: none; background: none; border: none; cursor: pointer;
  font-family: inherit; color: var(--muted); font-size: 10px; font-weight: 600;
}
.bottom-nav-item.active { color: var(--blue); }
.bottom-nav-item span { line-height: 1; }

/* ---------- "More" bottom sheet (mobile only) ---------- */
.more-sheet-backdrop { display: none; }
.more-sheet {
  display: none;
}
.more-sheet-item {
  display: flex; align-items: center; gap: 14px; padding: 15px 22px; text-decoration: none;
  color: var(--ink); font-weight: 600; font-size: 14.5px; border-bottom: 1px solid var(--border);
}
.more-sheet-item:last-child { border-bottom: none; }
.more-sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 999px; margin: 10px auto 4px; }

/* ============================================================
   MOBILE — under 768px
   Real app-pattern layout: bottom tab bar replaces the sidebar entirely,
   not a shrunk-down desktop view.
   ============================================================ */
@media (max-width: 768px) {
  .app-shell { position: relative; }

  /* Desktop sidebar hidden completely on mobile — dashboard uses a bottom nav instead */
  .sidebar { display: none; }
  .hamburger { display: none; }

  /* Admin has no bottom nav (too many sections) — give it a slide-in overlay sidebar instead */
  .admin-sidebar {
    display: flex;
    position: fixed;
    top: 0; left: 0;
    z-index: 100;
    width: 260px;
    max-width: 80vw;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .admin-sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 30px rgba(0,0,0,0.18);
  }
  .admin-hamburger { display: flex; align-items: center; justify-content: center; }

  .app-topbar {
    padding: 0 16px;
    height: 56px;
  }
  .topbar-tab-label { display: block; text-transform: capitalize; font-weight: 700; color: var(--ink) !important; }
  .topbar-wallet-label { display: none; }

  .app-content {
    padding: 16px 14px 96px; /* extra bottom padding so content clears the fixed bottom nav */
    max-width: 100%;
  }

  h1 { font-size: 21px !important; }
  h2 { font-size: 18px !important; }

  .grid-3, .grid-4 { grid-template-columns: 1fr; gap: 10px; }
  .product-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .product-grid .product-card-name { font-size: 10.5px !important; }
  .product-grid .product-card-price { font-size: 10.5px !important; }
  .product-grid .product-card-cat { display: none; }
  .split-2, .split-2-wide { grid-template-columns: 1fr; gap: 18px; }
  .blog-grid { grid-template-columns: 1fr; gap: 18px; }
  .blog-grid .blog-rail { display: none; }

  /* Blog on mobile: edge-to-edge cards like Facebook's app, not floating rounded boxes */
  .blog-grid .post-card, .blog-grid .composer-card {
    border-radius: 0 !important;
    border-left: none !important;
    border-right: none !important;
    margin-left: -14px;
    margin-right: -14px;
    width: calc(100% + 28px);
  }

  .row-item, .card-list > div, .card-list > form, .card-list > a {
    padding: 14px !important;
  }

  .balance-card { padding: 18px !important; border-radius: 16px !important; }

  .btn-primary, .btn-outline, .btn-get, .pill-blue {
    font-size: 13px;
  }

  img { max-width: 100%; }

  /* Bottom tab bar */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 64px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 95;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* "More" slide-up sheet */
  .more-sheet-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(10,10,20,0.4);
    z-index: 96;
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .more-sheet-backdrop.visible { opacity: 1; pointer-events: auto; }

  .more-sheet {
    display: block;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    z-index: 97;
    transform: translateY(100%);
    transition: transform 0.25s ease;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
    box-shadow: 0 -8px 30px rgba(0,0,0,0.15);
  }
  .more-sheet.open { transform: translateY(0); }
}

@media (max-width: 420px) {
  .grid-3 { grid-template-columns: 1fr; }
  .app-content { padding-left: 10px; padding-right: 10px; }
}

/* iOS Safari zooms into any input under 16px font-size — force 16px minimum on all form fields on mobile */
@media (max-width: 768px) {
  input, select, textarea { font-size: 16px !important; }
}