/* ============================================================
   OraScope — Design System
   ============================================================ */
:root {
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 16px;
  --sidebar-w: 248px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace;
  --shadow: 0 1px 2px rgba(0,0,0,.18), 0 8px 24px rgba(0,0,0,.16);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.16);
  --t: 160ms cubic-bezier(.4,0,.2,1);
}

/* ---------- Tema escuro (padrão) ---------- */
[data-theme="dark"] {
  --bg: #0c1018;
  --bg-elev: #131a26;
  --bg-elev2: #1a2434;
  --panel: #131a26;
  --border: #233044;
  --border-soft: #1b2535;
  --text: #e6edf6;
  --text-dim: #9fb0c6;
  --text-mute: #6c7f99;
  --accent: #4f8cff;
  --accent-soft: #1b3358;
  --good: #34d399;
  --good-soft: #0f3d31;
  --warn: #fbbf24;
  --warn-soft: #3d3413;
  --bad: #f87171;
  --bad-soft: #3d1f24;
  --crit: #e879f9;
  --crit-soft: #3a1b3d;
}
/* ---------- Tema claro ---------- */
[data-theme="light"] {
  --bg: #f3f5f9;
  --bg-elev: #ffffff;
  --bg-elev2: #f7f9fc;
  --panel: #ffffff;
  --border: #dde3ec;
  --border-soft: #e8edf4;
  --text: #16202e;
  --text-dim: #4d5e74;
  --text-mute: #8294a9;
  --accent: #2f6bff;
  --accent-soft: #e2ecff;
  --good: #0f9e6e;
  --good-soft: #d8f5ea;
  --warn: #b8810a;
  --warn-soft: #fbf0d4;
  --bad: #d6463f;
  --bad-soft: #fbe1e0;
  --crit: #a838c0;
  --crit-soft: #f6e2fb;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--accent); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-mute); }

/* ============================================================ LAYOUT */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px; }
.brand__logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  color: #fff; font-weight: 800; font-size: 20px;
  display: grid; place-items: center;
  box-shadow: 0 6px 16px rgba(79,140,255,.35);
}
.brand__txt { display: flex; flex-direction: column; line-height: 1.15; }
.brand__txt strong { font-size: 16px; }
.brand__txt span { font-size: 11.5px; color: var(--text-mute); }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; }
.nav__item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); cursor: pointer; border: 1px solid transparent;
  transition: background var(--t), color var(--t);
  user-select: none; font-weight: 500;
}
.nav__item:hover { background: var(--bg-elev2); color: var(--text); }
.nav__item.active { background: var(--accent-soft); color: var(--text); border-color: var(--border); }
.nav__item .ico { width: 20px; text-align: center; font-size: 16px; opacity: .95; }
.nav__item .lbl { flex: 1; }
.nav__item .count {
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 20px;
  background: var(--bg); color: var(--text-dim); border: 1px solid var(--border);
}
.nav__item.active .count { background: var(--accent); color: #fff; border-color: transparent; }

.sidebar__foot { display: flex; flex-direction: column; gap: 8px; }
.ai-chip {
  display: flex; align-items: center; gap: 8px; font-size: 12px;
  color: var(--text-dim); padding: 7px 10px; border-radius: 20px;
  background: var(--bg); border: 1px solid var(--border);
}
.ai-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-mute); }
.ai-chip.on .dot { background: var(--good); box-shadow: 0 0 8px var(--good); }
.iconbtn {
  text-align: left; background: transparent; border: 1px solid transparent;
  color: var(--text-dim); padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13px; transition: background var(--t), color var(--t);
}
.iconbtn:hover { background: var(--bg-elev2); color: var(--text); }

/* ---------- Main ---------- */
.main { display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  background: var(--bg-elev); flex-wrap: wrap;
}
.topbar__title h1 { font-size: 19px; }
.topbar__title p { margin: 2px 0 0; color: var(--text-mute); font-size: 12.5px; }
.topbar__actions { display: flex; align-items: center; gap: 12px; }
.filechips { display: flex; gap: 6px; flex-wrap: wrap; max-width: 420px; }
.filechip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; padding: 4px 9px; border-radius: 20px;
  background: var(--bg); border: 1px solid var(--border); color: var(--text-dim);
}
.filechip .x { cursor: pointer; opacity: .6; font-weight: 700; }
.filechip .x:hover { opacity: 1; color: var(--bad); }
.filechip .k { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }

.view { padding: 24px; overflow-y: auto; flex: 1; }

