/* ============================================================================================================
   HEADER.CSS - Estilos del Header, Sidebar y Saldo
   ============================================================================
   
   ÍNDICE:
   1. Reset y estilos base
   2. Estados del body (Sidebar abierto)
   3. Contenedores principales
   4. Sidebar
   5. Perfil de usuario en sidebar
   6. Links legales y versión en sidebar
   7. Overlay del sidebar (móvil)
   8. Header
   9. Información de saldo
   10. Menú hamburguesa (móvil)
   11. Responsive - móvil
   ============================================================================ */

/* ============================================================================================================
   1. RESET Y ESTILOS BASE
   ============================================================================ */

* {
  box-sizing: border-box;
}

html {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: "Inter", system-ui, sans-serif;
  background-color: #21232a;
  color: #e5e7eb;
  overscroll-behavior-y: none;
  overscroll-behavior-x: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  /* iOS viewport fix */
  position: relative;
  overflow: hidden;
}

body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: "Inter", system-ui, sans-serif;
  background-color: #21232a;
  color: #e5e7eb;
  overscroll-behavior-y: none;
  overscroll-behavior-x: none;
  /* iOS viewport fix - JavaScript ajustará la altura dinámicamente */
  position: relative;
}

/* ============================================================================
   2. ESTADOS DEL BODY (Sidebar Abierto)
   ============================================================================ */

body.sidebar-open #saldo-info {
  opacity: 0.1;
  filter: blur(4px);
  -webkit-filter: blur(4px);
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), 
              filter 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              -webkit-filter 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  user-select: none;
}

body.sidebar-open #header-container {
  background-color: rgba(0, 0, 0, 0.5);
}

body.sidebar-open #titulo-header h1 {
  color: #6b7280;
  opacity: 0.2;
}

/* ============================================================================
   3. CONTENEDORES PRINCIPALES
   ============================================================================ */

#main-container {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}

#principal-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

/* ============================================================================
   4. SIDEBAR
   ============================================================================ */

#sidebar {
  width: 250px;
  flex: 0 0 250px;
  min-width: 250px;
  background: linear-gradient(180deg, #18191f 0%, #14151a 100%);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 28px 20px 24px 20px;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

/* Botones del Sidebar */
#sidebar button {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  color: #e5e7eb;
  padding: 11px 16px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: inherit;
  font-size: 14px;
  width: 100%;
  display: flex;
  align-items: center;
  font-weight: 500;
  box-shadow: none;
  margin: 0 0 10px 0;
  letter-spacing: 0.01em;
}

#sidebar button:hover {
  background: rgba(255,255,255,0.07);
  border-color: rgba(0, 230, 161, 0.2);
  color: #00e6a1;
  transform: translateX(3px);
  box-shadow: 0 2px 8px rgba(0, 230, 161, 0.08);
}

#sidebar button:active {
  transform: translateX(1px);
  box-shadow: 0 1px 4px rgba(0, 230, 161, 0.06);
  background: rgba(255,255,255,0.06);
}

/* Botón de Logout */
#sidebar button.btn-logout {
  background: transparent;
  border: none;
  color: #ef4444;
  padding: 6px 0;
  margin-top: auto;
  margin-bottom: 0;
  text-align: center;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.2px;
  box-shadow: none;
  transform: none;
  justify-content: center;
}

#sidebar button.btn-logout:hover {
  background: transparent;
  border: none;
  color: #f87171;
  box-shadow: none;
  transform: none;
  text-decoration: underline;
}

/* ============================================================================
   5. PERFIL DE USUARIO EN SIDEBAR
   ============================================================================ */

.sidebar-user-profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0 16px 0;
  margin-bottom: 8px;
}

.user-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid rgba(0, 230, 161, 0.3);
  background: rgba(0, 230, 161, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
  transition: all 0.3s ease;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-name {
  color: #e5e7eb;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  letter-spacing: 0.3px;
}

.sidebar-separator {
  height: 1px;
  background: linear-gradient(90deg, 
    transparent 0%, 
    rgba(255,255,255,0.08) 30%, 
    rgba(255,255,255,0.08) 70%, 
    transparent 100%);
  margin: 16px 0;
  border: none;
}

/* ============================================================================
   6. LINKS LEGALES Y VERSIÓN EN SIDEBAR
   ============================================================================ */

.sidebar-legal {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 0 6px 0;
  font-size: 10px;
  color: rgba(255,255,255,0.35);
  text-align: center;
  flex-wrap: wrap;
}

.sidebar-link {
  color: rgba(255,255,255,0.35);
  text-decoration: none;
  font-weight: 400;
  transition: color 0.2s ease;
  cursor: pointer;
  letter-spacing: 0.01em;
}

.sidebar-link:hover {
  color: rgba(255,255,255,0.5);
  text-decoration: underline;
}

.sidebar-version {
  margin-top: 0;
  padding: 4px 0 6px 0;
  font-size: 10px;
  color: rgba(255,255,255,0.3);
  text-align: center;
  font-weight: 400;
  letter-spacing: 0.2px;
}

/* ============================================================================
   7. OVERLAY DEL SIDEBAR (Móvil)
   ============================================================================ */

#sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

#sidebar-overlay.active {
  opacity: 1;
  pointer-events: all;
}

