:root {
  --marino: #16263F;
  --marino-profundo: #0E1B2E;
  --beige: #F1E7D3;
  --arena: #E2D2B4;
  --terracota: #C9744E;
  --terracota-osc: #A9562F;
  --taupe: #967A5A;
  --taupe-texto: #6F5A40;
  --blanco: #FFFFFF;
  --papel: #FBF7EF;
  --linea: #DDD0B8;
  --sombra: 0 1px 2px rgba(22, 38, 63, .08);
  --radio: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Poppins', sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--marino);
  background: var(--beige);
}
#app { height: 100%; display: flex; flex-direction: column; }
h1, h2, h3, h4, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--terracota); outline-offset: 2px; }

/* logo */
.logo { width: 34px; height: 26px; display: block; flex: none; }
.logo path { fill: none; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.logo-chimenea { stroke: var(--terracota); }
.logo-tejado { stroke: var(--marino); }
.barra .logo-tejado { stroke: var(--beige); }

/* botones */
.btn {
  border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  font-weight: 500; white-space: nowrap; transition: background .15s;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primario { background: var(--terracota); color: var(--marino-profundo); font-weight: 600; }
.btn-primario:hover { background: #D5855F; }
.btn-fantasma { background: transparent; color: var(--beige); box-shadow: inset 0 0 0 1px rgba(241, 231, 211, .35); }
.btn-fantasma:hover { background: rgba(241, 231, 211, .12); }
.btn-suave { background: var(--arena); color: var(--marino); }
.btn-suave:hover { background: #D6C4A2; }
.btn-peligro { background: transparent; color: var(--terracota-osc); box-shadow: inset 0 0 0 1px var(--terracota); }
.btn-peligro:hover { background: rgba(201, 116, 78, .12); }
.btn-ancho { width: 100%; padding: 12px; }
.enlace {
  background: none; border: 0; padding: 0; cursor: pointer; font-weight: 500;
  color: var(--marino); text-decoration: underline; text-underline-offset: 3px; text-align: left;
}
.enlace-peligro { color: var(--terracota-osc); font-size: 12px; }

/* login */
.login { flex: 1; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--blanco); border-radius: 14px;
  padding: 32px 28px; box-shadow: 0 10px 40px rgba(22, 38, 63, .10);
  display: flex; flex-direction: column; gap: 14px;
}
.login-card .logo { width: 52px; height: 40px; align-self: center; }
.login-card h1 { font-size: 24px; font-weight: 700; text-align: center; line-height: 1.1; }
.login-sub { text-align: center; color: var(--taupe-texto); margin-top: -10px; margin-bottom: 6px; }
.login-ayuda { font-size: 13px; color: var(--taupe-texto); text-align: center; overflow-wrap: anywhere; }
.login-ayuda code { display: block; margin-top: 4px; font-size: 12.5px; color: var(--marino); user-select: all; }
.login-qr { width: 190px; height: 190px; align-self: center; background: var(--blanco); }
.login-volver { align-self: center; font-size: 13px; }
.login-error { color: var(--terracota-osc); font-size: 13px; min-height: 19px; }

/* barra superior */
.demo-aviso { background: var(--terracota); color: var(--marino-profundo); text-align: center; font-size: 12px; font-weight: 500; padding: 4px 16px; }
.barra {
  background: var(--marino); color: var(--beige);
  display: flex; align-items: center; gap: 16px; padding: 10px 20px; flex: none;
}
.marca { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.marca small { font-weight: 500; font-size: 11px; letter-spacing: .14em; color: var(--arena); margin-left: 2px; }
.buscador {
  flex: 1; max-width: 380px; min-width: 120px; margin-left: 12px; padding: 8px 12px; border-radius: 8px; border: 0;
  background: rgba(241, 231, 211, .12); color: var(--beige);
}
.buscador::placeholder { color: var(--arena); opacity: .8; }
.barra-acciones { display: flex; gap: 8px; margin-left: auto; }
.alerta { font-size: 12px; font-weight: 600; color: var(--marino-profundo); background: var(--terracota); border-radius: 6px; padding: 3px 9px; white-space: nowrap; }
.alerta:empty { display: none; }

/* tablero */
.contenido { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tablero {
  flex: 1; min-height: 0; display: flex; gap: 12px; padding: 16px 20px;
  overflow-x: auto; align-items: stretch;
}
.columna {
  flex: 1 0 224px; display: flex; flex-direction: column; min-height: 0;
  background: rgba(226, 210, 180, .5); border-radius: 12px; transition: box-shadow .12s;
}
.columna.sobre { box-shadow: inset 0 0 0 2px var(--terracota); }
.columna > header {
  display: flex; align-items: flex-start; gap: 8px; padding: 12px 12px 8px;
}
.columna h2 { font-size: 13px; font-weight: 600; line-height: 1.3; flex: 1; }
.col-num {
  flex: none; width: 4px; height: 16px; margin-top: 1px; border-radius: 2px;
  background: var(--terracota); font-size: 0;
}
.col-total { font-size: 12px; font-weight: 500; color: var(--taupe-texto); font-variant-numeric: tabular-nums; }
.columna-final { background: var(--marino); }
.columna-final h2, .columna-final .col-total { color: var(--beige); }
.columna-final .col-vacia { color: var(--arena); }
.col-lista { flex: 1; overflow-y: auto; padding: 0 8px 10px; display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
.col-vacia { font-size: 12px; color: var(--taupe-texto); padding: 6px 4px; }

.tarjeta {
  background: var(--blanco); border-radius: var(--radio); padding: 10px 12px; cursor: pointer;
  box-shadow: var(--sombra); flex: none; transition: box-shadow .12s, transform .12s;
}
.tarjeta:hover { box-shadow: 0 4px 12px rgba(22, 38, 63, .14); transform: translateY(-1px); }
.tarjeta.arrastrando { opacity: .45; }
.tarjeta h3 { font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.tarjeta h3 span { display: block; }
.t-ccaa { font-size: 12px; font-weight: 500; color: var(--terracota-osc); margin-top: 3px; }
.t-desc { font-size: 12px; color: var(--taupe-texto); margin-top: 3px; line-height: 1.4; }
.t-chip {
  display: inline-block; margin-top: 6px; font-size: 11px; font-weight: 500; color: var(--marino-profundo);
  background: rgba(201, 116, 78, .22); border-radius: 5px; padding: 1px 7px;
}

.t-ccaa b { font-weight: 600; color: var(--marino); }
.t-chip-listo { background: var(--terracota); font-weight: 600; }

/* descartadas */
.descartadas { padding: 20px; overflow-y: auto; }
.seccion {
  font-size: 15px; font-weight: 600; padding-left: 12px; position: relative; margin-bottom: 12px;
}
.seccion::before {
  content: ''; position: absolute; left: 0; top: 2px; bottom: 2px; width: 4px; border-radius: 2px; background: var(--terracota);
}
.seccion-cab { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.seccion-cab .seccion { margin-bottom: 0; }
.tabla-scroll { overflow-x: auto; background: var(--blanco); border-radius: var(--radio); box-shadow: var(--sombra); }
.tabla { width: 100%; border-collapse: collapse; font-size: 13px; }
.tabla th { text-align: left; font-weight: 500; font-size: 12px; color: var(--taupe-texto); padding: 9px 12px; border-bottom: 1px solid var(--linea); white-space: nowrap; }
.tabla td { padding: 9px 12px; border-bottom: 1px solid #EEE5D5; vertical-align: top; }
.tabla tr:last-child td { border-bottom: 0; }
.tabla .acciones { display: flex; gap: 6px; justify-content: flex-end; }
.vacio { color: var(--taupe-texto); padding: 16px 20px; font-size: 13px; }
section .vacio { padding: 4px 0; }

/* formularios */
.campo { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.campo > span { font-size: 12px; font-weight: 500; color: var(--taupe-texto); }
.campo input, .campo select, .campo textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--linea); background: var(--blanco); min-height: 38px;
}
.campo textarea { resize: vertical; }
.campo input:focus, .campo select:focus, .campo textarea:focus { outline: none; border-color: var(--marino); box-shadow: 0 0 0 1px var(--marino); }
.campo-ancho { grid-column: 1 / -1; }
.campo-nota:empty { display: none; }
.campo-nota, .contador { font-size: 11.5px; color: var(--taupe-texto); }
.nota-error, .excedido { color: var(--terracota-osc); font-weight: 500; }
.con-sufijo { position: relative; }
.con-sufijo input { padding-right: 52px; }
.con-sufijo em { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-style: normal; font-size: 12px; color: var(--taupe-texto); pointer-events: none; }
.rejilla { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.rejilla-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; align-self: end; min-height: 38px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--terracota); }

/* ficha */
dialog { border: 0; padding: 0; color: inherit; }
dialog::backdrop { background: rgba(14, 27, 46, .5); }
.ficha {
  position: fixed; inset: 0 0 0 auto; margin: 0; height: 100dvh; max-height: none;
  width: min(920px, 100vw); max-width: 100vw; background: var(--papel);
  box-shadow: -8px 0 30px rgba(14, 27, 46, .25);
}
.ficha[open] { display: flex; flex-direction: column; }
.ficha-cab { background: var(--marino); color: var(--beige); padding: 16px 24px 0; flex: none; }
.ficha-cab-sup { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.ficha-eyebrow { font-size: 12px; color: var(--arena); display: flex; gap: 14px; min-height: 18px; }
.guardado { font-weight: 500; }
.guardado-error { color: #F0A583; }
.ficha-cab h2 { font-size: 20px; font-weight: 700; line-height: 1.25; margin-top: 2px; }
.cerrar {
  background: none; border: 0; color: var(--beige); font-size: 26px; line-height: 1; cursor: pointer;
  width: 36px; height: 36px; border-radius: 8px; flex: none;
}
.cerrar:hover { background: rgba(241, 231, 211, .12); }
.pasos { list-style: none; margin: 12px 0 8px; padding: 0; display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.pasos button {
  width: 100%; height: 26px; border: 0; border-radius: 5px; cursor: pointer; font-size: 12px; font-weight: 600;
  background: rgba(241, 231, 211, .14); color: var(--arena);
}
.pasos button:hover { background: rgba(241, 231, 211, .28); }
.pasos button.hecho { background: var(--arena); color: var(--marino); }
.pasos button.actual { background: var(--terracota); color: var(--marino-profundo); }
.paso-texto { font-size: 13px; padding-bottom: 12px; color: var(--beige); }
.paso-texto strong { font-weight: 600; }
.pestanas { display: flex; gap: 2px; overflow-x: auto; margin: 0 -24px; padding: 0 24px; }
.pestanas button {
  flex: none; background: transparent; border: 0; color: var(--arena); cursor: pointer; font-weight: 500;
  padding: 7px 14px; border-radius: 8px 8px 0 0; display: flex; flex-direction: column; line-height: 1.25; text-align: left; justify-content: center;
}
.pestanas button small { font-size: 10.5px; font-weight: 400; opacity: .85; }
.pestanas button:hover { background: rgba(241, 231, 211, .12); }
.pestanas button.activa { background: var(--papel); color: var(--marino); }
.pestana-nueva { color: #F0A583 !important; }
.ficha-cuerpo { flex: 1; min-height: 0; overflow-y: auto; padding: 20px 24px; display: flex; flex-direction: column; gap: 24px; }
.comentarios { background: var(--blanco); border-radius: var(--radio); padding: 14px 16px; box-shadow: var(--sombra); flex: none; }
.comentario-nuevo { display: flex; gap: 8px; align-items: flex-end; }
.comentario-nuevo textarea {
  flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--linea); background: var(--blanco); resize: vertical;
}
.comentario-nuevo textarea:focus { outline: none; border-color: var(--marino); box-shadow: 0 0 0 1px var(--marino); }
.comentario-lista { list-style: none; margin: 12px 0 0; padding: 0 4px 0 0; max-height: 280px; overflow-y: auto; }
.comentario-lista li { padding: 9px 0; border-top: 1px solid #EEE5D5; }
.comentario-cab { display: flex; flex-wrap: wrap; gap: 2px 10px; align-items: baseline; font-size: 11.5px; color: var(--taupe-texto); }
.comentario-cab time { font-weight: 500; font-variant-numeric: tabular-nums; }
.comentario-cab .enlace { margin-left: auto; font-size: 11.5px; }
.comentario-lista p { margin-top: 3px; font-size: 13.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.titulares { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px; }
.titular { background: var(--blanco); border-radius: var(--radio); padding: 14px 16px; box-shadow: var(--sombra); }
.titular > header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.titular h4 { font-size: 13px; font-weight: 600; }
.ficha-pie { flex: none; padding: 10px 24px; display: flex; justify-content: flex-end; border-top: 1px solid var(--linea); }
.ficha-pie:empty { display: none; }

.expediente { background: var(--blanco); border-radius: var(--radio); padding: 14px 16px; box-shadow: var(--sombra); flex: none; }
.expediente .seccion-cab .enlace { font-size: 12.5px; }
.exp-paso { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid #EEE5D5; }
.exp-paso strong { display: block; font-weight: 600; font-size: 13.5px; }
.exp-paso.hecho strong::after { content: ' ✓'; color: var(--terracota-osc); }
.exp-paso span { font-size: 12.5px; color: var(--taupe-texto); }
.exp-acciones { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; flex: none; max-width: 60%; }
.exp-detalle { border-top: 1px solid #EEE5D5; padding-top: 8px; margin-top: 2px; }
.exp-detalle summary { cursor: pointer; font-weight: 500; font-size: 13px; }
.exp-detalle h4 { font-size: 12.5px; font-weight: 600; margin-top: 10px; }
.doc-lista, .envio-lista, .lista-faltan { list-style: none; margin: 4px 0 0; padding: 0; }
.doc-lista li { display: flex; gap: 10px; align-items: baseline; padding: 3px 0; font-size: 13px; }
.doc-tipo { flex: 1; min-width: 0; }
.doc-estado { font-size: 12px; color: var(--taupe-texto); white-space: nowrap; }
.doc-lista .enlace { font-size: 12px; white-space: nowrap; }
.doc-lista a.enlace { color: var(--marino); }
.doc-aprobado .doc-estado { color: var(--marino); font-weight: 500; }
.doc-no_aplica .doc-tipo { color: var(--taupe-texto); text-decoration: line-through; }
.envio-lista li { padding: 5px 0; font-size: 13px; }
.envio-lista span { display: block; font-size: 11.5px; color: var(--taupe-texto); }
.envio-cuerpo { white-space: pre-wrap; color: var(--marino) !important; }
.lista-faltan li { padding: 3px 0; font-size: 13px; }
.doc-titular { border: 1px solid var(--linea); border-radius: 8px; padding: 10px 12px; margin: 0 0 10px; }
.doc-titular legend { font-weight: 600; font-size: 13px; padding: 0 6px; }
.doc-casillas { display: grid; gap: 2px; margin: 8px 0; }
.doc-casillas .check { min-height: 28px; font-weight: 400; font-size: 13px; }

/* modales */
.modal {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; border-radius: 14px; background: var(--blanco); padding: 22px 24px;
  box-shadow: 0 20px 60px rgba(14, 27, 46, .35);
}
.modal h2 { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
.modal p { margin-bottom: 12px; color: var(--taupe-texto); }
.modal-pie { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.visor {
  width: min(900px, calc(100vw - 32px)); height: calc(100dvh - 32px); max-height: none; max-width: none;
  border-radius: 12px; background: var(--marino); overflow: hidden;
}
.visor[open] { display: flex; flex-direction: column; }
.visor header { display: flex; align-items: center; gap: 14px; padding: 6px 8px 6px 16px; color: var(--beige); flex: none; }
.visor header strong { flex: 1; min-width: 0; font-weight: 600; }
.visor .enlace { color: var(--beige); font-size: 13px; }
.visor iframe { flex: 1; min-height: 0; width: 100%; border: 0; background: var(--blanco); }

/* avisos */
.toast {
  position: fixed; inset: auto 20px 20px auto; margin: 0; border: 0; border-radius: 8px; padding: 10px 14px;
  background: var(--marino-profundo); color: var(--beige); font-size: 13px; max-width: min(380px, calc(100vw - 40px));
  box-shadow: 0 8px 24px rgba(14, 27, 46, .3);
}
.toast-error { background: var(--terracota); color: var(--marino-profundo); font-weight: 500; }

@media (max-width: 760px) {
  .barra { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .buscador { order: 3; flex-basis: 100%; max-width: none; margin-left: 0; }
  .tablero { padding: 12px 16px; scroll-snap-type: x proximity; }
  .columna { flex-basis: min(280px, 82vw); scroll-snap-align: center; }
  .ficha-cab { padding: 12px 16px 0; }
  .pestanas { margin: 0 -16px; padding: 0 16px; }
  .ficha-cuerpo { padding: 16px; }
  .ficha-pie { padding: 10px 16px; }
  .exp-paso { flex-direction: column; align-items: stretch; }
  .exp-acciones { max-width: none; justify-content: flex-start; }
  .rejilla-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .titulares { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 420px) {
  .rejilla, .rejilla-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
