/* =========================================================
   CRM V1438 - Correção responsiva, sidebar rolável sem barra
   e troca de tema com sensação imediata.
   ========================================================= */

:root{
  --crm-sidebar-safe-width:var(--crm-sidebar-width, 250px);
  --crm-sidebar-collapsed-width:88px;
}

html,
body{
  min-height:100%;
  overscroll-behavior-y:auto;
  touch-action:pan-y;
}

html.crm-theme-switching,
html.crm-theme-switching *,
html.crm-sidebar-resizing,
html.crm-sidebar-resizing *{
  transition:none !important;
  animation-duration:.001ms !important;
  animation-iteration-count:1 !important;
}

@media (min-width:981px){
  body:not(.sidebar-collapsed) .appShell{
    grid-template-columns:minmax(224px, var(--crm-sidebar-safe-width)) minmax(0, 1fr) !important;
  }

  body.sidebar-collapsed .appShell{
    grid-template-columns:var(--crm-sidebar-collapsed-width) minmax(0, 1fr) !important;
  }

  .sidebar{
    position:sticky !important;
    top:0 !important;
    height:100vh !important;
    height:100dvh !important;
    max-height:100vh !important;
    max-height:100dvh !important;
    min-height:0 !important;
    overflow-y:auto !important;
    overflow-x:hidden !important;
    scrollbar-width:none !important;
    -ms-overflow-style:none !important;
    -webkit-overflow-scrolling:touch !important;
    overscroll-behavior:contain !important;
    justify-content:flex-start !important;
    gap:14px !important;
  }

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

  .sidebar > div:first-child{
    min-height:0 !important;
  }

  .sidebarFooter{
    margin-top:auto !important;
    padding-top:12px !important;
    flex-shrink:0 !important;
    overflow:visible !important;
  }

  body:not(.sidebar-collapsed) .sidebar .brandText,
  body:not(.sidebar-collapsed) .sidebar .navLabel,
  body:not(.sidebar-collapsed) .sidebar .miniUser,
  body:not(.sidebar-collapsed) .sidebarFooter .navLabel{
    display:block !important;
    opacity:1 !important;
    visibility:visible !important;
  }

  body:not(.sidebar-collapsed) .sidebar .navItem,
  body:not(.sidebar-collapsed) .sidebarFooter .navItem{
    justify-content:flex-start !important;
  }

  body:not(.sidebar-collapsed) .sidebar .navIcon{
    flex:0 0 26px !important;
  }

  body:not(.sidebar-collapsed) .sidebar .navLabel{
    min-width:0 !important;
    white-space:nowrap !important;
    overflow:hidden !important;
    text-overflow:ellipsis !important;
  }

  body.sidebar-collapsed .sidebar{
    padding-left:8px !important;
    padding-right:8px !important;
  }

  body.sidebar-collapsed .sidebar .brandText,
  body.sidebar-collapsed .sidebar .navLabel,
  body.sidebar-collapsed .sidebar .miniUser,
  body.sidebar-collapsed .sidebarFooter .navLabel{
    display:none !important;
  }

  body.sidebar-collapsed .sidebar .navItem,
  body.sidebar-collapsed .sidebarFooter .navItem{
    justify-content:center !important;
    padding-left:8px !important;
    padding-right:8px !important;
  }
}

body.workspace-host-mode .sidebar{
  overflow-y:auto !important;
  overflow-x:hidden !important;
  scrollbar-width:none !important;
  -ms-overflow-style:none !important;
  -webkit-overflow-scrolling:touch !important;
  overscroll-behavior:contain !important;
}

body.workspace-host-mode .sidebar::-webkit-scrollbar{
  width:0 !important;
  height:0 !important;
  display:none !important;
}

body.workspace-host-mode .mainContent,
body.workspace-host-mode .currentWorkspacePane,
body.workspace-host-mode .workspacePane,
.workspace-embed .mainContent{
  -webkit-overflow-scrolling:touch !important;
  touch-action:pan-y !important;
}

