/* ═══ MarketsMill — Exness-Style Sidebar Layout ═══ */

:root {
  --sidebar-width: 240px;
  --topbar-height: 56px;
}

/* ── Base typography (light-touch readability/eye-comfort pass) ── */
/* Loaded AFTER each page's inline <style>, so these wins the cascade. */
body {
  font-size: 15px;
  line-height: 1.55;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Inter, system-ui, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { letter-spacing: -0.01em; line-height: 1.25; }
p, li { line-height: 1.6; }
/* Tone down aggressive uppercase letter-spacing site-wide (chips/labels feel less shouty) */
[class*="label" i], [class*="-label" i], .s-card-label, .pi-label, .rd-label,
.section-title { letter-spacing: 0.3px; }

/* ── Remove dark-mode ambient glow ── */
body.has-sidebar::before { display: none !important; }

/* ── Layout Grid ── */
body.has-sidebar {
  display: flex;
  min-height: 100vh;
}

/* ══════════════════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════════════════ */
.sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-SecondaryBg);
  border-right: 1px solid var(--color-Line);
  overflow-y: auto;
  z-index: 200;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease;
}

.sidebar-logo {
  padding: 14px 20px;
  border-bottom: 1px solid var(--color-Line);
  display: flex;
  align-items: center;
}
.sidebar-logo a { display: flex; align-items: center; text-decoration: none; }
.sidebar-logo img {
  height: 24px;
  display: block;
}

/* Invert logo for light mode */
[data-theme="light"] .sidebar-logo img { filter: invert(1); }

/* Navigation sections */
.nav-section {
  border-bottom: 1px solid var(--color-Line);
}

.nav-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-PrimaryText);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.nav-section-header:hover {
  background: var(--color-HoverBg);
}

.nav-section-header .nav-icon {
  flex-shrink: 0;
  color: var(--color-TertiaryText);
}

.nav-section-header span {
  flex: 1;
}

.nav-section-header .nav-chevron {
  flex-shrink: 0;
  transition: transform 0.2s;
  color: var(--color-TertiaryText);
}

.nav-section.collapsed .nav-chevron {
  transform: rotate(-90deg);
}

.nav-section-items {
  max-height: 500px;
  overflow: hidden;
  transition: max-height 0.25s ease;
}

.nav-section.collapsed .nav-section-items {
  max-height: 0 !important;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px 10px 48px;
  font-size: 14px;
  color: var(--color-SecondaryText);
  text-decoration: none;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.nav-item:hover {
  color: var(--color-PrimaryText);
  background: var(--color-HoverBg);
}
.nav-item.active {
  color: var(--color-PrimaryText);
  font-weight: 500;
  background: rgba(252, 213, 53, 0.08);
  border-left-color: var(--color-PrimaryYellow);
}

.nav-item .nav-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(46, 189, 133, 0.12);
  color: var(--color-Buy);
  margin-left: auto;
}
.nav-item .nav-badge-count {
  background: #f6465d;
  color: #fff;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.nav-item .nav-external {
  margin-left: auto;
  color: var(--color-TertiaryText);
}

/* Sidebar bottom promo */
.sidebar-bottom {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--color-Line);
}

.sidebar-promo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: #ED7B30;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.15s;
  color: #fff;
}
.sidebar-promo:hover { opacity: 0.9; }

.sidebar-promo-icon {
  flex-shrink: 0;
  color: #fff;
}
.sidebar-promo-text .promo-title {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}
.sidebar-promo-text .promo-desc {
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  margin-top: 1px;
}

/* Sidebar collapse toggle (bottom) */
.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  border-top: 1px solid var(--color-Line);
  cursor: pointer;
  color: var(--color-TertiaryText);
  background: none;
  border-left: none;
  border-right: none;
  border-bottom: none;
  width: 100%;
  transition: background 0.15s;
}
.sidebar-collapse-btn:hover {
  background: var(--color-HoverBg);
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 199;
}

/* ══════════════════════════════════════════════════════════
   TOPBAR
   ══════════════════════════════════════════════════════════ */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--color-SecondaryBg);
  border-bottom: 1px solid var(--color-Line);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 24px;
  z-index: 250;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-right: auto;
}