/* ============================================================================
   8. HEADER
   ============================================================================ */

#header-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  width: 100%;
  height: 72px;
  padding: 20px 28px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background-color: #21232a;
  position: sticky;
  top: 0;
  z-index: 101;
  box-sizing: border-box;
}

#titulo-header {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

#titulo-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: #9ca3af;
  letter-spacing: 0.01em;
  text-align: center;
}

/* ============================================================================
   9. INFORMACIÓN DE SALDO
   ============================================================================ */

#saldo-info {
  display: none;
  flex-direction: row;
  align-items: center;
  gap: 15px;
  background: linear-gradient(135deg, rgba(0, 230, 161, 0.12) 0%, #21232a 100%);
  border-bottom: 1px solid rgba(0, 230, 161, 0.15);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  color: #e5e7eb;
  font-size: 14px;
  padding: 14px 20px;
  letter-spacing: 0.3px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 72px;
  z-index: 100;
  box-sizing: border-box;
  width: 100%;
}

#saldo-info::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, 
    transparent 0%, 
    rgba(0, 230, 161, 0.4) 50%, 
    transparent 100%);
  pointer-events: none;
}

#saldo-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  position: relative;
}

/* Selector de Mes */
#mes-select {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #00e6a1;
  border-radius: 8px;
  padding: 6px 16px 6px 12px;
  font-size: 13px;
  cursor: pointer;
  outline: none;
  font-family: inherit;
  transition: all 0.2s ease;
  width: auto;
  position: relative;
  -webkit-appearance: menulist;
  -moz-appearance: menulist;
  appearance: menulist;
}

#mes-select:hover {
  background: rgba(0, 230, 161, 0.1);
  border-color: rgba(0, 230, 161, 0.3);
}

#mes-select:focus {
  border-color: rgba(0, 230, 161, 0.5);
  box-shadow: 0 0 6px rgba(0, 230, 161, 0.25);
  outline: none;
}

#mes-select:active {
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

#mes-select::-moz-focus-inner {
  border: 0;
  outline: none;
}

#mes-select option {
  background: #2b2d31;
  color: #e5e7eb;
}

/* Contenido del Saldo */
#saldo-content {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  position: relative;
  transition: opacity 0.25s ease-out, transform 0.25s ease-out;
  will-change: opacity;
  transform: translateZ(0);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  color: #e5e7eb;
}

#saldo-content::-webkit-scrollbar {
  display: none;
}

#saldo-content::-webkit-scrollbar,
#saldo-content::-webkit-scrollbar-track,
#saldo-content::-webkit-scrollbar-thumb {
  display: none;
}

#saldo-content span,
#saldo-content div {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 12px;
  position: relative;
  font-weight: 600;
}

#saldo-content span:not(:last-child)::after,
#saldo-content div:not(:last-child)::after {
  content: '';
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 1px;
  height: 20px;
  background: linear-gradient(180deg, 
    transparent 0%, 
    rgba(255, 255, 255, 0.15) 50%, 
    transparent 100%);
}

/* Colores del Saldo Financiero */
/* Ingresos - Verde brillante (#00e6a1) */
#saldo-content .saldo-ingresos,
#saldo-content [data-tipo="ingresos"],
#saldo-content strong.saldo-ingresos,
#saldo-content strong[data-tipo="ingresos"],
#saldo-content .saldo-ingresos strong,
#saldo-content [data-tipo="ingresos"] strong {
  color: #00e6a1 !important;
  -webkit-text-stroke: 0.5px #00e6a1;
}

/* Gastos - Rojo (#ef4444) */
#saldo-content .saldo-gastos,
#saldo-content [data-tipo="gastos"],
#saldo-content strong.saldo-gastos,
#saldo-content strong[data-tipo="gastos"],
#saldo-content .saldo-gastos strong,
#saldo-content [data-tipo="gastos"] strong {
  color: #ef4444 !important;
}

/* Saldo real - Verde (#00e6a1) */
#saldo-content .saldo-real,
#saldo-content [data-tipo="saldo-real"],
#saldo-content strong.saldo-real,
#saldo-content strong[data-tipo="saldo-real"],
#saldo-content .saldo-real strong,
#saldo-content [data-tipo="saldo-real"] strong {
  color: #00e6a1 !important;
}

/* Saldo previsto - Amarillo/Naranja (#f59e0b) */
#saldo-content .saldo-previsto,
#saldo-content [data-tipo="saldo-previsto"],
#saldo-content strong.saldo-previsto,
#saldo-content strong[data-tipo="saldo-previsto"],
#saldo-content .saldo-previsto strong,
#saldo-content [data-tipo="saldo-previsto"] strong {
  color: #f59e0b !important;
}

