/* ============================================================
   RESPONSIVE · Portal Contratistas
   Desde 320px (móviles pequeños) hasta 4K
   ============================================================ */

/* ------------------------------------------------------------
   Base: tipografía fluida y contenedores
   ------------------------------------------------------------ */
html{ -webkit-text-size-adjust:100%; }
body{ overflow-x:hidden; }

img{ max-width:100%; height:auto; }

/* ------------------------------------------------------------
   Header: botón hamburguesa
   ------------------------------------------------------------ */
.hdr-menu-btn{
  display:none;
  background:transparent;
  border:none;
  cursor:pointer;
  width:40px;height:40px;
  padding:0;margin-right:8px;
  border-radius:8px;
  position:relative;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  gap:5px;
  transition:background .15s;
}
.hdr-menu-btn:hover{ background:rgba(255,255,255,.08); }
.hdr-menu-btn span{
  display:block;
  width:22px;height:2px;
  background:#fff;
  border-radius:2px;
  transition:all .2s;
}

/* Sidebar overlay (móvil) */
.sidebar-overlay{
  display:none;
  position:fixed;
  inset:0;
  background:rgba(0,0,0,.5);
  z-index:98;
  opacity:0;
  pointer-events:none;
  transition:opacity .25s;
  backdrop-filter:blur(2px);
}
.sidebar-overlay.show{
  opacity:1;
  pointer-events:auto;
}

/* Botón cerrar sidebar (móvil) */
.sidebar-close{
  display:none;
  position:absolute;
  top:12px;right:12px;
  background:transparent;
  border:none;
  cursor:pointer;
  font-size:18px;
  color:var(--txt-mid);
  width:36px;height:36px;
  border-radius:8px;
  transition:background .15s;
  z-index:2;
}
.sidebar-close:hover{ background:var(--verde-light); color:var(--verde-dark); }

/* ------------------------------------------------------------
   Layout: se apila en móvil
   ------------------------------------------------------------ */
.layout{
  display:grid;
  grid-template-columns:220px 1fr;
  flex:1;
  min-height:calc(100vh - 62px);
}

/* ------------------------------------------------------------
   Breakpoints
   ------------------------------------------------------------ */

/* --- 1280px: contenedores un poco más estrechos --- */
@media (max-width:1280px){
  .content{ padding:20px 22px; }
  .stats{ grid-template-columns:repeat(4,1fr); gap:10px; }
}

/* --- 1024px: sidebar más chico, ocultar textos secundarios --- */
@media (max-width:1024px){
  .header{ padding:0 18px; }
  .hdr-contigo{ display:none; }
  .hdr-user-txt .hdr-urole{ display:none; }

  .layout{ grid-template-columns:200px 1fr; }
  .content{ padding:18px 20px; }

  .stats{ grid-template-columns:repeat(2,1fr); }
}

/* --- 900px: tablets --- */
@media (max-width:900px){
  .hdr-user-txt{ display:none; }
  .hdr-user{ padding:5px; }
  .btn-logout-txt{ display:none; }
  .btn-logout::before{ content:'↩'; font-size:14px; }
  .btn-logout{ padding:6px 10px; }

  .ph-title{ font-size:20px; }

  .fgrid{ grid-template-columns:1fr; }
  .info-grid{ grid-template-columns:1fr 1fr; }

  .rank-item{ grid-template-columns:36px 1fr auto; gap:10px; padding:12px; }
  .rank-n{ font-size:18px; }
}

