/* ═══════════════════════════════════════════════════════════════════
   GlueArrow PWA — Mobile-App Design System
   Mirrors: glueArrow_app/src/styles/theme.js
   ═══════════════════════════════════════════════════════════════════ */

:root {
  /* Stone palette (constant) */
  --stone-50: #fafaf9;
  --stone-100: #f5f5f4;
  --stone-200: #e7e5e4;
  --stone-300: #d6d3d1;
  --stone-400: #a8a29e;
  --stone-500: #78716c;
  --stone-600: #57534e;
  --stone-700: #44403c;
  --stone-800: #292524;
  --stone-900: #1c1917;
  --stone-950: #0c0a09;

  /* Brand (constant) */
  --emerald: #10b981;
  --emerald-dark: #059669;
  --emerald-light: #34d399;
  --orange: #f97316;
  --red: #ef4444;
  --blue: #3b82f6;

  /* ═══ DARK THEME (default — mirrors app Hub) ═══ */
  --color-primary: var(--emerald);
  --color-bg: #000000;
  --color-bg-elevated: #1a1a1a;
  --color-surface: #ffffff;
  --color-surface-dim: rgba(255,255,255,0.06);
  --color-text: #ffffff;
  --color-text-secondary: var(--stone-300);
  --color-text-muted: var(--stone-400);
  --color-border: rgba(255,255,255,0.08);
  --color-border-strong: rgba(255,255,255,0.12);
  --color-danger: var(--red);
  --color-card-bg: #1a1a1a;
  --color-card-border: rgba(255,255,255,0.06);
  --color-card-text: #ffffff;
  --color-input-bg: rgba(255,255,255,0.06);
  --color-input-border: rgba(255,255,255,0.08);
  --color-input-text: #ffffff;
  --color-header-bg: transparent;
  --color-header-text: #ffffff;
  --color-header-icon: #ffffff;
  --color-navbar-bg: #ffffff;
  --color-sidebar-bg: var(--stone-950);
  --color-topbar-bg: var(--stone-950);
  --color-drawer-bg: #ffffff;
  --color-toast-bg: var(--stone-900);
  --color-tab-active: #ffffff;
  --color-tab-inactive: rgba(255,255,255,0.4);
  --color-indicator: #ffffff;
  --neon-green: #00ff87;
  --neon-red: #ff4560;
  --neon-amber: #ffb800;
  --neon-blue: #4da6ff;

  /* Layout */
  --header-height: 55px;
  --subbar-height: 44px;
  --navbar-height: 68px;
  --sidebar-width: 240px;
  --dt-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

/* ═══ LIGHT THEME ═══ */
[data-theme="light"] {
  --color-bg: #f8fafc;
  --color-bg-elevated: #ffffff;
  --color-surface: #ffffff;
  --color-surface-dim: var(--stone-100);
  --color-text: var(--stone-900);
  --color-text-secondary: var(--stone-600);
  --color-text-muted: var(--stone-500);
  --color-border: var(--stone-200);
  --color-border-strong: var(--stone-300);
  --color-card-bg: #ffffff;
  --color-card-border: var(--stone-200);
  --color-card-text: var(--stone-900);
  --color-input-bg: var(--stone-100);
  --color-input-border: var(--stone-200);
  --color-input-text: var(--stone-900);
  --color-header-bg: #ffffff;
  --color-header-text: var(--stone-900);
  --color-header-icon: var(--stone-700);
  --color-navbar-bg: #ffffff;
  --color-sidebar-bg: #ffffff;
  --color-topbar-bg: #ffffff;
  --color-drawer-bg: #ffffff;
  --color-toast-bg: var(--stone-900);
  --color-tab-active: var(--stone-900);
  --color-tab-inactive: var(--stone-400);
  --color-indicator: var(--emerald);
  --neon-green: var(--emerald);
  --neon-red: var(--red);
  --neon-amber: var(--orange);
  --neon-blue: var(--blue);
}

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  transition: background 0.3s, color 0.3s;
}

