/* ==========================================================================
   GIS Seguridad Privada · Sistema de cuadrantes — hoja de estilos común
   Concepto: los colores del escudo GIS. Menú negro con el dorado del logo como acento;
   zona de trabajo clara y sobria; cifras alineadas (horas, euros).
   Tema claro a propósito: es una herramienta de oficina que también se imprime.
   ========================================================================== */
@font-face { font-family: 'Archivo'; src: url('../fonts/archivo.woff2') format('woff2');
             font-weight: 500 800; font-stretch: 62% 125%; font-display: swap; }
@font-face { font-family: 'IBM Plex Sans'; src: url('../fonts/plex-sans.woff2') format('woff2');
             font-weight: 400 600; font-display: swap; }
@font-face { font-family: 'IBM Plex Mono'; src: url('../fonts/plex-mono.woff2') format('woff2');
             font-weight: 500; font-display: swap; }

:root {
  color-scheme: light;
  /* color: negro, dorado y blanco del escudo */
  --ink: #131313;            /* negro del escudo: menú, títulos */
  --ink-2: #252525;          /* hover sobre negro */
  --gold: #e6bf63;           /* dorado del logo: botón principal, elemento activo */
  --gold-hover: #d8ad4b;
  --gold-deep: #85621a;      /* dorado oscuro: texto y bordes dorados sobre blanco (contraste AA) */
  --gold-soft: #faf2dc;      /* fondo dorado muy suave: resaltes */
  --paper: #f4f4f1;          /* fondo de trabajo: blanco roto neutro */
  --surface: #ffffff;
  --surface-2: #f8f7f4;      /* cabeceras de tabla, zonas secundarias */
  --line: #e2e0da;
  --line-strong: #c9c5bb;
  --text: #1a1a1a;
  --muted: #66625a;
  --chart: #a8812a;          /* barras de los gráficos (dorado validado para gráficos) */
  /* estados (no son el acento) */
  --ok: #1d7448;      --ok-soft: #e3f3ea;
  --warn: #9a6200;    --warn-soft: #fdf3dc;
  --bad: #b3261e;     --bad-soft: #fbe8e6;
  --info: #285a8c;    --info-soft: #e5eef8;
  /* tipografía */
  --f-display: 'Archivo', 'Arial Narrow', 'Helvetica Neue', Arial, sans-serif;
  --f-body: 'IBM Plex Sans', -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --f-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
  /* escala */
  --t-xs: 0.75rem; --t-sm: 0.8125rem; --t-md: 0.9375rem; --t-lg: 1.125rem; --t-xl: 1.5rem; --t-2xl: 1.875rem;
  --r: 8px; --r-sm: 6px;
  --sidebar-w: 248px;
  --gutter: clamp(16px, 2.4vw, 32px);
  /* compatibilidad con plantillas antiguas */
  --accent: var(--gold); --accent-hover: var(--gold-hover); --brass: var(--gold); --brass-deep: var(--gold-deep); --brass-soft: var(--gold-soft); --bg: var(--paper); --card-bg: var(--surface);
  --text-light: var(--muted); --border: var(--line); --success: var(--ok); --danger: var(--bad);
  --warning: var(--warn); --sidebar-bg: var(--ink); --sidebar-hover: var(--ink-2);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--f-body);
  font-size: var(--t-md);
  line-height: 1.5;
  background: var(--paper);
  color: var(--text);
}
a { color: inherit; text-decoration: none; }
.content-wrapper p a:not(.btn), .nota a:not(.btn), .alert a, .content-wrapper li a:not(.btn) { color: var(--gold-deep); text-decoration: underline; text-underline-offset: 2px; }
ul { list-style: none; }
img { max-width: 100%; }
[hidden] { display: none !important; }      /* que el atributo hidden mande aunque el elemento sea flex/grid */
h1, h2, h3, h4 { font-family: var(--f-display); font-stretch: 92%; color: var(--ink); line-height: 1.2; text-wrap: balance; }
h2 { font-size: var(--t-xl); font-weight: 700; margin-bottom: 12px; }
h3 { font-size: var(--t-lg); font-weight: 650; margin-bottom: 10px; }
h4 { font-size: var(--t-md); font-weight: 650; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
p + p { margin-top: 8px; }
code { font-family: var(--f-mono); font-size: 0.88em; background: var(--surface-2); border: 1px solid var(--line); padding: 0 5px; border-radius: 4px; }
small, .nota, .text-muted { color: var(--muted); }
.nota { font-size: var(--t-sm); }
:focus-visible { outline: 2px solid var(--gold-deep); outline-offset: 2px; }
.num, td.num, .tabular { font-variant-numeric: tabular-nums; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* utilidades que ya usan las plantillas */
.d-flex { display: flex; } .justify-content-between { justify-content: space-between; }
.mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 20px; }

/* ---------- Estructura ---------- */
.app-container { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--ink); color: #e4e1d9;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-header { padding: 18px 18px 16px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar-header a { display: flex; align-items: center; gap: 12px; color: #fff; }
.sidebar-header img { width: 44px; height: 52px; object-fit: contain; flex: none; }
.sidebar-header h2 { margin: 0; color: var(--gold); font-size: 0.95rem; font-weight: 700; font-stretch: 88%; letter-spacing: 0.02em; line-height: 1.2; }
.sidebar-header .sub { display: block; font-family: var(--f-body); font-size: var(--t-xs); font-weight: 400; color: rgba(255,255,255,0.55); letter-spacing: 0; margin-top: 2px; }
.sidebar-nav { overflow-y: auto; padding: 6px 0 18px; flex: 1; }
.sidebar-grupo {
  padding: 16px 20px 6px; font-size: 0.6875rem; font-weight: 600;
  letter-spacing: 0.09em; text-transform: uppercase; color: rgba(255,255,255,0.42);
}
.sidebar-nav li a {
  display: flex; align-items: center; gap: 11px;
  margin: 1px 10px; padding: 8px 10px; border-radius: var(--r-sm);
  font-size: 0.875rem; color: #d9d5cc; position: relative;
  transition: background 0.15s, color 0.15s;
}
.sidebar-nav li a svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; opacity: 0.8; }
.sidebar-nav li a:hover { background: var(--ink-2); color: #fff; }
.sidebar-nav li a.active { background: rgba(230,191,99,0.13); color: var(--gold); font-weight: 600; }
.sidebar-nav li a.active::before { content: ""; position: absolute; left: -10px; top: 6px; bottom: 6px; width: 3px; border-radius: 0 3px 3px 0; background: var(--gold); }
.sidebar-nav li a.active svg { opacity: 1; stroke: var(--gold); }
.nav-toggle { display: none; }

.main-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: 18px var(--gutter) 16px;
}
.topbar .eyebrow { display: block; font-size: var(--t-xs); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold-deep); margin-bottom: 2px; }
.topbar h1 { font-size: var(--t-2xl); font-weight: 750; font-stretch: 90%; letter-spacing: -0.005em; }
.content-wrapper { padding: 24px var(--gutter) 40px; flex: 1; min-width: 0; }
.content-wrapper > * + * { margin-top: 0; }