/* --- 768px: MÓVIL - menú hamburguesa + drawer --- */
@media (max-width:768px){
  /* Header */
  .header{
    height:58px;
    padding:0 14px;
  }
  .hdr-menu-btn{ display:flex; }
  .hdr-text .hdr-sub{ font-size:8px; }
  .hdr-text .hdr-title{ font-size:13px; }
  .hdr-escudo{ height:34px; margin-right:4px; }

  .pcg-toggle img{ height:36px; }
  .hdr-avatar{ width:32px; height:32px; font-size:12px; }

  /* Layout: sidebar se vuelve drawer */
  .layout{
    grid-template-columns:1fr;
    min-height:calc(100vh - 58px);
  }

  /* Sidebar como drawer lateral */
  .sidebar{
    position:fixed;
    top:0;
    left:0;
    bottom:0;
    width:280px;
    max-width:85vw;
    height:100vh;
    z-index:99;
    transform:translateX(-100%);
    transition:transform .28s cubic-bezier(.4,0,.2,1);
    box-shadow:4px 0 24px rgba(0,0,0,.15);
    padding-top:56px;
    overflow-y:auto;
  }
  .sidebar.open{
    transform:translateX(0);
  }
  .sidebar-close{ display:block; }
  .sidebar-overlay{ display:block; }

  /* Contenido */
  .content{
    padding:16px 14px;
  }

  /* Tipografía */
  .ph-title{ font-size:18px; }
  .ph-desc{ font-size:11px; }
  .stat-val{ font-size:22px; }
  .stat-lbl{ font-size:9px; }
  .card-ttl{ font-size:10px; }

  /* Botones */
  .btn{ padding:8px 12px; font-size:10px; }
  .btn-sm{ padding:5px 9px; font-size:9px; }

  /* Stats en 2 columnas */
  .stats{ grid-template-columns:1fr 1fr; gap:10px; }
  .stat-card{ padding:12px; }

  /* Tablas: scroll horizontal */
  .table-wrap{ margin:0 -14px; padding:0 14px; }
  th, td{ padding:8px 10px; font-size:11px; }
  th{ font-size:8px; }

  /* Modales */
  .modal{
    padding:20px;
    max-width:calc(100vw - 24px);
    width:calc(100vw - 24px);
    border-radius:14px;
  }
  .modal-title{ font-size:14px; }

  /* Cards */
  .card-body{ padding:14px; }
  .card-hdr{ padding:12px 14px; }

  /* Botones de acción en cards */
  .card-body > div[style*="display:flex"]{
    flex-direction:column;
  }
  .card-body > div[style*="display:flex"] .btn{
    width:100%;
    justify-content:center;
  }

  /* Alertas */
  .alert{ font-size:11px; padding:10px 12px; }

  /* Toast */
  .toast-wrap{ bottom:12px; right:12px; left:12px; }
  .toast{ font-size:11px; padding:10px 12px; }

  /* Documentos */
  .doc-item{
    flex-direction:column;
    align-items:flex-start;
    gap:8px;
  }
  .doc-item > div:last-child{
    width:100%;
    justify-content:flex-end;
  }

  /* Info grid */
  .info-grid{ grid-template-columns:1fr; gap:8px; }

  /* Rank */
  .rank-item{ grid-template-columns:32px 1fr; }
  .rank-item > div:last-child{ grid-column:1/-1; text-align:right; }

  /* Footer */
  .footer{
    grid-template-columns:1fr;
    text-align:center;
    padding:14px;
    gap:10px;
  }
  .footer-left, .footer-right{ justify-content:center; text-align:center; }
  .footer-contigo{ height:28px; }

  /* Modal de registro */
  #modal-registro .modal{
    max-width:calc(100vw - 20px);
    width:calc(100vw - 20px);
  }
}

/* --- 480px: móviles medianos --- */
@media (max-width:480px){
  .hdr-text .hdr-sub{ display:none; }
  .hdr-text .hdr-title{ font-size:12px; }

  .content{ padding:14px 12px; }
  .ph-title{ font-size:16px; }

  .stats{ grid-template-columns:1fr; }
  .stat-card{ padding:14px; }
  .stat-val{ font-size:26px; }

  .btn{ font-size:10px; padding:8px 10px; }

  th, td{ font-size:10px; padding:7px 8px; }
}

/* --- 360px: móviles pequeños --- */
@media (max-width:360px){
  .hdr-escudo{ height:28px; }
  .pcg-toggle img{ height:30px; }
  .hdr-avatar{ width:28px; height:28px; font-size:11px; }

  .ph-title{ font-size:15px; }
  .content{ padding:12px 10px; }

  .btn{ padding:7px 9px; font-size:9px; letter-spacing:.4px; }
}

