/* ============================================
   SIDEBAR COM POPOVER - Estilo Notion/Figma
   ============================================ */

:root {
  --sidebar-width: 56px;
  --popover-bg: #ffffff;
  --popover-border: #e5e7eb;
  --popover-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  --accent-color: #3b82f6;
}

/* Sidebar Minimalista */
.smart-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: #ffffff;
  border-right: 1px solid var(--popover-border);
  z-index: 1001;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 12px;
  gap: 6px;
  overflow: hidden;
  scrollbar-width: none;
}

.smart-sidebar-right {
  left: auto;
  right: 0;
  border-right: none;
  border-left: 1px solid var(--popover-border);
  justify-content: space-between;
  overflow: visible;
}

.smart-sidebar::-webkit-scrollbar,
.smart-sidebar-right::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* Seções da Sidebar */
.sidebar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 100%;
  padding: 4px 0;
}

.sidebar-divider {
  width: 32px;
  height: 1px;
  background: var(--popover-border);
  margin: 4px 0;
}

.sidebar-label {
  font-size: 9px;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
  white-space: nowrap;
}

/* Botões Padrão */
.sidebar-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #6b7280;
  font-size: 17px;
  transition: all 0.15s;
  position: relative;
}

.sidebar-btn:hover {
  background: #eef2f7;
  color: #374151;
}

.sidebar-btn:active {
  transform: scale(0.92);
}

.sidebar-btn.active {
  background: #eff6ff;
  color: var(--accent-color);
}

.sidebar-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.sidebar-btn-save {
  background: #eef2ff;
  color: #2563eb;
}

.sidebar-btn-save:hover {
  background: #dbeafe;
  color: #1d4ed8;
}

.sidebar-btn-save.dirty {
  background: #dcfce7;
  color: #15803d;
}

.sidebar-btn-save.saving {
  background: #fef3c7;
  color: #b45309;
}

#btn-export-pdf.saving {
  background: #fef3c7;
  color: #b45309;
}

#btn-export-png.saving {
  background: #fef3c7;
  color: #b45309;
}

/* Botão Principal (+) */
.sidebar-btn-primary {
  width: 38px;
  height: 38px;
  border: none;
  background: linear-gradient(180deg, #4f8df7, #2563eb);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: white;
  font-size: 16px;
  transition: all 0.15s;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
}

.sidebar-btn-primary:hover {
  background: linear-gradient(180deg, #3b82f6, #1d4ed8);
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.28);
}

.sidebar-btn-primary:active {
  transform: scale(0.95);
}

/* Elementos Fixos (Formas) */
.fixed-shapes {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.shape-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  transition: all 0.15s;
}

.shape-btn:hover {
  background: #f3f4f6;
}

.shape-btn:active {
  cursor: grabbing;
}

.shape-btn .shape-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none !important;
}

.shape-btn .shape-icon i,
.shape-btn .shape-icon svg {
  pointer-events: none !important;
  cursor: inherit !important;
}

/* Notas Fixas */
.fixed-notes {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.note-btn {
  width: 40px;
  height: 28px;
  border: 1px solid var(--popover-border);
  border-radius: 6px;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  position: relative;
}

.note-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.note-btn:active {
  cursor: grabbing;
}

.note-btn i {
  font-size: 14px;
  opacity: 0.5;
  pointer-events: none !important;
  cursor: inherit !important;
}

/* Recentes */
.recent-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.recent-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 20px;
}

.recent-btn:hover {
  background: #f3f4f6;
}

.recent-btn:empty::before {
  content: '•';
  color: #d1d5db;
  font-size: 24px;
}

/* Popover Menu */
.element-popover {
  position: fixed;
  left: 60px;
  background: var(--popover-bg);
  border: 1px solid var(--popover-border);
  border-radius: 12px;
  box-shadow: var(--popover-shadow);
  z-index: 1002;
  display: none;
  min-width: 320px;
  max-width: 400px;
  animation: popoverSlide 0.15s ease;
}

