:root {
  --bg: #0d1117;
  --bg-soft: #131923;
  --bg-elev: #161b22;
  --panel: #11161f;
  --border: #232b36;
  --border-soft: #1c232e;
  --fg: #c9d1d9;
  --fg-dim: #8b949e;
  --fg-muted: #5c6675;
  --accent: #7ee787;
  --accent-amber: #e3b341;
  --accent-blue: #58a6ff;
  --danger: #ff7b72;
  --row-h: 20px;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 13px;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button { font-family: inherit; }

/* ===== Topbar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.brand { display: flex; align-items: center; gap: 9px; }
.prompt { color: var(--accent); font-weight: 700; letter-spacing: 1px; }
.brand-name { font-weight: 500; color: var(--fg); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.stats { color: var(--fg-dim); font-size: 12px; }

/* ===== Botões ===== */
.btn {
  background: var(--bg-soft);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: border-color .12s, background .12s, color .12s;
  user-select: none;
}
.btn:hover { border-color: var(--fg-muted); }
.btn.primary {
  background: rgba(126,231,135,.12);
  border-color: rgba(126,231,135,.4);
  color: var(--accent);
}
.btn.primary:hover { background: rgba(126,231,135,.2); }
.btn.icon { padding: 6px 9px; line-height: 1; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--fg-dim); }
.btn.ghost:hover { color: var(--fg); background: var(--bg-soft); }
.btn.small { padding: 4px 9px; }
.file-btn { display: inline-flex; align-items: center; }
.link-btn {
  background: none; border: none; color: var(--accent-blue);
  cursor: pointer; font-size: 11px; padding: 0 2px;
}
.link-btn:hover { text-decoration: underline; }

/* ===== Tela de entrada ===== */
.input-view {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
}
.dropzone {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--panel);
  padding: 4px;
  transition: border-color .15s, background .15s;
}
.dropzone.dragover { border-color: var(--accent); background: rgba(126,231,135,.05); }
.log-input {
  flex: 1 1 auto;
  width: 100%;
  resize: none;
  background: transparent;
  border: none;
  outline: none;
  color: var(--fg);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  padding: 14px;
}
.log-input::placeholder { color: var(--fg-muted); }
.dropzone-hint {
  text-align: center;
  color: var(--fg-muted);
  font-size: 12px;
  padding: 8px;
  border-top: 1px solid var(--border-soft);
}
.input-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ===== Viewer ===== */
.viewer-view { flex: 1 1 auto; display: flex; min-height: 0; }

.filter-panel {
  flex: 0 0 260px;
  /* min-width:0 impede que nomes de tag longos (flex min-content) estiquem o
     painel além de 260px — sem isso a tela "racha no meio". */
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  min-height: 0;
}
.filter-panel.collapsed { display: none; }
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--fg-dim);
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
}
.panel-section { padding: 12px; border-bottom: 1px solid var(--border-soft); }
.panel-section.grow { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.section-title {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--fg-muted); margin-bottom: 8px;
}
.section-title.mt { margin-top: 18px; }
.section-actions { margin-left: auto; display: flex; gap: 6px; }

.level-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.level-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 5px;
  border: 1px solid var(--border);
  font-size: 11px; cursor: pointer; user-select: none;
  background: var(--bg-soft);
}
.level-chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.level-chip .lc-count { color: var(--fg-muted); }
.level-chip.off { opacity: .38; }

.mini-input {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--fg);
  font-family: var(--mono);
  font-size: 12px;
  padding: 5px 8px;
  outline: none;
  width: 100%;
}
.mini-input:focus { border-color: var(--fg-muted); }
.mini-input.grow { flex: 1 1 auto; width: auto; }

.tag-hint { font-size: 10px; color: var(--fg-muted); margin-top: 6px; }
.tag-hint .hide-glyph { color: var(--danger); }
.tag-list { margin-top: 6px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.tag-row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 6px; border-radius: 5px; cursor: pointer;
  font-size: 12px; border-left: 2px solid transparent;
  user-select: none;
}
.tag-row:hover { background: var(--bg-soft); }
.tag-swatch { width: 9px; height: 9px; border-radius: 2px; flex: 0 0 auto; box-shadow: 0 0 0 0 transparent; }
.tag-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-row .tag-n { color: var(--fg-muted); font-size: 11px; }
/* botão ocultar (aparece no hover ou quando ativo) */
.tag-hide {
  flex: 0 0 auto; background: none; border: none; cursor: pointer;
  color: var(--fg-muted); font-size: 13px; line-height: 1; padding: 0 2px;
  opacity: 0; transition: opacity .1s, color .1s;
}
.tag-row:hover .tag-hide { opacity: .7; }
.tag-hide:hover { color: var(--danger); opacity: 1; }
/* estado isolado */
.tag-row.iso { background: rgba(126,231,135,.1); border-left-color: var(--accent); }
.tag-row.iso .tag-swatch { box-shadow: 0 0 0 2px rgba(126,231,135,.4); }
.tag-row.iso .tag-name { font-weight: 600; }
/* estado oculto */
.tag-row.hid { opacity: .5; }
.tag-row.hid .tag-name { text-decoration: line-through; }
.tag-row.hid .tag-hide { opacity: 1; color: var(--danger); }