a { text-decoration: none; color: inherit; }

/* ─── App Shell ─────────────────────────────────────────────────── */
.pwa-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ─── App Header — mirrors AppHeader.js ─────────────────────────── */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding-top: var(--safe-top);
  transition: background 0.2s;
}

.app-header.light {
  background: var(--color-header-bg);
  border-bottom: 0.5px solid var(--color-border);
}

.app-header.dark {
  background: var(--color-header-bg);
}

.header-main {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.header-brand {
  font-size: 20px;
  font-weight: 900;
  color: var(--emerald);
  letter-spacing: -0.5px;
  cursor: pointer;
  user-select: none;
}

.app-header.light .header-brand { color: var(--emerald); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 50%;
  position: relative;
  color: var(--color-header-icon);
  transition: background 0.15s;
}

.header-icon-btn:active { background: var(--color-surface-dim); }
.app-header.light .header-icon-btn { color: var(--color-header-icon); }
.app-header.light .header-icon-btn:active { background: var(--color-surface-dim); }

.header-icon-btn svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.2;
}

.noti-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  min-width: 16px;
  height: 16px;
  border-radius: 99px;
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}

/* ─── Sub-bar Tabs — mirrors AppHeader dark nav tabs ────────────── */
.header-subbar {
  height: var(--subbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
}

.header-subbar.hidden { display: none; }

/* Left spacer mirrors profile button width for visual centering */
.subbar-side-spacer { width: 36px; flex-shrink: 0; }

/* Center tabs fill the middle */
.subbar-center-tabs {
  display: flex;
  flex: 1;
  justify-content: space-evenly;
  align-items: center;
}

/* Profile avatar button — right side */
.subbar-profile-btn {
  width: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

.subbar-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  overflow: hidden;
  background: rgba(255,255,255,0.15);
  border: 1.5px solid rgba(255,255,255,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
}

.subbar-avatar.guest {
  background: rgba(255,255,255,0.08);
}

.subbar-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Light theme adjustments for avatar */
.app-header.light .subbar-avatar {
  background: rgba(0,0,0,0.06);
  border-color: rgba(0,0,0,0.1);
}
.app-header.light .subbar-avatar i { color: var(--stone-500) !important; }

.tab-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.tab-btn .tab-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  color: var(--color-tab-inactive);
  transition: color 0.15s;
  white-space: nowrap;
}

.tab-btn.active .tab-label {
  color: var(--color-tab-active);
}

.app-header.light .tab-btn .tab-label { color: var(--color-tab-inactive); }
.app-header.light .tab-btn.active .tab-label { color: var(--color-tab-active); }

.tab-indicator {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--color-indicator);
  opacity: 0;
  transition: opacity 0.15s;
}

.tab-btn.active .tab-indicator { opacity: 1; }
.app-header.light .tab-btn.active .tab-indicator { background: var(--color-indicator); }

/* ─── Content Area ──────────────────────────────────────────────── */
.pwa-content {
  flex: 1;
  margin-top: calc(var(--safe-top) + var(--header-height) + var(--subbar-height));
  margin-bottom: calc(var(--navbar-height) + var(--safe-bottom));
  overflow: hidden; /* swipe-container and swipe-page handle their own scrolling */
}

.pwa-content.no-subbar {
  margin-top: calc(var(--safe-top) + var(--header-height));
}

/* Swipe container: 4 horizontal content views (hub, market, options, network) */
.swipe-container {
  display: flex;
  width: 400vw; /* 4 pages */
  height: 100%;
  scroll-snap-type: x mandatory;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.swipe-container::-webkit-scrollbar { display: none; }

.swipe-page {
  width: 100vw;
  height: 100%;
  flex-shrink: 0;
  scroll-snap-align: start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: 24px;
}

/* Full-page container (Plan/Scan/Wallet — replaces swipe area) */
.full-page-container,
#page-container {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: 24px;
  transition: opacity 0.15s ease;
}

