/* ============================================================
   PRIMETOUR — App CSS
   Main App Layout: Shell, Sidebar, Header, Content
   ============================================================ */

/* ─── APP SHELL ───────────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-dark);
  animation: fadeIn 0.3s ease;
}

/* ─── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-deepest);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--z-sidebar);
  transition: width var(--transition-normal), transform var(--transition-normal);
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

.sidebar-brand {
  /* Padding vertical 0 + horizontal var(--space-3) — libera espaço
   * MÁXIMO pra imagem dentro do container sem aumentar a área (min-height). */
  padding: 0 var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 124px;       /* área destinada permanece a mesma */
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
  overflow: hidden;
}
/* Logo customizado (img direta, sem brand-icon/brand-text) — preenche
 * praticamente toda a altura do container (124px) deixando apenas 4px
 * de respiro. max-width estreito (35px reservado pro toggle button)
 * pra logo poder expandir bem na largura. */
.sidebar-brand > img {
  height: auto;
  max-height: 120px;       /* basicamente preenche os 124px do container */
  max-width: calc(100% - 35px);
  object-fit: contain;
  flex: 1;
  min-width: 0;
}
.sidebar.collapsed .sidebar-brand > img {
  max-height: 75px;        /* colapsada: aumenta proporcionalmente */
  max-width: 100%;
}

.sidebar-brand::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: var(--space-4);
  right: var(--space-4);
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-accent), transparent);
}

.sidebar-brand-icon {
  width: 120px;            /* preenche o container (124px) */
  height: 120px;
  background: transparent;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}
.sidebar.collapsed .sidebar-brand-icon {
  width: 75px;
  height: 75px;
}
/* Inversão de tom: sidebar.js seta data-logo-tone="invert" no
 * .sidebar-brand quando o logo escolhido é claro mas a paleta é
 * clara (= ficaria invisível). O filter força o logo pra escuro.
 * Quando user upload uma versão dark explícita, NÃO inverte. */
.sidebar-brand[data-logo-tone="invert"] img {
  filter: brightness(0) saturate(0) invert(15%);
}

.sidebar-brand-text {
  overflow: hidden;
  transition: opacity var(--transition-fast), max-width var(--transition-normal);
  max-width: 200px;
  white-space: nowrap;
}

.sidebar.collapsed .sidebar-brand-text {
  opacity: 0;
  max-width: 0;
}

.sidebar-brand-name {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-primary);
  display: block;
}

.sidebar-brand-sub {
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* Sidebar Toggle Button */
.sidebar-toggle {
  position: absolute;
  right: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 0.75rem;
  z-index: 10;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.sidebar-toggle:hover {
  background: transparent;
  color: var(--text-inverse);
  border-color: var(--brand-gold);
}

.sidebar.collapsed .sidebar-toggle { transform: translateY(-50%) rotate(180deg); }

/* ─── SIDEBAR NAVIGATION ──────────────────────────────────── */
.sidebar-nav {
  flex: 1;
  padding: var(--space-4) var(--space-2);
  overflow-y: auto;
  overflow-x: hidden;
  /* Allow scroll when all accordions are open — footer stays fixed */
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border-subtle) transparent;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}

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

.sidebar-section {
  margin-bottom: var(--space-6);
}

.sidebar-section-label {
  font-size: 0.625rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 var(--space-3);
  margin-bottom: var(--space-2);
  white-space: nowrap;
  overflow: hidden;
  transition: opacity var(--transition-fast);
}

.sidebar.collapsed .sidebar-section-label {
  opacity: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  position: relative;
  margin-bottom: 2px;
  border: 1px solid transparent;
}

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

.nav-item.active {
  background: rgba(212,168,67,0.12);
  color: var(--brand-gold);
  border-color: rgba(212,168,67,0.20);
}

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

.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1rem;
  /* Ícones agora são SVG inline (Lucide-style). currentColor herda do
     .nav-item, então a cor segue o estado (default → hover → .active).
     Mantemos font-size pra fallback de Unicode ainda renderizar OK. */
  color: currentColor;
  transition: transform var(--transition-fast);
}
.nav-icon svg {
  width: 18px;
  height: 18px;
  display: block;
  /* Sem transform direto no SVG — o scale do hover roda no .nav-icon
     pai (já existente), evitando blur por sub-pixel. */
}

.nav-item:hover .nav-icon { transform: scale(1.1); }

.nav-label {
  transition: opacity var(--transition-fast), max-width var(--transition-normal);
  max-width: 200px;
  overflow: hidden;
}

.sidebar.collapsed .nav-label {
  opacity: 0;
  max-width: 0;
}

.nav-badge {
  margin-left: auto;
  background: transparent;
  color: var(--text-inverse);
  font-size: 0.625rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
  transition: opacity var(--transition-fast);
}

