@import url("https://fonts.googleapis.com/css2?family=Rubik:wght@400;500;600;700;800&display=swap");

:root {
  --brand: #252753;
  --brand-dark: #1b1d40;
  --accent: #147ba1;
  --background: #f8fafc;
  --foreground: #0f172a;
  --muted: #64748b;
  --muted-light: #94a3b8;
  --line: #e2e8f0;
  --panel: #ffffff;
  --soft: #f1f5f9;
  --danger: #b42318;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--foreground);
  background: var(--background);
  font: 14px/1.48 "Rubik", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.is-hidden {
  display: none !important;
}

.auth-gate {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
  background:
    linear-gradient(135deg, rgba(37, 39, 83, .96), rgba(20, 123, 161, .92)),
    var(--brand);
}

.auth-card {
  width: min(460px, 100%);
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
  padding: 32px;
}

.auth-card img {
  display: block;
  width: 138px;
  height: auto;
  margin-bottom: 28px;
}

.auth-card h1 {
  margin-top: 4px;
}

.auth-card .subhead {
  margin-top: 8px;
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 24px;
}

.auth-message {
  min-height: 20px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
}

.auth-message.error {
  color: var(--danger);
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  width: 250px;
  height: 100vh;
  flex-shrink: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 22px 14px;
}

.sidebar-brand {
  padding: 0 10px 20px;
}

.sidebar-brand img {
  display: block;
  width: 132px;
  height: auto;
}

.sidebar-brand p {
  margin: 8px 0 0;
  color: var(--muted-light);
  font-size: 12px;
}

.sidebar-nav {
  display: grid;
  gap: 4px;
}

.sidebar-nav a {
  border-radius: 9px;
  padding: 10px 12px;
  color: #334155;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background .15s ease, color .15s ease;
}

.sidebar-nav a:hover {
  background: var(--soft);
}

.sidebar-nav a.active {
  color: #ffffff;
  background: var(--brand);
}

.sidebar-note {
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px;
  background: #fbfdff;
}

.sidebar-note span {
  color: var(--brand);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.sidebar-note p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
}

.topbar {
  display: flex;
  min-height: 74px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 16px 28px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-badge {
  max-width: 230px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  text-align: right;
}

.user-badge strong {
  display: block;
  color: var(--foreground);
  font-size: 13px;
}

.content {
  width: 100%;
  padding: 28px;
  display: grid;
  grid-template-columns: minmax(600px, 50vw) 1fr;
  gap: 20px;
  align-items: start;
}

.content-main {
  min-width: 0;
}

.content-aside {
  position: sticky;
  top: 28px;
}

.content-aside .section-card {
  margin-top: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted-light);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1, h2, p { margin: 0; }

h1 {
  margin-top: 2px;
  color: var(--foreground);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: 0;
}

h2 {
  margin-top: 2px;
  color: var(--foreground);
  font-size: 18px;
  font-weight: 650;
}

.subhead {
  margin-top: 3px;
  color: var(--muted);
}

.status-pill,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 11px;
  color: #475569;
  background: var(--panel);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status-pill.ok,
.badge.completed {
  border-color: rgba(20, 123, 161, .24);
  color: #0f607e;
  background: rgba(20, 123, 161, .1);
}

.status-pill.bad,
.badge.failed {
  border-color: rgba(180, 35, 24, .22);
  color: var(--danger);
  background: rgba(180, 35, 24, .08);
}

.badge.running {
  border-color: rgba(37, 39, 83, .22);
  color: var(--brand);
  background: rgba(37, 39, 83, .08);
}

.intro-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.stat-card,
.section-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 6px 18px rgba(15, 23, 42, .035);
}

.compact-card {
  padding: 0;
}

.compact-card details {
  padding: 16px 20px;
}

.compact-card summary {
  color: var(--brand);
  font-weight: 600;
  cursor: pointer;
}

.stat-card {
  padding: 18px;
}

.stat-card p {
  color: var(--muted);
  font-size: 13px;
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  color: var(--foreground);
  font-size: 28px;
  line-height: 1;
}

.stat-card span {
  display: block;
  margin-top: 7px;
  color: var(--muted-light);
  font-size: 12px;
}

.section-card {
  margin-top: 18px;
  padding: 20px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.benchmark-form {
  display: grid;
  gap: 15px;
}

label {
  display: grid;
  gap: 6px;
  color: #475569;
  font-size: 12px;
  font-weight: 600;
}

input, textarea, select {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  padding: 10px 12px;
  color: var(--foreground);
  background: #fff;
  font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

select {
  cursor: pointer;
  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='%2364748b' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.field-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.help {
  display: inline-grid;
  place-items: center;
  width: 15px;
  height: 15px;
  border-radius: 999px;
  background: #cbd5e1;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  cursor: help;
}

.help:hover, .help:focus {
  background: var(--accent);
  outline: none;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(37, 39, 83, .1);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.form-grid:first-of-type {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.manual-queries {
  padding: 14px;
  border: 1px solid #dbe3ed;
  border-radius: 8px;
  background: #f8fafc;
}

.manual-queries:empty {
  display: none;
}

.manual-queries-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--foreground);
  font-size: 13px;
}

.manual-queries-head span {
  color: #64748b;
  font-size: 12px;
  font-weight: 500;
}

.manual-queries-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

button {
  border: 1px solid var(--brand);
  border-radius: 9px;
  padding: 10px 15px;
  color: #fff;
  background: var(--brand);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}

button:hover {
  border-color: var(--brand-dark);
  background: var(--brand-dark);
}

button:disabled {
  cursor: wait;
  opacity: .62;
}

button.secondary {
  color: #475569;
  border-color: #cbd5e1;
  background: #fff;
}

button.secondary:hover {
  color: var(--foreground);
  border-color: #94a3b8;
  background: var(--soft);
}

.job-summary {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--muted);
  background: #fbfdff;
}

.logs {
  height: 330px;
  margin: 12px 0 0;
  overflow: auto;
  border: 1px solid #1f2548;
  border-radius: 12px;
  padding: 14px;
  color: #d8f3fb;
  background: #11152f;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.result-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.result-empty {
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  padding: 22px;
  color: var(--muted);
  background: #fbfdff;
}

.result-view {
  display: grid;
  gap: 16px;
}

.result-summary {
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 16px 18px;
  background: rgba(20, 123, 161, .08);
}

.result-summary h3,
.friendly-card h3 {
  margin: 0;
  color: var(--brand);
  font-size: 15px;
  font-weight: 700;
}

.result-summary p {
  margin-top: 8px;
  color: #334155;
}

.friendly-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr);
  gap: 16px;
}

.friendly-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  background: #fff;
}

