:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5b6774;
  --border: #dfe4ea;
  --accent: #0b5fa5;
  --accent-light: #e3f0fa;
  --ok: #1a7f37;
  --ok-bg: #dcf2e3;
  --warn: #9a6700;
  --warn-bg: #fff3cd;
  --error: #b3261e;
  --error-bg: #fdecea;
  --radius: 8px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  justify-content: space-between;
}
h1 { font-size: 1.25rem; margin: 0; }
h1 span { color: var(--muted); font-weight: 400; font-size: 1rem; }
.header-right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.status { font-size: .9rem; color: var(--muted); }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.toolbar {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px;
}
.toolbar input[type="search"] {
  flex: 1 1 320px;
  padding: 9px 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.btn {
  padding: 8px 14px;
  font-size: .95rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #094d86; }
.btn-secondary { background: var(--surface); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.notice {
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn);
  margin-bottom: 14px;
}
.notice.error { background: var(--error-bg); color: var(--error); }
.hidden { display: none !important; }

.layout { display: flex; gap: 16px; align-items: flex-start; }
.tree { flex: 1 1 auto; min-width: 0; }
.node { margin: 2px 0; }
.node-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid transparent;
}
.node-row:hover { border-color: var(--border); }
.toggle {
  width: 22px; height: 22px;
  border: none; background: none;
  cursor: pointer; font-size: .85rem;
  color: var(--accent);
  flex: 0 0 auto;
  padding: 0;
}
.toggle.spacer { visibility: hidden; }
.node-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  background: none; border: none;
  text-align: left;
  font-size: .98rem;
  color: var(--text);
  padding: 0;
}
.node-name:hover { color: var(--accent); }
.node-name .kind { color: var(--muted); font-size: .8rem; margin-left: 6px; }
.count {
  flex: 0 0 auto;
  font-size: .8rem;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 999px;
  padding: 1px 8px;
}
.node-children { margin-left: 18px; border-left: 1px solid var(--border); padding-left: 6px; }
.node-questions { margin-left: 18px; }
.question-row {
  display: flex; gap: 8px; align-items: baseline;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: .93rem;
}
.question-row:hover { background: var(--accent-light); }
.question-row .q-code { font-family: ui-monospace, monospace; font-size: .85rem; color: var(--accent); flex: 0 0 auto; }
.question-row .q-desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.question-row .q-meta { color: var(--muted); font-size: .8rem; flex: 0 0 auto; }
.btn-analyze {
  flex: 0 0 auto;
  font-size: .78rem;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: none;
  color: var(--accent);
  cursor: pointer;
}
.btn-analyze:hover { background: var(--accent-light); }

.detail {
  flex: 0 0 420px;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.detail-close { margin-bottom: 10px; }
.detail h2 { font-size: 1.05rem; margin: 0 0 8px; word-break: break-word; }
.detail dl { margin: 0 0 12px; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .92rem; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  font-size: .78rem;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 9px;
}
.q-text {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin: 10px 0;
  background: #fbfcfd;
}
.q-text img { max-width: 100%; height: auto; }
.answers { list-style: none; padding: 0; margin: 0; }
.answers li {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin: 6px 0;
  font-size: .93rem;
}
.answers li.correct { border-color: var(--ok); background: var(--ok-bg); }
.answers li.correct::after { content: " ✓ correcta"; color: var(--ok); font-weight: 600; font-size: .85rem; }
.answers li .frac { color: var(--muted); font-size: .8rem; }

.modal {
  position: fixed; inset: 0;
  background: rgba(20, 30, 45, .5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px;
  z-index: 50;
  overflow-y: auto;
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 8px 30px rgba(0,0,0,.25);
}
.modal-wide { max-width: 760px; }
.modal-card h2 { margin-top: 0; }
.modal-card label { display: block; font-weight: 600; margin: 10px 0 4px; font-size: .92rem; }
.modal-card select, .modal-card input[type="password"] {
  width: 100%;
  padding: 9px 10px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.modal-card .btn { margin-top: 12px; margin-right: 8px; }
.modal-node { color: var(--muted); font-size: .92rem; }
.hint { color: var(--muted); font-size: .9rem; }
.error-text { color: var(--error); font-size: .9rem; }
.analyze-result {
  margin-top: 14px;
  white-space: pre-wrap;
  font-size: .95rem;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.analyze-result.loading { color: var(--muted); }
.analyze-result.error { color: var(--error); }
.provider-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.provider-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.provider-card h3 { margin: 0 0 4px; font-size: 1rem; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.badge {
  font-size: .75rem; font-weight: 600;
  border-radius: 999px; padding: 2px 9px;
  background: var(--warn-bg); color: var(--warn);
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.provider-card input[type="password"] { width: 100%; padding: 8px 10px; font-size: .95rem; border: 1px solid var(--border); border-radius: var(--radius); margin: 6px 0; }
.provider-card .saved-msg { font-size: .85rem; color: var(--ok); min-height: 1.1em; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .detail { flex: 1 1 auto; width: 100%; position: static; max-height: none; }
}
