/* RVT Viewer — sistema de diseno editorial monocromatico
   Regla: este es el UNICO archivo de estilos del proyecto.
   Ningun HTML puede definir estilos inline ni abrir otro CSS. */

:root {
  --bg: #ffffff;
  --bg-alt: #f8f8f6;
  --bg-canvas: #e8e8e6;
  --ink: #111111;
  --ink-mid: #555555;
  --ink-soft: #8a8a85;
  --rule: #dcdcd9;
  --rule-strong: #111111;
  --canvas-h: 44px;
  --panel-l: 252px;
  --panel-r: 300px;
  --font: "Barlow", "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", "Consolas", monospace;
}

* { box-sizing: border-box; border-radius: 0; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-mid); }
p  { margin: 0 0 8px; }
a  { color: var(--ink); text-decoration: underline; text-underline-offset: 2px; }

/* ---------- Estructura ---------- */

.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  height: var(--canvas-h); flex: 0 0 var(--canvas-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 14px; border-bottom: 1px solid var(--rule-strong);
  background: var(--bg);
}
.topbar .brand { font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; font-size: 13px; }
.topbar .spacer { flex: 1; }

.body { flex: 1; display: flex; min-height: 0; }

.panel-left {
  width: var(--panel-l); flex: 0 0 var(--panel-l);
  border-right: 1px solid var(--rule); overflow-y: auto; background: var(--bg);
}
.panel-right {
  width: var(--panel-r); flex: 0 0 var(--panel-r);
  border-left: 1px solid var(--rule); overflow-y: auto; background: var(--bg);
}
.panel-center { flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column; }

/* Las pestañas pueden envolver: con 4 pestañas el texto se cortaba. */
.tabs { display: flex; flex-wrap: wrap; border-bottom: 1px solid var(--rule); }
.tab {
  flex: 1; padding: 9px 8px; text-align: center; cursor: pointer;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-mid); background: var(--bg); border: 0; border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--rule-strong); }

.tab-panel { display: none; padding: 12px; }
.tab-panel.active { display: block; }

/* ---------- Toolbar ---------- */

.toolbar {
  height: var(--canvas-h); flex: 0 0 var(--canvas-h);
  display: flex; align-items: center; gap: 1px; padding: 0 8px;
  background: var(--bg); border-top: 1px solid var(--rule-strong);
}
.tool {
  height: 28px; padding: 0 11px; border: 1px solid transparent; background: transparent;
  color: var(--ink-mid); font-family: var(--font); font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.07em; cursor: pointer;
}
.tool:hover { color: var(--ink); border-color: var(--rule); }
.tool.active { color: var(--ink); border-color: var(--rule-strong); background: var(--bg-alt); }
.tool[disabled] { color: var(--ink-soft); cursor: default; }
.tool-sep { width: 1px; height: 18px; background: var(--rule); margin: 0 6px; }

/* ---------- Controles ---------- */

.btn {
  height: 30px; padding: 0 12px; border: 1px solid var(--rule-strong); background: var(--bg);
  color: var(--ink); font-family: var(--font); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em; cursor: pointer;
}
.btn:hover { background: var(--bg-alt); }
.btn-primary { background: var(--ink); color: var(--bg); }
.btn.active { background: var(--ink); color: var(--bg); }
.btn-primary:hover { background: #000; }
.btn-sm { height: 24px; padding: 0 8px; font-size: 10px; }

input[type="text"], input[type="search"], select, textarea {
  width: 100%; height: 30px; padding: 0 8px;
  border: 1px solid var(--rule); background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 13px;
}
input:focus, select:focus, textarea:focus { outline: 1px solid var(--ink); outline-offset: -1px; }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-mid); margin-bottom: 4px; }
/* Campo de formulario compartido por todos los paneles (medir, anotar, cortar). */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field > span { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-mid); }
input[type="range"] { width: 100%; }
.tool-row { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }

/* ---------- Tablas ---------- */

