/* ============================================================
   GOCHECK - Estilos compartidos
   ============================================================ */
:root {
  --azul:      #1ca4fc;
  --azul-osc:  #0d7dcc;
  --azul-claro:#e5f4ff;
  --gris-bg:    #f4f6f8;
  --gris-linea: #e2e6ea;
  --texto:      #1f2933;
  --texto-sec:  #647380;
  --rojo:       #c0392b;
  --rojo-bg:    #fdecea;
  --amarillo:   #b7791f;
  --amarillo-bg:#fdf6e3;
  --sombra:     0 2px 10px rgba(0,0,0,.06);
  --radio:      10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--texto);
  background: var(--gris-bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- LOGIN ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #0d7dcc 0%, #1ca4fc 100%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
  padding: 40px 34px;
}
.brand {
  text-align: center;
  margin-bottom: 26px;
}
.brand img.logo-img {
  width: 210px;
  max-width: 78%;
  height: auto;
  display: block;
  margin: 0 auto 6px;
}
.brand h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: 1px;
  color: var(--azul-osc);
  font-weight: 800;
}
.brand .sub {
  color: var(--texto-sec);
  font-size: 13px;
  margin-top: 4px;
}

/* ---------- FORM ---------- */
label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 14px 0 6px;
  color: var(--texto);
}
input, select, textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--gris-linea);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--texto);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--azul);
  box-shadow: 0 0 0 3px rgba(28,164,252,.18);
}
textarea { resize: vertical; min-height: 60px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn-primary { background: var(--azul); color: #fff; width: 100%; }
.btn-primary:hover { background: var(--azul-osc); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-ghost { background: transparent; color: var(--texto-sec); border: 1px solid var(--gris-linea); }
.btn-ghost:hover { background: var(--gris-bg); }
.btn-danger { background: var(--rojo); color: #fff; }
.btn-danger:hover { opacity: .9; }

.msg {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  display: none;
}
.msg.error { display: block; background: var(--rojo-bg); color: var(--rojo); }
.msg.ok    { display: block; background: var(--azul-claro); color: var(--azul-osc); }

/* ---------- APP LAYOUT ---------- */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--gris-linea);
  padding: 0 22px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .logo {
  font-size: 22px;
  font-weight: 800;
  color: var(--azul-osc);
  letter-spacing: .5px;
  display: flex;
  align-items: center;
}
.topbar .logo img { height: 30px; width: auto; display: block; }
.topbar .user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--texto-sec);
}
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 22px 60px;
}

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--gris-linea);
}
.tab {
  padding: 11px 18px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--texto-sec);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab.active { color: var(--azul-osc); border-bottom-color: var(--azul); }

