/* =========================================
   LAYOUTS — Sidebar slim, Topbar, App shell, Dashboard
   ========================================= */

/* ---- App shell ---- */
#app {
  display: flex;
  min-height: 100vh;
}

/* ====================================================================
   SIDEBAR — 220px expandida, icones SVG + label
   Adapta cor conforme tema (light/dark).
   ==================================================================== */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 50;
  padding: var(--space-4) 0;
  color: var(--text-primary);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  margin-bottom: var(--space-5);
  height: 32px;
  color: var(--logo-color);    /* verde no dark, preto no light */
  text-decoration: none;
  transition: opacity var(--transition);
}

.sidebar-logo:hover { opacity: 0.85; }

.sidebar-isotipo {
  display: block;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.sidebar-isotipo svg {
  width: 100%;
  height: 100%;
  display: block;
}

.sidebar-brand {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  color: var(--text-primary);
}

.sidebar-brand-name {
  font-size: var(--text-base);
  font-weight: var(--font-extra);
  letter-spacing: -0.02em;
}

.sidebar-brand-sub {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--logo-color);    /* verde no dark, preto no light */
  letter-spacing: 0.04em;
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 var(--space-2);
  gap: var(--space-5);
  overflow-y: auto;
  scrollbar-width: thin;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-spacer { flex: 1; min-height: var(--space-4); }

.nav-section-label {
  font-size: 0.65rem;
  font-weight: var(--font-bold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.10em;
  padding: var(--space-2) var(--space-3) var(--space-1);
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 8px var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-muted);
  color: var(--brand-green);
}

:root[data-theme="light"] .nav-item.active {
  /* Light: usa Deep Indigo (override de --accent feito em variables.css).
     bg indigo muted + texto e icone indigo. */
  background: var(--accent-muted);
  color: var(--accent);
  font-weight: var(--font-semibold);
}

:root[data-theme="light"] .nav-item.active .nav-icon { color: var(--accent); }

.nav-item.active .nav-icon { color: var(--brand-green); }

.nav-item .nav-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: currentColor;
}

.nav-item .nav-icon svg { display: block; }

.nav-item .nav-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item .nav-badge {
  background: var(--error);
  color: white;
  font-size: 0.6rem;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  font-weight: var(--font-bold);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
}

/* ====================================================================
   TOPBAR — grid 3 colunas iguais pra centralizar search de verdade
   ==================================================================== */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 var(--space-5);
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  z-index: 45;
  gap: var(--space-4);
}

.topbar-section {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.topbar-left { /* coluna esquerda intencionalmente vazia */ min-width: 0; }
.topbar-right { justify-content: flex-end; min-width: 0; gap: var(--space-2); }

/* Search central — coluna do meio, estilo Pipedrive (pill rounded). */
.topbar-search {
  width: 520px;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--bg-elevated);
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  padding: 0 14px;
  height: 38px;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
}

.topbar-search:hover {
  background: var(--bg-hover);
}

.topbar-search:focus-within,
.topbar-search.is-open {
  background: var(--bg-input);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.topbar-search-icon {
  color: var(--text-tertiary);
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.topbar-search:focus-within .topbar-search-icon,
.topbar-search.is-open .topbar-search-icon {
  color: var(--text-primary);
}

.topbar-search-icon svg { display: block; }

.topbar-search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: inherit;
  min-width: 0;
}

.topbar-search-input::placeholder { color: var(--text-tertiary); }
.topbar-search-input::-webkit-search-cancel-button { display: none; }

.topbar-search-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}
.topbar-search-clear:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}
.topbar-search-clear[hidden] { display: none; }

.topbar-search-hint {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-tertiary);
  background: var(--bg-surface);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-search-hint[hidden] { display: none; }

/* ====================================================================
   SEARCH DROPDOWN PANEL (Pipedrive-style: sidebar + results)
   ==================================================================== */
.topbar-search-panel {
  position: fixed;
  z-index: var(--z-dropdown);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: grid;
  grid-template-columns: 200px 1fr;
  max-height: min(560px, calc(100vh - 80px));
  overflow: hidden;
  animation: searchPanelIn 120ms ease;
}

@keyframes searchPanelIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.search-panel-sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: var(--space-2);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-cat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 8px var(--space-3);
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.search-cat:hover { background: var(--bg-hover); color: var(--text-primary); }
.search-cat.active {
  background: var(--bg-surface);
  color: var(--text-primary);
  font-weight: var(--font-semibold);
  box-shadow: var(--shadow-sm);
}
.search-cat-count {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  background: var(--bg-surface);
  padding: 0 6px;
  border-radius: var(--radius-full);
  font-variant-numeric: tabular-nums;
  min-width: 18px;
  text-align: center;
}
.search-cat.active .search-cat-count {
  background: var(--bg-elevated);
}

.search-panel-body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.search-panel-header {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border-subtle);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: var(--font-semibold);
  position: sticky;
  top: 0;
  background: var(--bg-surface);
  z-index: 1;
}

.search-panel-rows {
  padding: var(--space-1) 0;
}

.search-group-header {
  padding: var(--space-2) var(--space-4) 4px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  font-weight: var(--font-bold);
  margin-top: var(--space-2);
}
.search-group-header:first-child { margin-top: 0; }

.search-panel-empty,
.search-panel-loading {
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--text-tertiary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 220px;
}
.search-panel-empty-title {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}
.search-panel-empty-sub {
  font-size: var(--text-sm);
  max-width: 320px;
}

