/* Emulator Back Allocation · estilo visual de la plataforma New Pick Synergy.
   Fondo gris claro, tarjetas blancas con borde fino, teal como único acento de interfaz.
   Colores de fluido (solo dentro de los datos): aceite verde, agua azul, gas rojo. */
:root {
  --bg: #f2f4f3;
  --surface: #ffffff;
  --surface-2: #f8f9f9;
  --line: #dde2e3;
  --line-soft: #eceff0;
  --fg: #1f2a30;
  --fg-2: #3d4a51;
  --muted: #66737b;
  --primary: #037a8c;
  --primary-hover: #02697a;
  --primary-ink: #00678c;
  --primary-soft: #e3f3f5;
  --oil: #2f8a3e;      /* aceite: verde */
  --water: #1f6fb4;    /* agua: azul */
  --gas: #d2403a;      /* gas: rojo */
  --sim: #8e9aa2;
  --bad: #b42318;  --bad-soft: #fdecea;
  --ok: #157a3e;   --ok-soft: #e3f5ea;
  --warn: #9a5b00; --warn-soft: #fff4e0;
  --radius: 6px;
  --sans: "IBM Plex Sans", "Segoe UI", Roboto, Arial, sans-serif;
  --mono: "IBM Plex Mono", Consolas, "Courier New", monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font-family: var(--sans); font-size: 14px; line-height: 1.4; }
[hidden] { display: none !important; }
a { color: var(--primary-ink); }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--line-soft); padding: 0 4px; border-radius: 3px; color: var(--fg); }

/* ---------- Barra superior y navegación ---------- */
.appbar { position: sticky; top: 0; z-index: 20; height: 52px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: stretch; padding: 0 20px; gap: 24px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--fg); white-space: nowrap; }
.brand-mark { width: 28px; height: 28px; border-radius: 6px; background: var(--primary); display: grid; place-items: center; }
.brand-mark svg { width: 16px; height: 16px; }
.brand b { display: block; font-size: 14px; font-weight: 600; }
.brand small { display: block; font-size: 11.5px; color: var(--muted); }
.nav { display: flex; align-items: stretch; gap: 4px; min-width: 0; overflow-x: auto; }
.nav a { display: flex; align-items: center; padding: 0 12px; color: var(--muted); text-decoration: none; font-size: 14px; border-bottom: 2px solid transparent; white-space: nowrap; }
.nav a:hover { color: var(--fg); }
.nav a[aria-current="page"] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.appbar .spacer { flex: 1; }
.conn { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }

