:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #5b6676;
  --border: #d9dee5;
  --accent: #0b5f73;
  --accent-strong: #084a5a;
  --accent-soft: #e3f1f4;
  --error: #b42318;
  --error-soft: #fdecea;
  --ok: #146c43;
  --ok-soft: #e6f4ec;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --surface: #1b212a;
    --text: #e6e9ee;
    --muted: #a3adbb;
    --border: #313a46;
    --accent: #5fb7c9;
    --accent-strong: #8fd0dd;
    --accent-soft: #19323a;
    --error: #ff8a80;
    --error-soft: #3a1f1d;
    --ok: #7bd3a1;
    --ok-soft: #173225;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1 { font-size: clamp(1.5rem, 4vw, 2.1rem); line-height: 1.2; margin: 0 0 .5rem; }
h2 { font-size: 1.25rem; margin: 0 0 .5rem; }
code { font-size: .8em; color: var(--muted); }

.wrap { width: 100%; max-width: 960px; margin: 0 auto; padding: 0 16px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; }
.logo { background: var(--accent); color: #fff; border-radius: 7px; padding: 2px 7px; font-size: .8rem; letter-spacing: .04em; }
.badge { font-size: .7rem; font-weight: 600; text-transform: uppercase; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 1px 8px; }
.nav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.whoami { color: var(--muted); font-size: .9rem; }

.hero { padding: 28px 0 12px; max-width: 760px; }
.hero p { color: var(--muted); margin: 0 0 .4rem; }
.stats { font-weight: 600; color: var(--accent) !important; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin: 16px 0; }
.auth-card { max-width: 480px; }
.prose { max-width: 760px; margin-top: 24px; }
.prose h2 { margin-top: 1.4rem; }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 12px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

form label { display: block; margin: 0 0 14px; }
form label > span:first-child { display: block; font-weight: 600; margin-bottom: 4px; }
form label.check, form label.chip, form label.inline { font-weight: normal; }
form label.check > span:first-child, form label.chip > span, form label.inline > span { display: inline; font-weight: normal; margin: 0; }
small { color: var(--muted); }
input[type=email], input[type=password], input[type=search], input[type=number], input:not([type]), select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; min-height: 44px;
}
input[type=number] { width: 6.5em; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; accent-color: var(--accent); vertical-align: -3px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

button { font: inherit; cursor: pointer; }
button:disabled { opacity: .6; cursor: progress; }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 10px 18px; font-weight: 600; min-height: 44px; }
.primary:hover:not(:disabled) { background: var(--accent-strong); }
@media (prefers-color-scheme: dark) { .primary { color: #0d1a1f; } }
.primary.big { padding: 12px 22px; font-size: 1.05rem; }
.secondary { background: var(--surface); color: var(--accent); border: 1px solid var(--accent); border-radius: 8px; padding: 8px 14px; min-height: 40px; }
.link-btn { background: none; border: 0; color: var(--accent); padding: 6px 0; text-decoration: underline; text-underline-offset: 3px; }
#form-login .link-btn { display: block; margin-top: 10px; }

.error { color: var(--error); background: var(--error-soft); border-radius: 8px; padding: 8px 12px; }
.ok { color: var(--ok); background: var(--ok-soft); border-radius: 8px; padding: 8px 12px; }
.banner { margin-top: 16px; }

fieldset { border: 0; border-top: 1px solid var(--border); margin: 18px 0 0; padding: 14px 0 0; min-width: 0; }
legend { font-weight: 700; padding: 0 6px 0 0; }
.hint, .muted { color: var(--muted); font-size: .9rem; }
.hint { margin: 0 0 8px; }
.label { font-weight: 600; margin: 0 0 6px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.row input[type=search] { flex: 1 1 220px; width: auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px; padding: 6px 12px; margin: 0 !important; min-height: 40px; }
.chip:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

.country-list { max-height: 320px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 24px; align-items: start; }
.country-group { margin-bottom: 8px; }
.group-title { font-weight: 700; font-size: .85rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); margin: 6px 0 4px; }
label.country { margin: 0 0 4px; }
label.country small { font-size: .75rem; }
.var-group { margin-bottom: 10px; }
.var-group label.check { margin: 0 0 6px; }

.submit-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 22px; }
.status { min-height: 1.5em; margin: 10px 0 0; font-weight: 600; }
.citation { background: var(--bg); border-left: 3px solid var(--accent); padding: 10px 14px; border-radius: 4px; font-size: .95rem; }

.footer { color: var(--muted); font-size: .85rem; padding-top: 8px; padding-bottom: 32px; }

/* ---------- secciones y dashboards ---------- */
.apptabs { display: flex; gap: 4px; margin: 16px 0 0; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: thin; }
.apptabs a { white-space: nowrap; padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; }
.apptabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.dash h2 { margin-top: 8px; }
.dash h3 { font-size: 1rem; margin: 16px 0 4px; }
.filters { display: flex; gap: 12px 20px; flex-wrap: wrap; }
.filters label { margin: 0; flex: 0 1 auto; min-width: 0; max-width: 100%; }
.filters label > span:first-child { font-size: .85rem; color: var(--muted); }
.filters select { width: auto; min-width: 140px; max-width: 100%; }
@media (max-width: 640px) { .filters label, .filters select { width: 100%; } }
.chart {
  --series-1: #2a78d6;
  --ref: #52514e;
  margin-top: 12px;
}
@media (prefers-color-scheme: dark) { .chart { --series-1: #3987e5; --ref: #c3c2b7; } }
.bars { display: grid; gap: 2px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 32%) 1fr 4.2em; align-items: center; gap: 10px; min-height: 26px; padding: 1px 4px; border-radius: 4px; cursor: default; }
.bar-row:hover, .bar-row:focus-visible { background: var(--accent-soft); }
.bar-label { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { position: relative; height: 16px; }
.bar { position: absolute; left: 0; top: 0; bottom: 0; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-ref { position: absolute; top: -3px; bottom: -3px; border-left: 2px dashed var(--ref); }
.bar-value { font-size: .9rem; font-variant-numeric: tabular-nums; text-align: right; }
.ref-legend { font-size: .85rem; color: var(--muted); margin: 8px 0 0; display: flex; align-items: center; gap: 6px; }
.ref-swatch { display: inline-block; width: 0; height: 14px; border-left: 2px dashed var(--ref); }
.footnote { font-size: .8rem; color: var(--muted); margin-top: 14px; }
details summary { cursor: pointer; color: var(--accent); margin-top: 8px; }
details table { border-collapse: collapse; margin-top: 8px; font-size: .9rem; width: 100%; max-width: 480px; }
details th, details td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--border); }
details td:nth-child(n+2), details th:nth-child(n+2) { text-align: right; font-variant-numeric: tabular-nums; }
.chart-tip { position: absolute; z-index: 10; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: .85rem; box-shadow: 0 4px 14px rgba(0,0,0,.15); max-width: 240px; }

.defs { font-size: .85rem; color: var(--muted); padding-left: 18px; margin: 14px 0 0; }
.defs li { margin-bottom: 4px; }
.defs strong { color: var(--text); font-weight: 600; }

/* ---------- chat ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; resize: vertical; min-height: 64px; }
textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#chat-form .actions { margin-top: 8px; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; }
.examples .example { text-align: left; font-size: .9rem; }
.chat-entry { border-top: 1px solid var(--border); padding: 14px 0 4px; margin-top: 14px; }
.chat-q { font-weight: 600; margin: 0 0 8px; }
.chat-q::before { content: "› "; color: var(--accent); }
.chat-what { color: var(--muted); margin: 0; }
.chat-hero { font-size: 2.2rem; font-weight: 700; margin: 4px 0 0; font-variant-numeric: tabular-nums; }
.chat-msg { margin: 0; }
.chat-how dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .9rem; margin: 10px 0; }
.chat-how dt { color: var(--muted); }
.chat-how dd { margin: 0; }
pre.sql { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: .8rem; overflow-x: auto; white-space: pre; }
@media (max-width: 640px) { .chat-how dl { grid-template-columns: 1fr; } .chat-how dd { margin-bottom: 6px; } }

/* ---------- comentarios y panel ---------- */
#form-feedback select { max-width: 320px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 8px 0; }
.stat { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.stat-label { font-size: .85rem; color: var(--muted); }
.stat-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-note { font-size: .8rem; color: var(--muted); }
.notice { color: var(--text); background: var(--accent-soft); border-radius: 8px; padding: 8px 12px; }
.fb-item { border-top: 1px solid var(--border); padding: 10px 0; }
.fb-head { margin: 0 0 4px; font-size: .9rem; color: var(--muted); }
.fb-head strong { color: var(--text); }
.fb-text { margin: 0 0 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; }
table.plain { border-collapse: collapse; font-size: .85rem; width: 100%; }
table.plain th, table.plain td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.plain td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.upload-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
input[type=file] { width: 100%; font: inherit; padding: 8px 0; }
