/* =========================================================================
   Montra · Gestión de Servicios — Sistema de diseño
   Estilo: profesional y serio, con toques modernos.
   - Barra lateral oscura + contenido claro (contraste sobrio y actual).
   - Navegación tipo app: sidebar en escritorio, barra inferior en celular.
   - Tipografía DM Sans, acento rojo Montra, esquinas suaves y sombras sutiles.
   Se conservan los nombres de clase existentes (card, btn, kpi, tabla, badge,
   form-grid, equipo-lista, tarea, encuesta, firma...) para no romper el JS.
   ========================================================================= */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&display=swap');

:root {
  /* Marca */
  --rojo: #e2001a;
  --rojo-osc: #b30015;
  --rojo-soft: #fff0f1;
  /* Alias antiguos (compatibilidad con estilos/inline previos) */
  --negro: #12151d;
  --azul: #1f2937;          /* antes "azul", hoy tinta oscura neutra */
  --azul-claro: #e2001a;    /* acción principal = rojo */

  /* Neutros */
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --ink: #14171f;           /* títulos */
  --text: #363d49;          /* texto normal */
  --gris-texto: #697080;    /* texto atenuado */
  --gris-bg: #f3f5f9;
  --gris-borde: #e6e9f0;
  --borde: #e6e9f0;

  /* Semáforo */
  --verde: #17935a;  --verde-soft: #e6f6ee;
  --amarillo: #c98a00; --amarillo-soft: #fdf3da;
  --rojo-alerta: #d92d20; --rojo-alerta-soft: #fdecea;
  --info: #2b6cb0;  --info-soft: #e9f1fb;

  /* Barra lateral oscura */
  --side-bg: #12151d;
  --side-bg-2: #171b26;
  --side-text: #c3c9d6;
  --side-muted: #7b8598;
  --side-hover: rgba(255,255,255,0.07);

  /* Formas */
  --radio: 14px;
  --radio-sm: 10px;
  --radio-pill: 999px;
  --sombra-sm: 0 1px 2px rgba(16,24,40,0.06);
  --sombra: 0 4px 18px rgba(16,24,40,0.07);
  --sombra-lg: 0 14px 38px rgba(16,24,40,0.14);
  font-size: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
.anchor-sec { scroll-margin-top: 78px; }

body {
  margin: 0;
  font-family: 'DM Sans', system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { color: var(--ink); }

/* =========================================================================
   APP SHELL — sidebar + contenido
   ========================================================================= */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px 1fr;
  background: var(--bg);
}

/* --- Barra lateral (escritorio) --- */
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  background: linear-gradient(180deg, var(--side-bg-2), var(--side-bg));
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  padding: 1.1rem 0.85rem 0.9rem;
  gap: 0.6rem;
}
.sidebar .brand { display: flex; align-items: center; gap: 0.6rem; padding: 0.2rem 0.5rem 0.9rem; }
.sidebar .brand img { height: 30px; width: auto; display: block; }
.sidebar .brand .sub {
  font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--side-muted); margin-top: 2px;
}
.side-nav { display: flex; flex-direction: column; gap: 3px; overflow-y: auto; flex: 1; }
.side-nav::-webkit-scrollbar { width: 6px; }
.side-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }

