:root {
  --fondo: #f6f4ef;
  --papel: #ffffff;
  --tinta: #1d232a;
  --suave: #55606b;
  --borde: #d6d1c7;
  --primario: #1f5f8b;
  --primario-osc: #174a6c;
  --acento: #e8933a;
  --bien: #1d7a3e;
  --mal: #b3261e;
  --radio: 12px;
}
* { box-sizing: border-box; }
html { font-size: 18px; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--fondo);
  color: var(--tinta);
  line-height: 1.45;
}
a { color: var(--primario); }
h1 { font-size: 1.7rem; margin: 0; }
h2 { font-size: 1.25rem; margin: 1.4rem 0 .6rem; }
.oculto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* Barra superior */
.barra {
  display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: space-between;
  padding: .6rem 1rem; background: var(--papel); border-bottom: 1px solid var(--borde);
  position: sticky; top: 0; z-index: 10;
}
.logo { display: flex; align-items: center; gap: .5rem; font-weight: 800; font-size: 1.3rem; text-decoration: none; color: var(--tinta); }
.barra-acciones { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

main { max-width: 1200px; margin: 0 auto; padding: 1rem; }

/* Botones y formularios */
.boton {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: .5rem 1.1rem; border: 2px solid var(--primario); border-radius: var(--radio);
  background: var(--primario); color: #fff; font: inherit; font-weight: 700; cursor: pointer;
}
.boton:hover { background: var(--primario-osc); border-color: var(--primario-osc); }
.boton.claro { background: var(--papel); color: var(--primario); }
.boton.claro:hover { background: #eaf2f8; }
.boton.grande { font-size: 1.15rem; padding: .7rem 1.6rem; background: var(--acento); border-color: var(--acento); color: #1d232a; }
.boton.peligro { background: var(--papel); color: var(--mal); border-color: var(--mal); }
.boton.peligro:hover { background: #fbe9e7; }
.acciones-proyecto { display: flex; flex-wrap: wrap; gap: .5rem; }
.boton:disabled { opacity: .45; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .boton:focus-visible {
  outline: 3px solid var(--acento); outline-offset: 2px;
}
input, select, textarea {
  font: inherit; color: inherit; width: 100%;
  min-height: 48px; padding: .5rem .7rem; border: 2px solid var(--borde); border-radius: 10px; background: #fff;
}
textarea { resize: vertical; }
label { display: block; font-weight: 600; }
label small, .nota { display: block; font-weight: 400; color: var(--suave); font-size: .9rem; }
.fila { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .8rem 1rem; margin-bottom: .8rem; }
.fila > button { align-self: end; }
.casilla { display: flex; align-items: center; gap: .6rem; font-weight: 600; margin: .5rem 0; cursor: pointer; }
.casilla input { width: 26px; min-height: 26px; height: 26px; }

/* Asistente */
#form-asistente { max-width: 760px; margin: 1rem auto; background: var(--papel); border: 1px solid var(--borde); border-radius: 16px; padding: 1.5rem; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-size: 1.6rem; font-weight: 800; margin-bottom: 1rem; }
fieldset > label { margin-bottom: .8rem; }
.pasos { margin: 0 0 .4rem; color: var(--suave); font-weight: 700; }
.nav-pasos { display: flex; gap: .8rem; justify-content: flex-end; margin-top: 1.2rem; flex-wrap: wrap; }
.etiqueta { font-weight: 700; margin: 1rem 0 .4rem; }
.opciones { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .7rem; }
.tarjeta {
  position: relative; display: flex; flex-direction: column; gap: .2rem;
  border: 2px solid var(--borde); border-radius: var(--radio); padding: .8rem; cursor: pointer; background: #fff;
}
.tarjeta input { position: absolute; opacity: 0; }
.tarjeta:has(input:checked) { border-color: var(--primario); background: #eaf2f8; box-shadow: 0 0 0 2px var(--primario) inset; }
.tarjeta:has(input:focus-visible) { outline: 3px solid var(--acento); }
.tarjeta span { font-weight: 400; }
.tarjeta small { color: var(--suave); font-weight: 400; }
.muestras { display: flex; gap: 4px; }
.muestras i { width: 28px; height: 28px; border-radius: 6px; border: 1px solid #0002; }

/* Proyecto */
.encabezado { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.resumen { margin: .3rem 0 0; color: var(--suave); }
.bien { color: var(--bien); font-weight: 700; }
.mal { color: var(--mal); font-weight: 700; }
.pestanas { display: flex; gap: .3rem; overflow-x: auto; border-bottom: 2px solid var(--borde); margin-bottom: 1rem; }
.pestanas button {
  flex: 0 0 auto; font: inherit; font-weight: 700; padding: .7rem 1rem; min-height: 48px;
  border: 0; border-bottom: 4px solid transparent; background: none; color: var(--suave); cursor: pointer;
}
.pestanas button[aria-selected="true"] { color: var(--primario); border-bottom-color: var(--primario); }
.panel { background: var(--papel); border: 1px solid var(--borde); border-radius: 16px; padding: 1rem; }
.herramientas { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: .8rem; }
.selector { display: inline-flex; border: 2px solid var(--primario); border-radius: var(--radio); overflow: hidden; }
.selector button { font: inherit; font-weight: 700; min-height: 44px; padding: .4rem .9rem; border: 0; background: #fff; color: var(--primario); cursor: pointer; }
.selector button[aria-pressed="true"] { background: var(--primario); color: #fff; }
.lienzo-plano { background: #fff; border: 1px solid var(--borde); border-radius: 10px; overflow: auto; }
.lienzo-plano svg { display: block; width: 100%; height: auto; max-height: 85vh; margin: 0 auto; }
.lienzo-plano svg [data-id]:not([data-id=""]) { cursor: pointer; }
.avisos { margin: .8rem 0 0; padding: 0; list-style: none; }
.avisos li { background: #fff6e5; border-left: 5px solid var(--acento); padding: .6rem .8rem; border-radius: 8px; margin-bottom: .5rem; }
.vista3d { width: 100%; height: 68vh; min-height: 360px; border-radius: 10px; overflow: hidden; background: #dfeaf3; touch-action: none; }
.vista3d canvas { display: block; }

/* Presupuesto */
.cifras { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .7rem; }
.cifras div { border: 1px solid var(--borde); border-radius: var(--radio); padding: .8rem; }
.cifras span { display: block; color: var(--suave); font-size: .9rem; }
.cifras b { font-size: 1.3rem; }
.cifras b + span { margin-top: .2rem; font-weight: 700; }
.cifras .bien b { color: var(--bien); }
.cifras .mal b { color: var(--mal); }
.aviso-caja { margin-top: 1rem; background: #fff6e5; border-left: 5px solid var(--acento); padding: .8rem 1rem; border-radius: 8px; }
.aviso-caja ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.tabla-envoltura { overflow-x: auto; }
.tabla { width: 100%; border-collapse: collapse; }
.tabla td, .tabla th { padding: .5rem .6rem; border-bottom: 1px solid var(--borde); text-align: left; vertical-align: middle; }
.tabla .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tabla .partida td { color: var(--suave); padding-left: 1.6rem; font-size: .93rem; }
.tabla .sub td { font-weight: 700; }
.tabla .total td { font-weight: 800; font-size: 1.15rem; border-top: 2px solid var(--tinta); }
#tabla-cuartos input, #tabla-cuartos select { min-width: 110px; }
#tabla-cuartos tr.sel { background: #fff1e0; }
.quitar { font: inherit; min-height: 44px; padding: .3rem .8rem; border: 2px solid var(--mal); color: var(--mal); background: #fff; border-radius: 10px; cursor: pointer; }
#nuevo-tipo { width: auto; }

/* Inicio con IA */
.inicio-caja { max-width: 760px; margin: 1rem auto; background: var(--papel); border: 1px solid var(--borde); border-radius: 16px; padding: 1.5rem; }
.chat-inicio { min-height: 220px; max-height: 55vh; margin-top: 1rem; }
.propuesta-lista { text-align: center; margin: .6rem 0 1rem; }
.enlace { font: inherit; background: none; border: 0; padding: 0; color: var(--primario); text-decoration: underline; cursor: pointer; min-height: 32px; }
.msg.pensando { color: var(--suave); font-style: italic; }
.chip.grande { font-size: 1rem; min-height: 46px; padding: .4rem 1rem; border-color: var(--primario); color: var(--primario); font-weight: 700; }

/* Fases */
.fase-tabla .num b { font-size: 1.05rem; }
.fase-tabla small { display: block; color: var(--suave); }
.etiqueta-fase { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .85rem; font-weight: 700; background: #e7f4ec; color: var(--bien); }
.etiqueta-fase.no { background: #fbe9e7; color: var(--mal); }

/* Chat */
.config-ia { border: 1px solid var(--borde); border-radius: var(--radio); padding: .6rem 1rem; margin-bottom: 1rem; background: #fafcfe; }
.estado-ia { margin: 0 0 .8rem; padding: .6rem .9rem; border-radius: 10px; background: #e7f4ec; color: var(--bien); font-weight: 700; }
.config-ia code { background: #eef1f4; padding: 0 .3rem; border-radius: 4px; }
.config-ia summary { font-weight: 700; cursor: pointer; min-height: 32px; }
.chat { max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; margin-bottom: .8rem; }
.msg { margin: 0; padding: .6rem .9rem; border-radius: 14px; max-width: 85%; white-space: pre-wrap; }
.msg.yo { align-self: flex-end; background: var(--primario); color: #fff; }
.msg.ia { align-self: flex-start; background: #eef1f4; }
.sugerencias { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .6rem; }
.chip { font: inherit; font-size: .9rem; min-height: 40px; padding: .3rem .8rem; border: 1px solid var(--borde); border-radius: 999px; background: #fff; cursor: pointer; }
.form-chat { display: flex; gap: .6rem; align-items: stretch; }
.form-chat textarea { flex: 1; }

.pie { max-width: 1200px; margin: 1rem auto 2rem; padding: 0 1rem; color: var(--suave); font-size: .9rem; }
.solo-impresion { display: none; }

@media (max-width: 600px) {
  html { font-size: 17px; }
  main { padding: .6rem; }
  .barra .boton { min-height: 44px; padding: .4rem .7rem; font-size: .9rem; }
  .form-chat { flex-direction: column; }
}

@media print {
  .barra, main, .pie { display: none !important; }
  .solo-impresion { display: block; }
  .hoja-plano { page-break-after: always; }
  .hoja-plano svg { width: 100%; max-height: 24cm; }
  body { background: #fff; }
  .aviso-caja { display: none; }
}
