/* GM026 — web app styles. Professional light theme, no dark mode, no frameworks.
   Tokens + shared components (kpi, banner, alerts, bullets, badges, tables)
   live in tokens.css / ui.css — the same files inlined into the weekly report. */

@import url("https://fonts.googleapis.com/css2?family=Archivo:wght@400;500;600;700&family=Bebas+Neue&family=IBM+Plex+Mono:wght@400;500&family=Space+Grotesk:wght@500;600&display=swap");
@import url("tokens.css");
@import url("ui.css");
@import url("quinterra.css");

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; }

.app-shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 24px 60px;
}

/* ---- top bar ---- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 14px;
  margin-bottom: 22px;
}
.topbar .brand { font-size: 12px; letter-spacing: .06em; color: var(--ink-2); text-transform: uppercase; }
.topbar .brand-logo { display: block; height: 52px; width: auto; margin-bottom: 6px; }
.topbar h1 {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 400; letter-spacing: .03em;
  margin: 3px 0 0;
}
.topbar nav a {
  display: inline-block;
  margin-left: 14px;
  font-size: 13px;
  text-decoration: none;
  color: var(--ink-2);
  border-bottom: 1px solid transparent;
}
.topbar nav a:hover { color: var(--ink); border-color: var(--ink-2); }

/* ---- week chips ---- */
.week-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 20px; }
.week-chip {
  font-size: 12px;
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}
.week-chip:hover { border-color: var(--brand); color: var(--brand-active); }
.week-chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---- sections ---- */
section { margin-bottom: 28px; }
h2 {
  font-size: 13.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-2);
  margin: 0 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--grid);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
}
.card h3 { font-size: 12.5px; color: var(--ink-2); margin: 0 0 8px; font-weight: 600; }
.card svg { display: block; max-width: 100%; height: auto; }

/* ---- buttons / links ---- */
.btn {
  display: inline-block;
  font-size: 12.5px;
  padding: 7px 13px;
  border-radius: 6px;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--border); }

.muted { color: var(--ink-muted); }
.empty-state { color: var(--ink-muted); font-size: 13px; padding: 20px 0; }

/* ---- thresholds editor ---- */
.threshold-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 12px; }
.threshold-field label { display: block; font-size: 11.5px; color: var(--ink-2); margin-bottom: 4px; }
.threshold-field input {
  width: 100%; font: inherit; font-size: 13px; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--page); color: var(--ink);
}
.threshold-field input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.threshold-actions { display: flex; align-items: center; gap: 10px; }
.threshold-status { font-size: 12px; }
.threshold-status.ok { color: var(--good); }
.threshold-status.err { color: var(--critical); }

/* ---- plano oficial ---- */
.plano-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.plano-tab {
  font-size: 12.5px;
  padding: 6px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--ink-2);
  cursor: pointer;
}
.plano-tab:hover { border-color: var(--brand); color: var(--brand-active); }
.plano-tab.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.plano-viewport { overflow-x: auto; border: 1px solid var(--border); border-radius: 6px; background: var(--page); min-height: 120px; }
.plano-img { display: block; max-width: 100%; height: auto; }
.plano-img-wide { max-width: none; height: 420px; width: auto; }
.plano-caption { margin-top: 10px; font-size: 12px; color: var(--ink-2); }
.plano-caption a { color: var(--brand); text-decoration: underline; text-underline-offset: 2px; }

.section-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin-bottom: 12px; }
.section-buttons { display: flex; gap: 6px; }
.section-buttons .btn { padding: 5px 12px; }
.section-slider { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 200px; }
.section-slider input[type="range"] { flex: 1; }
.section-slider span { font-size: 12.5px; font-variant-numeric: tabular-nums; min-width: 52px; }
.section-viewport { position: relative; border: 1px solid var(--border); border-radius: 6px; background: var(--page); min-height: 200px; display: flex; align-items: center; justify-content: center; }
.section-viewport img { display: block; max-width: 100%; height: auto; }
.section-spinner {
  position: absolute; top: 10px; right: 10px;
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--ink-2);
  animation: gm-spin .7s linear infinite;
}
.section-caption { margin-top: 10px; font-size: 12px; color: var(--ink-muted); }
@keyframes gm-spin { to { transform: rotate(360deg); } }

/* ---- chat ---- */
.chat-shell {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 140px);
  min-height: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(11, 11, 11, .04), 0 10px 30px rgba(11, 11, 11, .05);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* message row wrappers */
.msg { display: flex; flex-direction: column; max-width: 80%; }
.msg.user { align-self: flex-end; align-items: flex-end; }
.msg.assistant { align-self: flex-start; align-items: flex-start; max-width: 94%; }