/* ---------- Tarjetas y paneles ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 20px; margin-bottom: 20px; min-width: 0;
}
.card-body { padding: 0; }
.card h3 { padding-bottom: 10px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }

/* cifras resumen (inicio) */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
a.stat-card:hover { border-color: var(--line-strong); box-shadow: 0 2px 8px rgba(21,33,47,0.06); }
.stat-card .icon { display: none; }
.stat-card .info { display: flex; flex-direction: column-reverse; gap: 2px; text-align: left; }
.stat-card .info span { font-size: var(--t-sm); color: var(--muted); }
.stat-card .info strong { font-family: var(--f-display); font-size: 2rem; font-weight: 700; font-stretch: 90%; color: var(--ink); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-card.estado-baja { background: var(--bad-soft); border-color: #f0c5c1; }
.stat-card.estado-baja .info strong, .stat-card.estado-baja .info span { color: var(--bad); }
.stat-card.estado-vac { background: var(--ok-soft); border-color: #bfe0cc; }
.stat-card.estado-vac .info strong, .stat-card.estado-vac .info span { color: var(--ok); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 7px 14px; border-radius: var(--r-sm);
  border: 1px solid transparent; cursor: pointer;
  font-family: var(--f-body); font-size: 0.875rem; font-weight: 500; line-height: 1.2;
  text-align: center; text-decoration: none; white-space: nowrap; vertical-align: middle;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:disabled, .btn.disabled { opacity: 0.5; cursor: not-allowed; }
/* .btn-sm solo encoge dentro de las tablas; fuera, todos los botones miden lo mismo (36 px) */
td .btn-sm, .envio-celda .btn-sm { min-height: 30px; padding: 4px 10px; font-size: 0.8125rem; }
/* principal: tinta. Una sola acción principal por zona */
.btn-primary { background: var(--gold); color: #131313; font-weight: 600; }
.btn-primary:hover { background: var(--gold-hover); }
/* secundario: neutro con borde */
.btn-secondary, .btn-outline-primary { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.btn-secondary:hover, .btn-outline-primary:hover { background: var(--surface-2); border-color: #a9b5c2; }
/* afirmativo (enviar, guardar oficialmente, exportar) */
.btn-success { background: var(--ok); color: #fff; }
.btn-success:hover { background: #175f3b; }
.btn-outline-success { background: var(--surface); color: var(--ok); border-color: #9fcdb2; }
.btn-outline-success:hover { background: var(--ok-soft); }
/* destructivo */
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover { background: #8f1e18; }
.btn-outline-danger { background: var(--surface); color: var(--bad); border-color: #eab0ab; }
.btn-outline-danger:hover { background: var(--bad-soft); }
/* atención */
.btn-warning { background: var(--surface); color: var(--warn); border-color: #e7c37c; }
.btn-warning:hover { background: var(--warn-soft); }

/* en tablas: discretos; solo "Eliminar" en rojo */
td form, .acciones form { display: inline-flex; margin: 0; }
td .btn + .btn, td .btn + form, td form + .btn, td form + form { margin-left: 4px; }
td .btn-sm.btn-primary, td .btn-sm.btn-success, td .btn-sm.btn-warning, td .btn-sm.btn-secondary {
  background: var(--surface); color: var(--text); border-color: var(--line-strong);
}
td .btn-sm.btn-primary:hover, td .btn-sm.btn-success:hover, td .btn-sm.btn-warning:hover, td .btn-sm.btn-secondary:hover { background: var(--surface-2); }
td .btn-sm.btn-danger { background: var(--surface); color: var(--bad); border-color: #eab0ab; }
td .btn-sm.btn-danger:hover { background: var(--bad); color: #fff; border-color: var(--bad); }

/* ---------- Formularios ---------- */
.form-group { margin-bottom: 14px; }
.form-group label, .form-label { display: block; margin-bottom: 5px; font-size: var(--t-sm); font-weight: 600; color: var(--text); }
.form-control, .form-select, select, input[type="text"], input[type="number"], input[type="email"], input[type="tel"],
input[type="date"], input[type="time"], input[type="month"], input[type="password"], input[type="search"], textarea {
  font-family: var(--f-body); font-size: 0.875rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  min-height: 36px; padding: 6px 10px;
}
.form-control, .form-select { width: 100%; }
textarea { min-height: 72px; line-height: 1.45; }
.form-control:focus, .form-select:focus, select:focus, input:focus, textarea:focus {
  outline: none; border-color: var(--gold-deep); box-shadow: 0 0 0 3px rgba(230,191,99,0.35);
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--ink); width: 16px; height: 16px; vertical-align: -3px; min-height: 0; }
label:has(> input[type="checkbox"]), label:has(> input[type="radio"]) { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; cursor: pointer; }
.form-inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-row, .row { display: flex; flex-wrap: wrap; gap: 14px; }
.form-row > *, .row > * { flex: 1 1 200px; min-width: 0; }

/* ---------- Tablas ---------- */
.table-responsive, .tabla-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--r); }
table { width: 100%; border-collapse: collapse; background: var(--surface); font-variant-numeric: tabular-nums; }
table th, table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
table th {
  background: var(--surface-2); color: var(--muted); font-size: var(--t-xs); font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap;
}
table tbody tr:hover { background: #fafbfc; }
table tbody tr:last-child td { border-bottom: 0; }
.card > table, .card > .table-responsive { border: 1px solid var(--line); border-radius: var(--r); }
td.acciones, th.acciones, .col-acciones { white-space: nowrap; text-align: right; }

/* ---------- Barras de acciones / búsqueda ---------- */
.action-bar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.action-bar h2, .action-bar h3 { margin: 0; }
.search-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.search-bar .form-control { width: auto; min-width: 220px; }

/* ---------- Avisos ---------- */
.flash-messages { padding: 16px var(--gutter) 0; display: grid; gap: 8px; }
.flash-messages:empty { display: none; }
.alert { padding: 11px 14px; border-radius: var(--r-sm); border: 1px solid transparent; font-size: 0.875rem; }
.alert-success { background: var(--ok-soft); color: #14532f; border-color: #bfe0cc; }
.alert-error, .alert-danger { background: var(--bad-soft); color: #7d1a14; border-color: #f0c5c1; }
.alert-warning { background: var(--warn-soft); color: #6b4500; border-color: #ecd39b; }
.alert-info { background: var(--info-soft); color: #1d4166; border-color: #c3d6ea; }

/* chips / estados */
.pill, .tag, .badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px;
  font-size: var(--t-xs); font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}

/* ---------- Cuadrantes ---------- */
.cuadrante-table th, .cuadrante-table td { padding: 5px; text-align: center; font-size: 0.85rem; }
.cuadrante-table th:first-child, .cuadrante-table td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; border-right: 1px solid var(--line-strong); min-width: 150px; }
.cell-turno { width: 30px; height: 30px; border-radius: 4px; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; color: #fff; cursor: pointer; }
.turno-M { background-color: #2f6db5; }
.turno-T { background-color: #c8691c; }
.turno-N { background-color: #5b3f99; }
.turno-L { background-color: #e7ebef; color: var(--text); }
.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }

/* ---------- Móvil ---------- */
@media (max-width: 900px) {
  .app-container { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: sticky; top: 0; z-index: 50; }
  .sidebar-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; }
  .sidebar-header img { width: 32px; height: 38px; }
  .nav-toggle {
    display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 6px 12px;
    background: transparent; color: #fff; border: 1px solid rgba(255,255,255,0.25); border-radius: var(--r-sm);
    font: 500 0.875rem var(--f-body); cursor: pointer;
  }
  .sidebar-nav { display: none; max-height: calc(100vh - 60px); padding-top: 0; }
  .sidebar.abierto .sidebar-nav { display: block; }
  .topbar { padding: 14px 16px 12px; }
  .topbar h1 { font-size: var(--t-xl); }
  .content-wrapper { padding: 16px 16px 32px; }
  .flash-messages { padding: 12px 16px 0; }
  .card { padding: 16px; }
  .stat-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .action-bar { align-items: stretch; }
  .search-bar .form-control { min-width: 0; flex: 1; }
  table th, table td { padding: 8px 8px; }
}

/* ---------- Impresión ---------- */
@media print {
  .sidebar, .topbar .eyebrow, .no-print, .flash-messages { display: none !important; }
  body, .main-content, .content-wrapper { background: #fff; padding: 0; }
  .card { border: 0; padding: 0; }
}

/* ---------- Formularios de alta/edición ---------- */
.form-card { max-width: 680px; }
.form-card form > .form-group:last-of-type { margin-bottom: 18px; }
.form-card .btn + .btn, .form-card .btn + a.btn { margin-left: 6px; }
.ficha-servicio { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; margin-bottom: 18px; font-size: var(--t-sm); }
.ficha-servicio p + p { margin-top: 4px; }

/* ---------- Selector de mes (igual en todas las pantallas) ---------- */
.selector-mes { display: inline-flex; align-items: center; gap: 6px; }
.selector-mes select { width: 9.5rem; }
.selector-mes input[type="number"] { width: 5.75rem; text-align: center; font-variant-numeric: tabular-nums; }
.selector-mes .btn { min-width: 36px; padding-inline: 0; }

/* ---------- Conmutador de vista (Por vigilante | Todos) ---------- */
.conmutador { display: inline-flex; height: 36px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); overflow: hidden; background: var(--surface); }
.conmutador button { border: 0; background: transparent; min-height: 34px; height: 34px; padding: 0 14px; font: 500 .875rem var(--f-body); color: var(--text); cursor: pointer; }
.conmutador button + button { border-left: 1px solid var(--line-strong); }
.conmutador button[aria-pressed="true"] { background: var(--ink); color: var(--gold); font-weight: 600; }

/* ---------- Igual en Safari, Chrome y Edge: mismas alturas en desplegables, buscadores y casillas ---------- */
select, .form-select, select.form-control {
  -webkit-appearance: none; appearance: none; height: 36px; padding-right: 30px; line-height: 1.2;
  background-color: var(--surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2366625a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 12px 8px;
}
/* la flecha siempre tiene su hueco, aunque una pantalla ponga otro relleno al desplegable (si no, tapa el texto) */
select, .form-select, select.form-control { padding-right: 30px !important; text-overflow: ellipsis; }
td select, .envio-celda select, .gx-t select { padding-right: 26px !important; background-position: right 8px center; background-size: 10px 7px; }
select::-ms-expand { display: none; }
input[type="search"] { -webkit-appearance: none; appearance: none; }
input.form-control, input[type="text"], input[type="number"], input[type="email"], input[type="tel"], input[type="search"],
input[type="date"], input[type="time"], input[type="password"], input[type="month"] { height: 36px; }
td select, td input.form-control, .envio-celda select { height: 30px; min-height: 30px; }

/* ---------- Usuario conectado (abajo del menú) ---------- */
.sidebar-usuario { border-top: 1px solid rgba(255,255,255,0.08); padding: 12px 18px 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: var(--t-sm); }
.sidebar-usuario div { flex: 1 1 100%; min-width: 0; }
.sidebar-usuario b { display: block; color: #fff; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-usuario span { font-size: var(--t-xs); color: rgba(255,255,255,.5); }
.sidebar-usuario a { color: var(--gold); font-weight: 500; }
.sidebar-usuario a:hover { text-decoration: underline; }
@media (max-width: 900px) { .sidebar-usuario { display: none; } .sidebar.abierto .sidebar-usuario { display: flex; } }
