:root {
  --accent: #b11116;
  --accent-d: #8a0d11;
  --accent-soft: #fdecec;
  --bg: #f7f7f8;
  --card: #ffffff;
  --line: #ececef;
  --txt: #18181b;
  --muted: #71717a;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --topbar-h: 52px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--txt); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* En táctil (iPad), los campos a 16px evitan el zoom automático de iOS al enfocar
   (que descoloca la escritura). */
@media (pointer: coarse) {
  input, textarea, select, [contenteditable] { font-size: 16px !important; }
}
.muted { color: var(--muted); }
.error { color: var(--accent); min-height: 1em; }
button { font: inherit; cursor: pointer; }

/* ---- Login ---- */
.login { display: flex; align-items: center; justify-content: center; height: 100%; padding: 20px; }
.login-card {
  background: var(--card); padding: 36px 32px; border-radius: 22px; width: 100%; max-width: 360px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px;
}
.brand { color: var(--accent); margin: 0 0 8px; font-size: 30px; font-weight: 700; letter-spacing: -.02em; }
.brand span { color: var(--txt); font-weight: 400; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input { padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); font-size: 16px; background: #fafafa; }
.login-card input:focus { outline: none; border-color: var(--accent); background: #fff; }
.login-card button { padding: 13px; border-radius: 12px; border: none; font-size: 16px; font-weight: 600; background: var(--accent); color: #fff; }

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 16px; background: var(--card);
  padding: 12px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand-sm { color: var(--accent); font-weight: 700; font-size: 18px; letter-spacing: -.02em; }
.brand-sm span { color: var(--txt); font-weight: 400; }
.topbar-tabs { flex: 1; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.topbar .tab { background: transparent; color: var(--muted); border: none; padding: 8px 14px; border-radius: 10px; font-weight: 600; cursor: pointer; }
.topbar .tab.active { background: var(--accent-soft); color: var(--accent); }
/* Menús desplegables (Ventas, Contactos, Referencias) */
.menu { position: relative; }
.menu .submenu { position: absolute; top: 100%; left: 0; margin-top: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 60; display: none; }
.menu.abierto .submenu { display: flex; flex-direction: row; gap: 4px; }
.menu .submenu button { background: transparent; border: none; padding: 9px 12px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--txt); cursor: pointer; white-space: nowrap; }
.menu .submenu button:hover { background: var(--accent-soft); color: var(--accent); }
.menu .submenu button.activo { background: var(--accent-soft); color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.usuario { font-size: 13px; color: var(--muted); }
.version { font-size: 11px; color: #a1a1aa; border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; }
.link { background: none; border: none; color: var(--accent); text-decoration: none; font-weight: 600; }

main { padding: 24px; max-width: 1180px; margin: 0 auto; }

/* ---- Botones ---- */
.prim { background: var(--accent); color: #fff; border: none; padding: 11px 18px; border-radius: 12px; font-weight: 600; }
.sec { background: var(--card); border: 1px solid var(--line); padding: 11px 16px; border-radius: 12px; font-weight: 500; }
.danger { background: #fff; color: var(--accent); border: 1px solid var(--accent); padding: 11px 16px; border-radius: 12px; font-weight: 600; }
.chip { background: var(--card); border: 1px solid var(--line); padding: 8px 14px; border-radius: 999px; font-size: 13px; color: var(--muted); }
.chip:hover { border-color: #d4d4d8; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.seg-tipo { display: inline-flex; gap: 6px; }

/* ---- Listado ---- */
.list-head { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.searchbar { flex: 1; display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 0 16px; box-shadow: var(--shadow); }
.searchbar .ic { color: var(--muted); }
.searchbar input { flex: 1; border: none; background: none; padding: 15px 0; font-size: 16px; outline: none; color: var(--txt); }
.list-tools { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.list-tools #selBusq { margin-left: auto; }
#contador { font-size: 13px; }

.filtros { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow); }
.filtros-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.filtros label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.filtros input, .filtros select { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; background: #fafafa; }
.filtros input:focus, .filtros select:focus { outline: none; border-color: var(--accent); background: #fff; }
.filtros-acc { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

select.chip, #selBusq { appearance: none; -webkit-appearance: none; }

/* ---- Listado en tabla (compacto, escala a miles) ---- */
.tabla-wrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; max-height: calc(100vh - 230px); }
.listado-tabla { width: 100%; border-collapse: collapse; font-size: 13px; }
.listado-tabla thead th { position: sticky; top: 0; background: #fafafa; text-align: left; padding: 8px 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1; }
.listado-tabla tbody td { padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.listado-tabla .nom { white-space: normal; }
.listado-tabla tbody tr { cursor: pointer; }
.listado-tabla tbody tr:hover { background: var(--accent-soft); }
.listado-tabla .nom { font-weight: 600; }
.listado-tabla .id { color: #a1a1aa; }
.listado-tabla .chk { width: 40px; text-align: center; }
.listado-tabla .chk input { width: 18px; height: 18px; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 999px; letter-spacing: .02em; }
.b-tienda { background: #e8f0fe; color: #1a56c4; }
.b-part { background: #eaf6e6; color: #2f7a1d; }
.b-pend { background: #fef3e2; color: #b45309; }
.b-rech { background: #fdecec; color: #b11116; }
.b-mod { background: #fff7ed; color: #b45309; }
.cat-edit { max-width: 160px; border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 3px 4px; font: inherit; color: inherit; cursor: pointer; -webkit-appearance: none; appearance: none; }
.cat-edit:hover { border-color: #e5e7eb; background: #fafafa; }
.cat-edit:focus { outline: none; border-color: var(--accent); background: #fff; }
/* Pestañas dentro de una ficha (Datos / Costes del albarán) */
.ficha-tabs .tabs-head { display: flex; gap: 6px; margin-bottom: 10px; }
.tab-sec { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 5px 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab-sec.activo { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.tab-panel.hidden { display: none; }
.coste-cab { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 12px; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.coste-cab .fr { display: flex; flex-direction: column; align-items: stretch; gap: 2px; margin: 0; }
.coste-cab .fr > label { flex: none; text-align: left; font-size: 11px; color: #71717a; font-weight: 600; }
.coste-cab .fr > input { flex: none; padding: 6px 8px; border: 1px solid #d4d4d8; border-radius: 7px; font-size: 13px; background: #fafafa; }
.coste-head { display: flex; align-items: center; margin-bottom: 8px; }
.coste-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.coste-row input { padding: 6px 8px; border: 1px solid #d4d4d8; border-radius: 7px; font-size: 13px; }
.coste-row input[data-c="concepto"], .coste-row input[data-t="concepto"] { flex: 1; min-width: 160px; }
.coste-row select[data-t], .coste-row select[data-c] { padding: 6px 8px; border: 1px solid #d4d4d8; border-radius: 7px; font-size: 13px; background: #fafafa; }
.coste-row select[data-t="concepto"], .coste-row select[data-c="concepto"] { flex: 2; min-width: 220px; }
.coste-row select[data-t="acabado"], .coste-row select[data-c="acabado"] { flex: 1; min-width: 150px; }
/* Desplegable propio de Concepto: botón compacto + panel ancho con texto extendido. */
.coste-row .cselect { flex: 2; min-width: 200px; display: flex; align-items: center; justify-content: space-between; gap: 6px; text-align: left; background: #fafafa; border: 1px solid #d4d4d8; border-radius: 7px; padding: 6px 8px; font-size: 13px; color: var(--txt); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: pointer; }
.coste-row .cselect .csel-car { color: var(--muted); flex: 0 0 auto; }
.csel-panel { position: fixed; z-index: 1000; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 18px 40px rgba(0,0,0,.22); max-height: 60vh; overflow: auto; padding: 4px; }
.csel-opt { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 8px 10px; font-size: 13px; border-radius: 6px; cursor: pointer; white-space: normal; }
.csel-opt:hover { background: var(--accent-soft); }
.csel-opt.sel { color: var(--accent); font-weight: 600; }
/* Histórico de costes del montador */
.mc-sec { margin-top: 12px; }
.mc-filtros { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 10px; }
.mc-filtros label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: #71717a; font-weight: 600; }
.mc-filtros select { padding: 6px 8px; border: 1px solid #d4d4d8; border-radius: 7px; font-size: 13px; background: #fafafa; }
.mc-resumen { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 10px; font-size: 13px; }
.mc-mes { margin-bottom: 12px; }
.mc-mes-cab { display: flex; justify-content: space-between; align-items: center; background: var(--accent-soft); color: var(--accent); padding: 6px 10px; border-radius: 8px; font-size: 13px; text-transform: capitalize; }
.mc-tabla { width: 100%; border-collapse: collapse; }
.mc-tabla td { padding: 7px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
.mc-fila { cursor: pointer; }
.mc-fila:hover td { background: var(--accent-soft); }
/* Filtros y totales del listado de albaranes */
.alb-filtros { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.alb-filtros label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: #71717a; font-weight: 600; }
.alb-filtros select { padding: 6px 8px; border: 1px solid #d4d4d8; border-radius: 7px; font-size: 13px; background: #fafafa; }
.listado-tabla th.num, .listado-tabla td.num { text-align: right; font-variant-numeric: tabular-nums; }
.alb-tot td { font-weight: 700; border-top: 2px solid var(--line); background: #fafafa; }
/* Facturas negativas (abonos) en rojo */
.fac-neg td { color: #b91c1c; }
.fac-neg .nom { color: #b91c1c; }
.tag-abono { font-size: 10px; font-weight: 700; background: #fee2e2; color: #b91c1c; border-radius: 6px; padding: 1px 5px; vertical-align: middle; }
.alb-filtros .chk-inline { flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--txt); font-weight: 500; }
/* Presupuestos / Albaranes dentro de la ficha de cliente */
.docs-cli th.num, .docs-cli td.num { text-align: right; font-variant-numeric: tabular-nums; }
.doc-fila { cursor: pointer; }
.doc-fila:hover td { background: var(--accent-soft); }
/* Celda Img (check de foto + botón para adjuntar/pegar) en albarán/proforma */
/* Selección de líneas vendidas (presupuesto → albarán) */
.sl-acc { margin-bottom: 8px; font-size: 12px; }
.sl-row { display: flex; align-items: center; gap: 10px; padding: 7px 6px; border-bottom: 1px solid var(--line); font-size: 13px; cursor: pointer; }
.sl-row .sl-d { flex: 1; }
.sl-row .sl-q { white-space: nowrap; }
.sl-cab { font-weight: 700; background: #faf7f0; padding: 6px 8px; margin: 8px 0 2px; border-radius: 6px; font-size: 12px; }
/* Líneas ya facturadas en el albarán */
/* Subtotal por cabecera en las líneas del presupuesto */
.lineas-tabla tr.lin-subtot td { background: #f8fafc; border-top: 1px solid #cbd5e1; border-bottom: 1px solid #cbd5e1; font-size: 12px; }
.lineas-tabla tr.lin-subtot .st-lbl { text-align: right; font-weight: 600; color: #475569; text-transform: uppercase; letter-spacing: .03em; }
.lineas-tabla tr.lin-subtot .st-val { text-align: right; font-weight: 700; white-space: nowrap; }
.lineas-tabla tr.lin-facturada td { opacity: .55; }
.lin-fact { color: #15803d; }
.img-cell { white-space: nowrap; text-align: center; }
.img-cell .foto-linea { background: transparent; border: 0; cursor: pointer; font-size: 15px; padding: 0 2px; line-height: 1; }
.mc-tabla td.num { text-align: right; font-variant-numeric: tabular-nums; }
.mc-ok { color: #15803d; font-weight: 600; }
.mc-pend { color: #b45309; font-weight: 600; }
.b-art { background: #ecebfd; color: #4f46e5; }
.b-mat { background: #fef3e2; color: #b45309; }

/* ---- Presupuesto: cliente, líneas y totales ---- */
.cli-res { border: 1px solid var(--line); border-radius: 8px; margin-top: 6px; max-height: 220px; overflow: auto; }
.cli-res:empty { display: none; }
.cli-item { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line); font-size: 14px; }
.cli-item:hover { background: var(--accent-soft); }
.cli-sel { font-size: 14px; }
.lineas-card { margin-top: 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.lineas-acc { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; position: sticky; top: var(--topbar-h); background: var(--card); z-index: 6; padding: 8px 0; }
.lineas-tabla thead th { position: sticky; top: 0; background: var(--card); z-index: 5; }
/* Cabecera plegable del presupuesto */
.cab-resumen { display: none; align-items: center; gap: 8px; cursor: pointer; padding: 10px 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 6px; font-size: 15px; }
.cab-chevron { color: var(--accent); font-weight: 700; }
.cab-colapsada .cab-resumen { display: flex; }
.cab-colapsada .presup-cab { display: none; }
/* Documentos del presupuesto */
.dropzone { border: 1.5px dashed var(--line); border-radius: 10px; padding: 14px; text-align: center; color: var(--muted); font-size: 13px; background: #fafafa; cursor: pointer; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.paste-box { display: inline-block; min-width: 70px; padding: 4px 10px; margin-left: 6px; border: 1px solid var(--accent); border-radius: 8px; background: #fff; color: var(--accent); font-size: 12px; cursor: text; vertical-align: middle; }
.paste-box img { max-height: 24px; vertical-align: middle; }
.docs-prev { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.doc-item { position: relative; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.doc-item img { width: 88px; height: 88px; object-fit: cover; display: block; cursor: pointer; }
#artFotos .doc-item img { width: 150px; height: 150px; object-fit: contain; background: #fafafa; }
.doc-item.doc-file { padding: 10px 28px 10px 10px; font-size: 13px; cursor: pointer; max-width: 220px; }
.doc-item.doc-file span { cursor: pointer; }
.doc-del { position: absolute; top: 2px; right: 2px; background: rgba(255,255,255,.9); border: 1px solid var(--line); border-radius: 50%; width: 22px; height: 22px; color: var(--accent); cursor: pointer; line-height: 1; }
.lineas-tabla { width: 100%; border-collapse: collapse; font-size: 13px; }
.lineas-tabla th { text-align: left; padding: 6px 8px; font-size: 11px; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap; }
.lineas-tabla td { padding: 4px 8px; border-bottom: 1px solid var(--line); }
.lineas-tabla input { padding: 5px 7px; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; background: #fafafa; }
.lineas-tabla input[type=checkbox] { width: 16px; height: 16px; }
.lineas-tabla .drag { cursor: grab; color: #a1a1aa; user-select: none; }
.lineas-tabla tr.arrastrando { opacity: .4; }
.lineas-tabla tr.lin-cab { background: #faf7f0; }
.lineas-tabla .imp { font-weight: 600; white-space: nowrap; }
/* Marcas de líneas nuevas/modificadas tras recibir una nueva versión del presupuesto */
.lineas-tabla tr.lin-nueva td:first-child { box-shadow: inset 4px 0 0 #16a34a; }
.lineas-tabla tr.lin-modif td:first-child { box-shadow: inset 4px 0 0 #d97706; }
.lineas-tabla tr.lin-nueva td { background: #f0fdf4; }
.lineas-tabla tr.lin-modif td { background: #fffbeb; }
.lin-tag { display: block; margin-top: 3px; font-size: 10px; font-weight: 700; line-height: 1.3; padding: 1px 6px; border-radius: 999px; white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.lin-tag.t-nueva { background: #dcfce7; color: #15803d; }
.lin-tag.t-modif { background: #fef3c7; color: #b45309; }
.totales { margin: 14px 0 0 auto; max-width: 320px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); }
.tot-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: 14px; }
.tot-row input { padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: #fafafa; max-width: 110px; text-align: right; }
.tot-row b { min-width: 90px; text-align: right; }
.tot-neto, .tot-total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px; }
.tot-total { font-size: 16px; color: var(--accent); }
.tot-total b { font-size: 18px; }
.vacio { text-align: center; color: var(--muted); padding: 40px; }

/* ---- Ficha (compacta: que entre todo de una) ---- */
.ficha-acc { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.ficha-acc h2 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.ficha-acc h2 small { color: var(--muted); font-weight: 400; font-size: 14px; }
.dup-aviso { margin: -6px 0 14px; padding: 8px 12px; background: #fff7ed; border: 1px solid #fed7aa; border-radius: 8px; font-size: 13px; color: #9a3412; }
.dup-aviso a { color: var(--accent); font-weight: 600; }
.mod-aviso { margin: -6px 0 14px; padding: 8px 12px; background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; font-size: 13px; color: #92400e; }
.mod-cambios { margin: 6px 0 0; padding-left: 20px; }
.mod-cambios li { margin: 2px 0; }
.spacer { flex: 1; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px; align-items: start; }

/* ---- Baraja de tarjetas solapadas (cascada) ---- */
.deck { position: relative; margin-bottom: 4px; }
.deck input, .deck textarea { text-transform: uppercase; }
.deck input[name="email"], .deck input[name="emailFactura"], .deck input[name="web"] { text-transform: none; }
.deck .deck-card {
  position: absolute; top: 0; left: 0; width: 280px; height: 172px; overflow: hidden;
  border-radius: 14px; transition: transform .18s ease, box-shadow .18s ease;
  cursor: pointer; box-shadow: 0 3px 12px rgba(0,0,0,.10);
}
.deck .deck-card.front { height: auto; overflow: visible; box-shadow: 0 18px 40px rgba(0,0,0,.22); border-color: var(--accent); }
.deck .deck-card.front legend { cursor: pointer; }
.deck .deck-card.front legend { color: var(--accent); }
.deck .deck-card:not(.front) { opacity: .97; }
/* Móvil: se apilan en vertical y ocupan el ancho */
.deck.stacked { display: flex; flex-direction: column; gap: 10px; height: auto !important; }
.deck.stacked .deck-card { position: static; width: auto; height: auto; overflow: visible; box-shadow: var(--shadow); }
.deck.rec-deck { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; align-items: start; height: auto !important; }
.deck.rec-deck .deck-card { position: static; width: auto; height: auto; overflow: visible; box-shadow: var(--shadow); }
.deck.rec-deck-mont { grid-template-columns: minmax(260px, 340px) 1fr; }
fieldset { border: 1px solid var(--line); border-radius: 12px; background: var(--card); padding: 11px 13px; box-shadow: var(--shadow); }
legend { font-size: 11px; color: var(--accent); font-weight: 700; padding: 0 6px; text-transform: uppercase; letter-spacing: .04em; }
.f { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--muted); font-weight: 600; margin-bottom: 7px; }
.f input, .f select, .f textarea { padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; color: var(--txt); background: #fafafa; font-weight: 400; }
.f input:focus, .f select:focus, .f textarea:focus { outline: none; border-color: var(--accent); background: #fff; }
.f textarea { min-height: 44px; }
.row { display: flex; gap: 8px; }
.row .f { flex: 1; }

/* ---- Ficha de Artículo (compacta, estilo FileMaker) ---- */
.art-grid { display: grid; grid-template-columns: 1.1fr 0.9fr; gap: 14px; align-items: start; }
.art-datos, .art-variantes { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.art-datos { display: flex; flex-direction: column; gap: 6px; }
.fr { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.fr > label { flex: 0 0 108px; font-size: 12px; color: var(--muted); font-weight: 600; text-align: right; }
.fr > input, .fr > textarea, .fr > select { flex: 1; min-width: 0; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: #fafafa; color: var(--txt); }
.fr > input:focus, .fr > textarea:focus, .fr > select:focus { outline: none; border-color: var(--accent); background: #fff; }
.presup-cab { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; align-items: start; margin-bottom: 6px; }
.presup-cab fieldset { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
/* Evita que el contenido de Costes (desplegables) ensanche la tarjeta y se solape con Incidencia. */
.ficha-tabs, .ficha-tabs .tab-panel, #costesBody { min-width: 0; }
.ficha-tabs .coste-row { max-width: 100%; }
.ficha-tabs .coste-row select { max-width: 100%; }
.fr.full { align-items: flex-start; }
.fr .chks { flex: 1; display: flex; gap: 16px; font-size: 13px; color: var(--txt); }
.fr .chks label { display: flex; align-items: center; gap: 6px; }
.art-variantes .vh { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.art-variantes .vh button { text-transform: none; letter-spacing: 0; }
.art-variantes .tabla.mini td, .art-variantes .tabla.mini th { padding: 5px 8px; }
@media (max-width: 760px) { .art-grid { grid-template-columns: 1fr; } }
/* Panel para gestionar opciones (familias) */
.opt-panel { margin-top: 10px; border: 1px solid var(--accent); border-radius: 12px; background: var(--card); padding: 12px 14px; box-shadow: var(--shadow); }
.opt-head { display: flex; align-items: center; justify-content: space-between; font-size: 12px; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 8px; }
.opt-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.opt-row input { flex: 1; padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: #fafafa; }
.opt-acc { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

/* ---- Campo con icono (teléfono / Maps) ---- */
.con-ico { display: flex; gap: 6px; align-items: stretch; }
.con-ico input { flex: 1; min-width: 0; }
.ico-btn { border: 1px solid var(--line); background: #fafafa; border-radius: 8px; padding: 0 11px; cursor: pointer; font-size: 15px; line-height: 1; }
.ico-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.ico-wa { color: #25D366; display: inline-flex; align-items: center; justify-content: center; }
.ico-wa:hover { background: #e7f9ee; border-color: #25D366; }

/* ---- Pestañas ficha ---- */
.pestanas { margin-top: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.pest-nav { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); background: #fafafa; }
.pest { background: transparent; border: none; padding: 7px 13px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 13px; }
.pest.active { background: var(--accent-soft); color: var(--accent); }
.pest-cuerpo { padding: 14px; }

/* ---- Tabla mini (contactos / datos bancarios) ---- */
.tabla { width: 100%; border-collapse: collapse; }
.tabla th, .tabla td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.tabla thead th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tabla.mini input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 7px; background: #fafafa; }
.del-ct { background: none; border: none; color: var(--accent); font-size: 16px; }
.edit-ln { background: none; border: none; color: var(--muted); font-size: 14px; margin-right: 4px; cursor: pointer; }
.drag-h { color: var(--muted); cursor: grab; margin-right: 6px; font-size: 22px; touch-action: none; padding: 6px 4px; display: inline-block; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
/* Mientras se arrastra una línea, bloquea la selección de texto (iPad) */
body.arrastrando-fila, body.arrastrando-fila * { user-select: none !important; -webkit-user-select: none !important; -webkit-touch-callout: none !important; }
.abrir-modal { background: none; border: 1px solid var(--line); border-radius: 7px; color: var(--accent); font-size: 18px; cursor: pointer; padding: 5px 10px; }
.abrir-modal:hover { background: var(--accent-soft); border-color: var(--accent); }
.lineas-tabla .drag { white-space: nowrap; }

/* Panel/ventana interna flotante (ficha por encima de la pantalla actual) */
.vi-fondo { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 80; display: flex; align-items: center; justify-content: center; }
.vi-panel { width: 80vw; height: 82vh; max-width: 1100px; background: var(--card); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.4); display: flex; flex-direction: column; overflow: hidden; }
.vi-cab { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--accent); color: #fff; cursor: move; font-weight: 600; }
.vi-cerrar { background: none; border: none; color: #fff; font-size: 18px; cursor: pointer; }
.vi-frame { flex: 1; width: 100%; border: 0; }
.rev-fondo { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 300; display: flex; align-items: center; justify-content: center; padding: 16px; }
.rev-panel { width: 640px; max-width: 96vw; max-height: 92vh; background: var(--card); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.4); display: flex; flex-direction: column; overflow: hidden; }
.rev-cab { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--accent); color: #fff; }
.rev-body { padding: 14px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.rev-f { display: flex; flex-direction: column; gap: 4px; }
.rev-f > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.rev-f input { padding: 9px 11px; border: 1px solid #d4d4d8; border-radius: 8px; font-size: 16px; }
.rev-msg { min-height: 190px; border: 1px solid #d4d4d8; border-radius: 8px; padding: 10px 12px; font: 14px/1.5 Arial, Helvetica, sans-serif; overflow: auto; background: #fff; }
.rev-msg:focus { outline: none; border-color: var(--accent); }
.rev-acc { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 14px; border-top: 1px solid #eee; }
body.modo-ficha .topbar { display: none; }
body.modo-ficha main { padding: 12px; }
.ml-lapiz { padding: 0 7px; font-size: 13px; vertical-align: middle; }
.acc-cell { white-space: nowrap; }
.ref-cell { white-space: nowrap; }
.ir-art { background: none; border: none; color: var(--accent); font-size: 14px; cursor: pointer; padding: 0 4px 0 0; }
.ref-link { background: none; border: none; color: var(--accent); font-weight: 600; cursor: pointer; padding: 4px 2px; text-align: left; text-decoration: underline; text-underline-offset: 2px; }
.ref-link:hover { color: #7d0c10; }

/* Modal de línea */
.modal-fondo { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; box-shadow: 0 16px 48px rgba(0,0,0,.25); }
.modal-cab { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-cab h3 { margin: 0; font-size: 17px; }
.modal-cuerpo { padding: 16px 18px; }
.modal-pie { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); }
.ml { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; font-weight: 600; }
.ml-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin-top: 6px; }
.ml-grid input, .ml-grid select { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fafafa; }
.ml-precio { font-weight: 700; font-size: 18px; padding: 6px 0; }
.ml-desc { padding: 8px 10px; border: 1px dashed var(--line); border-radius: 8px; background: #fafafa; font-size: 14px; min-height: 20px; }
.ml-foto { margin-top: 4px; }
.ml-foto-prev { min-height: 60px; display: flex; align-items: center; }
.ml-foto-prev img { max-width: 160px; max-height: 160px; border: 1px solid var(--line); border-radius: 8px; background: #fafafa; }
.ml-foto-acc { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.modal-cuerpo textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fafafa; font: inherit; resize: vertical; }
.desc-cell { cursor: text; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: #fafafa; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 240px; max-width: 360px; font-size: 14px; }
.desc-cell:hover { border-color: var(--accent); background: #fff; }
.desc-cell:focus { white-space: pre-wrap; overflow: visible; outline: none; border-color: var(--accent); background: #fff; box-shadow: var(--shadow); position: relative; z-index: 5; min-height: 60px; }
.rt-flotante { position: fixed; z-index: 60; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 6px 8px; }
.rt-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; }
.rt-toolbar button { min-width: 30px; padding: 4px 8px; border: 1px solid var(--line); background: #fafafa; border-radius: 6px; cursor: pointer; font-size: 14px; }
.rt-toolbar button:hover { background: var(--accent-soft); border-color: var(--accent); }
.rt-toolbar select, .rt-toolbar input[type=color] { padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fafafa; height: 30px; }
.rt-toolbar input[type=color] { width: 36px; padding: 2px; }
.rt-edit { min-height: 120px; max-height: 50vh; overflow: auto; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 14px; line-height: 1.5; }
.rt-edit:focus { outline: none; border-color: var(--accent); }
.ar-row { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.ar-row span { color: var(--muted); }
.ar-row b { text-align: right; }

@media (max-width: 600px) {
  main { padding: 16px; }
  .list-head { flex-wrap: wrap; }
}