.card {
  background: #fff;
  border: 1px solid var(--gris-linea);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { margin: 0 0 16px; font-size: 17px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}
.grid .full { grid-column: 1 / -1; }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { background: #fff; border: 1px solid var(--gris-linea); border-radius: var(--radio); padding: 16px 18px; box-shadow: var(--sombra); }
.kpi .n { font-size: 26px; font-weight: 800; color: var(--azul-osc); }
.kpi .l { font-size: 12px; color: var(--texto-sec); margin-top: 2px; }

/* ---------- TABLA ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--gris-linea); white-space: nowrap; }
th { background: var(--gris-bg); font-weight: 700; color: var(--texto-sec); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
tbody tr:hover { background: #fafbfc; }
td.wrap, th.wrap { white-space: normal; min-width: 160px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.badge.peligroso     { background: var(--rojo-bg); color: var(--rojo); }
.badge.no_peligroso  { background: var(--azul-claro); color: var(--azul-osc); }
.badge.admin         { background: #efe6ff; color: #6b3fbf; }
.badge.usuario       { background: var(--gris-bg); color: var(--texto-sec); }
.badge.si            { background: var(--azul-claro); color: var(--azul-osc); }
.badge.no            { background: var(--rojo-bg); color: var(--rojo); }

.rol-chip {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 11.5px; font-weight: 700; background: #efe6ff; color: #6b3fbf;
}
.rol-chip.usuario { background: var(--azul-claro); color: var(--azul-osc); }

.empty { text-align: center; color: var(--texto-sec); padding: 30px; font-size: 14px; }
.link-btn { background: none; border: none; color: var(--azul); cursor: pointer; font-size: 13px; font-weight: 600; padding: 2px 6px; }
.link-btn.del { color: var(--rojo); }

/* ---------- Carga de PDF ---------- */
.pdf-drop {
  border: 1.5px dashed var(--gris-linea); border-radius: var(--radio);
  padding: 14px 16px; background: #fbfcfd;
}
.pdf-drop input[type=file] { border: none; padding: 6px 0; background: transparent; }
.pdf-hint { font-size: 12.5px; margin-top: 6px; min-height: 16px; }
.pdf-hint.ok  { color: var(--azul-osc); }
.pdf-hint.err { color: var(--rojo); }
.pdf-link { color: var(--azul); font-weight: 600; text-decoration: none; cursor: pointer; }
.pdf-link:hover { text-decoration: underline; }

/* ---------- Líneas de residuo ---------- */
.items-head, .item-row {
  display: grid;
  grid-template-columns: 2.4fr 1fr 0.9fr 2fr 34px;
  gap: 8px; align-items: center;
}
.items-head { margin: 6px 0; font-size: 11.5px; font-weight: 700; color: var(--texto-sec); text-transform: uppercase; letter-spacing: .3px; }
.item-row { margin-bottom: 8px; }
.item-row input { padding: 8px 10px; }
.item-del {
  border: none; background: var(--rojo-bg); color: var(--rojo); border-radius: 8px;
  height: 34px; cursor: pointer; font-size: 16px; font-weight: 700; line-height: 1;
}
.item-del:hover { opacity: .85; }
@media (max-width: 720px) {
  .items-head { display: none; }
  .item-row { grid-template-columns: 1fr 1fr; }
}

.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters > div { display: flex; flex-direction: column; }
.filters label { margin: 0 0 4px; }
.filters input, .filters select { min-width: 150px; }

@media (max-width: 600px) {
  .topbar .user .email { display: none; }
  .container { padding: 16px 14px 50px; }
}

/* ============================================================
   LAYOUT CON MENÚ LATERAL
   ============================================================ */
.app-body { background: var(--gris-bg); }
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px; background: #fff; border-right: 1px solid var(--gris-linea);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar-logo { padding: 22px 18px 16px; border-bottom: 1px solid var(--gris-linea); text-align: center; }
.sidebar-logo img { height: 54px; width: auto; max-width: 100%; display: block; margin: 0 auto; }
.sidebar-lema { text-align: center; font-size: 13px; font-weight: 600; letter-spacing: .3px; color: var(--texto-sec); margin-top: 8px; }
.nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-group { font-size: 14px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px; color: var(--azul-osc); padding: 16px 12px 7px; }
.nav-item {
  display: block; padding: 10px 12px; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--texto); text-decoration: none; margin-bottom: 2px;
}
.nav-item:hover { background: var(--gris-bg); }
.nav-item.active { background: var(--azul-claro); color: var(--azul-osc); }
.sidebar-user { padding: 14px 16px; border-top: 1px solid var(--gris-linea); font-size: 13px; }
.su-name { font-weight: 600; color: var(--texto); margin-bottom: 4px; word-break: break-word; }
.su-rol { margin-bottom: 10px; }
.sidebar-user .btn { width: 100%; }

.main { flex: 1; min-width: 0; }
.main-head {
  height: 60px; background: #fff; border-bottom: 1px solid var(--gris-linea);
  display: flex; align-items: center; gap: 12px; padding: 0 22px; position: sticky; top: 0; z-index: 5;
}
.main-head h1 { font-size: 18px; margin: 0; }
.hamb { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--texto); }
.view { padding: 22px; max-width: 1300px; }

.toolbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar-right { display: flex; gap: 8px; align-items: flex-end; }

/* Botón cargar PDF por fila */
.btn-pdf {
  background: var(--azul); color: #fff; border: none; border-radius: 7px;
  padding: 6px 10px; font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn-pdf:hover { background: var(--azul-osc); }
.btn-pdf.has { background: var(--azul-claro); color: var(--azul-osc); }

/* Permisos (roles) */
.perms { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px,1fr)); gap: 8px; margin-top: 8px; }
.chk { display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13.5px; margin: 0; cursor: pointer; }
.chk input { width: auto; }

@media (max-width: 820px) {
  .sidebar { position: fixed; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .hamb { display: block; }
}

/* ---------- Ojo mostrar contraseña ---------- */
.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 42px; }
.pass-wrap .eye {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 18px; line-height: 1;
  padding: 4px 6px; color: var(--texto-sec);
}

/* ---------- Columna de selección (solo admin) ---------- */
.col-sel { display: none; text-align: center; width: 36px; }
.is-admin .col-sel { display: table-cell; }
.col-sel input { width: auto; cursor: pointer; }

/* ---------- Fila superior: KPI + gráfico ---------- */
.top-row { display: flex; gap: 14px; margin-bottom: 20px; align-items: stretch; }
.kpi-big { display: flex; flex-direction: column; justify-content: center; min-width: 200px; }
.kpi-big .n { font-size: 40px; }
.chart-card { flex: 1; margin-bottom: 0; }
.chart-box { position: relative; height: 260px; }
@media (max-width: 820px) {
  .top-row { flex-direction: column; }
  .chart-box { height: 220px; }
}

/* ============================================================
   AJUSTES v2: menú destacado/colapsable, densidad, KPIs
   ============================================================ */
/* Botón para mostrar/ocultar el menú, siempre visible */
.hamb { display: block; }
@media (min-width: 821px) {
  .app.sb-hidden .sidebar { display: none; }
}

/* Módulos principales resaltados */
.nav-main { font-size: 15px; font-weight: 800; padding: 12px 12px; margin-bottom: 5px; border: 1px solid transparent; border-radius: 9px; }
.nav-main .ni-ico { margin-right: 5px; font-size: 12px; }
.nav-main:hover { background: var(--azul-claro); }
.nav-main.active { background: var(--azul-claro); color: var(--azul-osc); border-color: #bfe3ff; }
.nav-item:not(.nav-main) { font-size: 12.5px; font-weight: 600; padding: 8px 12px; color: var(--texto-sec); }
.nav-item:not(.nav-main).active { color: var(--azul-osc); }

/* KPIs en columna: Total / Plástico / Cartón */
.kpi-col { display: flex; flex-direction: column; gap: 10px; min-width: 168px; }
.kpi-col .kpi { padding: 12px 16px; margin: 0; }
.kpi-col .kpi .n { font-size: 23px; }

/* Densidad: letra más compacta para ver más filas */
table { font-size: 12px; }
th, td { padding: 6px 9px; }
th { font-size: 11px; }
.view { padding: 16px; }
.card { padding: 16px; }
.card h2 { font-size: 15px; margin-bottom: 12px; }
.btn-pdf { padding: 5px 8px; font-size: 11px; }
.main-head h1 { font-size: 17px; }

/* KPIs en una sola línea (Total / Plástico / Cartón) */
.kpis-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }
.kpis-3 .kpi { padding: 14px 18px; }
.chart-card { margin-bottom: 20px; }
@media (max-width: 560px) { .kpis-3 { grid-template-columns: 1fr; } }

