:root {
  --bg: #f5f6f8; --panel: #ffffff; --ink: #1d2433; --muted: #667085; --line: #e3e6ec;
  --brand: #1f6f4a; --brand-ink: #ffffff; --brand-soft: #e6f2ec;
  --warn: #b54708; --warn-soft: #fff4e5; --bad: #b42318; --bad-soft: #fdecea; --ok: #067647; --ok-soft: #e7f6ee;
  --blue: #2563a8; --blue-soft: #e8f0fa; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 10px; --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d; --panel: #1b212b; --ink: #e8ebf0; --muted: #9aa4b2; --line: #2b3340;
    --brand: #3fa675; --brand-ink: #0c1410; --brand-soft: #1d3228;
    --warn: #f0a850; --warn-soft: #34281a; --bad: #f07b72; --bad-soft: #3a1f1d; --ok: #55c28f; --ok-soft: #1c3226;
    --blue: #7fb2ec; --blue-soft: #1d2a3b; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
h1, h2, h3 { margin: 0; font-weight: 650; }
h2 { font-size: 18px; } h3 { font-size: 15px; }
a { color: var(--blue); }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); }

/* ---- barra superior ---- */
.topbar { display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 54px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.tabs { display: flex; gap: 2px; height: 100%; }
.tab { border: 0; background: none; color: var(--muted); padding: 0 14px; height: 100%; border-bottom: 3px solid transparent; font-weight: 550; }
.tab:hover { color: var(--ink); } .tab.active { color: var(--ink); border-bottom-color: var(--brand); }
.spacer { flex: 1; }
.vendorpick { display: flex; align-items: center; gap: 8px; }
.userbox { display: flex; align-items: center; gap: 10px; }

/* ---- contenedor ---- */
main { max-width: 1500px; margin: 0 auto; padding: 18px 20px 60px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.card + .card { margin-top: 14px; }
.card > h3 { margin-bottom: 10px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > .card { flex: 1 1 380px; margin-top: 0 !important; }
.grid-kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.kpi .val { font-size: 24px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.warn .val { color: var(--warn); } .kpi.bad .val { color: var(--bad); }

/* ---- controles ---- */
input, select { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-height: 34px; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 7px 14px; min-height: 34px; font-weight: 550; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.filters .grow { flex: 1 1 220px; }

/* ---- tablas ---- */
.tablewrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { background: var(--bg); font-weight: 600; font-size: 12px; color: var(--muted); position: sticky; top: 0; z-index: 1; }
th.sort { cursor: pointer; user-select: none; } th.sort:hover { color: var(--ink); }
td.num, th.num { text-align: right; }
tbody tr:hover { background: var(--brand-soft); }
tr.clickable { cursor: pointer; }
td.desc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
tfoot td { font-weight: 650; background: var(--bg); }

/* ---- etiquetas ---- */
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.tag.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.tag.blue { background: var(--blue-soft); color: var(--blue); border-color: transparent; }

/* ---- barras ---- */
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--brand); }
.heat td.h { text-align: right; }

/* ---- corrida ---- */
.vendorlist { max-height: 300px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.vendorlist label { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.vendorlist label:hover { background: var(--brand-soft); }
.vendorlist .vn { flex: 1; } .vendorlist .vm { color: var(--muted); font-size: 12px; text-align: right; }
.timeline { list-style: none; padding: 0; margin: 8px 0 0; }
.timeline li { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--line); align-items: baseline; }
.timeline .st { width: 18px; text-align: center; }
.spin { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: sp 0.8s linear infinite; vertical-align: -2px; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---- panel lateral (de donde sale) ---- */
.drawer-back { position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--bg); z-index: 41; overflow: auto; box-shadow: -8px 0 24px rgba(0,0,0,.2); }
.drawer header { position: sticky; top: 0; background: var(--panel); border-bottom: 1px solid var(--line); padding: 14px 18px; z-index: 2; display: flex; gap: 12px; align-items: flex-start; }
.drawer header .t { flex: 1; } .drawer .body { padding: 14px 18px 40px; }
.result { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.result .big { font-size: 26px; font-weight: 700; }
.step { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.step > summary { list-style: none; cursor: pointer; padding: 11px 14px; display: flex; gap: 10px; align-items: flex-start; }
.step > summary::-webkit-details-marker { display: none; }
.step .n { flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font-weight: 700; display: grid; place-items: center; font-size: 12px; }
.step .tt { flex: 1; } .step .tt b { display: block; } .step .tt span { color: var(--muted); }
.step[open] > summary { border-bottom: 1px solid var(--line); }
.step dl { margin: 0; padding: 8px 14px 12px; display: grid; grid-template-columns: minmax(180px, 1.3fr) minmax(110px, .8fr); gap: 4px 14px; }
.step dt { color: var(--muted); } .step dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.step .hint { grid-column: 1 / -1; color: var(--muted); font-size: 12px; margin: -2px 0 6px; }
.chart { width: 100%; height: 170px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* ---- dialogos y avisos ---- */
.modal-back { position: fixed; inset: 0; background: rgba(16,24,40,.5); z-index: 60; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; padding: 20px 22px; width: min(720px, 100%); max-height: 90vh; overflow: auto; border: 1px solid var(--line); }
.modal h3 { margin-bottom: 8px; } .modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.notice { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border: 1px solid transparent; }
.notice.warn { background: var(--warn-soft); color: var(--warn); } .notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--ok-soft); color: var(--ok); } .notice.info { background: var(--blue-soft); color: var(--blue); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 8px; z-index: 80; box-shadow: 0 6px 20px rgba(0,0,0,.3); }

/* ---- login ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 26px; }
.login h1 { font-size: 22px; margin-bottom: 4px; }
.login label { display: block; margin-top: 12px; font-weight: 550; } .login input { width: 100%; margin-top: 4px; }

@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; } .tabs { order: 3; width: 100%; overflow-x: auto; height: 40px; }
  main { padding: 12px; } .step dl { grid-template-columns: 1fr auto; }
}

/* ---- progreso en vivo de la corrida ---- */
.timeline li { align-items: center; }
.timeline li .tx { flex: 1; }
.timeline li.phase .tx { font-weight: 600; }
.timeline li.sub { padding-left: 30px; color: var(--muted); }
.timeline li.sub .st { width: 16px; }
/* ---- ajuste de cantidades ---- */
.pen { border: 1px solid transparent; background: none; color: var(--muted); border-radius: 6px; padding: 0 6px; font-size: 14px; line-height: 22px; }
.pen:hover { background: var(--bg); color: var(--ink); border-color: var(--line); }
.edq { color: var(--warn); }

/* ---- lineas de una orden dentro de Exportar a NAV ---- */
tr.ordlines > td { background: var(--bg); padding: 10px 14px 14px; }
tr.ordlines:hover { background: var(--bg); }
.ordbox { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.qin { width: 92px; text-align: right; padding: 4px 6px; min-height: 28px; }
.qin.edited { border-color: var(--warn); background: var(--warn-soft); }
