/* DevSapience admin console — dark, dense, no external assets. */

:root {
  --bg:          #070c14;
  --bg-2:        #0b111b;
  --surface:     #0e1520;
  --surface-2:   #161f2c;
  --line:        #212c3b;
  --line-2:      #2e3c4e;
  --text:        #e6ecf3;
  --muted:       #8b9aab;
  --accent:      #4fd1b8;
  --accent-ink:  #7ee0cc;
  --accent-soft: rgba(79, 209, 184, 0.12);
  --warn:        #f0b45f;
  --bad:         #f0736a;
  --good:        #4fd1b8;
  --radius:      12px;
  --rail:        228px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.9em; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.spacer { margin-left: auto; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ── rail ──────────────────────────────────────────────────────────────── */

.rail {
  position: fixed; inset: 0 auto 0 0; width: var(--rail);
  background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 1.1rem 0.9rem; gap: 1.4rem;
}
.brand { display: flex; align-items: center; gap: 0.6rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand .mark { width: 34px; height: 34px; color: var(--accent); flex: none; }
.brand .mark svg { width: 34px; height: 34px; display: block; }
.brand .word { display: flex; flex-direction: column; line-height: 1.15; }
.brand .word b { font-size: 0.95rem; font-weight: 700; letter-spacing: -0.01em; }
.brand .word span { font-size: 0.63rem; text-transform: uppercase; letter-spacing: 0.11em; color: var(--muted); }

.rail nav { display: flex; flex-direction: column; gap: 2px; }
.rail nav a {
  padding: 0.5rem 0.7rem; border-radius: 8px; color: var(--muted);
  font-size: 0.91rem; font-weight: 500;
}
.rail nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.rail nav a.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

.who { margin-top: auto; border-top: 1px solid var(--line); padding-top: 0.9rem; font-size: 0.85rem; }
.who-name { font-weight: 600; }
.who-role { margin: 0.35rem 0 0.5rem; }
.who-link { display: block; color: var(--muted); }
.linkish {
  background: none; border: 0; padding: 0; color: var(--muted);
  font: inherit; cursor: pointer; text-align: left;
}
.linkish:hover { color: var(--accent-ink); text-decoration: underline; }
.inline { display: inline; }

/* ── layout ────────────────────────────────────────────────────────────── */

.shell { margin-left: var(--rail); padding: 1.6rem 1.8rem 4rem; max-width: 1500px; }
.bare { padding: 0; }
.page { padding: 3rem 1.8rem; max-width: 44rem; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem;
}
.page-head h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.02em; }
.lede { margin: 0.25rem 0 0; color: var(--muted); font-size: 0.94rem; }
.head-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

h2.section {
  margin: 2.2rem 0 0.9rem; font-size: 0.74rem; font-weight: 700;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted);
}

/* ── filters ───────────────────────────────────────────────────────────── */

.filters {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.9rem 1rem; margin-bottom: 1.3rem;
}
.filter-row { display: flex; gap: 0.9rem; align-items: flex-end; flex-wrap: wrap; }
.filters label, .adv-grid label, .stack label {
  display: flex; flex-direction: column; gap: 0.25rem;
  font-size: 0.74rem; font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--muted);
}
.filters label.check {
  flex-direction: row; align-items: center; gap: 0.4rem; text-transform: none;
  letter-spacing: 0; font-size: 0.86rem; font-weight: 500;
}
select, input[type=text], input[type=date], input[type=search], input[type=email], input[type=password], input:not([type]) {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line-2); border-radius: 8px;
  padding: 0.42rem 0.6rem; font: inherit; font-size: 0.88rem; min-width: 8rem;
}
select[multiple] { min-height: 6rem; padding: 0.3rem; }
input[type=checkbox] { accent-color: var(--accent); }

.advanced { flex-basis: 100%; margin-top: 0.4rem; }
.advanced summary {
  cursor: pointer; font-size: 0.82rem; color: var(--accent-ink);
  font-weight: 600; padding: 0.2rem 0;
}
.adv-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 0.8rem; margin: 0.7rem 0;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-top: 0.8rem; }
.chip {
  display: inline-flex; gap: 0.35rem; align-items: center;
  background: var(--accent-soft); border: 1px solid rgba(79,209,184,0.28);
  color: var(--accent-ink); border-radius: 999px;
  padding: 0.15rem 0.6rem; font-size: 0.78rem;
}
.chip:hover { text-decoration: none; background: rgba(79,209,184,0.2); }
.chip span { opacity: 0.7; }
.chip.clear { background: none; border-color: var(--line-2); color: var(--muted); }

