/* Marketplace Watcher — tema dark estilo Obsidian. Zero dependência externa
   (sem CDN, sem build step). Layout: sidebar fixa + conteúdo. */

:root {
  --bg: #1e1e2e;
  --bg-elevated: #26263a;
  --panel: #26263a;
  --border: #33334d;
  --text: #cdd6f4;
  --text-muted: #8a8aa3;
  --accent: #8b7cf6;
  --accent-hover: #a394f8;
  --accent-soft: rgba(139, 124, 246, 0.15);
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.15);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.15);
  --bad: #f87171;
  --bad-soft: rgba(248, 113, 113, 0.15);
  --off: #8a8aa3;
  --off-soft: rgba(138, 138, 163, 0.15);
  --radius: 8px;
  --sidebar-w: 220px;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

h1, h2, h3, h4 { color: var(--text); line-height: 1.25; margin: 0 0 .4rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; margin-top: 1.4rem; }

hgroup { margin-bottom: 1rem; }
hgroup h2 { margin-bottom: .15rem; }

.muted { color: var(--text-muted); font-size: .85em; }
code {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 4px;
  padding: .05rem .35rem; font-size: .85em; color: var(--text);
}
hr { border: none; border-top: 1px solid var(--border); margin: .9rem 0; }

/* -- layout: sidebar -----------------------------------------------------
   position: fixed (nao CSS Grid + sticky) — grid+sticky+overflow no mesmo
   elemento e uma combinacao conhecida por causar artefato de composicao
   (ghosting/repeticao) em scroll no Chrome. fixed e mais simples e robusto:
   o conteudo so precisa de margin-left pra nao ficar embaixo dela. */
