:root {
  --bg: #1d2733;
  --bg-soft: #253242;
  --panel: #ffffff;
  --ink: #17202a;
  --ink-soft: #5d6b7a;
  --line: #dfe4ea;
  --accent: #2f6fed;
  --accent-soft: #e8f0fe;
  --danger: #c92a2a;
  --ok: #2b8a3e;
  --radius: 10px;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  font:
    15px/1.45 -apple-system,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial,
    sans-serif;
  color: var(--ink);
  background: #f4f6f9;
}
button,
input,
select,
textarea {
  font: inherit;
}
button {
  cursor: pointer;
}
h1,
h2,
h3 {
  margin: 0 0 12px;
  font-weight: 650;
}
h1 {
  font-size: 20px;
}
h2 {
  font-size: 17px;
}
h3 {
  font-size: 15px;
}
a {
  color: var(--accent);
  text-decoration: none;
}
.muted {
  color: var(--ink-soft);
}
.small {
  font-size: 13px;
}
.boot {
  padding: 60px 20px;
  text-align: center;
  color: var(--ink-soft);
}

/* ---------- Login ---------- */
.login {
  max-width: 380px;
  margin: 12vh auto;
  background: var(--panel);
  border-radius: 14px;
  padding: 36px 30px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, 0.12);
  text-align: center;
}
.login h1 {
  font-size: 30px;
}
.login h1 span {
  color: var(--accent);
}
.login .denied {
  background: #fff5f5;
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 12px;
  margin: 14px 0;
  font-size: 14px;
}
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding: 11px 20px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 600;
}
.btn-google:hover {
  background: #f7f9fc;
}

/* ---------- Shell ---------- */
.shell {
  display: flex;
  min-height: 100vh;
}
.side {
  width: 230px;
  background: var(--bg);
  color: #cdd6e1;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.side .brand {
  padding: 18px 18px 14px;
  font-size: 21px;
  font-weight: 700;
  color: #fff;
}
.side .brand span {
  color: #6ea8ff;
}
.side .ctx {
  padding: 0 12px 10px;
  display: grid;
  gap: 8px;
}
.side .ctx select {
  width: 100%;
  background: var(--bg-soft);
  color: #e8edf4;
  border: 1px solid #33455a;
  border-radius: 8px;
  padding: 8px 10px;
}
.side nav {
  display: grid;
  gap: 1px;
  padding: 6px 10px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  align-content: start;
  grid-auto-rows: max-content;
}
.side nav a {
  color: #cdd6e1;
  padding: 6px 12px;
  border-radius: 7px;
  font-weight: 550;
  font-size: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.side nav .navgrp {
  color: #cdd6e1;
  padding: 6px 12px;
  border-radius: 7px;
  font-weight: 550;
  font-size: 14px;
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  background: none;
  border: 0;
  font: inherit;
  cursor: pointer;
  text-align: left;
}
.side nav .navgrp:hover {
  background: var(--bg-soft);
  color: #fff;
}
.hidden {
  display: none !important;
}
tr.arch td > input,
tr.arch td.small {
  opacity: 0.55;
}
.badge-arch {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: #7e93ad;
  border: 1px solid #33455a;
  border-radius: 6px;
  padding: 1px 6px;
  margin-left: 8px;
  vertical-align: middle;
}
.side nav a:hover {
  background: var(--bg-soft);
  color: #fff;
}
.side nav a.on {
  background: var(--accent);
  color: #fff;
}
.side .navsec {
  padding: 8px 12px 3px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #7e93ad;
}
.side nav a.sub {
  padding-left: 26px;
  padding-top: 5px;
  padding-bottom: 5px;
  font-weight: 500;
  font-size: 13px;
}
.side .who label {
  display: block;
  margin-top: 10px;
}
.side .who select {
  width: 100%;
  margin-top: 4px;
  background: var(--bg-soft);
  color: #e8edf4;
  border: 1px solid #33455a;
  border-radius: 8px;
  padding: 7px 9px;
}
.side .who select:disabled {
  opacity: 0.6;
}
.side .who .who-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}
.side .who #btn-logout {
  width: auto;
  margin: 0;
  padding: 5px 9px;
  display: inline-flex;
  align-items: center;
}
.side .who {
  margin-top: 0;
  flex-shrink: 0;
  padding: 14px 18px;
  border-top: 1px solid #33455a;
  font-size: 13px;
}
.side .who button {
  margin-top: 8px;
  width: 100%;
  background: transparent;
  color: #9fb2c8;
  border: 1px solid #33455a;
  border-radius: 8px;
  padding: 7px;
}
.topbar {
  display: none;
}
.brandrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 8px;
}
#nav-open,
#nav-hide,
#nav-close,
#nav-show {
  background: none;
  border: 0;
  color: #cdd6e1;
  cursor: pointer;
  padding: 8px;
  border-radius: 7px;
  display: flex;
  align-items: center;
}
#nav-open:hover,
#nav-hide:hover,
#nav-close:hover,
#nav-show:hover {
  background: var(--bg-soft);
  color: #fff;
}
#nav-close {
  display: none;
}
#nav-show {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 50;
  background: var(--bg);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}
