:root {
  --fondo: #f4f6f9;
  --texto: #1f2933;
  --gris: #6b7785;
  --borde: #d9dee5;
  --primario: #1f6feb;
  --primario-osc: #1859c4;
  --ok: #1a7f37;
  --error: #c62828;
  --naranja: #fff1dd;
  --naranja-borde: #f0a040;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--texto);
  background: var(--fondo);
}

a { color: var(--primario); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.35rem; margin: 0 0 .8rem; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 .6rem; }

/* ---------- Cabecera ---------- */
.top {
  display: flex; align-items: center; gap: 1.5rem;
  background: #16212e; color: #fff; padding: .55rem 1.2rem;
  position: sticky; top: 0; z-index: 20;
}
.top .marca { color: #fff; font-weight: 700; font-size: 1.05rem; }
.top nav { display: flex; gap: .3rem; flex: 1; }
.top nav a { color: #c9d4e0; padding: .35rem .7rem; border-radius: 6px; }
.top nav a.on, .top nav a:hover { background: #2a3a4d; color: #fff; text-decoration: none; }
.top .yo { display: flex; align-items: center; gap: .9rem; color: #c9d4e0; font-size: .9rem; }
.top .yo a { color: #c9d4e0; }
.inline { display: inline; margin: 0; }
button.link { background: none; border: 0; color: #c9d4e0; cursor: pointer; font: inherit; padding: 0; }
button.link:hover { color: #fff; text-decoration: underline; }

main { padding: 1rem 1.2rem 3rem; }
main.centro { display: flex; justify-content: center; padding-top: 12vh; }

/* ---------- Formularios ---------- */
.caja {
  background: #fff; border: 1px solid var(--borde); border-radius: 10px;
  padding: 1.6rem; width: 100%; max-width: 380px; margin: 0 auto;
  display: flex; flex-direction: column; gap: .9rem;
}
.caja label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .9rem; }
.caja input { padding: .55rem .6rem; border: 1px solid var(--borde); border-radius: 6px; font: inherit; }

.btn {
  display: inline-block; background: var(--primario); color: #fff; border: 0; border-radius: 6px;
  padding: .5rem .9rem; font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.btn:hover { background: var(--primario-osc); text-decoration: none; }
.btn.sec { background: #e8edf3; color: var(--texto); }
.btn.sec:hover { background: #dbe2ea; }
.btn.peligro { background: var(--error); }

.error { background: #fdecea; color: var(--error); padding: .6rem .8rem; border-radius: 6px; margin: 0; }
.ok { background: #e8f5ec; color: var(--ok); padding: .6rem .8rem; border-radius: 6px; margin: 0; }
.aviso { background: #fff7e0; color: #7a5b00; padding: .6rem .8rem; border-radius: 6px; margin: 0; }
.gris { color: var(--gris); }
.nowrap { white-space: nowrap; }

/* ---------- Filtros ---------- */
.filtros {
  display: flex; flex-wrap: wrap; gap: .6rem .8rem; align-items: flex-end;
  background: #fff; border: 1px solid var(--borde); border-radius: 10px; padding: .8rem 1rem; margin-bottom: .8rem;
}
.filtros label { display: flex; flex-direction: column; gap: .2rem; font-size: .75rem; font-weight: 600; color: var(--gris); text-transform: uppercase; }
.filtros input, .filtros select {
  font: inherit; font-size: .85rem; padding: .35rem .45rem; border: 1px solid var(--borde); border-radius: 5px;
  min-width: 130px; background: #fff; color: var(--texto); text-transform: none;
}
.filtros label.ancho input { min-width: 260px; }
.filtros label.nfilas select { min-width: 70px; }
.filtros .acciones { display: flex; gap: .4rem; margin-left: auto; }

.resumen { margin: .4rem 0 .6rem; font-size: 1rem; }
.cabecera { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .7rem 1rem; border-radius: 8px; margin-bottom: .8rem; }
.cabecera h1 { margin: 0; }

/* ---------- Tablas ---------- */
.tabla-scroll { overflow: auto; max-height: calc(100vh - 260px); background: #fff; border: 1px solid var(--borde); border-radius: 8px; }
.tabla { border-collapse: collapse; width: 100%; font-size: .78rem; }
.tabla th {
  position: sticky; top: 0; z-index: 2; background: #e9eef4; text-align: left; white-space: nowrap;
  padding: .45rem .5rem; border-bottom: 1px solid var(--borde); font-size: .72rem;
}
.tabla th a { color: var(--texto); }
.tabla td { padding: .2rem .35rem; border-bottom: 1px solid rgba(0,0,0,.07); vertical-align: middle; }
.tabla td.vacio { text-align: center; color: var(--gris); padding: 2rem; }

/* Celdas editables del listado: heredan el color de la fila (color del estado) */
.ayudas input, .ayudas select, .ayudas textarea {
  font: inherit; font-size: .75rem; color: inherit; background: transparent;
  border: 1px solid transparent; border-radius: 3px; padding: .15rem .2rem; width: 100%;
}
.ayudas input:hover, .ayudas select:hover, .ayudas textarea:hover { border-color: rgba(0,0,0,.25); }
.ayudas input:focus, .ayudas select:focus, .ayudas textarea:focus { outline: none; border-color: var(--primario); background: rgba(255,255,255,.85); color: #000; }
.ayudas select option { color: #000; background: #fff; }
.ayudas textarea { resize: vertical; min-width: 200px; background: rgba(255,255,255,.12); }
.ayudas td.ver a { color: inherit; opacity: .75; font-size: .7rem; }
.ayudas .c-empresa { min-width: 55px; }
.ayudas .c-segmento { min-width: 60px; }
.ayudas .c-cliente_id { min-width: 150px; }
.ayudas .c-cliente { min-width: 170px; }
.ayudas .c-contacto, .ayudas .c-telefono, .ayudas .c-expediente { min-width: 110px; }
.ayudas .c-contratos { min-width: 70px; }
.ayudas .c-servicio_id, .ayudas .c-estado { min-width: 130px; }
.ayudas .c-importe { min-width: 80px; }
.ayudas .c-gestor, .ayudas .c-comercial_id { min-width: 120px; }
.ayudas td[class*="fecha"], .ayudas .c-banco, .ayudas .c-plazo_maximo_entrega { min-width: 118px; }
.ayudas select.factura { color: #fff; font-weight: 600; }
.ayudas select.factura.f1 { background: #2cbc09; }
.ayudas select.factura.f0 { background: #f25757; }
.ayudas .guardado { box-shadow: 0 0 0 2px var(--ok) inset; }
.ayudas .fallo { box-shadow: 0 0 0 2px var(--error) inset; }

.paginas { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin: .8rem 0; }
.paginas a, .paginas b { padding: .3rem .6rem; border-radius: 5px; background: #fff; border: 1px solid var(--borde); }
.paginas b { background: var(--primario); color: #fff; border-color: var(--primario); }

/* ---------- Ficha ---------- */
.ficha { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .5rem; background: #fff; border: 1px solid var(--borde); border-radius: 10px; padding: 1rem; margin: 0; }
.ficha div { border-bottom: 1px solid #eef1f5; padding: .3rem 0; }
.ficha dt { font-size: .72rem; text-transform: uppercase; color: var(--gris); font-weight: 600; }
.ficha dd { margin: .1rem 0 0; }

/* ---------- Dispositivos ---------- */
.disp td { padding: .3rem .4rem; }
.disp input, .disp select { font: inherit; font-size: .8rem; padding: .3rem .4rem; border: 1px solid var(--borde); border-radius: 5px; width: 100%; background: #fff; }
.disp tr.manual { background: var(--naranja); }
.disp tr.manual td { border-bottom-color: var(--naranja-borde); }
.pill { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-weight: 600; font-size: .75rem; }
.disp .col-exp { min-width: 230px; position: relative; }
.disp .col-cli { min-width: 170px; }
.disp .col-dis { min-width: 190px; }
.disp .col-est { min-width: 170px; }
.disp .col-fec { min-width: 130px; }
.btn-mini { border: 1px solid var(--borde); background: #fff; border-radius: 5px; padding: .25rem .5rem; cursor: pointer; font: inherit; font-size: .8rem; }
.btn-mini.on { background: var(--naranja-borde); color: #fff; border-color: var(--naranja-borde); }
.btn-mini.borrar { color: var(--error); }
.autocomplete { position: absolute; left: .4rem; right: .4rem; top: 100%; z-index: 30; background: #fff; border: 1px solid var(--borde); border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.12); max-height: 280px; overflow: auto; }
.autocomplete div { padding: .4rem .55rem; cursor: pointer; border-bottom: 1px solid #f0f2f5; font-size: .8rem; }
.autocomplete div:hover, .autocomplete div.activo { background: #eef4ff; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 100; padding: .6rem 1rem; border-radius: 8px;
  color: #fff; background: var(--ok); box-shadow: 0 6px 18px rgba(0,0,0,.2); font-weight: 600;
}
.toast.error { background: var(--error); }

@media (max-width: 700px) {
  .top { flex-wrap: wrap; gap: .5rem; }
  .filtros .acciones { margin-left: 0; }
  .filtros label.ancho input { min-width: 0; }
}
