/* =========================================================
   ErrorProtect — sistema visual (dark por defecto)
   ========================================================= */

:root, :root[data-theme="dark"] {
  --bg: #0a0a1a;
  --sidebar: #0d0d2b;
  --card: #1a1a3e;
  --input: #12122e;
  --border: #2a2a5e;
  --text: #ffffff;
  --muted: #8888aa;
  --primary: #6c5ce7;
  --primary-h: #7c6cf7;
  --green: #00b894;
  --orange: #fdcb6e;
  --red: #ff6b6b;
  --cyan: #00cec9;
  --blue: #74b9ff;
  --grey: #555;
  --row-alt: rgba(255, 255, 255, 0.02);
  --hover: rgba(108, 92, 231, 0.1);
  --skeleton: #22224a;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --on-accent: #ffffff;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f3f3fa;
  --sidebar: #ffffff;
  --card: #ffffff;
  --input: #f7f7fd;
  --border: #dcdcf0;
  --text: #1a1a3e;
  --muted: #6b6b8f;
  --primary: #6c5ce7;
  --primary-h: #5a4bd4;
  --green: #00a383;
  --orange: #c98f00;
  --red: #e5484d;
  --cyan: #00a5a1;
  --blue: #2f80d1;
  --grey: #8a8aa0;
  --row-alt: rgba(26, 26, 62, 0.025);
  --hover: rgba(108, 92, 231, 0.08);
  --skeleton: #e8e8f4;
  --shadow: 0 8px 30px rgba(26, 26, 62, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary-h); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.mono { font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace; font-size: .85em; }
.label, label {
  display: block; font-size: .72rem; font-weight: 500; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin-bottom: 8px;
}
.ic { width: 18px; height: 18px; flex: none; }
.ic-lg { width: 22px; height: 22px; }
.ic-xl { width: 56px; height: 56px; }

/* ---------- Layout ---------- */
.app { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 260px; background: var(--sidebar);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 20px 14px; z-index: 40;
  transition: transform .25s ease;
}
.main { margin-left: 260px; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px;
  padding: 14px 32px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); min-height: 56px;
}
.main { overflow-x: clip; }
.view { padding: 28px 32px 48px; max-width: 1400px; width: 100%; position: relative; }
/* Se anima "top" (no transform) para no crear un containing block que rompa los position:fixed internos (drawer) */
.view.enter { animation: viewIn .32s ease both; }
@keyframes viewIn { from { opacity: 0; top: 10px; } to { opacity: 1; top: 0; } }

/* ---------- Sidebar ---------- */
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; color: var(--text); }
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #a29bfe); color: #fff;
}
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em; }
.brand-sub { display: block; font-size: .7rem; color: var(--muted); font-weight: 500; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 8px;
  color: var(--muted); font-weight: 500; cursor: pointer; border: none; background: none; font: inherit;
  border-left: 3px solid transparent; width: 100%; text-align: left; transition: background .15s, color .15s;
}
.nav-item:hover { color: var(--text); background: var(--hover); }
.nav-item.active { background: rgba(108, 92, 231, .2); color: var(--text); border-left-color: var(--primary); }
.nav-sep { height: 1px; background: var(--border); margin: 14px 6px; }
.nav-bottom { margin-top: auto; }
.version { display: flex; align-items: center; gap: 12px; padding: 10px 14px; color: var(--muted); font-size: .8rem; }

