/* ============================================================
   Diagnóstico PX/EX — interfaz de trabajo profesional
   Tokens: tinta azul petróleo sobre blanco frío; el estado de
   cada fase es el único acento de color fuerte (y siempre va
   acompañado de símbolo y texto).
   ============================================================ */
:root {
  --ink: #0F4C82;
  --ink-soft: #0F4C82;
  --muted: #6B7A80;
  --paper: #F5F7F8;
  --surface: #FFFFFF;
  --line: #D8E0E3;
  --line-soft: #E8EDEF;
  --accent: #0F4C82;
  --accent-hover: #093b67;
  --accent-soft: #E4EFF0;

  --s-pending: #6B7780;   --s-pending-bg: #EEF1F2;
  --s-running: #0F4C82;   --s-running-bg: #E4EFF0;
  --s-review: #8A5A00;    --s-review-bg: #FBF1DC;
  --s-validated: #2A6F46; --s-validated-bg: #E3F1E8;
  --s-outdated: #A3400B;  --s-outdated-bg: #FCE9DD;
  --s-error: #A61F17;     --s-error-bg: #FBE4E2;

  --font-ui: "Source Sans 3", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --font-read: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bs-body-font-family: var(--font-ui);
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--paper);
  --bs-link-color: var(--accent);
  --bs-link-hover-color: var(--accent-hover);
  --bs-link-color-rgb: #0F4C82;
  --bs-border-color: var(--line);
  --bs-primary: var(--accent);
  --bs-primary-rgb: 29, 92, 99;
}

