/* scope-agent console — flat, quiet, tool-like. */

:root {
  --bg: #0b0b0c;
  --s1: #101012;
  --s2: #16161a;
  --s3: #1d1d22;
  --line: #26262c;
  --line-soft: #1b1b20;
  --tx: #e9e9ec;
  --tx2: #9a9aa4;
  --tx3: #6b6b75;
  --acc: #6f9bff;
  --ok: #56c98a;
  --warn: #e0b25c;
  --bad: #e56a72;
  --r: 7px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
}

html[data-theme="light"] {
  --bg: #fbfbfc;
  --s1: #ffffff;
  --s2: #f4f5f7;
  --s3: #ebedf1;
  --line: #dfe2e8;
  --line-soft: #eceef2;
  --tx: #17181c;
  --tx2: #63666f;
  --tx3: #9498a3;
  --acc: #2f6bdd;
  --ok: #1f9d5f;
  --warn: #a97a18;
  --bad: #c8393f;
}

* { box-sizing: border-box; margin: 0; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--tx);
  font: 14px/1.55 -apple-system, "Segoe UI", Inter, Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); }
.muted { color: var(--tx2); }

/* ---------------- top bar ---------------- */

.bar {
  display: flex; align-items: center; justify-content: space-between;
  height: 44px; padding: 0 12px;
  border-bottom: 1px solid var(--line);
  background: var(--s1);
  flex: 0 0 auto;
}
.bar-left, .bar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mark { font-family: var(--mono); font-size: 13px; letter-spacing: .02em; color: var(--tx2); }
.sep { width: 1px; height: 16px; background: var(--line); }
.model-btn {
  display: flex; align-items: center; gap: 8px; padding: 4px 8px;
  border-radius: var(--r); max-width: 46vw; min-width: 0;
}
.model-btn:hover { background: var(--s2); }
.model-btn span:first-child {
  font-family: var(--mono); font-size: 13px; color: var(--tx);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.caret { color: var(--tx3); font-size: 10px; }
.conn { font-family: var(--mono); font-size: 11px; color: var(--tx3); }
.conn.ok { color: var(--ok); }
.conn.bad { color: var(--bad); }
.tbtn { padding: 4px 9px; border-radius: var(--r); color: var(--tx2); font-size: 12px; }
.tbtn:hover { background: var(--s2); color: var(--tx); }
.tbtn.icon { width: 26px; padding: 4px 0; text-align: center; }

/* ---------------- layout ---------------- */

.shell { flex: 1; display: grid; grid-template-columns: 252px 1fr; min-height: 0; }

.rail {
  border-right: 1px solid var(--line);
  background: var(--s1);
  display: flex; flex-direction: column; min-height: 0;
}
.search {
  margin: 10px; padding: 6px 9px;
  background: var(--s2); border: 1px solid var(--line); border-radius: var(--r);
  font-family: var(--mono); font-size: 12px; outline: none;
}
.search:focus { border-color: var(--acc); }
.search::placeholder { color: var(--tx3); }

.models { flex: 1; overflow-y: auto; padding: 0 6px 8px; }
.models::-webkit-scrollbar { width: 8px; }
.models::-webkit-scrollbar-thumb { background: var(--s3); border-radius: 8px; }

.mi { padding: 5px 8px; border-radius: var(--r); cursor: pointer; border-left: 2px solid transparent; }
.mi:hover { background: var(--s2); }
.mi.on { background: var(--s2); border-left-color: var(--acc); }
.mi .n { font-family: var(--mono); font-size: 12px; color: var(--tx2); line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mi.on .n { color: var(--tx); }
.mi .c { font-size: 10px; color: var(--tx3); font-family: var(--mono); }
.mi.off .n { color: var(--tx3); text-decoration: line-through; }

.rail-foot { border-top: 1px solid var(--line); padding: 6px; display: flex; flex-direction: column; }
.lbtn {
  display: flex; justify-content: space-between; align-items: center;
  padding: 5px 8px; border-radius: var(--r); color: var(--tx2); font-size: 12px;
}
.lbtn:hover { background: var(--s2); color: var(--tx); }
kbd {
  font-family: var(--mono); font-size: 10px; color: var(--tx3);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 4px;
}

/* ---------------- chat ---------------- */

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }

.messages { flex: 1; overflow-y: auto; padding: 26px 0 10px; }
.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-thumb { background: var(--s3); border-radius: 8px; }

.wrap { max-width: 780px; margin: 0 auto; padding: 0 22px; }

.empty { max-width: 640px; margin: 12vh auto 0; padding: 0 22px; }
.empty h1 { font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.empty p { color: var(--tx2); margin-top: 6px; font-size: 13px; }
.empty dl { margin-top: 22px; border-top: 1px solid var(--line); }
.empty dt {
  font-family: var(--mono); font-size: 11px; color: var(--tx3);
  padding: 12px 0 4px; text-transform: uppercase; letter-spacing: .08em;
}
.empty dd { color: var(--tx2); font-size: 13px; padding-bottom: 12px; border-bottom: 1px solid var(--line-soft); }
.empty dd code { font-family: var(--mono); color: var(--tx); font-size: 12px; }

.row-msg { display: grid; grid-template-columns: 96px 1fr; gap: 14px; padding: 9px 0; align-items: start; }
.row-msg .who { font-family: var(--mono); font-size: 11px; color: var(--tx3); padding-top: 2px; text-align: right; overflow-wrap: anywhere; }
.row-msg.user .who { color: var(--tx2); }
.row-msg .body { min-width: 0; }
.row-msg.err .body { color: var(--bad); }
.txt { white-space: normal; word-break: break-word; }
.txt > *:first-child { margin-top: 0; }
.txt > *:last-child { margin-bottom: 0; }
.txt p { margin: 0 0 10px; }
.txt code, .txt .inline-code {
  font-family: var(--mono); font-size: 12.5px;
  background: var(--s2); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px;
}
.txt a { color: var(--acc); text-decoration: none; border-bottom: 1px solid var(--line); }
.txt a:hover { border-bottom-color: var(--acc); }
.txt h1, .txt h2, .txt h3, .txt h4 { margin: 16px 0 6px; line-height: 1.3; font-weight: 600; }
.txt h1 { font-size: 17px; }
.txt h2 { font-size: 15px; }
.txt h3 { font-size: 14px; }
.txt h4 { font-size: 13.5px; color: var(--tx2); }
.txt ul, .txt ol { margin: 6px 0 10px; padding-left: 22px; }
.txt li { margin: 2px 0; }
.txt li > ul, .txt li > ol { margin: 2px 0; }
.txt li::marker { color: var(--tx3); }
.txt li input[type=checkbox] { margin-right: 6px; accent-color: var(--acc); }
.txt blockquote {
  margin: 8px 0; padding: 2px 0 2px 12px;
  border-left: 2px solid var(--line); color: var(--tx2);
}
.txt hr { border: none; border-top: 1px solid var(--line); margin: 16px 0; }
.txt img { max-width: 100%; border-radius: var(--r); border: 1px solid var(--line); }
.txt del { color: var(--tx3); }
.txt kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

.codebox { margin: 10px 0; border: 1px solid var(--line); border-radius: var(--r); background: var(--s1); overflow: hidden; }
.codehead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 10px; border-bottom: 1px solid var(--line); background: var(--s2);
}
.codehead span { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: var(--tx3); }
.codehead button { font-family: var(--mono); font-size: 10.5px; color: var(--tx3); padding: 2px 4px; }
.codehead button:hover { color: var(--tx); }
.codebox pre { margin: 0; border: none; border-radius: 0; background: none; padding: 10px 12px; overflow-x: auto; }
.codebox pre code { background: none; border: none; padding: 0; font-size: 12.5px; line-height: 1.55; display: block; white-space: pre; }

.tablewrap { overflow-x: auto; margin: 10px 0; border: 1px solid var(--line); border-radius: var(--r); }
.tablewrap table { border-collapse: collapse; width: 100%; font-size: 13px; }
.tablewrap th { background: var(--s2); font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--tx3); font-weight: 500; }
.tablewrap th, .tablewrap td { padding: 7px 10px; border-bottom: 1px solid var(--line-soft); text-align: left; }
.tablewrap tr:last-child td { border-bottom: none; }
.blink::after { content: "▍"; color: var(--tx3); animation: bl 1.1s steps(2) infinite; }
@keyframes bl { 50% { opacity: 0; } }

