/* Traza · tokens y componentes compartidos */
:root {
  --ink-950: #070C17;
  --ink-900: #0B1220;
  --ink-800: #121B2E;
  --ink-700: #1C2840;
  --ink-600: #2A3854;
  --ink-400: #6B7891;
  --ink-300: #98A3B8;
  --bg: #F3F4F6;
  --surface: #FFFFFF;
  --surface-2: #F8F9FB;
  --border: #E2E5EA;
  --border-strong: #CDD2DA;
  --text: #0F172A;
  --text-2: #334155;
  --muted: #667085;
  --accent: #F26B1D;
  --accent-600: #D85A0F;
  --accent-50: #FFF3EB;
  --ok: #138A4B;
  --ok-50: #E8F6EE;
  --warn: #B7791F;
  --warn-50: #FDF5E3;
  --bad: #C8332B;
  --bad-50: #FCECEB;
  --info: #2563EB;
  --info-50: #EBF2FE;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 14px rgba(15, 23, 42, .06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, .18);
  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --stage-0: #E5E7EB;
  --stage-1: #93C5FD;
  --stage-2: #60A5FA;
  --stage-3: #3B82F6;
  --stage-4: #1D4ED8;
  --stage-5: #138A4B;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--text); background: var(--bg); font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
p { margin: 0; }
.mono { font-family: var(--mono); font-size: .93em; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.tiny { font-size: 11.5px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.ic { flex: none; display: block; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 500; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, box-shadow .12s;
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); border-color: #B8BFCA; }
.btn:focus-visible, .icon-btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-600); border-color: var(--accent-600); }
.btn-dark { background: var(--ink-900); border-color: var(--ink-900); color: #fff; }
.btn-dark:hover { background: var(--ink-700); border-color: var(--ink-700); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { filter: brightness(.94); background: var(--ok); }
.btn-bad { background: var(--surface); border-color: #E7B4B0; color: var(--bad); }
.btn-bad:hover { background: var(--bad-50); border-color: var(--bad); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: rgba(15, 23, 42, .05); border-color: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-lg { height: 44px; padding: 0 20px; font-size: 15px; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: rgba(15, 23, 42, .06); color: var(--text); }

/* Formularios */
label.field { display: grid; gap: 5px; }
label.field > span { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.input, select.input, textarea.input {
  width: 100%; height: 36px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); transition: border-color .12s, box-shadow .12s;
}
textarea.input { height: auto; padding: 9px 11px; resize: vertical; min-height: 80px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(242, 107, 29, .15); outline: none; }
select.input { padding-right: 30px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.4'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .span2 { grid-column: span 2; }
.switch { position: relative; display: inline-block; width: 34px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i { position: absolute; inset: 0; background: #CBD2DC; border-radius: 20px; transition: .15s; cursor: pointer; }
.switch i::before { content: ''; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::before { transform: translateX(14px); }
.switch input:disabled + i { opacity: .5; cursor: not-allowed; }

/* Insignias */
.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #EEF0F3; color: var(--text-2); }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.plain::before { display: none; }
.badge.ok { background: var(--ok-50); color: var(--ok); }
.badge.warn { background: var(--warn-50); color: var(--warn); }
.badge.bad { background: var(--bad-50); color: var(--bad); }
.badge.info { background: var(--info-50); color: var(--info); }
.badge.muted { background: #EEF0F3; color: var(--muted); }
.sys-chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.sys-chip i { width: 8px; height: 8px; border-radius: 2px; background: var(--c, #999); }
.avatar { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--ink-700); color: #fff; font-size: 11.5px; font-weight: 700; flex: none; letter-spacing: .02em; }

/* Avisos */
#toasts { position: fixed; z-index: 1000; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 9px; padding: 11px 16px; border-radius: 10px; background: var(--ink-900); color: #fff; box-shadow: var(--shadow-lg); font-weight: 500; opacity: 0; transform: translateY(8px); transition: .22s; max-width: 90vw; }
.toast.in { opacity: 1; transform: none; }
.toast-ok .ic { color: #4ADE80; }
.toast-bad { background: #7F1D1D; }

/* Modal */
.modal-wrap { position: fixed; inset: 0; z-index: 900; background: rgba(7, 12, 23, .5); display: grid; place-items: center; padding: 24px; opacity: 0; transition: opacity .18s; }
.modal-wrap.in { opacity: 1; }
.modal { width: min(520px, 100%); max-height: calc(100vh - 48px); display: flex; flex-direction: column; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); transform: translateY(8px) scale(.99); transition: transform .18s; }
.modal-wrap.in .modal { transform: none; }
.modal-wide { width: min(880px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 10px; }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 6px 20px 18px; overflow: auto; display: grid; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 14px 14px; }

/* Etapas de punto */
.stages { display: inline-flex; gap: 3px; }
.stages i { width: 16px; height: 8px; border-radius: 2px; background: var(--stage-0); }
.stages i.on { background: var(--stage-4); }
.stages i.on.last { background: var(--stage-5); }
.stages i.fail { background: var(--bad); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); display: grid; gap: 8px; justify-items: center; }
.empty .ic { color: var(--border-strong); }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: 60px; }

/* Barras de progreso */
.bar { display: block; height: 8px; border-radius: 4px; background: #EEF0F3; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.ok > i { background: var(--ok); }
.bar.blue > i { background: var(--stage-4); }
