:root {
  --navy: #1d2f5a;
  --navy-2: #2a4277;
  --navy-osc: #15233f;
  --naranja: #f26a2e;
  --naranja-2: #f7913b;
  --naranja-claro: #fff1e8;
  --amarillo: #fbbf24;
  --fondo: #f6f4f1;
  --tarjeta: #ffffff;
  --borde: #ebe6df;
  --borde-fuerte: #d9d2c8;
  --texto: #1c2333;
  --suave: #6b7385;
  --verde: #15803d;
  --rojo: #c0262d;
  --radio: 16px;
  --sombra: 0 1px 2px rgba(29, 47, 90, .04), 0 6px 20px rgba(29, 47, 90, .06);
  --sombra-alta: 0 12px 40px rgba(29, 47, 90, .18);
  --titulos: Nunito, "Segoe UI", system-ui, sans-serif;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  color: var(--texto);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--fondo); }
a { color: var(--navy-2); text-decoration-color: rgba(42, 66, 119, .3); text-underline-offset: 3px; }
h1, h2, h3 { font-family: var(--titulos); }
h1 { font-size: 1.85rem; font-weight: 800; margin: 0 0 4px; color: var(--navy); letter-spacing: -.02em; }
h2 { font-size: 1.12rem; font-weight: 800; margin: 0 0 14px; color: var(--navy); display: flex; align-items: center; gap: 10px; }
h3 { font-size: .78rem; margin: 26px 0 10px; color: var(--suave); text-transform: uppercase; letter-spacing: .08em; font-family: inherit; font-weight: 600; }
h2 .ico-titulo { width: 32px; height: 32px; border-radius: 10px; display: inline-grid; place-items: center; background: var(--naranja-claro); color: var(--naranja); flex: none; }
.suave { color: var(--suave); }
.pequeno { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.oculto { display: none !important; }
svg.ico { width: 18px; height: 18px; flex: none; }

/* ---------- estructura ---------- */
.layout { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.lateral {
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-osc) 100%); color: #fff; padding: 22px 14px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow: hidden;
}
.lateral::after {
  content: ""; position: absolute; width: 260px; height: 260px; border-radius: 50%; right: -150px; top: -150px;
  background: linear-gradient(135deg, var(--naranja-2), var(--naranja)); opacity: .18; pointer-events: none;
}
.boton.blanco { background: #fff; color: var(--navy); border-color: #fff; box-shadow: 0 6px 18px rgba(0, 0, 0, .15); }
.boton.blanco:hover { background: #fff7f1; }
.marca { display: flex; align-items: center; gap: 10px; margin: 0 8px 26px; color: #fff; text-decoration: none; position: relative; z-index: 1; }
.marca b { font-family: var(--titulos); font-weight: 800; font-size: 1.6rem; letter-spacing: -.03em; line-height: 1; }
.marca small { display: block; font-size: .68rem; opacity: .65; letter-spacing: .02em; margin-top: 2px; }
.lateral nav { display: flex; flex-direction: column; gap: 3px; position: relative; z-index: 1; }
.lateral a.nav { color: #c9d2e8; text-decoration: none; padding: 10px 12px; border-radius: 12px; display: flex; gap: 12px; align-items: center; font-weight: 500; transition: background .15s, color .15s; }
.lateral a.nav:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.lateral a.nav.activo { background: linear-gradient(135deg, var(--naranja-2), var(--naranja)); color: #fff; box-shadow: 0 6px 16px rgba(242, 106, 46, .35); }
.lateral a.nav.destacado:not(.activo) { color: #fff; background: rgba(255, 255, 255, .08); }
.lateral .pie { margin-top: auto; position: relative; z-index: 1; display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid rgba(255, 255, 255, .1); }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--amarillo); color: var(--navy); display: grid; place-items: center; font-weight: 800; font-family: var(--titulos); flex: none; }
.lateral .pie .quien { font-size: .85rem; line-height: 1.3; min-width: 0; flex: 1; }
.lateral .pie .quien span { opacity: .65; font-size: .78rem; }
.lateral .pie button { background: rgba(255, 255, 255, .1); border: 0; color: #fff; padding: 8px; border-radius: 10px; }
.lateral .pie button:hover { background: rgba(255, 255, 255, .2); }
.contenido { padding: 30px 36px 70px; max-width: 1440px; width: 100%; min-width: 0; }
.cabecera { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 14px; margin-bottom: 22px; }
.cabecera .sub { color: var(--suave); }
.acciones { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.menu-movil { display: none !important; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .lateral { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px 14px; align-items: center; }
  .lateral::after { display: none; }
  .marca { margin: 0 auto 0 0; }
  .marca b { font-size: 1.3rem; }
  .menu-movil { display: inline-flex !important; background: rgba(255, 255, 255, .12) !important; border: 0 !important; }
  .lateral nav { display: none; width: 100%; padding-top: 10px; }
  .lateral.abierto nav { display: flex; }
  .lateral .pie { display: none; }
  .lateral.abierto .pie { display: flex; width: 100%; margin-top: 10px; }
  .contenido { padding: 18px 16px 70px; }
  h1 { font-size: 1.5rem; }
}

/* ---------- tarjetas y rejillas ---------- */
.tarjeta { background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio); padding: 22px; box-shadow: var(--sombra); }
.tarjeta + .tarjeta { margin-top: 16px; }
.rejilla > .tarjeta { margin-top: 0; }
.rejilla { display: grid; gap: 16px; }
.r2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.r3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.r4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .r3, .r4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .r2, .r3, .r4 { grid-template-columns: minmax(0, 1fr); } }
.detalle-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1150px) { .detalle-grid { grid-template-columns: minmax(0, 1fr); } }

.kpi { display: flex; gap: 14px; align-items: center; text-decoration: none; color: inherit; transition: transform .15s, box-shadow .15s; }
.kpi .icono { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; flex: none; background: var(--naranja-claro); color: var(--naranja); }
.kpi .icono svg { width: 24px; height: 24px; }
.kpi .valor { font-family: var(--titulos); font-size: 1.75rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.kpi .etiqueta { color: var(--suave); font-size: .86rem; }
a.kpi:hover { transform: translateY(-2px); box-shadow: var(--sombra-alta); }
.kpi.azul .icono { background: #e9efff; color: #2b55c9; }
.kpi.verde .icono { background: #e7f6ec; color: var(--verde); }
.kpi.rojo .icono { background: #fdecec; color: var(--rojo); }

.bienvenida { background: linear-gradient(120deg, var(--navy) 0%, var(--navy-2) 100%); color: #fff; border: 0; position: relative; overflow: hidden; margin-bottom: 18px; }
.bienvenida::after { content: ""; position: absolute; width: 240px; height: 240px; border-radius: 50%; right: -60px; top: -120px; background: linear-gradient(135deg, var(--naranja-2), var(--naranja)); }
.bienvenida > * { position: relative; z-index: 1; }
.bienvenida h1 { color: #fff; }
.bienvenida .sub { color: #c9d2e8; }

dl.datos { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 9px 14px; margin: 0; }
dl.datos dt { color: var(--suave); font-size: .88rem; }
dl.datos dd { margin: 0; word-break: break-word; font-weight: 500; }
@media (max-width: 500px) { dl.datos { grid-template-columns: minmax(0, 1fr); gap: 2px; } dl.datos dd { margin-bottom: 8px; } }

/* ---------- tablas ---------- */
.tabla-wrap { overflow-x: auto; background: var(--tarjeta); border: 1px solid var(--borde); border-radius: var(--radio); box-shadow: var(--sombra); }
.tabla-wrap.plana { box-shadow: none; border-radius: 12px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--borde); vertical-align: middle; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .07em; color: var(--suave); background: #fbfaf8; white-space: nowrap; font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tr.clic { cursor: pointer; transition: background .1s; }
tr.clic:hover td { background: #fcf8f4; }
tr.retirado td { color: var(--suave); }
td.vacio { text-align: center; color: var(--suave); padding: 40px; }
.id-contrato { font-family: var(--titulos); font-weight: 800; color: var(--navy); font-size: 1.02rem; }
.celda-sub { color: var(--suave); font-size: .82rem; margin-top: 2px; }

/* ---------- formularios ---------- */
label { display: block; font-size: .84rem; color: var(--suave); margin-bottom: 5px; font-weight: 500; }
.campo { margin-bottom: 14px; }
.campo.req label::after { content: " *"; color: var(--naranja); }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border: 1.5px solid var(--borde-fuerte); border-radius: 10px; background: #fff; color: var(--texto);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--naranja); box-shadow: 0 0 0 4px rgba(242, 106, 46, .14); }
input:disabled, select:disabled { background: #f6f4f1; color: var(--suave); }
input[type=checkbox] { width: 18px; height: 18px; margin: 0 8px 0 0; accent-color: var(--naranja); flex: none; }
textarea { min-height: 76px; resize: vertical; }
.check { display: flex; align-items: center; color: var(--texto); font-size: .95rem; margin: 8px 0 14px; cursor: pointer; }
.filtros { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.filtros > * { width: auto; min-width: 150px; flex: 1 1 150px; max-width: 260px; }
.filtros .buscar { flex: 2 1 260px; max-width: 420px; position: relative; }
.filtros .buscar input { padding-left: 38px; }
.filtros .buscar svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--suave); }

button, .boton {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 11px; padding: 9px 16px; border: 1.5px solid var(--navy); background: var(--navy); color: #fff;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; transition: background .15s, transform .1s, box-shadow .15s;
}
button:hover, .boton:hover { background: var(--navy-2); }
button:active, .boton:active { transform: translateY(1px); }
button.naranja, .boton.naranja { background: linear-gradient(135deg, var(--naranja-2), var(--naranja)); border-color: transparent; box-shadow: 0 4px 14px rgba(242, 106, 46, .3); }
button.naranja:hover, .boton.naranja:hover { box-shadow: 0 6px 20px rgba(242, 106, 46, .45); background: linear-gradient(135deg, var(--naranja-2), #e65a1c); }
button.sec, .boton.sec { background: #fff; color: var(--navy); border-color: var(--borde-fuerte); }
button.sec:hover, .boton.sec:hover { background: #faf7f3; border-color: var(--navy); }
button.verde, .boton.verde { background: #25d366; border-color: #25d366; color: #fff; }
button.verde:hover, .boton.verde:hover { background: #1fb457; }
button.peligro { background: #fff; color: var(--rojo); border-color: #f1c9c9; }
button.peligro:hover { background: #fdf1f1; }
button.mini, .boton.mini { padding: 5px 10px; font-size: .82rem; border-radius: 9px; }
button.icono-solo { padding: 8px; }
button:disabled { opacity: .55; cursor: default; transform: none; }
.ancho { width: 100%; }

.tipos { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.tipos button { background: #fff; color: var(--navy); border-color: var(--borde-fuerte); border-radius: 999px; padding: 8px 16px; }
.tipos button:hover { border-color: var(--navy); background: #fff; }
.tipos button.sel { background: var(--navy); color: #fff; border-color: var(--navy); }
.tipos.grandes { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.tipos.grandes button { flex-direction: column; border-radius: 14px; padding: 14px 8px; gap: 6px; font-size: .9rem; }
.tipos.grandes button svg { width: 24px; height: 24px; color: var(--naranja); }
.tipos.grandes button.sel { background: var(--naranja-claro); color: var(--navy); border-color: var(--naranja); box-shadow: 0 0 0 1px var(--naranja); }
@media (max-width: 640px) { .tipos.grandes { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* ---------- etiquetas ---------- */
.estado {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap;
  background: color-mix(in srgb, var(--c) 13%, white); color: color-mix(in srgb, var(--c) 82%, black);
}
.estado::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.estado.grande { font-size: .92rem; padding: 7px 14px 7px 12px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 7px; font-size: .76rem; font-weight: 500; background: #f0ede8; color: var(--navy); white-space: nowrap; }
.chip.naranja { background: var(--naranja-claro); color: #b2481a; }
.chip.verde { background: #e7f6ec; color: var(--verde); }
.chip.azul { background: #e9efff; color: #2b4bb0; }
.chips-estado { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chips-estado a { text-decoration: none; display: inline-flex; gap: 7px; align-items: center; padding: 7px 13px; border-radius: 999px; background: #fff; border: 1px solid var(--borde); color: var(--texto); font-size: .85rem; transition: border-color .15s; }
.chips-estado a:hover { border-color: var(--borde-fuerte); }
.chips-estado a.sel { border-color: var(--navy); background: var(--navy); color: #fff; }
.chips-estado .punto { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.aviso { background: var(--naranja-claro); border: 1px solid #fbd6bf; padding: 12px 14px; border-radius: 12px; font-size: .9rem; margin-bottom: 14px; display: flex; gap: 10px; align-items: flex-start; }
.aviso.info { background: #eef3ff; border-color: #d6e0fb; }
.aviso.ok { background: #e9f7ee; border-color: #c4e8d0; }
.aviso svg { flex: none; margin-top: 1px; }

/* ---------- comentarios ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; max-height: 520px; overflow-y: auto; padding: 4px 2px; margin-bottom: 14px; }
.msg { background: #f4f1ec; border-radius: 14px 14px 14px 4px; padding: 9px 13px; max-width: 88%; }
.msg.mio { background: var(--navy); color: #fff; align-self: flex-end; border-radius: 14px 14px 4px 14px; }
.msg.mio .quien { color: #c9d2e8; }
.msg.admin:not(.mio) { background: var(--naranja-claro); }
.msg .quien { font-size: .76rem; color: var(--suave); margin-bottom: 2px; }
.msg .txt { white-space: pre-wrap; word-break: break-word; }
.msg.sistema { background: none; border: 0; align-self: center; font-size: .78rem; color: var(--suave); text-align: center; max-width: 100%; padding: 2px 10px; }
.msg.sistema::before { content: "• "; color: var(--naranja); }

.lineas-precios { font-size: .82rem; color: var(--suave); margin-top: 4px; line-height: 1.5; }
.extra-fila { display: grid; grid-template-columns: minmax(0, 1fr) 190px 90px auto; gap: 10px; align-items: end; margin-bottom: 10px; padding: 12px; background: #fbfaf8; border-radius: 12px; border: 1px solid var(--borde); }
.extra-fila .campo { margin: 0; }
@media (max-width: 700px) { .extra-fila { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.kv-fila { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 6px; }
.estimacion { font-family: var(--titulos); font-size: 2rem; font-weight: 800; color: var(--verde); line-height: 1.1; }
.resumen-tabla td { padding: 7px 0; border-color: var(--borde); font-size: .9rem; }
.paso { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--navy); color: #fff; font-size: .85rem; font-weight: 800; flex: none; }

/* ---------- formulario del cliente (tarjeta en el contrato) ---------- */
.canales { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.canales button { flex-direction: column; padding: 12px 6px; font-size: .85rem; gap: 6px; }
.canales button svg { width: 22px; height: 22px; }
.linea-tiempo { list-style: none; margin: 12px 0 0; padding: 0; font-size: .86rem; }
.linea-tiempo li { display: flex; gap: 10px; padding: 5px 0; color: var(--suave); }
.linea-tiempo li.hecho { color: var(--texto); }
.linea-tiempo li::before { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--borde-fuerte); margin-top: 4px; flex: none; }
.linea-tiempo li.hecho::before { background: var(--verde); border-color: var(--verde); }
.copiar { display: flex; gap: 8px; }
.copiar input { font-size: .82rem; }

/* ---------- PDFs de tarifas ---------- */
.pdf-fila { display: flex; gap: 14px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--borde); flex-wrap: wrap; }
.pdf-fila:last-child { border-bottom: 0; }
.pdf-fila .icono-pdf { width: 42px; height: 42px; border-radius: 11px; background: #fdecec; color: var(--rojo); display: grid; place-items: center; flex: none; }
.pdf-fila .info { flex: 1; min-width: 200px; }
.zona-subida { border: 2px dashed var(--borde-fuerte); border-radius: 14px; padding: 24px; text-align: center; background: #fcfbf9; transition: border-color .15s, background .15s; }
.zona-subida.encima { border-color: var(--naranja); background: var(--naranja-claro); }
.cambio { border: 1px solid var(--borde); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; display: flex; gap: 12px; align-items: flex-start; }
.cambio .antes { text-decoration: line-through; color: var(--suave); }
.cambio .despues { color: var(--verde); font-weight: 600; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; background: #fff; }
.login .lado { background: var(--navy); color: #fff; position: relative; overflow: hidden; padding: 48px; display: flex; flex-direction: column; justify-content: flex-end; }
.login .lado::before { content: ""; position: absolute; width: 560px; height: 560px; border-radius: 50%; right: -200px; top: -200px; background: linear-gradient(135deg, var(--naranja-2), var(--naranja)); }
.login .lado::after { content: ""; position: absolute; width: 420px; height: 420px; border-radius: 50%; right: -130px; top: -130px; border: 1.5px solid rgba(255, 255, 255, .35); }
.login .lado > * { position: relative; z-index: 1; }
.login .lado .marca { position: absolute; top: 44px; left: 48px; margin: 0; }
.login .lado h2 { color: #fff; font-size: 2.6rem; line-height: 1.1; margin: 0 0 12px; display: block; }
.login .lado p { color: #c9d2e8; font-size: 1.05rem; max-width: 420px; margin: 0; }
.login form { align-self: center; justify-self: center; width: 100%; max-width: 380px; padding: 24px; }
.login form h1 { margin-bottom: 4px; }
.login form .sub { margin-bottom: 26px; }
.login .pie-login { margin: 18px 0 0; text-align: center; font-size: .92rem; }
.login .pie-login a { color: var(--naranja); font-weight: 600; text-decoration: none; }
.login .pie-login a:hover { text-decoration: underline; }
@media (max-width: 800px) {
  .login { grid-template-columns: minmax(0, 1fr); }
  .login .lado { min-height: 230px; padding: 28px; }
  .login .lado .marca { top: 26px; left: 28px; }
  .login .lado h2 { font-size: 1.7rem; }
  .login .lado::before { width: 300px; height: 300px; right: -110px; top: -110px; }
  .login .lado::after { display: none; }
}

/* ---------- avisos y modal ---------- */
#avisos { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: calc(100% - 36px); }
.toast { background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: var(--sombra-alta); max-width: 420px; animation: entra .2s ease-out; }
.toast.error { background: var(--rojo); }
@keyframes entra { from { transform: translateY(8px); opacity: 0; } }
.modal-fondo { position: fixed; inset: 0; background: rgba(21, 35, 63, .5); backdrop-filter: blur(3px); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 18px; padding: 24px; width: 100%; max-width: 660px; max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: var(--sombra-alta); }
.modal .pie-modal { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.cargando { color: var(--suave); padding: 30px 0; }

/* ---------- reparto de comisiones y albaranes ---------- */
tr.reparto td { border-top: 0; padding-top: 2px; padding-bottom: 2px; font-size: .9rem; color: var(--suave); }
.albaranes { display: flex; flex-wrap: wrap; gap: 6px; }
a.boton { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; border-radius: 10px; padding: 6px 10px; font-weight: 600; font-size: .85rem; border: 1px solid var(--borde, #e3e6ee); color: var(--navy); background: #fff; white-space: nowrap; }
a.boton.naranja { background: var(--naranja); border-color: var(--naranja); color: #fff; }
a.boton svg { width: 15px; height: 15px; }
.rejilla.r4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 640px) { .rejilla.r4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.lista-companias { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 12px; margin-top: 4px; }
@media (max-width: 640px) { .lista-companias { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
