:root {
  --bg: #0b0e14;
  --header-bg: #0b0e14;
  --card-bg: #131722;
  --surface-bg: #181c27;
  --input-bg: #141822;
  --border: #1f232d;
  --sub-border: #2a2e39;
  --text-primary: #e0e3eb;
  --text-secondary: #787b86;
  --text-muted: #50535e;
  --accent: #2962ff;
  --accent-blue: #2962ff;
  --buy-green: #089981;
  --buy-green-bg: rgba(8, 153, 129, 0.18);
  --sell-red: #f23645;
  --sell-red-bg: rgba(242, 54, 69, 0.18);
  --gold: #f59e0b;
  --modal-overlay: rgba(0, 0, 0, 0.82);
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', Helvetica, Arial, sans-serif;
  --font-mono: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', Helvetica, Arial, sans-serif;
}

body.light-theme {
  --bg: #f8fafc;
  --header-bg: #ffffff;
  --card-bg: #ffffff;
  --surface-bg: #f1f5f9;
  --input-bg: #e2e8f0;
  --border: #cbd5e1;
  --sub-border: #94a3b8;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --accent: #2962ff;
  --accent-blue: #2962ff;
  --buy-green: #089981;
  --buy-green-bg: rgba(8, 153, 129, 0.12);
  --sell-red: #f23645;
  --sell-red-bg: rgba(242, 54, 69, 0.12);
  --gold: #f59e0b;
  --modal-overlay: rgba(15, 23, 42, 0.6);
}

*,
button,
input,
textarea,
select {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-family);
}

html {
  height: 100%;
  background-color: var(--bg);
  font-family: var(--font-family);
}

body {
  font-family: var(--font-family);
  background-color: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: 0;
  overflow-x: hidden;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior-y: contain;
}

.app-container {
  width: 100%;
  max-width: 540px;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: max(32px, env(safe-area-inset-bottom, 20px));
}

/* Active Tap Feedback */
button:active,
.btn-ls:active,
.header-btn:active,
.tool-btn:active,
.filter-pill:active {
  transform: scale(0.96);
  opacity: 0.9;
}

/* Global Scrollbar Suppression */
* {
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}

*::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}

/* 1. Header (Standardized Across All Pages) */
.admin-header,
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  gap: 10px;
}

.admin-brand,
.brand-box {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  min-width: 0;
  flex: 1;
  cursor: pointer;
}

.admin-logo,
.brand-logo-img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--sub-border);
  flex-shrink: 0;
  display: block;
}

.admin-title-wrap,
.brand-title-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.admin-title,
.brand-title {
  font-size: 14.5px;
  font-weight: 900;
  letter-spacing: -0.2px;
  color: var(--text-primary);
  line-height: 1.2;
}

.admin-subtitle {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-secondary);
  line-height: 1.2;
}

.brand-version-badge {
  font-size: 9.5px;
  font-weight: 800;
  color: #2962ff;
  background: var(--input-bg);
  border: 1px solid var(--sub-border);
  padding: 1px 5px;
  border-radius: 4px;
}

.header-links,
.header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.header-btn {
  background: var(--card-bg);
  border: 1px solid var(--sub-border);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 11px;
  color: var(--text-primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  box-sizing: border-box;
  transition: all 0.15s ease;
}

.header-btn:hover {
  background: var(--surface-bg);
}

.push-badge-btn {
  padding: 3px 6px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  box-sizing: border-box;
  border: 1px solid #089981;
  background: var(--card-bg);
}

/* 2. Top Navigation Tabs */
.tabs-bar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 10px;
  position: sticky;
  top: 53px;
  z-index: 99;
}

.tab-btn {
  flex: 0 0 auto;
  text-align: left;
  padding: 12px 6px;
  font-size: 13px;
  font-weight: 800;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-bottom: 2.5px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

#tabWatchlistBtn,
#tabPositionsBtn,
#tabScannerBtn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  padding-left: 6px;
  padding-right: 6px;
}

.tab-btn.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.tab-pnl-pill,
.tab-m2m-badge {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.2px;
  padding: 2px 7px;
  border-radius: 4px;
  font-family: var(--font-mono);
  display: inline-flex;
  align-items: center;
  line-height: 1.1;
  white-space: nowrap;
  flex-shrink: 0;
}

