:root {
  --bg: #f3f6fc; --surface: #ffffff; --surface-2: #e9eef8;
  --ink: #0e1a33; --ink-2: #43506b; --ink-3: #5f6b84; --line: #dce3f0;
  --accent: #1564e6; --accent-ink: #ffffff; --accent-text: #1564e6;
  --brand: #0a1a3a; --brand-raised: #13285a; --brand-line: #1f3566; --brand-ink-2: #a9b8d6;
  --red: #b8291d; --red-bg: #fde9e6; --amber: #8a5300; --amber-bg: #fff2d6;
  --green: #17703d; --green-bg: #e1f5e8; --blue: #2563c9; --blue-bg: #e3ecfb;
  --radius: 14px; --shadow: 0 1px 2px rgba(18,22,26,.06), 0 2px 8px rgba(18,22,26,.05);
  --mono: ui-monospace, 'SF Mono', Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #071022; --surface: #0f1a30; --surface-2: #16243f; --ink: #eaf0fb; --ink-2: #adb9d0; --ink-3: #7c89a4;
    --line: #22314f; --brand: #060d1c; --brand-raised: #112142; --brand-line: #182a4d;
    --red: #ff6b5c; --red-bg: #3a1714; --amber: #ffb547; --amber-bg: #352510;
    --green: #4ad584; --green-bg: #112d1d; --blue: #7aa7ff; --blue-bg: #15233d; --shadow: none; color-scheme: dark;
    --accent-text: #7aa7ff;
  }
}
:root[data-theme="dark"] {
  --bg: #071022; --surface: #0f1a30; --surface-2: #16243f; --ink: #eaf0fb; --ink-2: #adb9d0; --ink-3: #7c89a4;
  --line: #22314f; --brand: #060d1c; --brand-raised: #112142; --brand-line: #182a4d;
  --red: #ff6b5c; --red-bg: #3a1714; --amber: #ffb547; --amber-bg: #352510;
  --green: #4ad584; --green-bg: #112d1d; --blue: #7aa7ff; --blue-bg: #15233d; --shadow: none; color-scheme: dark;
  --accent-text: #7aa7ff;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--bg); color: var(--ink);
  font-size: 15px; line-height: 1.4; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }

/* ---------- estructura: menú lateral en escritorio, barra abajo en el celular ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100dvh; }
.side { background: var(--brand); color: #fff; padding: 16px 12px; position: sticky; top: 0; height: 100dvh; display: flex; flex-direction: column; gap: 4px; }
.side nav { display: flex; flex-direction: column; gap: 2px; margin-top: 12px; }
.side a.nav { color: var(--brand-ink-2); text-decoration: none; padding: 10px 12px; border-radius: 10px; font-weight: 500; display: flex; align-items: center; gap: 10px; min-height: 44px; }
.side a.nav.on, .side a.nav:hover { background: var(--brand-raised); color: #fff; }
.side a.nav svg { width: 20px; height: 20px; flex: none; }
/* barra superior y engranaje: medidas exactas de Cobranzas e750652 (ORQ-80) */
.barra-acciones { display: flex; align-items: center; gap: 10px; }
.barra-btn { width: 36px; height: 36px; border-radius: 10px; border: 0; background: rgba(255,255,255,.08); color: #fff; display: grid; place-items: center;
  cursor: pointer; flex: none; padding: 0; }
