/* =========================================================
   RESET GENERAL
========================================================= */

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

:root {
  --header-height: 58px;
  --footer-height: 60px;

  --sidebar-bg: #9BCDED;
  --sidebar-width: 280px;
  --sidebar-collapsed-width: 80px;

  --sidebar-mobile-width: 56px;
  --sidebar-mobile-open-width: 165px;

  --icon-mobile-size: 14px;
  --text-mobile-size: 12px;
}

/* =========================================================
   BODY GENERAL
========================================================= */

body {
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;

  display: flex;
  flex-direction: column;

  background-image: url("iconos/fondo_final.png");
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  background-color: #4DA5E0;
}

body.bg-simple {
  background-image: none;
  background-color: #F0F2F5;
}

body.bg-simple .main-content {
  height: calc(100vh - var(--header-height) - var(--footer-height));
  overflow-y: auto;
}

main {
  flex: 1;
}

/* =========================================================
   HEADER / FOOTER
========================================================= */

.header-bar {
  min-height: var(--header-height);
  display: flex;
  align-items: center;
}

.bg-barra-tarea {
  background-color: #1F77B2;
}

.pie {
  background-color: #124364;
}

/* Header y footer fijos */
body.bg-simple #mainHeader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1100;
}

body.bg-simple #mainFooter {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1100;

  min-height: var(--footer-height);
  padding-top: 1rem !important;
  padding-bottom: 1rem !important;
}

body.bg-simple .app-container {
  padding-top: var(--header-height);
  padding-bottom: var(--footer-height);
}

/* Tipo de Usurio Header*/

.user-info-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-text-header {
  text-align: right;
  line-height: 1.4;
}

.user-label-header {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.75);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}


.user-role-header {
  font-size: 14px;
  color: #fff;
  font-weight: 500;
}