.search-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  padding: 10px var(--space-4);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: background var(--transition);
}
.search-row:last-child { border-bottom: none; }
.search-row:hover { background: var(--bg-hover); }

.search-row-main {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  flex: 1;
  flex-wrap: wrap;
}

.search-row-title {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.search-row-sub {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: var(--font-bold);
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.04em;
  font-family: var(--font-mono);
  white-space: nowrap;
  flex-shrink: 0;
}
.search-tag-contact  { background: rgba(124,0,255,0.15);  color: var(--brand-indigo); }
.search-tag-account  { background: rgba(107,114,128,0.18); color: #6B7280; }
.search-tag-lead     { background: var(--info-bg);        color: var(--info); }
.search-tag-activity { background: var(--warning-bg);     color: var(--warning); }

.search-badge {
  font-size: 10px;
  font-weight: var(--font-bold);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  letter-spacing: 0.05em;
  flex-shrink: 0;
  background: var(--bg-elevated);
  color: var(--text-secondary);
}
.search-badge-won     { background: var(--success-bg); color: var(--success); }
.search-badge-lost    { background: var(--error-bg);   color: var(--error); }
.search-badge-open    { background: var(--bg-elevated); color: var(--text-secondary); }
.search-badge-done    { background: var(--success-bg); color: var(--success); }
.search-badge-pending { background: var(--warning-bg); color: var(--warning); }
.search-badge-hot     { background: var(--hot-bg);  color: var(--hot); }
.search-badge-warm    { background: var(--warm-bg); color: var(--warm); }
.search-badge-cold    { background: var(--cold-bg); color: var(--cold); }

@media (max-width: 768px) {
  .topbar-search-panel { grid-template-columns: 1fr; }
  .search-panel-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }
  .search-cat { flex-shrink: 0; }
}

.topbar-icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  padding: 0;
}

.topbar-icon-btn svg { display: block; }

.topbar-icon-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.topbar-icon-btn [data-theme-icon] {
  display: inline-flex;
  align-items: center;
}

.user-menu-trigger {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px;
  border-radius: var(--radius-full);
  transition: transform var(--transition);
}

.user-menu-trigger:hover { transform: scale(1.05); }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--font-bold);
  font-size: var(--text-sm);
  flex-shrink: 0;
  letter-spacing: -0.02em;
}

.user-avatar-lg { width: 44px; height: 44px; font-size: var(--text-base); }

/* User dropdown (aparece pelo Topbar.toggleUserMenu) */
.user-dropdown {
  position: fixed;
  top: calc(var(--topbar-height) + 4px);
  right: var(--space-5);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-2);
  z-index: var(--z-dropdown);
  min-width: 240px;
  box-shadow: var(--shadow-lg);
  animation: dropdownIn 120ms ease;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.user-dropdown-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
}

.user-dropdown-info {
  flex: 1;
  min-width: 0;
}

.user-dropdown-name {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-dropdown-email {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: var(--space-2) 0;
}

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: var(--text-sm);
  border-radius: var(--radius-md);
  cursor: pointer;
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  transition: background var(--transition), color var(--transition);
}

.user-dropdown-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.user-dropdown-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  color: var(--text-tertiary);
}

.user-dropdown-icon svg { display: block; }

.user-dropdown-item:hover .user-dropdown-icon { color: var(--text-primary); }

/* ====================================================================
   MAIN
   ==================================================================== */
.main-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  /* min-width:0 e max-width:100% impedem que filhos flexbox/grid
     estourem o tamanho do wrapper e empurrem o body. */
  min-width: 0;
  max-width: calc(100vw - var(--sidebar-width));
  overflow-x: hidden;
}

.page-content {
  flex: 1;
  padding: var(--space-6);
  padding-top: calc(var(--topbar-height) + var(--space-6));
  animation: fadeIn var(--transition) forwards;
  /* Nada da pagina pode forcar o body a rolar horizontalmente. Quando uma
     tabela ou kanban-board crescem maior que o viewport, eles rolam em
     containers internos com overflow-x:auto. */
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
}

/* ---- Page header ---- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.page-header h1 {
  font-size: var(--text-2xl);
  font-weight: var(--font-extra);
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.page-header p {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--space-1);
  max-width: 60ch;
}

/* ---- Dashboard grid ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

/* ---- Filters bar ---- */
.filters-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

/* ====================================================================
   LOGIN
   ==================================================================== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  padding: var(--space-4);
}

.login-box {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
}

.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: var(--space-8);
  gap: var(--space-3);
}

.login-logo .logo-mark-lg {
  width: 64px;
  height: 64px;
  background: var(--accent);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: var(--font-bold);
  color: var(--accent-text);
  box-shadow: var(--shadow-accent);
}

.login-logo h1 {
  font-size: var(--text-2xl);
  font-weight: var(--font-extra);
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.login-logo p {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* ====================================================================
   RESPONSIVE
   ==================================================================== */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .main-wrapper {
    margin-left: 0 !important;
  }
  .topbar {
    left: 0 !important;
    padding: 0 var(--space-3);
  }
  .topbar-search { display: none; }
  .charts-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .page-content { padding: var(--space-4); padding-top: calc(var(--topbar-height) + var(--space-4)); }
}

/* ---- QR Code display ---- */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-6);
}

.qr-image {
  width: 220px;
  height: 220px;
  border: 4px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  padding: var(--space-2);
}

.qr-image img { width: 100%; }
