/* ============================================================================
   Capi Când-IA Pro — App Shell (Fase 1)
   Layout do #chatScreen: sidebar fixa à esquerda + main area à direita.
   Mobile: sidebar como drawer com backdrop.
   ============================================================================ */

#chatScreen.ds-shell {
  display: grid;
  grid-template-columns: 256px 1fr;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--ds-bg);
  color: var(--ds-text);
  font-family: var(--ds-font-sans);
  position: relative;
}

#chatScreen.ds-shell.hidden { display: none }

/* ─── Sidebar ─── */
.ds-sidebar {
  background: var(--ds-bg);
  border-right: 1px solid var(--ds-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  height: 100vh;
  height: 100dvh;
  position: sticky;
  top: 0;
}

/* Header do sidebar (brand + hamburger) · 60px pra alinhar com topbar */
.ds-sidebar-header {
  padding: 14px 14px;
  min-height: 60px;
  height: 60px;
  box-sizing: border-box;
  border-bottom: 1px solid var(--ds-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.ds-sidebar-collapse {
  background: transparent;
  border: none;
  color: var(--ds-text-muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
  border-radius: 4px;
}

.ds-sidebar-collapse:hover {
  color: var(--ds-text);
  background: rgba(255,255,255,0.04);
}

.ds-sidebar-collapse svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
}

/* Hamburger no header da sidebar — visível em todas as resoluções (decorativo no desktop, funcional no mobile) */

/* Conteúdo principal do sidebar (scrollável) */
.ds-sidebar-body {
  flex: 1;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.ds-sidebar-spacer { flex: 1 }

/* ─── Sidebar bottom sections (Favoritos + Projetos) ─────────────────────
   Cap em altura + scroll interno, pra não comer espaço da lista de conversas.
   Quando colapsadas, only header é visível (chevron rotaciona).
   ──────────────────────────────────────────────────────────────────────── */
.ds-sidebar-body .fav-section,
.ds-sidebar-body .projects-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 32vh;
  flex-shrink: 0;
}

.ds-sidebar-body .fav-section[data-collapsed="1"],
.ds-sidebar-body .projects-section[data-collapsed="1"] {
  max-height: none;
  flex: 0 0 auto;
}

.ds-sidebar-body .fav-section[data-collapsed="1"] > #favList,
.ds-sidebar-body .projects-section[data-collapsed="1"] > #projectsList {
  display: none !important;
}

.ds-sidebar-body .fav-section > #favList,
.ds-sidebar-body .projects-section > #projectsList {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}

.ds-sidebar-body .fav-section > #favList::-webkit-scrollbar,
.ds-sidebar-body .projects-section > #projectsList::-webkit-scrollbar {
  width: 4px;
}
.ds-sidebar-body .fav-section > #favList::-webkit-scrollbar-thumb,
.ds-sidebar-body .projects-section > #projectsList::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
}

/* Header collapsible (chevron + label + count) — Favoritos & Projetos */
.ds-sidebar-body .fav-section-title,
.ds-sidebar-body .projects-header {
  flex-shrink: 0;
}

.ds-sidebar-body .fav-section .fav-chevron,
.ds-sidebar-body .projects-section .projects-header > svg:first-of-type {
  transition: transform 0.18s ease;
}

.ds-sidebar-body .fav-section[data-collapsed="1"] .fav-chevron,
.ds-sidebar-body .projects-section[data-collapsed="1"] .projects-header > svg:first-of-type {
  transform: rotate(0deg);
}

.ds-sidebar-body .fav-section:not([data-collapsed="1"]) .fav-chevron,
.ds-sidebar-body .projects-section:not([data-collapsed="1"]) .projects-header > svg:first-of-type {
  transform: rotate(90deg);
}

/* Footer (user info + menu) */
.ds-sidebar-footer {
  border-top: 1px solid var(--ds-border);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  flex-shrink: 0;
  background: var(--ds-bg);
}

.ds-sidebar-footer:hover {
  background: rgba(255,255,255,0.02);
}