/* ─── Nav Loader ────────────────────────────────────────────────── */
#nav-loader {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--emerald);
  z-index: 9999;
  transition: width 0.3s ease;
  display: none;
  width: 0;
}

/* ─── Bottom Nav — mirrors SmartNavBar / NavigationLayer.js ──────── */
.smart-navbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  padding-bottom: var(--safe-bottom);
}

.navbar-bg {
  background: var(--color-navbar-bg);
  border-radius: 32px 32px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.08);
  height: var(--navbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  transition: background 0.3s;
}

.nav-side {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.nav-side:last-child {
  justify-content: flex-end;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 16px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 16px;
  transition: background 0.15s;
  min-width: 56px;
}

.nav-btn:active {
  background: var(--stone-100);
}

.nav-btn svg {
  width: 22px;
  height: 22px;
  stroke-width: 2;
  color: var(--stone-400);
  transition: color 0.15s;
}

.nav-btn.active svg {
  color: var(--emerald);
}

.nav-btn-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--stone-400);
  transition: color 0.15s;
}

.nav-btn.active .nav-btn-label {
  color: var(--emerald);
}

/* Center dock button */
.dock-spacer {
  width: 68px;
  flex-shrink: 0;
}

.dock-btn {
  position: fixed;
  bottom: calc(var(--navbar-height) - 22px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 101;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--emerald);
  border: 4px solid #fff;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.dock-btn:active {
  transform: translateX(-50%) scale(0.92);
}

.dock-btn svg {
  width: 24px;
  height: 24px;
  color: #fff;
  stroke-width: 2.5;
}

/* ─── Side Drawer — mirrors SideDrawer.js ───────────────────────── */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.side-drawer {
  position: fixed;
  top: calc(var(--safe-top) + var(--header-height));
  right: 0;
  bottom: calc(var(--navbar-height) + var(--safe-bottom));
  width: 72vw;
  max-width: 320px;
  background: var(--color-drawer-bg);
  z-index: 201;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-left: 1px solid rgba(0,0,0,0.08);
  box-shadow: -3px 0 12px rgba(0,0,0,0.06);
}

.side-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--stone-100);
  padding-top: calc(20px + var(--safe-top));
}

.drawer-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--stone-900);
}

.drawer-close {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--stone-100);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--stone-600);
}

.drawer-close:active { background: var(--stone-200); }

.drawer-close svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.5;
}

/* User card in drawer — mirrors app SideDrawer.js */
.drawer-user-card {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.drawer-avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--stone-100);
  flex-shrink: 0;
}

.drawer-avatar.guest-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
}

.drawer-user-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--stone-900);
}

/* Role pill badge — matches app shield + role pattern */
.drawer-role-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: var(--emerald);
  padding: 2px 10px;
  border-radius: 99px;
  text-transform: capitalize;
}

/* Drawer nav section */
.drawer-section {
  padding: 16px 20px 8px;
}

.drawer-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--stone-400);
}

/* Nav items — matches app's 32x32 icon containers */
.drawer-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 20px;
  cursor: pointer;
  transition: background 0.12s;
  color: var(--stone-800);
  font-size: 14px;
  font-weight: 500;
  border-radius: 10px;
  margin: 0 8px;
}

.drawer-nav-item:active { background: var(--stone-50); }

.drawer-nav-icon {
  width: 32px;
  height: 32px;
  background: var(--stone-50);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.drawer-nav-icon svg {
  width: 17px;
  height: 17px;
  color: var(--stone-500);
  stroke-width: 2;
}

/* Separator line */
.drawer-separator {
  height: 1px;
  background: var(--stone-100);
  margin: 8px 20px;
}

/* Sign out button — red style */
.drawer-signout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-radius: 14px;
  background: #FEF2F2;
  color: var(--red);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}

