/**
 * CRM JURÍDICO PANAMÁ - SISTEMA DE DISEÑO (FASE 2)
 * layout.css: Shell de Aplicación, Sidebar Colapsable, Topbar Persistente y Responsive Drawer
 */

/* Shell Principal del CRM */
.app-shell {
  display: flex;
  min-height: 100vh;
  background-color: var(--bg-canvas);
  position: relative;
}

/* ==========================================================================
   SIDEBAR IZQUIERDO (COLAPSABLE CON PERSISTENCIA EN LOCALSTORAGE)
   ========================================================================== */
.app-sidebar {
  width: 240px;
  background-color: #14191e;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: width var(--transition-normal);
  overflow-y: auto;
  overflow-x: hidden;
}

/* Estado Colapsado en Desktop */
.app-shell.sidebar-collapsed .app-sidebar {
  width: 64px;
}

.app-sidebar-header {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  text-decoration: none;
  overflow: hidden;
  white-space: nowrap;
}

.brand-icon-box {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.1);
  color: #efece4;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.brand-text-wrap {
  display: flex;
  flex-direction: column;
  transition: opacity var(--transition-fast);
}

.brand-name {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.05rem;
  color: #f7f6f2;
  letter-spacing: -0.01em;
}

.brand-tag {
  font-size: 0.68rem;
  color: #8d98a5;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.app-shell.sidebar-collapsed .brand-text-wrap {
  display: none;
}

/* Navegación del Sidebar */
.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sidebar-section-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64707d;
  padding: 14px 10px 4px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-shell.sidebar-collapsed .sidebar-section-title {
  display: none;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: #c2bbb0;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--transition-fast), color var(--transition-fast);
  white-space: nowrap;
  position: relative;
  user-select: none;
}

.sidebar-nav-item:hover {
  background-color: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  text-decoration: none;
}

.sidebar-nav-item.active {
  background-color: #1b365d;
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
}

.sidebar-nav-item.active {
  background-color: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.sidebar-nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  background-color: var(--primary);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
}

.sidebar-nav-icon {
  font-size: 16px;
  min-width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.app-shell.sidebar-collapsed .sidebar-nav-label {
  display: none;
}

.sidebar-nav-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  background: var(--neutral-badge-bg);
  color: var(--neutral-badge-text);
}

.app-shell.sidebar-collapsed .sidebar-nav-badge {
  display: none;
}

/* Pie del Sidebar */
.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-toggle-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar-toggle-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.app-shell.sidebar-collapsed .sidebar-toggle-btn {
  width: 100%;
}

.sidebar-study-info {
  font-size: 0.75rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell.sidebar-collapsed .sidebar-study-info {
  display: none;
}

/* ==========================================================================
   ÁREA DE CONTENIDO Y TOPBAR PERSISTENTE
   ========================================================================== */
.app-main-viewport {
  flex: 1;
  margin-left: 240px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
  transition: margin-left var(--transition-normal);
}

.app-shell.sidebar-collapsed .app-main-viewport {
  margin-left: 64px;
}

/* Topbar Minimalista */
.app-topbar {
  height: 56px;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 90;
}

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

.mobile-menu-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  color: var(--text-secondary);
  cursor: pointer;
}

/* Breadcrumbs y Título Dinámico */
.topbar-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.breadcrumb-root {
  color: var(--text-muted);
  font-weight: 500;
}

.breadcrumb-separator {
  color: var(--text-subtle);
  font-size: 0.75rem;
}

.breadcrumb-current {
  color: var(--text-primary);
  font-weight: 600;
}

/* Topbar Controles Derechos */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Botón Buscador Rápido Ctrl+K Estilo Linear */
.topbar-search-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.topbar-search-trigger:hover {
  border-color: var(--border-strong);
  color: var(--text-secondary);
  background: var(--bg-surface);
}

.topbar-search-trigger kbd {
  font-size: 0.7rem;
  padding: 1px 5px;
}

/* Widget Discreto de Almacenamiento */
.topbar-storage-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.topbar-storage-pill:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.storage-progress-bar-wrap {
  width: 48px;
  height: 4px;
  background: var(--border-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.storage-progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
}

/* Menú Rápido + Nuevo */
.quick-create-dropdown {
  position: relative;
}

/* Perfil de Usuario y Selector de Rol Demo */
.topbar-user-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 8px;
  border-left: 1px solid var(--border-subtle);
  cursor: pointer;
  position: relative;
}

.user-avatar-circle {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-subtle);
}

.user-meta-info {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.user-meta-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

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

/* Contenido Principal de las Pestañas */
.app-content-body {
  flex: 1;
  padding: 24px 28px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* ==========================================================================
   DRAWER MÓVIL Y RESPONSIVE
   ========================================================================== */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(2px);
  z-index: 95;
}

@media (max-width: 900px) {
  .app-sidebar {
    transform: translateX(-100%);
    width: 250px !important;
    box-shadow: var(--shadow-lg);
  }

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

  .app-shell.mobile-drawer-open .sidebar-backdrop {
    display: block;
  }

  .app-main-viewport {
    margin-left: 0 !important;
  }

  .mobile-menu-btn {
    display: inline-flex;
  }

  .app-content-body {
    padding: 16px;
  }

  .topbar-search-trigger .search-label-text,
  .topbar-search-trigger kbd {
    display: none;
  }

  .user-meta-info {
    display: none;
  }
}