@media (max-width:980px){
  html,
  body{
    min-height:100%;
    overflow-x:hidden !important;
    touch-action:pan-y !important;
  }

  .appShell,
  body.sidebar-collapsed .appShell{
    display:block !important;
    grid-template-columns:1fr !important;
    min-height:100vh !important;
    min-height:100dvh !important;
    overflow-x:hidden !important;
  }

  .mobileSidebarBtn{
    display:inline-flex !important;
    position:fixed !important;
    top:calc(12px + env(safe-area-inset-top)) !important;
    left:12px !important;
    z-index:12050 !important;
    width:44px !important;
    height:44px !important;
    min-width:44px !important;
    border-radius:999px !important;
    background:rgba(5,14,24,.78) !important;
    backdrop-filter:blur(14px) !important;
    box-shadow:0 14px 30px rgba(0,0,0,.32), 0 0 0 1px color-mix(in srgb, var(--primary) 28%, transparent) !important;
  }

  .sidebarBackdrop{
    display:block !important;
    position:fixed !important;
    inset:0 !important;
    z-index:12020 !important;
    border:0 !important;
    padding:0 !important;
    background:rgba(3,9,16,.62) !important;
    backdrop-filter:blur(4px) !important;
    opacity:0 !important;
    pointer-events:none !important;
    transition:opacity .16s ease !important;
  }

  body.mobile-sidebar-open .sidebarBackdrop{
    opacity:1 !important;
    pointer-events:auto !important;
  }

  .sidebar,
  body.sidebar-collapsed .sidebar{
    position:fixed !important;
    left:0 !important;
    top:0 !important;
    right:auto !important;
    bottom:0 !important;
    width:min(88vw, 340px) !important;
    max-width:min(88vw, 340px) !important;
    height:100vh !important;
    height:100dvh !important;
    max-height:100vh !important;
    max-height:100dvh !important;
    z-index:12040 !important;
    padding:18px 14px calc(18px + env(safe-area-inset-bottom)) !important;
    transform:translate3d(-110%,0,0) !important;
    transition:transform .18s ease !important;
    overflow-y:auto !important;
    overflow-x:hidden !important;
    scrollbar-width:none !important;
    -ms-overflow-style:none !important;
    -webkit-overflow-scrolling:touch !important;
    overscroll-behavior:contain !important;
    justify-content:flex-start !important;
    gap:14px !important;
    border-right:2px solid #000 !important;
    border-top:0 !important;
  }

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

  body.mobile-sidebar-open .sidebar{
    transform:translate3d(0,0,0) !important;
  }

  body.mobile-sidebar-open{
    overflow:hidden !important;
    touch-action:none !important;
  }

  body.mobile-sidebar-open .sidebar{
    touch-action:pan-y !important;
  }

  .sidebar .brandRow,
  .sidebar .brandText,
  .sidebar .navLabel,
  .sidebar .miniUser,
  .sidebarFooter .navLabel{
    display:block !important;
    opacity:1 !important;
    visibility:visible !important;
  }

  .sidebar .brandRow{
    display:flex !important;
  }

  .sidebar .navMenu{
    display:grid !important;
    grid-auto-flow:row !important;
    gap:10px !important;
    margin-top:12px !important;
    overflow:visible !important;
    max-height:none !important;
  }

  .sidebar .navSubMenu{
    display:grid !important;
    gap:8px !important;
    padding-left:12px !important;
  }

  .sidebar .navItem,
  .sidebarFooter .navItem{
    width:100% !important;
    min-height:52px !important;
    justify-content:flex-start !important;
    padding:12px 14px !important;
  }

  .sidebarFooter{
    margin-top:auto !important;
    display:grid !important;
    gap:10px !important;
    overflow:visible !important;
    padding-top:12px !important;
  }

  .mainContent,
  body.workspace-host-mode .mainContent{
    width:100% !important;
    min-width:0 !important;
    max-width:100% !important;
    padding:12px !important;
    overflow-x:hidden !important;
    touch-action:pan-y !important;
  }

  .topbarTitleWrap{
    padding-left:52px !important;
  }

  body.workspace-host-mode,
  body.workspace-host-mode .appShell{
    height:100vh !important;
    height:100dvh !important;
    overflow:hidden !important;
  }

  body.workspace-host-mode .currentWorkspacePane,
  body.workspace-host-mode .workspacePane{
    overflow:auto !important;
    -webkit-overflow-scrolling:touch !important;
    touch-action:pan-y !important;
  }
}