.table-container { border: 1px solid var(--rule); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th {
  text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--rule-strong);
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-mid);
}
td { padding: 6px 9px; border-bottom: 1px solid var(--rule); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--bg-alt); }
td.num, th.num { text-align: right; font-family: var(--mono); font-size: 11.5px; }

/* ---------- Tarjetas y stats ---------- */

.card { border: 1px solid var(--rule); padding: 12px; margin-bottom: 10px; background: var(--bg); }
.card > h3 { margin-bottom: 8px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); }
.stat-card { background: var(--bg); padding: 10px; }
.stat-val { font-family: var(--mono); font-size: 20px; font-weight: 500; }
.stat-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-mid); }

/* ---------- Badges ---------- */

.badge { display: inline-block; padding: 1px 6px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; border: 1px solid var(--rule-strong); }
.badge-ok { color: var(--ink); background: var(--bg-alt); }
.badge-warn { color: var(--ink); background: #e9e9e4; }
.badge-err { color: var(--bg); background: var(--ink); }

/* ---------- Arbol ---------- */

.tree { font-size: 12.5px; }
.tree ul { list-style: none; margin: 0; padding-left: 13px; border-left: 1px solid var(--rule); }
.tree > ul { padding-left: 0; border-left: 0; }
.tree li { margin: 0; }
.tree .node { padding: 3px 5px; cursor: pointer; display: flex; gap: 6px; align-items: baseline; }
.tree .node:hover { background: var(--bg-alt); }
.tree .node.selected { background: var(--ink); color: var(--bg); }
.tree .node .count { font-family: var(--mono); font-size: 10.5px; color: var(--ink-soft); margin-left: auto; }
.tree .node.selected .count { color: var(--bg-alt); }

/* ---------- Canvas 3D ---------- */

.viewport { flex: 1; position: relative; background: var(--bg-canvas); overflow: hidden; }

/* Vista 2D: el PDF del plano, encima del viewport 3D */
.sheet-view {
  position: absolute; inset: 0; z-index: 5;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.sheet-view.hidden { display: none; }
.sheet-view-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-bottom: 1px solid var(--rule);
  font-size: 12.5px;
}
.sheet-view-bar .spacer { flex: 1; }
.sheet-view iframe { flex: 1; width: 100%; border: 0; background: #fff; }

/* ---------- Visor 2D de planos (Etapa 5A) ---------- */

/* La lamina se dibuja como lienzo vectorial dentro de la pagina. */
.sheet-page {
  position: absolute; left: 0; top: 0;
  transform-origin: 0 0;
  background: #ffffff;
  outline: 1px solid var(--rule);
}
.sheet-canvas { display: block; background: #ffffff; }
.sheet-overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.sheet-lines { position: absolute; inset: 0; width: 100%; height: 100%; }
.sheet-pin {
  position: absolute; width: 9px; height: 9px; margin: -5px 0 0 -5px;
  background: var(--ink); border: 1px solid #ffffff;
  pointer-events: auto; cursor: pointer;
}
.sheet-pin.selected { background: #ff9f1c; }
.sheet-pin-label {
  position: absolute; transform: translate(11px, -140%);
  max-width: 180px; padding: 2px 6px;
  background: var(--ink); color: var(--bg); font-size: 11px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Miniaturas de planos (Etapa 5, tarea 4). La lamina es vectorial: la
   miniatura se dibuja en el cliente. Escala de grises, sin sombras ni
   bordes redondeados; hasta que llega solo se ve el recuadro. */
.sheet-thumb {
  width: 44px; height: 32px; flex: 0 0 auto;
  object-fit: contain;
  background: var(--bg-canvas);
  border: 1px solid var(--rule);
  filter: grayscale(1);
  opacity: 0;
  transition: opacity .12s linear;
}
.sheet-thumb.listo { opacity: 1; }
.sheet-thumb.fallo { opacity: .22; }
.tree .node.node-thumb { align-items: center; }

/* Control del corte */
#tabSection .row { flex-wrap: wrap; }
.viewport > canvas {
  position: absolute; inset: 0; display: block;
  width: 100%; height: 100%; touch-action: none;
}
.viewport-overlay {
  position: absolute; left: 10px; top: 10px; padding: 6px 9px; z-index: 2;
  background: rgba(255,255,255,0.92); border: 1px solid var(--rule-strong);
  font-family: var(--mono); font-size: 11px; color: var(--ink);
  pointer-events: none;
}
.viewport-overlay.hidden { display: none; }
.viewport-hud {
  position: absolute; left: 10px; bottom: 10px; z-index: 2;
  padding: 4px 7px; border: 1px solid var(--rule);
  background: rgba(255,255,255,0.85); color: var(--ink-mid); font-size: 10.5px;
  pointer-events: none;
}
.viewport-hud:empty { display: none; }
.viewport-hint {
  position: absolute; right: 10px; bottom: 10px; z-index: 2;
  font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-mid);
  pointer-events: none;
}

/* ---------- ViewCube ---------- */

.viewcube { position: absolute; right: 10px; top: 10px; width: 92px; height: 92px; }

/* ---------- Herramientas de la Etapa 4 ---------- */

/* Capas de etiquetas sobre el canvas: no interceptan el raton. */
.measure-layer, .markup-layer {
  position: absolute; inset: 0; z-index: 3;
  pointer-events: none; overflow: hidden;
}
.measure-label {
  position: absolute; transform: translate(-50%, -50%);
  padding: 1px 5px; white-space: nowrap;
  background: rgba(255,255,255,0.94); border: 1px solid var(--rule-strong);
  font-family: var(--mono); font-size: 11px; color: var(--ink);
}
.markup-label {
  position: absolute; transform: translate(-50%, -140%);
  max-width: 190px; padding: 2px 6px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
  background: var(--ink); color: var(--bg); font-size: 11px;
}
.measure-item, .markup-item, .view-item {
  display: flex; gap: 6px; align-items: baseline;
  padding: 3px 5px; border-bottom: 1px solid var(--rule); font-size: 12.5px;
}
.measure-item .count, .markup-item .count, .view-item .count {
  font-family: var(--mono); font-size: 10.5px; color: var(--ink-soft); margin-left: auto;
}
.view-item { align-items: center; }
.view-item .count { margin-left: 0; }
.view-item .btn { margin-left: auto; }

/* ---------- Estados ---------- */

.empty { padding: 22px 12px; text-align: center; color: var(--ink-soft); font-size: 12.5px; }
.notice { padding: 8px 10px; border-left: 2px solid var(--ink); background: var(--bg-alt); font-size: 12.5px; margin-bottom: 10px; }
.mono { font-family: var(--mono); font-size: 11.5px; }
.muted { color: var(--ink-mid); }
.small { font-size: 11.5px; }
.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stack > * + * { margin-top: 8px; }

/* ---------- Scrollbars ---------- */

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: var(--bg-alt); }
::-webkit-scrollbar-thumb { background: var(--rule); border: 2px solid var(--bg-alt); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-soft); }

/* ---------- Utilidades de disposicion (sin estilos inline) ---------- */

.mb-10 { margin-bottom: 10px; }
.mt-6  { margin-top: 6px; }
.mb-14 { margin-bottom: 14px; }
.mt-8  { margin-top: 8px; }
.mt-18 { margin-top: 18px; }
.pane-padded { padding: 16px; overflow-y: auto; }
.center-pane { align-items: center; justify-content: center; text-align: center; }

/* Menu contextual del visor 3D (boton derecho). Editorial: filete de 1px,
   sin sombras, sin bordes redondeados, texto en caja alta. */
.viewer-menu {
  position: fixed;
  z-index: 40;
  min-width: 178px;
  background: var(--bg);
  border: 1px solid var(--rule-strong);
  border-radius: 0;
  padding: 2px 0;
}
.viewer-menu-item {
  display: block;
  width: 100%;
  padding: 6px 12px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  text-align: left;
  cursor: pointer;
}
.viewer-menu-item:hover { background: var(--bg-alt); }