/* PerfectHome Taller - interfaz tactil, letra grande, alto contraste para el taller */
:root {
  --oscuro: #1d2329;
  --oscuro2: #2b333b;
  --fondo: #eef0f2;
  --papel: #ffffff;
  --texto: #15191d;
  --suave: #5b6570;
  --borde: #cfd5db;
  --naranja: #ff6a00;
  --naranja-osc: #c44f00;
  --verde: #1f8a4c;
  --rojo: #c62828;
  --azul: #1565c0;
  --sombra: 0 6px 24px rgba(0, 0, 0, .18);
  --seg-arriba: env(safe-area-inset-top, 0px);
  --seg-abajo: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px; color: var(--texto); background: var(--fondo);
  -webkit-text-size-adjust: 100%; overflow: hidden; overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.oculta { display: none !important; }
.invisible { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.pantalla { position: absolute; top: 0; left: 0; right: 0; bottom: 0; }

/* ---------- botones ---------- */
.boton, .fila-botones button, .modal button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 1.5px solid var(--borde);
  background: var(--papel); font-weight: 600; text-decoration: none; color: var(--texto);
}
.primario, .boton.primario, .fila-botones button.primario, .modal button.primario {
  background: var(--naranja); border-color: var(--naranja); color: #fff;
}
button:active, .boton:active { transform: scale(.97); }
.boton.grande { flex-direction: column; min-height: 96px; font-size: 20px; padding: 16px 22px; flex: 1 1 240px; gap: 2px; }
.boton.grande small { font-weight: 400; font-size: 14px; opacity: .85; }
.boton .ico { font-size: 26px; line-height: 1; }
button.icono { width: 48px; height: 48px; border: 0; background: transparent; font-size: 30px; line-height: 1; border-radius: 10px; }

/* ---------- pantalla de proyectos ---------- */
#proyectos { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: calc(20px + var(--seg-arriba)) 20px calc(30px + var(--seg-abajo)); max-width: 860px; margin: 0 auto; }
.cabecera { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.cabecera .logo { width: auto; height: 104px; flex: none; }
.marca-agua { position: absolute; right: 14px; bottom: calc(12px + var(--seg-abajo)); width: 46px; height: auto; opacity: .85; pointer-events: none; z-index: 2; }
.cabecera h1 { margin: 0; font-size: 28px; }
.cabecera .sub { margin: 2px 0 0; color: var(--suave); }
.acciones { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 26px; }
h2 { font-size: 19px; margin: 8px 0 10px; color: var(--suave); text-transform: uppercase; letter-spacing: .04em; }
.lista-proyectos { list-style: none; margin: 0; padding: 0; }
.lista-proyectos li {
  display: flex; align-items: center; gap: 12px; background: var(--papel); border-radius: 14px;
  padding: 12px 12px 12px 16px; margin-bottom: 10px; border: 1px solid var(--borde);
}
.lista-proyectos .info { flex: 1; min-width: 0; }
.lista-proyectos .nombre { font-size: 19px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lista-proyectos .det { color: var(--suave); font-size: 14px; margin-top: 2px; }
.lista-proyectos button.borrar { border: 0; background: transparent; color: var(--rojo); font-size: 15px; min-height: 48px; padding: 0 10px; }
.vacio { color: var(--suave); background: var(--papel); border-radius: 14px; padding: 18px; border: 1px dashed var(--borde); line-height: 1.45; }
.ajustes { margin-top: 26px; }
.interruptor { display: flex; gap: 12px; align-items: flex-start; font-size: 16px; line-height: 1.35; }
.interruptor input { width: 26px; height: 26px; flex: none; margin: 0; accent-color: var(--naranja); }
.nota { color: var(--suave); font-size: 14px; line-height: 1.4; }

/* ---------- visor ---------- */
#visor { display: flex; flex-direction: column; background: var(--fondo); }
.barra {
  display: flex; align-items: center; gap: 8px; background: var(--oscuro); color: #fff;
  padding: calc(8px + var(--seg-arriba)) 10px 8px; flex: none; z-index: 5;
}
.barra .icono { color: #fff; }
.buscador { flex: 1; position: relative; }
#buscar {
  width: 100%; height: 50px; border-radius: 12px; border: 2px solid transparent; padding: 0 46px 0 16px;
  font-size: 19px; background: #fff; color: var(--texto); -webkit-appearance: none; appearance: none; -webkit-user-select: text; user-select: text;
}
#buscar:focus { outline: none; border-color: var(--naranja); }
#buscar::-webkit-search-cancel-button, #buscar::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.limpiar { position: absolute; right: 4px; top: 4px; width: 42px; height: 42px; border: 0; background: transparent; font-size: 28px; color: var(--suave); }
#unidad {
  height: 50px; border-radius: 12px; border: 0; padding: 0 10px; background: var(--oscuro2); color: #fff; font-weight: 700; font-size: 17px;
  -webkit-appearance: none; appearance: none; min-width: 64px; text-align: center;
}
.resultados {
  position: absolute; z-index: 20; left: 10px; right: 10px; top: calc(66px + var(--seg-arriba)); max-height: 60%;
  overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--papel); border-radius: 14px; box-shadow: var(--sombra);
}
.resultados .cab { padding: 10px 16px; font-size: 14px; color: var(--suave); border-bottom: 1px solid var(--borde); }
.resultados .fila { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid #eceff2; min-height: 60px; }
.resultados .fila:active { background: #fff3ea; }
.resultados .todas { color: var(--naranja-osc); font-weight: 700; }
.resultados .nada { padding: 16px; color: var(--suave); line-height: 1.4; }
.chip-cod {
  flex: none; min-width: 52px; text-align: center; font-weight: 800; padding: 6px 8px; border-radius: 8px;
  background: var(--oscuro); color: #fff; font-size: 15px;
}
.chip-cod.vacio-cod { background: #e3e7eb; color: var(--suave); font-weight: 600; }
.fila .txt { flex: 1; min-width: 0; }
.fila .t1 { font-weight: 700; font-size: 18px; }
.fila .t2 { color: var(--suave); font-size: 14px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cuerpo { flex: 1; position: relative; display: flex; min-height: 0; }
.herramientas {
  flex: none; width: 92px; background: var(--oscuro); display: flex; flex-direction: column; gap: 2px;
  padding: 6px 6px calc(6px + var(--seg-abajo)); overflow-y: auto; z-index: 4;
}
.herramientas button {
  border: 0; background: transparent; color: #d9dee3; font-size: 13px; font-weight: 600; padding: 8px 2px;
  border-radius: 12px; display: flex; flex-direction: column; align-items: center; gap: 3px; min-height: 66px;
}
.herramientas button .ico { font-size: 26px; line-height: 1; color: #fff; }
.herramientas button.activo { background: var(--naranja); color: #fff; }
.herramientas button:disabled { opacity: .35; }
.lienzo-caja { flex: 1; position: relative; overflow: hidden; touch-action: none; }
.lienzo { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.capa { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.vistas {
  position: absolute; z-index: 3; top: 10px; left: 50%; transform: translateX(-50%); display: flex;
  background: rgba(29, 35, 41, .9); border-radius: 14px; padding: 4px; gap: 2px; max-width: calc(100% - 20px); overflow-x: auto;
}
.vistas button { border: 0; background: transparent; color: #e3e7eb; padding: 10px 14px; border-radius: 10px; font-weight: 700; font-size: 15px; min-height: 44px; white-space: nowrap; }
.vistas button.activo { background: #fff; color: var(--texto); }
.control-despiece {
  position: absolute; z-index: 3; top: 70px; left: 50%; transform: translateX(-50%); background: rgba(255, 255, 255, .94);
  border-radius: 12px; padding: 6px 14px; display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; box-shadow: var(--sombra);
}
.control-despiece input { width: 180px; accent-color: var(--naranja); }
.titulo-proyecto { position: absolute; left: 12px; bottom: calc(8px + var(--seg-abajo)); font-size: 13px; color: var(--suave); pointer-events: none; z-index: 2; }

/* etiquetas SVG */
.capa text { font-family: -apple-system, "Segoe UI", Roboto, sans-serif; font-weight: 800; paint-order: stroke; }
.et-medida { font-size: 18px; fill: #0b3d91; stroke: #fff; stroke-width: 5px; }
.et-cota { font-size: 14px; fill: #6b2c00; stroke: #fff; stroke-width: 4px; }

.barra-medir {
  position: absolute; z-index: 6; left: 50%; bottom: calc(14px + var(--seg-abajo)); transform: translateX(-50%);
  width: min(560px, calc(100% - 20px)); width: calc(100% - 20px); max-width: 560px; background: var(--papel); border-radius: 16px; box-shadow: var(--sombra); padding: 12px 14px;
}
#medir-texto { font-weight: 700; font-size: 17px; color: var(--azul); }
.medir-resultado .grande { font-size: 32px; font-weight: 800; margin: 4px 0; }
.medir-resultado .comp { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 15px; }
.medir-resultado .x { color: #c62828; } .medir-resultado .y { color: #2e7d32; } .medir-resultado .z { color: #1565c0; }
.medir-resultado .nota { margin: 6px 0 0; }
.fila-botones { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.fila-botones button { flex: 1 1 auto; min-height: 46px; padding: 8px 12px; font-size: 15px; }

.cargando { position: absolute; inset: 0; top: 0; left: 0; right: 0; bottom: 0; background: rgba(238, 240, 242, .92); z-index: 9; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; font-weight: 700; color: var(--suave); }
.giro { width: 44px; height: 44px; border-radius: 50%; border: 5px solid #d6dbe0; border-top-color: var(--naranja); animation: giro 1s linear infinite; }
@keyframes giro { to { transform: rotate(360deg); } }

/* ---------- paneles (ficha de pieza / modulos) ---------- */
.panel {
  position: absolute; z-index: 7; right: 10px; top: 10px; bottom: calc(10px + var(--seg-abajo)); width: 350px; max-width: calc(100% - 112px);
  background: var(--papel); border-radius: 18px; box-shadow: var(--sombra); overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 16px 18px;
}
.panel-cab { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.panel h3 { margin: 6px 0 8px; font-size: 20px; }
.ficha-tipo { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--naranja-osc); }
.ficha-nombre { font-size: 25px; font-weight: 800; line-height: 1.15; margin: 4px 0 2px; word-break: break-word; }
.ficha-nombre.sin { color: var(--rojo); font-size: 20px; }
.ficha-cod { display: inline-block; margin: 6px 0; font-size: 20px; font-weight: 800; background: var(--oscuro); color: #fff; padding: 4px 12px; border-radius: 10px; }
.fuente { font-size: 13px; color: var(--suave); }
.ruta { font-size: 14px; color: var(--suave); margin: 4px 0 10px; }
.medidas { display: flex; gap: 6px; margin: 10px 0 4px; }
.medidas div { flex: 1; background: #f4f6f8; border-radius: 12px; padding: 8px 6px; text-align: center; }
.medidas b { display: block; font-size: 23px; font-weight: 800; letter-spacing: -.01em; }
.medidas span { font-size: 12px; color: var(--suave); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.etiqueta-medida { display: inline-block; font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 6px; margin: 4px 0; }
.calc { background: #e3f0ff; color: #0b3d91; }
.indic { background: #fff0e0; color: #8a3a00; }
.seccion { margin-top: 14px; border-top: 1px solid #e6e9ec; padding-top: 10px; }
.seccion h4 { margin: 0 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--suave); }
.datos { width: 100%; border-collapse: collapse; font-size: 15px; }
.datos td { padding: 5px 0; vertical-align: top; }
.datos td:first-child { color: var(--suave); width: 38%; padding-right: 8px; }
.alerta { background: #fff4e5; border-left: 4px solid #f59e0b; padding: 8px 10px; border-radius: 6px; font-size: 14px; margin: 8px 0; line-height: 1.35; }
.alerta.roja { background: #fdecea; border-color: var(--rojo); }
.duplicados { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.duplicados button { min-height: 40px; border-radius: 10px; border: 1.5px solid var(--borde); background: #fff; padding: 4px 10px; font-size: 14px; }
.duplicados button.activo { border-color: var(--naranja); background: #fff3ea; font-weight: 700; }

.arbol { list-style: none; padding: 0; margin: 10px 0 0; }
.arbol li { display: flex; align-items: center; gap: 4px; min-height: 48px; border-bottom: 1px solid #eef0f2; }
.arbol .exp { width: 36px; height: 44px; border: 0; background: transparent; font-size: 16px; color: var(--suave); flex: none; }
.arbol .ojo { width: 46px; height: 44px; border: 0; background: transparent; font-size: 22px; flex: none; }
.arbol .ojo.apagado { opacity: .3; }
.arbol .nom { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; padding: 8px 4px; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arbol .nom.sel { color: var(--naranja-osc); font-weight: 800; }
.arbol .nom.modulo { font-weight: 700; }
.arbol .nom.sin { color: var(--rojo); font-style: italic; }
.arbol .cnt { color: var(--suave); font-size: 13px; padding-right: 6px; }
.arbol li.apagado .nom { opacity: .45; }

/* ---------- dialogos y avisos ---------- */
.modal { position: fixed; z-index: 50; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-caja { background: var(--papel); border-radius: 18px; max-width: 560px; width: 100%; max-height: 90%; overflow-y: auto; padding: 20px; box-shadow: var(--sombra); -webkit-user-select: text; user-select: text; }
.modal-caja h3 { margin: 0 0 10px; font-size: 22px; }
.modal-caja p, .modal-caja li { line-height: 1.45; }
.modal-caja ul { padding-left: 20px; }
.aviso { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); top: calc(76px + var(--seg-arriba)); background: var(--oscuro); color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: var(--sombra); max-width: 90%; text-align: center; font-weight: 600; }

/* ---------- iPhone / pantallas estrechas ---------- */
@media (max-width: 700px) {
  body { font-size: 16px; }
  .cabecera .logo { height: 84px; }
  .marca-agua { width: 38px; bottom: 8px; right: 10px; }
  .cuerpo { flex-direction: column-reverse; }
  .herramientas { width: auto; flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 4px 4px calc(4px + var(--seg-abajo)); }
  .herramientas button { flex: 1 0 64px; min-height: 58px; font-size: 11px; }
  .herramientas button .ico { font-size: 22px; }
  .panel { left: 8px; right: 8px; top: auto; width: auto; max-width: none; bottom: 8px; max-height: 58%; border-radius: 18px; }
  .vistas { top: 6px; }
  .vistas button { padding: 8px 10px; font-size: 14px; }
  .control-despiece { top: 62px; }
  .barra-medir { bottom: 8px; }
  .ficha-nombre { font-size: 22px; }
  .medidas b { font-size: 20px; }
  #buscar { font-size: 17px; height: 46px; }
  #unidad { height: 46px; }
}
