:root {
  --plum: #632340;
  --plum-d: #4a1a30;
  --plum-t: #f6eef2;
  --yellow: #ffd400;
  --ink: #2a1620;
  --ink-2: #6b5761;
  --line: #e9e1e5;
  --paper: #ffffff;
  --bg: #fbf9fa;
  --red-bg: #f6d5d5;  --red-tx: #8a1c1c;
  --amb-bg: #fcebc2;  --amb-tx: #7a5200;
  --neu-bg: #f4f0f2;  --neu-tx: #2a1620;
  --grn-bg: #d7edd9;  --grn-tx: #1f5e2a;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); font-size: 15px; line-height: 1.5; background: var(--bg); }
h1 { font-size: 26px; font-weight: 600; margin: 0 0 20px; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 600; margin: 0 0 6px; }
p { margin: 0 0 10px; max-width: 78ch; }
code, kbd { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--plum-t); padding: 1px 5px; border-radius: 4px; }
a { color: var(--plum); }
:focus-visible { outline: 2px solid var(--plum); outline-offset: 2px; }

.top { background: var(--plum); color: #fff; border-bottom: 4px solid var(--yellow); }
.top-in { max-width: 1280px; margin: 0 auto; padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; display: flex; align-items: baseline; gap: 12px; }
.brand-name { font-weight: 600; font-size: 20px; }
.brand-sub { color: #e9d3dd; font-size: 14px; }
.top nav { display: flex; gap: 4px; }
.top nav a { color: #f1e3ea; text-decoration: none; padding: 6px 12px; border-radius: 6px; font-size: 14px; }
.top nav a:hover { background: var(--plum-d); }
.top nav a.on { background: #fff; color: var(--plum); font-weight: 500; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 24px; }
.hint { color: var(--ink-2); font-size: 13px; }
.hint.ok { color: var(--grn-tx); } .hint.err { color: var(--red-tx); }

.btn { font: inherit; font-size: 14px; border: 1px solid var(--plum); color: var(--plum); background: #fff; padding: 8px 16px; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover { background: var(--plum-t); }
.btn.primary { background: var(--plum); color: #fff; }
.btn.primary:hover { background: var(--plum-d); }

select, input { font: inherit; font-size: 14px; color: var(--ink); border: 1px solid #d6cad0; background: #fff; border-radius: 6px; padding: 6px 10px; min-height: 36px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); }

.filters { display: flex; flex-wrap: wrap; gap: 14px 20px; align-items: flex-end; padding: 14px 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 18px; }
.seg { display: flex; align-items: center; border: 1px solid #d6cad0; border-radius: 6px; overflow: hidden; background: #fff; }
.seg-l { font-size: 12px; color: var(--ink-2); padding: 0 10px; }
.seg button { font: inherit; font-size: 13px; border: 0; border-left: 1px solid var(--line); background: #fff; color: var(--ink); padding: 8px 12px; cursor: pointer; }
.seg button:hover { background: var(--plum-t); }
.seg button.on { background: var(--plum); color: #fff; }

.summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 28px; margin: 4px 0 20px; }
.summary .big { font-size: 44px; font-weight: 600; color: var(--plum); line-height: 1; font-variant-numeric: tabular-nums; }
.summary .big small { font-size: 14px; font-weight: 400; color: var(--ink-2); margin-left: 8px; }
.summary .fig { font-size: 14px; color: var(--ink-2); }
.summary .fig b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.summary .warn { color: var(--amb-tx); }

.board, .worst, .card { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.board-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.legend { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 12px; font-size: 12px; color: var(--ink-2); align-items: center; }
.legend span.k { padding: 2px 8px; border-radius: 4px; }
.scroll { overflow-x: auto; }

table.heat { border-collapse: separate; border-spacing: 2px; width: 100%; min-width: 720px; font-variant-numeric: tabular-nums; table-layout: fixed; }
.heat th { font-size: 12px; font-weight: 500; color: var(--ink-2); padding: 4px 0; text-align: center; }
.heat th.l, .heat td.l { width: 104px; white-space: nowrap; text-align: right; padding-right: 10px; font-size: 12px; color: var(--ink-2); font-weight: 400; }
.heat td { text-align: center; font-size: 12.5px; padding: 3px 0; border-radius: 3px; }
.heat.g60 td { padding: 7px 0; font-size: 13.5px; }
.heat td.wk, .heat th.wk { border-left: 2px solid var(--plum); }
.heat th.wk { color: var(--plum); font-weight: 600; }
.heat tr.tot td { font-weight: 600; padding: 9px 0; border-top: 2px solid var(--plum); }
.heat tr.tot td.l { color: var(--plum); }
.r { background: var(--red-bg); color: var(--red-tx); }
.a { background: var(--amb-bg); color: var(--amb-tx); }
.n { background: var(--neu-bg); color: var(--neu-tx); }
.g { background: var(--grn-bg); color: var(--grn-tx); }
.x { color: #b9aab2; }
.heat td[data-i]:hover, .heat td[data-t]:hover { outline: 2px solid var(--plum); outline-offset: -2px; }

table.list { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
.list th { text-align: left; font-weight: 500; font-size: 12px; color: var(--ink-2); border-bottom: 1px solid var(--line); padding: 8px 10px; }
.list td { border-bottom: 1px solid var(--line); padding: 8px 10px; }
.list .num { text-align: right; }
.pill { display: inline-block; min-width: 46px; text-align: center; padding: 2px 8px; border-radius: 4px; font-weight: 600; }

.foot { color: var(--ink-2); font-size: 12px; }
.empty { text-align: left; padding: 48px 0; max-width: 560px; }

.plain { padding-left: 20px; margin: 0 0 14px; } .plain li { margin-bottom: 4px; }
.drop { display: block; border: 2px dashed #d6cad0; border-radius: 10px; padding: 26px; text-align: center; color: var(--ink-2); font-size: 14px; cursor: pointer; margin: 10px 0 14px; background: var(--bg); }
.drop.over { border-color: var(--plum); background: var(--plum-t); }
.drop input { display: none; }
.row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; margin: 8px 0 12px; }
pre.code { background: #2a1620; color: #f6eef2; padding: 14px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; line-height: 1.5; max-height: 300px; }
.res { margin-top: 12px; padding: 10px 12px; border-radius: 6px; font-size: 14px; }
.res.ok { background: var(--grn-bg); color: var(--grn-tx); }
.res.err { background: var(--red-bg); color: var(--red-tx); }

@media (max-width: 720px) {
  .wrap { padding: 16px; }
  .summary .big { font-size: 36px; }
  .brand-sub { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.banner { background: var(--amb-bg); color: var(--amb-tx); padding: 10px 24px; font-size: 14px; text-align: center; }
textarea { font: 13px ui-monospace, Menlo, Consolas, monospace; width: 100%; border: 1px solid #d6cad0; border-radius: 6px; padding: 8px 10px; margin: 6px 0 8px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); }
label.check input { min-height: auto; }
.list td div.ok { color: var(--grn-tx); } .list td div.err { color: var(--red-tx); }
button:disabled { opacity: .5; cursor: not-allowed; }

.sync-btn { font: inherit; font-size: 14px; margin-left: 8px; background: var(--yellow); color: var(--plum-d); border: 0; border-radius: 6px; padding: 6px 14px; font-weight: 600; cursor: pointer; }
.sync-btn:hover { background: #ffe14d; }
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 22px; width: min(520px, 92vw); color: var(--ink); }
dialog::backdrop { background: rgba(42, 22, 32, .35); }
.row.end { justify-content: flex-end; margin-bottom: 0; }
.steps div, #dlg-out div.ok, #dlg-out div.err { font-size: 13px; margin-top: 4px; }
#dlg-out div.ok { color: var(--grn-tx); } #dlg-out div.err { color: var(--red-tx); }
#dlg-out .res { color: inherit; }
.list tr.sum td { border-top: 2px solid var(--plum); border-bottom: 0; }
.heat td.lowS, .legend .lowS { opacity: .6; font-style: italic; outline: 1px dashed currentColor; outline-offset: -3px; }
.legend .lowS { background: var(--neu-bg); color: var(--neu-tx); }
.heat td.nos { font-size: 11px; color: #9a8790; background: repeating-linear-gradient(135deg, var(--neu-bg) 0 4px, #fff 4px 8px); }
.worst-scroll { max-height: 560px; overflow-y: auto; }
.worst-scroll thead th { position: sticky; top: 0; background: var(--paper); z-index: 1; }
.list tr.lowrow td { font-style: italic; color: var(--ink-2); }

/* ---- GOFO Coste ---- */
.top nav { flex-wrap: wrap; }
.neg { color: var(--red-tx); }
.pos { color: var(--grn-tx); }
table.pl { border-collapse: collapse; width: 100%; min-width: 760px; font-size: 14px; font-variant-numeric: tabular-nums; }
.pl th { font-weight: 500; font-size: 12px; color: var(--ink-2); text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.pl th:first-child, .pl td:first-child { text-align: left; white-space: nowrap; }
.pl td { text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.pl tr.sub td { color: var(--ink-2); font-size: 13px; }
.pl tr.sub td:first-child { padding-left: 24px; }
.pl tr.key td { font-weight: 600; border-top: 2px solid var(--plum); }
.pl tr.key td:first-child { color: var(--plum); }
.pl tr.gap td { border: 0; padding: 6px; }
.pl td.tot, .pl th.tot { border-left: 2px solid var(--plum); font-weight: 600; }
table.daily { border-collapse: collapse; width: 100%; min-width: 1200px; font-size: 13px; font-variant-numeric: tabular-nums; }
.daily th { font-weight: 500; font-size: 11.5px; color: var(--ink-2); text-align: right; padding: 6px 6px; border-bottom: 1px solid var(--line); vertical-align: bottom; line-height: 1.25; }
.daily td { text-align: right; padding: 4px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.daily th.l, .daily td.l { text-align: left; }
.daily tr.we td { background: #faf6f8; }
.daily tr.fut td { color: #b9aab2; }
.daily tr.sum td { font-weight: 600; border-top: 2px solid var(--plum); border-bottom: 0; }
.daily td.res { font-weight: 600; }
.daily button.day { font: inherit; border: 0; background: none; color: var(--plum); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px; }
input.cell { width: 64px; min-height: 28px; padding: 2px 6px; text-align: right; font-size: 13px; background: #fffbe0; border-color: #eadf9e; }
input.cell.txt { width: 220px; text-align: left; }
input.cell.saved { background: var(--grn-bg); }
input.cell.bad { background: var(--red-bg); }
.src { font-size: 11px; color: var(--ink-2); }
.src.cps { color: var(--grn-tx); font-weight: 600; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 18px; margin: 10px 0 14px; }
.grid-form label small { color: var(--ink-2); font-size: 11.5px; line-height: 1.3; }
table.edit { border-collapse: collapse; width: 100%; font-size: 13px; min-width: 980px; }
.edit th { text-align: left; font-weight: 500; font-size: 12px; color: var(--ink-2); padding: 6px; border-bottom: 1px solid var(--line); }
.edit td { padding: 4px 6px; border-bottom: 1px solid var(--line); }
.edit input, .edit select { min-height: 30px; font-size: 13px; padding: 3px 6px; width: 100%; }
.edit td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--red-tx); padding: 4px 6px; }
.sim td { text-align: right; }
.kpis { display: flex; flex-wrap: wrap; gap: 10px 28px; margin: 4px 0 18px; font-size: 14px; color: var(--ink-2); }
.kpis b { color: var(--ink); font-size: 22px; font-weight: 600; display: block; font-variant-numeric: tabular-nums; }
.kpis b.neg { color: var(--red-tx); }
.note-list { color: var(--ink-2); font-size: 13px; padding-left: 18px; }
#fixed { min-width: 1500px; }
#fixed select { min-width: 112px; }
#fixed select.fx-staff { min-width: 200px; }
#fixed input[type="date"] { min-width: 140px; }
#staff select { min-width: 150px; }

.pill { display:inline-block; font-size:11.5px; font-weight:600; padding:2px 8px; border-radius:999px; text-decoration:none; white-space:nowrap; }
.pill.ok { background:var(--grn-bg); color:var(--grn-tx); }
.pill.warn { background:var(--amb-bg); color:var(--amb-tx); }
.pill.bad { background:var(--red-bg); color:var(--red-tx); }
.kpis-inline { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
details summary { cursor:pointer; margin:10px 0 4px; }

.mhead { font-size: 15px; margin: 18px 0 8px; color: var(--plum); display: flex; gap: 8px; align-items: center; }
.jt-scores { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 18px; align-items: end; margin-bottom: 10px; }
.jt-scores label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.jt-scores input.cell { width: 110px; }
.jt-scores small { color: var(--ink-2); font-size: 11.5px; line-height: 1.3; }
.jt-ach { display: flex; flex-direction: column; font-size: 13px; color: var(--ink-2); }
.jt-ach b { font-size: 22px; color: var(--ink); font-variant-numeric: tabular-nums; }

.jt-grid { display:flex; flex-wrap:wrap; gap:18px; margin:6px 0 4px; }
table.mini { width:auto; min-width:0; font-size:12.5px; }
table.mini caption { text-align:left; font-weight:600; font-size:12.5px; color:var(--plum); padding-bottom:4px; }
table.mini td, table.mini th { padding:4px 12px 4px 0; }
.jt-ach small { color: var(--ink-2); font-size: 11.5px; }

.jt-ach label.fix { flex-direction: row; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-2); margin-top: 4px; }
.jt-ach label.fix input.cell { width: 72px; min-height: 24px; font-size: 12px; }

#incentivo .edit input.cell { width: 90px; }

.kpis .kpi-gofo { padding-left: 22px; border-left: 2px solid var(--line); }
.kpis .kpi-gofo + .kpi-gofo { padding-left: 0; border-left: 0; }
.kpis b.warn { color: var(--amb-tx); }
.kpis b.pos { color: var(--grn-tx); }

.kpis { gap: 10px 22px; }
.kpis b { font-size: 20px; }
.kpis .kpi-gofo { padding-left: 18px; }
.pl tr.blk td { background: var(--plum); color: #fff; font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 6px 10px; border: 0; }
.pl tr.grp td { font-weight: 600; }
.pl tr.res td { font-size: 15px; }

.pl th.nq, .pl td.nq { text-align: center; color: var(--ink-2); width: 60px; font-weight: 600; }
.pl th.nq small { font-weight: 400; font-size: 10.5px; }

#p-facturas .list td:first-child, .list td.nowrap { white-space: nowrap; }

.pl td .q { display:inline-block; min-width:22px; margin-right:10px; padding:0 6px; border-radius:999px; background:var(--neu-bg); color:var(--ink-2); font-size:11px; font-weight:600; text-align:center; }
/* Rentabilidad */
table.sc { min-width: 640px; }
.sc th { vertical-align: bottom; min-width: 150px; }
.sc th.on { box-shadow: inset 0 -3px 0 var(--plum); }
.sc input.sc-name { font-weight: 600; font-size: 13px; text-align: right; width: 100%; min-height: 30px; padding: 3px 6px; }
.sc .sc-actions { display: flex; justify-content: flex-end; gap: 2px; margin-top: 2px; }
.sc .sc-actions .btn.link { font-size: 11.5px; color: var(--plum); padding: 2px 4px; }
.sc input.sc-in { width: 110px; min-height: 28px; padding: 2px 6px; text-align: right; font-size: 13px; }
.sc input.sc-in.chg { background: #fff4c2; border-color: #eadf9e; color: #2a1620; }
svg.sens { width: 100%; height: auto; max-width: 900px; font-size: 11px; fill: var(--ink-2); }
svg.sens .grid { stroke: var(--line); }
svg.sens .zero { stroke: var(--ink-2); stroke-width: 1.2; }
svg.sens .be { stroke: var(--amb-tx); stroke-dasharray: 4 3; }
svg.sens .l1 { fill: none; stroke: var(--plum); stroke-width: 2.5; }
svg.sens .l2 { fill: none; stroke: var(--grn-tx); stroke-width: 2; stroke-dasharray: 6 4; }
.ai-box { background: var(--neu-bg); border-left: 3px solid var(--plum); padding: 10px 14px; border-radius: 6px; font-size: 14px; line-height: 1.5; margin-top: 8px; }
/* Asistente */
.chat { display: flex; flex-direction: column; gap: 10px; max-height: 60vh; overflow-y: auto; margin-bottom: 12px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 12px; font-size: 14px; line-height: 1.5; }
.msg.user { align-self: flex-end; background: var(--plum); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--neu-bg); border-bottom-left-radius: 4px; }
.act { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.act.done { opacity: .75; }
.act-h { font-weight: 600; margin-bottom: 8px; }
.act-p { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 12px; margin-bottom: 8px; }
.act-p label { display: flex; flex-direction: column; font-size: 11.5px; color: var(--ink-2); gap: 3px; }
.act-p input { min-height: 30px; font-size: 13px; padding: 3px 6px; }
.act-r { font-size: 13px; }

/* Marca OptiGest */
.top .brand { display: flex; align-items: center; gap: 10px; }
.top .brand-logo { width: 36px; height: 36px; flex: none; }
.top .brand-gofo { color: #FFD400; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; font-size: 13px; }

/* Entregas por plazo */
.board.buckets { padding: 14px 18px; margin-bottom: 14px; }
.bk-title { font-weight: 600; margin-bottom: 10px; }
.bk-row { display: grid; grid-template-columns: repeat(6, minmax(110px, 1fr)); gap: 10px; }
.bk { background: var(--neu-bg); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.bk span { font-size: 12px; color: var(--ink-2); }
.bk b { font-size: 22px; font-variant-numeric: tabular-nums; }
.bk small { font-size: 12px; color: var(--ink-2); }
.bk.tot { background: var(--plum); color: #fff; }
.bk.tot span, .bk.tot small { color: #f1dbe6; }
@media (max-width: 800px) { .bk-row { grid-template-columns: repeat(3, 1fr); } }
/* Incidencias */
.inc-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .inc-grid { grid-template-columns: 1fr; } }
.res.warn { background: var(--amb-bg); color: var(--amb-tx); padding: 10px 14px; border-radius: 8px; }

#cases-tbl thead tr.filters-row th { padding: 4px 6px 8px; background: var(--paper); position: sticky; top: 0; }
#cases-tbl .cf { width: 100%; min-width: 90px; min-height: 30px; font-size: 12.5px; padding: 3px 6px; }

button.jump { font: inherit; background: none; border: 0; padding: 0; color: var(--plum); cursor: pointer; text-align: left; text-decoration: underline; text-underline-offset: 2px; }
button.jump:hover { color: var(--ink); }
#case-dlg { max-width: 640px; width: 92vw; }

/* Inicio de sesión */
.login-wrap { display: flex; justify-content: center; padding-top: 56px; }
.login-card { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 28px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card input { font: inherit; font-size: 15px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); }
.login-card .res { margin-top: 0; }
.top nav form.logout { display: inline; margin: 0; }
.top nav form.logout button { font: inherit; font-size: 13px; color: #e9d3dd; background: none; border: 0; padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.top nav form.logout button:hover { background: var(--plum-d); }
