/* ==========================================================================
   Dashboard Customizer (v0.7.8)
   Estilos isolados — não afeta o resto do app.
   ========================================================================== */

/* CSS para N colunas é gerado dinamicamente via injectGridCSS() no JS.   */
/* Isso contorna o bug do GridStack 10.x que gera width=0 para column>12. */

/* Botão "Personalizar" injetado no header do dashboard */
#dash-customize-btn {
  position: relative;
}
#dash-customize-btn.is-editing {
  background: rgb(37 99 235 / 0.15);
  color: rgb(37 99 235);
}
.dark #dash-customize-btn.is-editing {
  background: rgb(96 165 250 / 0.15);
  color: rgb(96 165 250);
}

/* ---------- Drawer lateral ---------- */
#dash-customizer-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 360px;
  max-width: 90vw;
  height: 100vh;
  z-index: 90;
  transform: translateX(100%);
  transition: transform 280ms ease;
  display: flex;
  flex-direction: column;
}
#dash-customizer-drawer.open {
  transform: translateX(0);
}
#dash-customizer-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.35);
  z-index: 89;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}
#dash-customizer-drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}
#dash-customizer-drawer .drawer-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgb(226 232 240 / 1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.dark #dash-customizer-drawer .drawer-header {
  border-bottom-color: rgb(51 65 85 / 1);
}
#dash-customizer-drawer .drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
}
#dash-customizer-drawer .drawer-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgb(226 232 240 / 1);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-shrink: 0;
}
.dark #dash-customizer-drawer .drawer-footer {
  border-top-color: rgb(51 65 85 / 1);
}

.dash-widget-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.5rem;
  border-radius: 0.5rem;
  cursor: pointer;
  user-select: none;
  transition: background 120ms ease;
}
.dash-widget-row:hover {
  background: rgb(241 245 249 / 1);
}
.dark .dash-widget-row:hover {
  background: rgb(30 41 59 / 0.5);
}
.dash-widget-row input[type='checkbox'] {
  width: 1rem;
  height: 1rem;
  accent-color: rgb(37 99 235);
  flex-shrink: 0;
}
.dash-widget-row span {
  font-size: 0.875rem;
  color: rgb(51 65 85);
}
.dark .dash-widget-row span {
  color: rgb(203 213 225);
}

/* ---------- Modo edição (Gridstack ativo) ---------- */
#dash-gridstack.grid-stack {
  background: transparent;
}
#dash-gridstack .grid-stack-item-content {
  display: flex;
  flex-direction: column;
  inset: 0;
  padding: 0;
  overflow: hidden;
}
#dash-gridstack .grid-stack-item-content {
  border-radius: 1rem;
  overflow: hidden;
}
#dash-gridstack .grid-stack-item-content > .glass-card {
  flex: 1;
  margin: 0 !important;
  height: 100%;
  overflow: auto;
}
/* handle de drag aparece só em modo edição */
#dash-gridstack.editing .grid-stack-item-content::before {
  content: '⋮⋮ arraste';
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
  background: rgb(37 99 235 / 0.9);
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 9999px;
  z-index: 10;
  cursor: move;
  pointer-events: none;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#dash-gridstack.editing .grid-stack-item {
  outline: 2px dashed rgb(37 99 235 / 0.6);
  outline-offset: -2px;
  border-radius: 1rem;
}
#dash-gridstack.editing .grid-stack-item:hover {
  outline-color: rgb(37 99 235);
}

/* Esconde handles de resize quando NÃO está em modo edição */
#dash-gridstack:not(.editing) .ui-resizable-handle {
  display: none !important;
}

/* Quando o grid está ativo, esconde o HTML original */
#page-dashboard[data-custom-layout='1'] > div > div.max-w-7xl.mx-auto.space-y-6 {
  display: none;
}

/* Mobile: nunca mostra grid custom nem drawer */
@media (max-width: 1023px) {
  #dash-customize-btn { display: none !important; }
  #dash-customizer-drawer,
  #dash-customizer-drawer-backdrop { display: none !important; }
  #page-dashboard[data-custom-layout='1'] > div > div.max-w-7xl.mx-auto.space-y-6 {
    display: block;
  }
  #dash-gridstack { display: none !important; }
}
