/* ============================================================================
   KOK Workspace — sidebar (sep-2026)
   Reemplaza visualmente el aside #mainSidebar. Se carga DESPUÉS de styles.css
   y cada regla cuelga de #mainSidebar.kok-workspace, así pisa por especificidad
   (ID) las reglas viejas de .sidebar / .nav-item sin tocarlas. Las reglas
   viejas siguen en styles.css porque este bloque hereda algunas (opacidad de
   labels al expandir, márgenes de .main-content, media queries de celular).
   Origen: fragmento KOKWorkspaceSidebar.html; test: tests/frontend/sidebar-workspace.test.js
   ============================================================================ */
/* Load after the existing sidebar CSS. Every rule is limited to this aside. */
#mainSidebar.kok-workspace {
  --kws-text: rgba(255,255,255,.76);
  --kws-muted: rgba(255,255,255,.6);
  --kws-line: rgba(255,255,255,.10);
  position: fixed; inset: 0 auto 0 0; z-index: 100;
  display: flex; flex-direction: column; width: 70px;
  height: 100vh; height: 100dvh; padding: 0; overflow: hidden;
  background: linear-gradient(180deg,var(--kok-navy,#1b3a5f) 0%,#142d4a 100%);
  color: var(--kws-text);
  font-family: var(--font-body,ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif);
  font-size: 13px; line-height: 1.4;
  transition: width .25s ease;
}
#mainSidebar.kok-workspace.expanded { width: 260px; overflow: hidden; }
#mainSidebar.kok-workspace * { box-sizing: border-box; }
#mainSidebar.kok-workspace button { font: inherit; cursor: pointer; }
#mainSidebar.kok-workspace a { cursor: pointer; }
#mainSidebar.kok-workspace :is(a,button,summary):focus-visible { outline: 2px solid #b9e4dc; outline-offset: -2px; }
#mainSidebar.kok-workspace svg { display: block; flex: 0 0 auto; }
#mainSidebar.kok-workspace .kws-header { display: flex; align-items: center; min-height: 54px; padding: 9px 13px; flex: 0 0 auto; }
#mainSidebar.kok-workspace .kws-title { font-size: 12px; font-weight: 650; letter-spacing: .7px; color: var(--kws-muted); }
#mainSidebar.kok-workspace .sidebar-toggle { width: 32px; height: 32px; min-width: 32px; padding: 6px; margin: 0 0 0 auto; color: var(--kws-text); background: transparent; border: 0; border-radius: 8px; }
#mainSidebar.kok-workspace .sidebar-toggle:hover { background: rgba(255,255,255,.08); color: #fff; }
#mainSidebar.kok-workspace .sidebar-toggle svg { width: 20px; height: 20px; transition: transform .25s ease; }
#mainSidebar.kok-workspace.expanded .sidebar-toggle svg { transform: rotate(180deg); }
#mainSidebar.kok-workspace .sidebar-cta { flex: 0 0 auto; padding: 0 12px 14px; margin: 0; }
#mainSidebar.kok-workspace .new-lead-btn { display: flex; min-height: 48px; padding: 8px 10px; justify-content: flex-start; gap: 11px; border-radius: 10px; background: linear-gradient(135deg,#10b981,#059669); color: #fff; text-decoration: none; box-shadow: inset 0 1px 0 rgba(255,255,255,.3),0 5px 12px rgba(5,21,37,.26); transition: transform .16s ease,filter .16s ease; }
#mainSidebar.kok-workspace .new-lead-btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
#mainSidebar.kok-workspace .new-lead-btn-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 7px; flex: 0 0 30px; background: rgba(255,255,255,.23); box-shadow: inset 0 1px 0 rgba(255,255,255,.25); }
#mainSidebar.kok-workspace .new-lead-btn-icon svg { width: 20px; height: 20px; color: #fff; }
#mainSidebar.kok-workspace .new-lead-btn-text { display: flex; flex-direction: column; min-width: 0; }
#mainSidebar.kok-workspace .new-lead-btn-title { color: #fff; font-size: 13px; font-weight: 700; }
#mainSidebar.kok-workspace .new-lead-btn-subtitle { color: rgba(255,255,255,.85); font-size: 10px; line-height: 1.4; }

/* All navigation scrolls together; .nav-section retains its Sales-only role. */
#mainSidebar.kok-workspace .kws-scroll { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; padding: 0 10px 15px; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.25) transparent; }
#mainSidebar.kok-workspace .kws-scroll::-webkit-scrollbar { width: 6px; }
#mainSidebar.kok-workspace .kws-scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,.22); border-radius: 4px; }
#mainSidebar.kok-workspace .nav-section { flex: 0 0 auto; padding: 0; margin: 0; overflow: visible; }
/* El orden visual ES el orden del DOM: Tab y lectores de pantalla lo siguen.
   Son tres bloques .sidebar-personal hermanos (My Work, Reports/Contacts,
   Administration); el login los oculta con querySelectorAll. Un inline
   display:none de la lógica de roles siempre gana sobre estas reglas. */
#mainSidebar.kok-workspace .sidebar-personal,
#mainSidebar.kok-workspace .sidebar-modules { display: block; flex: 0 0 auto; padding: 0; margin: 0; border: 0; }
#mainSidebar.kok-workspace .kws-work { padding-bottom: 10px; margin-bottom: 9px; border-bottom: 1px solid var(--kws-line); }
#mainSidebar.kok-workspace .kws-shared { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--kws-line); }
#mainSidebar.kok-workspace #loansNavItem { flex: 0 0 auto; }
#mainSidebar.kok-workspace .sidebar-section { flex: 0 0 auto; margin-top: 4px; }
#mainSidebar.kok-workspace .nav-label { color: var(--kws-muted); font-size: 11px; font-weight: 600; line-height: 1.4; text-transform: uppercase; letter-spacing: 1px; padding: 12px 10px 8px; margin: 0; }
#mainSidebar.kok-workspace .nav-item { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 10px 10px; margin: 2px 0; border: 0; border-radius: 9px; background: transparent; color: var(--kws-text); font-size: 13px; font-weight: 500; line-height: 1.4; text-decoration: none; transition: color .16s ease,background .16s ease,box-shadow .16s ease; }
#mainSidebar.kok-workspace .nav-item:hover { color: #fff; background: rgba(255,255,255,.07); }
#mainSidebar.kok-workspace .nav-item > svg { width: 17px; height: 17px; transition: transform .16s ease; }
#mainSidebar.kok-workspace .nav-item:hover > svg:not(.kws-chevron) { transform: translateX(1px); }
#mainSidebar.kok-workspace .nav-item > .kws-item-label { flex: 1; min-width: 0; }
#mainSidebar.kok-workspace.expanded .nav-item span { opacity: 1; visibility: visible; }
#mainSidebar.kok-workspace .nav-item .kws-item-label { white-space: normal; }
#mainSidebar.kok-workspace .nav-item.active { color: #fff; background: linear-gradient(135deg,var(--kok-teal,#3b9b8e),var(--kok-teal-dark,#2d7a6f)); box-shadow: inset 0 1px 0 rgba(255,255,255,.22),0 4px 8px rgba(5,21,37,.18); font-weight: 650; }
#mainSidebar.kok-workspace .kws-module-toggle { min-height: 54px; gap: 11px; padding: 9px 8px; margin: 2px 0; }
#mainSidebar.kok-workspace .kws-module-icon { display: flex; align-items: center; justify-content: center; flex: 0 0 32px; width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(145deg,rgba(255,255,255,.09),rgba(255,255,255,.025)); border: 1px solid rgba(255,255,255,.1); box-shadow: inset 0 1px 0 rgba(255,255,255,.07),0 3px 6px rgba(5,21,37,.16); opacity: 1; visibility: visible; transition: transform .16s ease,border-color .16s ease; }
#mainSidebar.kok-workspace .kws-module-icon svg { width: 18px; height: 18px; color: inherit; }
#mainSidebar.kok-workspace .kws-module-toggle:hover .kws-module-icon { transform: translateY(-1px); border-color: rgba(255,255,255,.25); }
#mainSidebar.kok-workspace .kws-parent-active { color: #fff; background: rgba(255,255,255,.035); }
#mainSidebar.kok-workspace .kws-parent-active .kws-module-icon { color: #fff; background: linear-gradient(135deg,var(--kok-teal,#3b9b8e),var(--kok-teal-dark,#2d7a6f)); border-color: rgba(255,255,255,.2); box-shadow: inset 0 1px 0 rgba(255,255,255,.22),0 3px 8px rgba(5,21,37,.2); }
#mainSidebar.kok-workspace .kws-module-copy { min-width: 0; flex: 1; display: flex; flex-direction: column; white-space: normal; }
#mainSidebar.kok-workspace .kws-module-copy > span { white-space: normal; }
#mainSidebar.kok-workspace .kws-module-caption { display: none; color: var(--kws-muted); font-size: 11px; font-weight: 400; line-height: 1.35; margin-top: 3px; }
#mainSidebar.kok-workspace.expanded .kws-module-toggle[aria-expanded="true"] .kws-module-caption { display: block; }
#mainSidebar.kok-workspace .nav-item > .kws-chevron { width: 14px; height: 14px; margin-left: auto; color: var(--kws-muted); transition: transform .18s ease; }
#mainSidebar.kok-workspace [data-kws-toggle="sales"][aria-expanded="true"] > .kws-chevron,
#mainSidebar.kok-workspace [data-kws-toggle="admin"][aria-expanded="true"] > .kws-chevron { transform: rotate(180deg); }
#mainSidebar.kok-workspace [data-kws-panel] { padding: 2px 0 5px 10px; margin: 0 0 7px 24px; border-left: 1px solid rgba(255,255,255,.12); }
#mainSidebar.kok-workspace [data-kws-panel] .nav-item { padding: 9px 8px; }
#mainSidebar.kok-workspace .nav-badge { flex: 0 0 auto; margin-left: auto; padding: 1px 6px; min-width: 21px; border-radius: 6px; color: #fff; background: #3b5573; font-size: 11px; line-height: 18px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; box-shadow: inset 0 1px 0 rgba(255,255,255,.12); }
#mainSidebar.kok-workspace :is(.nav-badge-blue,.nav-badge-purple,#mentionsBadge) { background: #2b5f8e; }
#mainSidebar.kok-workspace #cleanupBadge { background: #ef4444; }

#mainSidebar.kok-workspace .kws-footer { position: relative; flex: 0 0 auto; padding: 7px 10px 10px; border-top: 1px solid var(--kws-line); background: rgba(0,0,0,.035); }
#mainSidebar.kok-workspace .kws-preferences { margin: 0 0 3px; }
#mainSidebar.kok-workspace .kws-preferences > summary { list-style: none; display: flex; align-items: center; gap: 9px; min-height: 36px; padding: 8px 10px; border-radius: 8px; font-size: 12px; cursor: pointer; color: var(--kws-text); }
#mainSidebar.kok-workspace .kws-preferences > summary::-webkit-details-marker { display: none; }
#mainSidebar.kok-workspace .kws-preferences > summary:hover { background: rgba(255,255,255,.07); color: #fff; }
#mainSidebar.kok-workspace .kws-preferences > summary svg { width: 16px; height: 16px; }
#mainSidebar.kok-workspace .kws-preferences-panel { position: absolute; left: 10px; right: 10px; bottom: 100%; margin-bottom: 7px; padding: 7px; border: 1px solid var(--kws-line); border-radius: 11px; background: var(--kok-navy,#1b3a5f); box-shadow: 0 10px 28px rgba(5,21,37,.4); z-index: 2; }
#mainSidebar.kok-workspace .dark-mode-toggle-wrap,
#mainSidebar.kok-workspace .app-mode-toggle-wrap { padding: 2px; }
#mainSidebar.kok-workspace .dark-mode-toggle,
#mainSidebar.kok-workspace .app-mode-toggle { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 10px; border: 0; border-radius: 7px; background: transparent; color: var(--kws-text); font-size: 12px; }
#mainSidebar.kok-workspace :is(.dark-mode-toggle,.app-mode-toggle):hover { color: #fff; background: rgba(255,255,255,.07); }
#mainSidebar.kok-workspace :is(.dark-mode-toggle,.app-mode-toggle) span { opacity: 1; visibility: visible; }
#mainSidebar.kok-workspace :is(.dark-mode-toggle,.app-mode-toggle) svg { width: 17px; height: 17px; }
#mainSidebar.kok-workspace .dm-icon-moon { display: none; }
#mainSidebar.kok-workspace .dm-icon-sun { display: block; }
#mainSidebar.kok-workspace:is(.dark-mode,.dark-mode *) .dm-icon-sun { display: none; }
#mainSidebar.kok-workspace:is(.dark-mode,.dark-mode *) .dm-icon-moon { display: block; }
#mainSidebar.kok-workspace:is(.app-mode,.app-mode *) .app-mode-toggle-wrap { display: none !important; }
#mainSidebar.kok-workspace .user-section-top { display: flex; align-items: center; gap: 9px; padding: 10px 4px 2px; margin: 0; border: 0; flex-shrink: 0; }
#mainSidebar.kok-workspace .user-section-top .user-avatar { display: grid; place-items: center; width: 36px; height: 36px; flex: 0 0 36px; border-radius: 11px; background: linear-gradient(135deg,var(--kok-teal,#3b9b8e),#2d7a6f 50%,var(--kok-navy,#1b3a5f)); color: #fff; border: 1px solid rgba(255,255,255,.2); box-shadow: inset 0 1px 0 rgba(255,255,255,.15); font-size: 12px; font-weight: 700; letter-spacing: .3px; }
#mainSidebar.kok-workspace .user-info { min-width: 0; flex: 1; }
#mainSidebar.kok-workspace .user-name { color: #fff; font-size: 12px; font-weight: 650; }
#mainSidebar.kok-workspace .user-email { color: var(--kws-muted); margin-top: 2px; font-size: 11px; }
#mainSidebar.kok-workspace :is(.user-name,.user-email) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#mainSidebar.kok-workspace .logout-btn { display: flex; align-items: center; justify-content: center; flex: 0 0 28px; width: 28px; height: 30px; padding: 5px; margin: 0; background: transparent; border: 0; border-radius: 7px; color: var(--kws-muted); opacity: 1; visibility: visible; }
#mainSidebar.kok-workspace .logout-btn:hover { color: #ef4444; background: rgba(239,68,68,.12); }
#mainSidebar.kok-workspace .logout-btn svg { width: 16px; height: 16px; }

/* The surrounding CRM still reserves exactly 70px / 260px. */
#mainSidebar.kok-workspace:not(.expanded) .kws-title,
#mainSidebar.kok-workspace:not(.expanded) .nav-label,
#mainSidebar.kok-workspace:not(.expanded) .nav-item .kws-item-label,
#mainSidebar.kok-workspace:not(.expanded) .kws-module-copy,
#mainSidebar.kok-workspace:not(.expanded) .kws-chevron,
#mainSidebar.kok-workspace:not(.expanded) .new-lead-btn-text,
#mainSidebar.kok-workspace:not(.expanded) .user-info,
#mainSidebar.kok-workspace:not(.expanded) .logout-btn,
#mainSidebar.kok-workspace:not(.expanded) .kws-preferences > summary span { display: none; }
/* !important a propósito: updateMentionsBadge() (tools-modules.js) pone
   badge.style.display='flex' inline con menciones sin leer; sin esto el badge
   queda invisible pero ocupando ancho y corre el ícono de la @ (7-sep-2026). */
#mainSidebar.kok-workspace:not(.expanded) .nav-badge { display: none !important; }
#mainSidebar.kok-workspace:not(.expanded) .kws-header { justify-content: center; padding: 9px 8px; }
#mainSidebar.kok-workspace:not(.expanded) .sidebar-toggle { margin: 0; }
#mainSidebar.kok-workspace:not(.expanded) .kws-scroll { padding-left: 7px; padding-right: 7px; }
#mainSidebar.kok-workspace:not(.expanded) .nav-item { justify-content: center; padding: 10px 4px; }
#mainSidebar.kok-workspace:not(.expanded) .kws-module-icon { display: flex; opacity: 1; visibility: visible; }
#mainSidebar.kok-workspace:not(.expanded) [data-kws-panel] { margin-left: 0; padding-left: 0; border-left: 0; }
#mainSidebar.kok-workspace:not(.expanded) .sidebar-cta { padding: 0 8px 12px; }
#mainSidebar.kok-workspace:not(.expanded) .new-lead-btn { justify-content: center; padding: 7px 5px; }
#mainSidebar.kok-workspace:not(.expanded) .kws-footer { padding-left: 7px; padding-right: 7px; }
#mainSidebar.kok-workspace:not(.expanded) .user-section-top { justify-content: center; padding: 8px 0 2px; }
#mainSidebar.kok-workspace:not(.expanded) .kws-preferences > summary { justify-content: center; padding: 8px; }
#mainSidebar.kok-workspace:not(.expanded) .kws-preferences-panel { left: 3px; right: 3px; padding: 2px; }
#mainSidebar.kok-workspace:not(.expanded) .kws-preferences-panel :is(.dark-mode-toggle,.app-mode-toggle) { justify-content: center; padding: 9px 3px; }
#mainSidebar.kok-workspace:not(.expanded) .kws-preferences-panel :is(.dark-mode-toggle,.app-mode-toggle) span { display: none; }
@media(max-width:768px) { #mainSidebar.kok-workspace .app-mode-toggle-wrap { display: none; } }
@media(max-width:480px) { #mainSidebar.kok-workspace { display: none !important; } }
@media(prefers-reduced-motion:reduce) {
  #mainSidebar.kok-workspace,
  #mainSidebar.kok-workspace *,
  #mainSidebar.kok-workspace *::before,
  #mainSidebar.kok-workspace *::after { transition: none !important; animation: none !important; }
}
