:root {
  --purple: #4b0aa8;
  --purple-soft: #f1ecfb;
  --cyan: #2ab3f6;
  --cyan-ink: #0b7fbd;
  --ink: #17161c;
  --muted: #6b6a76;
  --line: #e5e3ec;
  --bg: #f6f5f9;
  --card: #fff;
  --ok: #128c4b;
  --ok-bg: #e5f6ec;
  --warn: #9a6200;
  --warn-bg: #fff3d6;
  --bad: #b3261e;
  --bad-bg: #fdeceb;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 14.5px/1.45 'Poppins', system-ui, sans-serif; }
a { color: var(--cyan-ink); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--cyan); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 70px; }
label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
label.check input { width: auto; }

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 8px 16px; background: #fff; border-bottom: 1px solid var(--line);
}
.top .logo img { display: block; }
.top nav { display: flex; gap: 4px; flex: 1; }
.top nav a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--ink); font-weight: 500; }
.top nav a.on { background: var(--purple-soft); color: var(--purple); }
.top .fx { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.top .fx input { width: 90px; padding: 5px 8px; font-weight: 600; color: var(--ink); }
@media (max-width: 720px) { .top nav { order: 3; flex-basis: 100%; overflow-x: auto; } }

#view { max-width: 1280px; margin: 0 auto; padding: 18px 16px 80px; }
.bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.bar .grow { flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stack > * + * { margin-top: 14px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 9px; font-weight: 600; text-decoration: none; color: var(--ink); white-space: nowrap;
}
.btn:hover { border-color: #cfcbe0; }
.btn.primary { background: var(--purple); border-color: var(--purple); color: #fff; }
.btn.primary:hover { background: #3c0889; }
.btn.cyan { background: var(--cyan); border-color: var(--cyan); color: #fff; }
.btn.wa { background: #1faa59; border-color: #1faa59; color: #fff; }
.btn.sm { padding: 4px 9px; font-size: 13px; border-radius: 7px; }
.btn.danger { color: var(--bad); }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.info { background: var(--purple-soft); color: var(--purple); }

/* lista de presupuestos */
.qlist { display: grid; gap: 8px; }
.qrow {
  display: grid; grid-template-columns: minmax(0, 2.2fr) 1fr 1.2fr 1.3fr auto; gap: 12px; align-items: center;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.qrow .who strong { display: block; }
.qrow .who span { color: var(--muted); font-size: 13px; }
.qrow .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 900px) {
  .qrow { grid-template-columns: 1fr auto; }
  .qrow .acts { grid-column: 1 / -1; justify-content: flex-start; }
}
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }

/* editor */
.editor { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
@media (max-width: 1300px) { .editor { grid-template-columns: minmax(0, 1fr) 280px; gap: 12px; } }
@media (max-width: 1050px) { .editor { grid-template-columns: 1fr; } }
.summary { position: sticky; top: 70px; }
.summary dl { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; margin: 0; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.summary .big { font-size: 30px; font-weight: 700; color: var(--purple); text-align: right; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.summary hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.summary .gain { color: var(--ok); font-weight: 600; }
.linkbox { display: flex; gap: 6px; }
.linkbox input { font-size: 12.5px; }

.tablewrap { margin: 0; }
table.items { width: 100%; border-collapse: collapse; table-layout: fixed; }
table.items col.c-qty { width: 58px; }
table.items col.c-cost { width: 118px; }
table.items col.c-iva { width: 66px; }
table.items col.c-mar { width: 54px; }
table.items col.c-calc { width: 82px; }
table.items col.c-acts { width: 112px; }
table.items .dwrap { max-width: 100%; }
table.items th { font-size: 11.5px; color: var(--muted); font-weight: 600; text-align: left; padding: 6px 3px; border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
table.items td { padding: 4px 3px; border-bottom: 1px solid #f0eff4; vertical-align: middle; }
table.items input, table.items select { width: 100%; min-width: 0; padding: 6px 6px; border-radius: 7px; }
table.items select { padding-right: 0; }
table.items input[type=number] { -moz-appearance: textfield; appearance: textfield; text-align: right; }
table.items input[type=number]::-webkit-inner-spin-button, table.items input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
table.items td.c, table.items th.c { text-align: center; }
table.items td.acts { white-space: nowrap; text-align: center; }
table.items td.acts .iconbtn { padding: 4px 3px; font-size: 14px; }
table.items .iconbtn.on { opacity: 1; }
table.items .calc { font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
table.items .calc.fin { font-weight: 700; }
table.items tr.opt td { background: #fbfaff; }
table.items tr.opt .calc { color: var(--muted); }
table.items tr.detail td { background: #faf9fc; padding: 10px 8px 14px; }
.tagcell { position: relative; }
.tag { position: absolute; right: 2px; top: -5px; border: 0; border-radius: 5px; padding: 0 4px; font-size: 9.5px; line-height: 14px; font-weight: 700; background: var(--purple-soft); color: var(--purple); cursor: pointer; white-space: nowrap; box-shadow: 0 0 0 2px #fff; }
.tag.man { background: #fff3d6; color: var(--warn); }
table.items td { padding-top: 7px; }
.costcell { display: flex; }
.costcell .cur { border: 1px solid var(--line); border-right: 0; border-radius: 7px 0 0 7px; background: #f6f5f9; font-size: 12px; font-weight: 700; padding: 0 6px; cursor: pointer; color: var(--purple); min-width: 36px; }
.costcell .cur:hover { background: var(--purple-soft); }
.costcell input { border-radius: 0 7px 7px 0 !important; }
.iconbtn { border: 0; background: none; cursor: pointer; font-size: 16px; padding: 4px 6px; border-radius: 6px; line-height: 1; }
.iconbtn:hover { background: var(--bg); }
.iconbtn.off { opacity: .3; }
.addrow { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.addrow select { flex: 1; min-width: 220px; }

.thumbs { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; }
.thumb { width: 150px; }
.thumb .pv { width: 150px; height: 96px; border-radius: 8px; background: #eceaf2 center/cover no-repeat; display: grid; place-items: center; color: var(--muted); font-size: 12px; overflow: hidden; }
.thumb .pv video { width: 100%; height: 100%; object-fit: cover; }
.thumb .row { display: flex; gap: 4px; margin-top: 4px; }
.progress { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--cyan); transition: width .2s; }

/* catálogo */
table.cat { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
table.cat th, table.cat td { padding: 9px 10px; border-bottom: 1px solid #f0eff4; text-align: left; }
table.cat th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fbfbfd; }
table.cat tr.cat-h td { background: var(--purple-soft); color: var(--purple); font-weight: 700; font-size: 13px; }
table.cat tr.p { cursor: pointer; }
table.cat tr.p:hover td { background: #faf9fd; }
.badges { display: flex; gap: 4px; }

dialog { border: 0; border-radius: 14px; padding: 0; width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 40px); box-shadow: 0 30px 80px -20px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(20, 10, 40, .4); }
dialog .dh { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 1; }
dialog .db { padding: 16px 18px; }
dialog .df { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: #fff; }
dialog .df .grow { flex: 1; }

#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; }
#toast.show { opacity: 1; transform: translateX(-50%); }

body.login { display: grid; place-items: center; min-height: 100vh; }
body.login .card { width: min(360px, 92vw); display: grid; gap: 14px; justify-items: center; padding: 28px; }
body.login label { width: 100%; }
body.login .btn { width: 100%; }
.err { color: var(--bad); margin: 0; }

/* precios de proveedores */
.sups { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.supcard { display: grid; gap: 1px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; font-size: 13px; }
.supcard strong { font-size: 15px; }
.pfilters { display: grid; gap: 10px; margin-bottom: 12px; position: sticky; top: 52px; z-index: 5; }
.bigsearch { font-size: 17px; padding: 12px 14px; border-radius: 10px; }
.frow { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.frow select { width: auto; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 7px 14px; cursor: pointer; font-weight: 500; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--purple); color: #fff; }
.slist { display: grid; gap: 8px; }
.srow { display: grid; grid-template-columns: 72px minmax(0, 1fr) 230px auto; gap: 14px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.simg { width: 72px; height: 72px; border-radius: 8px; background: #f3f2f7; display: grid; place-items: center; overflow: hidden; font-size: 11px; color: var(--muted); }
.simg img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.stitle { font-size: 15px; }
.sdesc { font-size: 13px; color: var(--muted); margin: 1px 0 4px; }
.smeta { font-size: 12.5px; display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.sprice { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }
.sprice .pnet { font-size: 17px; font-weight: 700; }
.sprice .pnet small { font-size: 12px; font-weight: 500; color: var(--muted); }
.sprice .psale { color: var(--purple); }
.sacts { display: grid; gap: 6px; }
.chip.sup { background: #eef7fd; color: var(--cyan-ink); }
.chip.sup-teletex { background: #fdf0e8; color: #a14a0b; }
@media (max-width: 860px) {
  .srow { grid-template-columns: 60px minmax(0, 1fr); }
  .simg { width: 60px; height: 60px; }
  .sprice { grid-column: 2; text-align: left; }
  .sacts { grid-column: 2; display: flex; }
  .pfilters { position: static; }
}

/* buscador de productos en el editor */
.picker { position: relative; flex: 1; min-width: 260px; }
.pickres { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 20; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 18px 40px -16px rgba(30, 10, 60, .35); max-height: 420px; overflow: auto; }
.phead { padding: 8px 12px 4px; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.popt { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 6px 12px; cursor: pointer; }
.popt.on, .popt:hover { background: var(--purple-soft); }
.popt .pimg { width: 40px; height: 40px; border-radius: 6px; background: #f3f2f7; overflow: hidden; }
.popt .pimg img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.popt .ptxt { display: grid; font-size: 13px; line-height: 1.3; }
.popt .ptxt span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.popt .num { font-size: 13px; }

/* ofertas en el producto */
.offers { display: grid; gap: 6px; background: #faf9fc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.orow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.orow .grow { flex: 1; min-width: 160px; }

/* revisión y plantillas */
.checks { border: 1px solid #f3d3d0; background: #fff8f7; border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; display: grid; gap: 6px; }
.checks.ok { border-color: #cdebd9; background: #f3fbf6; }
.checks h2 { margin: 0 0 2px; font-size: 14.5px; }
.checks.ok h2 { color: var(--ok); }
.chk { display: grid; grid-template-columns: 20px 1fr; gap: 6px; font-size: 13px; line-height: 1.35; }
.chk .btn { margin-top: 3px; }
.chk.info { color: var(--muted); }
.tplb { flex: none; border: 0; border-radius: 6px; padding: 2px 5px; font-size: 11px; font-weight: 700; background: var(--purple-soft); color: var(--purple); cursor: pointer; white-space: nowrap; }
.tplb.man { background: #fff3d6; color: var(--warn); }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; border-radius: 10px; background: #fff; color: var(--purple); font-size: 12px; margin-left: 6px; padding: 0 5px; }
.summary { max-height: calc(100vh - 86px); overflow: auto; }
.fxsrc-l { font-size: 12px; color: var(--muted); text-decoration: none; margin-left: 6px; }
.fxsrc { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 8px; }
.fxopt { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; color: var(--ink); font-size: 13.5px; cursor: pointer; }
.fxopt input { width: auto; }
.fxopt span { flex: 1; }
.fxopt.on { border-color: var(--purple); background: var(--purple-soft); }
.tplcard { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fcfbfe; }
.tplcard + .tplcard { margin-top: 10px; }
table.tpllines { width: 100%; border-collapse: collapse; }
table.tpllines th { font-size: 11.5px; color: var(--muted); text-align: left; padding: 4px; }
table.tpllines td { padding: 3px 4px; }
.savebar { position: sticky; bottom: 0; background: #fff; padding: 10px 0 2px; }

@media (max-width: 760px) {
  .tablewrap { overflow-x: auto; }
  table.items { min-width: 700px; }
}
.chk.fix { margin-top: -4px; }
.chk.fix .btn { margin-top: 0; text-align: left; white-space: normal; }
.popt.other { opacity: .75; }
.chk { min-width: 0; }
.chk > div { min-width: 0; overflow-wrap: anywhere; }
.chk .btn { white-space: normal; text-align: left; max-width: 100%; }
.tag.sup { background: #e3f3fd; color: var(--cyan-ink); cursor: default; }
.tag.sup-teletex { background: #fdeee3; color: #a14a0b; }

/* huecos de plantilla */
tr.slotrow td { background: #fbfaff; }
.slotin { border-style: dashed !important; border-color: #c9bfe6 !important; background: #fff !important; cursor: pointer; }
.slotin::placeholder { color: #9a93ad; font-style: italic; }
.slotin:focus { cursor: text; }
.slotcell .pickres { min-width: 560px; }
.phead.ptitle { color: var(--purple); text-transform: none; letter-spacing: 0; font-size: 12.5px; }
.slotedit { display: grid; grid-template-columns: 1fr 1.3fr auto; gap: 4px; }
.slotedit input { border-style: dashed; }
table.tpllines td.c { text-align: center; }
.svcedit { display: grid; grid-template-columns: 1fr 130px 70px 62px; gap: 4px; }
.svcedit input[type=number] { text-align: right; }

/* aprobación e historial */
.approval { font-size: 13px; line-height: 1.4; border-radius: 10px; padding: 10px 12px; background: var(--bg); }
.approval.pending { background: var(--warn-bg); color: #5c3b00; }
.approval.ok { background: var(--ok-bg); color: var(--ok); }
.approval .link { color: inherit; text-decoration: underline; padding: 0 4px; }
.approval-actions { display: flex; gap: 6px; margin-top: 8px; }
.timeline h3 { font-size: 13px; margin: 4px 0 6px; }
.timeline ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 260px; overflow: auto; }
.timeline li { display: grid; grid-template-columns: 78px 1fr; gap: 6px; font-size: 12.5px; line-height: 1.3; }
.timeline .ev-at { color: var(--muted); font-variant-numeric: tabular-nums; }
.timeline small { display: block; color: var(--muted); }
.timeline .ev-accept span, .timeline .ev-ask_financing span { font-weight: 600; }
.timeline .ev-approved span { color: var(--ok); font-weight: 600; }