.topbar-brand {
  display: flex;
  align-items: center;
  text-decoration: none;
  padding: 8px 4px;
}
.topbar-brand img {
  height: 22px;
  display: block;
}
[data-theme="light"] .topbar-brand img { filter: invert(1); }

.sidebar-toggle {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--color-PrimaryText);
  border-radius: 8px;
}
.sidebar-toggle:hover {
  background: var(--color-HoverBg);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-balance {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--color-PrimaryText);
  padding: 6px 12px;
  border-radius: 8px;
}
.topbar-balance svg {
  color: var(--color-TertiaryText);
}
.topbar-balance-label {
  font-size: 12px;
  font-weight: 400;
  color: var(--color-SecondaryText);
  margin-right: 2px;
}

.topbar-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-TertiaryText);
  transition: background 0.15s, color 0.15s;
  position: relative;
}
.topbar-icon:hover {
  background: var(--color-HoverBg);
  color: var(--color-PrimaryText);
}
.topbar-icon .notif-dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 6px;
  height: 6px;
  background: var(--color-Sell);
  border-radius: 50%;
  border: 1.5px solid var(--color-SecondaryBg);
}

/* ══════════════════════════════════════════════════════════
   MAIN WRAPPER
   ══════════════════════════════════════════════════════════ */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
}

.main-content {
  padding: calc(var(--topbar-height) + 24px) 32px 32px;
  max-width: 1440px;
}

.page-title {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 24px;
  color: var(--color-PrimaryText);
}

/* ══════════════════════════════════════════════════════════
   OVERRIDE EXISTING STYLES FOR SIDEBAR LAYOUT
   ══════════════════════════════════════════════════════════ */

/* Hide old brand-bar (replaced by sidebar + topbar) */
body.has-sidebar .brand-bar {
  display: none !important;
}

/* Remove old page container constraints */
body.has-sidebar .section-bg {
  background: transparent;
  padding: 0;
}
body.has-sidebar .page-container {
  max-width: none;
  padding: 0;
}

/* ── Role Tabs (centered iOS-style segmented control) ── */
body.has-sidebar .role-tabs {
  display: flex;
  width: fit-content;
  margin: 0 auto 32px;
  padding: 5px;
  gap: 3px;
  background: var(--color-Vessel);
  border: 1px solid var(--color-Line);
  border-radius: 999px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}
body.has-sidebar .role-tab {
  padding: 12px 40px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--color-SecondaryText);
  border-radius: 999px;
  transition: color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease, transform 0.1s ease;
}
body.has-sidebar .role-tab:first-child,
body.has-sidebar .role-tab:last-child {
  border-radius: 999px;
  border-left: none;
}
body.has-sidebar .role-tab:hover:not(.active) {
  color: var(--color-PrimaryText);
  background: var(--color-HoverBg);
}
body.has-sidebar .role-tab:active:not(.active) {
  transform: scale(0.97);
}
body.has-sidebar .role-tab.active {
  background: var(--color-CardBg);
  color: var(--color-PrimaryText);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.06);
  text-shadow: none;
}
@media (max-width: 520px) {
  body.has-sidebar .role-tabs { width: 100%; max-width: 400px; }
  body.has-sidebar .role-tab { flex: 1; padding: 12px 20px; text-align: center; font-size: 14.5px; }
}

/* ── Portfolio Hero (Exness account card) ── */
body.has-sidebar .portfolio-hero {
  background: var(--color-CardBg);
  border: 1px solid var(--color-Line);
  border-left: none;
  border-radius: 12px;
  padding: 24px 28px;
  margin-bottom: 20px;
  box-shadow: none;
  position: relative;
  overflow: visible;
}
body.has-sidebar .portfolio-hero::before {
  display: none;
}
body.has-sidebar .portfolio-hero-icon {
  background: var(--color-HoverBg);
  box-shadow: none;
  color: var(--color-PrimaryText);
}
body.has-sidebar .portfolio-hero-value {
  font-size: 36px;
  font-weight: 600;
  letter-spacing: -0.5px;
}
body.has-sidebar .hero-btn {
  padding: 10px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
}
body.has-sidebar .hero-btn-deposit {
  background: #ED7B30;
  color: #000;
  box-shadow: none;
}
body.has-sidebar .hero-btn-deposit:hover {
  background: #f08c4a;
  box-shadow: none;
  transform: none;
}
body.has-sidebar .hero-btn-withdraw {
  border: 1px solid var(--color-Line);
  color: var(--color-PrimaryText);
  background: transparent;
}
body.has-sidebar .hero-btn-withdraw:hover {
  border-color: var(--color-SecondaryText);
  color: var(--color-PrimaryText);
}

