/* ============================================================
   TRAVELDESK — Layout principal
   Sidebar, header, contenido, panel derecho
   ============================================================ */

/* ============================================================
   ESTRUCTURA GLOBAL
   ============================================================ */

.app-wrapper {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--td-primary);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition-slow);
  position: relative;
  z-index: var(--z-sidebar);
  flex-shrink: 0;
}

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

/* Logo y marca */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4);
  border-bottom: 1px solid rgb(255 255 255 / 0.1);
  height: var(--header-height);
  flex-shrink: 0;
}

.sidebar-brand .brand-logo {
  width: 32px;
  height: 32px;
  background: var(--td-accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.9rem;
  color: white;
  flex-shrink: 0;
  letter-spacing: -0.02em;
}

.sidebar-brand .brand-text {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-brand .brand-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: white;
  white-space: nowrap;
  line-height: 1.2;
}

.sidebar-brand .brand-tagline {
  font-size: 0.65rem;
  color: rgb(255 255 255 / 0.5);
  white-space: nowrap;
}

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

/* Info de agencia */
.sidebar-agency {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid rgb(255 255 255 / 0.08);
  flex-shrink: 0;
}

.agency-info {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.agency-logo {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: rgb(255 255 255 / 0.15);
  border: 1px solid rgb(255 255 255 / 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.agency-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.agency-logo .agency-initials {
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
}

.agency-details {
  flex: 1;
  overflow: hidden;
}

.agency-name {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: white;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.agency-plan {
  font-size: var(--font-size-xs);
  color: var(--td-accent-light);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.sidebar.collapsed .agency-details { display: none; }

/* Navegación */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-2) 0;
  scrollbar-width: thin;
  scrollbar-color: rgb(255 255 255 / 0.1) transparent;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgb(255 255 255 / 0.15); border-radius: 4px; }

/* Grupos del menú */
.nav-group {
  margin-bottom: var(--space-1);
}

.nav-group-label {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgb(255 255 255 / 0.35);
  padding: var(--space-3) var(--space-4) var(--space-1);
  white-space: nowrap;
  overflow: hidden;
}

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

/* Items del menú */
.nav-item {
  position: relative;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.45rem var(--space-4);
  color: rgb(255 255 255 / 0.7);
  font-size: var(--font-size-sm);
  font-weight: 400;
  cursor: pointer;
  transition: all var(--transition-fast);
  border-radius: 0;
  white-space: nowrap;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  text-decoration: none;
}

.nav-link:hover {
  color: white;
  background: rgb(255 255 255 / 0.08);
}

.nav-link.active {
  color: white;
  background: rgb(255 255 255 / 0.14);
  font-weight: 500;
}

.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--td-accent);
  border-radius: 0 2px 2px 0;
}

.nav-link .nav-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.9rem;
  opacity: 0.85;
}

.nav-link.active .nav-icon { opacity: 1; }

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

.sidebar.collapsed .nav-label { display: none; }
.sidebar.collapsed .nav-group-label { padding: var(--space-3) 0 var(--space-1); text-align: center; }

/* Badge de count en menú */
.nav-badge {
  background: var(--td-accent);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

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

/* Submenú (grupos colapsables) */
.nav-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4) var(--space-2);
  cursor: pointer;
  color: rgb(255 255 255 / 0.5);
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border: none;
  background: none;
  width: 100%;
  transition: color var(--transition-fast);
}

.nav-group-toggle:hover { color: rgb(255 255 255 / 0.8); }

.nav-group-toggle .toggle-arrow {
  font-size: 0.7rem;
  transition: transform var(--transition);
}

.nav-group-toggle.open .toggle-arrow {
  transform: rotate(180deg);
}

.nav-subitems {
  overflow: hidden;
  max-height: 0;
  transition: max-height var(--transition-slow);
}

.nav-subitems.open {
  max-height: 500px;
}

/* Parte inferior del sidebar */
.sidebar-bottom {
  border-top: 1px solid rgb(255 255 255 / 0.1);
  padding: var(--space-3) var(--space-4);
  flex-shrink: 0;
}

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

.user-menu:hover { background: rgb(255 255 255 / 0.08); }

.user-info {
  flex: 1;
  overflow: hidden;
}

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

.user-role {
  font-size: var(--font-size-xs);
  color: rgb(255 255 255 / 0.5);
}

.sidebar.collapsed .user-info { display: none; }
.sidebar.collapsed .user-menu { justify-content: center; }

/* Toggle collapse */
.sidebar-toggle {
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  background: white;
  border: 1px solid var(--td-gray-200);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--td-gray-500);
  font-size: 0.7rem;
  box-shadow: var(--shadow);
  transition: all var(--transition);
  z-index: 10;
}

.sidebar-toggle:hover { color: var(--td-primary); border-color: var(--td-primary); }

/* ============================================================
   ÁREA PRINCIPAL
   ============================================================ */

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* ============================================================
   HEADER
   ============================================================ */

.app-header {
  height: var(--header-height);
  background: white;
  border-bottom: 1px solid var(--td-gray-200);
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  gap: var(--space-4);
  flex-shrink: 0;
  z-index: var(--z-header);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1;
  min-width: 0;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
  color: var(--td-gray-500);
  overflow: hidden;
}

.breadcrumb .crumb {
  white-space: nowrap;
}

.breadcrumb .crumb.active {
  color: var(--td-gray-800);
  font-weight: 600;
}

.breadcrumb .separator {
  color: var(--td-gray-300);
  font-size: 0.7rem;
}

/* Búsqueda global */
.global-search {
  flex: 1;
  max-width: 420px;
}

.global-search-wrapper {
  position: relative;
}

.global-search-wrapper .search-icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--td-gray-400);
  pointer-events: none;
  font-size: 0.9rem;
}