.element-popover.open {
  display: block;
}

@keyframes popoverSlide {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Header do Popover */
.popover-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--popover-border);
}

.popover-search {
  position: relative;
  display: flex;
  align-items: center;
}

.popover-search i {
  position: absolute;
  left: 10px;
  color: #9ca3af;
  font-size: 14px;
}

.popover-search input {
  width: 100%;
  padding: 8px 10px 8px 32px;
  border: 1px solid var(--popover-border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
}

.popover-search input:focus {
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Conteúdo do Popover */
.popover-content {
  max-height: 400px;
  overflow-y: auto;
  padding: 8px;
}

.popover-section {
  margin-bottom: 12px;
}

.popover-section-title {
  font-size: 11px;
  font-weight: 600;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 4px 8px;
  margin-bottom: 4px;
}

/* Grid de Elementos no Popover */
.popover-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.popover-item {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  border-radius: 6px;
  cursor: grab;
  transition: all 0.12s;
  border: 1px solid transparent;
  user-select: none;
}

.popover-item:hover {
  background: #f9fafb;
  border-color: #e5e7eb;
}

.popover-item:active {
  cursor: grabbing;
}

.popover-item i {
  font-size: 20px;
}

.popover-item span {
  font-size: 10px;
  text-align: center;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Footer do Popover */
.popover-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--popover-border);
  background: #f9fafb;
  border-radius: 0 0 12px 12px;
  font-size: 11px;
  color: #9ca3af;
  display: flex;
  justify-content: space-between;
}

.popover-footer kbd {
  background: white;
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid #d1d5db;
  font-size: 10px;
}

/* Tooltip nos botões */
.sidebar-btn[title]:hover::after,
.shape-btn[title]:hover::after,
.note-btn[title]:hover::after {
  content: attr(title);
  position: absolute;
  left: 100%;
  margin-left: 8px;
  padding: 4px 8px;
  background: #1f2937;
  color: white;
  font-size: 11px;
  border-radius: 4px;
  white-space: nowrap;
  z-index: 1003;
  pointer-events: none;
}

.smart-sidebar-right .sidebar-btn[title]:hover::after {
  left: auto;
  right: 100%;
  margin-left: 0;
  margin-right: 8px;
}

.sidebar-stack-top,
.sidebar-stack-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.sidebar-stack-top {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
}

.smart-sidebar-right .sidebar-stack-top {
  overflow: visible;
}

.sidebar-stack-top::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.sidebar-stack-bottom {
  flex: 0 0 auto;
}

.sidebar-export-group {
  position: relative;
  overflow: visible;
}

.sidebar-export-menu {
  position: absolute;
  top: 0;
  right: calc(100% + 10px);
  min-width: 92px;
  padding: 6px;
  border: 1px solid var(--popover-border);
  border-radius: 10px;
  background: #ffffff;
  box-shadow: var(--popover-shadow);
  display: none;
  flex-direction: column;
  gap: 4px;
  z-index: 1004;
}

.sidebar-export-menu.open {
  display: flex;
}

#pdf-export-menu {
  top: 0;
}

#png-export-menu {
  top: 0;
}

.sidebar-export-option {
  border: none;
  background: transparent;
  color: #374151;
  font-size: 12px;
  text-align: left;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.sidebar-export-option:hover {
  background: #eef2f7;
  color: #111827;
}

.sidebar-stack-top {
  padding-top: 2px;
}

.sidebar-stack-bottom {
  padding-bottom: 2px;
}

@media (max-height: 760px) {
  .sidebar-btn,
  .sidebar-btn-primary,
  .shape-btn,
  .recent-btn {
    width: 40px;
    height: 40px;
  }

  .note-btn {
    width: 40px;
    height: 28px;
  }

  .sidebar-divider {
    margin: 2px 0;
  }

  .sidebar-section {
    gap: 1px;
    padding: 2px 0;
  }

  .active-diagram-badge {
    display: none;
  }
}