/* Estilo por defecto para strong solo si no tiene clase o atributo de tipo */
#saldo-content strong:not([class*="saldo-"]):not([data-tipo]) {
  color: #00e6a1;
}

/* ============================================================================
   10. MENÚ HAMBURGUESA (Móvil)
   ============================================================================ */

#menu-toggle {
  display: none !important;
  position: fixed;
  top: calc(36px - 21px); /* (altura header 72px / 2) - (altura botón 42px / 2) */
  left: 15px;
  transform: translateY(0);
  background: none;
  border: none;
  color: #00e6a1;
  border-radius: 10px;
  width: 42px;
  height: 42px;
  cursor: pointer;
  z-index: 101;
  font-size: 22px;
  line-height: 1;
  transition:
    left 0.35s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
    color 0.3s ease;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#menu-toggle::before {
  content: "☰";
  display: block;
  transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 1;
  transform: rotate(0deg);
}

#menu-toggle.active::before {
  content: "✕";
  opacity: 1;
  transform: rotate(90deg);
}

#menu-toggle:active::before {
  transform: scale(0.85);
}

#menu-toggle.active:active::before {
  transform: rotate(90deg) scale(0.85);
}

#menu-toggle.active {
  background: none;
  border: none;
  color: #00e6a1;
  left: 260px; /* 250px (ancho sidebar) + 10px (gap) */
  transform: translateY(0);
}

#menu-toggle.active:hover {
  background: none;
  border: none;
  color: #00c08b;
}

/* Excluir el botón del menú del efecto blur/opacidad cuando el sidebar está abierto */
body.sidebar-open #menu-toggle {
  opacity: 1 !important;
  filter: none !important;
  -webkit-filter: none !important;
  pointer-events: auto !important;
  /* Crear un nuevo contexto de renderizado aislado para evitar heredar el blur del padre */
  isolation: isolate;
  transform: translateZ(0);
  will-change: transform;
  z-index: 120 !important; /* Mayor que el z-index del sidebar (120) y header (101) */
  /* Forzar un nuevo contexto de apilamiento */
  position: fixed !important;
}

/* ============================================================================
   11. RESPONSIVE - MÓVIL
   ============================================================================ */

@media (max-width: 768px) {
  #main-container {
    flex-direction: column;
  }

  /* Sidebar en móvil */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 250px;
    max-width: 250px;
    height: 100vh;
    height: 100dvh;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: none;
    z-index: 120;
    overflow-y: auto;
  }

  #sidebar[data-open="true"] {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.4);
  }

  #sidebar-overlay {
    display: block;
  }

  #sidebar-overlay.active {
    opacity: 1;
    pointer-events: all;
  }

  /* Principal Container */
  #principal-container {
    width: 100%;
    min-height: 100%;
    margin-left: 0;
  }

  /* Header en móvil */
  #header-container {
    position: sticky;
    top: 0;
    z-index: 101;
    padding: 18px 16px;
    justify-content: space-between;
    height: 54px;
    box-sizing: border-box;
  }

  /* Menú Hamburguesa en móvil */
  #menu-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    top: calc(27px - 21px); /* (altura header móvil 54px / 2) - (altura botón 42px / 2) */
    transform: translateY(0);
  }

  #menu-toggle.active {
    transform: translateY(0);
  }

  /* Título del Header en móvil */
  #titulo-header {
    justify-content: flex-end;
  }

  #titulo-header h1 {
    font-size: 16px;
    text-align: right;
  }

  /* Saldo Info en móvil */
  #saldo-info {
    font-size: 12px;
    padding: 12px 15px;
    gap: 10px;
    background: linear-gradient(135deg, rgba(0, 230, 161, 0.12) 0%, #21232a 100%);
    flex-direction: row;
    top: 54px;
    z-index: 100;
    box-sizing: border-box;
    width: 100%;
  }

  #saldo-header {
    flex-shrink: 0;
    position: relative;
  }

  /* Selector de Mes en móvil */
  #mes-select {
    font-size: 12px;
    padding: 5px 14px 5px 10px;
    width: auto;
    outline: none !important;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: menulist;
    -moz-appearance: menulist;
    appearance: menulist;
  }

  #mes-select:focus,
  #mes-select:active {
    outline: none !important;
    border-color: rgba(0, 230, 161, 0.3);
    box-shadow: none;
  }

  #mes-select::-moz-focus-inner {
    border: 0;
    outline: none;
  }

  /* Contenido del Saldo en móvil */
  #saldo-content {
    white-space: nowrap;
    text-align: left;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  #saldo-content::-webkit-scrollbar {
    display: none;
  }

  #saldo-content span,
  #saldo-content div {
    margin: 0 8px;
  }

  #saldo-content span:not(:last-child)::after,
  #saldo-content div:not(:last-child)::after {
    right: -8px;
    height: 16px;
  }

  #saldo-content strong {
    font-size: 13px;
  }
}
