:root {
  --bg: #f7f6f4;
  --surface: #ffffff;
  --surface-2: #f2f0ee;
  --border: #e5e2de;
  --border-strong: #d3cfca;
  --text: #1b1720;
  --text-muted: #5f5867;
  --text-faint: #6e6678;
  --accent: #3d2352;
  --accent-ink: #26142f;
  --accent-soft: #f0eaf5;

  --error: #a8322b;      --error-bg: #f9edec;
  --warning: #8a5a08;    --warning-bg: #fbf2e2;
  --convention: #2b5a8f; --convention-bg: #eaf0f7;
  --refactor: #6b4e9e;   --refactor-bg: #f1ecf8;

  --good: #1c7a45;
  --mid: #8a5a08;
  --low: #a8322b;

  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 8px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ---- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 18px; flex-wrap: wrap;
  padding: 7px 22px;
}
.topbar-row-main { border-bottom: 1px solid var(--border); }

.brand { display: flex; align-items: center; gap: 11px; }
.brand-logo { height: 26px; width: auto; border-radius: 7px; display: block; }
.brand-name { font-weight: 600; font-size: 16px; letter-spacing: -0.015em; }
.brand-tag {
  font-size: 11px; color: var(--text-faint); font-family: var(--mono);
  padding-left: 11px; border-left: 1px solid var(--border);
}