/* ---------- Topbar ---------- */
.icon-btn.hamburger { display: none; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-size: .85rem; color: var(--muted); min-width: 0; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { opacity: .5; }
.crumbs .current { color: var(--text); font-weight: 500; }
.save-ind { margin-left: auto; font-size: .8rem; font-weight: 500; color: var(--muted); opacity: 0; transition: opacity .3s; white-space: nowrap; }
.save-ind.show { opacity: 1; }
.save-ind.ok { color: var(--green); }
.save-ind.err { color: var(--red); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 24px;
  border-radius: 8px; border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--primary); color: #fff; transition: background .15s, border-color .15s, transform .1s, opacity .15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--primary-h); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-secondary { background: transparent; border-color: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: var(--hover); border-color: var(--primary); }
.btn-outline { background: transparent; border-color: var(--primary); color: var(--primary-h); }
.btn-outline:hover:not(:disabled) { background: rgba(108, 92, 231, .15); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: color-mix(in srgb, var(--red) 85%, #fff); }
.btn-sm { padding: 7px 14px; font-size: .85rem; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.danger:hover { background: rgba(255, 107, 107, .15); color: var(--red); }
.link-btn { background: none; border: none; color: var(--primary-h); font: inherit; font-size: .82rem; font-weight: 500; cursor: pointer; padding: 4px 0; display: inline-flex; align-items: center; gap: 6px; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Forms ---------- */
input[type=text], input[type=search], textarea, select {
  width: 100%; padding: 10px 14px; background: var(--input); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font: inherit; transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(108, 92, 231, .2); }
textarea { resize: vertical; }
textarea.code { font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace; font-size: .8rem; line-height: 1.6; }
select { cursor: pointer; }
.field { margin-bottom: 18px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.invalid, .invalid:focus { border-color: var(--red) !important; box-shadow: 0 0 0 3px rgba(255, 107, 107, .15) !important; }
.field-error { color: var(--red); font-size: .78rem; margin-top: 6px; }
.req { color: var(--red); }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { margin: 6px 0 0; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.search { position: relative; }
.search input { padding-left: 38px; width: 240px; }
.search .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; }

/* ---------- Panels ---------- */
.panel { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 24px; margin-bottom: 20px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.panel-head h2 { display: flex; align-items: center; gap: 10px; }
.count { font-size: .75rem; font-weight: 600; color: var(--muted); background: var(--input); border: 1px solid var(--border); padding: 1px 9px; border-radius: 999px; }

/* ---------- Evaluation cards ---------- */
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.ecard {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 20px;
  display: flex; flex-direction: column; gap: 10px; cursor: pointer; min-height: 196px;
  transition: border-color .2s, transform .2s, box-shadow .2s;
}
.ecard:hover { border-color: var(--primary); transform: scale(1.02); box-shadow: var(--shadow); }
.ecard-badges { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.ecard h3 { font-size: 1.05rem; font-weight: 700; margin-top: 4px; overflow-wrap: anywhere; }
.ecard-desc { color: var(--muted); font-size: .85rem; flex: 1; }
.ecard-meta { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ecard-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
.ecard-foot small { color: var(--muted); font-size: .78rem; }
.ecard-foot .actions { display: flex; align-items: center; gap: 4px; }

/* Skeletons */
.skeleton { background: var(--skeleton); border-radius: 6px; position: relative; overflow: hidden; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .06), transparent);
  animation: shimmer 1.3s infinite; transform: translateX(-100%);
}
:root[data-theme="light"] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .7), transparent); }
@keyframes shimmer { to { transform: translateX(100%); } }
.sk-card { cursor: default; }
.sk-card:hover { transform: none; border-color: var(--border); box-shadow: none; }

/* Empty state */
.empty-state { text-align: center; padding: 64px 20px; background: var(--card); border: 1px dashed var(--border); border-radius: 16px; }
.empty-illu {
  width: 110px; height: 110px; margin: 0 auto 20px; border-radius: 50%; display: grid; place-items: center;
  background: radial-gradient(circle, rgba(108, 92, 231, .25), rgba(108, 92, 231, .05) 70%); color: var(--primary-h);
}
.empty-state h2 { font-size: 1.25rem; margin-bottom: 6px; }
.empty-state p { color: var(--muted); max-width: 420px; margin: 0 auto 20px; }
.empty-inline { text-align: center; color: var(--muted); padding: 28px 12px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px;
  font-size: .72rem; font-weight: 600; white-space: nowrap; border: 1px solid transparent; line-height: 1.5;
  background: color-mix(in srgb, var(--muted) 15%, transparent); color: var(--muted);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-outline { background: transparent; border-color: var(--primary); color: var(--primary-h); }
.b-green { background: rgba(0, 184, 148, .15); color: var(--green); }
.b-purple { background: rgba(108, 92, 231, .15); color: var(--primary-h); }
.b-orange { background: rgba(253, 203, 110, .15); color: var(--orange); }
.b-red { background: rgba(255, 107, 107, .15); color: var(--red); }
.b-cyan { background: rgba(0, 206, 201, .15); color: var(--cyan); }
.b-blue { background: rgba(116, 185, 255, .15); color: var(--blue); }
.b-grey { background: color-mix(in srgb, var(--grey) 25%, transparent); color: var(--muted); }
/* Mecanismo SRK */
.badge-skill { background: rgba(0, 184, 148, .15); color: var(--green); }
.badge-rule { background: rgba(253, 203, 110, .15); color: var(--orange); }
.badge-knowledge { background: rgba(108, 92, 231, .15); color: var(--primary-h); }
.gen-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.gen-warnings { margin: 8px 0 0; padding-left: 18px; font-size: .82rem; }
.gen-warnings li { margin: 2px 0; }
.badge-code {font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace; font-size: .75rem; cursor: help; }
.badge-lg { font-size: .95rem; padding: 6px 16px; }

/* ---------- Stepper ---------- */
.eval-head { margin-bottom: 20px; }
.eval-head .meta { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: .85rem; margin-top: 8px; }
.eval-head .meta span { display: inline-flex; align-items: center; gap: 6px; }
.eval-head .meta .ic { width: 15px; height: 15px; }
.stepper { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 24px; }
.step {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--muted); font-weight: 500; font-size: .88rem; transition: border-color .15s, background .15s;
}
.step:hover { border-color: var(--primary); color: var(--text); }
.step .n { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .78rem; font-weight: 700; background: var(--input); border: 1px solid var(--border); flex: none; }
.step.done .n { background: rgba(0, 184, 148, .15); border-color: transparent; color: var(--green); }
.step.active { border-color: var(--primary); background: rgba(108, 92, 231, .15); color: var(--text); }
.step.active .n { background: var(--primary); border-color: var(--primary); color: #fff; }
.step.disabled { opacity: .4; pointer-events: none; }

/* ---------- Notices ---------- */
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 10px; margin-bottom: 20px; border: 1px solid; font-size: .88rem; }
.notice .ic { margin-top: 1px; }
.notice-warn { background: rgba(253, 203, 110, .08); border-color: rgba(253, 203, 110, .35); color: var(--orange); }
.notice-info { background: rgba(108, 92, 231, .08); border-color: rgba(108, 92, 231, .35); color: var(--text); }
.notice-info .ic { color: var(--primary-h); }
.notice a { font-weight: 600; }

/* ---------- Upload ---------- */
.dropzone {
  border: 2px dashed var(--border); border-radius: 12px; background: var(--input); padding: 44px 20px;
  text-align: center; cursor: pointer; transition: border-color .2s, background .2s;
}
.dropzone:hover, .dropzone.over, .dropzone:focus-visible { border-color: var(--primary); background: rgba(108, 92, 231, .05); outline: none; }
.dropzone .ic-xl { color: var(--primary-h); margin-bottom: 12px; }
.dropzone strong { display: block; font-size: 1rem; font-weight: 600; margin-bottom: 4px; }
.dropzone .sub { color: var(--muted); font-size: .85rem; }
.file-chip {
  display: inline-flex; align-items: center; gap: 10px; margin-top: 18px; padding: 8px 10px 8px 14px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--primary); color: var(--text); font-weight: 500; cursor: default;
}
.file-chip .ic { color: var(--primary-h); }
.file-chip small { color: var(--muted); }
.gen-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--input); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
th {
  background: var(--card); color: var(--muted); font-size: .7rem; font-weight: 500; text-transform: uppercase;
  letter-spacing: .05em; white-space: nowrap; position: sticky; top: 0;
}
tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr:hover { background: var(--hover); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }
td.mono { white-space: nowrap; }
td.center, th.center { text-align: center; }
td.actions-cell { white-space: nowrap; width: 1%; text-align: right; }
td.wrap { min-width: 220px; }
.yes { color: var(--green); font-weight: 600; }
.no { color: var(--red); font-weight: 600; }
.na { color: var(--muted); }
.table-filter { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: .85rem; cursor: pointer; text-transform: none; letter-spacing: 0; margin: 0; font-weight: 500; }
.table-filter input { accent-color: var(--primary); width: 16px; height: 16px; }

/* ---------- Fase B ---------- */
.fb-top { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.fb-top .grow { flex: 1; min-width: 220px; }
.fb-top .pos { font-weight: 600; font-size: 1rem; }
.fb-top .pos small { color: var(--muted); font-weight: 500; margin-left: 8px; }
.progress { height: 8px; background: var(--input); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: linear-gradient(90deg, var(--primary), #a29bfe); border-radius: 999px; transition: width .35s ease; }
.fb-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.fb-card { max-width: 860px; width: 100%; justify-self: center; }
.fb-card.panel { padding: 28px; }
.fb-card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.fb-card-head h2 { font-size: 1.25rem; }
.fb-card-head .grow { flex: 1; }
.fb-card { position: relative; }
.fb-anim { animation: viewIn .25s ease both; }
.err-detail { display: grid; gap: 14px; padding: 18px; background: var(--input); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; }
.err-detail .label { margin-bottom: 4px; }
.err-detail .val { font-size: .93rem; }
.err-detail .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.q { padding: 18px 0; border-bottom: 1px solid var(--border); transition: opacity .2s; }
.q:last-of-type { border-bottom: none; }
.q.dep-off { opacity: .45; }
.q-head { display: flex; align-items: center; gap: 14px; justify-content: space-between; flex-wrap: wrap; }
.q-title { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: .95rem; }
.q-num {
  font-family: 'JetBrains Mono', monospace; font-weight: 600; font-size: .78rem; padding: 3px 8px; border-radius: 6px;
  background: rgba(108, 92, 231, .15); color: var(--primary-h); flex: none;
}
.q-info { color: var(--muted); cursor: help; display: inline-flex; }
.q-info .ic { width: 16px; height: 16px; }
.q-note { color: var(--muted); font-size: .8rem; margin: 6px 0 0 44px; }
.q-comment { margin: 8px 0 0 44px; }
.q-comment textarea { font-size: .85rem; min-height: 40px; }

.seg { display: inline-flex; gap: 6px; }
.seg button {
  min-width: 64px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--input);
  color: var(--muted); font: inherit; font-weight: 600; font-size: .85rem; cursor: pointer; transition: all .15s;
}
.seg button:hover:not(:disabled) { border-color: var(--primary); color: var(--text); }
.seg button:disabled { cursor: not-allowed; }
.seg button.on { color: #fff; border-color: transparent; }
.seg button.on.v-true { background: var(--green); }
.seg button.on.v-false { background: var(--red); }
.seg button.on.v-null { background: var(--grey); }
.seg button.on.v-Baja { background: var(--green); }
.seg button.on.v-Media { background: var(--orange); color: #1a1a3e; }
.seg button.on.v-Alta { background: var(--red); }

.crit-box { margin-top: 18px; padding: 20px; border-radius: 10px; border: 1px solid rgba(255, 107, 107, .4); background: rgba(255, 107, 107, .06); }
.crit-box h3 { display: flex; align-items: center; gap: 8px; color: var(--red); margin-bottom: 6px; }
.crit-grid { display: flex; gap: 28px; flex-wrap: wrap; align-items: flex-end; margin-top: 14px; }
.crit-result .badge { font-size: 1.05rem; padding: 8px 22px; }

.fb-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.kbd-hint { color: var(--muted); font-size: .78rem; }
kbd { font-family: 'JetBrains Mono', monospace; font-size: .72rem; padding: 2px 6px; border-radius: 4px; border: 1px solid var(--border); background: var(--input); }

.drawer { position: sticky; top: 76px; max-height: calc(100vh - 96px); display: flex; flex-direction: column; padding: 16px; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.drawer-list { overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.drawer-close { display: none; }
.err-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: .84rem;
  border: 1px solid transparent; color: var(--text);
}
.err-item:hover { background: var(--hover); }
.err-item.active { background: rgba(108, 92, 231, .2); border-color: var(--primary); }
.err-item .st { width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--border); display: grid; place-items: center; flex: none; }
.err-item .st.partial { border-color: var(--orange); background: rgba(253, 203, 110, .15); }
.err-item .st.done { background: var(--green); border-color: var(--green); color: #fff; }
.err-item .st .ic { width: 12px; height: 12px; stroke-width: 3; }
.err-item .txt { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.err-item.active .txt { color: var(--text); }
.err-item .flag { width: 7px; height: 7px; border-radius: 50%; background: var(--red); flex: none; }

/* ---------- Results ---------- */
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
.metric { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 22px; display: flex; gap: 18px; align-items: center; }
.metric .ring { position: relative; width: 120px; height: 120px; flex: none; }
.metric .ring svg { width: 120px; height: 120px; transform: rotate(-90deg); }
.metric .ring .track { stroke: var(--input); }
.metric .ring .bar { stroke: var(--primary); transition: stroke-dashoffset 1s ease; }
.metric .ring .val { position: absolute; inset: 0; display: grid; place-items: center; font-size: 1.5rem; font-weight: 700; }
.metric .ring .val.na { font-size: .82rem; color: var(--muted); text-align: center; line-height: 1.2; }
.metric .code { font-weight: 700; color: var(--primary-h); font-size: 1rem; }
.metric .name { color: var(--muted); font-size: .82rem; margin: 2px 0 10px; }
.metric .formula { font-family: 'JetBrains Mono', monospace; font-size: .82rem; }
.metric .formula small { display: block; color: var(--muted); font-family: 'Inter', sans-serif; margin-top: 2px; }

.summary-row { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; margin-bottom: 20px; }
.summary { display: flex; flex-direction: column; justify-content: center; gap: 22px; }
.summary-main { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.nivel-badge { font-size: 2.1rem; font-weight: 800; padding: 16px 34px; border-radius: 16px; letter-spacing: -.01em; }
.nivel-badge.b-red { box-shadow: 0 0 40px rgba(255, 107, 107, .2); }
.nivel-badge.b-orange { box-shadow: 0 0 40px rgba(253, 203, 110, .2); }
.nivel-badge.b-cyan { box-shadow: 0 0 40px rgba(0, 206, 201, .2); }
.nivel-badge.b-green { box-shadow: 0 0 40px rgba(0, 184, 148, .2); }
.prom-val { font-size: 2.6rem; font-weight: 800; line-height: 1; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 10px; }
.stat { background: var(--input); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.stat b { display: block; font-size: 1.35rem; }
.stat span { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 500; }

.cmatrix { display: grid; grid-template-columns: 64px repeat(3, 1fr); gap: 6px; }
.cmatrix .hd { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 500; display: grid; place-items: center; padding: 4px; text-align: center; }
.cmatrix .cell {
  aspect-ratio: 1.5; border-radius: 10px; display: grid; place-items: center; font-size: 1.6rem; font-weight: 800;
  border: 1px solid transparent; position: relative;
}
.cmatrix .cell small { position: absolute; bottom: 6px; font-size: .62rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; opacity: .8; }
.cmatrix .cell.c-Baja { background: rgba(0, 184, 148, .15); color: var(--green); border-color: rgba(0, 184, 148, .3); }
.cmatrix .cell.c-Media { background: rgba(253, 203, 110, .15); color: var(--orange); border-color: rgba(253, 203, 110, .3); }
.cmatrix .cell.c-Alta { background: rgba(255, 107, 107, .15); color: var(--red); border-color: rgba(255, 107, 107, .3); }
.cmatrix .cell.zero { opacity: .45; }
.cmatrix-axis { font-size: .72rem; color: var(--muted); margin-top: 10px; text-align: center; }

.chain { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.chain .arrow { color: var(--muted); font-size: .8rem; }
.result-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.footnote { color: var(--muted); font-size: .78rem; margin-top: 8px; }
.comment-line { display: block; color: var(--muted); font-size: .78rem; margin-top: 4px; }

/* ---------- Metrics page ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
.kpi { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.kpi .label { margin-bottom: 6px; }
.kpi b { font-size: 2rem; font-weight: 800; }
.hbars { display: grid; gap: 14px; }
.hbar-row { display: grid; grid-template-columns: 90px 1fr 36px; gap: 12px; align-items: center; font-size: .88rem; }
.hbar { height: 10px; background: var(--input); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.hbar > div { height: 100%; border-radius: 999px; transition: width .6s ease; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 20px;
  background: rgba(0, 0, 0, .6); backdrop-filter: blur(6px); opacity: 0; transition: opacity .2s;
}
.modal-backdrop.show { opacity: 1; }
.modal {
  width: 100%; max-width: 520px; max-height: calc(100vh - 40px); overflow-y: auto;
  background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  transform: translateY(12px) scale(.98); transition: transform .2s;
}
.modal.lg { max-width: 720px; }
.modal-backdrop.show .modal { transform: none; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.modal-head h2 { font-size: 1.25rem; }
.modal-head p { margin: 6px 0 0; color: var(--muted); font-size: .88rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 26px; }
.modal-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; margin-bottom: 14px; }
.modal-icon.danger { background: rgba(255, 107, 107, .15); color: var(--red); }
.cfg-section { padding: 18px; background: var(--input); border: 1px solid var(--border); border-radius: 10px; margin-bottom: 16px; }
.cfg-section h3 { margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.cfg-section p { color: var(--muted); font-size: .86rem; }
pre.snippet { margin: 10px 0 0; padding: 12px 14px; border-radius: 8px; background: var(--bg); border: 1px solid var(--border); overflow-x: auto; font-family: 'JetBrains Mono', monospace; font-size: .78rem; color: var(--text); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; top: 18px; right: 18px; z-index: 120; display: flex; flex-direction: column; gap: 10px; width: min(380px, calc(100vw - 36px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--primary); box-shadow: var(--shadow);
  animation: toastIn .25s ease both; font-size: .88rem;
}
.toast.out { animation: toastOut .25s ease both; }
.toast .ic { margin-top: 1px; }
.toast.ok { border-left-color: var(--green); } .toast.ok .ic { color: var(--green); }
.toast.err { border-left-color: var(--red); } .toast.err .ic { color: var(--red); }
.toast.info .ic { color: var(--primary-h); }
.toast .msg { flex: 1; overflow-wrap: anywhere; }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(30px); } }

/* ---------- Tooltip ---------- */
.tooltip {
  position: fixed; z-index: 130; max-width: 300px; padding: 8px 12px; border-radius: 8px; font-size: .78rem; line-height: 1.45;
  background: #2d2d66; color: #fff; border: 1px solid #3d3d80; box-shadow: 0 6px 24px rgba(0, 0, 0, .4);
  pointer-events: none; opacity: 0; transform: translateY(4px); transition: opacity .12s, transform .12s;
}
:root[data-theme="light"] .tooltip { background: #1a1a3e; border-color: #1a1a3e; }
.tooltip.show { opacity: 1; transform: none; }

/* ---------- Loading overlay ---------- */
.overlay { position: fixed; inset: 0; z-index: 110; display: grid; place-items: center; background: rgba(0, 0, 0, .6); backdrop-filter: blur(6px); }
.overlay-box { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 36px 40px; text-align: center; max-width: 420px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
.overlay-box p { font-weight: 600; font-size: 1.05rem; margin: 20px 0 6px; }
.overlay-box small { display: block; color: var(--muted); }
.loading-timer { margin-top: 10px; font-family: 'JetBrains Mono', monospace; }
.spinner {
  width: 54px; height: 54px; border-radius: 50%; margin: 0 auto;
  border: 4px solid rgba(108, 92, 231, .2); border-top-color: var(--primary); animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
.sidebar-backdrop { position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .5); opacity: 0; pointer-events: none; transition: opacity .2s; }
body.nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
body.drawer-open .sidebar-backdrop { opacity: 1; pointer-events: auto; z-index: 55; }
.drawer-toggle { display: none; }
@media (max-width: 1024px) { .drawer-toggle { display: inline-flex; } }

@media (max-width: 1200px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-row { grid-template-columns: 1fr; }
}
@media (max-width: 1024px) {
  .fb-layout { grid-template-columns: 1fr; }
  .drawer {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(320px, 85vw); max-height: none; z-index: 60; border-radius: 0;
    margin: 0; transform: translateX(105%); transition: transform .25s ease; box-shadow: var(--shadow);
  }
  body.drawer-open .drawer { transform: none; }
  .drawer-close { display: inline-grid; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: none; }
  .main { margin-left: 0; }
  .icon-btn.hamburger { display: inline-grid; }
  .topbar { padding: 12px 16px; }
  .view { padding: 20px 16px 40px; }
  .stepper { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .cards, .kpis { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .search input { width: 100%; }
  .toolbar, .search { width: 100%; }
  .metric { flex-direction: column; text-align: center; }
  .q-note, .q-comment { margin-left: 0; }
  .modal { padding: 24px; }
  .fb-card.panel { padding: 20px; }
  .nivel-badge { font-size: 1.6rem; padding: 12px 24px; }
}

/* ---------- Print ---------- */
@media print {
  :root, :root[data-theme="dark"] {
    --bg: #fff; --card: #fff; --input: #fff; --border: #ccc; --text: #111; --muted: #555; --row-alt: transparent; --hover: transparent;
    --green: #00875f; --orange: #b07800; --red: #c62828; --cyan: #00807d; --primary-h: #4b3cc4;
  }
  .sidebar, .sidebar-backdrop, .topbar, .stepper, .no-print, .toasts, .overlay, .tooltip, .drawer { display: none !important; }
  .main { margin: 0; }
  .view { padding: 0; max-width: none; animation: none !important; }
  .panel, .metric { break-inside: avoid; box-shadow: none !important; }
  .collapsible { display: block !important; }
  .nivel-badge { box-shadow: none !important; border: 2px solid currentColor; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