@media (max-width:720px){
  body.loginBody{
    display:block !important;
    min-height:100vh !important;
    min-height:100dvh !important;
    height:auto !important;
    overflow-y:auto !important;
    overflow-x:hidden !important;
    -webkit-overflow-scrolling:touch !important;
    touch-action:pan-y !important;
    padding:14px !important;
    place-items:unset !important;
  }

  .loginBody .loginCardWide,
  .loginBody .loginCardPremium{
    width:100% !important;
    max-width:100% !important;
    margin:0 auto calc(18px + env(safe-area-inset-bottom)) !important;
    overflow:visible !important;
  }

  .loginBody .loginBrandPremium,
  .loginBody .loginFormPremium{
    padding:20px 16px !important;
  }

  .loginBody .loginFeatureGrid,
  .loginBody .loginMiniStats{
    grid-template-columns:1fr !important;
  }
}


/* =========================================================
   CRM V1438 - Sidebar sempre rolável, sem barra visível,
   login móvel com arraste e hover sem trocar cor das letras.
   ========================================================= */

html,
body{
  overscroll-behavior-y:auto !important;
}

html body .sidebar,
html body[data-ui-theme] .sidebar,
html body.workspace-host-mode .sidebar,
html body .sidebar:has(.navTree[open]){
  overflow-y:auto !important;
  overflow-x:hidden !important;
  scrollbar-width:none !important;
  -ms-overflow-style:none !important;
  -webkit-overflow-scrolling:touch !important;
  overscroll-behavior:contain !important;
  touch-action:pan-y !important;
}

html body .sidebar::-webkit-scrollbar,
html body .sidebar *::-webkit-scrollbar{
  width:0 !important;
  height:0 !important;
  display:none !important;
}

html body:not(.sidebar-collapsed) .sidebar .navLabel,
html body:not(.sidebar-collapsed) .sidebarFooter .navLabel{
  display:inline-flex !important;
  opacity:1 !important;
  visibility:visible !important;
  width:auto !important;
  max-width:100% !important;
}

html body:not(.sidebar-collapsed) .sidebar .navItem,
html body:not(.sidebar-collapsed) .sidebarFooter .navItem{
  grid-template-columns:auto minmax(0,1fr) auto !important;
}

html body .sidebarFooter{
  margin-top:8px !important;
  flex:0 0 auto !important;
}

html body .sidebar > div:first-child{
  flex:0 0 auto !important;
  min-height:auto !important;
}

@media (min-width:981px){
  html body .sidebar{
    position:sticky !important;
    top:0 !important;
    height:100vh !important;
    height:100dvh !important;
    max-height:100vh !important;
    max-height:100dvh !important;
    display:flex !important;
    flex-direction:column !important;
    justify-content:flex-start !important;
  }
}

@media (max-width:980px){
  html body.mobile-sidebar-open{
    overflow:hidden !important;
    touch-action:auto !important;
  }

  html body.mobile-sidebar-open .sidebar{
    overflow-y:auto !important;
    -webkit-overflow-scrolling:touch !important;
    touch-action:pan-y !important;
    overscroll-behavior:contain !important;
  }

  html body .sidebarFooter{
    margin-top:8px !important;
  }
}

html body.loginBody,
html body.loginBody.crmLoginBody{
  min-height:100vh !important;
  min-height:100dvh !important;
  height:auto !important;
  overflow-y:auto !important;
  overflow-x:hidden !important;
  -webkit-overflow-scrolling:touch !important;
  touch-action:pan-y !important;
  overscroll-behavior-y:auto !important;
}

@media (max-width:980px){
  html body.loginBody,
  html body.loginBody.crmLoginBody{
    display:block !important;
    align-items:unset !important;
    justify-content:unset !important;
    place-items:unset !important;
    padding:14px !important;
  }

  html body.loginBody .loginCardWide,
  html body.loginBody .loginCardPremium{
    width:100% !important;
    max-width:100% !important;
    margin:0 auto calc(18px + env(safe-area-inset-bottom)) !important;
    overflow:visible !important;
  }
}

/* Linhas antigas com cor individual: o tema do CRM prevalece sempre. */
html body[data-ui-theme] tr.rowThemeCustom > td,
html body[data-ui-theme] tr.rowSpecialGlow > td,
html body[data-ui-theme] tr[class*="rowTheme-"] > td{
  background-image:none !important;
  text-shadow:none !important;
}

