/* Saturno Residencial — mobile first */
:root {
  --azul: #0f3d5e;
  --azul-2: #1b5f8c;
  --acento: #f2a516;
  --ok: #1f8a5b;
  --warn: #c98200;
  --bad: #c0392b;
  --wa: #25d366;
  --fondo: #f4f6f9;
  --card: #ffffff;
  --texto: #1d2733;
  --muted: #6b7785;
  --borde: #e2e7ee;
  --radio: 14px;
  --sombra: 0 1px 3px rgba(16, 38, 64, .08), 0 4px 14px rgba(16, 38, 64, .05);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fondo); color: var(--texto);
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--azul-2); }
h1 { font-size: 1.45rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; margin: 0 0 .7rem; }
code { background: #eef2f7; padding: 1px 5px; border-radius: 5px; font-size: .9em; }
.container { max-width: 1180px; margin: 0 auto; padding: 14px 14px 90px; }
.container.narrow { max-width: 560px; padding-top: 30px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.pre { white-space: pre-line; margin: .3rem 0 0; }
[hidden] { display: none !important; }

/* Barra superior y menú */
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px;
  background: var(--azul); color: #fff; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
}
.topbar .brand { flex: 1; display: flex; flex-direction: column; line-height: 1.15; }
.topbar .brand small { opacity: .8; font-size: .8rem; }
.menu-btn { background: none; border: 0; color: #fff; font-size: 1.5rem; cursor: pointer; padding: 0 4px; }
.topbar .user {
  width: 36px; height: 36px; border-radius: 50%; background: var(--acento); color: var(--azul);
  display: grid; place-items: center; font-weight: 700; text-decoration: none;
}
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: 270px; background: #fff; z-index: 50; overflow-y: auto;
  transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--sombra); padding-bottom: 30px;
}
.drawer.open { transform: none; }
.drawer-user { background: var(--azul); color: #fff; padding: 22px 18px 16px; display: flex; flex-direction: column; }
.drawer-user small { opacity: .8; }
.drawer a, .drawer .linklike {
  display: flex; gap: 12px; align-items: center; padding: 11px 18px; color: var(--texto); text-decoration: none;
  width: 100%; background: none; border: 0; font: inherit; text-align: left; cursor: pointer;
}
.drawer a.active { background: #e8f0f7; color: var(--azul); font-weight: 600; border-left: 4px solid var(--acento); }
.drawer a:hover, .drawer .linklike:hover { background: #f3f6fa; }
.drawer span { width: 22px; text-align: center; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; display: none; }
.backdrop.open { display: block; }

/* Barra inferior (residentes y guardias) */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; background: #fff;
  border-top: 1px solid var(--borde); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 7px 2px 6px; text-decoration: none; color: var(--muted); }
.tabbar a span { font-size: 1.3rem; }
.tabbar a small { font-size: .7rem; }
.tabbar a.active { color: var(--azul); font-weight: 600; }

/* Tarjetas y grillas */
.card { background: var(--card); border-radius: var(--radio); box-shadow: var(--sombra); padding: 16px; margin-bottom: 14px; display: block; }
a.card { color: inherit; text-decoration: none; }
.sub-card { border: 1px solid var(--borde); border-radius: 10px; padding: 10px; margin-bottom: 10px; }
.grid2, .grid3, .grid4 { display: grid; gap: 14px; grid-template-columns: 1fr; }
.grid2 > *, .grid3 > *, .grid4 > * { margin-bottom: 0; }
.grid2, .grid3, .grid4 { margin-bottom: 14px; }
.cards { display: grid; gap: 12px; grid-template-columns: 1fr; }
.cards .card { margin: 0; }
@media (min-width: 720px) {
  .grid2 { grid-template-columns: 1fr 1fr; }
  .grid3 { grid-template-columns: repeat(3, 1fr); }
  .grid4 { grid-template-columns: repeat(2, 1fr); }
  .cards { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
  form .grid2 { margin-bottom: 0; }
}
@media (min-width: 1000px) { .grid4 { grid-template-columns: repeat(4, 1fr); } }
form .grid2 { gap: 0 12px; margin-bottom: 0; }

.stat { display: flex; flex-direction: column; gap: 2px; border-top: 4px solid var(--azul-2); }
.stat small { color: var(--muted); }
.stat strong { font-size: 1.6rem; }
.stat span { font-size: .85rem; color: var(--muted); }
.stat-ok { border-top-color: var(--ok); }
.stat-warn { border-top-color: var(--warn); }
.stat-bad { border-top-color: var(--bad); }
.bar { height: 7px; background: #e6ebf1; border-radius: 9px; overflow: hidden; margin: 6px 0 2px; min-width: 70px; }
.bar i { display: block; height: 100%; background: var(--ok); }

.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 10px; margin-bottom: 14px; }
.quick-btn {
  background: #fff; border-radius: 12px; box-shadow: var(--sombra); padding: 14px 10px; text-align: center;
  text-decoration: none; color: var(--texto); font-weight: 500; display: flex; flex-direction: column; gap: 4px; align-items: center; font-size: .9rem;
}
.quick-btn span { font-size: 1.6rem; }
.quick-btn b { background: var(--azul); color: #fff; border-radius: 20px; padding: 0 8px; font-size: .8rem; }
.quick-btn.primary { background: var(--azul); color: #fff; }

/* Formularios */
label { display: block; font-size: .88rem; color: #3b4754; margin-bottom: 12px; font-weight: 500; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; font: inherit; color: inherit; background: #fff;
  border: 1px solid #cfd7e1; border-radius: 10px; padding: 11px 12px; min-height: 46px;
}
input[type="checkbox"], input[type="radio"] { display: inline; width: auto; min-height: 0; margin: 0 6px 0 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--azul-2); outline-offset: 0; border-color: transparent; }
label.check { display: flex; align-items: center; font-weight: 400; }
.seg { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.seg label { border: 1px solid #cfd7e1; border-radius: 10px; padding: 10px 12px; margin: 0; cursor: pointer; flex: 1; font-weight: 400; }
.seg label:has(input:checked) { border-color: var(--azul-2); background: #e8f0f7; }
details > summary { cursor: pointer; padding: 4px 0; list-style-position: inside; }
details[open] > summary { margin-bottom: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters label { margin: 0; flex: 1 1 150px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.inline-form input { flex: 1 1 140px; margin: 0; min-height: 38px; padding: 7px 10px; }
.inline-form label { margin: 0; }
.w-sm { max-width: 90px; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid #cfd7e1; background: #fff; color: var(--texto);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .6; }
.btn-primary { background: var(--azul); border-color: var(--azul); color: #fff; }
.btn-primary:hover { background: var(--azul-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--azul-2); }
.btn-wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn-sm { min-height: 34px; padding: 5px 11px; font-size: .85rem; }
.btn-lg { min-height: 56px; font-size: 1.1rem; }
.btn-block { width: 100%; margin-top: 6px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.actions form { margin: 0; }
td.actions { margin: 0; }
.head-row, .row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.head-row h1 { margin-bottom: .6rem; }

/* Alertas y etiquetas */
.alert { border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; border: 1px solid; }
.alert-ok { background: #e7f6ee; border-color: #b6e2c9; color: #155f3e; }
.alert-warn { background: #fff5e0; border-color: #f3d79c; color: #7a5200; }
.alert-bad { background: #fdecea; border-color: #f2b8b1; color: #8c2219; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: .76rem; font-weight: 600; background: #eef1f5; color: var(--muted); vertical-align: middle; }
.badge-ok { background: #e1f4ea; color: var(--ok); }
.badge-warn { background: #fff1d6; color: var(--warn); }
.badge-bad { background: #fde3e0; color: var(--bad); }
.dot { display: inline-block; width: 8px; height: 8px; background: var(--acento); border-radius: 50%; margin-right: 6px; }

/* Tablas y listas */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 8px; border-bottom: 2px solid var(--borde); white-space: nowrap; }
.table td { padding: 9px 8px; border-bottom: 1px solid var(--borde); vertical-align: top; }
.table .num { text-align: right; white-space: nowrap; }
.neg { color: var(--bad); }
.pos { color: var(--ok); }
tr.inactivo, .card.inactivo { opacity: .5; }
.table-filter { margin-bottom: 10px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--borde); }
.list li:last-child { border-bottom: 0; }
.list li small { display: block; }
.tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 14px; border-bottom: 1px solid var(--borde); }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--muted); white-space: nowrap; border-bottom: 3px solid transparent; }
.tabs a.active { color: var(--azul); border-bottom-color: var(--acento); font-weight: 600; }

/* Login */
.login-wrap { min-height: 90vh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 400px; text-align: left; }
.login-card h1 { text-align: center; margin-bottom: 0; }
.login-card > p { text-align: center; }
.login-logo { text-align: center; }
.login-logo img { border-radius: 18px; }

/* Pase QR */
.pase { max-width: 420px; margin: 0 auto 14px; text-align: center; overflow: hidden; padding: 0 0 16px; }
.pase-head { background: var(--azul); color: #fff; padding: 18px; }
.pase-head h2 { margin: 4px 0; font-size: 1.4rem; }
.pase-head small { opacity: .85; }
.qr { width: 260px; height: 260px; margin: 18px auto 6px; }
.qr svg { width: 100%; height: 100%; }
.codigo { font-size: 1.1rem; letter-spacing: .05em; }
.codigo strong { font-size: 1.6rem; letter-spacing: .12em; }
.pase-vigencia { color: var(--muted); padding: 0 16px; }
.pase-invalido .pase-head { background: #7d8a97; }
.pase .alert { margin: 16px; }
.share { max-width: 420px; margin: 0 auto 14px; }

/* Garita */
.scanner-card { text-align: center; }
.reader { width: 100%; max-width: 420px; margin: 0 auto 10px; border-radius: 12px; overflow: hidden; }
.resultado { text-align: center; border-top: 6px solid; }
.resultado-ok { border-color: var(--ok); }
.resultado-bad { border-color: var(--bad); }
.resultado-icono { font-size: 3rem; }
.resultado .big { font-size: 1.5rem; font-weight: 700; margin: 6px 0; }
.resultado form input { margin-bottom: 8px; }

/* Bitácora */
.thumb { max-width: 220px; max-height: 160px; border-radius: 10px; display: block; margin: 8px 0; object-fit: cover; }
.tl-item { border-left: 4px solid var(--azul-2); }
.tl-incidente { border-left-color: var(--bad); }
.tl-ronda { border-left-color: var(--ok); }
.tl-turno { border-left-color: var(--acento); }

.comunicado-item.no-leido { border-left: 4px solid var(--acento); }
.comunicado .cuerpo { margin: 14px 0; font-size: 1.02rem; }
.slots { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 12px; }
.onboarding ol { margin: 0; padding-left: 20px; }
.legal h3 { margin-top: 18px; }

/* Reporte */
.reporte-head { border-bottom: 3px solid var(--azul); margin-bottom: 14px; }
.reporte h2 { border-bottom: 1px solid var(--borde); padding-bottom: 4px; margin-top: 24px; }
.reporte .stat { border: 1px solid var(--borde); border-radius: 10px; padding: 10px; }

/* Logotipo del conjunto */
.topbar-logo { height: 36px; width: auto; max-width: 120px; object-fit: contain; flex: none; background: #fff; border-radius: 8px; padding: 3px; }
.banner-conjunto { display: flex; align-items: center; gap: 16px; border-left: 5px solid var(--acento); }
.banner-logo { height: 72px; width: auto; max-width: 160px; object-fit: contain; flex: none; }
.banner-txt { display: flex; flex-direction: column; min-width: 0; }
.banner-txt strong { font-size: 1.15rem; line-height: 1.25; }
.banner-txt span { font-size: 1.35rem; font-weight: 700; color: var(--azul); margin-top: 2px; }
.pase-logo { display: block; height: 56px; width: auto; max-width: 160px; margin: 0 auto 8px; background: #fff; border-radius: 10px; padding: 6px; object-fit: contain; }
.reporte-logo { float: right; max-width: 140px; max-height: 80px; object-fit: contain; }
.conj-nombre { display: inline-flex; align-items: center; gap: 8px; }
.conj-logo { height: 32px; width: auto; max-width: 90px; object-fit: contain; }
.logo-editor { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.logo-preview { width: 120px; height: 120px; border: 1px dashed #cfd7e1; border-radius: 12px; display: grid; place-items: center; background: #fff; flex: none; }
.logo-preview img { max-width: 104px; max-height: 104px; object-fit: contain; }

/* Escritorio: menú lateral fijo */
@media (min-width: 1000px) {
  body.rol-admin .drawer, body.rol-superadmin .drawer { transform: none; top: 56px; box-shadow: none; border-right: 1px solid var(--borde); }
  body.rol-admin .drawer-user, body.rol-superadmin .drawer-user { display: none; }
  body.rol-admin .menu-btn, body.rol-superadmin .menu-btn { visibility: hidden; }
  body.rol-admin .container, body.rol-superadmin .container { margin-left: 270px; padding: 20px 26px 30px; }
  body.rol-admin .backdrop, body.rol-superadmin .backdrop { display: none !important; }
}
@media print {
  .topbar, .drawer, .tabbar, .no-print, .backdrop, .btn { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 0; padding: 0; }
  .container { padding: 0; max-width: none; margin-left: 0 !important; }
}
@media (max-width: 420px) { .topbar-logo { max-width: 84px !important; } .banner-logo { max-width: 110px !important; } }
