:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --panel-2: #f5f6f8;
  --border: #dcdfe6;
  --border-soft: #e6e8ee;
  --text: #1a1d24;
  --muted: #5b6270;
  --faint: #8b93a3;
  --accent: #6366f1;
  --accent-hover: #4f52e0;
  --green: #16a34a;
  --amber: #b45309;
  --red: #dc2626;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 19px; margin: 0 0 4px; letter-spacing: -0.2px; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--faint); margin: 0 0 12px; font-weight: 600; }
p.sub { color: var(--muted); margin: 0 0 16px; font-size: 13px; }

/* layout */
#shell { display: flex; min-height: 100vh; }
#sidebar {
  width: 210px; flex-shrink: 0; background: var(--panel-2);
  border-right: 1px solid var(--border-soft); padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
#sidebar .brand { font-weight: 700; font-size: 16px; padding: 4px 10px 18px; letter-spacing: -0.3px; }
#sidebar .brand span { color: var(--accent); }
#sidebar nav a {
  display: block; padding: 9px 12px; border-radius: 8px; color: var(--muted); font-size: 14px; margin-bottom: 2px;
}
#sidebar nav a:hover { background: #e9ebf1; color: var(--text); }
#sidebar nav a.active { background: #e2e5fb; color: var(--text); font-weight: 600; }
#sidebar .foot { position: absolute; bottom: 16px; left: 12px; right: 12px; font-size: 11px; color: var(--faint); padding: 0 10px; }
#main { flex: 1; padding: 26px 32px 60px; min-width: 0; }

/* components */
.panel { background: var(--panel); border: 1px solid var(--border-soft); border-radius: 12px; padding: 18px 20px; margin-bottom: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid2 .full { grid-column: 1 / -1; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } #sidebar { width: 64px; } #sidebar .brand, #sidebar nav a .lbl, #sidebar .foot { display: none; } }

/* agent editor: scrollable settings column + fixed call column on the right */
.editor-layout { display: flex; align-items: flex-start; gap: 20px; }
.editor-settings { flex: 1; min-width: 0; max-height: calc(100vh - 120px); overflow-y: auto; padding-right: 6px; }
.editor-call { width: 380px; flex-shrink: 0; position: sticky; top: 26px; }
@media (max-width: 1100px) {
  .editor-layout { flex-direction: column; }
  .editor-settings { max-height: none; overflow-y: visible; padding-right: 0; }
  .editor-call { width: 100%; position: static; }
}

button {
  background: var(--accent); color: #fff; border: none; padding: 8px 16px; border-radius: 8px;
  font-size: 13.5px; cursor: pointer; font-family: inherit;
}
button:hover { background: var(--accent-hover); }
button:disabled { background: #e2e4ea; color: #a4abb8; cursor: not-allowed; }
button.ghost { background: #eef0f4; color: var(--text); }
button.ghost:hover { background: #e2e5ec; }
button.danger { background: #fbe2e2; color: #b42318; }
button.danger:hover { background: #f6cccc; }
button.ok { background: #dcf5e3; color: #15803d; }
button.mini { padding: 5px 11px; font-size: 12.5px; border-radius: 6px; }

input, select, textarea {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  padding: 8px 11px; border-radius: 8px; font-size: 13.5px; font-family: inherit; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; line-height: 1.5; }
textarea.code { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
label.fl { display: block; font-size: 12px; color: var(--muted); margin: 0 0 5px; }
.hint { font-size: 11.5px; color: var(--faint); line-height: 1.5; }
.ok-text { color: var(--green); }
.err-text { color: #c0362c; }
.pill { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: 12px; background: #eef0f4; color: var(--muted); }
.pill.green { background: #dcf5e3; color: var(--green); }
.pill.amber { background: #fdecd2; color: var(--amber); }
.pill.red { background: #fbe2e2; color: #c0362c; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 5px; font-size: 11px; background: #eef0f4; color: var(--muted); margin: 1px 2px 1px 0; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: 0.7px; padding: 8px 10px; border-bottom: 1px solid var(--border-soft); }
td { padding: 10px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f5f6f8; }

/* estimate panel */
.est-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 700px) { .est-grid { grid-template-columns: 1fr; } }
.est-big { font-size: 22px; font-weight: 700; }
.est-big small { font-size: 12px; color: var(--muted); font-weight: 400; }
.lat-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; margin: 8px 0 6px; background: #eef0f4; }
.lat-bar div { height: 100%; }
.lat-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 11px; color: var(--muted); }
.lat-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }

/* transcript + events */
.transcript { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 7px; padding: 4px 0; }
.transcript:empty::before { content: "Transcript will appear here."; color: var(--faint); font-size: 12.5px; text-align: center; padding: 16px 0; }
.msg { padding: 8px 12px; border-radius: 10px; max-width: 85%; font-size: 13.5px; }
.msg.user { align-self: flex-end; background: #e2e5fb; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: #eef0f4; border-bottom-left-radius: 4px; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 11.5px; padding: 1px; }
.event-feed { max-height: 340px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.event-feed:empty::before { content: "Tool calls & KB retrievals appear here live."; color: var(--faint); font-size: 12.5px; text-align: center; padding: 16px 0; }
.ev { border: 1px solid var(--border-soft); border-left: 3px solid var(--accent); background: var(--panel-2); border-radius: 8px; padding: 8px 11px; font-size: 12.5px; }
.ev.tool { border-left-color: var(--amber); }
.ev.retrieval { border-left-color: var(--green); }
.ev.warn { border-left-color: var(--red); }
.ev .ev-title { font-weight: 600; font-size: 12.5px; }
.ev .ev-body { color: var(--muted); font-size: 11.5px; margin-top: 3px; white-space: pre-wrap; word-break: break-word; }
.ev time { float: right; color: var(--faint); font-size: 10.5px; }

/* speaking indicator */
.speak-dot { display: inline-flex; gap: 2.5px; align-items: flex-end; height: 14px; margin-left: 8px; opacity: 0.2; transition: opacity 0.2s; vertical-align: middle; }
.speak-dot.on { opacity: 1; }
.speak-dot span { width: 3px; background: var(--green); border-radius: 2px; height: 4px; }
.speak-dot.on span { animation: pvb 0.9s ease-in-out infinite; }
.speak-dot span:nth-child(2) { animation-delay: 0.15s; }
.speak-dot span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pvb { 0%, 100% { height: 4px; } 50% { height: 13px; } }

/* search rows / kb results */
.res-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--panel-2); border: 1px solid var(--border-soft); border-radius: 8px; padding: 7px 11px; margin-top: 6px; }
.res-row .ri { min-width: 0; font-size: 13px; }
.res-row .ri .hint { margin-top: 1px; }
.res-row .ra { display: flex; gap: 6px; flex-shrink: 0; }

/* auth + centered pages */
.center-wrap { max-width: 420px; margin: 12vh auto 0; padding: 0 20px; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; border-bottom: 1px solid var(--border-soft); padding-bottom: 10px; }
.section-sep { border: none; border-top: 1px solid var(--border-soft); margin: 18px 0; }
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 4px 12px; font-size: 13px; }
.kv .k { color: var(--faint); }
code.inline { background: #eef0f4; padding: 1px 6px; border-radius: 5px; font-size: 12px; font-family: ui-monospace, Consolas, monospace; word-break: break-all; }
.copy-url { display: flex; gap: 6px; align-items: center; min-width: 0; }
.copy-url code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast {
  position: fixed; bottom: 22px; right: 22px; background: #ffffff; border: 1px solid var(--border);
  color: var(--text); padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 50;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15); opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.toast.show { opacity: 1; }