.global-search-input {
  width: 100%;
  padding: 0.4rem var(--space-3) 0.4rem 2.2rem;
  background: var(--td-gray-50);
  border: 1px solid var(--td-gray-200);
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  color: var(--td-gray-700);
  transition: all var(--transition);
}

.global-search-input:focus {
  outline: none;
  background: white;
  border-color: var(--td-primary);
  box-shadow: 0 0 0 3px rgb(27 61 122 / 0.1);
}

.global-search-input::placeholder { color: var(--td-gray-400); }

/* Acciones del header */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.header-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: var(--td-gray-500);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  background: none;
  border: none;
  font-size: 1rem;
}

.header-btn:hover {
  background: var(--td-gray-100);
  color: var(--td-gray-700);
}

.header-btn .notif-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background: var(--td-danger);
  border-radius: 50%;
  border: 2px solid white;
}

/* ============================================================
   CONTENIDO PRINCIPAL
   ============================================================ */

.content-area {
  flex: 1;
  overflow: hidden;
  display: flex;
}

.content-main {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
  min-width: 0;
}

/* Cabecera de módulo */
.module-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  gap: var(--space-4);
  flex-wrap: wrap;
}

.module-title-area {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.module-title {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--td-gray-900);
}

.module-subtitle {
  font-size: var(--font-size-sm);
  color: var(--td-gray-500);
  margin-top: 2px;
}

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

/* ============================================================
   PANEL DERECHO FLOTANTE (CRM, actividades, notas)
   ============================================================ */

.right-panel {
  width: var(--right-panel-width);
  min-width: var(--right-panel-width);
  height: 100%;
  background: white;
  border-left: 1px solid var(--td-gray-200);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: width var(--transition-slow), min-width var(--transition-slow);
}

.right-panel.hidden {
  width: 0;
  min-width: 0;
  border-left: none;
}

.right-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--td-gray-200);
  flex-shrink: 0;
}

.right-panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--td-gray-200);
  flex-shrink: 0;
}

.right-panel-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-2);
  font-size: var(--font-size-xs);
  font-weight: 500;
  color: var(--td-gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all var(--transition);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.right-panel-tab:hover { color: var(--td-primary); }
.right-panel-tab.active { color: var(--td-primary); border-bottom-color: var(--td-primary); }

.right-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
}

/* Tabs flotantes en el borde derecho (como GIAV) */
.floating-tabs {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  z-index: 50;
}

.floating-tab {
  width: 32px;
  writing-mode: vertical-lr;
  text-orientation: mixed;
  transform: rotate(180deg);
  padding: var(--space-3) var(--space-2);
  background: var(--td-primary);
  color: white;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  border-radius: var(--radius) 0 0 var(--radius);
  border: none;
  transition: background var(--transition);
  white-space: nowrap;
}

.floating-tab:hover { background: var(--td-primary-light); }

/* ============================================================
   VISTA DE FICHA / DETALLE
   ============================================================ */

.detail-view {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: var(--space-5);
  align-items: start;
}

.detail-main {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.detail-sidebar-right {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  position: sticky;
  top: 0;
}

/* ============================================================
   TOOLBAR DE MÓDULO (acciones sobre tabla)
   ============================================================ */

.module-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
}

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

/* ============================================================
   FICHA LATERAL (panel de detalle rápido)
   ============================================================ */

.quick-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 480px;
  background: white;
  border-left: 1px solid var(--td-gray-200);
  box-shadow: var(--shadow-xl);
  z-index: calc(var(--z-modal) - 1);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-slow);
}

.quick-panel.open {
  transform: translateX(0);
}

.quick-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--td-gray-200);
  flex-shrink: 0;
}

.quick-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
}

.quick-panel-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--td-gray-200);
  flex-shrink: 0;
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

/* ============================================================
   SECCIÓN DE DATOS (info display)
   ============================================================ */

.data-section {
  background: white;
  border: 1px solid var(--td-gray-200);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.data-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  background: var(--td-gray-50);
  border-bottom: 1px solid var(--td-gray-200);
}

.data-section-title {
  font-size: var(--font-size-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--td-gray-600);
}

.data-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
}

.data-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }

.data-field {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--td-gray-100);
  border-right: 1px solid var(--td-gray-100);
}

.data-field:nth-child(2n) { border-right: none; }
.data-field:nth-last-child(-n+2) { border-bottom: none; }

.data-field .field-label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--td-gray-400);
  margin-bottom: var(--space-1);
}

.data-field .field-value {
  font-size: var(--font-size-sm);
  color: var(--td-gray-800);
  font-weight: 500;
}

.data-field .field-value.empty { color: var(--td-gray-300); font-style: italic; }

/* ============================================================
   RESUMEN FINANCIERO (en expedientes, facturas)
   ============================================================ */

.financial-summary {
  background: var(--td-primary);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  color: white;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}

.fin-item { text-align: center; }
.fin-item .fin-label {
  font-size: var(--font-size-xs);
  opacity: 0.7;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-1);
}
.fin-item .fin-value {
  font-size: var(--font-size-xl);
  font-weight: 700;
}
.fin-item .fin-value.accent { color: var(--td-accent-light); }
.fin-item .fin-value.success { color: #6EE7B7; }
.fin-item .fin-value.danger { color: #FCA5A5; }

/* ============================================================
   SCROLLBAR PERSONALIZADO
   ============================================================ */

.content-main::-webkit-scrollbar { width: 6px; }
.content-main::-webkit-scrollbar-track { background: transparent; }
.content-main::-webkit-scrollbar-thumb { background: var(--td-gray-200); border-radius: 3px; }
.content-main::-webkit-scrollbar-thumb:hover { background: var(--td-gray-300); }