/* ---------- Página ---------- */
.page { max-width: 1480px; margin: 0 auto; padding: 24px 24px 48px; display: grid; gap: 20px; }
.pagehead { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 16px; }
.pagehead h1 { margin: 0; font-size: 24px; font-weight: 600; letter-spacing: -.01em; }
.pagehead p { margin: 4px 0 0; color: var(--muted); font-size: 15px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Botones y controles ---------- */
.btn { font: inherit; font-size: 14px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 14px; min-height: 38px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); color: var(--fg); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #c5cdd0; background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.field { display: grid; gap: 6px; min-width: 0; }
.field > .seg, .filters > .seg, .filters > .checks { justify-self: start; }
.field > span, .field > label { font-size: 13px; font-weight: 500; color: var(--fg-2); }
.input, select.input { font: inherit; font-size: 14px; color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; min-height: 38px; width: 100%; }
.input:hover { border-color: #c5cdd0; }
.input:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.seg button { font: inherit; font-size: 13px; background: transparent; color: var(--muted); border: 0; padding: 7px 12px; min-height: 36px; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { color: var(--fg); }
.seg button[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.checks { display: flex; flex-wrap: wrap; gap: 6px; }
.check { display: inline-flex; align-items: center; gap: 7px; padding: 6px 11px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; cursor: pointer; background: var(--surface); user-select: none; }
.check input { accent-color: var(--primary); margin: 0; }
.check:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 600; }

/* ---------- Pestañas tipo plataforma ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a, .tabs button { font: inherit; font-size: 14px; background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; color: var(--muted); padding: 10px 14px; cursor: pointer; text-decoration: none; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; }
.tabs a:hover, .tabs button:hover { color: var(--fg); }
.tabs [aria-selected="true"], .tabs [aria-current="page"] { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tabs .count { font-size: 12px; color: var(--muted); font-weight: 400; }

/* ---------- Tarjetas ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.card-h { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.card-h h2, .card-h h3 { margin: 0; font-size: 16px; font-weight: 600; }
.card-h p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.card-b { padding: 16px; }
.card-f { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--line); }
.section-title { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 12px; margin: 4px 0 -6px; }
.section-title h2 { margin: 0; font-size: 17px; font-weight: 600; }
.section-title p { margin: 0; color: var(--muted); font-size: 13px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 6px; align-content: start; }
.kpi .lbl { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.kpi .val { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .val i { font-style: normal; font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 4px; }
.kpi .sub { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex: none; }
.sw.sim { background: repeating-linear-gradient(135deg, var(--sim) 0 2px, #d6dcdf 2px 4px); }

/* ---------- Estados ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.na { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.notice { padding: 10px 14px; border: 1px solid #f0d9a8; background: var(--warn-soft); color: #6b4300; border-radius: var(--radius); font-size: 13px; line-height: 1.5; }
.notice.bad { border-color: #f3c3bd; background: var(--bad-soft); color: var(--bad); }
.note { color: var(--muted); font-size: 13px; line-height: 1.55; margin: 0; }
.delta-up { color: var(--ok); } .delta-down { color: var(--bad); }

/* ---------- Tablas ---------- */
.tblwrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.tbl th { background: var(--surface-2); text-align: right; font-size: 13px; font-weight: 600; color: var(--fg-2); padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl thead tr.group th { background: var(--surface); text-align: center; border-bottom: 1px solid var(--line-soft); font-size: 12.5px; color: var(--muted); font-weight: 500; }
.tbl thead tr.group th.a { box-shadow: inset 0 -2px 0 var(--primary); color: var(--fg); }
.tbl td { text-align: right; padding: 11px 14px; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .l, .tbl th.l, .tbl td.l { text-align: left; }
.tbl tbody tr:hover td { background: #fafbfb; }
.tbl .strong { font-weight: 600; }
.tbl .muted { color: var(--muted); }
.tbl .sepl { border-left: 1px solid var(--line-soft); }
.tbl .empty { text-align: center; color: var(--muted); padding: 28px; }
.phase-dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 8px; vertical-align: 1px; }

/* ---------- Gráficas ---------- */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; }
.chart { position: relative; }
.chart canvas, .chart svg { display: block; width: 100%; height: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .line { width: 16px; height: 0; border-top: 2px solid; }
.legend .line.dash { border-top-style: dashed; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 18px rgba(20,35,40,.12); padding: 8px 10px; font-size: 12.5px; line-height: 1.55; white-space: nowrap; z-index: 5; font-variant-numeric: tabular-nums; }
.tip .h { font-weight: 600; display: block; margin-bottom: 2px; color: var(--fg-2); }
.tip .row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tip .row b { font-weight: 600; }

.footnote { color: var(--muted); font-size: 12.5px; line-height: 1.6; margin: 0; }
@media (max-width: 720px) { .appbar { padding: 0 12px; gap: 12px; } .brand small { display: none; } .page { padding: 16px 12px 40px; } }

/* ---------- Barra lateral (como la plataforma) ---------- */
body.has-sb { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.app { min-width: 0; }
.sidebar { position: sticky; top: 0; height: 100vh; background: #2b3033; color: #e8ecee; display: flex; flex-direction: column; overflow-y: auto; z-index: 30; }
.sb-brand { display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-bottom: 1px solid #3a4145; text-decoration: none; color: #fff; min-height: 56px; }
.sb-brand b { display: block; font-size: 14px; font-weight: 700; }
.sb-brand small { display: block; color: #aab3b8; font-size: 12px; }
.sb-logo { width: 32px; height: 32px; border-radius: 6px; background: #fff; display: grid; place-items: center; overflow: hidden; flex: none; }
.sb-logo img { width: 78%; height: 78%; object-fit: contain; }
.sb-logo-ph { font-size: 10px; font-weight: 700; color: var(--primary); letter-spacing: .02em; }
.sb-nav { padding: 6px 10px 12px; display: grid; gap: 2px; }
.sb-group { font-size: 12px; color: #aab3b8; font-weight: 600; padding: 16px 8px 6px; }
.sb-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: #e8ecee; text-decoration: none; font-size: 14px; }
.sb-item svg { width: 16px; height: 16px; flex: none; opacity: .85; }
.sb-item:hover { background: #353b3f; }
.sb-item[aria-current="page"] { background: #474e53; color: #fff; font-weight: 500; }
.sb-item:focus-visible { outline: 2px solid #69c8d6; outline-offset: -2px; }
.sb-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid #3a4145; font-size: 11.5px; color: #8f999e; }
.sb-beta { border: 1px solid #a8862f; color: #e3c675; border-radius: 999px; padding: 1px 8px; }
.appbar .crumb { display: flex; align-items: center; color: var(--muted); font-size: 14px; white-space: nowrap; }
.appbar .crumb span { margin: 0 8px; color: #b5bec3; }
.appbar .crumb b { color: var(--fg); font-weight: 600; }
.appbar { align-items: center; }
#sb-toggle { display: inline-flex; padding: 6px; min-height: 34px; margin-right: 6px; }
body.has-sb { transition: grid-template-columns .18s ease; }
body.has-sb.sb-collapsed { grid-template-columns: 64px minmax(0, 1fr); }
.sb-collapsed .sb-brand { justify-content: center; padding: 12px 0; }
.sb-collapsed .sb-brand > span:last-child, .sb-collapsed .sb-item span, .sb-collapsed .sb-foot span:last-child { display: none; }
.sb-collapsed .sb-group { font-size: 0; padding: 10px 8px 4px; border-top: 1px solid #3a4145; margin: 6px 4px 0; }
.sb-collapsed .sb-group:first-child { border-top: 0; }
.sb-collapsed .sb-item { justify-content: center; padding: 10px 0; }
.sb-collapsed .sb-item svg { width: 18px; height: 18px; }
.sb-collapsed .sb-foot { justify-content: center; padding: 10px 4px; }
.sb-collapsed .sb-beta { font-size: 0; width: 8px; height: 8px; padding: 0; border-radius: 50%; background: #a8862f; }
@media (max-width: 1000px) {
  body.has-sb, body.has-sb.sb-collapsed { grid-template-columns: minmax(0, 1fr); }
  .sb-collapsed .sb-brand > span:last-child, .sb-collapsed .sb-item span, .sb-collapsed .sb-foot span:last-child { display: initial; }
  .sidebar { position: fixed; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .18s ease; }
  body.sb-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(20, 30, 35, .35); }
  #sb-toggle { display: inline-flex; }
}

/* ---------- Filtros desplegables ---------- */
.filterbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.dd { position: relative; display: inline-block; }
.dd-btn { font: inherit; font-size: 13.5px; display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 7px 10px 7px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--fg); cursor: pointer; white-space: nowrap; }
.dd-btn:hover { border-color: #c5cdd0; }
.dd-btn[aria-expanded="true"] { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.dd-btn svg { width: 14px; height: 14px; color: var(--muted); }
.dd-lbl { color: var(--muted); }
.dd-val { font-weight: 600; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.dd-panel { position: absolute; top: calc(100% + 6px); left: 0; z-index: 40; min-width: 230px; max-width: 320px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 28px rgba(20, 35, 40, .14); padding: 6px; }
.dd-actions { display: flex; justify-content: space-between; gap: 8px; padding: 4px 6px 8px; border-bottom: 1px solid var(--line-soft); margin-bottom: 4px; }
.dd-actions button { font: inherit; font-size: 12.5px; color: var(--primary-ink); background: none; border: 0; padding: 2px 0; cursor: pointer; }
.dd-actions button:hover { text-decoration: underline; }
.dd-list { display: grid; gap: 1px; max-height: 300px; overflow: auto; }
.dd-opt { font: inherit; font-size: 13.5px; display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 7px 8px; border: 0; border-radius: 4px; background: none; color: var(--fg); cursor: pointer; }
.dd-opt:hover { background: var(--surface-2); }
.dd-opt input { accent-color: var(--primary); margin: 0; }
.dd-opt[aria-selected="true"] { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

/* ---------- Usuario en la barra lateral ---------- */
.sb-user { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 16px; border-top: 1px solid #3a4145; }
.sb-avatar { width: 32px; height: 32px; border-radius: 50%; background: #037a8c; color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.sb-uinfo { min-width: 0; flex: 1; }
.sb-uinfo b { display: block; font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-uinfo small { display: block; font-size: 11.5px; color: #aab3b8; }
.sb-uact { display: flex; gap: 2px; }
.sb-ubtn { width: 30px; height: 30px; display: grid; place-items: center; background: none; border: 0; border-radius: 6px; color: #c4ccd0; cursor: pointer; }
.sb-ubtn:hover { background: #353b3f; color: #fff; }
.sb-ubtn svg { width: 16px; height: 16px; }
.sb-collapsed .sb-user { flex-direction: column; padding: 10px 4px; gap: 6px; }
.sb-collapsed .sb-uinfo { display: none; }
.sb-collapsed .sb-uact { flex-direction: column; }
@media (max-width: 1000px) { .sb-collapsed .sb-uinfo { display: block; } .sb-collapsed .sb-user { flex-direction: row; padding: 12px 12px 12px 16px; } .sb-collapsed .sb-uact { flex-direction: row; } }

/* ---------- Ventanas modales ---------- */
.modal-back { position: fixed; inset: 0; z-index: 100; background: rgba(20, 30, 35, .45); display: grid; place-items: center; padding: 16px; }
.modal { width: min(460px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 8px; box-shadow: 0 20px 50px rgba(20, 35, 40, .25); }

/* ---------- Interruptor ---------- */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; user-select: none; }
.switch input { appearance: none; -webkit-appearance: none; width: 34px; height: 20px; border-radius: 999px; background: #c9d1d4; position: relative; margin: 0; cursor: pointer; transition: background .15s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: left .15s; }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { left: 16px; }
.switch input:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
textarea.input { min-height: 72px; resize: vertical; font-family: inherit; line-height: 1.45; }
