:root {
  --bg: #0b0e14;
  --panel: #12161f;
  --panel-2: #161b26;
  --elevated: #1b212e;
  --border: #232a37;
  --border-2: #2c3444;
  --text: #e7edf5;
  --muted: #8a94a6;
  --faint: #5b6474;
  --accent: #5b8cff;
  --accent-2: #22d3ee;
  --accent-grad: linear-gradient(135deg, #5b8cff, #7b5cff);
  --good: #34d399;
  --warn: #f5b544;
  --danger: #f87171;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow: 0 10px 40px rgba(0,0,0,.45);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
input, textarea, button { font-family: inherit; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 20px; }
::-webkit-scrollbar-thumb:hover { background: #3a4456; }

.btn { background: var(--accent-grad); color: #fff; border: 0; border-radius: var(--radius-sm);
  padding: 9px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer; transition: filter .15s, transform .05s; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; border: 1px solid var(--border-2); color: var(--muted); }
.btn.ghost:hover { color: var(--text); border-color: var(--accent); }
input, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border-2); color: var(--text);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; transition: border-color .15s; }
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { display: block; font-size: 12.5px; color: var(--muted); margin: 14px 0 6px; }

/* ─── App shell ─── */
#app { display: grid; grid-template-columns: 272px 1fr; height: 100vh; }
#app[hidden] { display: none; }

/* Sidebar */
#sidebar { background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 12px; gap: 12px; min-height: 0; }
.side-head { display: flex; align-items: center; gap: 10px; padding: 4px 6px 2px; }
.logo { width: 30px; height: 30px; }
.logo-sm { width: 20px; height: 20px; vertical-align: -4px; }
.wordmark { font-size: 20px; font-weight: 800; letter-spacing: .5px;
  background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.new-chat { width: 100%; text-align: left; background: var(--elevated); color: var(--text);
  border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 10px 14px;
  font-size: 14px; font-weight: 600; cursor: pointer; transition: border-color .15s, background .15s; }
.new-chat:hover { border-color: var(--accent); background: var(--panel-2); }

.history-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.history-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--faint); padding: 6px 8px; }
.history { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.chat-item { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 8px;
  cursor: pointer; color: var(--muted); font-size: 13.5px; position: relative; transition: background .12s, color .12s; }
.chat-item:hover { background: var(--panel-2); color: var(--text); }
.chat-item.active { background: var(--elevated); color: var(--text); }
.chat-item .ci-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .ci-actions { display: none; gap: 2px; }
.chat-item:hover .ci-actions { display: flex; }
.ci-btn { background: none; border: 0; color: var(--faint); cursor: pointer; padding: 2px 4px;
  border-radius: 5px; font-size: 13px; }
.ci-btn:hover { color: var(--text); background: var(--border-2); }

/* Account + popup */
.account-wrap { position: relative; border-top: 1px solid var(--border); padding-top: 10px; }
.account { width: 100%; display: flex; align-items: center; gap: 10px; background: transparent;
  border: 1px solid transparent; border-radius: var(--radius-sm); padding: 8px 10px; cursor: pointer;
  color: var(--text); transition: background .12s; }
.account:hover { background: var(--panel-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-grad);
  display: grid; place-items: center; font-weight: 700; font-size: 14px; color: #fff; flex-shrink: 0; }
.account-name { flex: 1; text-align: left; font-size: 13.5px; font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.account-caret { color: var(--faint); font-size: 14px; }
.account-menu { position: absolute; bottom: 62px; left: 0; right: 0; background: var(--elevated);
  border: 1px solid var(--border-2); border-radius: var(--radius); padding: 6px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 1px; z-index: 20; }
.account-menu[hidden] { display: none; }
.am-item { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text);
  padding: 9px 11px; border-radius: 8px; font-size: 13.5px; cursor: pointer; text-decoration: none; }
.am-item:hover { background: var(--panel-2); }
.am-sep { height: 1px; background: var(--border); margin: 5px 4px; }

/* Main chat */
#main { display: flex; flex-direction: column; height: 100vh; min-width: 0; }
.chat-head { height: 52px; border-bottom: 1px solid var(--border); display: flex; align-items: center;
  padding: 0 22px; background: rgba(18,22,31,.6); backdrop-filter: blur(6px); }
.chat-title { font-size: 14px; font-weight: 600; color: var(--muted); }
.log { flex: 1; overflow-y: auto; padding: 28px 22px; display: flex; flex-direction: column;
  gap: 14px; max-width: 900px; width: 100%; margin: 0 auto; }
.msg { max-width: 92%; padding: 13px 16px; border-radius: 14px; line-height: 1.6; font-size: 14.5px;
  white-space: pre-wrap; word-wrap: break-word; animation: rise .18s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.user { align-self: flex-end; background: var(--accent-grad); color: #fff; border-bottom-right-radius: 5px; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--border);
  border-bottom-left-radius: 5px; }
.msg.error { align-self: center; background: rgba(248,113,113,.12); border: 1px solid var(--danger);
  color: var(--danger); font-size: 13px; }
.trace { align-self: flex-start; font-size: 12px; color: var(--muted); background: var(--panel-2);
  border: 1px dashed var(--border-2); border-radius: 8px; padding: 6px 11px; }
.trace code { color: var(--accent-2); }
.typing { color: var(--muted); font-style: italic; }
/* Animated thinking indicator */
.msg.thinking { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); }
.think-label { font-size: 13.5px; background: var(--accent-grad); -webkit-background-clip: text;
  background-clip: text; color: transparent; animation: shimmer 1.6s ease-in-out infinite; }
@keyframes shimmer { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
.think-dots { display: inline-flex; gap: 5px; align-items: center; }
.think-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: think 1.2s infinite ease-in-out; }
.think-dots i:nth-child(2) { animation-delay: .18s; }
.think-dots i:nth-child(3) { animation-delay: .36s; }
@keyframes think { 0%, 80%, 100% { transform: scale(.5); opacity: .4; } 40% { transform: scale(1); opacity: 1; } }
.empty-hint { margin: auto; text-align: center; color: var(--faint); }
.empty-hint img { width: 54px; height: 54px; opacity: .8; margin-bottom: 12px; }

.composer { display: flex; gap: 10px; padding: 14px 22px 20px; max-width: 900px; width: 100%;
  margin: 0 auto; align-items: flex-end; }
.composer textarea { resize: none; max-height: 200px; border-radius: 14px; padding: 13px 16px;
  background: var(--panel); border-color: var(--border-2); }
.send { width: 46px; height: 46px; flex-shrink: 0; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--accent-grad); color: #fff; font-size: 17px; transition: filter .15s, transform .05s; }
.send:hover { filter: brightness(1.1); }
.send:active { transform: translateY(1px); }

/* ─── Landing ─── */
.landing { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: radial-gradient(1100px 560px at 50% -8%, rgba(91,140,255,.20), transparent 60%), var(--bg); }
.landing[hidden] { display: none; }
.landing-card { width: 100%; max-width: 400px; text-align: center; background: var(--panel);
  border: 1px solid var(--border); border-radius: 18px; padding: 40px 32px; box-shadow: var(--shadow); }
.landing-logo-img { width: 72px; height: 72px; filter: drop-shadow(0 6px 18px rgba(91,140,255,.4)); }
.landing-card h1 { font-size: 30px; margin: 14px 0 6px; letter-spacing: .5px;
  background: var(--accent-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.landing-sub { color: var(--muted); font-size: 14px; margin: 0 0 26px; line-height: 1.5; }
.gbtn { display: inline-flex; align-items: center; gap: 12px; justify-content: center; width: 100%;
  background: #fff; color: #1f2328; text-decoration: none; font-weight: 600; font-size: 15px;
  padding: 12px 16px; border-radius: 10px; border: 1px solid #dadce0; transition: filter .15s; }
.gbtn:hover { filter: brightness(.97); }
.gmark { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  border-radius: 50%; background: conic-gradient(#ea4335 0 25%, #fbbc05 0 50%, #34a853 0 75%, #4285f4 0);
  color: #fff; font-weight: 800; font-size: 13px; }
.landing-note { color: var(--muted); font-size: 12px; margin: 16px 0 0; min-height: 16px; }
.owner { margin-top: 22px; text-align: left; }
.owner summary { color: var(--muted); font-size: 12px; cursor: pointer; }
.owner input { margin-top: 10px; }
.owner .btn { width: 100%; margin-top: 8px; }
.owner-err { color: var(--danger); font-size: 12px; margin-top: 6px; min-height: 14px; }

/* ─── Settings modal ─── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.62); display: flex; align-items: center;
  justify-content: center; z-index: 50; padding: 24px; backdrop-filter: blur(3px); }
.modal[hidden] { display: none; }
.modal-card { display: grid; grid-template-columns: 210px 1fr; width: 100%; max-width: 780px;
  height: 78vh; max-height: 640px; background: var(--panel); border: 1px solid var(--border-2);
  border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
.modal-side { background: var(--panel-2); border-right: 1px solid var(--border); padding: 16px 10px;
  display: flex; flex-direction: column; gap: 3px; }
.modal-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px;
  padding: 4px 10px 14px; }
.tab { text-align: left; background: none; border: 0; color: var(--muted); padding: 10px 12px;
  border-radius: 8px; font-size: 13.5px; cursor: pointer; transition: background .12s, color .12s; }
.tab:hover { background: var(--panel); color: var(--text); }
.tab.active { background: var(--elevated); color: var(--text); font-weight: 600; }
.modal-main { position: relative; padding: 26px 28px; overflow-y: auto; }
.modal-x { position: absolute; top: 16px; right: 18px; background: none; border: 0; color: var(--muted);
  font-size: 18px; cursor: pointer; }
.modal-x:hover { color: var(--text); }
.pane h2 { margin: 0 0 6px; font-size: 20px; }
.pane-intro { color: var(--muted); font-size: 13px; line-height: 1.55; margin: 0 0 16px; }
.pane-intro code, .plugins-empty code { color: var(--accent-2); }
.redirects { background: var(--bg); border: 1px solid var(--border-2); border-radius: 9px;
  padding: 10px 12px; font-family: ui-monospace, monospace; font-size: 11.5px; color: var(--accent-2);
  word-break: break-all; line-height: 1.7; margin-bottom: 18px; }
.cfg { border: 1px solid var(--border); border-radius: 11px; padding: 14px 16px; margin-bottom: 16px;
  background: var(--panel-2); }
.cfg h3 { margin: 0 0 6px; font-size: 14.5px; }
.hint2 { color: var(--faint) !important; font-size: 11.5px !important; }
.chk { display: flex; align-items: center; gap: 9px; color: var(--text); cursor: pointer; margin-top: 14px; }
.chk input { width: auto; }
.row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.setbadge { font-size: 11px; color: var(--good); }
.kv { display: flex; justify-content: space-between; padding: 10px 2px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--muted); margin-top: 6px; }
.kv b { color: var(--text); }
.cfgmsg { font-size: 13px; color: var(--good); min-height: 18px; margin-top: 12px; }
.cfgmsg.err { color: var(--danger); }
.conn-row { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--border); border-radius: 11px; padding: 14px 16px; margin-bottom: 12px; background: var(--panel-2); }
.cstat { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.cstat.on { color: var(--good); }
.skills-list { display: flex; flex-direction: column; gap: 8px; }
.skill-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--panel-2); }
.skill-card .sk-name { font-weight: 600; font-size: 14px; }
.skill-card .sk-name code { color: var(--accent-2); font-size: 13px; }
.skill-card .sk-desc { color: var(--muted); font-size: 12.5px; margin-top: 4px; line-height: 1.5; }
.plugins-empty { color: var(--faint); font-size: 13px; padding: 20px; text-align: center;
  border: 1px dashed var(--border-2); border-radius: 11px; }
.sys { display: grid; gap: 12px; }
.sys .metric { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.sys .metric .m-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 8px; }
.sys .metric .m-top b { color: var(--text); }
.bar { height: 7px; background: var(--bg); border-radius: 5px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent-grad); }
.bar > span.warn { background: var(--warn); } .bar > span.hot { background: var(--danger); }

@media (max-width: 720px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { display: none; }
  .modal-card { grid-template-columns: 1fr; }
  .modal-side { flex-direction: row; overflow-x: auto; }
}