.drawer-signout:active { background: #FEE2E2; }

.drawer-signout svg { color: var(--red); }

/* Sign in button — emerald style */
.drawer-signin {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(16, 185, 129, 0.06);
  color: var(--emerald);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}

.drawer-signin:active { background: rgba(16, 185, 129, 0.12); }

.drawer-signin svg { color: var(--emerald); }

/* ─── App Download Banner ───────────────────────────────────────── */
.app-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 150;
  background: var(--stone-900);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: calc(10px + var(--safe-top));
  transform: translateY(-100%);
  transition: transform 0.3s ease;
}

.app-banner.show {
  transform: translateY(0);
}

.app-banner-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--emerald);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.app-banner-icon svg {
  width: 18px;
  height: 18px;
  color: #fff;
}

.app-banner-text {
  flex: 1;
}

.app-banner-text strong {
  display: block;
  font-size: 13px;
  color: #fff;
  font-weight: 700;
}

.app-banner-text span {
  font-size: 11px;
  color: var(--stone-400);
}

.app-banner-open {
  padding: 6px 14px;
  border-radius: 99px;
  background: var(--emerald);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  white-space: nowrap;
}

.app-banner-close {
  background: none;
  border: none;
  color: var(--stone-500);
  cursor: pointer;
  padding: 4px;
}

.app-banner-close svg {
  width: 16px;
  height: 16px;
}

/* ─── Dock Quick Menu ───────────────────────────────────────────── */
.dock-menu {
  position: fixed;
  bottom: calc(var(--navbar-height) + 24px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) scale(0.8);
  z-index: 102;
  background: #fff;
  border-radius: 24px;
  padding: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.15);
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s cubic-bezier(0.22, 1, 0.36, 1);
  min-width: 200px;
}

.dock-menu.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) scale(1);
}

.dock-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.12s;
  color: var(--stone-800);
  font-size: 14px;
  font-weight: 600;
}

.dock-menu-item:active { background: var(--stone-50); }

.dock-menu-item svg {
  width: 20px;
  height: 20px;
  color: var(--emerald);
  stroke-width: 2.2;
}

/* ─── Cards — matches mobile glassCard style ────────────────────── */
.pwa-card {
  background: var(--color-card-bg);
  border-radius: 24px;
  border: 1px solid var(--color-card-border);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  color: var(--color-card-text);
  transition: background 0.3s, border-color 0.3s, color 0.3s;
}

.pwa-card-dark {
  background: var(--stone-900);
  border-color: var(--stone-800);
  color: #fff;
}

/* ─── Typography — matches mobile ───────────────────────────────── */
.pwa-heading {
  font-size: 24px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: -0.5px;
}

.pwa-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--stone-400);
}

/* ─── Toast ─────────────────────────────────────────────────────── */
.pwa-toast {
  position: fixed;
  bottom: calc(var(--navbar-height) + 16px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  z-index: 300;
  background: var(--stone-900);
  color: #fff;
  padding: 12px 24px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.pwa-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.pwa-toast.error { background: var(--red); }
.pwa-toast.success { background: var(--emerald); }

/* ─── Responsive — tablet centered ─────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
  /* Swipe pages centered, not the container itself (needs full width for scroll) */
  .swipe-page {
    display: flex;
    flex-direction: column;
    padding-left: calc((100vw - 640px) / 2);
    padding-right: calc((100vw - 640px) / 2);
  }

  /* Full-page container centered — 640px for wallet buckets and radar viewport */
  #page-container {
    max-width: 640px;
    margin-left: auto;
    margin-right: auto;
  }

  .smart-navbar .navbar-bg {
    max-width: 640px;
    margin: 0 auto;
  }

  .app-header .header-main,
  .app-header .header-subbar {
    max-width: 640px;
    margin: 0 auto;
  }
}

/* ─── Scrollbar ─────────────────────────────────────────────────── */
.pwa-content::-webkit-scrollbar { width: 0; }
.swipe-page::-webkit-scrollbar { width: 0; }