/* ── buttons ───────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line-2); border-radius: 8px;
  padding: 0.5rem 0.9rem; font: inherit; font-size: 0.88rem; font-weight: 600;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent-ink); text-decoration: none; }
.btn.small { padding: 0.34rem 0.65rem; font-size: 0.82rem; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06110e; }
.btn.primary:hover { background: var(--accent-ink); color: #06110e; }

/* ── cards, KPIs ───────────────────────────────────────────────────────── */

.grid { display: grid; gap: 1rem; margin-bottom: 1rem; }
.grid.two   { grid-template-columns: repeat(auto-fit, minmax(23rem, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.1rem; min-width: 0;
}
.card.wide { margin-bottom: 1rem; }
.card-head { margin-bottom: 0.8rem; }
.card-head h2 { margin: 0; font-size: 0.95rem; font-weight: 700; letter-spacing: -0.01em; }
.card-head p { margin: 0.15rem 0 0; font-size: 0.8rem; color: var(--muted); }

.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(11.5rem, 1fr));
  gap: 0.75rem; margin-bottom: 1.2rem;
}
.kpi-grid.tight { margin-bottom: 0.8rem; }
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.8rem 0.9rem;
}
.kpi.warn { border-color: rgba(240,180,95,0.45); }
.kpi-label {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--muted);
}
.kpi-value {
  font-size: 1.5rem; font-weight: 750; letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums; margin: 0.2rem 0 0.1rem;
}
.kpi-sub { font-size: 0.78rem; color: var(--muted); }
.delta { font-weight: 700; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }

/* ── charts ────────────────────────────────────────────────────────────── */

.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart .pt circle { opacity: 0; transition: opacity 0.1s; }
.chart .pt:hover circle { opacity: 1; }
.chart-empty {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 0.85rem;
  border: 1px dashed var(--line-2); border-radius: 8px;
}
.donut { width: 100%; max-width: 168px; margin: 0 auto 0.6rem; display: block; }
.donut-total { fill: var(--text); font-size: 20px; font-weight: 700; }
.donut-cap { fill: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: 0.1em; }

/* ── bar lists ─────────────────────────────────────────────────────────── */

.barlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.bl-head { display: flex; justify-content: space-between; gap: 0.6rem; font-size: 0.85rem; }
.bl-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bl-value { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.bl-track { height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bl-track span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* ── tables ────────────────────────────────────────────────────────────── */

.table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
.table th {
  text-align: left; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
  padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--line-2); white-space: nowrap;
}
.table td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table.compact td, .table.compact th { padding: 0.35rem 0.5rem; }
.card > .table, .card > .tablewrap { margin-top: 0.2rem; }

.stats { display: grid; grid-template-columns: 1fr auto; gap: 0.3rem 1rem; margin: 0; font-size: 0.87rem; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ── pills, scores ─────────────────────────────────────────────────────── */

.pill {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line-2);
  font-size: 0.72rem; font-weight: 600; color: var(--muted); text-transform: lowercase;
}
.pill.ok { color: var(--good); border-color: rgba(79,209,184,0.4); background: rgba(79,209,184,0.1); }
.pill.warn { color: var(--warn); border-color: rgba(240,180,95,0.4); background: rgba(240,180,95,0.1); }
.pill.bad { color: var(--bad); border-color: rgba(240,115,106,0.4); background: rgba(240,115,106,0.1); }

.role-pill {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: 6px;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  background: var(--surface-2); border: 1px solid var(--line-2); color: var(--muted);
}
.role-pill.role-ceo { background: rgba(79,209,184,0.15); border-color: rgba(79,209,184,0.45); color: var(--accent-ink); }
.role-pill.role-admin { background: rgba(107,140,255,0.15); border-color: rgba(107,140,255,0.4); color: #9db3ff; }
.role-pill.role-support { background: rgba(240,180,95,0.13); border-color: rgba(240,180,95,0.35); color: var(--warn); }

.sev { font-weight: 700; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }
.sev-critical { color: #f0736a; }
.sev-high { color: #f0995f; }
.sev-medium { color: var(--warn); }
.sev-low, .sev-info { color: var(--muted); }

.score { font-weight: 700; }
.score.good, .good { color: var(--good); }
.score.warn { color: var(--warn); }
.score.bad, .bad { color: var(--bad); }
.tick { color: var(--good); font-weight: 700; }

/* ── alerts ────────────────────────────────────────────────────────────── */

.alert {
  border-radius: 8px; padding: 0.65rem 0.9rem; font-size: 0.88rem;
  border: 1px solid var(--line-2); background: var(--surface); margin: 0 0 1rem;
}
.alert.error { border-color: rgba(240,115,106,0.5); background: rgba(240,115,106,0.1); color: #ffb3ad; }
.alert.ok { border-color: rgba(79,209,184,0.45); background: rgba(79,209,184,0.1); color: var(--accent-ink); }
.alert.warn { border-color: rgba(240,180,95,0.45); background: rgba(240,180,95,0.1); color: #ffd9a1; }

/* ── login ─────────────────────────────────────────────────────────────── */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; }
.login {
  width: 100%; max-width: 23rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; padding: 1.8rem;
  display: grid; gap: 0.9rem;
}
.login-brand { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.5rem; }
.login-brand .mark { width: 40px; height: 40px; color: var(--accent); }
.login-brand .mark svg { width: 40px; height: 40px; }
.login-brand b { display: block; font-size: 1rem; }
.login-brand span { display: block; font-size: 0.66rem; text-transform: uppercase;
  letter-spacing: 0.12em; color: var(--muted); }
.login label {
  display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.74rem;
  font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted);
}
.login input { min-width: 0; }

/* ── feedback ──────────────────────────────────────────────────────────── */

.search {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem; margin-bottom: 1.2rem;
}
.search-row { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.search-input {
  flex: 1 1 22rem; font-size: 1rem !important; padding: 0.6rem 0.8rem !important;
}
.syntax { margin: 0.55rem 0 0; }
.syntax code {
  background: var(--surface-2); border: 1px solid var(--line-2);
  border-radius: 4px; padding: 0.05rem 0.32rem; font-size: 0.82em;
}
.search-adv { margin-top: 0.8rem; border-top: 1px solid var(--line); padding-top: 0.8rem; }

.feedback-layout { display: grid; grid-template-columns: 15rem minmax(0, 1fr); gap: 1.2rem; }
@media (max-width: 980px) { .feedback-layout { grid-template-columns: minmax(0, 1fr); } }

.facets { display: grid; gap: 1rem; align-content: start; }
.facet {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.75rem 0.9rem;
}
.facet h3 {
  margin: 0 0 0.5rem; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--muted);
}
.facet ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.28rem; font-size: 0.85rem; }
.facet li { display: flex; justify-content: space-between; gap: 0.5rem; }
.facet .count { color: var(--muted); font-variant-numeric: tabular-nums; }
.save-form {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.75rem 0.9rem; display: grid; gap: 0.5rem;
}

.results { display: grid; gap: 0.7rem; align-content: start; }
.result-count { margin: 0 0 0.2rem; color: var(--muted); font-size: 0.9rem; }
.fb {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.9rem 1rem;
}
.fb header { display: flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; margin-bottom: 0.4rem; }
.fb h3 { margin: 0 0 0.3rem; font-size: 1rem; letter-spacing: -0.01em; }
.snippet { margin: 0 0 0.5rem; font-size: 0.9rem; color: #c3ceda; }
.snippet mark { background: rgba(240,180,95,0.28); color: #ffe3b5; border-radius: 3px; padding: 0 2px; }
.fb-meta { display: flex; gap: 0.7rem; flex-wrap: wrap; font-size: 0.78rem; color: var(--muted); }
.fb-full { margin-top: 0.6rem; }
.fb-full summary { cursor: pointer; font-size: 0.83rem; color: var(--accent-ink); font-weight: 600; }
.body {
  white-space: pre-wrap; word-wrap: break-word; margin: 0.6rem 0;
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 0.7rem 0.85rem; font-size: 0.87rem;
  font-family: inherit; max-height: 30rem; overflow: auto;
}
.note { font-size: 0.86rem; color: var(--warn); margin: 0.4rem 0; }
.triage { display: flex; gap: 0.6rem; align-items: flex-end; flex-wrap: wrap; margin-top: 0.6rem; }
.triage label {
  display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.72rem;
  font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted);
}
.triage label.grow { flex: 1 1 16rem; }
.triage label.grow input { width: 100%; }

.empty { background: var(--surface); border: 1px dashed var(--line-2);
  border-radius: var(--radius); padding: 2rem 1.2rem; text-align: center; }
.empty h3 { margin: 0 0 0.4rem; font-size: 1rem; }

.pager { display: flex; gap: 0.8rem; align-items: center; justify-content: center; padding: 0.8rem 0; }

/* ── misc ──────────────────────────────────────────────────────────────── */

.stack { display: grid; gap: 0.8rem; }
.stack.narrow { max-width: 22rem; }
.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.actions select { min-width: 7rem; font-size: 0.8rem; padding: 0.2rem 0.4rem; }
.rolenotes { margin: 1rem 0 0; padding-left: 1.1rem; font-size: 0.85rem; color: var(--muted); }
.rolenotes strong { color: var(--text); }
.perms { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.3rem; font-size: 0.88rem; }
.perms li.no { color: var(--muted); }
.perms li.yes { color: var(--text); }

/* ── ask the data ──────────────────────────────────────────────────────── */

.chat-layout { display: grid; grid-template-columns: 17rem minmax(0, 1fr); gap: 1.2rem; }
@media (max-width: 1020px) { .chat-layout { grid-template-columns: minmax(0, 1fr); } }

.chat-rail { display: grid; gap: 1rem; align-content: start; }
.newchat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.9rem 1rem; display: grid; gap: 0.6rem;
}
.newchat select { width: 100%; }
.req {
  font-size: 0.62rem; color: var(--warn); border: 1px solid rgba(240,180,95,0.4);
  border-radius: 4px; padding: 0 0.3rem; margin-left: 0.3rem; letter-spacing: 0.04em;
}
.chat-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.25rem; }
.chat-list a { display: block; padding: 0.4rem 0.5rem; border-radius: 7px; color: var(--text); }
.chat-list a:hover { background: var(--surface-2); text-decoration: none; }
.chat-list li.on a { background: var(--accent-soft); }
.ct-title {
  display: block; font-size: 0.86rem; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.ct-meta { display: block; font-size: 0.72rem; color: var(--muted); }

.chat-main { display: grid; gap: 0.9rem; align-content: start; min-width: 0; }
.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 0.6rem 0.9rem;
}
.ch-title { margin-left: 0.5rem; font-size: 0.92rem; }

.thread { display: grid; gap: 1.1rem; }
.turn { display: grid; gap: 0.5rem; }
.bubble { border-radius: var(--radius); padding: 0.8rem 1rem; }
.bubble.you {
  background: var(--accent-soft); border: 1px solid rgba(79,209,184,0.28);
  color: var(--accent-ink); justify-self: end; max-width: 44rem; font-size: 0.93rem;
}
.bubble.bot { background: var(--surface); border: 1px solid var(--line); min-width: 0; }
.answer { margin: 0 0 0.7rem; font-size: 0.96rem; line-height: 1.6; }

.chat-chart {
  background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 0.8rem; margin: 0.7rem 0;
}
.chat-chart h4 {
  margin: 0 0 0.5rem; font-size: 0.78rem; font-weight: 700;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}

.rows, .sqlbox, .tracebox { margin-top: 0.6rem; }
.rows summary, .sqlbox summary, .tracebox summary {
  cursor: pointer; font-size: 0.8rem; font-weight: 600; color: var(--accent-ink);
  padding: 0.2rem 0;
}
.rows .tablewrap { max-height: 24rem; overflow: auto; margin-top: 0.4rem; }
.sql {
  margin: 0.4rem 0 0; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 0.7rem 0.85rem; overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem; color: #b8d8d0; white-space: pre-wrap; word-break: break-word;
}
.trace { margin: 0.4rem 0 0; padding-left: 1.2rem; font-size: 0.82rem; color: var(--muted); }
.trace li { margin-bottom: 0.2rem; }
.tstep {
  display: inline-block; min-width: 5.5rem; color: var(--accent-ink); font-weight: 600;
}
.bot-meta { margin-top: 0.6rem; padding-top: 0.5rem; border-top: 1px solid var(--line); }

.askbar { display: flex; gap: 0.6rem; }
.ask-input {
  flex: 1; font-size: 0.98rem !important; padding: 0.7rem 0.9rem !important; min-width: 0;
}
.asknote { margin: 0; }

.examples { background: var(--surface); border: 1px dashed var(--line-2);
  border-radius: var(--radius); padding: 0.9rem 1rem; }
.ex-grid { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-top: 0.5rem; }
.ex-grid .chip { border: 1px solid var(--line-2); background: var(--surface-2);
  color: var(--text); cursor: pointer; font: inherit; font-size: 0.82rem; }
.ex-grid .chip:hover { border-color: var(--accent); color: var(--accent-ink); }