.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 1.1rem .9rem;
  z-index: 20;
}
.sidebar-brand {
  display: flex; align-items: center; gap: .5rem;
  font-weight: 700; font-size: 1.05rem; color: var(--text);
  padding: 0 .4rem .9rem;
  margin-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-nav { display: flex; flex-direction: column; gap: .1rem; flex: 1; }
.sidebar-nav a {
  display: flex; align-items: center; gap: .55rem;
  color: var(--text-muted); text-decoration: none;
  padding: .5rem .6rem; border-radius: var(--radius);
  font-size: .92rem;
}
.sidebar-nav a:hover { background: var(--accent-soft); color: var(--text); }
.sidebar-nav a.active { background: var(--accent-soft); color: var(--accent-hover); font-weight: 600; }
.sidebar-nav .icon { width: 1.1em; text-align: center; opacity: .9; }

.sidebar-section-label {
  text-transform: uppercase; letter-spacing: .06em; font-size: .68rem;
  color: var(--text-muted); padding: .8rem .6rem .3rem;
}
.sidebar-cta {
  margin: .9rem 0 .3rem;
  display: block; text-align: center;
  background: var(--accent); color: #fff;
  border-radius: var(--radius); padding: .5rem .6rem;
  font-weight: 600; font-size: .88rem;
}
.sidebar-cta:hover { background: var(--accent-hover); color: #fff; text-decoration: none; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: .7rem; margin-top: .7rem;
  font-size: .78rem; color: var(--text-muted);
}

.sidebar-toggle {
  display: none;
  position: fixed; top: .7rem; left: .7rem; z-index: 30;
  background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  width: 2.4rem; height: 2.4rem; font-size: 1.15rem;
  align-items: center; justify-content: center; cursor: pointer;
}

main.content {
  margin-left: var(--sidebar-w);
  padding: 1.6rem 2rem 3rem;
  max-width: 1600px;
  width: 100%;
}

/* tabelas e paineis de dados (admin, health, sources) usam a largura toda —
   nao faz sentido cortar uma tabela de 8 colunas em 1180px num monitor largo */
main.content:has(table) {
  max-width: none;
}

footer.app-footer { margin-top: 2rem; }

/* -- mobile: sidebar vira off-canvas ----------------------------------- */
@media (max-width: 768px) {
  .sidebar-toggle { display: flex; }
  .sidebar {
    width: 260px;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: 2px 0 16px rgba(0, 0, 0, .4);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open::after {
    content: ""; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 15;
  }
  main.content { margin-left: 0; padding: 4rem 1rem 2.5rem; max-width: 100%; }
}

/* -- cards -------------------------------------------------------------- */
.card, article.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .8rem 1rem;
  margin-bottom: .8rem;
}
article { margin-bottom: .8rem; }

/* -- pills / badges ------------------------------------------------------ */
.pill {
  display: inline-block;
  padding: .12rem .55rem;
  border-radius: 1rem;
  font-size: .75em;
  font-weight: 600;
  line-height: 1.6;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.off { background: var(--off-soft); color: var(--off); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

/* -- tables ---------------------------------------------------------- */
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}
th, td { padding: .5rem .65rem; text-align: left; border-bottom: 1px solid var(--border); font-size: .92rem; }
th { color: var(--text-muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: rgba(255, 255, 255, .02); }

/* -- forms ------------------------------------------------------------ */
label { display: block; margin-bottom: .8rem; font-size: .88rem; color: var(--text-muted); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .8rem; margin: 0 0 .8rem; }
legend { padding: 0 .4rem; color: var(--text-muted); font-size: .85rem; }

input, select, textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .5rem .65rem;
  font-size: .92rem;
  font-family: inherit;
  margin-top: .3rem;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="checkbox"] { width: auto; margin: 0 .4rem 0 0; vertical-align: middle; }
textarea { resize: vertical; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .8rem;
  align-items: start;
}

/* -- buttons ------------------------------------------------------------ */
button, a[role="button"], input[type="submit"] {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: .5rem .9rem;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  font-family: inherit;
}
button:hover, a[role="button"]:hover, input[type="submit"]:hover {
  background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; text-decoration: none;
}
button.secondary, a[role="button"].secondary {
  background: var(--bg-elevated); border-color: var(--border); color: var(--text);
}
button.secondary:hover, a[role="button"].secondary:hover { background: var(--border); color: var(--text); }
button.outline, a[role="button"].outline {
  background: transparent; border-color: var(--accent); color: var(--accent);
}
button.outline:hover, a[role="button"].outline:hover { background: var(--accent-soft); color: var(--accent-hover); }
button.secondary.outline, a[role="button"].secondary.outline {
  background: transparent; border-color: var(--border); color: var(--text-muted);
}
button.secondary.outline:hover, a[role="button"].secondary.outline:hover {
  background: var(--bg-elevated); color: var(--text); border-color: var(--text-muted);
}
button[disabled], button[aria-busy="true"] { opacity: .6; cursor: progress; }

/* -- details / summary -------------------------------------------------- */
details { margin: .4rem 0; }
summary { cursor: pointer; color: var(--text-muted); }
details ul { margin: .4rem 0 0; padding-left: 1.2rem; }

/* -- progress ------------------------------------------------------------ */
progress {
  width: 100%; height: .5rem; accent-color: var(--accent);
  background: var(--bg-elevated); border: none; border-radius: 4px;
}

/* -- status bar (HTMX, todas as paginas) --------------------------------- */
.status-bar-alert {
  background: var(--warn-soft);
  border: 1px solid rgba(251, 191, 36, .35);
  border-radius: var(--radius);
  padding: .6rem .9rem;
  margin-bottom: 1rem;
}

/* -- banner de personificacao (admin vendo como outro usuario) ------------ */
.impersonation-banner {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: .6rem .9rem;
  margin-bottom: 1rem;
}

/* -- runlog (rodar agora / SSE) ------------------------------------------ */
.runlog { border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .7rem; font-size: .85rem; }
.runlog .l { padding: .12rem 0; display: flex; gap: .4rem; align-items: baseline; }
.runlog .l .ic { width: 1.2rem; text-align: center; }
.runlog .l.err { color: var(--bad); }
.runlog .l.ok { color: var(--ok); }
.runlog .l.step { color: var(--text-muted); }
#last-run .card { background: var(--ok-soft); border-color: rgba(74, 222, 128, .3); }

/* -- avisos inline (negociação: rascunho pendente / erro) ---------------- */
.notice-pending { background: #3d3319; border: 1px solid #6b5a1f; color: var(--text); }
.notice-error { background: #3d1f1f; border: 1px solid #6b2f2f; color: var(--text); }

/* -- chart tooltip --------------------------------------------------------- */
#chart-tip {
  position: fixed; z-index: 999;
  background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--border);
  padding: .35rem .55rem;
  border-radius: 6px; font-size: .8rem;
  pointer-events: none; display: none; max-width: 320px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .4);
}

.pt { cursor: pointer; }

/* -- campo de tags (variantes / deve conter / excluir nos forms) ---------- */
.tag-field {
  display: flex; flex-wrap: wrap; align-items: center; gap: .35rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .4rem .5rem;
  margin-top: .3rem;
}
.tag-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.tag-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.tag-chip {
  display: inline-flex; align-items: center; gap: .3rem;
  background: var(--accent-soft); color: var(--accent-hover);
  border-radius: 1rem; padding: .15rem .35rem .15rem .6rem;
  font-size: .85rem; white-space: nowrap;
}
.tag-chip-remove {
  background: none; border: none; color: inherit; cursor: pointer;
  font-size: 1rem; line-height: 1; padding: 0 .2rem; margin: 0;
}
.tag-chip-remove:hover { color: var(--bad); }
.tag-entry {
  border: none; background: transparent; flex: 1; min-width: 8rem;
  padding: .2rem 0; margin: 0;
}
.tag-entry:focus { outline: none; box-shadow: none; }
