:root {
  --bg: #f3f4f6; --card: #ffffff; --text: #16191d; --muted: #6b7280; --line: #e3e5e8;
  --accent: #1d6fe0; --accent-text: #ffffff; --accent-soft: #e6efff;
  --ok: #138a4b; --ok-soft: #e3f5ea; --warn: #9a5b00; --warn-soft: #fdf1dc;
  --bad: #c0352b; --bad-soft: #fde8e6; --gris-soft: #eceef1;
  --radio: 12px; --sombra: 0 1px 2px rgba(0,0,0,.06), 0 1px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --card: #191d23; --text: #eef0f3; --muted: #9aa3ae; --line: #2a3038;
    --accent: #5b9bff; --accent-text: #0b1220; --accent-soft: #15264a;
    --ok: #4ccf86; --ok-soft: #133323; --warn: #f0b456; --warn-soft: #3a2a10;
    --bad: #ff7a6e; --bad-soft: #3b1714; --gris-soft: #232830;
    --sombra: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --card: #191d23; --text: #eef0f3; --muted: #9aa3ae; --line: #2a3038;
  --accent: #5b9bff; --accent-text: #0b1220; --accent-soft: #15264a;
  --ok: #4ccf86; --ok-soft: #133323; --warn: #f0b456; --warn-soft: #3a2a10;
  --bad: #ff7a6e; --bad-soft: #3b1714; --gris-soft: #232830;
  --sombra: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

.barra {
  position: sticky; top: 0; z-index: 500; background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  display: flex; align-items: center; gap: 12px;
}
.barra .titulo { flex: 1; min-width: 0; }
.barra .titulo b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.angosto { max-width: 640px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radio);
  box-shadow: var(--sombra); padding: 14px;
}
.lista { display: grid; gap: 10px; }
.fila { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.fila > .crece { flex: 1; min-width: 0; }
.grilla { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

button, .boton {
  font: inherit; font-weight: 600; border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 10px; padding: 10px 14px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
}
button:disabled { opacity: .55; cursor: default; }
.primario { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.exito { background: var(--ok); border-color: var(--ok); color: #fff; }
.peligro { color: var(--bad); }
.chico { min-height: 34px; padding: 6px 10px; font-size: 13px; }
.bloque { width: 100%; }
.acciones { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.acciones .ancho { grid-column: 1 / -1; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); min-height: 44px;
}
textarea { min-height: 84px; resize: vertical; }
.campos { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.campos .ancho { grid-column: 1 / -1; }
@media (max-width: 560px) { .campos { grid-template-columns: 1fr; } }

.pill {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px;
  font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--gris-soft); color: var(--muted);
}
.pill.asignada { background: var(--gris-soft); color: var(--muted); }
.pill.en_camino { background: var(--accent-soft); color: var(--accent); }
.pill.en_domicilio { background: var(--warn-soft); color: var(--warn); }
.pill.cerrada { background: var(--ok-soft); color: var(--ok); }
.pill.cancelada { background: var(--bad-soft); color: var(--bad); }
.pill.reprogramar { background: var(--warn-soft); color: var(--warn); }
.senal { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 6px; }
.senal + .senal { margin-top: 8px; }
.senal .valores { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.senal .valores small { display: block; color: var(--muted); font-size: 11px; }
.senal .valores strong { font-size: 15px; }
.galeria { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.galeria .ft { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--gris-soft); }
.galeria .ft img { width: 100%; height: 100%; object-fit: cover; display: block; }
.galeria .ft button { position: absolute; top: 4px; right: 4px; min-height: 0; width: 28px; height: 28px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; border: 0; }
.firma-canvas { width: 100%; height: 180px; border: 1px dashed var(--line); border-radius: 10px; background: #fff; touch-action: none; display: block; }
.seccion { display: grid; gap: 10px; }
.seccion > h3 { display: flex; align-items: center; gap: 8px; }
details > summary { cursor: pointer; font-weight: 600; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::after { content: ' ▾'; color: var(--muted); }
.banner { position: sticky; top: 64px; z-index: 400; background: var(--accent); color: var(--accent-text); padding: 10px 16px; font-weight: 700; text-align: center; cursor: pointer; }
.tag { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.avatar {
  width: 44px; height: 44px; border-radius: 50%; object-fit: cover; flex: none; background: var(--accent-soft);
  color: var(--accent); display: grid; place-items: center; font-weight: 700;
}
.foto-movil { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 10px; background: var(--gris-soft); display: block; }

.tabs { display: flex; gap: 4px; background: var(--gris-soft); padding: 4px; border-radius: 12px; }
.tabs button { flex: 1; border: 0; background: transparent; min-height: 38px; }
.tabs button.activa { background: var(--card); box-shadow: var(--sombra); }

.mapa { height: 260px; border-radius: 10px; border: 1px solid var(--line); z-index: 0; }

dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
  background: var(--card); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .cab { padding: 14px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
dialog .cab h2 { flex: 1; }
dialog .cuerpo { padding: 16px; overflow: auto; max-height: calc(100vh - 170px); }
dialog .pie { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

#toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600;
  z-index: 2000; max-width: calc(100vw - 32px); opacity: 0; transition: opacity .2s; pointer-events: none;
}
#toast.visible { opacity: 1; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); display: grid; gap: 12px; }
.vacio { text-align: center; padding: 32px 16px; color: var(--muted); }
.separador { height: 1px; background: var(--line); margin: 12px 0; }
.pin-casa { font-size: 26px; line-height: 1; filter: drop-shadow(0 1px 2px rgba(0,0,0,.4)); }