/* Los ítems de navegación reutilizan .tab (los enlaza el JS por data-tab). */
.side-nav .tab, .side-link {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.68rem 0.8rem;
  border-radius: var(--radio-sm);
  color: var(--side-text);
  font-weight: 600; font-size: 0.92rem;
  cursor: pointer; border: none; background: transparent;
  text-align: left; text-decoration: none; width: 100%;
  transition: background 0.15s, color 0.15s;
}
.side-nav .tab .ico, .side-link .ico { font-size: 1.05rem; width: 1.3rem; text-align: center; flex-shrink: 0; }
.side-nav .tab:hover, .side-link:hover { background: var(--side-hover); color: #fff; }
.side-nav .tab.activo {
  background: var(--rojo); color: #fff;
  box-shadow: 0 8px 20px rgba(226,0,26,0.32);
}
.side-foot { border-top: 1px solid rgba(255,255,255,0.08); padding-top: 0.7rem; margin-top: 0.3rem; }
.side-foot .user { display: block; color: #fff; font-weight: 600; font-size: 0.85rem; }
.side-foot .role { display: block; color: var(--side-muted); font-size: 0.72rem; margin-bottom: 0.6rem; }
.side-foot .btn-logout, .side-foot .btn-ghost { width: 100%; justify-content: center; margin-top: 0.4rem; }

/* --- Contenido --- */
.main { min-width: 0; display: flex; flex-direction: column; }
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255,255,255,0.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--borde);
  padding: 0.85rem 1.4rem;
  display: flex; align-items: center; gap: 0.8rem;
}
.appbar .brand-mini { display: none; align-items: center; gap: 0.5rem; }
.appbar .brand-mini img { height: 24px; }
.appbar h1 { font-size: 1.12rem; margin: 0; font-weight: 700; }
.appbar .spacer { flex: 1; }
.content {
  padding: 1.3rem 1.4rem 3rem;
  width: 100%; max-width: 1120px; margin: 0 auto;
}

/* --- Botón hamburguesa (solo celular) --- */
.hamburger {
  display: none;
  align-items: center; justify-content: center;
  width: 42px; height: 42px; flex-shrink: 0;
  background: transparent; border: 1px solid var(--gris-borde);
  border-radius: var(--radio-sm); cursor: pointer;
  color: var(--ink); font-size: 1.25rem; line-height: 1;
}
.hamburger:hover { background: var(--surface-2); }

/* Fondo oscuro tras el drawer abierto */
.nav-backdrop { display: none; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .appbar .brand-mini { display: flex; }
  .hamburger { display: inline-flex; }
  .content { padding: 1rem 1rem 2rem; }

  /* La barra lateral se convierte en un cajón (drawer) deslizante */
  .sidebar {
    display: flex;
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 90;
    width: 270px; max-width: 82vw; height: 100vh;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 6px 0 28px rgba(0,0,0,0.28);
  }
  .app.nav-open .sidebar { transform: translateX(0); }

  .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 80;
    background: rgba(8,10,16,0.5);
    opacity: 0; pointer-events: none; transition: opacity 0.2s;
  }
  .app.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }

  /* Bloquea el scroll de fondo cuando el cajón está abierto */
  body:has(.app.nav-open) { overflow: hidden; }
}

/* =========================================================================
   Encabezado clásico (login, técnico, orden de servicio)
   ========================================================================= */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--borde);
  color: var(--ink);
  padding: 0.7rem 1.2rem;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
  box-shadow: var(--sombra-sm);
}
.topbar .brand { display: flex; align-items: center; gap: 0.7rem; }
.topbar .brand img { height: 30px; width: auto; display: block; }
.topbar h1 { font-size: 1.05rem; margin: 0; font-weight: 700; }
.topbar .user { font-size: 0.85rem; color: var(--gris-texto); }
.topbar .right { display: flex; align-items: center; gap: 0.7rem; }

/* =========================================================================
   Contenedores y tarjetas
   ========================================================================= */
.container { max-width: 820px; margin: 0 auto; padding: 1.1rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 1.15rem 1.2rem;
  margin-bottom: 1.1rem;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.section-title { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--gris-texto); font-weight: 700; margin: 0.4rem 0 0.6rem; }