/* barra "isolando: ..." */
.iso-bar { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-bottom: 8px; }
.iso-label { font-size: 10px; color: var(--fg-muted); text-transform: uppercase; letter-spacing: .5px; }
.iso-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 12px; padding: 2px 6px 2px 8px; font-size: 11px;
}
.iso-chip .iso-dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.iso-chip .iso-chip-name { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iso-chip .iso-x { background: none; border: none; color: var(--fg-muted); cursor: pointer; font-size: 10px; padding: 0; flex: 0 0 auto; }
.iso-chip .iso-x:hover { color: var(--danger); }
.iso-more {
  background: var(--bg-soft); border: 1px solid var(--border); color: var(--fg-dim);
  border-radius: 12px; padding: 2px 9px; font-size: 11px; cursor: pointer;
}
.iso-more:hover { border-color: var(--accent); color: var(--accent); }

/* modal de filtros ativos */
.fm-list { display: flex; flex-direction: column; gap: 5px; margin-top: 6px; }
.fm-row {
  display: flex; align-items: center; gap: 9px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px; font-size: 12.5px;
}
.fm-swatch { width: 10px; height: 10px; border-radius: 2px; flex: 0 0 auto; }
.fm-name { flex: 1 1 auto; min-width: 0; word-break: break-all; }
.fm-x { background: none; border: none; color: var(--fg-muted); cursor: pointer; font-size: 12px; flex: 0 0 auto; }
.fm-x:hover { color: var(--danger); }

/* ===== Coluna de log ===== */
.log-column { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.log-toolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.search-box {
  display: flex; align-items: center; gap: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  flex: 1 1 auto;
  max-width: 560px;
}
.search-box:focus-within { border-color: var(--fg-muted); }
.search-icon { color: var(--fg-muted); }
.search-input {
  flex: 1 1 auto;
  background: none; border: none; outline: none;
  color: var(--fg); font-family: var(--mono); font-size: 12px;
  padding: 5px 4px;
}
.search-input.invalid { color: var(--danger); }
.search-count { color: var(--fg-muted); font-size: 11px; white-space: nowrap; padding: 0 4px; }
.search-opt {
  display: inline-flex; align-items: center; gap: 3px;
  color: var(--fg-dim); font-size: 11px; cursor: pointer; padding: 0 2px;
}
.search-opt input { margin: 0; accent-color: var(--accent); }
.toolbar-opt {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--fg-dim); font-size: 12px; cursor: pointer;
}
.toolbar-opt input { accent-color: var(--accent); }

/* ===== Virtual scroll ===== */
.viewport {
  flex: 1 1 auto;
  position: relative;
  overflow: auto;
  outline: none;
  background: var(--bg);
}
.spacer { width: 1px; }
.rows { position: absolute; top: 0; left: 0; font-family: var(--mono); font-size: 12.5px; }
.log-row {
  position: absolute;
  left: 0;
  width: 100%;
  display: flex;
  height: var(--row-h);
  line-height: var(--row-h);
  white-space: pre;
}
.viewport.wrap .log-row { height: auto; white-space: pre-wrap; word-break: break-word; }
.log-row:hover { background: var(--bg-soft); }
.log-row:hover .ln { background: var(--bg-soft); }
.log-row.cur-match { background: rgba(227,179,65,.14); }
.ln {
  position: sticky;
  left: 0;
  z-index: 1;
  flex: 0 0 auto;
  width: 56px;
  padding-right: 12px;
  text-align: right;
  color: var(--fg-muted);
  user-select: none;
  background: var(--bg);
  border-right: 1px solid var(--border-soft);
  margin-right: 12px;
}
.lt { flex: 1 1 auto; padding-right: 16px; }
.viewport.wrap .lt { white-space: pre-wrap; word-break: break-word; }

/* níveis de severidade aplicam um leve tom à linha */
.log-row[data-lvl] .lt { color: var(--fg); }
.tag { font-weight: 500; }
.tag.dim { color: var(--fg-muted); font-weight: 400; }
.hl { background: rgba(88,166,255,.28); border-radius: 2px; }
.hl.cur { background: var(--accent-amber); color: #1a1205; }

.empty-state {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--fg-muted); font-size: 13px;
}

/* ===== Loading ===== */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(8,11,16,.72);
  backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.loading-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 36px;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  min-width: 280px;
}
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--fg-dim); font-size: 12px; }
.progress-track {
  width: 100%; height: 6px;
  background: var(--bg-soft);
  border-radius: 4px; overflow: hidden;
}
.progress-bar { height: 100%; width: 0%; background: var(--accent); transition: width .1s linear; }
.progress-pct { color: var(--accent); font-size: 12px; font-weight: 500; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(8,11,16,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 60;
}
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 540px; max-width: 92vw; max-height: 86vh;
  display: flex; flex-direction: column;
}
.modal-header, .modal-footer {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
}
.modal-header { border-bottom: 1px solid var(--border-soft); font-weight: 500; }
.modal-footer { border-top: 1px solid var(--border-soft); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.check-row {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 0; font-size: 12.5px; cursor: pointer; color: var(--fg);
}
.check-row input { accent-color: var(--accent); }
.check-row code { color: var(--accent-blue); background: var(--bg-soft); padding: 1px 5px; border-radius: 4px; }

.custom-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.custom-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 9px; font-size: 12px;
}
.custom-item .ci-swatch { width: 10px; height: 10px; border-radius: 2px; }
.custom-item .ci-name { font-weight: 500; }
.custom-item .ci-pat { color: var(--fg-muted); flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-item .ci-del { color: var(--danger); cursor: pointer; background: none; border: none; }
.custom-form { display: flex; gap: 6px; align-items: center; }
.color-input {
  width: 30px; height: 30px; padding: 0; border: 1px solid var(--border);
  border-radius: 5px; background: var(--bg-soft); cursor: pointer;
}
.custom-error { color: var(--danger); font-size: 11px; min-height: 14px; margin-top: 6px; }

.muted { color: var(--fg-muted); }
.small { font-size: 11px; }

/* scrollbars */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #283041; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #364152; }
[hidden] { display: none !important; }