/* --- 1920px+: pantallas grandes --- */
@media (min-width:1920px){
  .header{ padding:0 40px; height:70px; }
  .hdr-escudo{ height:48px; }
  .hdr-title{ font-size:18px; }
  .pcg-toggle img{ height:48px; }
  .hdr-avatar{ width:34px; height:34px; }

  .layout{ grid-template-columns:260px 1fr; min-height:calc(100vh - 70px); }
  .sidebar{ top:70px; height:calc(100vh - 70px); }

  .content{ padding:32px 40px; max-width:1800px; margin:0 auto; width:100%; }

  .ph-title{ font-size:28px; }
  .ph-desc{ font-size:14px; }

  .stat-val{ font-size:34px; }
  .stat-lbl{ font-size:11px; }

  .card-ttl{ font-size:12px; }
  th, td{ font-size:13px; padding:13px 16px; }
  th{ font-size:10px; }

  .modal{ max-width:600px; }
}

/* --- 2560px+: 2K --- */
@media (min-width:2560px){
  body{ font-size:16px; }
  .content{ max-width:2200px; }
  .ph-title{ font-size:32px; }
  .stat-val{ font-size:40px; }
}

/* --- 3840px+: 4K --- */
@media (min-width:3840px){
  body{ font-size:18px; }
  .header{ height:90px; padding:0 80px; }
  .hdr-escudo{ height:60px; }
  .hdr-title{ font-size:22px; }
  .hdr-sub{ font-size:11px; }

  .layout{ grid-template-columns:340px 1fr; min-height:calc(100vh - 90px); }
  .sidebar{ top:90px; height:calc(100vh - 90px); padding:28px 0; }
  .nav-item{ font-size:15px; padding:12px 18px; }
  .nav-sect{ font-size:11px; }

  .content{ padding:48px 80px; max-width:3000px; }
  .ph-title{ font-size:42px; }
  .ph-desc{ font-size:16px; }

  .stat-val{ font-size:52px; }
  .stat-lbl{ font-size:13px; }
  .stat-sub{ font-size:13px; }

  .card-ttl{ font-size:14px; }
  .card-body{ padding:28px; }
  th, td{ padding:16px 20px; }
  th{ font-size:12px; }
  td{ font-size:15px; }

  .btn{ padding:12px 22px; font-size:13px; }

  .modal{ max-width:800px; padding:40px; }
  .modal-title{ font-size:22px; }
}

/* ------------------------------------------------------------
   Ajustes de accesibilidad táctil
   ------------------------------------------------------------ */
@media (hover:none){
  /* Sin hover en pantallas táctiles: evita estados raros */
  .nav-item:hover{ background:transparent; color:var(--txt-mid); }
  .nav-item.active:hover{ background:var(--verde-light); color:var(--verde-dark); }
  tr:hover td{ background:transparent; }
}

/* Áreas de toque mínimas para dedos */
@media (pointer:coarse){
  .nav-item{ padding:12px 14px; }
  .btn{ min-height:38px; }
  .btn-sm{ min-height:32px; }
  input, select, textarea{ font-size:16px !important; } /* evita zoom en iOS */
}

/* ------------------------------------------------------------
   Orientación landscape en móvil
   ------------------------------------------------------------ */
@media (max-width:900px) and (orientation:landscape){
  .header{ height:52px; }
  .layout{ min-height:calc(100vh - 52px); }
  .content{ padding:12px 16px; }
}

/* ------------------------------------------------------------
   Impresión
   ------------------------------------------------------------ */