html body[data-ui-theme] tr.rowThemeCustom:nth-child(odd) > td,
html body[data-ui-theme] tr.rowSpecialGlow:nth-child(odd) > td,
html body[data-ui-theme] tr[class*="rowTheme-"]:nth-child(odd) > td{
  background:var(--crm-table-row-odd, var(--row-odd-bg, rgba(255,255,255,.045))) !important;
  color:var(--crm-row-text, var(--row-odd-text, #f8fbff)) !important;
  box-shadow:var(--crm-table-cell-shadow, none) !important;
}

html body[data-ui-theme] tr.rowThemeCustom:nth-child(even) > td,
html body[data-ui-theme] tr.rowSpecialGlow:nth-child(even) > td,
html body[data-ui-theme] tr[class*="rowTheme-"]:nth-child(even) > td{
  background:var(--crm-table-row-even, var(--row-even-bg, rgba(224,248,255,.92))) !important;
  color:var(--crm-row-even-text, var(--row-even-text, #06111f)) !important;
  box-shadow:var(--crm-table-cell-shadow, none) !important;
}

html body[data-ui-theme] tr.rowThemeCustom > td *,
html body[data-ui-theme] tr.rowSpecialGlow > td *,
html body[data-ui-theme] tr[class*="rowTheme-"] > td *{
  color:inherit !important;
  text-shadow:none !important;
}

/* =========================================================
   CRM V1439 - Temas claros premium com mais contraste
   Os 4 temas claros continuam existindo, mas deixam de ser lavados.
   ========================================================= */
html body[data-ui-theme="light-tech"]{
  --bg-main:#dbeafe;--text-main:#f8fbff;--bg-card:#17263a;--text-card:#f8fbff;
  --accent-primary:#38bdf8;--text-accent:#06111f;--accent-status:#34d399;--text-status:#052e16;
  --border-color:#0ea5e9;--text-border:#f8fbff;--row-odd-bg:#132235;--row-odd-text:#f8fbff;--row-even-bg:#eef8ff;--row-even-text:#07111f;
  --bg:#dbeafe;--text:#f8fbff;--muted:#c8d9ea;--panel:#17263a;--panel-2:#102033;--panel-top:#1d314a;--panel-bottom:#0f1e2e;
  --metric-top:#1d314a;--metric-bottom:#102033;--sidebar-top:#102033;--sidebar-bottom:#07121f;--thead-bg:#38bdf8;--line:#0ea5e9;--primary:#38bdf8;--primary-2:#34d399;
  --success:#34d399;--warning:#facc15;--danger:#fb7185;--crm-row-odd:#132235;--crm-row-even:#eef8ff;--crm-row-text:#f8fbff;--crm-row-even-text:#07111f;--crm-table-head-text:#06111f;
  --crm-badge-neutral:#0f2b3a;--crm-badge-neutral-text:#e0f7ff;color-scheme:dark;
}
html body[data-ui-theme="light-luxury"]{
  --bg-main:#ead7b7;--text-main:#fff7ed;--bg-card:#2b2117;--text-card:#fff7ed;
  --accent-primary:#facc15;--text-accent:#16110a;--accent-status:#a3e635;--text-status:#16110a;
  --border-color:#d6a934;--text-border:#fff7ed;--row-odd-bg:#2a2118;--row-odd-text:#fff7ed;--row-even-bg:#fff3db;--row-even-text:#1f160d;
  --bg:#ead7b7;--text:#fff7ed;--muted:#ead6b9;--panel:#2b2117;--panel-2:#201811;--panel-top:#3a2d1f;--panel-bottom:#1f160d;
  --metric-top:#3a2d1f;--metric-bottom:#201811;--sidebar-top:#251c13;--sidebar-bottom:#120c08;--thead-bg:#facc15;--line:#d6a934;--primary:#facc15;--primary-2:#a3e635;
  --success:#a3e635;--warning:#facc15;--danger:#fb7185;--crm-row-odd:#2a2118;--crm-row-even:#fff3db;--crm-row-text:#fff7ed;--crm-row-even-text:#1f160d;--crm-table-head-text:#16110a;
  --crm-badge-neutral:#40311f;--crm-badge-neutral-text:#fff7ed;color-scheme:dark;
}
html body[data-ui-theme="light-urban"]{
  --bg-main:#d6dde6;--text-main:#f8fafc;--bg-card:#1f2937;--text-card:#f8fafc;
  --accent-primary:#fb923c;--text-accent:#111827;--accent-status:#2dd4bf;--text-status:#042f2e;
  --border-color:#60a5fa;--text-border:#f8fafc;--row-odd-bg:#1f2937;--row-odd-text:#f8fafc;--row-even-bg:#eef2f7;--row-even-text:#111827;
  --bg:#d6dde6;--text:#f8fafc;--muted:#d4dde8;--panel:#1f2937;--panel-2:#17202b;--panel-top:#293545;--panel-bottom:#151d27;
  --metric-top:#293545;--metric-bottom:#17202b;--sidebar-top:#1d2734;--sidebar-bottom:#0f1722;--thead-bg:#fb923c;--line:#60a5fa;--primary:#fb923c;--primary-2:#2dd4bf;
  --success:#2dd4bf;--warning:#fb923c;--danger:#fb7185;--crm-row-odd:#1f2937;--crm-row-even:#eef2f7;--crm-row-text:#f8fafc;--crm-row-even-text:#111827;--crm-table-head-text:#111827;
  --crm-badge-neutral:#2b3746;--crm-badge-neutral-text:#f8fafc;color-scheme:dark;
}
html body[data-ui-theme="light-clean"]{
  --bg-main:#e5e7eb;--text-main:#f8fafc;--bg-card:#231b32;--text-card:#f8fafc;
  --accent-primary:#a78bfa;--text-accent:#0f0b18;--accent-status:#bef264;--text-status:#111827;
  --border-color:#f0abfc;--text-border:#f8fafc;--row-odd-bg:#231b32;--row-odd-text:#f8fafc;--row-even-bg:#f6f2ff;--row-even-text:#171326;
  --bg:#e5e7eb;--text:#f8fafc;--muted:#d9ccf4;--panel:#231b32;--panel-2:#1a1427;--panel-top:#2e2344;--panel-bottom:#171326;
  --metric-top:#2e2344;--metric-bottom:#1a1427;--sidebar-top:#21182f;--sidebar-bottom:#110c1c;--thead-bg:#a78bfa;--line:#f0abfc;--primary:#a78bfa;--primary-2:#bef264;
  --success:#bef264;--warning:#f0abfc;--danger:#fb7185;--crm-row-odd:#231b32;--crm-row-even:#f6f2ff;--crm-row-text:#f8fafc;--crm-row-even-text:#171326;--crm-table-head-text:#0f0b18;
  --crm-badge-neutral:#33274a;--crm-badge-neutral-text:#f8fafc;color-scheme:dark;
}
html body[data-ui-theme^="light-"]{
  background:radial-gradient(circle at 12% -12%,color-mix(in srgb,var(--accent-primary) 32%,transparent),transparent 34%),radial-gradient(circle at 92% 2%,color-mix(in srgb,var(--accent-status) 24%,transparent),transparent 30%),linear-gradient(135deg,color-mix(in srgb,var(--bg-main) 78%,#000 22%),var(--bg-main) 52%,color-mix(in srgb,var(--bg-main) 78%,#000 22%)) !important;
}
html body[data-ui-theme^="light-"] .sidebar,
html body[data-ui-theme^="light-"] .panel,
html body[data-ui-theme^="light-"] .metricCard,
html body[data-ui-theme^="light-"] .metricBubbleCard,
html body[data-ui-theme^="light-"] .budgetCard,
html body[data-ui-theme^="light-"] .crmDialog,
html body[data-ui-theme^="light-"] .subPanel,
html body[data-ui-theme^="light-"] .costRowCard{
  color:var(--text-card) !important;
  box-shadow:0 22px 42px rgba(0,0,0,.26),inset 0 1px 0 rgba(255,255,255,.12) !important;
}
html body[data-ui-theme^="light-"] .navItem,
html body[data-ui-theme^="light-"] .navSubItem,
html body[data-ui-theme^="light-"] .btn,
html body[data-ui-theme^="light-"] .iconBtn,
html body[data-ui-theme^="light-"] .menuAction,
html body[data-ui-theme^="light-"] .tabButton{
  color:var(--text-card) !important;
  text-shadow:0 1px 1px rgba(0,0,0,.45) !important;
}
html body[data-ui-theme^="light-"] .navItem.active,
html body[data-ui-theme^="light-"] .navSubItem.active,
html body[data-ui-theme^="light-"] .btn.primary,
html body[data-ui-theme^="light-"] .tabButton.active{
  color:var(--text-accent) !important;
  text-shadow:none !important;
}
html body[data-ui-theme^="light-"] input,
html body[data-ui-theme^="light-"] select,
html body[data-ui-theme^="light-"] textarea{
  background:#fff !important;
  color:#07111f !important;
  border-color:color-mix(in srgb,var(--border-color) 78%,#000 22%) !important;
}