.bubble {
  position: relative;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble.user {
  background: var(--ink);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble.assistant {
  background: var(--page);
  border: 1px solid var(--border);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
.bubble.assistant.rich { white-space: normal; padding: 14px 16px; width: 100%; }
.bubble.error {
  background: #fdecec;
  border: 1px solid var(--critical);
  color: var(--critical);
}

/* copy action (footer row under assistant rich messages) */
.msg-actions {
  display: flex;
  gap: 8px;
  margin: 6px 0 0 2px;
  opacity: 0;
  transition: opacity .12s ease;
}
.msg.assistant:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
.copy-btn {
  font-size: 11px;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 9px;
  cursor: pointer;
  transition: color .12s ease, border-color .12s ease;
}
.copy-btn:hover { color: var(--ink); border-color: var(--ink-2); }
.copy-btn.done { color: var(--good); border-color: var(--good); }

/* typing indicator */
.typing { display: inline-flex; gap: 4px; padding: 3px 0; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-muted);
  animation: gm-typing 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes gm-typing {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* streaming: tool call in progress (chat page + quinterra panel) */
.tool-note {
  margin-top: 8px;
  font-size: 12px;
  font-style: italic;
  color: var(--ink-muted);
}

/* suggestion chips */
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; align-self: flex-start; max-width: 94%; }
.suggest-chip {
  font-size: 12.5px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  transition: border-color .12s ease, color .12s ease, background .12s ease;
}
.suggest-chip:hover { border-color: var(--ink-2); color: var(--ink); background: var(--page); }

/* ---- markdown inside assistant bubbles ---- */
.md { font-size: 13.5px; line-height: 1.6; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.3; color: var(--ink); font-weight: 650; }
.md h1 { font-size: 16px; margin: 4px 0 10px; }
.md h2 {
  font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-2); margin: 16px 0 8px; padding-bottom: 5px;
  border-bottom: 1px solid var(--grid);
}
.md h3 { font-size: 13px; color: var(--ink-2); margin: 14px 0 6px; }
.md h4 { font-size: 12.5px; color: var(--ink-2); margin: 12px 0 4px; }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 8px 0; padding-left: 20px; }
.md li { margin: 3px 0; }
.md li::marker { color: var(--ink-muted); }
.md strong { font-weight: 650; color: var(--ink); }
.md a { color: var(--brand); text-decoration: underline; text-underline-offset: 2px; }
.md code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  background: rgba(11, 11, 11, .055);
  padding: 1px 5px; border-radius: 4px;
}
.md pre {
  background: rgba(11, 11, 11, .05);
  border: 1px solid var(--border);
  padding: 12px 14px; border-radius: 8px;
  overflow-x: auto; margin: 10px 0;
}
.md pre code { background: none; padding: 0; font-size: 12px; }
.md blockquote {
  margin: 10px 0; padding: 4px 12px;
  border-left: 3px solid var(--axis); color: var(--ink-2);
}
.md hr { border: none; border-top: 1px solid var(--grid); margin: 14px 0; }

/* markdown tables reuse the report look */
.md .md-table {
  overflow-x: auto; margin: 12px 0;
  border: 1px solid var(--border); border-radius: 8px;
}
.md table { width: 100%; border-collapse: collapse; font-size: 12px; }
.md th, .md td {
  padding: 7px 11px; text-align: right;
  border-bottom: 1px solid var(--grid);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.md th:first-child, .md td:first-child {
  text-align: left; font-variant-numeric: normal; white-space: normal;
}
.md thead th {
  background: var(--page); color: var(--ink-2);
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .02em;
}
.md tbody tr:last-child td { border-bottom: none; }
.md tbody tr:nth-child(even) td { background: rgba(11, 11, 11, .015); }
.md td.md-neg { color: var(--critical); }
.md td.md-pos { color: var(--good); }

/* chat form + key bar */
.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--grid);
  background: var(--surface);
}
.chat-form textarea {
  flex: 1;
  resize: none;
  font: inherit;
  font-size: 13.5px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--page);
  color: var(--ink);
}
.chat-form textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.chat-form button {
  border: none;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  padding: 0 20px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
}
.chat-form button:disabled { opacity: .5; cursor: default; }