/* ============================================================ COMPONENTES */
.btn {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg-elev2); color: var(--text);
  padding: 9px 15px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  transition: filter var(--t), background var(--t), border var(--t);
}
.btn:hover { filter: brightness(1.08); }
.btn--primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn--ghost { background: transparent; }
.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn--ai { background: linear-gradient(135deg,#7c5cff,#4f8cff); border-color: transparent; color:#fff; }

/* KPI cards */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--gap); }
.kpi {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden;
}
.kpi__label { font-size: 12px; color: var(--text-mute); display: flex; align-items: center; gap: 7px; }
.kpi__value { font-size: 28px; font-weight: 750; margin-top: 6px; letter-spacing: -.02em; }
.kpi__sub { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }
.kpi__accent { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.kpi--good .kpi__accent { background: var(--good); } .kpi--good .kpi__value { color: var(--good); }
.kpi--bad  .kpi__accent { background: var(--bad);  } .kpi--bad  .kpi__value { color: var(--bad); }
.kpi--warn .kpi__accent { background: var(--warn); }

/* Panels / cards */
.grid { display: grid; gap: var(--gap); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1100px) { .grid--2, .grid--3 { grid-template-columns: 1fr; } }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); display: flex; flex-direction: column; overflow: hidden;
}
.card__head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border-soft);
}
.card__head h3 { font-size: 14.5px; }
.card__head .hint { font-size: 11.5px; color: var(--text-mute); font-weight: 400; }
.card__body { padding: 16px 18px; }
.card__body--flush { padding: 0; }
.chart { width: 100%; height: 300px; }
.chart--sm { height: 240px; }
.chart--lg { height: 380px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab {
  padding: 9px 14px; cursor: pointer; color: var(--text-dim); font-weight: 600; font-size: 13px;
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color var(--t);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Time-window filter */
.windowbar { display: flex; gap: 6px; flex-wrap: wrap; }
.windowbar button {
  background: var(--bg-elev2); border: 1px solid var(--border); color: var(--text-dim);
  padding: 6px 12px; border-radius: 20px; cursor: pointer; font-size: 12.5px; font-weight: 600;
  transition: all var(--t);
}
.windowbar button:hover { color: var(--text); }
.windowbar button.active { background: var(--accent); color: #fff; border-color: transparent; }

/* Tabelas */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; padding: 10px 14px; color: var(--text-mute); font-weight: 600;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel);
  white-space: nowrap; cursor: pointer; user-select: none;
}
table.tbl th:hover { color: var(--text); }
table.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
table.tbl tr:hover td { background: var(--bg-elev2); }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); white-space: nowrap; }
.bar-cell { position: relative; }
.bar-cell .fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent-soft); z-index: 0; }
.bar-cell > span { position: relative; z-index: 1; }

.tbl-toolbar { display: flex; justify-content: flex-end; padding: 0 0 10px; }
.help-i { cursor: help; color: var(--text-mute); font-size: 11.5px; margin-left: 5px; font-weight: 400; }
.help-i:hover { color: var(--accent); }

/* Glossário */
.gloss-search { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; color: var(--text); font-size: 13px; margin-bottom: 14px; }
.gloss-term { padding: 11px 0; border-bottom: 1px solid var(--border-soft); }
.gloss-term dt { font-weight: 650; color: var(--text); margin-bottom: 3px; }
.gloss-term dt .tag { font-size: 10.5px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 1px 7px; border-radius: 20px; margin-left: 8px; text-transform: uppercase; }
.gloss-term dd { margin: 0; color: var(--text-dim); font-size: 13px; }

/* Plano de execução visual (TKPROF) */
.plan { font-family: var(--mono); font-size: 12px; }
.plan-row { display: flex; justify-content: space-between; gap: 12px; padding: 5px 8px; border-radius: 6px; align-items: center; }
.plan-row:hover { background: var(--bg-elev2); }
.plan-row--worst { background: var(--bad-soft); }
.plan-op { display: flex; align-items: center; gap: 8px; min-width: 0; }
.plan-bar { display: inline-block; height: 8px; background: var(--accent); border-radius: 4px; min-width: 2px; flex: none; }
.plan-row--worst .plan-bar { background: var(--bad); }
.plan-meta { color: var(--text-mute); white-space: nowrap; font-size: 11px; flex: none; }
.suggest { list-style: none; padding: 0; margin: 8px 0 0; }
.suggest li { padding: 8px 12px; background: var(--bg-elev2); border-left: 3px solid var(--accent); border-radius: 6px; margin-bottom: 7px; font-size: 13px; }