/* ── Earnings Row ── */
body.has-sidebar .earnings-item {
  background: var(--color-CardBg);
  border: 1px solid var(--color-Line);
  border-radius: 12px;
  box-shadow: none;
}
body.has-sidebar .earnings-item::before {
  display: none;
}
body.has-sidebar .earnings-item:hover {
  border-color: var(--color-SecondaryText);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  transform: none;
}

/* ── Summary Cards ── */
body.has-sidebar .summary-card {
  background: var(--color-CardBg);
  border: 1px solid var(--color-Line);
  border-radius: 12px;
  box-shadow: none;
}
body.has-sidebar .summary-card::after {
  display: none;
}
body.has-sidebar .summary-card:hover {
  background: var(--color-HoverBg);
  border-color: var(--color-SecondaryText);
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  transform: none;
}
body.has-sidebar .summary-card .card-icon {
  background: var(--color-HoverBg);
}
body.has-sidebar .summary-card:hover .card-icon {
  background: rgba(0,0,0,0.05);
  box-shadow: none;
}

/* ── Plan Cards ── */
body.has-sidebar .plan-card {
  background: var(--color-CardBg);
  border: 1px solid var(--color-Line);
  border-radius: 12px;
  box-shadow: none;
}
body.has-sidebar .plan-card::before {
  display: none;
}
body.has-sidebar .plan-card:hover {
  background: var(--color-HoverBg);
  border-color: var(--color-SecondaryText);
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
  transform: translateY(-2px);
}
body.has-sidebar .btn-accent {
  background: var(--color-PrimaryYellow);
  color: #000;
  box-shadow: none;
}

/* ── Tables ── */
body.has-sidebar .inv-table {
  background: var(--color-CardBg);
  border: 1px solid var(--color-Line);
  border-radius: 12px;
  box-shadow: none;
}
body.has-sidebar .inv-table thead {
  background: var(--color-Vessel);
}

/* ── Partner Section Cards ── */
body.has-sidebar .partner-balance-card,
body.has-sidebar .partner-level-card,
body.has-sidebar .partner-link-card,
body.has-sidebar .p2p-bond-card,
body.has-sidebar .residual-pool-card,
body.has-sidebar .quick-reports,
body.has-sidebar .pool-card,
body.has-sidebar .mi-card,
body.has-sidebar .tree-card {
  background: var(--color-CardBg);
  border: 1px solid var(--color-Line);
  border-radius: 12px;
  box-shadow: none;
}
body.has-sidebar .partner-balance-card:hover,
body.has-sidebar .partner-level-card:hover,
body.has-sidebar .partner-link-card:hover,
body.has-sidebar .p2p-bond-card:hover,
body.has-sidebar .residual-pool-card:hover,
body.has-sidebar .quick-reports:hover,
body.has-sidebar .pool-card:hover,
body.has-sidebar .mi-card:hover {
  box-shadow: 0 2px 12px rgba(0,0,0,0.05);
}

/* ── Pool / MI Tier Cards ── */
body.has-sidebar .pool-tier,
body.has-sidebar .mi-tier {
  background: var(--color-Vessel);
  border: 1px solid var(--color-Line);
}

/* ── Divider ── */
body.has-sidebar .divider {
  background: none;
}

/* ── Section Title ── */
body.has-sidebar .section-title {
  font-size: 18px;
}