/* Botón vincular PDF de Google Drive por fila */
.btn-drive { background: #fff; border: 1px solid var(--gris-linea); color: var(--texto-sec); border-radius: 7px; padding: 5px 8px; font-size: 11px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn-drive:hover { background: var(--gris-bg); }

/* v8: KPIs y gráfico más compactos */
.kpis-3 { gap: 12px; margin-bottom: 12px; }
.kpis-3 .kpi { padding: 10px 14px; }
.kpis-3 .kpi .n { font-size: 20px; }
.kpis-3 .kpi .l { font-size: 11px; }
.chart-card { padding: 12px 14px; margin-bottom: 14px; }
.chart-card h2 { font-size: 13px; margin-bottom: 8px; }
.chart-box { height: 170px; }
@media (max-width: 820px) { .chart-box { height: 150px; } }

/* Columnas ordenables */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--azul-osc); }
th.sort-activo { color: var(--azul-osc); }

/* Nota junto al título */
.head-note { font-size: 12px; color: var(--texto-sec); font-weight: 500; font-style: italic; }
@media (max-width: 600px) { .head-note { display: none !important; } }
.head-reloj { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--texto-sec); white-space: nowrap; }
.head-reloj .hr-fecha { text-transform: capitalize; font-weight: 600; color: var(--texto); }
.head-reloj .hr-sem { font-weight: 500; }
.head-reloj .hr-hora { font-weight: 700; color: var(--azul-osc); font-variant-numeric: tabular-nums; }
.head-reloj .hr-sep { color: var(--gris-linea); }
@media (max-width: 760px) { .head-reloj { display: none !important; } }

/* ============================================================
   Recuperar contraseña (enlace en login)
   ============================================================ */
.link-forgot { color: var(--azul); font-size: 13px; text-decoration: none; }
.link-forgot:hover { text-decoration: underline; }

/* ============================================================
   Botón secundario y modal de inactividad
   ============================================================ */