html { font-size: 16px; }
body { font-family: var(--font-ui); color: var(--ink); background: var(--paper); line-height: 1.5; }
h1, h2, h3, h4, h5, h6 { color: var(--ink); font-weight: 600; letter-spacing: -0.005em; }
h1 { font-size: 1.6rem; margin-bottom: .25rem; }
code { color: var(--ink-soft); font-size: .88em; }
:focus-visible { outline: 3px solid #5B9AA2; outline-offset: 2px; }
.skip:focus { position: absolute; top: .5rem; left: .5rem; z-index: 2000; background: var(--surface); padding: .5rem 1rem; }

/* Botones Bootstrap con el acento del proyecto */
.btn-primary { --bs-btn-bg: var(--accent); --bs-btn-border-color: var(--accent); --bs-btn-hover-bg: var(--accent-hover); --bs-btn-hover-border-color: var(--accent-hover); --bs-btn-active-bg: var(--accent-hover); --bs-btn-disabled-bg: #7FA3A7; --bs-btn-disabled-border-color: #7FA3A7; }
.btn-outline-primary { --bs-btn-color: var(--accent); --bs-btn-border-color: var(--accent); --bs-btn-hover-bg: var(--accent); --bs-btn-hover-border-color: var(--accent); --bs-btn-active-bg: var(--accent-hover); }
.btn-success { --bs-btn-bg: var(--s-validated); --bs-btn-border-color: var(--s-validated); --bs-btn-hover-bg: #1F5836; --bs-btn-hover-border-color: #1F5836; }
.link-quiet { color: var(--muted); text-decoration: none; }
.link-quiet:hover { color: var(--ink); text-decoration: underline; }
.form-control, .form-select { border-color: var(--line); }
.form-control:focus, .form-select:focus { border-color: var(--accent); box-shadow: 0 0 0 .2rem rgba(29, 92, 99, .18); }

/* ---------- Barra superior ---------- */
.topbar { background: var(--ink); color: #fff; }
.topbar-inner { max-width: 1440px; margin: 0 auto; padding: .55rem 1.5rem; display: flex; align-items: center; gap: 2rem; }
.brand { color: #fff; font-weight: 600; text-decoration: none; font-size: 1.02rem; }
.brand:hover { color: #fff; }
.topnav { display: flex; gap: .25rem; flex: 1; }
.topnav-link { color: #C9D8DC; background: none; border: 0; padding: .35rem .7rem; border-radius: 4px; text-decoration: none; font-size: .95rem; }
.topnav-link:hover, .topnav-link.active { color: #fff; background: rgba(255, 255, 255, .1); }
.topbar-user { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: #C9D8DC; }
.topbar-user .link-quiet { color: #C9D8DC; }
.topbar-user .link-quiet:hover { color: #fff; }

.page { max-width: 1440px; margin: 0 auto; padding: 1.5rem 1.5rem 4rem; }

/* ---------- Encabezados de página ---------- */
.page-head, .panel-head, .phase-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1.5rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-actions, .panel-actions, .action-bar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.panel-actions { margin: 1.25rem 0 1.5rem; }
.crumbs { font-size: .9rem; color: var(--muted); margin-bottom: .35rem; display: flex; gap: .4rem; flex-wrap: wrap; }
.crumbs a { color: var(--muted); }
.subnav { display: flex; gap: 1.25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.5rem; overflow-x: auto; }
.subnav a { padding: .5rem 0; color: var(--ink-soft); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
.subnav a:hover { color: var(--ink); }
.subnav a.active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

.section { margin-bottom: 2.25rem; }
.section-title { font-size: 1.05rem; font-weight: 600; margin-bottom: .75rem; color: var(--ink); }
.empty { color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: 6px; padding: 1.25rem; margin: 0; }
.form-narrow { max-width: 760px; }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: .25rem 0; }
.pre-line { white-space: pre-line; }
.row-muted td { color: var(--muted); }
.row-op td { background: #FAFBFB; }
.check-columns { columns: 2 280px; }

/* ---------- Tablas ---------- */
.table-quiet { --bs-table-bg: var(--surface); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.table-quiet thead th { font-size: .85rem; font-weight: 600; color: var(--ink-soft); background: #F0F4F5; border-bottom-color: var(--line); }
.table-quiet td { border-color: var(--line-soft); }

/* ---------- Estados (símbolo + texto; el color refuerza, no informa solo) ---------- */
.st { display: inline-flex; align-items: center; gap: .3rem; font-size: .84rem; font-weight: 600; padding: .12rem .5rem; border-radius: 999px; line-height: 1.4; white-space: nowrap; }
.st-sym { font-weight: 700; }
.st-pending { color: var(--s-pending); background: var(--s-pending-bg); }
.st-running { color: var(--s-running); background: var(--s-running-bg); }
.st-review { color: var(--s-review); background: var(--s-review-bg); }
.st-validated { color: var(--s-validated); background: var(--s-validated-bg); }
.st-outdated { color: var(--s-outdated); background: var(--s-outdated-bg); }
.st-error { color: var(--s-error); background: var(--s-error-bg); }
.code-tag { font-family: var(--font-mono); font-size: .8rem; font-weight: 600; color: var(--ink-soft); background: #EDF2F3; border-radius: 3px; padding: .05rem .35rem; }
.code-tag.muted { color: var(--muted); }

/* ---------- Avisos ---------- */
.callout { border-left: 4px solid var(--line); background: var(--surface); padding: .75rem 1rem; border-radius: 0 6px 6px 0; margin-bottom: 1rem; }
.callout-info { border-left-color: var(--s-running); background: var(--s-running-bg); }
.callout-warning { border-left-color: var(--s-review); background: var(--s-review-bg); }
.callout-danger { border-left-color: var(--s-error); background: var(--s-error-bg); }
.callout-plain { border-left-color: var(--line); }
.notice-foot { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.blockers { list-style: none; padding: .6rem .9rem; margin: .5rem 0 1rem; background: var(--s-pending-bg); border-radius: 6px; font-size: .9rem; color: var(--ink-soft); }
.blockers li::before { content: "— "; color: var(--muted); }

/* ---------- Panel del diagnóstico ---------- */
.panel-client { color: var(--muted); margin: 0; font-size: .95rem; }
.panel-head h1 { font-size: 1.8rem; }
.panel-progress { min-width: 220px; text-align: right; }
.panel-progress-num { display: block; font-size: 2rem; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.panel-progress-label { color: var(--muted); font-size: .9rem; }
.progress-native { display: block; width: 100%; height: 6px; margin-top: .5rem; border: 0; border-radius: 3px; background: var(--line-soft); overflow: hidden; appearance: none; -webkit-appearance: none; }
.progress-native::-webkit-progress-bar { background: var(--line-soft); border-radius: 3px; }
.progress-native::-webkit-progress-value { background: var(--s-validated); border-radius: 3px; }
.progress-native::-moz-progress-bar { background: var(--s-validated); border-radius: 3px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; margin-bottom: 1rem; }
.fact { background: var(--surface); padding: .9rem 1.1rem; }
.fact-num { display: block; font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.fact-num.fact-text { font-size: 1.05rem; }
.fact-label { color: var(--muted); font-size: .88rem; }
.dl-grid { display: grid; grid-template-columns: minmax(160px, 260px) 1fr; gap: .4rem 1.25rem; margin-bottom: 1.5rem; }
.dl-grid dt { font-weight: 600; color: var(--ink-soft); }
.dl-grid dd { margin: 0; }

/* ---------- Fase: stepper + contenido ---------- */
.phase-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 2rem; align-items: start; }
.phase-aside { position: sticky; top: 1rem; }
.stepper ol { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--line); }
.step a { display: grid; grid-template-columns: 1.4rem 2.4rem 1fr; align-items: baseline; gap: .15rem; padding: .42rem .6rem .42rem .75rem; margin-left: -2px; border-left: 2px solid transparent; color: var(--ink-soft); text-decoration: none; font-size: .93rem; }
.step a:hover { background: var(--surface); color: var(--ink); }
.step.current a { border-left-color: var(--accent); background: var(--surface); color: var(--ink); font-weight: 600; }
.step-mark { font-weight: 700; text-align: center; }
.step-code { font-family: var(--font-mono); font-size: .78rem; color: var(--muted); }
.step-op a { font-size: .86rem; padding-left: 1.4rem; }
.step-validated .step-mark { color: var(--s-validated); }
.step-review .step-mark { color: var(--s-review); }
.step-outdated .step-mark { color: var(--s-outdated); }
.step-error .step-mark { color: var(--s-error); }
.step-running .step-mark { color: var(--s-running); }
.step-pending .step-mark { color: var(--s-pending); }
.stepper-legend { font-size: .78rem; color: var(--muted); margin: .75rem 0 0 .75rem; }

.phase-code { color: var(--muted); margin: 0; font-size: .95rem; }
.phase-head h1 { font-size: 1.7rem; }
.context-grid, .export-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.context-card { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: .9rem 1rem; }
.context-title { font-size: .92rem; font-weight: 600; color: var(--ink-soft); margin-bottom: .4rem; }
.inline-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 1rem; margin: .75rem 0 1rem; max-width: 760px; }

.result { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 1.25rem 1.5rem 1.5rem; }
.result-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.result .nav-tabs { margin-bottom: 1rem; }
.result .nav-link { color: var(--ink-soft); }
.result .nav-link.active { color: var(--ink); font-weight: 600; }

/* Texto largo de lectura: serif, medida contenida */
.reading { font-family: var(--font-read); font-size: 1.04rem; line-height: 1.65; max-width: 78ch; color: #1C2B30; }
.reading h1, .reading h2, .reading h3, .reading h4 { font-family: var(--font-ui); margin-top: 1.6em; margin-bottom: .5em; }
.reading h1 { font-size: 1.4rem; } .reading h2 { font-size: 1.22rem; } .reading h3 { font-size: 1.08rem; }
.reading table { font-family: var(--font-ui); font-size: .92rem; border-collapse: collapse; width: 100%; margin: 1rem 0; display: block; overflow-x: auto; }
.reading th, .reading td { border: 1px solid var(--line); padding: .4rem .6rem; vertical-align: top; }
.reading th { background: #F0F4F5; }
.reading blockquote { border-left: 3px solid var(--line); padding-left: 1rem; color: var(--ink-soft); }
.reading.document { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 2rem 2.5rem; max-width: 90ch; }
.src-ref { font-family: var(--font-mono); font-size: .76rem; font-weight: 600; color: var(--accent); background: var(--accent-soft); border: 0; border-radius: 3px; padding: .02rem .3rem; margin: 0 .05rem; cursor: pointer; vertical-align: baseline; }
.src-ref:hover { background: #CFE2E4; }
.src-purged { font-family: var(--font-mono); font-size: .76rem; color: var(--s-error); background: var(--s-error-bg); border-radius: 3px; padding: .02rem .3rem; }
.chunk-list { line-height: 2; }

.editor { font-family: var(--font-mono); font-size: .88rem; line-height: 1.55; min-height: 24rem; }
.editor-json { font-family: var(--font-mono); font-size: .84rem; }
.json-view, .prompt-view { font-family: var(--font-mono); font-size: .8rem; background: #F3F6F7; border: 1px solid var(--line-soft); border-radius: 6px; padding: .9rem; max-height: 32rem; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.log-tail { max-height: 24rem; }
.log-detail { max-width: 28rem; word-break: break-word; }
details > summary { cursor: pointer; color: var(--ink-soft); font-weight: 600; }
.chunk-body { font-family: var(--font-read); white-space: pre-wrap; line-height: 1.6; }

.purge-box { max-width: 900px; }
.lead-sm { font-size: 1.05rem; }
.timeline { list-style: none; padding: 0; border-left: 2px solid var(--line); }
.timeline li { padding: .4rem 0 .6rem 1rem; }
.prompt-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 2rem; }

/* ---------- Mínimo (login / error) ---------- */
body.minimal { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.minimal-main { width: 100%; max-width: 420px; padding: 1.5rem; }
.brand-lg { color: var(--ink); font-size: 1.25rem; font-weight: 600; margin-bottom: 1.25rem; }
.card-plain { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 1.75rem; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
  .phase-layout, .prompt-layout { grid-template-columns: 1fr; }
  .phase-aside { position: static; }
  .stepper ol { display: flex; overflow-x: auto; border-left: 0; border-bottom: 2px solid var(--line); }
  .step a { display: flex; gap: .3rem; border-left: 0; border-bottom: 2px solid transparent; margin: 0 0 -2px; white-space: nowrap; padding: .45rem .6rem; }
  .step.current a { border-bottom-color: var(--accent); }
  .step-op a { padding-left: .6rem; }
  .stepper-legend { display: none; }
  .panel-progress { text-align: left; }
  .dl-grid { grid-template-columns: 1fr; }
  .topbar-inner { flex-wrap: wrap; gap: .75rem; }
  .reading.document { padding: 1.25rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

.login-brand { text-align: center; margin-bottom: 1.25rem; }
.login-logo { display: block; max-width: 315px; max-height: 115px; margin: 0 auto .75rem; }
.login-brand .brand-lg { margin-bottom: 0; }