.tools { display: flex; gap: 10px; margin-top: 4px; opacity: 0; transition: opacity .12s; }
.row-msg:hover .tools { opacity: 1; }
.tools button { font-size: 11px; color: var(--tx3); font-family: var(--mono); }
.tools button:hover { color: var(--tx); }
.stat { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--tx3); }

/* ---------------- composer ---------------- */

.composer { flex: 0 0 auto; padding: 8px 0 12px; background: var(--bg); }
.chips { max-width: 780px; margin: 0 auto 8px; padding: 0 22px; display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 12px; color: var(--tx2); border: 1px solid var(--line);
  border-radius: var(--r); padding: 3px 8px; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chip:hover { border-color: var(--tx3); color: var(--tx); }

.input-box {
  max-width: 780px; margin: 0 auto; padding: 10px 12px;
  display: grid; grid-template-columns: 1fr auto; grid-template-areas: "ta send" "tools send";
  gap: 8px; align-items: end;
  background: var(--s1); border: 1px solid var(--line); border-radius: 10px;
}
.input-box:focus-within { border-color: var(--tx3); }
#prompt {
  grid-area: ta; resize: none; border: none; outline: none; background: none;
  max-height: 200px; min-height: 24px; font-size: 14px; line-height: 1.5;
}
#prompt::placeholder { color: var(--tx3); }
.input-tools { grid-area: tools; display: flex; gap: 12px; align-items: center; }
.chk { font-family: var(--mono); font-size: 11px; color: var(--tx3); display: flex; gap: 4px; align-items: center; cursor: pointer; }
.num { font-family: var(--mono); font-size: 11px; color: var(--tx3); display: flex; gap: 5px; align-items: center; }
.num input {
  width: 54px; background: var(--s2); border: 1px solid var(--line);
  border-radius: 5px; padding: 2px 5px; font-family: var(--mono); font-size: 11px; outline: none;
}
.num input:focus { border-color: var(--tx3); }
.send {
  grid-area: send; width: 34px; height: 34px; border-radius: 8px;
  background: var(--s3); color: var(--tx); font-size: 14px;
}
.send:hover { background: var(--tx); color: var(--bg); }
.send.stop { background: var(--bad); color: #fff; }
.send:disabled { opacity: .35; cursor: not-allowed; }
.hint { max-width: 780px; margin: 6px auto 0; padding: 0 22px; font-size: 11px; color: var(--tx3); font-family: var(--mono); min-height: 14px; }

/* ---------------- modal ---------------- */

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-start; justify-content: center; padding: 9vh 16px 16px; z-index: 50; }
.sheet {
  width: min(680px, 100%); max-height: 78vh; display: flex; flex-direction: column;
  background: var(--s1); border: 1px solid var(--line); border-radius: 10px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.sheet-body { padding: 14px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.f { display: flex; flex-direction: column; gap: 4px; }
.f > label { font-family: var(--mono); font-size: 11px; color: var(--tx3); }
.f input[type=text], .f input[type=password], .f input[type=number], .f select, .f textarea {
  background: var(--s2); border: 1px solid var(--line); border-radius: var(--r);
  padding: 7px 9px; outline: none; width: 100%; font-size: 13px;
}
.f textarea { font-family: var(--mono); font-size: 12px; resize: vertical; min-height: 70px; }
.f input:focus, .f textarea:focus, .f select:focus { border-color: var(--tx3); }
.r2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.r3 { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 10px; align-items: end; }
.act { display: flex; gap: 8px; align-items: center; }
.pri { background: var(--tx); color: var(--bg); padding: 7px 13px; border-radius: var(--r); font-size: 13px; font-weight: 500; }
.pri:hover { opacity: .88; }
.sec { border: 1px solid var(--line); color: var(--tx2); padding: 7px 13px; border-radius: var(--r); font-size: 13px; }
.sec:hover { color: var(--tx); border-color: var(--tx3); }
.note { border: 1px solid var(--line); border-left: 2px solid var(--acc); border-radius: var(--r); padding: 9px 11px; font-size: 12.5px; color: var(--tx2); word-break: break-all; }
.sec-title {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: .09em; color: var(--tx3); border-top: 1px solid var(--line); padding-top: 12px;
}
.sec-title:first-child { border-top: none; padding-top: 0; }

table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { text-align: left; font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--tx3); font-weight: 400; padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 7px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
td .mono, .mono { font-family: var(--mono); font-size: 11.5px; }
.lnk { color: var(--acc); font-size: 11.5px; font-family: var(--mono); }
.lnk:hover { text-decoration: underline; }
.on { color: var(--ok); }
.off { color: var(--bad); }

/* ---------------- toasts ---------------- */

.toasts { position: fixed; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 6px; z-index: 60; }
.toast {
  background: var(--s2); border: 1px solid var(--line); border-left: 2px solid var(--tx3);
  border-radius: var(--r); padding: 8px 12px; font-size: 12.5px; max-width: 380px;
  animation: in .14s ease;
}
.toast.bad { border-left-color: var(--bad); color: var(--bad); }
.toast.ok { border-left-color: var(--ok); }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .rail { position: absolute; inset: 44px auto 0 0; width: 252px; z-index: 30; transform: translateX(-100%); transition: transform .16s; }
  .rail.open { transform: none; }
  .row-msg { grid-template-columns: 1fr; gap: 2px; }
  .row-msg .who { text-align: left; }
}