/* =========================================================================
   Botones
   ========================================================================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  min-height: 46px; padding: 0.6rem 1.15rem;
  border: none; border-radius: var(--radio-sm);
  background: var(--rojo); color: #fff;
  font-size: 0.98rem; font-weight: 600; font-family: inherit;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 6px 16px rgba(226,0,26,0.20);
}
.btn:hover { background: var(--rojo-osc); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
.btn-block { width: 100%; }
.btn-verde { background: var(--verde); box-shadow: 0 6px 16px rgba(23,147,90,0.22); }
.btn-verde:hover { background: #127645; }
.btn-gris { background: #667085; box-shadow: none; }
.btn-gris:hover { background: #525b6b; }
.btn-outline {
  background: var(--surface); color: var(--ink);
  border: 1.5px solid var(--gris-borde); box-shadow: var(--sombra-sm);
}
.btn-outline:hover { background: var(--surface-2); border-color: var(--rojo); color: var(--rojo-osc); }
.btn-logout, .btn-ghost {
  background: transparent; color: var(--gris-texto);
  border: 1px solid var(--gris-borde);
  min-height: 38px; padding: 0.35rem 0.8rem;
  border-radius: var(--radio-sm); font-size: 0.85rem; font-weight: 600;
  cursor: pointer; box-shadow: none;
}
.btn-logout:hover, .btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
/* En la barra lateral oscura, el botón de salir va claro */
.sidebar .btn-logout, .sidebar .btn-ghost {
  color: var(--side-text); border-color: rgba(255,255,255,0.16); background: rgba(255,255,255,0.04);
}
.sidebar .btn-logout:hover, .sidebar .btn-ghost:hover { background: rgba(255,255,255,0.12); color: #fff; }

/* =========================================================================
   Formularios
   ========================================================================= */
label { display: block; font-weight: 600; margin: 0.65rem 0 0.28rem; font-size: 0.88rem; color: var(--ink); }
input, select, textarea {
  width: 100%; min-height: 46px;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio-sm);
  font-size: 0.98rem; font-family: inherit;
  background: var(--surface); color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--rojo);
  box-shadow: 0 0 0 3px var(--rojo-soft);
}
textarea { min-height: 92px; resize: vertical; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.15rem 1rem;
}
.form-grid label { margin-top: 0.45rem; }

/* =========================================================================
   Login
   ========================================================================= */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background:
    radial-gradient(1100px 500px at 90% -10%, rgba(226,0,26,0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(18,21,29,0.08), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 400px; padding: 1.8rem 1.6rem;
  box-shadow: var(--sombra-lg); border: 1px solid var(--borde);
}
.login-card h2 { text-align: center; margin: 0.2rem 0 0.1rem; }

/* =========================================================================
   Lista de servicios (tarjetas)
   ========================================================================= */
.servicio {
  display: flex; justify-content: space-between; align-items: center; gap: 0.6rem;
  cursor: pointer; transition: box-shadow 0.15s, transform 0.06s, border-color 0.15s;
  border-left: 4px solid transparent;
}
.servicio:hover { box-shadow: var(--sombra-lg); border-left-color: var(--rojo); }
.servicio:active { transform: translateY(1px); }
.servicio h3 { margin: 0 0 0.2rem; font-size: 1rem; }
.servicio small { color: var(--gris-texto); }

/* =========================================================================
   Badges de estado
   ========================================================================= */
.badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.22rem 0.65rem; border-radius: var(--radio-pill);
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em;
}
.badge.asignado { background: var(--info-soft); color: var(--info); }
.badge.en_proceso { background: var(--amarillo-soft); color: var(--amarillo); }
.badge.completado, .badge.cerrado { background: var(--verde-soft); color: var(--verde); }
.badge.cancelado { background: var(--rojo-alerta-soft); color: var(--rojo-alerta); }
.badge.rol-admin { background: #efe7fb; color: #7c3aed; }
.badge.rol-lider { background: var(--info-soft); color: var(--info); }
.badge.rol-tecnico { background: var(--verde-soft); color: var(--verde); }
.badge.inactivo { background: #eef0f4; color: #6b7280; }

/* =========================================================================
   KPIs
   ========================================================================= */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.9rem; margin-bottom: 1.1rem;
}
.kpi {
  position: relative; overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 1.05rem 1.1rem;
}
.kpi::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--rojo);
}
.kpi.verde::before { background: var(--verde); }
.kpi.rojo::before { background: var(--rojo-alerta); }
.kpi.naranja::before { background: var(--amarillo); }
.kpi .valor { font-size: 1.9rem; font-weight: 800; color: var(--ink); line-height: 1.05; }
.kpi.verde .valor { color: var(--verde); }
.kpi.rojo .valor { color: var(--rojo-alerta); }
.kpi.naranja .valor { color: var(--amarillo); }
.kpi .etiqueta { font-size: 0.8rem; color: var(--gris-texto); margin-top: 0.35rem; }