/* Chat IA */
.chat-msgs { max-height: 52vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px; }
.chat-msg { display: flex; }
.chat-msg--user { justify-content: flex-end; }
.chat-bubble { max-width: 82%; padding: 10px 14px; border-radius: 12px; font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; }
.chat-msg--user .chat-bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg--ai .chat-bubble { background: var(--bg-elev2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

/* Busca global */
.search-hit { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); margin-bottom: 8px; cursor: pointer; transition: background var(--t), border var(--t); }
.search-hit:hover { background: var(--bg-elev2); border-color: var(--border); }
.search-hit__ico { font-size: 18px; }
.search-hit__t { font-weight: 600; font-size: 13.5px; }
.search-hit__s { font-size: 12px; color: var(--text-mute); }
.search-hit__go { margin-left: auto; color: var(--accent); font-size: 12px; font-weight: 600; }

/* Badges de severidade */
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700;
  padding: 2px 9px; border-radius: 20px; white-space: nowrap;
}
.badge--good { background: var(--good-soft); color: var(--good); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--bad  { background: var(--bad-soft);  color: var(--bad); }
.badge--crit { background: var(--crit-soft); color: var(--crit); }
.badge--info { background: var(--accent-soft); color: var(--accent); }
.mono { font-family: var(--mono); font-size: 12.5px; }

/* Empty state */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 60px 24px; color: var(--text-dim); gap: 10px;
}
.empty__icon {
  width: 76px; height: 76px; border-radius: 20px; display: grid; place-items: center;
  background: var(--bg-elev2); border: 1px solid var(--border); font-size: 34px; margin-bottom: 6px;
}
.empty h2 { font-size: 18px; color: var(--text); }
.empty p { max-width: 460px; }
.empty .dropcta {
  margin-top: 10px; border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 22px 30px; cursor: pointer; transition: border var(--t), background var(--t); color: var(--text-dim);
}
.empty .dropcta:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.muted { color: var(--text-mute); }

/* Solução / KB callout */
.kb {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 12px;
  background: var(--bg-elev2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; font-size: 13px; margin-top: 8px;
}
.kb dt { color: var(--text-mute); font-weight: 600; font-size: 11.5px; text-transform: uppercase; }
.kb dd { margin: 0; }

/* Listas de detalhe (trace) */
pre.code {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px; overflow: auto; font-family: var(--mono); font-size: 12px; color: var(--text-dim);
  max-height: 360px; margin: 0;
}

/* ============================================================ DROPZONE OVERLAY */
.dropzone {
  position: fixed; inset: 0; background: rgba(8,11,18,.78); backdrop-filter: blur(3px);
  display: none; place-items: center; z-index: 100;
}
.dropzone.show { display: grid; }
.dropzone__inner {
  border: 3px dashed var(--accent); border-radius: 20px; padding: 60px 90px; text-align: center;
  color: #fff; background: rgba(79,140,255,.08);
}
.dropzone__icon { font-size: 56px; animation: bob 1.2s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(8px); } }
.dropzone h2 { font-size: 24px; margin: 8px 0 4px; }
.dropzone p { color: #b9c6da; font-family: var(--mono); font-size: 13px; }

/* ============================================================ PROGRESSO */
.progress {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px);
  width: min(440px, 92vw); background: var(--bg-elev2); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; z-index: 250;
  opacity: 0; pointer-events: none; transition: opacity var(--t), transform var(--t);
}
.progress.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.progress__row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 12.5px; }
.progress__label { color: var(--text); font-weight: 600; }
.progress__pct { color: var(--text-dim); font-family: var(--mono); }
.progress__track { height: 7px; background: var(--bg); border-radius: 20px; overflow: hidden; }
.progress__bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #7c5cff); border-radius: 20px; transition: width 120ms linear; }

/* ============================================================ TOASTS */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  background: var(--bg-elev2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 12px 16px; box-shadow: var(--shadow); min-width: 260px;
  font-size: 13px; animation: slidein var(--t); }
.toast--good { border-left-color: var(--good); }
.toast--bad { border-left-color: var(--bad); }
.toast strong { display: block; margin-bottom: 2px; }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }

/* ============================================================ MODAL */
.modal-bg {
  position: fixed; inset: 0; background: rgba(6,9,14,.6); display: none; place-items: center; z-index: 300;
  backdrop-filter: blur(2px);
}
.modal-bg.show { display: grid; }
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  width: min(680px, 92vw); max-height: 88vh; overflow: auto; box-shadow: var(--shadow);
}
.modal__head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal__head h3 { font-size: 16px; }
.modal__body { padding: 20px; }
.modal__close { cursor: pointer; font-size: 20px; color: var(--text-mute); background: none; border: none; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; color: var(--text); font-size: 13px; font-family: var(--font);
}
.field textarea { font-family: var(--mono); min-height: 90px; resize: vertical; }
.field .help { font-size: 11.5px; color: var(--text-mute); margin-top: 5px; }
