/* layout.css · Estructura, grids, contenedores y topbar */

/* ============================================= */
/*          NAVEGACIÓN ENTRE SECCIONES           */
/* ============================================= */
.admin-section{
  display:none;
  width:100%;
}

.admin-section.active{
  display:block;
}

/* Ocultar elementos exclusivos de dashboard en otras secciones */
.admin-section:not(#section-dashboard) .dashboard-only {
  display: none !important;
}

#section-obreros {
  min-width: 100%;
  width: 100%;
}

#section-obreros .card-body {
  padding: 20px;
}

/* ============================================= */
/*          CENTRO DE CUENTAS - COUNTRY CARDS    */
/* ============================================= */
.country-config-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: default;
  transition: border-color 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.country-card-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.country-card-info {
  flex: 1;
  min-width: 0;
}

.country-card-info h5 {
  margin: 0 0 2px 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}

.country-card-info p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

/* ============================================= */
/*          LAYOUT PRINCIPAL                     */
/* ============================================= */
.app-shell{
  display:flex;
  flex-direction:column;
  align-items:stretch;
  flex:1;
  width:100%;
  min-height:100vh;
  position:relative;
  background:var(--bg);
}

.main-wrapper{
  flex:1;
  display:flex;
  flex-direction:column;
  min-width:0;
  width:100%;
  overflow-x:hidden;
}

/* ============================================= */
/*          SIDEBAR                              */
/* ============================================= */
.admin-sidebar{
  width:clamp(240px, 78vw, 280px);
  background:var(--panel);
  border-right:none;
  border-radius:0 var(--radius-lg) var(--radius-lg) 0;
  padding:24px 20px;
  display:flex;
  flex-direction:column;
  gap:20px;
  overflow-y:auto;
  height:100vh;
  position:fixed;
  inset:0 auto 0 0;
  transform:translateX(-105%);
  transition:transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index:1200;
  box-shadow:4px 0 24px rgba(0,0,0,0.12);
}

.admin-sidebar.open{
  transform:translateX(0);
}

.sidebar-backdrop{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,0.32);
  opacity:0;
  visibility:hidden;
  transition:opacity 0.2s ease;
  z-index:1185;
}

.sidebar-backdrop.show{
  opacity:1;
  visibility:visible;
}

.sidebar-brand{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:12px;
}

.sidebar-brand .topbar-logo{
  height:48px;
  width:auto;
}

.sidebar-user{
  display:flex;
}

.sidebar-username{
  display:flex;
  align-items:center;
  gap:12px;
  height:48px;
  padding:0 16px;
  border-radius:var(--radius);
  border:1px solid var(--border);
  background:var(--panel);
  font-weight:600;
  color:var(--text);
  font-size:14px;
  width:100%;
  transition:all 0.2s ease;
}

.sidebar-username:hover{
  background:var(--bg);
}

.sidebar-actions{
  display:flex;
  flex-direction:column;
  gap:8px;
  margin-top:8px;
  flex:1;
  min-height:0;
}

.admin-header-actions{
  display:flex;
  flex-direction:column;
  gap:8px;
  flex:1;
}

.sidebar-actions .btn-icon,
.admin-sidebar .btn-icon{
  width:100%;
  justify-content:flex-start;
  padding:0 16px;
  height:48px;
  border-radius:var(--radius-lg);
  background:transparent;
  border:none;
  color:var(--text);
  transition:all 0.2s ease;
  cursor:pointer;
  box-shadow:none !important;
}

.admin-sidebar .btn-icon:hover{
  background:rgba(59,130,246,0.04) !important;
  color:var(--text) !important;
  border-color:transparent !important;
  transform:translateX(4px);
}

.admin-sidebar .btn-icon.active,
.admin-sidebar .nav-btn.active{
  background:rgba(59,130,246,0.08) !important;
  color:var(--primary) !important;
  border-color:transparent !important;
  font-weight:700;
}

.admin-sidebar .btn-icon.active:hover,
.admin-sidebar .nav-btn.active:hover{
  background:rgba(59,130,246,0.12) !important;
  color:var(--primary) !important;
  border-color:transparent !important;
  transform:translateX(4px);
}

.admin-sidebar .btn-icon i{
  margin-right:12px;
  font-size:19px;
}

.admin-sidebar .btn-icon::after{
  content:attr(title);
  font-size:14px;
  font-weight:600;
}