.shell.nav-off .side {
  display: none;
}
.shell.nav-off #nav-show {
  display: flex;
}
.shell.nav-off .main {
  padding-top: 46px;
}
.main {
  flex: 1;
  min-width: 0;
  padding: 22px 26px 60px;
}
.page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.page-head h1 {
  margin: 0;
}
.page-head .spacer {
  flex: 1;
}

/* ---------- Controles ---------- */
.btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 9px 16px;
  font-weight: 600;
}
.btn:hover {
  filter: brightness(1.06);
}
.btn.sec {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}
.btn.danger {
  background: var(--danger);
}
.btn.small {
  padding: 5px 10px;
  font-size: 13px;
  border-radius: 6px;
}
.btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.field {
  display: grid;
  gap: 5px;
  margin-bottom: 12px;
}
.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}
.field input,
.field select,
.field textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  background: #fff;
  min-width: 0;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}
.grid3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0 14px;
}

/* ---------- Tarjetas y tablas ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.tablewrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 14px;
}
th,
td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th {
  background: #f8fafc;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  position: sticky;
  top: 0;
}
tbody tr:hover {
  background: #f4f8ff;
  cursor: pointer;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  background: var(--accent-soft);
  color: #1a4fc0;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12.5px;
  font-weight: 600;
  border: 0;
}
.chip.pick {
  background: #eef1f5;
  color: var(--ink);
  border: 1px solid var(--line);
  cursor: pointer;
}
.chip.pick:hover {
  background: var(--accent-soft);
}
.chip.on {
  background: var(--accent);
  color: #fff;
}
.chip.pick.on,
.chip.pick.on:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip.on span,
.chip.on .muted,
.chip.pick.on span,
.chip.pick.on .muted {
  color: #d7e4ff;
}
.chip button {
  background: none;
  border: 0;
  color: inherit;
  font-weight: 700;
  padding: 0 0 0 6px;
}
.badge {
  background: #eef1f5;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
}

/* ---------- Filtros ---------- */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 2px;
  margin-bottom: 14px;
}

