:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --ink: #10233f;
  --muted: #61718a;
  --line: #dde5f0;
  --blue: #1769e0;
  --blue-dark: #0d4ba8;
  --amber: #b26a00;
  --green: #0d7a4f;
  --red: #b3261e;
  --shadow: 0 2px 10px rgba(16, 35, 63, .08);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

h1 { font-size: 1.25rem; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; margin: 0 0 .35rem; }
p { margin: .35rem 0; }
.muted { color: var(--muted); font-size: .85rem; }
.note { font-size: .72rem; color: var(--muted); margin-top: 1.2rem; }
.error { color: var(--red); font-size: .85rem; min-height: 1.2rem; }

/* Portal de PIN */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.2rem;
  background: linear-gradient(160deg, #0b1f3a, #123b70);
}
.gate-card {
  width: min(100%, 420px);
  background: var(--card);
  border-radius: 18px;
  padding: 1.6rem;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
}
.logo {
  width: 52px; height: 52px;
  border-radius: 14px;
  background: var(--blue);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 800; letter-spacing: .04em;
  margin-bottom: 1rem;
}
label { display: block; font-size: .82rem; font-weight: 600; margin: 1rem 0 .35rem; }
input[type="password"], input[type="search"], select, textarea {
  width: 100%;
  padding: .75rem .85rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: .95rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: .7rem 1rem;
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:active { background: var(--blue-dark); }
.btn.danger { color: var(--red); border-color: #f0c7c3; }
.gate .btn.primary { width: 100%; margin-top: 1rem; }

/* Cabecera */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem;
  padding: calc(.85rem + env(safe-area-inset-top)) 1rem .85rem;
  background: rgba(11, 31, 58, .97);
  color: #fff;
  backdrop-filter: blur(8px);
}
.topbar .muted { color: #a8c2e6; }
.top-actions { display: flex; gap: .4rem; }
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.08);
  color: #fff;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}
.icon-btn.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.offline {
  background: #fff3cd; color: #7a5200;
  padding: .6rem 1rem; font-size: .8rem; text-align: center;
}

/* Resumen */
.resumen { padding: 1rem 1rem .25rem; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: .6rem; }
.pill { background: #e3ecfa; color: var(--blue-dark); border-radius: 999px; padding: .1rem .5rem; font-size: .75rem; letter-spacing: 0; }
.sitios { display: flex; gap: .6rem; overflow-x: auto; padding-bottom: .4rem; scrollbar-width: none; }
.sitios::-webkit-scrollbar { display: none; }
.sitio-card {
  flex: 0 0 auto;
  min-width: 132px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: .75rem .9rem;
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
}
.sitio-card.activo { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(23,105,224,.25); }
.sitio-card .cant { font-size: 1.65rem; font-weight: 800; line-height: 1; }
.sitio-card .nom { font-size: .76rem; color: var(--muted); margin-top: .3rem; max-width: 150px; }

.herramientas {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .5rem;
  padding: .6rem 1rem 0;
}
.herramientas select { width: auto; max-width: 45vw; }

/* Lista */
#lista { padding: .85rem 1rem 0; }
.grupo { margin-bottom: 1.4rem; }
.grupo-titulo {
  display: flex; align-items: center; gap: .5rem;
  font-size: .8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted);
  margin: .2rem 0 .65rem;
}
.grupo-titulo::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.ticket {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: .9rem;
  margin-bottom: .7rem;
  box-shadow: var(--shadow);
}
.ticket-top { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.tid { font-weight: 800; font-size: .9rem; }
.badge { font-size: .68rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; background: #eef2f8; color: #40536e; text-transform: uppercase; letter-spacing: .03em; }
.badge.Pendiente, .badge.Sin Validar { background: #fff1d6; color: var(--amber); }
.badge.Validado, .badge.Cerrado { background: #dcf5e8; color: var(--green); }
.badge.Bloqueado, .badge.Rechazado { background: #fde4e2; color: var(--red); }
.badge.En Gestión, .badge.Tomado, .badge.Reabierto { background: #e4ecff; color: var(--blue-dark); }
.prioridad { font-size: .7rem; color: var(--muted); margin-left: auto; }
.asunto { font-weight: 650; margin: .5rem 0 .15rem; font-size: .98rem; }
.motivo { font-size: .78rem; color: var(--blue-dark); }
.desc { font-size: .86rem; color: #33445e; margin: .55rem 0; white-space: pre-wrap; }
.desc.cerrada { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.vermas { background: none; border: 0; color: var(--blue); font-size: .78rem; font-weight: 600; padding: 0; cursor: pointer; }
.meta { font-size: .74rem; color: var(--muted); border-top: 1px dashed var(--line); padding-top: .5rem; margin-top: .5rem; }
.meta b { color: #40536e; font-weight: 600; }
.comentario { font-size: .76rem; background: #f5f8fd; border-left: 3px solid var(--blue); padding: .4rem .6rem; border-radius: 0 8px 8px 0; margin-top: .5rem; }
.acciones { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .7rem; }
.acciones .btn { padding: .45rem .7rem; font-size: .78rem; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.actualizado { text-align: center; color: var(--muted); font-size: .72rem; padding: 1rem 1rem 2rem; }
.vacio { text-align: center; color: var(--muted); padding: 2rem 1rem; }

/* Modal y toast */
.modal { position: fixed; inset: 0; background: rgba(8,20,38,.55); display: grid; place-items: center; padding: 1rem; z-index: 50; }
.modal-card { background: #fff; border-radius: 16px; padding: 1.2rem; width: min(100%, 420px); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.toast {
  position: fixed; left: 50%; bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #10233f; color: #fff;
  padding: .7rem 1rem; border-radius: 10px;
  font-size: .85rem; z-index: 60; max-width: calc(100% - 2rem);
  box-shadow: 0 8px 30px rgba(0,0,0,.3);
}
.toast.error { background: var(--red); }

@media (min-width: 720px) {
  #lista, .resumen, .herramientas { max-width: 860px; margin-inline: auto; }
  .topbar { padding-inline: max(1rem, calc((100vw - 860px) / 2)); }
}