/* ── Filter / Pagination Buttons ── */
body.has-sidebar .ptx-filter {
  background: var(--color-CardBg);
  border: 1px solid var(--color-Line);
  color: var(--color-SecondaryText);
}
body.has-sidebar .ptx-filter.active {
  background: var(--color-PrimaryText);
  color: var(--color-SecondaryBg);
  border-color: var(--color-PrimaryText);
}
body.has-sidebar .ptx-page-btn {
  background: var(--color-CardBg);
  border: 1px solid var(--color-Line);
}

/* ── Profile Dropdown ── */
body.has-sidebar .profile-dropdown {
  background: var(--color-CardBg);
  border: 1px solid var(--color-Line);
  box-shadow: 0 4px 24px rgba(0,0,0,0.1);
  backdrop-filter: none;
}
body.has-sidebar .profile-menu-item:hover {
  background: var(--color-HoverBg);
}

/* ── Footer ── */
body.has-sidebar .page-footer {
  border-top: 1px solid var(--color-Line);
  padding: 24px 0;
  text-align: center;
  background: transparent;
}

/* ══════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
   ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: min(86vw, 320px);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
  }
  .sidebar.open ~ .sidebar-overlay {
    display: block;
  }
  .sidebar-toggle {
    display: flex;
    flex-shrink: 0;
  }
  .main-wrapper {
    margin-left: 0;
    /* Allow flex shrinking — without min-width:0 the wrapper takes its
       children's min-content size and overflows viewport, causing iOS
       to auto-zoom out on phones with content wider than 375px. */
    min-width: 0;
  }
  .main-content {
    padding: calc(var(--topbar-height) + 16px) 16px 16px;
    min-width: 0;
    max-width: 100vw;
    /* Clip any deeply-nested wider content (e.g. data tables inside
       overflow-x:auto wrappers) — iOS Safari otherwise treats them as
       viewport-content and auto-zooms-out to fit. The wrappers' own
       horizontal scroll still works for the user. */
    overflow-x: hidden;
  }

  /* Topbar tightens up — less padding, smaller gaps */
  .topbar {
    padding: 0 12px;
    gap: 6px;
  }
  .topbar-left {
    gap: 6px;
    /* Allow the brand to shrink so the hamburger + logo never spill off
       the left edge (topbar uses justify-content:flex-end). */
    min-width: 0;
  }
  .topbar-brand {
    padding: 8px 2px;
    min-width: 0;
  }
  .topbar-brand img {
    /* Scale the logo down proportionally on very narrow phones instead
       of letting the fixed-height logo overflow the topbar. */
    height: auto;
    max-height: 20px;
    max-width: 100%;
  }
  .topbar-right {
    gap: 4px;
  }

  /* Drop the "Portfolio Balance" word — the $ value is enough on mobile */
  .topbar-balance {
    padding: 6px 8px;
    font-size: 13px;
  }
  .topbar-balance-label {
    display: none;
  }
}

/* Extra-small phones: hide balance pill entirely, only icons + brand remain */
@media (max-width: 480px) {
  .topbar {
    padding: 0 8px;
    gap: 4px;
  }
  .topbar-brand img {
    max-height: 18px;
  }
  .topbar-balance {
    display: none;
  }
  .topbar-icon {
    width: 34px;
    height: 34px;
  }
  .sidebar-toggle {
    width: 36px;
    height: 36px;
  }
}

/* Lock background scroll while the mobile sidebar drawer is open */
@media (max-width: 768px) {
  body.has-sidebar:has(.sidebar.open) {
    overflow: hidden;
  }
}

/* ── Sidebar scrollbar ── */
.sidebar::-webkit-scrollbar {
  width: 4px;
}
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar::-webkit-scrollbar-thumb {
  background: var(--color-Line);
  border-radius: 2px;
}

/* ── Profile UID copy button ────────────────────────────── */
.profile-uid {
  display: flex;
  align-items: center;
  gap: 6px;
}
.profile-uid-copy {
  background: none;
  border: none;
  padding: 2px;
  margin: 0;
  cursor: pointer;
  color: var(--color-TertiaryText);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}
.profile-uid-copy:hover {
  color: var(--color-PrimaryText);
  background: var(--color-HoverBg);
}
.profile-uid-copy.copied {
  color: var(--color-Buy);
}