/* ─── Overrides for existing templates loaded inside PWA shell ──── */
#page-container .container,
#page-container .container-fluid {
  padding-left: 0;
  padding-right: 0;
  max-width: 100%;
}

/* Remove sidebar offsets from loaded templates */
#page-container .main-content {
  margin-left: 0 !important;
  padding-top: 0 !important;
}

/* Dark page mode — applied by JS when on hub/market views */
body.dark-view {
  background: var(--color-bg);
}

body.light-view {
  background: var(--color-bg);
}

body.light-view .app-header {
  background: var(--color-header-bg);
  border-bottom: 0.5px solid var(--color-border);
}

body.light-view .header-icon-btn {
  color: var(--color-header-icon);
}

body.light-view .header-brand {
  color: var(--emerald);
}

/* ═══ LIGHT THEME — desktop sidebar & topbar overrides ═══ */
[data-theme="light"] .desktop-sidebar {
  background: #ffffff;
  border-right: 1px solid var(--stone-200);
}
[data-theme="light"] .ds-brand a { color: var(--emerald); }
[data-theme="light"] .ds-nav-item svg { color: var(--stone-400); }
[data-theme="light"] .ds-nav-item span { color: var(--stone-600); }
[data-theme="light"] .ds-nav-item:hover { background: var(--stone-100); }
[data-theme="light"] .ds-nav-item.active { background: rgba(16,185,129,0.08); }
[data-theme="light"] .ds-nav-item.active svg { color: var(--emerald); }
[data-theme="light"] .ds-nav-item.active span { color: var(--stone-900); }
[data-theme="light"] .ds-divider { background: var(--stone-200); }
[data-theme="light"] .ds-section-title { color: var(--stone-400); }
[data-theme="light"] .ds-link { color: var(--stone-600); }
[data-theme="light"] .ds-link:hover { background: var(--stone-100); color: var(--stone-900); }
[data-theme="light"] .ds-link svg { color: var(--stone-400); }
[data-theme="light"] .ds-user { border-top-color: var(--stone-200); }
[data-theme="light"] .ds-user-name { color: var(--stone-900); }
[data-theme="light"] .ds-footer a { color: var(--stone-400); }
[data-theme="light"] .ds-footer a:hover { color: var(--stone-600); }

[data-theme="light"] .desktop-topbar {
  background: #ffffff;
  border-bottom: 1px solid var(--stone-200);
}
[data-theme="light"] .dt-search input {
  background: var(--stone-100);
  border-color: var(--stone-200);
  color: var(--stone-900);
}
[data-theme="light"] .dt-search input:focus {
  border-color: var(--emerald);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(16,185,129,0.12);
}
[data-theme="light"] .dt-search input::placeholder { color: var(--stone-400); }
[data-theme="light"] .dt-search .dt-search-icon { color: var(--stone-400); }
[data-theme="light"] .dt-icon-btn { background: var(--stone-100); color: var(--stone-600); }
[data-theme="light"] .dt-icon-btn:hover { background: var(--stone-200); color: var(--stone-900); }
[data-theme="light"] .dt-user-pill { background: var(--stone-100); border-color: var(--stone-200); }
[data-theme="light"] .dt-user-pill:hover { background: var(--stone-200); }
[data-theme="light"] .dt-user-pill span { color: var(--stone-700); }

/* Light theme — page mode */
[data-theme="light"] .page-back-header { background: #fff; border-bottom-color: var(--stone-200); }
[data-theme="light"] .pwa-toast { background: var(--stone-900); }

/* Light theme — drawer */
[data-theme="light"] .drawer-header { border-bottom-color: var(--stone-200); }
[data-theme="light"] .drawer-user-card { border-bottom-color: var(--stone-200); }

/* ═══ THEME TOGGLE BUTTON ═══ */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 12px;
  width: 100%;
  text-align: left;
  transition: background 0.15s;
  color: var(--stone-400);
  font-size: 12.5px;
  font-weight: 500;
}
.theme-toggle:hover { background: var(--color-surface-dim); }
.theme-toggle svg { width: 18px; height: 18px; stroke-width: 2; flex-shrink: 0; }
.theme-toggle-label { flex: 1; }
.theme-toggle-pill {
  width: 40px;
  height: 22px;
  border-radius: 12px;
  background: var(--stone-600);
  position: relative;
  transition: background 0.3s;
  flex-shrink: 0;
}
.theme-toggle-pill::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.3s;
}
[data-theme="light"] .theme-toggle-pill { background: var(--emerald); }
[data-theme="light"] .theme-toggle-pill::after { transform: translateX(18px); }