body.sidebar-open{
  overflow:hidden;
}

/* ============================================= */
/*          TOPBAR MÓVIL                         */
/* ============================================= */
.mobile-topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:16px;
  padding:12px 20px;
  background:var(--panel);
  box-shadow:0 2px 12px rgba(0,0,0,.06);
  position:sticky;
  top:0;
  z-index:100;
  min-height:60px;
}

.mobile-topbar-logo{
  height:38px;
  width:auto;
  flex-shrink:0;
}

/* ============================================= */
/*          MOBILE BOTTOM NAV DOCK               */
/* ============================================= */
.nav-spacer{
  display:none;
}

@media(max-width:768px){
  .mobile-bottom-nav{
    display:grid;
    grid-template-columns:1fr 1fr auto 1fr 1fr;
    align-items:center;
    height:70px;
    background:var(--surface, #fff);
    padding-bottom:env(safe-area-inset-bottom);
    z-index:1000;
  }

  .mobile-bottom-nav .nav-item{
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    gap:4px;
    font-size:10px;
    text-align:center;
  }

  .mobile-bottom-nav .nav-item .nav-label,
  .mobile-bottom-nav .nav-item .nav-text-stack{
    display:none;
  }

  .mobile-bottom-nav .nav-label,
  .mobile-bottom-nav .nav-text-main,
  .mobile-bottom-nav .nav-text-sub{
    font-size:10px;
  }

  .mobile-bottom-nav .nav-item i{
    font-size:22px;
    line-height:1;
  }

  .mobile-bottom-nav .nav-item.active .nav-label,
  .mobile-bottom-nav .nav-item.active .nav-text-stack{
    display:flex;
    flex-direction:column;
    align-items:center;
  }

  .mobile-bottom-nav .nav-item.active i{
    font-size:18px;
  }

  .mobile-bottom-nav .nav-item-desktop-only{
    display:none;
  }

  .mobile-bottom-nav .nav-spacer{
    display:block;
    width:70px;
    pointer-events:none;
  }

  .fab-main-action{
    position:fixed;
    bottom:25px;
    left:50%;
    transform:translateX(-50%);
    width:65px;
    height:65px;
    border-radius:50%;
    background:var(--brand, var(--primary, #1d4ed8));
    color:#fff;
    border:5px solid #f4f6f9;
    box-shadow:0 -4px 10px rgba(0,0,0,0.1);
    z-index:1001;
    display:inline-flex;
    align-items:center;
    justify-content:center;
  }

  .fab-main-action i{
    font-size:28px;
    line-height:1;
  }
}

@media(min-width:769px){
  .fab-main-action{
    display:none;
  }
}

/* ============================================= */
/*          TOPBAR                               */
/* ============================================= */
.topbar{
  position:sticky;
  top:0;
  z-index:10;
  min-height:56px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:8px var(--space-2);
  background:var(--panel);
  border-bottom:none;
  flex-wrap:wrap;
  gap:var(--space-1);
  box-shadow:0 1px 4px rgba(15,23,42,.06);
}

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

.topbar-logo {
  height: clamp(40px, 8vw, 72px);
  width: auto;
  display: block;
}

.topbar-title{
  margin:0;
  font-size:14px;
  font-weight:800;
  letter-spacing:.08em;
  text-transform:uppercase;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.topbar-actions{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}

/* ============================================= */
/*          BARRA SUPERIOR DEL DASHBOARD         */
/* ============================================= */
.content-toolbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:0 6px 12px;
  flex-wrap:wrap;
}

.toolbar-titles{
  display:flex;
  flex-direction:column;
  gap:4px;
}

.toolbar-eyebrow{
  font-size:11px;
  text-transform:uppercase;
  letter-spacing:.14em;
  color:var(--muted);
  font-weight:800;
}

.page-title{
  margin:0;
  font-size:20px;
  font-weight:800;
  letter-spacing:-0.03em;
  color:var(--text);
}

.toolbar-subtitle{
  margin:0;
  color:var(--muted);
  font-size:13px;
  font-weight:600;
}

.toolbar-actions{
  display:flex;
  align-items:center;
  gap:10px;
  margin-left:auto;
}

.mode-toggle{
  display:inline-flex;
  align-items:center;
  gap:10px;
  padding:10px 14px;
  border-radius:12px;
  border:1px solid var(--border);
  background:var(--surface);
  color:var(--text);
  font-weight:700;
  cursor:pointer;
  transition:all 0.2s ease;
  box-shadow:0 10px 28px rgba(0,0,0,0.08);
}

.mode-toggle:hover{
  border-color:var(--primary);
  color:var(--primary);
  box-shadow:0 12px 32px rgba(0,0,0,0.12);
}

.mode-icon{
  display:inline-flex;
  width:28px;
  height:28px;
  border-radius:8px;
  align-items:center;
  justify-content:center;
  background:var(--surface-muted);
  color:inherit;
  font-size:14px;
}

.mode-pill{
  background:var(--primary-soft);
  color:var(--primary);
  padding:4px 10px;
  border-radius:999px;
  font-size:11px;
  letter-spacing:.08em;
  font-weight:800;
}

body.theme-dark .mode-toggle{
  box-shadow:none;
}

body.theme-dark .mode-pill{
  background:rgba(90,168,255,0.18);
  color:var(--text);
}

@media (max-width:768px){
  .content-toolbar{
    align-items:flex-start;
  }
  .toolbar-actions{
    width:100%;
    justify-content:flex-start;
  }
}

.btn-menu{
  display:flex;
  align-items:center;
  justify-content:center;
  width:42px;
  height:42px;
  border-radius:var(--radius);
  background:transparent;
  border:1px solid var(--border);
  font-size:20px;
  cursor:pointer;
  transition:all 0.2s;
  color:var(--text);
  flex-shrink:0;
}

.btn-menu:hover{
  background:var(--surface-muted);
  border-color:var(--primary);
  color:var(--primary);
}

/* ============================================= */
/*          CONTENEDOR PRINCIPAL                 */
/* ============================================= */
.admin-content{
  padding:24px;
  flex:1;
  max-width:100%;
  overflow-x:hidden;
}

/* ============================================= */
/*          GRIDS                                */
/* ============================================= */
.kpis-grid,
.kpi-grid{
  display:grid;
  gap:12px;
  grid-template-columns:repeat(auto-fit,minmax(160px,1fr));
  margin-bottom:var(--space-2);
}

/* ============================================= */
/*          KPI ASYMMETRIC LAYOUT                */
/* ============================================= */
.kpi-asymmetric-layout{
  display:grid;
  grid-template-columns:400px 1fr;
  gap:20px;
  margin-bottom:var(--space-3);
}

/* Gauge Module Card - Izquierda */
.gauge-module-card{
  background:#1A2E50;
  border-radius:var(--radius-lg);
  padding:28px 24px;
  color:#fff;
  box-shadow:0 4px 16px rgba(26, 46, 80, 0.15);
  display:flex;
  flex-direction:column;
  min-height:420px;
}

.gauge-header{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  margin-bottom:16px;
}

.gauge-title{
  font-size:18px;
  font-weight:600;
  margin:0;
  color:#fff;
  letter-spacing:-0.02em;
}

.gauge-menu-btn{
  background:rgba(255, 255, 255, 0.1);
  width:32px;
  height:32px;
  border-radius:var(--radius);
  border:none;
  cursor:pointer;
  display:flex;
  flex-direction:column;
  justify-content:center;
  align-items:center;
  gap:3px;
}

.gauge-menu-btn .dot{
  width:3px;
  height:3px;
  background:rgba(255, 255, 255, 0.4);
  border-radius:50%;
}

.gauge-values{
  display:flex;
  gap:24px;
  margin-bottom:20px;
}

.gauge-value-item{
  display:flex;
  flex-direction:column;
  gap:4px;
}

.gauge-label{
  font-size:11px;
  font-weight:600;
  text-transform:uppercase;
  letter-spacing:0.05em;
  color:rgba(255, 255, 255, 0.6);
}

.gauge-number{
  font-size:28px;
  font-weight:700;
  color:#fff;
  line-height:1;
}

.gauge-chart-container{
  flex:1;
  display:flex;
  justify-content:center;
  align-items:flex-end;
  position:relative;
  padding-bottom:20px;
}

.gauge-svg{
  width:100%;
  max-width:280px;
  height:auto;
}

.gauge-bg{
  stroke:rgba(255, 255, 255, 0.15);
  stroke-width:12;
  stroke-linecap:round;
  fill:none;
}

.gauge-progress{
  stroke:#fff;
  stroke-width:12;
  stroke-linecap:round;
  stroke-dasharray:0, 1000;
  fill:none;
  transition:stroke-dasharray 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.needle-wrapper{
  position:absolute;
  bottom:20px;
  left:50%;
  width:0;
  height:0;
  z-index:10;
}

.needle{
  position:absolute;
  bottom:0;
  left:-1px;
  width:2px;
  height:120px;
  background:linear-gradient(to top, rgba(255,255,255,0.9) 0%, rgba(255,255,255,0.2) 100%);
  transform-origin:bottom center;
  transform:rotate(-90deg);
  transition:transform 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.pivot-dot{
  position:absolute;
  bottom:-5px;
  left:-5px;
  width:10px;
  height:10px;
  background:#fff;
  border-radius:50%;
  box-shadow:0 0 8px rgba(255, 255, 255, 0.3);
}

/* KPI Stack - Derecha */
.kpi-stack{
  display:grid;
  grid-template-columns:repeat(3, 1fr);
  gap:14px;
  align-content:start;
}

.kpi-card.kpi-compact{
  min-height:90px;
}

.charts-grid{
  display:grid;
  gap:var(--space-2);
  grid-template-columns:repeat(4,1fr);
  margin-bottom:var(--space-2);
  grid-auto-rows:1fr;
}

.charts-grid-secondary{
  display:grid;
  gap:var(--space-2);
  margin-bottom:var(--space-2);
  grid-template-columns:repeat(auto-fit,minmax(280px,1fr));
}

.charts-grid-secondary .chart-card {
  background:var(--panel);
  border:none;
  border-radius:var(--radius-lg);
  box-shadow:0 6px 18px rgba(16,24,40,.06);
  overflow:hidden;
  display:flex;
  flex-direction:column;
}

.charts-grid-secondary .chart-card [style*="gap: 32px"]{
  gap:16px;
}

@media(max-width:768px){
  .charts-grid-secondary .chart-card [style*="gap: 32px"],
  .charts-grid-secondary .chart-card [style*="gap: 16px"]{
    gap:8px !important;
  }

  .charts-grid-secondary .chart-card .chart[style*="width: 220px"]{
    width:180px;
    height:180px;
  }
}

/* ============================================= */
/*          RESPONSIVE - DESKTOP                 */
/* ============================================= */
@media(min-width:1024px){
  .app-shell{
    flex-direction:row;
  }

  .mobile-topbar{
    display:none;
  }

  .admin-sidebar{
    position:static;
    transform:translateX(0);
    box-shadow:none;
  }
  
  .btn-menu{
    display:none;
  }
  
  .sidebar-backdrop{
    display:none;
  }
  
  .admin-content{
    padding:28px;
  }
  
  .kpis-grid,
  .kpi-grid{
    grid-template-columns:repeat(6,1fr);
  }
  
  .charts-grid{
    grid-template-columns:repeat(2,1fr);
  }
}

@media(min-width:768px){
  .topbar{
    padding:8px var(--space-3);
  }
  
  .topbar-title{
    font-size:16px;
  }
  
  .topbar-logo{
    height:clamp(48px, 6vw, 72px);
  }
  
  /* Layout de gráficos - 4 columnas en desktop */
  .charts-grid{
    grid-template-columns:repeat(4,1fr);
  }
  
  /* Altura uniforme para charts */
  .charts-grid .chart{
    height:var(--chart-h);
    aspect-ratio:auto;
    min-height:0;
  }
  
  .lists-grid{
    grid-template-columns:1fr 1fr;
  }
  
  .content-area{
    padding:24px;
  }
  
  .kpi-grid,
  .kpis-grid{
    grid-template-columns:repeat(4,1fr);
  }
}

/* ============================================= */
/*          RESPONSIVE - TABLET                  */
/* ============================================= */
@media(max-width:1024px){
  .kpi-asymmetric-layout{
    grid-template-columns:1fr;
    gap:16px;
  }
  
  .gauge-module-card{
    min-height:360px;
  }
  
  .kpi-stack{
    grid-template-columns:repeat(3, 1fr);
  }
}

/* ============================================= */
/*          RESPONSIVE - MOBILE                  */
/* ============================================= */
@media(max-width:720px){
  .admin-content{
    padding:16px;
  }

  .content-area{
    padding:12px;
  }
  
  .charts-grid{
    grid-template-columns:repeat(2, 1fr);
    gap:12px;
  }

  .charts-grid .chart-card:first-child{
    grid-column:1 / -1;
  }

  .charts-grid-secondary, .lists-grid{
    grid-template-columns:1fr;
  }
  
  .chart, .charts-grid-secondary .chart{
    min-height:200px;
  }
  
  .search-input-wrapper{
    flex-direction:column;
    align-items:stretch;
  }
  
  .search-input-wrapper .btn-icon{
    width:100%;
    height:var(--h);
  }
  
  #username-display{
    width:100%;
  }
  
  .admin-header-actions{
    width:100%;
    justify-content:flex-start;
  }
  
  .kpi-asymmetric-layout{
    grid-template-columns:1fr;
  }
  
  .kpi-stack{
    grid-template-columns:repeat(2, 1fr);
    gap:10px;
  }
  
  .gauge-module-card{
    min-height:320px;
    padding:20px 18px;
  }
  
  .gauge-number{
    font-size:24px;
  }
  
  .gauge-title{
    font-size:16px;
  }

  .kpis-grid, .kpi-grid{
    grid-template-columns:repeat(2, 1fr);
    gap:10px;
  }
}

/* ============================================= */
/*          FOOTER                               */
/* ============================================= */
.admin-footer{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:12px;
  padding:20px;
  background:var(--surface);
  color:var(--text);
  font-size:0.9rem;
  margin-top:auto;
  border-top: 1px solid var(--border);
}

.admin-footer img{
  height:24px;
  width:auto;
}

/* ============================================= */
/*          CONTROL BAR UNIFICADO               */
/* ============================================= */
.analytics-control-bar {
  background: var(--panel);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}

.control-row {
  display: flex;
  gap: 20px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 200px;
}

.control-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--muted);
  margin: 0;
}

/* Date Range Group */
.date-range-group {
  display: flex;
  background: var(--surface-muted);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.date-btn {
  padding: 8px 16px;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  white-space: nowrap;
}

.date-btn:hover {
  color: var(--primary);
  background: rgba(255, 255, 255, 0.5);
}

.date-btn.active {
  background: #fff;
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Search Field */
.search-field-container {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search-field-container input {
  width: 100%;
  padding-right: 38px;
}

.btn-icon-inside {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  transition: all 0.2s;
}

.btn-icon-inside:hover {
  background: var(--primary-soft);
}

/* Responsive */
@media(max-width:768px){
  .control-row {
    flex-direction: column;
    gap: 12px;
  }
  
  .control-group {
    min-width: 100%;
  }
  
  .date-range-group {
    flex-wrap: wrap;
  }
  
  .date-btn {
    flex: 1;
    min-width: 60px;
  }
}

/* ============================================= */
/*          FILTROS LEGACY (DEPRECADOS)         */
/* ============================================= */
/* ============================================= */
/*          FILTROS LEGACY (DEPRECADOS)         */
/* ============================================= */
/* NOTA: Estilos mantenidos para compatibilidad - migrar a analytics-control-bar */
.filters-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
  margin: 0;
}

/* Pills antiguas (deprecado - usar date-btn) */
.range-selector-wrapper {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

.range-preset-pills {
  display: flex;
  gap: 4px;
}

.preset-pill {
  padding: 8px 12px;
  border: none;
  background: var(--surface-muted);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.preset-pill:hover {
  color: var(--primary);
  background: var(--primary-soft);
}

.preset-pill.active {
  background: var(--primary);
  color: #fff;
}

.search-input-wrapper {
  display: flex;
  gap: 6px;
  align-items: stretch;
}

/* Responsive para filtros */
@media(min-width:640px){
  .filters-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
}

@media(min-width:768px){
  .filters-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    align-items: end;
  }
  
  .range-selector-wrapper {
    flex-direction: column;
    gap: 5px;
  }
}

@media(min-width:1024px){
  .filters-grid {
    grid-template-columns: 140px 1fr 1.8fr 1.4fr;
    gap: 14px;
  }
  
  .range-selector-wrapper {
    flex-direction: row;
    gap: 6px;
  }
}

@media(max-width:520px){
  .filters-grid{
    gap:10px;
  }
  
  .card{
    margin-bottom:10px;
  }
  
  .kpi-card, .chart-card, .analytics-chart-card{
    min-width:0;
  }
}