/* ---------- Visita ---------- */
.steps {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.step {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}
.step.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.vivienda-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

/* ---------- Detalle ---------- */
/* Indicador de conexión (diseño de Jorge): conectado solo un círculo verde
   con tick; sin conexión pastilla roja con dos líneas. */
.offlinestatus a {
  text-decoration: none;
}
.conn-ok {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #1f9d55;
  margin: 0 18px 10px;
}
.conn-ok .tick {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  line-height: 1;
}
.conn-off {
  display: inline-flex;
  flex-direction: column;
  background: #d64545;
  color: #fff;
  border-radius: 10px;
  padding: 6px 12px;
  margin: 0 18px 10px;
}
.conn-off .l1 {
  font-weight: 700;
}
.conn-off .l2 {
  font-size: 12px;
  opacity: 0.95;
}
/* Modal de alta en el gestor de datos */
.modal-ov {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  width: min(440px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}
.modal .m-actions {
  position: sticky;
  bottom: 0;
  background: inherit;
  padding: 10px 0 2px;
}
.modal .close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: 0;
  font-size: 22px;
  color: var(--ink-soft);
  cursor: pointer;
}
/* Barra de actualización de versión */
.upd {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: #123c2b;
  color: #e7f6ee;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 14px;
}
.hist {
  display: grid;
  gap: 10px;
}
.hist .entry {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
}
.hist .entry .meta {
  font-size: 12px;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.fotos {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.fotos .foto {
  position: relative;
}
.fotos img {
  width: 92px;
  height: 92px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.fotos .foto button {
  position: absolute;
  top: -7px;
  right: -7px;
  background: var(--danger);
  color: #fff;
  border: 0;
  border-radius: 999px;
  width: 22px;
  height: 22px;
  font-size: 12px;
  line-height: 1;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  z-index: 60;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  max-width: 90vw;
}
.toast.err {
  background: var(--danger);
}

/* ---------- Móvil: hamburguesa + menú lateral ---------- */
@media (max-width: 820px) {
  .shell {
    flex-direction: column;
  }
  .topbar {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 40;
    padding: 4px 8px;
  }
  .topbar .brand {
    padding: 4px 6px;
    font-size: 18px;
  }
  .side {
    position: fixed;
    left: 0;
    top: 0;
    width: min(280px, 85vw);
    height: 100vh;
    overflow-y: auto;
    transform: translateX(-102%);
    transition: transform 0.18s ease;
    z-index: 70;
  }
  .side.open {
    transform: none;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.45);
  }
  .side .who {
    margin-top: auto;
  }
  #nav-close {
    display: block;
  }
  #nav-hide,
  #nav-show {
    display: none !important;
  }
  .nav-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 65;
  }
  .main {
    padding: 14px 12px 60px;
  }
  .grid2,
  .grid3 {
    grid-template-columns: 1fr;
  }
}