/* Desktop topbar theme toggle */
.dt-theme-toggle {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: rgba(255,255,255,0.06);
  border-radius: 12px;
  cursor: pointer;
  color: var(--stone-400);
  transition: all 0.15s;
}
.dt-theme-toggle:hover { background: rgba(255,255,255,0.1); color: #fff; }
[data-theme="light"] .dt-theme-toggle { background: var(--stone-100); color: var(--stone-600); }
[data-theme="light"] .dt-theme-toggle:hover { background: var(--stone-200); color: var(--stone-900); }
.dt-theme-toggle svg { width: 18px; height: 18px; stroke-width: 2; }

/* ─── Utility: Desktop / Mobile Only ───────────────────────────── */
.desktop-only { display: none !important; }
.mobile-only { display: flex; }

/* ─── Page-Mode Back Header ────────────────────────────────────── */
.page-back-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  z-index: 100;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  padding-top: var(--safe-top);
  background: #fff;
  border-bottom: 1px solid var(--stone-100);
}

.back-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 50%;
  color: var(--stone-900);
  transition: background 0.15s;
}
.back-btn:active { background: var(--stone-100); }
.back-btn svg { width: 20px; height: 20px; stroke-width: 2.2; }

.back-brand {
  font-size: 16px;
  font-weight: 800;
  color: var(--emerald);
  cursor: pointer;
}

.page-mode-title {
  margin-left: auto;
  font-size: 14px;
  font-weight: 600;
  color: var(--stone-500);
}

/* ─── Page Mode — sub-pages (Store, Directory, etc.) ─────────── */
/* Light theme for sub-pages — white bg, dark text */
body.page-mode {
  background: var(--stone-50);
  color: var(--stone-900);
}

body.page-mode .app-header { display: none; }
body.page-mode .page-back-header { display: flex; }
body.page-mode .smart-navbar { display: none; }
body.page-mode .dock-btn { display: none; }
body.page-mode .dock-menu { display: none; }
body.page-mode .header-subbar { display: none; }
body.page-mode .app-banner { display: none !important; }

body.page-mode .pwa-content {
  margin-top: calc(var(--safe-top) + var(--header-height));
  margin-bottom: 0;
}

/* Sub-page content defaults to dark text on white */
body.page-mode #page-container {
  color: var(--stone-900);
}

body.page-mode .pwa-card {
  background: #fff;
  border-color: var(--stone-200);
  color: var(--stone-900);
}

body.page-mode .pwa-heading {
  color: var(--stone-900);
}

body.page-mode .pwa-label {
  color: var(--stone-500);
}

body.page-mode .pwa-toast {
  bottom: 24px;
}

/* ─── Desktop Sidebar (hidden on mobile) ───────────────────────── */
.desktop-sidebar { display: none; }

/* ─── Desktop Topbar (hidden on mobile) ────────────────────────── */
.desktop-topbar { display: none; }