/* ---- chat history sidebar ---- */
.chat-layout { display: flex; gap: 16px; align-items: stretch; }
.chat-layout .chat-shell { flex: 1; min-width: 0; }
.chat-sidebar {
  width: 230px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: calc(100vh - 140px);
  min-height: 460px;
}
#new-chat-btn {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  cursor: pointer;
  text-align: left;
}
#new-chat-btn:hover { border-color: var(--ink-2); }
.chat-history { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.chat-history-empty { font-size: 12px; color: var(--ink-muted); padding: 8px 4px; }
.chat-history-item {
  display: flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
}
.chat-history-item:hover { background: var(--surface); border-color: var(--border); }
.chat-history-item.active { background: var(--surface); border-color: var(--ink-2); }
.chat-history-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: none;
  border: 0;
  padding: 7px 4px 7px 10px;
  cursor: pointer;
  text-align: left;
}
.chat-history-title {
  font-size: 12.5px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-history-date { font-size: 10.5px; color: var(--ink-muted); }
.chat-history-del {
  background: none;
  border: 0;
  color: var(--ink-muted);
  font-size: 11px;
  padding: 6px 8px;
  cursor: pointer;
  opacity: 0;
}
.chat-history-item:hover .chat-history-del { opacity: 1; }
.chat-history-del:hover { color: var(--critical); }

@media (max-width: 640px) {
  .app-shell { padding: 16px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .msg.user { max-width: 90%; }
  .msg.assistant { max-width: 100%; }
  .msg-actions { opacity: 1; }
  .chat-layout { flex-direction: column; }
  .chat-sidebar { width: 100%; height: auto; min-height: 0; max-height: 200px; }
}

/* ---- sector dashboard (Fase IX) ---- */
.sector-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.sector-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 13px 15px; cursor: pointer; text-align: left; font: inherit; color: inherit;
}
.sector-card:hover { border-color: var(--brand); }
.sector-card.active { border-color: var(--brand); outline: 2px solid var(--brand-border); }
.sector-card .name { font-weight: 600; font-size: 13.5px; margin-bottom: 2px; }
.sector-card .date { font-size: 11.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.sector-card .avance { font-family: var(--font-mono); font-size: 17px; margin-top: 7px; }
.sector-card .meta { font-size: 11px; color: var(--ink-muted); margin-top: 2px; }
.sector-card .badge { float: right; }
.badge .dot.good { background: var(--good); }
.badge .dot.warning { background: var(--warning); }
.badge .dot.critical { background: var(--critical); }
tr.group-row td {
  text-align: left; font-weight: 600; font-size: 11.5px; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: .02em; background: var(--page);
  font-variant-numeric: normal;
}
.minitrack {
  position: relative; display: inline-block; width: 64px; height: 8px;
  border-radius: 4px; background: var(--grid); vertical-align: 1px; margin-left: 8px;
}
.minitrack .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px 0 0 4px; max-width: 100%; background: var(--brand); }

/* ---- sincronización (estado del proceso de archivos) ---- */
.sync-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.sync-actions .btn:disabled { opacity: .55; cursor: default; }
.sync-run-state { font-size: 12.5px; display: inline-flex; align-items: center; gap: 8px; }
.sync-run-state.err { color: var(--critical); }
.sync-spinner {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--brand);
  animation: gm-spin .7s linear infinite; flex: none;
}
.sync-steps { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.sync-step {
  font-size: 11.5px; padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--page); color: var(--ink-muted);
}
.sync-step.done { color: var(--good); border-color: rgba(12, 163, 12, .35); }
.sync-step.active { color: var(--brand-active); border-color: var(--brand); font-weight: 600; }
.sync-meta { font-size: 11.5px; color: var(--ink-muted); margin: 10px 0 0; }

.state-pill {
  display: inline-block; font-size: 10.5px; font-weight: 600; padding: 2px 8px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--page);
  color: var(--ink-2); text-transform: uppercase; letter-spacing: .02em;
  font-variant-numeric: normal;
}
.state-pill.ingested { color: var(--good); border-color: rgba(12, 163, 12, .35); }
.state-pill.registered { color: var(--brand-active); border-color: var(--brand-border); }
.state-pill.failed { color: var(--critical); border-color: rgba(208, 59, 59, .4); }
.state-pill.skipped, .state-pill.superseded { color: var(--ink-muted); }

.stackbar {
  display: flex; height: 10px; border-radius: 5px; overflow: hidden;
  background: var(--grid); min-width: 110px;
}
.stackbar span { display: block; height: 100%; }
.stackbar .sb-ingested { background: var(--good); }
.stackbar .sb-registered { background: var(--brand); }
.stackbar .sb-failed { background: var(--critical); }
.stackbar .sb-skipped { background: var(--axis); }

.zone-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 12px; }
.zone-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 13px 15px; }
.zone-card .name { font-weight: 600; font-size: 13.5px; margin-bottom: 8px; }
.zone-card .badge { float: right; }
.zone-stat {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 12px; padding: 3px 0; border-bottom: 1px dashed var(--grid);
}
.zone-stat:last-child { border-bottom: none; }
.zone-stat .l { color: var(--ink-2); }
.zone-stat .v { font-variant-numeric: tabular-nums; text-align: right; }

.week-toggle { background: none; border: 0; cursor: pointer; font: inherit; color: var(--brand); padding: 0; }
.week-toggle:hover { text-decoration: underline; text-underline-offset: 2px; }
tr.file-subrow > td { background: var(--page); padding: 0 8px 12px; }
.file-table-wrap {
  border: 1px solid var(--border); border-radius: 6px; overflow-x: auto;
  margin-top: 8px; background: var(--surface);
}
.file-error { font-size: 11px; color: var(--critical); font-variant-numeric: normal; }
.path-muted { font-size: 10.5px; color: var(--ink-muted); font-variant-numeric: normal; }
.r2-link { color: var(--brand); text-decoration: underline; text-underline-offset: 2px; }
.run-errors { font-size: 11px; color: var(--critical); text-align: left; font-variant-numeric: normal; }
.run-errors summary { cursor: pointer; }