/* ---------- Panel Sin conexión ---------- */
.offlinepanel .card h2 {
  margin: 0 0 10px;
  font-size: 17px;
}
.offlinepanel .card p:first-child {
  margin-top: 0;
}
.offlinepanel .card p:last-child {
  margin-bottom: 0;
}
.offlinepanel .btnrow {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.offlinepanel .ops article {
  border-top: 1px solid var(--line);
  padding: 14px 0;
}
.offlinepanel .ops article:first-child {
  border-top: 0;
  padding-top: 2px;
}
.offlinepanel .ops article h3 {
  margin: 0 0 4px;
  font-size: 15px;
}
.offlinepanel .ops article > p {
  margin: 0 0 6px;
}
.offlinepanel .opstatus-bad {
  color: var(--danger);
  font-weight: 600;
}
.conflictfield {
  display: inline-block;
  vertical-align: top;
  margin: 4px 22px 4px 0;
}
.conflictfield h4 {
  margin: 0 0 2px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
}
.conflictfield p {
  margin: 0;
}
.conflict-resolve {
  background: #fff8e6;
  border: 1px solid #ecd9a0;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 10px 0 4px;
}
.conflict-resolve p {
  margin: 0;
}
label.check {
  display: flex;
  align-items: center;
  gap: 7px;
}

/* Indicador ámbar: con conexión pero con cambios pendientes o por revisar. */
.conn-pend {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #d97706;
  margin: 0 18px 10px;
}
.conn-pend .mark {
  color: #fff;
  font-weight: 700;
  line-height: 1;
}

/* Reordenar arrastrando: asa táctil/ratón, fila en arrastre y destino. */
.drag-handle {
  cursor: grab;
  touch-action: none;
  user-select: none;
  min-width: 40px;
  min-height: 36px;
}
.drag-handle:active {
  cursor: grabbing;
}
.drag-handle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
tr.dragging {
  opacity: 0.45;
}
tr.drop-target td {
  border-top: 2px solid var(--accent);
}

/* Gestor en pantallas estrechas: las acciones de fila envuelven para que
   el asa de arrastre y los botones queden dentro del viewport. */
@media (max-width: 640px) {
  .tablewrap td.rowactions {
    white-space: normal;
    min-width: 132px;
  }
  .tablewrap td.rowactions .btn {
    margin: 0 0 4px 4px;
  }
}

.tablewrap td.rowactions {
  text-align: right;
  white-space: nowrap;
}

/* Gestor en pantallas estrechas (refuerzo final, debe ir al final del
   archivo): las celdas envuelven para que nombre, enlaces y asa quepan. */
@media (max-width: 640px) {
  .tablewrap td {
    white-space: normal;
  }
  .tablewrap td:first-child {
    min-width: 110px;
  }
  .tablewrap td input {
    min-width: 0;
  }
}

@media (max-width: 640px) {
  .tablewrap td.rowactions {
    white-space: normal;
    min-width: 132px;
  }
}

@media (max-width: 640px) {
  .tablewrap td {
    padding: 8px 8px;
  }
}

@media (max-width: 640px) {
  .tablewrap td:first-child {
    min-width: 96px;
  }
  .tablewrap td.rowactions .btn {
    padding: 5px 8px;
  }
}

@media (max-width: 640px) {
  .tablewrap td:first-child {
    min-width: 106px;
  }
  .tablewrap td.rowactions {
    min-width: 122px;
  }
}

/* Lote 15-nov. */
/* Empresas/Oficios en el gestor: aire entre el resumen de enlaces y su botón
   (antes el texto largo quedaba pegado al botón, captura de Jorge). */
[data-links] .btn {
  margin-left: 12px;
}
/* Mientras se arrastra una fila del gestor, nada de la tabla se puede
   seleccionar: en táctil el mantener pulsado abría la selección de texto y
   «se seleccionaba todo» (Jorge 15-nov). */
.tablewrap tbody.drag-active,
.tablewrap tbody.drag-active * {
  -webkit-user-select: none !important;
  user-select: none !important;
  -webkit-touch-callout: none !important;
}

/* Aviso de datos actualizados (Jorge 16-nov): la sync nunca regenera la
   vista; solo ofrece refrescar, abajo a la derecha y sin estorbar. */
.updnotice {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 45;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #1f2937;
  color: #fff;
  border-radius: 10px;
  padding: 8px 10px 8px 14px;
  font-size: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
.updnotice .btn {
  background: #fff;
  color: #1f2937;
  border: none;
}

/* Etiquetas de texto libre con sugerencias (16-nov) */
.field{position:relative}
.etqsug{position:absolute;left:0;right:0;top:100%;z-index:46;background:#fff;border:1px solid #d5dbe7;border-radius:10px;box-shadow:0 8px 24px rgba(15,23,42,.14);overflow:hidden;max-height:220px;overflow-y:auto}
.etqsug-item{display:block;width:100%;text-align:left;padding:9px 12px;border:0;background:#fff;cursor:pointer;font-size:14px;color:#0f172a}
.etqsug-item:hover{background:#f1f5f9}

/* Paginación del listado (16-nov): selector de tamaño arriba a la izquierda
   de la tabla y navegación de páginas debajo */
.pagbar{display:flex;align-items:center;gap:8px;margin:6px 0}
.pagbar select{width:auto;padding:4px 8px}

/* Ordenación del listado por cabecera (16-nov) */
.tablewrap th.sortable{cursor:pointer;user-select:none;white-space:nowrap}
.tablewrap th .sa{font-size:10px;opacity:.7}