.tab-pnl-pill.green,
.tab-m2m-badge.green {
  background: rgba(8, 153, 129, 0.18);
  color: #089981;
}

.tab-pnl-pill.red,
.tab-m2m-badge.red {
  background: rgba(242, 54, 69, 0.18);
  color: #f23645;
}

/* 3. Screen Views */
.screen-view {
  display: none;
  flex-direction: column;
  padding: 10px 12px calc(140px + env(safe-area-inset-bottom, 24px));
  width: 100%;
  box-sizing: border-box;
}

.screen-view.active {
  display: flex;
}

/* Buttons and Common Helpers */
.btn-block {
  width: 100%;
  padding: 11px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  border: none;
  text-align: center;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-success {
  background: #2ea043;
  color: #ffffff;
}

.btn-danger {
  background: var(--sell-red);
  color: #ffffff;
}

.btn-secondary {
  background: var(--surface-bg);
  color: var(--text-primary);
  border: 1px solid var(--sub-border);
}

/* Orientation Guard: Prevent Horizontal / Landscape Rotation */
.orientation-blocker {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: rgba(11, 14, 20, 0.98);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

@media screen and (orientation: landscape) and (max-height: 520px) and (hover: none) and (pointer: coarse) {
  .orientation-blocker {
    display: flex;
  }
}

.orientation-card {
  background: var(--surface, #131722);
  border: 1px solid var(--border, #2a2e39);
  border-radius: 16px;
  padding: 24px 20px;
  max-width: 320px;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: pwaModalFadeIn 0.3s ease;
}

.orientation-icon {
  font-size: 36px;
  display: inline-block;
  animation: rotatePrompt 2s ease-in-out infinite alternate;
}

@keyframes rotatePrompt {
  0% { transform: rotate(90deg); }
  50% { transform: rotate(0deg); }
  100% { transform: rotate(0deg); }
}

.orientation-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-primary, #f1f5f9);
}

.orientation-desc {
  font-size: 12px;
  color: var(--text-secondary, #94a3b8);
  line-height: 1.4;
}

/* ==========================================================================
   Google Auth Gate Overlay (Full-screen gate when unauthenticated)
   ========================================================================== */
.auth-gate-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 30%, rgba(41, 98, 255, 0.15), var(--bg, #0b0e14) 75%);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.auth-gate-card {
  background: var(--card-bg, #131722);
  border: 1px solid var(--border, #1f232d);
  border-radius: 18px;
  max-width: 400px;
  width: 100%;
  padding: 32px 24px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(41, 98, 255, 0.15);
  animation: gatePopIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes gatePopIn {
  from { opacity: 0; transform: scale(0.92) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.auth-gate-logo-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}

.auth-gate-logo {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  border: 2px solid rgba(41, 98, 255, 0.4);
  box-shadow: 0 8px 24px rgba(41, 98, 255, 0.35);
  object-fit: cover;
}

.auth-gate-title {
  font-size: 22px;
  font-weight: 900;
  color: var(--text-primary, #f1f5f9);
  margin-bottom: 4px;
  letter-spacing: -0.3px;
}

.auth-gate-badge {
  font-size: 10px;
  font-weight: 800;
  color: #60a5fa;
  letter-spacing: 0.8px;
  margin-bottom: 12px;
}

.auth-gate-desc {
  font-size: 12.5px;
  color: var(--text-secondary, #94a3b8);
  line-height: 1.5;
  margin-bottom: 22px;
}

.auth-gate-google-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 800;
  border-radius: 10px;
  background: #ffffff;
  color: #1f2937;
  border: 1px solid #d1d5db;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease;
  user-select: none;
}
.auth-gate-google-btn:hover {
  background: #f3f4f6;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.auth-gate-google-btn:active {
  transform: scale(0.97) translateY(1px);
}

.auth-gate-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 18px 0 12px;
  font-size: 9.5px;
  font-weight: 800;
  color: var(--text-muted, #50535e);
  letter-spacing: 0.6px;
  position: relative;
}
.auth-gate-divider::before,
.auth-gate-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--sub-border, #2a2e39);
  margin: 0 10px;
}

.auth-gate-email-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.auth-gate-footer {
  font-size: 10.5px;
  color: var(--text-muted, #50535e);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* ==========================================================================
   Hard Refresh Button & Icon (Universal App Cache Buster)
   ========================================================================== */
.refresh-icon-btn {
  width: 26px;
  height: 26px;
  min-width: 26px;
  border-radius: 6px;
  background: rgba(41, 98, 255, 0.14) !important;
  border: 1px solid rgba(41, 98, 255, 0.35) !important;
  color: #60a5fa !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
  box-sizing: border-box;
  outline: none;
}
.refresh-icon-btn:hover {
  background: rgba(41, 98, 255, 0.28) !important;
  border-color: #2962ff !important;
  color: #93c5fd !important;
  transform: translateY(-1px);
  box-shadow: 0 0 10px rgba(41, 98, 255, 0.4);
}
.refresh-icon-btn:active {
  transform: scale(0.92);
  background: rgba(41, 98, 255, 0.38) !important;
}
.refresh-icon-btn .spin-icon {
  font-size: 12.5px;
  line-height: 1;
  display: inline-block;
  transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}
.refresh-icon-btn:hover .spin-icon {
  transform: rotate(180deg);
}

/* ==========================================================================
   Ghost Working / Refreshing Pulse & Glow Animations
   ========================================================================== */
@keyframes ghostSpinPulse {
  0% {
    transform: rotate(0deg) scale(0.92);
    opacity: 0.35;
    filter: drop-shadow(0 0 4px #38bdf8) drop-shadow(0 0 10px #2962ff);
  }
  50% {
    transform: rotate(180deg) scale(1.22);
    opacity: 1;
    filter: drop-shadow(0 0 12px #38bdf8) drop-shadow(0 0 24px #60a5fa);
  }
  100% {
    transform: rotate(360deg) scale(0.92);
    opacity: 0.35;
    filter: drop-shadow(0 0 4px #38bdf8) drop-shadow(0 0 10px #2962ff);
  }
}

@keyframes ghostGlowRing {
  0%, 100% {
    background: rgba(41, 98, 255, 0.15) !important;
    border-color: rgba(56, 189, 248, 0.4) !important;
    box-shadow: 0 0 8px rgba(41, 98, 255, 0.3), inset 0 0 6px rgba(56, 189, 248, 0.2) !important;
  }
  50% {
    background: rgba(41, 98, 255, 0.38) !important;
    border-color: #38bdf8 !important;
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.8), 0 0 35px rgba(41, 98, 255, 0.5), inset 0 0 12px rgba(41, 98, 255, 0.6) !important;
  }
}

.refresh-icon-btn.is-refreshing,
.header-btn.is-refreshing,
.hard-refresh-btn.is-refreshing,
.tool-btn.is-refreshing,
.order-snapshot-btn.is-refreshing {
  animation: ghostGlowRing 0.85s ease-in-out infinite !important;
  pointer-events: none !important;
  cursor: wait !important;
}

.refresh-icon-btn.is-refreshing .spin-icon,
.header-btn.is-refreshing .spin-icon,
.hard-refresh-btn.is-refreshing .spin-icon,
.tool-btn.is-refreshing .spin-icon,
.order-snapshot-btn.is-refreshing .spin-icon,
.spin-icon.is-refreshing {
  animation: ghostSpinPulse 0.7s linear infinite !important;
  display: inline-block !important;
}

.hard-refresh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 8px;
  font-size: 10.5px;
  font-weight: 800;
  border-radius: 6px;
  background: rgba(41, 98, 255, 0.14) !important;
  border: 1px solid rgba(41, 98, 255, 0.35) !important;
  color: #60a5fa !important;
  cursor: pointer;
  transition: all 0.18s ease;
  user-select: none;
  white-space: nowrap;
  height: 26px;
  box-sizing: border-box;
  outline: none;
}
.hard-refresh-btn:hover {
  background: rgba(41, 98, 255, 0.28) !important;
  border-color: #2962ff !important;
  color: #93c5fd !important;
  transform: translateY(-1px);
  box-shadow: 0 0 10px rgba(41, 98, 255, 0.4);
}
.hard-refresh-btn:active {
  transform: scale(0.92);
  background: rgba(41, 98, 255, 0.38) !important;
}
.hard-refresh-btn .spin-icon {
  display: inline-block;
  font-size: 11px;
  transition: transform 0.4s ease;
}
.hard-refresh-btn:hover .spin-icon {
  transform: rotate(180deg);
}

/* Device ID Inconsolata Monospace Font (Consolas alternative from Google Fonts) */
.device-id-value,
#loginDeviceIdDisplay,
#gateDeviceIdDisplay,
#brokerDeviceIdDisplay,
#authDeviceSerialLabel {
  font-family: 'Inconsolata', 'Consolas', 'Lucida Console', monospace !important;
  font-size: 15.5px !important;
  font-weight: 700 !important;
  color: #38bdf8 !important;
  letter-spacing: 1px !important;
  line-height: 1.35 !important;
  word-break: break-all !important;
}

/* ==========================================================================
   Broker Funds & Limits Real-time Widget
   ========================================================================== */
.broker-funds-container {
  margin-top: 10px;
  background: rgba(13, 16, 23, 0.95);
  border: 1px solid var(--border, #1f232d);
  border-radius: 9px;
  padding: 10px 12px;
}

.btn-get-funds {
  width: 100%;
  padding: 8px 12px;
  font-size: 11px;
  font-weight: 800;
  border-radius: 7px;
  background: rgba(41, 98, 255, 0.16);
  border: 1px solid rgba(41, 98, 255, 0.4);
  color: #60a5fa;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.18s ease;
  user-select: none;
  box-sizing: border-box;
}

.btn-get-funds:hover {
  background: rgba(41, 98, 255, 0.28);
  border-color: #2962ff;
  color: #93c5fd;
  transform: translateY(-1px);
  box-shadow: 0 0 12px rgba(41, 98, 255, 0.35);
}

.btn-get-funds:active {
  transform: scale(0.97);
}

.broker-funds-box {
  margin-top: 10px;
  animation: fadeIn 0.25s ease;
}

.funds-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.funds-title {
  font-size: 11px;
  font-weight: 800;
  color: #f1f5f9;
  letter-spacing: 0.2px;
}

.funds-badge {
  font-size: 9.5px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 5px;
}

.funds-badge.success {
  background: rgba(16, 185, 129, 0.18);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #34d399;
}

.funds-badge.error {
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #f87171;
}

.funds-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}

.funds-tile {
  background: #0d1017;
  border: 1px solid #1f232d;
  border-radius: 7px;
  padding: 7px 9px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.funds-tile.highlight {
  background: rgba(41, 98, 255, 0.08);
  border-color: rgba(41, 98, 255, 0.3);
}

.funds-tile-label {
  font-size: 9px;
  font-weight: 800;
  color: #787b86;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.funds-tile-val {
  font-size: 13px;
  font-weight: 800;
  color: #38bdf8;
  font-family: 'Inconsolata', 'Consolas', monospace !important;
}

.funds-msg {
  font-size: 10.5px;
  padding: 7px 9px;
  border-radius: 6px;
  line-height: 1.35;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.funds-msg.success {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #a7f3d0;
}

.funds-msg.error {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

/* Inline 1-Tap Auth Status Message Box */
.auth-status-msg {
  font-size: 10.5px;
  padding: 8px 10px;
  border-radius: 6px;
  line-height: 1.4;
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 8px;
  animation: fadeIn 0.2s ease;
}

.auth-status-msg.loading {
  background: rgba(96, 165, 250, 0.1);
  border: 1px solid rgba(96, 165, 250, 0.35);
  color: #93c5fd;
}

.auth-status-msg.success {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #a7f3d0;
}

.auth-status-msg.error {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

/* System-Wide Toast Suppression (Per User Request) */
#toast, #adminToast, .toast, .toast-notification, .pwa-toast {
  display: none !important;
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  height: 0 !important;
  width: 0 !important;
  overflow: hidden !important;
}

