:root {
  --bg: #0b0d12;
  --panel: #141820;
  --panel2: #1a2030;
  --line: #2a3344;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #6ea8fe;
  --bad: #f07178;
  --ok: #7fd99a;
  --warn: #e6c07b;
  --font: "Segoe UI", "Tahoma", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tab-h: 56px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}
body { display: flex; flex-direction: column; }
.hidden { display: none !important; }
#gate, #app { flex: 1; display: flex; flex-direction: column; min-height: 0; }
#gate {
  align-items: center; justify-content: center; padding: 1.5rem;
  background:
    radial-gradient(900px 420px at 70% -5%, #1a3048 0%, transparent 55%),
    radial-gradient(700px 380px at 10% 100%, #152028 0%, transparent 50%),
    var(--bg);
}
.gate-card {
  width: min(440px, 100%);
  background: linear-gradient(165deg, #171d28 0%, var(--panel) 60%);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.35rem 1.25rem 1.2rem;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.brand {
  font-size: 1.55rem; font-weight: 700; letter-spacing: -.03em;
  margin: 0 0 .35rem;
  background: linear-gradient(90deg, #e8ecf4, #6ea8fe);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.lede { color: var(--muted); font-size: .9rem; margin: 0 0 1rem; line-height: 1.45; }
label { display: block; font-size: .75rem; color: var(--muted); margin: .55rem 0 .25rem; }
input, textarea, select, button { font: inherit; color: var(--text); }
input, textarea, select {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .65rem .75rem;
}
textarea#accessToken { font-family: ui-monospace, Consolas, monospace; font-size: .82rem; }
button {
  border: 0; border-radius: 10px; padding: .65rem 1rem;
  background: var(--accent); color: #061018; font-weight: 600; cursor: pointer;
}
button.secondary, .icon-btn.secondary {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
}
button:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn {
  border: 0; border-radius: 10px; padding: .45rem .7rem;
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  cursor: pointer; min-width: 40px;
}
.row { display: flex; gap: .5rem; margin-top: .75rem; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 120px; }
.row.tight { margin: .5rem 0 .75rem; }
.err { color: var(--bad); font-size: .85rem; margin-top: .5rem; min-height: 1.2em; }
.hint { color: var(--ok); font-size: .85rem; margin-top: .4rem; min-height: 1.1em; }
.muted { color: var(--muted); font-size: .85rem; margin: 0 0 .75rem; }
.top {
  display: flex; gap: .4rem; align-items: center;
  padding: .55rem .65rem; border-bottom: 1px solid var(--line);
  background: var(--panel); flex-shrink: 0;
}
.top .title {
  flex: 1; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 600;
}
.top select { max-width: 130px; padding: .4rem .5rem; font-size: .8rem; }
.ws-select { max-width: 150px !important; }
.desk-tabs { display: none; gap: .25rem; }
.dtab {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  border-radius: 8px; padding: .35rem .55rem; font-size: .78rem; font-weight: 600; cursor: pointer;
}
.dtab.active { color: var(--accent); border-color: var(--line); background: var(--panel2); }
@media (min-width: 861px) {
  .desk-tabs { display: flex; }
}
.shell { flex: 1; display: grid; grid-template-columns: 260px 1fr; min-height: 0; position: relative; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    display: none; position: absolute; inset: 0; z-index: 8;
  }
  .sidebar.open { display: flex; }
  .ws-select { display: none; }
}
.sidebar {
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: var(--panel);
  min-height: 0; overflow: hidden;
}
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem .75rem; border-bottom: 1px solid var(--line);
  font-size: .8rem; color: var(--muted); font-weight: 600;
}
.chat-list { flex: 1; overflow: auto; }
.chat-list .chat-row {
  display: flex; gap: .25rem; align-items: stretch;
  border-bottom: 1px solid var(--line);
}
.chat-list button.chat {
  flex: 1; text-align: right;
  background: transparent; color: var(--text); border: 0; border-radius: 0;
  padding: .7rem .75rem; font-weight: 500; cursor: pointer;
}
.chat-list button.chat.active { background: var(--panel2); }
.chat-list .chat-actions { display: flex; flex-direction: column; }
.chat-list .chat-actions button {
  flex: 1; border: 0; border-radius: 0; background: transparent;
  color: var(--muted); padding: 0 .45rem; font-size: .75rem; cursor: pointer;
}
.chat-list .chat-actions button:hover { color: var(--bad); background: #1e1518; }
.main { display: flex; flex-direction: column; min-height: 0; position: relative; }
.panel { display: none; flex-direction: column; flex: 1; min-height: 0; overflow: auto; padding-bottom: calc(var(--tab-h) + var(--safe-b)); }
.panel.active { display: flex; }
#panel-chat { padding-bottom: 0; }
#panel-chat.active { overflow: hidden; }
.panel-bar {
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .75rem .85rem .35rem; flex-shrink: 0;
}
.panel-bar h2, .panel-bar h3 { margin: 0; font-size: 1.05rem; }
.panel-bar.sub { padding-top: .35rem; }
.panel-bar.sub h3 { font-size: .85rem; color: var(--muted); font-family: ui-monospace, Consolas, monospace; word-break: break-all; }
.status {
  padding: .4rem .75rem; font-size: .75rem; color: var(--muted);
  border-bottom: 1px solid var(--line); background: var(--panel2);
  font-family: ui-monospace, Consolas, monospace; flex-shrink: 0;
}
.diag { color: var(--warn); white-space: pre-wrap; }
.messages {
  flex: 1; overflow: auto; padding: .75rem; display: flex; flex-direction: column; gap: .65rem;
}
.bubble {
  max-width: min(92%, 720px); padding: .7rem .85rem; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); white-space: pre-wrap; line-height: 1.45;
  word-break: break-word;
}
.bubble.user { align-self: flex-start; background: #1c2a22; border-color: #2d4a38; }
.bubble.bot { align-self: flex-end; }
.bubble.sys { align-self: center; font-size: .8rem; color: var(--muted); background: transparent; border-style: dashed; }
.bubble.stream { border-color: var(--accent); }
.composer {
  display: flex; gap: .45rem; padding: .55rem .65rem;
  border-top: 1px solid var(--line); background: var(--panel);
  align-items: flex-end; flex-shrink: 0;
  padding-bottom: calc(.55rem + var(--tab-h) + var(--safe-b));
}
@media (min-width: 861px) {
  .composer { padding-bottom: .65rem; }
  .panel { padding-bottom: .5rem; }
  .tabs { display: none; }
  #panel-projects, #panel-inbox, #panel-settings {
    position: absolute; inset: 0; z-index: 4; background: var(--bg);
    padding: 0 0 .5rem; overflow: auto;
  }
  .shell.desk-settings .sidebar { display: none; }
  .shell.desk-settings { grid-template-columns: 1fr; }
}
.composer textarea {
  flex: 1; resize: none; min-height: 42px; max-height: 140px;
  border-radius: 12px;
}
.send {
  width: 46px; height: 46px; border-radius: 12px; padding: 0;
  font-size: 1.1rem; flex-shrink: 0;
}
.attach-hint {
  font-size: .75rem; color: var(--muted); padding: 0 .75rem .35rem;
  min-height: 0;
}
.tabs {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(20,24,32,.96); border-top: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.tab {
  background: transparent; color: var(--muted); border: 0; border-radius: 0;
  font-size: .78rem; font-weight: 600; padding: .35rem;
}
.tab.active { color: var(--accent); }
.list { padding: 0 .75rem .75rem; display: flex; flex-direction: column; gap: .4rem; }
.list-item {
  display: flex; align-items: center; gap: .5rem;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: .65rem .75rem; text-align: right;
}
.list-item button, .list-item a {
  background: transparent; border: 0; color: var(--text); cursor: pointer;
  flex: 1; text-align: right; padding: 0; text-decoration: none; font-weight: 500;
}
.list-item .meta { font-size: .72rem; color: var(--muted); }
.list-item .act { flex: 0; color: var(--muted); font-size: .8rem; padding: .25rem .4rem; }
.viewer {
  margin: 0 .75rem .75rem; padding: .75rem; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 12px;
  max-height: 280px; overflow: auto; white-space: pre-wrap;
  font-size: .78rem; color: var(--muted); display: none;
}
.viewer.show { display: block; }
.cards { padding: 0 .75rem 1.25rem; display: flex; flex-direction: column; gap: .75rem; }
.scard {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: .9rem;
}
.scard h3 { margin: 0 0 .5rem; font-size: .95rem; }
.scard p, .scard .line { margin: .2rem 0; font-size: .85rem; color: var(--muted); }
.scard .line strong { color: var(--text); font-weight: 600; }
.scard .actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .65rem; }
.scard .actions button { font-size: .82rem; padding: .45rem .7rem; }
.bar {
  height: 8px; background: #0e1218; border-radius: 99px; overflow: hidden; margin: .35rem 0 .5rem;
}
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.warn > i { background: var(--warn); }
.bar.bad > i { background: var(--bad); }
code { font-size: .8em; color: var(--accent); }