/* ─── Desktop Layout — 1024px+ ─────────────────────────────────── */
@media (min-width: 1024px) {
  /* Utility classes */
  .desktop-only { display: flex !important; }
  .mobile-only { display: none !important; }

  /* ── Show sidebar ──────────────────────────────────────────────── */
  .desktop-sidebar {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--color-sidebar-bg);
    border-right: 1px solid var(--color-border);
    z-index: 101;
    overflow: hidden;
    transition: background 0.3s, border-color 0.3s;
  }

  .ds-brand { padding: 16px 20px 12px; }
  .ds-brand a {
    font-size: 20px;
    font-weight: 900;
    color: var(--emerald);
    letter-spacing: -0.5px;
    cursor: pointer;
    user-select: none;
  }

  .ds-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 12px;
  }
  .ds-nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 14px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 12px;
    transition: background 0.15s;
    width: 100%;
    text-align: left;
  }
  .ds-nav-item:hover { background: rgba(255,255,255,0.06); }
  .ds-nav-item:active { background: rgba(255,255,255,0.1); }
  .ds-nav-item svg {
    width: 22px; height: 22px; stroke-width: 2;
    color: var(--stone-500); flex-shrink: 0; transition: color 0.15s;
  }
  .ds-nav-item span {
    font-size: 14px; font-weight: 600;
    color: var(--stone-400); transition: color 0.15s;
  }
  .ds-nav-item.active svg { color: var(--emerald); }
  .ds-nav-item.active span { color: #fff; }
  .ds-nav-item.active { background: rgba(16, 185, 129, 0.08); }

  .ds-divider { height: 1px; background: rgba(255,255,255,0.06); margin: 8px 20px; }
  .ds-section { padding: 0 12px; }
  .ds-section-title {
    font-size: 10px; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.1em; color: var(--stone-600); padding: 8px 14px 8px;
  }
  .ds-link {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 14px; border-radius: 10px; cursor: pointer;
    transition: background 0.12s; color: var(--stone-400);
    font-size: 12.5px; font-weight: 500;
  }
  .ds-link:hover { background: rgba(255,255,255,0.06); color: var(--stone-300); }
  .ds-link:active { background: rgba(255,255,255,0.1); }
  .ds-link.active { background: rgba(16, 185, 129, 0.08); color: var(--emerald-light); }
  .ds-link.active svg { color: var(--emerald); }
  .ds-link svg { width: 18px; height: 18px; stroke-width: 2; flex-shrink: 0; }

  .ds-user {
    padding: 10px 16px; display: flex; align-items: center; gap: 10px;
    border-top: 1px solid rgba(255,255,255,0.06);
  }
  .ds-user-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    object-fit: cover; background: var(--stone-700); flex-shrink: 0;
  }
  .ds-user-name { font-size: 13px; font-weight: 600; color: var(--stone-200); }
  .ds-user-role { font-size: 10px; font-weight: 600; color: var(--emerald); text-transform: capitalize; }

  .ds-footer { padding: 8px 16px; display: flex; flex-wrap: wrap; gap: 8px; }
  .ds-footer a { font-size: 11px; color: var(--stone-600); cursor: pointer; transition: color 0.15s; }
  .ds-footer a:hover { color: var(--stone-400); }

  /* ── Show desktop topbar ───────────────────────────────────────── */
  .desktop-topbar {
    display: flex;
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--dt-height);
    align-items: center;
    padding: 0 32px;
    gap: 20px;
    background: var(--color-topbar-bg);
    border-bottom: 1px solid var(--color-border);
    z-index: 100;
    transition: background 0.3s, border-color 0.3s;
  }

  .dt-search {
    flex: 1;
    max-width: 480px;
    position: relative;
    display: flex;
    align-items: center;
  }
  .dt-search input {
    width: 100%;
    padding: 10px 16px 10px 42px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    color: #fff;
    font-size: 14px;
    font-family: inherit;
    font-weight: 500;
    transition: all 0.2s;
  }
  .dt-search input:focus {
    outline: none;
    border-color: var(--emerald);
    background: rgba(255,255,255,0.1);
    box-shadow: 0 0 0 3px rgba(16,185,129,0.12);
  }
  .dt-search input::placeholder { color: var(--stone-500); }
  .dt-search .dt-search-icon {
    position: absolute;
    left: 14px;
    width: 18px;
    height: 18px;
    color: var(--stone-500);
    pointer-events: none;
  }

  .dt-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
  }

  .dt-icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: rgba(255,255,255,0.06);
    border-radius: 12px;
    cursor: pointer;
    position: relative;
    color: var(--stone-400);
    transition: all 0.15s;
  }
  .dt-icon-btn:hover { background: rgba(255,255,255,0.1); color: #fff; }
  .dt-icon-btn svg { width: 18px; height: 18px; stroke-width: 2; }

  .dt-user-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 16px 6px 6px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 100px;
    cursor: pointer;
    transition: all 0.15s;
  }
  .dt-user-pill:hover { background: rgba(255,255,255,0.1); }
  .dt-user-pill img {
    width: 30px; height: 30px; border-radius: 50%;
    object-fit: cover; background: var(--stone-700);
  }
  .dt-user-pill span {
    font-size: 13px; font-weight: 600; color: var(--stone-300);
  }

  .dt-signin-btn {
    padding: 9px 22px;
    background: var(--emerald);
    color: #fff;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.15s;
    text-decoration: none;
  }
  .dt-signin-btn:hover { background: var(--emerald-dark); }

  /* ── Hide mobile nav elements on desktop ────────────────────────── */
  .smart-navbar { display: none !important; }
  .dock-btn { display: none !important; }
  .dock-menu { display: none !important; }
  .app-banner { display: none !important; }
  .app-header { display: none !important; }

  /* ── Desktop content layout ────────────────────────────────────── */
  .pwa-content {
    margin-top: var(--dt-height);
    margin-left: var(--sidebar-width);
    margin-bottom: 0;
    max-width: none;
  }

  /* Override 768px max-width constraints */
  .pwa-content,
  .smart-navbar .navbar-bg,
  .app-header .header-main,
  .app-header .header-subbar {
    max-width: none;
  }
  .pwa-content { margin-left: var(--sidebar-width); }

  /* Desktop: swipe container is NOT swipeable — show active view only */
  .swipe-container {
    width: 100%;
    overflow-x: hidden;
    scroll-snap-type: none;
  }
  .swipe-page {
    width: 100%;
    display: none;
    max-width: 1000px;
    margin: 0 auto;
    padding: 28px 40px 40px;
  }
  .swipe-page.active-view {
    display: block;
  }

  /* Content container — centered, proper desktop width */
  #page-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 16px 40px 40px;
  }

  /* ── Desktop page mode (breadcrumb bar — light) ───────────────── */
  body.page-mode .page-back-header {
    left: var(--sidebar-width);
    top: var(--dt-height);
    background: #fff;
    border-bottom: 1px solid var(--stone-200);
    height: 48px;
    padding: 0 40px;
  }
  body.page-mode .back-btn {
    color: var(--stone-500);
    width: 32px;
    height: 32px;
  }
  body.page-mode .back-btn:hover { background: var(--stone-100); color: var(--stone-900); }
  body.page-mode .back-brand { color: var(--emerald); font-size: 14px; }
  body.page-mode .page-mode-title { color: var(--stone-500); font-size: 13px; }

  body.page-mode .pwa-content {
    margin-top: calc(var(--dt-height) + 48px);
    margin-left: var(--sidebar-width);
  }

  /* Desktop page mode — white content area */
  body.page-mode {
    background: var(--stone-50);
  }

  /* ── Toast on desktop ──────────────────────────────────────────── */
  .pwa-toast {
    bottom: 24px;
    left: calc(var(--sidebar-width) + 50%);
    transform: translateX(-50%) translateY(20px);
  }
  .pwa-toast.show {
    transform: translateX(-50%) translateY(0);
  }

  /* ── Nav loader offset ─────────────────────────────────────────── */
  #nav-loader {
    left: var(--sidebar-width);
    top: calc(var(--dt-height) - 2px);
  }

  /* ── Desktop card / content improvements ───────────────────────── */
  .pwa-card {
    border-radius: 16px;
  }

  .pwa-heading {
    font-size: 28px;
  }
}