@media print{
  .header, .sidebar, .footer, .pcg-toggle, .btn-logout, .hdr-menu-btn{
    display:none !important;
  }
  .layout{ grid-template-columns:1fr; }
  .content{ padding:0; background:#fff; }
  .card{ box-shadow:none; border:1px solid #ddd; }
}

/* ============================================================
   FIX DRAWER MÓVIL
   ============================================================ */

@media (max-width:768px){

  /* Asegurar que el contenedor principal no recorte el drawer */
  html, body {
    overflow-x: hidden;
    position: relative;
  }

  #app-screen {
    overflow: visible !important;
  }

  /* El sidebar debe estar por ENCIMA de TODO */
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    height: 100vh !important;
    width: 280px !important;
    max-width: 85vw !important;
    z-index: 9999 !important;
    background: #ffffff !important;
    transform: translateX(-100%);
    transition: transform .3s cubic-bezier(.4,0,.2,1) !important;
    box-shadow: 4px 0 24px rgba(0,0,0,.25) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow-y: auto !important;
    padding-top: 56px !important;
  }

  [data-theme="dark"] .sidebar {
    background: #1a1d21 !important;
  }

  .sidebar.open {
    transform: translateX(0) !important;
  }

  /* El overlay DEBE estar debajo del sidebar pero encima del contenido */
  .sidebar-overlay {
    position: fixed !important;
    inset: 0 !important;
    background: rgba(0,0,0,.55) !important;
    z-index: 9998 !important;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s !important;
    display: block !important;
  }

  .sidebar-overlay.show {
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  /* Header por debajo del drawer */
  .header {
    z-index: 50 !important;
  }

  /* Botón cerrar visible */
  .sidebar-close {
    display: block !important;
    position: absolute !important;
    top: 12px !important;
    right: 12px !important;
    z-index: 10000 !important;
  }
}

/* ============================================================
   CAMPANITA DE NOTIFICACIONES
   ============================================================ */
.notif-wrap{
  position: relative;
}
.notif-btn{
  background: rgba(255,255,255,.08);
  border: none;
  cursor: pointer;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  position: relative;
  transition: background .15s;
}
.notif-btn:hover{
  background: rgba(255,255,255,.15);
}
.notif-badge{
  position: absolute;
  top: -2px;
  right: -2px;
  background: #dc2626;
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  border: 2px solid var(--bg-header);
}

.notif-panel{
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 360px;
  max-width: calc(100vw - 24px);
  background: var(--bg-card);
  border: 1px solid var(--borde);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
  z-index: 9999;
  overflow: hidden;
}
.notif-panel-head{
  padding: 14px 16px;
  border-bottom: 1px solid var(--borde);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(to right, var(--verde-light), transparent);
}
.notif-panel-title{
  font-size: 13px;
  font-weight: 800;
  color: var(--txt-main);
}
.notif-panel-close{
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--txt-mid);
  padding: 4px 8px;
  border-radius: 6px;
}
.notif-panel-close:hover{
  background: var(--bg-elev);
}
.notif-panel-list{
  max-height: 400px;
  overflow-y: auto;
}
.notif-item{
  padding: 12px 16px;
  border-bottom: 1px solid var(--borde);
  cursor: pointer;
  transition: background .15s;
  position: relative;
}
.notif-item:hover{
  background: var(--verde-pale);
}
.notif-item.no-leida::before{
  content: '';
  position: absolute;
  left: 6px;
  top: 18px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--verde-dark);
}
.notif-item.no-leida{
  padding-left: 20px;
}
.notif-item-title{
  font-size: 12px;
  font-weight: 800;
  color: var(--txt-main);
  margin-bottom: 3px;
}
.notif-item-msg{
  font-size: 11px;
  color: var(--txt-mid);
  line-height: 1.4;
}
.notif-item-meta{
  font-size: 10px;
  color: var(--txt-soft);
  margin-top: 5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.notif-item-link{
  color: var(--verde-dark);
  font-weight: 700;
  text-decoration: none;
}
.notif-item-link:hover{
  text-decoration: underline;
}
.notif-empty{
  padding: 40px 20px;
  text-align: center;
  color: var(--txt-mid);
  font-size: 12px;
}
.notif-panel-foot{
  padding: 10px 14px;
  border-top: 1px solid var(--borde);
  text-align: center;
  background: var(--bg-elev);
}

@media (max-width: 480px){
  .notif-panel{
    position: fixed;
    top: 60px;
    right: 8px;
    left: 8px;
    width: auto;
  }
  .notif-btn{
    width: 34px;
    height: 34px;
    font-size: 16px;
  }
}