.ds-sidebar-footer-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.ds-sidebar-footer-name {
  font-size: 12.5px;
  color: var(--ds-text);
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.ds-sidebar-footer-email {
  font-size: 10px;
  color: var(--ds-text-muted);
  font-family: var(--ds-font-mono);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.ds-sidebar-footer-menu {
  background: transparent;
  border: none;
  color: var(--ds-text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  position: relative;
}

.ds-sidebar-footer-menu:hover {
  color: var(--ds-text);
  background: rgba(255,255,255,0.06);
}

.ds-sidebar-footer-menu svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
}

/* Divider entre seções do sidebar */
.ds-sidebar-divider {
  height: 1px;
  background: var(--ds-border);
  margin: 10px 14px;
}

/* ─── Main area ─── */
.ds-shell-main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  overflow: hidden;
}

/* Topbar */
.ds-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--ds-border);
  background: var(--ds-bg);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.ds-topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ds-topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.ds-topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--ds-text-2);
}

.ds-topbar-status-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--ds-radius-full);
  background: var(--ds-success);
  box-shadow: 0 0 8px rgba(74,222,128,0.55);
}

/* Hamburger mobile (oculto no desktop) */
.ds-shell-hamburger {
  display: none;
  background: transparent;
  border: none;
  color: var(--ds-text-2);
  padding: 6px;
  border-radius: 6px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

.ds-shell-hamburger svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
}

/* ─── Mobile · drawer ─── */
.ds-shell-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  z-index: 90;
}

@media (max-width: 900px) {
  #chatScreen.ds-shell {
    grid-template-columns: 1fr;
  }

  .ds-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    height: 100vh;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    /* Acima do backdrop (z-index:9998) pra não bloquear toques no drawer */
    z-index: 10000;
    border-right: 1px solid var(--ds-border);
  }

  #chatScreen.ds-shell.is-sidebar-open .ds-sidebar {
    transform: translateX(0);
    box-shadow: 0 0 32px rgba(0,0,0,0.5);
  }

  #chatScreen.ds-shell.is-sidebar-open .ds-shell-backdrop {
    display: block;
  }

  .ds-shell-hamburger { display: inline-flex }
}

/* ───────── Conv items (lista de conversas) ──────────────────────────────────
   Estilo compartilhado entre /app (renderizado por loadConversations no
   index.html) e dashboards/outras páginas (renderizado por loadSidebarConvs
   em shell.js). Escopo `.ds-sidebar` aplica em ambos os hosts da sidebar.
   No /app existem regras paralelas em `#chatScreen.ds-shell` (shell-overrides
   e force-final) com `!important` que vencem em conflito — esperado. */
.ds-sidebar #convList {
  padding: 0;
}
.ds-sidebar .conv-item {
  padding: 6px 12px;
  margin: 0 10px 1px;
  border-radius: var(--ds-radius);
  background: transparent;
  border: none;
  border-left: 2px solid transparent;
  color: var(--ds-text-2);
  font-family: var(--ds-font-sans);
  font-size: var(--ds-text-base);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 0;
  transition: background 0.15s ease;
  position: relative;
  text-decoration: none;
}
.ds-sidebar .conv-item:hover {
  background: rgba(255,255,255,0.04);
  color: var(--ds-text);
}
.ds-sidebar .conv-item.active {
  background: var(--ds-gold-dim);
  border-left-color: var(--ds-gold);
  color: var(--ds-gold);
  padding-left: 10px;
}
.ds-sidebar .conv-item-text {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.ds-sidebar .conv-item-title {
  font-family: var(--ds-font-sans);
  font-size: var(--ds-text-base);
  font-weight: 500;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  flex: 1;
  min-width: 0;
  color: inherit;
}
.ds-sidebar .conv-item-date {
  font-family: var(--ds-font-mono);
  font-size: 10px;
  color: #555;
  margin-top: 0;
  flex-shrink: 0;
  letter-spacing: 0;
  transition: opacity 0.15s ease;
}
.ds-sidebar .conv-item:hover .conv-item-date {
  opacity: 0;
}
.ds-sidebar .conv-item.active .conv-item-date {
  color: #8a6810;
}
