/* RhinoGraph palette: #055FE9 brand blue, white, #202020 surfaces. */
:root {
  --bg: #202020;
  --bg-raised: #272727;
  --bg-inset: #191919;
  --border: #383838;
  --text: #ffffff;
  --text-dim: #a0a0a0;
  --accent: #055FE9;
  --accent-soft: rgba(5, 95, 233, 0.16);
  --danger: #e5544c;
  --radius: 8px;
  --mono: ui-monospace, "Cascadia Mono", "Consolas", "SF Mono", Menlo, monospace;
  --sans: ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

/*
 * The browser's [hidden] rule is a UA-stylesheet default, so ANY author rule
 * that sets `display` on the same element silently defeats it — the element
 * stays visible and toggling `hidden` in JS appears to do nothing. Several
 * components here set display (modals, the working strip, the admin shell), so
 * enforce it once, globally.
 */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

button {
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  padding: 6px 12px;
  transition: background 0.12s ease, border-color 0.12s ease;
}
button:hover:not(:disabled) { background: #2f2f2f; border-color: #4a4a4a; }
button:disabled { opacity: 0.4; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #ffffff; font-weight: 600; }
button.primary:hover { background: #1f74f5; border-color: #1f74f5; }
button.icon { padding: 3px 7px; font-size: 12px; }
kbd {
  font-family: var(--mono);
  font-size: 10px;
  opacity: 0.6;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 3px;
  margin-left: 4px;
}

.brand { display: flex; align-items: center; gap: 9px; }
.brand-logo {
  height: 24px;
  width: auto;
  border-radius: 4px;
  flex: 0 0 auto;
  display: block;
}
.login-card .brand-logo { height: 40px; }
.brand-sub-inline {
  color: var(--text-dim);
  font-size: 12px;
  padding-left: 9px;
  margin-left: 2px;
  border-left: 1px solid var(--border);
  white-space: nowrap;
}
@media (max-width: 900px) { .brand-sub-inline { display: none; } }

/* ---------------------------------------------------------- login */

.login-body {
  display: grid;
  place-items: center;
  background: radial-gradient(1000px 600px at 50% -10%, #10305e 0%, var(--bg) 62%);
}
.login-card {
  width: min(380px, calc(100vw - 32px));
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  display: flex;
  flex-direction: column;
}
.login-card h1 { font-size: 18px; margin: 0; font-weight: 600; }
.brand-sub { color: var(--text-dim); margin: 6px 0 24px; font-size: 13px; }
.login-card label { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.login-card input {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 11px;
  margin-bottom: 16px;
  font-family: inherit;
  font-size: 14px;
}
.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.login-card button { margin-top: 4px; padding: 10px; background: var(--accent); border-color: var(--accent); color: #ffffff; font-weight: 600; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 12px 0 0; }

/* ---------------------------------------------------------- shell */

body:not(.login-body) { display: flex; flex-direction: column; }

.topbar {
  flex: 0 0 auto;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.who { color: var(--text-dim); font-size: 12px; }
.ghost { background: transparent; }
a.ghost.linkbtn { color: var(--text); text-decoration: none; font-size: 13px; padding: 6px 12px; }
a.ghost.linkbtn:hover { background: #2f2f2f; border-color: #4a4a4a; }

.layout { flex: 1 1 auto; display: flex; min-height: 0; }

/* ---------------------------------------------------------- sidebar */

.sidebar {
  flex: 0 0 250px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-raised);
  min-height: 0;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 8px;
}
.sidebar-title { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-dim); }
.sidebar-actions { display: flex; gap: 4px; }
.crumbs {
  padding: 0 12px 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  word-break: break-all;
}
.crumbs a { color: var(--accent); text-decoration: none; cursor: pointer; }
.crumbs a:hover { text-decoration: underline; }

.tree { list-style: none; margin: 0; padding: 0 6px 12px; overflow-y: auto; flex: 1 1 auto; }
.tree li {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
}
.tree li:hover { background: #2f2f2f; }
.tree li.active { background: var(--accent-soft); color: var(--accent); }
.tree .glyph { color: var(--text-dim); width: 13px; flex: 0 0 auto; text-align: center; }
.tree .label { overflow: hidden; text-overflow: ellipsis; flex: 1 1 auto; }
.tree .del, .tree .dl { opacity: 0; color: var(--text-dim); flex: 0 0 auto; font-size: 12px; padding: 0 3px; text-decoration: none; }
.tree li:hover .del, .tree li:hover .dl { opacity: 0.7; }
.tree .del:hover { color: var(--danger); opacity: 1; }
.tree .dl:hover { color: var(--accent); opacity: 1; }
.tree .empty { color: var(--text-dim); font-style: italic; cursor: default; }
.tree .empty:hover { background: transparent; }

/* ---------------------------------------------------------- main panes */

.main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pane { display: flex; flex-direction: column; min-height: 0; }
.editor-pane { flex: 0 0 38%; }
.terminal-pane { flex: 1 1 auto; }

.pane-head, .tabbar {
  flex: 0 0 auto;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.pane-title { font-family: var(--mono); font-size: 12px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pane-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.dirty { color: var(--accent); font-size: 11px; }

.editor {
  flex: 1 1 auto;
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  background: var(--bg-inset);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  padding: 12px 14px;
  tab-size: 2;
}

.divider {
  flex: 0 0 5px;
  background: var(--border);
  cursor: row-resize;
}
.divider:hover { background: var(--accent); }

.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1 1 auto; }
.tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 9px;
  border-radius: 5px;
  font-size: 12px;
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
  border: 1px solid transparent;
}
.tab:hover { background: #2f2f2f; }
.tab.active { background: var(--bg-inset); color: var(--text); border-color: var(--border); }
.tab .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: 0 0 auto; }
.tab.shell .dot { background: #6f9e6f; }
.tab .x { opacity: 0.5; font-size: 13px; padding: 0 2px; }
.tab .x:hover { opacity: 1; color: var(--danger); }
.tab-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.terminals { flex: 1 1 auto; position: relative; background: var(--bg-inset); min-height: 0; }
.term-host { position: absolute; inset: 0; padding: 8px 4px 4px 10px; display: none; }
.term-host.active { display: block; }

.placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.8;
  pointer-events: none;
}
.placeholder strong { color: var(--text); display: block; margin-bottom: 4px; }

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

.tab.k-shell .dot { background: #6f9e6f; }
.tab.k-chat .dot { background: #7aa6d9; }

.chat-host {
  display: none;
  flex-direction: column;
  padding: 0;
  background: var(--bg-inset);
}
.chat-host.active { display: flex; }

/* ---------------------------------------------------------- seo panel */

.tab.k-seo .dot { background: #3fbf7f; }

.seo-host {
  display: none;
  flex-direction: column;
  padding: 0;
  background: var(--bg-inset);
}
.seo-host.active { display: flex; }

.seo-launcher {
  flex: 0 0 auto;
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 52%;
  overflow-y: auto;
}
.seo-row { display: flex; align-items: flex-start; gap: 12px; }
.seo-label {
  flex: 0 0 74px;
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding-top: 6px;
}
.seo-label em { font-style: normal; opacity: 0.6; text-transform: none; letter-spacing: 0; }

.seo-projects, .seo-actions { display: flex; flex-wrap: wrap; gap: 6px; flex: 1 1 auto; }

.seo-chip {
  padding: 5px 11px;
  font-size: 12.5px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-inset);
  color: var(--text-dim);
}
.seo-chip:hover:not(:disabled) { color: var(--text); border-color: #4a4a4a; }
.seo-chip.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.seo-notes-row { align-items: stretch; }
.seo-notes {
  flex: 1 1 auto;
  resize: none;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  padding: 8px 11px;
  max-height: 160px;
  overflow-y: auto;
}
.seo-notes:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.seo-run-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-left: 86px;
}
.seo-summary {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.seo-run { flex: 0 0 auto; padding: 7px 20px; }

.auth-banner {
  flex: 0 0 auto;
  margin: 12px 20px 0;
  padding: 12px 14px;
  border: 1px solid rgba(5, 95, 233, 0.45);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--accent-soft);
  font-size: 13px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.auth-banner code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg .bubble {
  max-width: min(760px, 88%);
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.6;
  font-size: 14px;
  overflow-wrap: anywhere;
}
.msg.user .bubble {
  background: var(--accent-soft);
  border: 1px solid rgba(5, 95, 233, 0.35);
  white-space: pre-wrap;
}
.msg.claude .bubble {
  background: var(--bg-raised);
  border: 1px solid var(--border);
}
.msg.streaming .bubble::after {
  content: '▍';
  color: var(--accent);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.msg .bubble > *:first-child { margin-top: 0; }
.msg .bubble > *:last-child { margin-bottom: 0; }
.msg .bubble p { margin: 0 0 10px; }
.msg .bubble h1, .msg .bubble h2, .msg .bubble h3 { font-size: 15px; margin: 16px 0 8px; }
.msg .bubble ul, .msg .bubble ol { margin: 0 0 10px; padding-left: 22px; }
.msg .bubble li { margin-bottom: 4px; }
.msg .bubble a { color: var(--accent); }
.msg .bubble a.dl-link {
  display: inline-block;
  background: var(--bg-inset);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 3px 10px 3px 26px;
  margin: 2px 0;
  text-decoration: none;
  font-family: var(--mono);
  font-size: 12.5px;
  position: relative;
}
.msg .bubble a.dl-link::before {
  content: '↓';
  position: absolute;
  left: 10px;
  font-family: var(--sans);
}
.msg .bubble a.dl-link:hover { background: var(--accent-soft); }
.msg .bubble code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}
.msg .bubble pre {
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0 0 10px;
}
.msg .bubble pre code { background: none; border: 0; padding: 0; font-size: 12.5px; line-height: 1.55; }
.msg .bubble table { border-collapse: collapse; width: 100%; margin-bottom: 10px; font-size: 13px; }
.msg .bubble th, .msg .bubble td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; }
.msg .bubble blockquote {
  margin: 0 0 10px;
  padding-left: 12px;
  border-left: 3px solid var(--border);
  color: var(--text-dim);
}

.chat-meta {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--mono);
  text-align: center;
}

details.tool, details.thinking {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-raised);
  font-size: 12.5px;
  overflow: hidden;
}
details.tool summary, details.thinking summary {
  cursor: pointer;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  list-style: none;
  color: var(--text-dim);
}
details.tool summary::-webkit-details-marker,
details.thinking summary::-webkit-details-marker { display: none; }
details.tool summary:hover, details.thinking summary:hover { background: #2f2f2f; }
.tool-name { font-family: var(--mono); color: var(--accent); flex: 0 0 auto; }
.tool-arg {
  font-family: var(--mono);
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.75;
}
.tool-state { flex: 0 0 auto; font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.7; }
.tool-state.err { color: var(--danger); opacity: 1; }
details.tool pre, details.thinking pre {
  margin: 0;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-inset);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 320px;
  overflow-y: auto;
}

.chat-status {
  flex: 0 0 auto;
  padding: 6px 20px;
  font-size: 12px;
  color: var(--text-dim);
}
.chat-status.bad { color: var(--danger); }

.chat-composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
}
.chat-composer textarea {
  flex: 1 1 auto;
  resize: none;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 13px;
  max-height: 200px;
  overflow-y: auto;
}
.chat-composer textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.chat-composer-actions { display: flex; gap: 6px; flex: 0 0 auto; }

.toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  max-width: 340px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 50;
}
.toast.bad { border-left-color: var(--danger); }