.user-divider-header {
  width: 1px;
  height: 28px;
  background: rgba(255, 255, 255, 0.25);
}
/*Cliente*/
.user-icon-cliente-header {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: black;
  border: 1px solid white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-icon-cliente-header img {
  opacity: 0.9;
  filter: brightness(0) invert(1);
}
/*Tecnico*/
.user-icon-tecnico-header {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: white;
  border: 1px solid black;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-icon-tecnico-header img {
  opacity: 0.9;
  filter: brightness(0);
}
/* =========================================================
   LINKS / ICONOS
========================================================= */

a.tyc {
  color: #fff !important;
}

a.tyc:hover {
  color: #0d6efd !important;
}

.icon-img {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -.125em;
}

.icon-img img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.imagen-redonda {
  border-radius: 50%;
}

.color-icono {
  filter: invert(100%);
}

.logo-app {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

/* =========================================================
   FORMULARIOS
========================================================= */

.form-floating > .form-control:not(textarea),
.form-floating > .form-select {
  height: 2.6rem;
  min-height: 2.6rem;
  padding-top: 1.1rem;
  padding-bottom: 0.25rem;
  line-height: 1.1;
}

/* =========================================================
   LAYOUT PRINCIPAL
========================================================= */

.app-container {
  display: flex;
  min-height: calc(100vh - var(--header-height) - var(--footer-height));
}

.main-content {
  margin-left: var(--sidebar-width);
  width: 100%;
  padding: 1rem;
  transition: margin-left 0.3s ease;
}

/* =========================================================
   SIDEBAR DESKTOP
========================================================= */

.sidebar {
  position: fixed;
  top: var(--header-height);
  bottom: var(--footer-height);
  left: 0;

  width: var(--sidebar-width);
  background-color: var(--sidebar-bg);
  color: #fff;

  overflow-y: auto;
  overflow-x: hidden;

  transition: width 0.3s ease;
  z-index: 1000;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed ~ .main-content {
  margin-left: var(--sidebar-collapsed-width);
}

/* Links */

.sidebar a,
.sidebar .nav-link,
.sidebar .dropdown > a {
  color: #fff;
}

.sidebar .nav-link.active {
  background-color: rgba(255,255,255,.25);
}

.sidebar .nav-link:hover {
  background-color: rgba(255,255,255,.15);
}

/* Texto */

.sidebar .link-text {
  transition: opacity 0.2s ease;
}

.sidebar.collapsed .link-text {
  display: none;
}

/* Iconos */

.sidebar.collapsed .nav-link {
  justify-content: center;
}

.sidebar.collapsed .nav-link svg {
  margin-right: 0;
}

/* =========================================================
   DROPDOWN PERFIL
========================================================= */

.sidebar .dropdown-toggle::after {
  filter: invert(1);
}

.sidebar .dropdown-menu {
  width: 100%;
  background: #fff;
}

.sidebar .dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #000;
  font-weight: 400;
}

.sidebar .dropdown-item:hover,
.sidebar .dropdown-item:focus {
  background: transparent;
  font-weight: 600;
}

.sidebar .dropdown-divider {
  border-color: #ddd;
}

/* collapsed */

.sidebar.collapsed .dropdown-menu {
  width: var(--sidebar-collapsed-width);
  min-width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .dropdown-item {
  font-size: 0;
  justify-content: center;
  gap: 0;
  padding: 0.75rem 0;
}

.sidebar.collapsed .dropdown-divider {
  width: 40%;
  margin: 0.5rem auto;
}

.modal {
  z-index: 5000 !important;
}

.modal-backdrop {
  z-index: 4999 !important;
}

/* =========================================================
   SWEETALERT2 - Siempre por encima de todo
========================================================= */

.swal2-container {
  z-index: 99999 !important;
}

.swal2-popup {
  z-index: 99999 !important;
}

/* Por si acaso el backdrop también */
.swal2-backdrop-show {
  z-index: 99998 !important;
}

/* SweetAlert2 - ícono warning en rojo */
.swal2-icon.swal2-warning {
  border-color: #dc3545 !important;
  color: #dc3545 !important;
}

/* =========================================================
   MOBILE
========================================================= */

@media (max-width: 768px) {

  body {
    display: block;
    min-height: auto;
  }

  /* ============================================== */
  /* SIDEBAR BASE EN MÓVIL                          */
  /* ============================================== */

  .sidebar {
    width: var(--sidebar-mobile-width) !important;
    padding: 0.5rem 0 !important;
    font-size: var(--text-mobile-size);
    transition: width 0.3s ease;
    height: calc(100dvh - var(--header-height) - var(--footer-height));
    overflow-y: auto;
    overflow-x: hidden;
    position: fixed;
    top: var(--header-height);
    left: 0;
    z-index: 2000;
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important; /* no center, que empuja contenido */
  }

  .sidebar.collapsed {
    width: var(--sidebar-mobile-width) !important;
  }

  .sidebar.open {
    width: var(--sidebar-mobile-open-width) !important;
  }

  /* 🔑 CLAVE: empujar el dropdown del perfil al final */
  .sidebar .dropdown {
    margin-top: auto !important;
  }

  /* ============================================== */
  /* TEXTOS                                         */
  /* ============================================== */

  .sidebar .link-text {
    display: none !important;
  }

  .sidebar.open .link-text {
    display: inline !important;
  }
  
  /* FIX 3: Móvil - sidebar alineación interna sin romper el JS */
  .sidebar .nav-pills {
    width: 100%;
  }

  .sidebar .nav-item {
    width: 100%;
  }

  .sidebar .nav-link {
    width: 100% !important;
    box-sizing: border-box !important;
    white-space: nowrap;
    overflow: hidden;
  }

  /* ============================================== */
  /* BOTÓN TOGGLE (abrir/cerrar sidebar)            */
  /* ============================================== */

  #toggleSidebar {
    padding: 0.25rem !important;
    margin-bottom: 0.5rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  #toggleSidebar img {
    width: 18px !important;
    height: 18px !important;
    width: 18px !important;
    height: 18px !important;
    display: block !important;
  }

  /* ============================================== */
  /* ICONOS UNIFORMES                               */
  /* ============================================== */

  .sidebar .nav-link img,
  .sidebar .dropdown-item img,
  .sidebar .dropdown-toggle img {
    width: 18px !important;
    height: 18px !important;
    flex-shrink: 0;
    object-fit: contain;
    margin: 0 !important;
  }

  /* ============================================== */
  /* NAV-LINK ALINEACIÓN                            */
  /* ============================================== */

  .sidebar .nav-link {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0.6rem 0 !important;
    gap: 0 !important;
    width: 100% !important;
    border: 1px solid rgba(255,255,255,0.2) !important;
    margin-bottom: 4px !important;
    box-sizing: border-box !important;
  }

  .sidebar .dropdown-toggle {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0.6rem 0 !important;
    gap: 0 !important;
    width: 100% !important;
  }

  /* Sidebar ABIERTA: alinear a la izquierda */
  .sidebar.open .nav-link,
  .sidebar.open .dropdown-toggle {
    justify-content: flex-start !important;
    gap: 0.5rem !important;
    padding: 0.6rem 0.75rem !important;
  }

  /* ============================================== */
  /* DROPDOWN PERFIL MÓVIL                          */
  /* ============================================== */

  #menuPerfil {
    margin-left: 0 !important;
  }

  /* Dropdown cuando sidebar CERRADA */
  .sidebar:not(.open) .dropdown-menu {
    width: var(--sidebar-mobile-width) !important;
    min-width: var(--sidebar-mobile-width) !important;
    padding: 0.5rem 0 !important;
  }

  .sidebar:not(.open) .dropdown-item {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    padding: 0.5rem 0 !important;
    gap: 0 !important;
    font-size: 0 !important;
  }

  .sidebar:not(.open) .dropdown-item .link-text {
    display: none !important;
  }

  /* Dropdown cuando sidebar ABIERTA */
  .sidebar.open .dropdown-menu {
    width: var(--sidebar-mobile-open-width) !important;
    min-width: var(--sidebar-mobile-open-width) !important;
    padding: 0.5rem 0 !important;
  }

  .sidebar.open .dropdown-item {
    display: flex !important;
    justify-content: flex-start !important;
    align-items: center !important;
    padding: 0.5rem 0.75rem !important;
    gap: 0.5rem !important;
    font-size: var(--text-mobile-size) !important;
  }

  .sidebar.open .dropdown-item .link-text {
    display: inline !important;
  }
  
  

  /* ============================================== */
  /* LISTA SIN ESTILOS                              */
  /* ============================================== */

  .sidebar ul.nav {
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
  }

  .sidebar .nav-item,
  .sidebar li {
    list-style: none;
    padding: 0 !important;
    margin: 0 !important;
    width: 100% !important;
  }

  /* ============================================== */
  /* CONTENIDO                                      */
  /* ============================================== */

  .main-content {
     flex: 1;
    margin-left: var(--sidebar-mobile-width);
    width: auto;
    transition: margin-left 0.3s ease;
    overflow-y: auto;   /* permite scroll vertical si el contenido es alto */
  }

  .sidebar.open ~ .main-content {
    margin-left: var(--sidebar-mobile-open-width);
  }
  
  /* FIX 3: Móvil - sidebar alineación interna sin romper el JS */
  .sidebar .nav-pills {
    width: 100%;
  }

  .sidebar .nav-item {
    width: 100%;
  }

  .sidebar .nav-link {
    width: 100% !important;
    box-sizing: border-box !important;
    white-space: nowrap;
    overflow: hidden;
  }

  /* FIX 4: Móvil - modal por encima del sidebar */
  .modal {
    z-index: 5000 !important;
  }

  .modal-backdrop {
    z-index: 4999 !important;
  }

  .modal.show .modal-dialog {
    margin: 1rem auto !important;
    width: 92% !important;
    max-width: 480px !important;
  }

  /* ============================================== */
  /* FOOTER                                         */
  /* ============================================== */

  #mainFooter .nav.list-unstyled {
    display: none !important;
  }

  #mainFooter {
    padding: 0.5rem 0 !important;
  }

  #mainFooter .container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  #mainFooter .logo-app {
    width: 24px;
    height: 24px;
  }

  #mainFooter .text-white,
  #mainFooter .tyc {
    font-size: 0.75rem;
    white-space: nowrap;
  }
}