/* =========================================================================
   SG-SST Multihospital · Hoja de estilos principal
   ========================================================================= */
:root {
  --primario: #0f766e;
  --primario-2: #115e59;
  --primario-claro: #ccfbf1;
  --acento: #0ea5e9;
  --fondo: #f1f5f9;
  --superficie: #ffffff;
  --borde: #e2e8f0;
  --texto: #0f172a;
  --texto-2: #475569;
  --texto-3: #94a3b8;
  --ok: #16a34a;     --ok-bg: #dcfce7;
  --warn: #d97706;   --warn-bg: #fef3c7;
  --mal: #dc2626;    --mal-bg: #fee2e2;
  --info: #2563eb;   --info-bg: #dbeafe;
  --gris-bg: #f1f5f9;
  --p: #2563eb; --h: #16a34a; --v: #d97706; --a: #9333ea;
  --radio: 10px;
  --sombra: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --sidebar: 252px;
  font-size: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--fondo); color: var(--texto); line-height: 1.45;
}
a { color: var(--primario); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
small, .muted { color: var(--texto-2); }
.hidden { display: none !important; }

/* ------------------------------ Layout ------------------------------ */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); background: #0b3b38; color: #d1fae5; flex-shrink: 0;
  position: fixed; inset: 0 auto 0 0; overflow-y: auto; z-index: 40; transition: transform .2s;
}
.sidebar .marca { padding: 18px 18px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar .marca b { display: block; color: #fff; font-size: 1.05rem; letter-spacing: .3px; }
.sidebar .marca span { font-size: .78rem; color: #99f6e4; }
.sidebar nav { padding: 8px 10px 30px; }
.sidebar .grupo { margin: 14px 8px 4px; font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #5eead4; display: flex; align-items: center; gap: 6px; }
.sidebar .grupo i { width: 18px; height: 18px; border-radius: 4px; display: inline-grid; place-items: center; font-style: normal; color: #fff; font-size: .68rem; }
.sidebar a.item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #ccfbf1; font-size: .92rem; }
.sidebar a.item:hover { background: rgba(255,255,255,.07); text-decoration: none; }
.sidebar a.item.activo { background: #14b8a6; color: #042f2e; font-weight: 600; }
.sidebar a.item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .9; }

.principal { margin-left: var(--sidebar); flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 58px; background: var(--superficie); border-bottom: 1px solid var(--borde);
  display: flex; align-items: center; gap: 12px; padding: 0 20px; position: sticky; top: 0; z-index: 30;
}
.topbar .hospital { display: flex; flex-direction: column; min-width: 0; }
.topbar .hospital b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .hospital small { font-size: .75rem; }
.topbar .espacio { flex: 1; }
.topbar select { min-width: 0; }
.menu-btn { display: none; background: none; border: 0; font-size: 1.4rem; cursor: pointer; color: var(--texto); }
.usuario { display: flex; align-items: center; gap: 8px; position: relative; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primario); color: #fff; display: grid; place-items: center; font-weight: 700; cursor: pointer; border: 0; }
.dropdown { position: absolute; right: 0; top: 44px; background: #fff; border: 1px solid var(--borde); border-radius: 10px; box-shadow: 0 10px 25px rgba(0,0,0,.12); min-width: 230px; padding: 6px; display: none; }
.dropdown.abierto { display: block; }
.dropdown .cab { padding: 8px 10px; border-bottom: 1px solid var(--borde); margin-bottom: 4px; }
.dropdown button, .dropdown a { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none; border-radius: 6px; cursor: pointer; color: var(--texto); font: inherit; }
.dropdown button:hover, .dropdown a:hover { background: var(--gris-bg); text-decoration: none; }

.contenido { padding: 22px; max-width: 1500px; width: 100%; }
.encabezado { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.encabezado p { margin: 2px 0 0; color: var(--texto-2); }
.migas { font-size: .78rem; color: var(--texto-3); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }

/* ------------------------------ Tarjetas ------------------------------ */
.card { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); box-shadow: var(--sombra); }
.card .card-h { padding: 14px 16px; border-bottom: 1px solid var(--borde); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card .card-h h2, .card .card-h h3 { margin: 0; }
.card .card-b { padding: 16px; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; }
.chart-box canvas { max-width: 100%; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

.kpi { padding: 14px 16px; position: relative; overflow: hidden; }
.kpi .t { font-size: .78rem; color: var(--texto-2); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi .v { font-size: 1.75rem; font-weight: 700; margin: 4px 0 2px; }
.kpi .s { font-size: .8rem; color: var(--texto-2); }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--primario); }
.kpi.ok::before { background: var(--ok); } .kpi.warn::before { background: var(--warn); } .kpi.mal::before { background: var(--mal); } .kpi.info::before { background: var(--info); }

.barra { height: 8px; background: var(--gris-bg); border-radius: 99px; overflow: hidden; }
.barra > span { display: block; height: 100%; background: var(--primario); border-radius: 99px; }
.barra.ok > span { background: var(--ok); } .barra.warn > span { background: var(--warn); } .barra.mal > span { background: var(--mal); }
.prog { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.prog .barra { flex: 1; }
.prog b { font-size: .8rem; min-width: 38px; text-align: right; }

/* ------------------------------ Badges ------------------------------ */
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .74rem; font-weight: 600; white-space: nowrap; background: var(--gris-bg); color: var(--texto-2); }
.b-ok { background: var(--ok-bg); color: #166534; } .b-warn { background: var(--warn-bg); color: #92400e; }
.b-mal { background: var(--mal-bg); color: #991b1b; } .b-info { background: var(--info-bg); color: #1e40af; }
.b-P { background: #dbeafe; color: #1e40af; } .b-H { background: #dcfce7; color: #166534; }
.b-V { background: #fef3c7; color: #92400e; } .b-A { background: #f3e8ff; color: #6b21a8; }
.nivel-I { background: #dc2626; color: #fff; } .nivel-II { background: #f97316; color: #fff; }
.nivel-III { background: #facc15; color: #422006; } .nivel-IV { background: #22c55e; color: #fff; }

/* ------------------------------ Botones / formularios ------------------------------ */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--borde); background: #fff; color: var(--texto); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--gris-bg); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-p { background: var(--primario); border-color: var(--primario); color: #fff; }
.btn-p:hover { background: var(--primario-2); }
.btn-d { color: var(--mal); }
.btn-d:hover { background: var(--mal-bg); }
.btn-sm { padding: 4px 9px; font-size: .82rem; }
.btn-icon { padding: 5px 7px; }
.btn svg { width: 16px; height: 16px; }
.acciones { display: flex; gap: 4px; justify-content: flex-end; }

input, select, textarea {
  font: inherit; color: var(--texto); background: #fff; border: 1px solid #cbd5e1; border-radius: 8px; padding: 7px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #5eead4; border-color: var(--primario); }
input[type=checkbox] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
label { font-weight: 600; font-size: .84rem; display: block; margin-bottom: 4px; color: #334155; }
.req::after { content: " *"; color: var(--mal); }
.campo { margin-bottom: 2px; }
.campo .err { color: var(--mal); font-size: .78rem; margin-top: 3px; }
.campo.con-error input, .campo.con-error select, .campo.con-error textarea { border-color: var(--mal); }
.campo .ayuda { font-size: .76rem; color: var(--texto-3); margin-top: 3px; }
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px 14px; }
.c-12 { grid-column: span 12; } .c-8 { grid-column: span 8; } .c-6 { grid-column: span 6; } .c-4 { grid-column: span 4; } .c-3 { grid-column: span 3; }
.seccion-form { grid-column: span 12; font-weight: 700; color: var(--primario); border-bottom: 1px solid var(--borde); padding-bottom: 4px; margin-top: 8px; font-size: .88rem; text-transform: uppercase; letter-spacing: .04em; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.meses { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.meses label { display: flex; align-items: center; justify-content: center; gap: 4px; border: 1px solid var(--borde); border-radius: 6px; padding: 5px 0; cursor: pointer; font-weight: 500; margin: 0; }
.meses input:checked + span { color: var(--primario); font-weight: 700; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--borde); }
.toolbar .buscar { flex: 1 1 220px; max-width: 340px; }
.toolbar select { width: auto; max-width: 220px; }
.toolbar .der { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ------------------------------ Tablas ------------------------------ */
.tabla-wrap { overflow-x: auto; }
table.tabla { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tabla th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--texto-2); background: #f8fafc; padding: 9px 10px; border-bottom: 1px solid var(--borde); white-space: nowrap; position: sticky; top: 0; }
.tabla td { padding: 9px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
.tabla tr:hover td { background: #f8fafc; }
.tabla td.num, .tabla th.num { text-align: right; white-space: nowrap; }
.tabla td.centro, .tabla th.centro { text-align: center; }
.tabla .sub { color: var(--texto-2); font-size: .8rem; }
.tabla .clip { max-width: 360px; }
.tabla tr.fila-alerta td { background: #fff7ed; }
.vacio { padding: 36px; text-align: center; color: var(--texto-3); }
.paginacion { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; gap: 10px; flex-wrap: wrap; font-size: .85rem; color: var(--texto-2); }
.paginacion .pags { display: flex; gap: 4px; }

/* Cronograma */
.crono th.mes, .crono td.mes { text-align: center; width: 44px; padding: 4px 2px; }
.celda { width: 30px; height: 22px; border-radius: 4px; margin: 0 auto; display: grid; place-items: center; font-size: .68rem; font-weight: 700; }
.celda.p { background: #e0f2fe; color: #0369a1; border: 1px dashed #38bdf8; }
.celda.e { background: #22c55e; color: #fff; }
.celda.x { background: #fecaca; color: #991b1b; }
.celda.a { background: #fde68a; color: #92400e; }
.leyenda { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--texto-2); align-items: center; }
.leyenda span { display: inline-flex; align-items: center; gap: 6px; }
.leyenda .celda { width: 18px; height: 14px; display: inline-block; }

/* ------------------------------ Modal / toast ------------------------------ */
.modal-fondo { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 30px 14px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 25px 50px rgba(0,0,0,.25); animation: entra .15s ease-out; }
.modal.lg { max-width: 920px; } .modal.xl { max-width: 1180px; }
.modal-h { padding: 14px 18px; border-bottom: 1px solid var(--borde); display: flex; justify-content: space-between; align-items: center; }
.modal-h h3 { margin: 0; }
.modal-b { padding: 18px; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--borde); display: flex; justify-content: flex-end; gap: 8px; background: #f8fafc; border-radius: 0 0 12px 12px; }
.cerrar { background: none; border: 0; font-size: 1.5rem; cursor: pointer; color: var(--texto-2); line-height: 1; }
@keyframes entra { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #0f172a; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 10px 20px rgba(0,0,0,.2); max-width: 380px; font-size: .9rem; animation: entra .15s; }
.toast.ok { background: #166534; } .toast.mal { background: #991b1b; }

/* Alertas */
.alertas { list-style: none; margin: 0; padding: 0; }
.alertas li { display: flex; gap: 10px; padding: 9px 4px; border-bottom: 1px solid #f1f5f9; align-items: flex-start; }
.alertas li:last-child { border-bottom: 0; }
.alertas .punto { width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.alertas .alta .punto { background: var(--mal); } .alertas .media .punto { background: var(--warn); }
.aviso { padding: 10px 14px; border-radius: 8px; background: var(--info-bg); color: #1e3a8a; margin-bottom: 14px; font-size: .9rem; }
.aviso.warn { background: var(--warn-bg); color: #78350f; }

.semaforo { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.sem-ok { background: var(--ok); } .sem-warn { background: var(--warn); } .sem-mal { background: var(--mal); } .sem-na { background: #cbd5e1; }

.lista-def { display: grid; grid-template-columns: 180px 1fr; gap: 6px 12px; font-size: .9rem; }
.lista-def dt { color: var(--texto-2); font-weight: 600; }
.lista-def dd { margin: 0; }
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--borde); padding: 0 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 11px 12px; cursor: pointer; font: inherit; font-weight: 600; color: var(--texto-2); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.activo { color: var(--primario); border-bottom-color: var(--primario); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-lado { background: linear-gradient(150deg, #0b3b38, #0f766e 60%, #14b8a6); color: #ecfeff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.login-lado h1 { font-size: 2rem; color: #fff; }
.login-lado ul { padding-left: 18px; line-height: 1.9; color: #ccfbf1; }
.login-form { display: grid; place-items: center; padding: 30px; background: #fff; }
.login-form form { width: 100%; max-width: 360px; }

@media (max-width: 1100px) {
  .g-4, .g-6 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.abierto { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .principal { margin-left: 0; }
  .menu-btn { display: block; }
  .g-2, .g-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .contenido { padding: 16px; }
  .c-8, .c-6, .c-4, .c-3 { grid-column: span 12; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-lado { display: none; }
  .topbar .hospital small, .topbar label[for="sel-anio"] { display: none; }
  .topbar { padding: 0 12px; gap: 8px; }
  #sel-anio { flex-shrink: 0; width: 82px !important; }
  .lista-def { grid-template-columns: 1fr; }
}
@media (max-width: 520px) { .g-4, .g-6 { grid-template-columns: 1fr; } }

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .principal { margin: 0; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