.wide-card {
  grid-column: 1 / -1;
}

.query-list,
.opportunity-list {
  margin: 12px 0 0;
  padding-left: 22px;
}

.query-list li,
.opportunity-list li {
  margin: 10px 0;
}

.query-list strong {
  display: block;
  color: var(--foreground);
  font-weight: 600;
}

.query-list span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.domain-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.domain-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid #dbe5ee;
  border-radius: 999px;
  padding: 7px 10px;
  background: #f8fafc;
}

.domain-chip strong {
  color: var(--brand);
  font-size: 12px;
}

.domain-chip em {
  display: inline-grid;
  min-width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  background: var(--accent);
  font-size: 11px;
  font-style: normal;
  font-weight: 600;
}

.sources-block,
.answer-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-top: 14px;
  background: #fbfdff;
  overflow: hidden;
}

.sources-block:first-of-type,
.answer-block:first-of-type {
  margin-top: 16px;
}

.sources-query,
.answer-query {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  color: var(--brand);
  font-weight: 700;
  cursor: pointer;
}

.sources-query span,
.answer-query span {
  min-width: 0;
}

.sources-query em,
.answer-query em {
  flex-shrink: 0;
  border-radius: 999px;
  padding: 4px 9px;
  color: #0f607e;
  background: rgba(20, 123, 161, .1);
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
}

.sources-block[open] .sources-query,
.answer-block[open] .answer-query {
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.model-answer {
  margin: 0;
  padding: 14px 16px;
  color: #334155;
  background: #fff;
  white-space: pre-wrap;
}

.sources-list {
  display: grid;
  gap: 11px;
  margin: 0;
  padding: 14px 18px 14px 36px;
  background: #fff;
}

.sources-list li {
  padding-right: 6px;
}

.sources-list a {
  display: block;
  color: var(--foreground);
  font-weight: 600;
  text-decoration: none;
  word-break: break-word;
}

.sources-list a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.source-url {
  display: block;
  margin-top: 3px;
  color: var(--accent);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.source-note {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.reports {
  display: grid;
  gap: 9px;
}

.report-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fff;
  transition: border-color .15s ease, background .15s ease;
}

.report-row:hover {
  border-color: #cbd5e1;
  background: #fbfdff;
}

.report-row a {
  color: var(--brand);
  font-weight: 600;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.report-row a:hover {
  color: var(--accent);
}

.muted {
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 1200px) {
  .content { grid-template-columns: 1fr; }
  .content-aside { position: static; }
}

@media (max-width: 1080px) {
  .intro-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid, .form-grid:first-of-type { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .friendly-grid { grid-template-columns: 1fr; }
}

@media (max-width: 780px) {
  .manual-queries-grid { grid-template-columns: 1fr; }
  .app-shell { display: block; }
  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .sidebar-nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sidebar-note { display: none; }
  .topbar { align-items: flex-start; flex-direction: column; padding: 18px; }
  .topbar-actions { width: 100%; justify-content: space-between; }
  .content { padding: 18px; }
  .intro-grid, .form-grid, .form-grid:first-of-type { grid-template-columns: 1fr; }
  .section-head { align-items: stretch; flex-direction: column; }
  .report-row { grid-template-columns: 1fr; }
}

/* Fan-out del modelo */
.fanout-block {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 12px;
}
.fanout-block:first-of-type {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}
.fanout-source {
  font-weight: 600;
  color: var(--foreground);
  margin: 0 0 6px;
}
.fanout-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
}
.fanout-list li {
  color: var(--muted);
  font-size: 13px;
}

/* Analisis de fan-out */
.fanout-totals {
  font-weight: 600;
  color: var(--foreground);
  margin: 0 0 14px;
}
.fanout-analysis .friendly-grid { margin-bottom: 16px; }
.rank-list { display: grid; gap: 10px; }
.rank-row { display: grid; gap: 4px; }
.rank-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.rank-label { color: var(--foreground); font-size: 13px; word-break: break-word; }
.rank-count { color: var(--muted); font-size: 12px; font-weight: 600; flex: none; }
.rank-track { height: 6px; background: var(--soft); border-radius: 4px; overflow: hidden; }
.rank-fill { height: 100%; background: var(--brand); border-radius: 4px; }