.barra-btn:active { background: rgba(255,255,255,.18); }
.barra-btn svg { width: 19px; height: 19px; stroke-width: 2; }
/* computadora: barra transparente arriba del contenido (el reloj), botones de 40 px */
.barra-escr { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px 0; max-width: 1100px; }
.barra-escr[hidden] { display: none; }
.barra-escr .barra-btn { width: 40px; height: 40px; background: var(--surface); border: 1px solid var(--line); color: var(--ink); }
.barra-escr .barra-btn:hover { border-color: var(--ink-3); }
/* computadora: el engranaje al pie de la barra lateral, al lado del nombre */
.side .pie .barra-btn { width: 34px; height: 34px; background: transparent; color: var(--brand-ink-2); }
.side .pie .barra-btn:hover { background: rgba(255,255,255,.08); color: #fff; }
.pie-txt { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.pie-txt strong { color: #fff; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pie-txt span { font-size: 12px; }
/* menú del engranaje: fijo en pantalla */
.ajustes-menu { position: fixed; z-index: 30; min-width: 220px; padding: 6px; border-radius: 12px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0,0,0,.18); }
.ajustes-menu .mod-op { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; font-size: 14px; font-weight: 500; color: var(--ink); text-decoration: none; }
.ajustes-menu .mod-op:hover { background: var(--surface-2); }
.ajustes-menu .mod-op.on { color: var(--accent); }
.ajustes-menu .mod-op svg { width: 20px; height: 20px; flex: none; color: var(--ink-3); }
.ajustes-menu .mod-op.on svg { color: var(--accent); }
.ajustes-menu button.mod-op { width: 100%; border: 0; background: none; font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; text-align: left; }
.menu-usuario { padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; display: flex; flex-direction: column; }
.menu-usuario span { color: var(--ink-3); font-size: 13px; }
.side .pie { margin-top: auto; font-size: 13px; color: var(--brand-ink-2); display: flex; align-items: center; gap: 8px; padding: 8px 4px 0 8px; border-top: 1px solid var(--brand-line); }
main.cont { padding: 24px; max-width: 1100px; width: 100%; }
.top { display: none; }
.bottom { display: none; }
.globo { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--amber); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-grid; place-items: center; line-height: 1; }
.side .globo { margin-left: auto; }
/* las listas (.lista) tienen su propio display: !important para que no las pisen */
.solo-cel { display: none !important; }
@media (max-width: 820px) {
  .layout { display: block; }
  .side { display: none; }
  .solo-cel { display: flex !important; }
  .solo-escr { display: none !important; }
  .top { display: flex; align-items: center; gap: 10px; background: var(--brand); color: #fff;
    padding: calc(12px + env(safe-area-inset-top)) 16px 12px; position: sticky; top: 0; z-index: 5; }
  .top .top-sel { margin-right: auto; }
  .barra-escr { display: none !important; }
  main.cont { padding: 16px 16px calc(92px + env(safe-area-inset-bottom)); }
  .bottom { display: grid; grid-template-columns: repeat(var(--n, 5), 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
    background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .bottom a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 52px;
    font-size: 11px; color: var(--ink-3); text-decoration: none; font-weight: 600; }
  .bottom a svg { width: 22px; height: 22px; }
  .bottom a[aria-current="page"] { color: var(--accent-text); }
  .bottom a .globo { position: absolute; top: 4px; left: calc(50% + 6px); }
}

/* ---------- selector de módulos ---------- */
.mod { position: relative; }
.mod-btn { display: flex; align-items: center; gap: 6px; background: none; border: 0; color: #fff; font-weight: 700; font-size: 17px; padding: 4px 6px; border-radius: 8px; cursor: pointer; }
.mod-btn:hover { background: var(--brand-raised); }
.mod-nombre { color: #fff; font-weight: 700; font-size: 17px; padding: 4px 6px; display: flex; align-items: center; gap: 8px; }
.mod img.logo, .mod-btn img.logo { width: 24px; height: 24px; }
.mod-menu { position: absolute; top: calc(100% + 6px); left: 0; min-width: 220px; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 6px; z-index: 20; }
.mod-op { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500; }
a.mod-op:hover { background: var(--surface-2); }
.mod-op.on { color: var(--accent); font-weight: 700; }
.mod-ini { width: 20px; height: 20px; border-radius: 6px; background: var(--surface-2); display: grid; place-items: center; font-size: 12px; font-weight: 700; }

/* ---------- piezas ---------- */
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 24px 0 10px; }
.cab { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.cab-h2 { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 24px 0 10px; }
.cab-h2 h2 { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.lista { display: flex; flex-direction: column; gap: 10px; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: start; color: inherit; }
.item .tit { font-weight: 600; color: var(--ink); text-decoration: none; }
.item .tit:hover { color: var(--accent-text); }
.item a.sub { text-decoration: none; }
.item .sub { color: var(--ink-3); font-size: 13px; grid-column: 1 / -1; display: flex; gap: 6px 14px; flex-wrap: wrap; }
.item .viejo { color: var(--red); font-weight: 600; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 0 14px; min-height: 40px; cursor: pointer; font-weight: 500; font-size: 14px; }
.chip.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip .n { margin-left: 4px; opacity: .7; }
.badge { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-gris { background: var(--surface-2); color: var(--ink-2); }
.b-azul { background: var(--blue-bg); color: var(--blue); }
.b-ambar { background: var(--amber-bg); color: var(--amber); }
.b-verde { background: var(--green-bg); color: var(--green); }
.b-rojo { background: var(--red-bg); color: var(--red); }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 0 16px; min-height: 44px; font-weight: 600; cursor: pointer; text-decoration: none;
  color: var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.pri { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.peligro { color: var(--red); }
.btn.chico { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.volver { margin: 0 0 10px; }
.fila { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
dl.datos { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dl.datos dt { color: var(--ink-3); }
dl.datos dd { margin: 0; overflow-wrap: anywhere; }
label.campo { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
/* 16 px y 44 px de alto: el iPhone no hace zoom al tocar un campo */
input, select, textarea { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 0 12px; font-size: 16px; min-height: 44px; min-width: 0; }
textarea { min-height: 88px; padding: 10px 12px; resize: vertical; }
input[type="checkbox"] { min-height: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-text); outline-offset: -1px; }
.buscar { width: 100%; margin-bottom: 12px; }
form.form { display: grid; gap: 12px; }
.fotos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; max-width: 420px; }
.fotos button { padding: 0; border: 0; background: none; cursor: zoom-in; aspect-ratio: 1; border-radius: 10px; overflow: hidden; }
.fotos img { width: 100%; height: 100%; object-fit: cover; display: block; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; }
dialog.foto { width: min(900px, calc(100% - 24px)); padding: 12px; }
dialog.foto img { width: 100%; max-height: 75dvh; object-fit: contain; display: block; border-radius: 8px; background: #000; }
.persona { border-top: 1px solid var(--line); padding: 10px 0; }
.persona:first-child { border-top: 0; padding-top: 0; }
.vacio { text-align: center; color: var(--ink-3); padding: 28px 12px; }
.vacio p { margin: 4px 0 0; font-size: 13px; }
table.tabla { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla th { text-align: left; color: var(--ink-3); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tabla td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tabla td.der, .tabla th.der { text-align: right; }
.scroll { overflow-x: auto; }
.cero { color: var(--ink-3); }
.hay { color: var(--amber); }
.barra { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; min-width: 80px; }
.barra > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.barra.lleno > span { background: var(--green); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
@media (max-width: 820px) { .stats { grid-template-columns: 1fr 1fr; } }
.stat { text-decoration: none; color: inherit; }
.stat .v { font-size: 24px; font-weight: 700; }
.stat .l { color: var(--ink-3); font-size: 13px; }
.ficha h3 { margin: 0 0 8px; font-size: 16px; }
.ficha .linea { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-size: 14px; }
.aviso { background: var(--amber-bg); color: var(--amber); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }
details.crudo summary { cursor: pointer; color: var(--ink-3); font-size: 13px; }
details.crudo div { font-family: var(--mono); font-size: 12px; color: var(--ink-3); overflow-wrap: anywhere; margin-top: 4px; }
#toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--surface);
  padding: 10px 16px; border-radius: 10px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; width: max-content; max-width: calc(100% - 32px);
  display: flex; align-items: center; gap: 14px; }
#toast.ver { opacity: 1; pointer-events: auto; }
#toast button { background: none; border: 0; color: var(--surface); font-weight: 700; text-decoration: underline; cursor: pointer; min-height: 36px; padding: 0 4px; }
dialog { border: 0; border-radius: 16px; padding: 20px; width: min(520px, calc(100% - 32px)); max-height: calc(100dvh - 32px); overflow: auto;
  background: var(--surface); color: var(--ink); box-shadow: 0 12px 40px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(7,16,34,.5); }
/* ---------- En curso y las hojas para mover trabajos (ORQ-120) ---------- */
.ec h2 { margin-top: 18px; }
.ec-cols { display: grid; gap: 0 18px; }
.ec-cols > * { min-width: 0; }
.viejo { color: var(--red); font-weight: 600; }
.libre { color: var(--green); font-weight: 600; }
.oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.persona-cab { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.persona-cab > div { min-width: 0; }
.persona-cab h3 { margin: 0; font-size: 16px; overflow-wrap: anywhere; }
.persona-cab .btn, .trabajo .btn { flex: none; min-height: 44px; }
.persona-ec { padding: 12px 14px; }
.lista-tr { padding: 2px 14px; }
.lista-tr > .btn { margin: 10px 0; }
.trabajo { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.persona-cab + .trabajo { margin-top: 10px; }
.lista-tr > .trabajo:first-child { border-top: 0; }
.trabajo > svg { width: 20px; height: 20px; flex: none; color: var(--ink-3); align-self: flex-start; margin-top: 2px; }
.trabajo-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; color: inherit; text-decoration: none; min-height: 44px; justify-content: center; }
.op-nombre { font-weight: 600; overflow-wrap: anywhere; }
.trabajo-txt:hover .op-nombre { color: var(--accent-text); }
.plegable { border-top: 1px solid var(--line); margin-top: 10px; }
.plegable summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); list-style: none; }
.plegable summary::-webkit-details-marker { display: none; }
.plegable summary::before { content: '▸'; }
.plegable[open] summary::before { content: '▾'; }
.persona-ec > .plegable:last-child { margin-bottom: -12px; }
.btn.ancho { width: 100%; }
dialog.hoja { padding: 0; width: min(560px, calc(100% - 32px)); overflow: hidden; }
dialog.hoja[open] { display: flex; flex-direction: column; }
.hoja-cab { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 16px 10px; }
.hoja-cab > div { min-width: 0; }
.hoja-cab h2 { margin: 0; overflow-wrap: anywhere; }
.hoja-cab h2:focus { outline: none; }
.hoja-cab p { margin: 2px 0 0; }
.hoja-cab .btn { flex: none; min-height: 44px; }
.hoja-cuerpo { overflow-y: auto; padding: 4px 16px 16px; overscroll-behavior: contain; }
.hoja-pie { border-top: 1px solid var(--line); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); display: flex; gap: 8px; flex-wrap: wrap; }
.hoja-pie[hidden] { display: none; }
.hoja-pie .btn.pri { flex: 1; }
.hoja-h { font-size: 14px; margin: 14px 0 6px; }
.hoja-h:first-child { margin-top: 0; }
.ops { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.op-persona, .op-trabajo { display: flex; gap: 10px; align-items: center; min-height: 56px; padding: 8px 14px; border: 0; border-top: 1px solid var(--line); background: none; text-align: left; cursor: pointer; width: 100%; }
.ops > :first-child { border-top: 0; }
.op-persona { justify-content: space-between; }
.op-persona .small { flex: none; text-align: right; max-width: 55%; }
.op-persona:hover, .op-trabajo:hover { background: var(--surface-2); }
.op-persona:disabled { opacity: .5; }
.op-persona:focus-visible, .op-trabajo:focus-within { outline-offset: -2px; }
.op-trabajo > span { display: flex; flex-direction: column; min-width: 0; }
.op-trabajo input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.recorte { margin: 4px 0 0; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
@media (min-width: 1000px) { .ec-cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); } }
@media (max-width: 820px) {
  .ec .chip { padding: 0 11px; font-size: 13px; }
  .ec .lista { gap: 8px; }
  dialog.hoja { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 16px 16px 0 0; max-height: 88dvh; }
  .hoja-cuerpo { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .item .pasar { width: 100%; min-height: 44px; }
}
.login { min-height: 100dvh; display: grid; place-items: center; background: var(--brand); padding: 16px; }
.login .card { width: min(380px, 100%); }
@media (max-width: 820px) {
  /* lista en una columna; el selector de asignar a lo ancho */
  .item { grid-template-columns: 1fr; }
  .item select { width: 100%; }
  .item .der { justify-content: flex-start; }
}

/* Cerrar un recupero desde la web (ORQ-169) */
.campo[hidden] { display: none; }
.opciones-cierre { display: grid; gap: 8px; }
.opciones-cierre label { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.opciones-cierre label:has(input:checked) { border-color: var(--accent); }
.opciones-cierre input { margin: 3px 0 0; flex: none; width: 18px; height: 18px; }
.opciones-cierre label > span { display: grid; gap: 2px; }
/* Ubicación del domicilio en el detalle (ORQ-219) */
.ubic { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.ubic .btn.chico { min-height: 32px; }