/* =========================================================================
   Tablas
   ========================================================================= */
.tabla-wrap { overflow-x: auto; border-radius: var(--radio-sm); }
table.tabla { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.tabla th, table.tabla td {
  text-align: left; padding: 0.68rem 0.8rem;
  border-bottom: 1px solid var(--borde); white-space: nowrap;
}
table.tabla th {
  background: var(--surface-2);
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--gris-texto); font-weight: 700; position: sticky; top: 0;
}
table.tabla tbody tr { transition: background 0.12s; }
table.tabla tbody tr:hover { background: var(--surface-2); }
table.tabla tr:last-child td { border-bottom: none; }

/* =========================================================================
   Checklist / actividades
   ========================================================================= */
.tarea {
  border: 1px solid var(--borde);
  border-radius: var(--radio-sm);
  padding: 0.85rem 0.9rem; margin-bottom: 0.7rem;
  background: var(--surface); box-shadow: var(--sombra-sm);
  border-left: 5px solid var(--gris-borde);
}
.tarea.completada { border-left-color: var(--verde); }
.tarea.no_aplica { border-left-color: #9aa4b2; opacity: 0.8; }
.tarea.pendiente { border-left-color: var(--amarillo); }
.tarea-head { display: flex; justify-content: space-between; gap: 0.5rem; align-items: center; }
.tarea-nombre { font-weight: 600; }
.tarea-sla { font-size: 0.75rem; color: var(--gris-texto); white-space: nowrap; }
.tarea-acciones { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.7rem; }
.tarea-acciones .btn { min-height: 40px; padding: 0.4rem 0.9rem; font-size: 0.88rem; }
.chip-evidencia { font-size: 0.78rem; color: var(--verde); margin-top: 0.4rem; }
.req-evidencia { font-size: 0.72rem; color: var(--amarillo); font-weight: 700; }

/* Veredicto del líder */
.veredicto { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.veredicto .btn.vd { min-height: 34px; padding: 0.25rem 0.7rem; font-size: 0.8rem; box-shadow: none; }
.veredicto .muted { margin-right: 0.2rem; }

/* =========================================================================
   Selector de equipo / listas con checkbox
   ========================================================================= */
.equipo-lista {
  border: 1px solid var(--borde); border-radius: var(--radio-sm);
  max-height: 210px; overflow-y: auto; padding: 0.3rem; background: var(--surface);
}
.equipo-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem 0.6rem; border-radius: 8px;
}
.equipo-item:hover { background: var(--surface-2); }
.equipo-item input[type="checkbox"] { width: auto; min-height: auto; margin: 0; accent-color: var(--rojo); }
.equipo-item input[type="radio"] { accent-color: var(--rojo); }
.equipo-item .nombre { flex: 1; }
.equipo-item .resp { font-size: 0.8rem; color: var(--gris-texto); }
.equipo-item label { margin: 0; font-weight: 400; display: flex; align-items: center; gap: 0.6rem; flex: 1; cursor: pointer; }

/* =========================================================================
   Encuesta (estrellas / opciones)
   ========================================================================= */
.encuesta-opciones { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.encuesta-opciones label {
  flex: 1 1 30%; text-align: center;
  border: 1.5px solid var(--gris-borde); border-radius: var(--radio-sm);
  padding: 0.6rem 0.3rem; cursor: pointer; margin: 0; font-weight: 500;
}
.encuesta-opciones input { display: none; }
.encuesta-opciones input:checked + span { color: var(--rojo); font-weight: 700; }
.encuesta-opciones label:has(input:checked) { border-color: var(--rojo); background: var(--rojo-soft); }
.encuesta-resultado { background: var(--info-soft); border-radius: var(--radio-sm); padding: 0.85rem 1rem; margin-top: 0.5rem; }
.estrellas { color: #f0ad4e; font-size: 1.2rem; letter-spacing: 2px; }

/* Evidencias */
.evidencia-link { display: inline-block; margin-top: 0.4rem; font-size: 0.82rem; color: var(--rojo-osc); text-decoration: none; font-weight: 600; }
.evidencia-link:hover { text-decoration: underline; }

/* =========================================================================
   Overlay de carga
   ========================================================================= */
.loading-overlay {
  position: fixed; inset: 0; background: rgba(243,245,249,0.72);
  backdrop-filter: blur(2px);
  display: none; align-items: center; justify-content: center; z-index: 100;
}
.loading-overlay.activo { display: flex; }
.loading-box {
  background: var(--surface); border-radius: 16px; padding: 1.4rem 1.8rem;
  box-shadow: var(--sombra-lg); display: flex; flex-direction: column; align-items: center; gap: 0.8rem;
}
.loading-box .ring {
  width: 46px; height: 46px;
  border: 4px solid var(--gris-borde); border-top-color: var(--rojo);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
.loading-box span { font-size: 0.9rem; color: var(--gris-texto); font-weight: 600; }
.spinner { width: 22px; height: 22px; border: 3px solid rgba(255,255,255,0.5); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================================
   Modal de firma
   ========================================================================= */
.firma-overlay { position: fixed; inset: 0; background: rgba(12,20,34,0.55); display: none; z-index: 50; }
.firma-overlay.abierto { display: block; }
.firma-panel { position: absolute; inset: 0; background: #fff; display: flex; flex-direction: column; }
.firma-panel header { padding: 0.9rem 1.2rem; background: var(--side-bg); color: #fff; display: flex; justify-content: space-between; align-items: center; }
.firma-panel header h3 { margin: 0; font-size: 1rem; color: #fff; }
#firmaCanvas { flex: 1; width: 100%; touch-action: none; background: #fff; cursor: crosshair; }
.firma-linea { text-align: center; color: var(--gris-texto); font-size: 0.8rem; border-top: 2px dashed var(--gris-borde); margin: 0 1.2rem; padding-top: 0.3rem; }
.firma-footer { display: flex; gap: 0.7rem; padding: 1rem 1.2rem 1.4rem; background: #fff; border-top: 1px solid var(--borde); }
.firma-footer .btn { flex: 1; min-height: 54px; font-size: 1.05rem; }

/* =========================================================================
   Utilidades
   ========================================================================= */
.muted { color: var(--gris-texto); font-size: 0.85rem; }
.alerta {
  background: var(--rojo-alerta-soft); color: var(--rojo-alerta);
  border: 1px solid #f7cfca; border-radius: var(--radio-sm);
  padding: 0.7rem 0.9rem; margin-bottom: 0.8rem; font-size: 0.9rem;
}
.exito { background: var(--verde-soft); color: var(--verde); border: 1px solid #b6e6c8; }
.hidden { display: none !important; }

/* --- Modal genérico (p. ej. cambiar contraseña) --- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 120;
  background: rgba(8,10,16,0.5);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  opacity: 0; pointer-events: none; transition: opacity 0.18s;
}
.modal-overlay.abierto { opacity: 1; pointer-events: auto; }
.modal-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border-radius: var(--radio);
  box-shadow: var(--sombra-lg); padding: 1.3rem 1.3rem 1.4rem;
  transform: translateY(8px); transition: transform 0.18s;
}
.modal-overlay.abierto .modal-card { transform: translateY(0); }
.modal-card h3 { margin: 0 0 0.3rem; }
.modal-actions { display: flex; gap: 0.6rem; margin-top: 1rem; }
.modal-actions .btn { flex: 1; }
hr { border: none; border-top: 1px solid var(--borde); margin: 0.9rem 0; }

/* Ajustes finos para móvil */
@media (max-width: 620px) {
  .topbar { padding: 0.55rem 0.8rem; }
  .topbar h1 { font-size: 0.95rem; }
  .content { padding-left: 0.9rem; padding-right: 0.9rem; }
  .kpi .valor { font-size: 1.7rem; }
}