.sidebar.collapsed .nav-badge { opacity: 0; }

/* Tooltip on collapsed */
.sidebar.collapsed .nav-item {
  justify-content: center;
  position: relative;
}

.sidebar.collapsed .nav-item::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast);
  z-index: 100;
  box-shadow: var(--shadow-md);
}

.sidebar.collapsed .nav-item:hover::after {
  opacity: 1;
}

/* ─── SIDEBAR FOOTER ──────────────────────────────────────── */
.sidebar-footer {
  padding: var(--space-4) var(--space-2);
  border-top: 1px solid var(--border-subtle);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.sidebar-user:hover { background: var(--bg-hover); }

.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8125rem;
  font-weight: 600;
  flex-shrink: 0;
  color: white;
}

.sidebar-user-info {
  flex: 1;
  overflow: hidden;
  transition: opacity var(--transition-fast), max-width var(--transition-normal);
  max-width: 200px;
}

.sidebar.collapsed .sidebar-user-info {
  opacity: 0;
  max-width: 0;
}

.sidebar-user-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-role {
  font-size: 0.6875rem;
  color: var(--text-muted);
}

.sidebar-user-menu-btn {
  color: var(--text-muted);
  font-size: 0.875rem;
  background: none;
  border: none;
  padding: 0;
  transition: color var(--transition-fast), opacity var(--transition-fast);
}

.sidebar.collapsed .sidebar-user-menu-btn { opacity: 0; }
.sidebar-user:hover .sidebar-user-menu-btn { color: var(--text-primary); }

/* ─── MAIN CONTENT AREA ───────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: margin-left var(--transition-normal);
}

.sidebar.collapsed ~ .main-content {
  margin-left: var(--sidebar-collapsed-width);
}

/* ─── TOP HEADER ──────────────────────────────────────────── */
.app-header {
  height: 64px;
  min-height: 64px;
  flex-shrink: 0;
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.app-header-title {
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.app-header-breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.875rem;
  color: var(--text-muted);
  flex: 1;
}

.breadcrumb-sep { color: var(--border-default); }
.breadcrumb-current { color: var(--text-primary); font-weight: 500; }

/* Search Bar */
.header-search {
  position: relative;
  width: 280px;
}

.header-search-input {
  width: 100%;
  padding: 8px 14px 8px 38px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: all var(--transition-fast);
  outline: none;
}

.header-search-input::placeholder { color: var(--text-muted); }
.header-search-input:focus {
  border-color: var(--brand-gold);
  background: var(--bg-elevated);
  width: 320px;
}

.header-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.header-action-btn {
  width: 40px;
  height: 40px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.header-action-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-default);
}

.header-action-btn .notif-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background: transparent;
  border-radius: 50%;
  border: 2px solid var(--bg-dark);
}

/* ─── PAGE CONTENT ────────────────────────────────────────── */
.page-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-6);
  padding-bottom: 48px;
  animation: fadeIn 0.25s ease;
}

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

.page-header-left {}

.page-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.page-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
}

/* ─── WORKSPACE SELECTOR ─────────────────────────────────── */
.sidebar-ws-selector {
  flex-shrink: 0;
}

.ws-toggle-chip:hover {
  background: var(--bg-hover) !important;
  border-color: var(--border-subtle) !important;
}

.sidebar.collapsed .sidebar-ws-selector {
  display: none;
}

/* ─── MOBILE SIDEBAR OVERLAY ──────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 999;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.visible { display: block; }

/* ─── RESPONSIVE ──────────────────────────────────────────── */
@media (max-width: 1024px) {
  .header-search { width: 200px; }
  .header-search-input:focus { width: 240px; }
}

@media (max-width: 768px) {
  /* Mobile layout: body scrolls, not page-content */
  body {
    height: auto !important;
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sidebar {
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0 !important;
    overflow: visible;
    height: auto;
    min-height: 100vh;
    flex: none;
    width: 100%;
  }

  .app-header {
    position: sticky;
    top: 0;
    z-index: 90;
    padding: 0 var(--space-3);
    gap: var(--space-2);
  }

  .page-content {
    overflow: visible;
    padding: var(--space-4);
    padding-bottom: 80px;
  }

  .header-search { display: none; }

  #mobile-menu-btn { display: flex !important; }

  .page-header {
    flex-direction: column;
    gap: var(--space-3);
  }

  .page-header-actions {
    flex-wrap: wrap;
    width: 100%;
  }

  .page-title { font-size: 1.25rem; }
}

@media (max-width: 480px) {
  .page-content { padding: var(--space-3); }

  .page-header-actions .btn { font-size: 0.75rem; padding: 7px 12px; }

  .header-actions { gap: 4px; }
  .header-action-btn { width: 36px; height: 36px; }
}
