/* ============================================================
   v212.css — ValdiviaLux v2.12
   Se carga AL FINAL (después de v211.css).

   1. Contraste con cualquier tema de color
   2. Visor de documentos (previsualizar / guardar PDF / imprimir)
   3. Cuadro «Documento» del presupuesto
   4. Ajustes responsivos encontrados en la revisión
   ============================================================ */

/* ── 1. Contraste ───────────────────────────────────────────────
   --on-accent: color del texto que va SOBRE el color de acento. Lo
   calcula applyTheme() (blanco u oscuro según el acento elegido), así
   un acento claro como el del tema Grafito no deja texto blanco
   ilegible. Aquí va el valor de respaldo.                          */
:root { --on-accent: #fff; }

/* Menú lateral: los rótulos tenues no se leían sobre fondos de tono
   medio (Azul, Verde, Clásico). */
.sidebar-brand-sub,
.sidebar-section-label { color: rgba(255,255,255,.66); }
.sidebar-footer { color: rgba(255,255,255,.62); }
.nav-item { color: rgba(255,255,255,.86); }
.nav-num { color: rgba(255,255,255,.85); }
.sidebar-logo-icon, .user-avatar { color: var(--on-accent); }

/* Textos secundarios: usan --text-muted (que applyTheme garantiza legible) */
#topbar-sep { color: var(--text-muted); opacity: .7; }
#topbar-time, .field-hint, .cm-arrow, .cm-foot { color: var(--text-muted); }
.cm-arrow { opacity: 1; }

/* Fila elegida de la grilla: todo su contenido toma el color sobre-acento */
.cq-grid tr.cq-row.sel td,
.cq-grid tr.cq-row.sel td * { color: var(--on-accent); }
.cq-grid tr.cq-row.sel .btn { background: transparent !important; }
table.rt tr.cq-row.sel td { color: var(--on-accent); }

/* Botones «secundario» y campos sobre temas oscuros */
.btn:focus-visible, .docv-btn:focus-visible, .doc-kind:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.input, select.input, textarea.input { color: var(--text); background-color: var(--surface); }
.input::placeholder { color: var(--text-muted); opacity: .8; }
select.input option { color: var(--text); background: var(--surface); }

/* ── 2. Visor de documentos ─────────────────────────────────── */
.docv-overlay {
  position: fixed; inset: 0; z-index: 1500;
  display: flex; flex-direction: column;
  background: #3b4250;
  height: 100vh; height: 100dvh;
}
.docv-bar {
  display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap;
  padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  background: #1f2430; color: #fff;
  box-shadow: 0 1px 0 rgba(255,255,255,.08);
  flex-shrink: 0;
}
.docv-title {
  flex: 1 1 160px; min-width: 0;
  font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.docv-zoom, .docv-actions { display: flex; align-items: center; gap: 6px; }
.docv-zoom-val { min-width: 44px; text-align: center; font: 600 12.5px var(--font-mono); color: #d5d9e2; }
.docv-btn {
  min-height: 38px; padding: 0 14px;
  border-radius: 8px; border: 1px solid rgba(255,255,255,.28);
  background: transparent; color: #fff;
  font: 600 13.5px var(--font-body); cursor: pointer;
  touch-action: manipulation; white-space: nowrap;
}
.docv-btn:hover { background: rgba(255,255,255,.1); }
.docv-btn:focus-visible { outline-color: #fff; }
.docv-ico { min-width: 38px; padding: 0; font-size: 18px; line-height: 1; }
.docv-primary { background: #fff; color: #111827; border-color: #fff; }
.docv-primary:hover { background: #e5e7eb; }
.docv-scroll {
  flex: 1 1 auto; min-height: 0; overflow: auto;
  padding: 16px 12px calc(24px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  outline: none;
}
.docv-paper {
  width: 794px; min-height: 1123px;        /* A4 */
  margin: 0 auto; padding: 53px;            /* 14 mm */
  background: #fff; color: #000;
  box-shadow: 0 4px 24px rgba(0,0,0,.45);
  box-sizing: border-box;
}
.docv-paper.landscape { width: 1123px; min-height: 794px; padding: 38px; }

.docv-close { order: 9; }
@media (max-width: 767px) {
  .docv-bar { gap: 6px 8px; }
  .docv-title { flex: 1 1 60%; font-size: 14px; }
  .docv-close { order: 0; }
  .docv-zoom { order: 1; }
  .docv-actions { order: 2; }
  .docv-zoom { flex: 0 0 auto; }
  .docv-actions { flex: 1 1 auto; justify-content: flex-end; }
  .docv-btn { min-height: 42px; padding: 0 12px; }
  .docv-ico { min-width: 42px; }
  .docv-scroll { padding: 10px 8px calc(20px + env(safe-area-inset-bottom)); }
}
@media (max-width: 420px) {
  .docv-zoom .docv-ghost { display: none; }        /* «Ajustar»: basta − y + */
  .docv-zoom-val { min-width: 38px; }
  .docv-actions { gap: 4px; }
  .docv-btn { padding: 0 9px; font-size: 13px; }
}

/* Al imprimir desde el visor sólo sale la hoja */
@media print {
  html:has(body.docv-printing), body.docv-printing {
    height: auto !important; overflow: visible !important; background: #fff !important;
  }
  body.docv-printing > *:not(.docv-overlay) { display: none !important; }
  body.docv-printing .docv-overlay {
    position: static !important; display: block !important;
    height: auto !important; background: #fff !important;
  }
  body.docv-printing .docv-bar { display: none !important; }
  body.docv-printing .docv-scroll { overflow: visible !important; padding: 0 !important; }
  body.docv-printing .docv-paper {
    zoom: 1 !important; width: auto !important; min-height: 0 !important;
    margin: 0 !important; padding: 0 !important; box-shadow: none !important;
  }
}

/* ── 3. Cuadro «Documento» ──────────────────────────────────── */
.doc-kinds { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.doc-kind {
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  padding: 12px; min-height: 64px;
  border: 1.5px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font-family: var(--font-body); cursor: pointer; touch-action: manipulation;
}
.doc-kind:hover { border-color: var(--border-dark); }
.doc-kind.active { border-color: var(--accent); background: var(--accent-lt); box-shadow: inset 0 0 0 1px var(--accent); }
.doc-kind-t { font-size: 14px; font-weight: 650; }
.doc-kind-h { font-size: 12px; color: var(--text-muted); line-height: 1.3; }
.doc-kind.active .doc-kind-h { color: var(--text); opacity: .8; }
.doc-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.doc-actions .btn { justify-content: center; min-height: 44px; width: 100%; }
.doc-warn {
  margin: 0 0 10px; padding: 8px 10px; border-radius: 8px; font-size: 13px;
  background: color-mix(in srgb, var(--warn) 14%, var(--surface)); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--warn) 45%, var(--surface));
}
@media (max-width: 560px) {
  .doc-kinds, .doc-actions { grid-template-columns: 1fr; }
  .doc-kind { min-height: 0; flex-direction: row; align-items: baseline; justify-content: space-between; gap: 10px; }
  .doc-kind-h { text-align: right; }
}

/* ── 4. Responsivo ──────────────────────────────────────────── */
/* Menú de informes de la cotización: filas cómodas para el dedo */
.cq-menu-item { min-height: 44px; touch-action: manipulation; }

/* Anchos intermedios (tablet horizontal, portátil con el menú abierto): la
   tabla todavía no pasa a tarjetas pero ya no cabe holgada. Se compacta y
   esconde las columnas secundarias en vez de obligar a desplazar de lado. */
@container (min-width: 601px) and (max-width: 900px) {
  table.rt th, table.rt td { padding: 8px 7px; font-size: 13px; }
  table.rt th.col-hide-mobile, table.rt td.col-hide-mobile { display: none; }
  table.rt td.rt-actions { width: auto; white-space: normal; }
  table.rt td.rt-actions > div { flex-wrap: wrap !important; }
  table.rt td.rt-actions .btn { padding: 6px 10px; font-size: 12.5px; }
  .cq-grid.rt th, .cq-grid.rt td { padding: 6px 5px; }
  .cq-grid.rt .cq-actions { white-space: normal; }
  .cq-grid.rt { min-width: 0; }
  .cq-grid.rt .cq-glosa { min-width: 110px; }
  /* Color, vidrio y % de la fila elegida ya se leen en la franja de estado */
  .cq-grid.rt th:nth-child(4), .cq-grid.rt td:nth-child(4),
  .cq-grid.rt th:nth-child(5), .cq-grid.rt td:nth-child(5),
  .cq-grid.rt th:nth-child(10), .cq-grid.rt td:nth-child(10) { display: none; }
}

/* El dibujo del elemento desaparecía cuando la tabla se apretaba */
.cq-grid .cq-dwg { min-width: 52px; }
.cq-grid .cq-dwg svg { min-width: 40px; }

/* Objetivos táctiles que quedaban chicos */
@media (max-width: 1024px) and (pointer: coarse), (max-width: 767px) {
  .fn-chip { min-height: 40px; padding-left: 14px; padding-right: 14px; }
  .cq-ask .btn { min-height: 40px; min-width: 56px; }
}

/* ── Editor de elemento: componentes con su nombre ──────────────
   Primera línea el nombre del perfil o accesorio; debajo código,
   medida y costo. */
.calc-mat { padding: 6px 6px 5px; border-bottom: 1px solid var(--border); }
.calc-mat:last-child { border-bottom: 0; }
.calc-mat-name { font-size: 12.5px; font-weight: 600; color: var(--text); line-height: 1.25; overflow-wrap: anywhere; }
.calc-mat-data {
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.3fr) auto;
  gap: 8px; align-items: baseline; margin-top: 2px;
  font-size: 11.5px; color: var(--text-muted);
}
.calc-mat-data .num { text-align: right; color: var(--text); white-space: nowrap; }
.calc-mat-code { white-space: nowrap; }