/* ---- Controles ---- */
.controls { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; width: 100%; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span {
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  color: var(--text-faint); text-transform: uppercase; letter-spacing: .07em;
}

.actions {
  display: flex; align-items: center; gap: 8px;
  margin-left: auto; padding-left: 14px;
  border-left: 1px solid var(--border);
}

select {
  font-family: var(--sans); font-size: 13.5px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 6px 9px; min-width: 112px; cursor: pointer;
}
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.txt-input {
  font-family: var(--sans); font-size: 13.5px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 6px 9px; width: 150px;
}

#filename-input { width: 200px; }
#project-input { width: 160px; }
.txt-input::placeholder { color: var(--text-faint); }
.txt-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn-primary {
  font-family: var(--sans); font-size: 13.5px; font-weight: 500;
  color: #fff; background: var(--accent); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 6px 17px; cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn-primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { opacity: .5; cursor: progress; }

.btn-secondary {
  font-family: var(--sans); font-size: 13.5px; font-weight: 500;
  color: var(--text); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 6px 13px; cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn-secondary:disabled { opacity: .5; cursor: progress; }
.btn-primary:focus-visible,
.btn-secondary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Layout ---- */
main {
  max-width: 1440px; width: 100%; margin: 0 auto;
  padding: 12px 20px 12px;
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
}
/* Las tres bandas fijas no se encogen; el workspace absorbe lo que sobra. */
.score-panel, .notes, .reaction, .vuln-section { flex-shrink: 0; }

/* ---- Score panel (hero) ---- */
.score-panel {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center; gap: 26px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 22px;
  margin-bottom: 10px;
}
.score-figure { display: flex; align-items: baseline; gap: 5px; }
.score-value {
  font-family: var(--mono); font-weight: 600; font-size: 36px; line-height: .9;
  letter-spacing: -.03em; color: var(--text-faint);
  font-variant-numeric: tabular-nums; transition: color .3s;
}
.score-max { font-family: var(--mono); font-size: 17px; color: var(--text-faint); }
.score-meta { min-width: 200px; }
.score-label { font-size: 14px; font-weight: 600; letter-spacing: -.01em; margin-bottom: 7px; }
.score-bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.score-bar-fill {
  height: 100%; width: 0; background: var(--text-faint); border-radius: 3px;
  transition: width .4s ease, background .3s;
}
.score-hint { font-size: 12.5px; color: var(--text-muted); margin-top: 7px; }

/* Los contadores dejan de ser cuatro cajas pastel: superficie neutra, unidos
   en un solo bloque, y el color de severidad vive en el filete superior. */
.counts {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.count {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: var(--surface); padding: 8px 16px; min-width: 72px;
  border-top: 2px solid transparent;
}
.count-n {
  font-family: var(--mono); font-weight: 600; font-size: 19px;
  font-variant-numeric: tabular-nums;
}
.count-l {
  font-family: var(--mono); font-size: 10px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.count[data-sev="error"]      { border-top-color: var(--error); }
.count[data-sev="error"] .count-n { color: var(--error); }
.count[data-sev="warning"]    { border-top-color: var(--warning); }
.count[data-sev="warning"] .count-n { color: var(--warning); }
.count[data-sev="convention"] { border-top-color: var(--convention); }
.count[data-sev="convention"] .count-n { color: var(--convention); }
.count[data-sev="refactor"]   { border-top-color: var(--refactor); }
.count[data-sev="refactor"] .count-n { color: var(--refactor); }

/* ---- Workspace ---- */
.workspace {
  display: grid; grid-template-columns: 1.3fr 1fr; gap: 10px;
  flex: 1; min-height: 0;
}
.pane {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column; min-height: 0;
}
/* Las dos cajas del área de trabajo llenan el alto que queda y hacen scroll
   por dentro. Así el editor, los resultados y las vulnerabilidades entran
   siempre en la misma pantalla, sin importar cuántos hallazgos haya. */
.workspace > .pane { height: 100%; min-height: 0; }
.pane-head {
  display: flex; align-items: center; gap: 9px;
  padding: 0 14px; height: 34px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-family: var(--mono); font-size: 12.5px; color: var(--text); flex-shrink: 0;
}
.pane-head i {
  font-style: normal; font-family: var(--mono); font-size: 10.5px;
  color: var(--text-faint); text-transform: uppercase; letter-spacing: .08em;
}
.fmt-badge {
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  background: var(--convention-bg); color: var(--convention);
  padding: 2px 8px; border-radius: 4px; margin-left: auto;
}
#editor { flex: 1; min-height: 0; }

/* ---- Filtros (pestañas) ---- */
.filters {
  display: flex; gap: 2px; padding: 0 12px; flex-wrap: wrap;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.filter {
  font-family: var(--sans); font-size: 12.5px; color: var(--text-muted);
  background: transparent; border: none;
  border-bottom: 2px solid transparent; border-radius: 0;
  padding: 11px 10px; cursor: pointer; transition: color .12s, border-color .12s;
}
.filter:hover { color: var(--text); }
.filter.active { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.filter:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---- Hallazgos ---- */
.issues { flex: 1; overflow-y: auto; min-height: 0; }
.issue {
  display: flex; gap: 11px; padding: 11px 14px;
  border-bottom: 1px solid var(--border); cursor: pointer;
  transition: background .12s;
  border-left: 3px solid transparent;
}
.issue:hover { background: var(--surface-2); }
/* El filete izquierdo toma el color de la severidad leyendo el punto interno,
   así la lista se escanea por columna sin tocar app.js. */
.issue:has(.issue-dot[data-sev="error"])      { border-left-color: var(--error); }
.issue:has(.issue-dot[data-sev="warning"])    { border-left-color: var(--warning); }
.issue:has(.issue-dot[data-sev="convention"]) { border-left-color: var(--convention); }
.issue:has(.issue-dot[data-sev="refactor"])   { border-left-color: var(--refactor); }
.vuln:has(.vuln-dot[data-sev="high"])   { border-left-color: var(--error); }
.vuln:has(.vuln-dot[data-sev="medium"]) { border-left-color: var(--warning); }
.vuln:has(.vuln-dot[data-sev="low"])    { border-left-color: var(--border-strong); }

/* Marca el hallazgo en el que se está trabajando, para no perderlo de vista. */
.issue.active, .vuln.active { background: var(--accent-soft); }

.issue-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.issue-dot[data-sev="error"] { background: var(--error); }
.issue-dot[data-sev="warning"] { background: var(--warning); }
.issue-dot[data-sev="convention"] { background: var(--convention); }
.issue-dot[data-sev="refactor"] { background: var(--refactor); }
.issue-body { flex: 1; min-width: 0; }
.issue-msg { font-size: 13.5px; line-height: 1.42; }
.issue-sub { font-family: var(--mono); font-size: 11px; color: var(--text-faint); margin-top: 4px; }
.issue-fix { color: var(--good); }

.placeholder { padding: 18px; text-align: center; color: var(--text-muted); font-size: 13px; }
.placeholder.is-error { color: var(--error); }

/* ---- Vulnerabilidades (seguridad) ---- */
.vuln-section { margin-top: 10px; min-height: 0; }
.vuln-head { justify-content: flex-start; gap: 12px; }
.vuln-badges { display: flex; gap: 6px; margin-left: auto; }
.vuln-badge {
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  padding: 3px 9px; border-radius: 4px;
}
.vuln-badge[data-sev="high"]   { background: var(--error-bg);   color: var(--error); }
.vuln-badge[data-sev="medium"] { background: var(--warning-bg); color: var(--warning); }
.vuln-badge[data-sev="low"]    { background: var(--surface-2);  color: var(--text-muted); }

.vulns { max-height: 88px; overflow-y: auto; }
.vuln {
  display: flex; gap: 11px; padding: 11px 14px;
  border-bottom: 1px solid var(--border); cursor: pointer;
  transition: background .12s;
  border-left: 3px solid transparent;
}
.vuln:hover { background: var(--surface-2); }
.vuln:last-child { border-bottom: none; }
.vuln-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.vuln-dot[data-sev="high"]   { background: var(--error); }
.vuln-dot[data-sev="medium"] { background: var(--warning); }
.vuln-dot[data-sev="low"]    { background: var(--text-faint); }
.vuln-body { flex: 1; min-width: 0; }
.vuln-msg { font-size: 13.5px; line-height: 1.42; }
.vuln-sub { font-family: var(--mono); font-size: 11px; color: var(--text-faint); margin-top: 4px; }

/* ---- Veredicto de aprobación ---- */
.verdict {
  font-family: var(--sans); font-size: 10.5px; font-weight: 600;
  letter-spacing: .09em; text-transform: uppercase;
  padding: 4px 10px; border-radius: 5px; margin-left: 12px;
  white-space: nowrap; align-self: center; border: 1px solid transparent;
}
.verdict[data-ok="true"]  { background: #e6f2ea; color: var(--good); }
.verdict[data-ok="false"] { background: var(--error-bg); color: var(--error); }

/* ---- Mensajes bilingües ---- */
.issue-en, .vuln-en { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.issue-sub a, .vuln-sub a { color: var(--convention); text-decoration: none; }
.issue-sub a:hover, .vuln-sub a:hover { text-decoration: underline; }

/* ---- Avisos (dependencias %run, etc.) ---- */
.notes {
  background: var(--convention-bg); border: 1px solid var(--border);
  border-left: 3px solid var(--convention);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px;
  font-size: 13px; color: var(--text); line-height: 1.5;
}
.notes-item { display: flex; align-items: flex-start; gap: 8px; }
.notes-item + .notes-item { margin-top: 6px; }
.notes-deps {
  font-family: var(--mono); font-size: 11.5px; color: var(--text-muted);
  margin-top: 6px; word-break: break-all;
}
.deps-chip {
  font-family: var(--mono); font-size: 11px;
  background: var(--convention-bg); color: var(--convention);
  padding: 3px 8px; border-radius: 4px; margin-left: 6px;
}
.btn-secondary.has-deps { border-color: var(--convention); color: var(--convention); }

/* ---- Reacción según el puntaje ---- */
/* Se conserva el chiste, pero en una línea: antes el emoji de 40px dominaba
   la pantalla por encima del propio puntaje. */
.reaction {
  display: flex; align-items: center; gap: 11px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--text-faint);
  border-radius: var(--radius); padding: 11px 16px; margin-bottom: 14px;
}
.reaction[data-tone="bad"]  { border-left-color: var(--low); }
.reaction[data-tone="mid"]  { border-left-color: var(--mid); }
.reaction[data-tone="good"] { border-left-color: var(--good); }
.reaction-emoji { font-size: 20px; line-height: 1; flex-shrink: 0; }
.reaction-text { font-size: 14px; font-weight: 500; color: var(--text); }

.reaction.show { animation: reaction-pop .38s cubic-bezier(.18, .89, .32, 1.15); }
@keyframes reaction-pop {
  0%   { opacity: 0; transform: translateY(-5px); }
  100% { opacity: 1; transform: translateY(0); }
}
.reaction-emoji.wobble { animation: reaction-wobble .45s ease; }
@keyframes reaction-wobble {
  0%, 100% { transform: rotate(0) scale(1); }
  25%      { transform: rotate(-8deg) scale(1.1); }
  75%      { transform: rotate(8deg) scale(1.1); }
}

/* ---- Autenticación OpenID ---- */
/* Sin gradientes ni sombras de color: eran lo único así en toda la app. */
.auth-section { display: flex; align-items: center; gap: 12px; }

.auth-user-pill {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 4px 12px 4px 6px;
  font-size: 13px; color: var(--text);
}

.auth-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-family: var(--sans); font-weight: 600; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  text-transform: uppercase; flex-shrink: 0;
}

.auth-details { display: flex; flex-direction: column; line-height: 1.2; }
.auth-name { font-weight: 600; font-size: 12.5px; color: var(--text); }
.auth-email { font-size: 11px; color: var(--text-muted); }

.btn-auth-login {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--sans); font-size: 13.5px; font-weight: 500;
  color: #ffffff; background: var(--accent);
  border: 1px solid var(--accent); border-radius: var(--radius);
  padding: 8px 16px; text-decoration: none; cursor: pointer;
  transition: background .15s;
}
.btn-auth-login:hover { background: var(--accent-ink); border-color: var(--accent-ink); }

.btn-auth-logout {
  font-family: var(--sans); font-size: 11.5px; font-weight: 500;
  color: var(--text-muted); background: transparent;
  border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 10px; text-decoration: none; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.btn-auth-logout:hover { background: var(--error-bg); color: var(--error); border-color: var(--error); }

/* Modal overlay para alerta de autenticación */
.auth-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(27, 23, 32, .5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn .2s ease;
}
.auth-modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 28px;
  max-width: 420px; width: 100%;
  box-shadow: 0 20px 44px -18px rgba(27, 23, 32, .35);
  text-align: center;
}
.auth-modal-icon { font-size: 34px; margin-bottom: 12px; }
.auth-modal h3 { margin: 0 0 8px; font-size: 18px; font-weight: 600; color: var(--text); }
.auth-modal p { margin: 0 0 20px; font-size: 14px; color: var(--text-muted); line-height: 1.5; }
.auth-modal-actions { display: flex; gap: 10px; justify-content: center; }

@keyframes fadeIn {
  from { opacity: 0; transform: scale(.97); }
  to   { opacity: 1; transform: scale(1); }
}

/* ---- Responsive ---- */
@media (max-width: 1180px) {
  .actions { margin-left: 0; padding-left: 0; border-left: none; width: 100%; }
}

@media (max-height: 520px), (max-width: 1000px) {
  body { height: auto; overflow: visible; display: block; }
  main { display: block; flex: none; padding: 20px 22px 26px; }
  .workspace { display: grid; }
  .workspace > .pane { height: auto; min-height: 420px; }
  .vulns { max-height: 300px; }
}

@media (max-width: 860px) {
  .score-panel { grid-template-columns: 1fr; gap: 18px; text-align: center; }
  .score-figure { justify-content: center; }
  .workspace { grid-template-columns: 1fr; }
  .workspace > .pane { height: auto; max-height: 70vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}