.btn-sec { background: #e4e7eb; color: #1f2933; }
.btn-sec:hover { background: #d2d6dc; }

.idle-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: none; align-items: center; justify-content: center; z-index: 9999;
}
.idle-overlay.show { display: flex; }
.idle-box {
  background: #fff; border-radius: 14px; padding: 26px 28px;
  width: min(92vw, 360px); box-shadow: 0 20px 50px rgba(0,0,0,.3); text-align: center;
}
.idle-box h3 { margin: 0 0 8px; font-size: 19px; color: #1f2933; }
.idle-box p  { margin: 0 0 18px; color: #52606d; font-size: 14px; }
.idle-box b  { color: var(--azul-osc); }
.idle-actions { display: flex; gap: 10px; justify-content: center; }
.idle-actions .btn { width: auto; padding: 10px 16px; }

/* ============================================================
   PORTAL de servicios (multiempresa)
   ============================================================ */
.portal-body { background: var(--gris-bg, #f1f5f9); margin: 0; min-height: 100vh; }
.portal-top {
  background: #fff; border-bottom: 1px solid var(--gris-linea, #e4e7eb);
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 26px; gap: 16px;
}
.portal-logo { height: 40px; width: auto; max-width: 200px; object-fit: contain; }
.portal-user { display: flex; align-items: center; gap: 14px; text-align: right; }
.pu-org  { font-weight: 700; color: var(--azul-osc); font-size: 14px; }
.pu-name { color: var(--texto-sec, #52606d); font-size: 13px; }
.portal-main { max-width: 960px; margin: 0 auto; padding: 40px 24px; }
.portal-title { font-size: 24px; margin: 0 0 4px; color: #1f2933; }
.portal-sub { color: var(--texto-sec, #64748b); margin: 0 0 28px; }
.portal-cards { display: flex; flex-wrap: wrap; gap: 20px; }
.svc-card {
  background: #fff; border-radius: 16px; padding: 24px; width: 280px;
  box-shadow: 0 8px 24px rgba(0,0,0,.07); border-top: 4px solid var(--azul);
  display: flex; flex-direction: column; gap: 8px;
}
.svc-card.svc-off { opacity: .6; border-top-color: #cbd2d9; }
.svc-ico { font-size: 34px; }
.svc-nom { font-weight: 700; font-size: 17px; color: #1f2933; }
.svc-desc { color: var(--texto-sec, #64748b); font-size: 13px; flex: 1; }
.svc-btn { width: auto; align-self: flex-start; margin-top: 8px; }
.svc-prep {
  align-self: flex-start; margin-top: 8px; font-size: 12px; font-weight: 600;
  color: #7b8794; background: #eef1f4; padding: 6px 12px; border-radius: 8px;
}

/* Selector de empresa para el super administrador */
.org-switch {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--gris-linea); border-left: 4px solid var(--azul);
  border-radius: 12px; padding: 12px 16px; margin-bottom: 22px;
}
.org-switch label { font-weight: 700; color: var(--texto); margin: 0; }
.org-switch select {
  padding: 8px 12px; border: 1px solid var(--gris-linea); border-radius: 8px;
  font-size: 14px; min-width: 200px; background: #fff;
}
.org-switch-hint { color: var(--texto-sec); font-size: 12px; }

/* Módulo de seguridad */
.sec-desc { color: var(--texto-sec); font-size: 14px; margin: 0 0 14px; max-width: 72ch; line-height: 1.5; }

/* Enlace a la resolución oficial junto al título */
.head-res {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; font-weight: 600; color: var(--azul-osc);
  text-decoration: none; background: var(--azul-claro);
  padding: 4px 10px; border-radius: 8px; white-space: nowrap;
}
.head-res:hover { text-decoration: underline; }

/* Módulo Mano de Obra */
.kpi-comp { font-size: 11px; margin-top: 4px; color: var(--texto-sec); }
.kpi-comp.up { color: #b23b3b; }      /* costo sube = rojo */
.kpi-comp.down { color: #2e7d32; }    /* costo baja = verde */
.fila-total td { background: var(--azul-claro); }
.progress { height: 10px; background: #e4e7eb; border-radius: 6px; overflow: hidden; margin-top: 12px; }
.progress-fill { height: 100%; width: 0; background: var(--azul); transition: width .2s; }

/* Spinner de trabajo (importación) */
.cargando-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: none; align-items: center; justify-content: center; z-index: 9999; }
.cargando-box { background: #fff; border-radius: 14px; padding: 26px 30px; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.3); max-width: 90vw; }
.cargando-box #cargandoTxt { margin-top: 14px; color: #1f2933; font-size: 14px; max-width: 320px; }
.spinner { width: 44px; height: 44px; margin: 0 auto; border: 5px solid var(--azul-claro); border-top-color: var(--azul); border-radius: 50%; animation: girar 0.9s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }

/* Aviso de privacidad en el login */
.login-aviso { margin-top: 16px; font-size: 12px; color: var(--texto-sec); text-align: center; line-height: 1.5; }
.login-aviso a { color: var(--azul-osc); }

/* Tickets de recepción final (verde con enlace / rojo pendiente) */
.rf-ok   { color: #2e7d32; font-weight: 600; cursor: pointer; margin-right: 6px; white-space: nowrap; }
.rf-ok:hover { text-decoration: underline; }
.rf-pend { color: var(--rojo); font-weight: 600; margin-right: 6px; white-space: nowrap; }

/* Filas de residuos del SIDREP (revisión OCR) */
.sid-item { display: flex; gap: 8px; margin: 6px 0; align-items: center; flex-wrap: wrap; }
.sid-item input { padding: 7px 9px; border: 1px solid var(--gris-linea); border-radius: 8px; font-size: 13px; }
.sid-item .si-desc { flex: 1; min-width: 200px; }
.sid-item .si-cod { max-width: 110px; }
.sid-item .si-pel { max-width: 130px; }
.sid-item .si-kg { max-width: 100px; }
