:root {
  --bg: #0f1115;
  --panel: #151923;
  --panel2: #0b0d12;
  --text: #e6e8ef;
  --muted: #9aa3b2;
  --accent: #6aa9ff;
  --accent2: #9b8cff;
  --border: #2a3140;
  --shadow: rgba(0,0,0,.25);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel2);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 140px;
}

.brand__icon { width: 18px; height: 18px; }
.brand__name { font-weight: 600; letter-spacing: .2px; }

.topbar .brand .icon-btn {
  margin-right: 2px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}
.controls select {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 4px 8px;
  border-radius: 8px;
}

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width, 260px) 6px 1fr;
  flex: 1 1 auto;
  min-height: 0;
}

.sessions {
  border-right: 1px solid var(--border);
  background: var(--panel2);
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  min-height: 0;
}

.sessions__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}
.sessions__title { font-size: 12px; color: var(--muted); }
.sessions__actions { display: flex; gap: 6px; }
.sessions__list { padding: 10px; display: flex; flex-direction: column; gap: 6px; overflow: auto; min-height: 0; }

.splitter {
  background: rgba(255,255,255,0.04);
  border-right: 1px solid rgba(255,255,255,0.06);
  border-left: 1px solid rgba(0,0,0,0.25);
  cursor: col-resize;
}
.splitter:hover {
  background: rgba(106,169,255,0.12);
}

body.sidebar-collapsed {
  --sidebar-width: 0px;
}
body.sidebar-collapsed .sessions {
  opacity: 0;
  pointer-events: none;
  border-right: none;
}

.session {
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.session--active {
  border-color: rgba(106,169,255,.7);
  box-shadow: 0 0 0 1px rgba(106,169,255,.25) inset;
}

.chat {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.chat__stream {
  flex: 1;
  overflow: auto;
  padding: 14px 14px 0 14px;
  min-height: 0;
}

.toast {
  margin: 10px 14px 0 14px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.06);
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 12px;
  color: rgba(230,232,239,.92);
}
.toast--hidden { display: none; }
.toast--error {
  border-color: rgba(255,150,150,0.35);
  background: rgba(255,120,120,0.10);
}

.turn {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.turn__user,
.turn__assistant {
  max-width: min(720px, 86%);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.turn__user { align-self: flex-end; align-items: flex-end; }
.turn__assistant { align-self: flex-start; align-items: flex-start; }

.turn__progress {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 2px;
}

.turn__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}
.turn__metaSpacer { flex: 1; }
.turn__label { color: var(--muted); }

.turn__bubble {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(21,25,35,.65);
  box-shadow: 0 10px 24px var(--shadow);
  padding: 10px 12px;
}
.turn__bubble--user {
  background: rgba(106,169,255,.10);
  border-color: rgba(106,169,255,.28);
}

.turn__summary {
  font-size: 13px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}
.turn__summary.md {
  white-space: normal;
}
.turn__summary.md p {
  margin: 0 0 8px 0;
}
.turn__summary.md p:last-child {
  margin-bottom: 0;
}
.turn__summary.md h1,
.turn__summary.md h2,
.turn__summary.md h3,
.turn__summary.md h4,
.turn__summary.md h5,
.turn__summary.md h6 {
  margin: 10px 0 8px 0;
  line-height: 1.25;
}
.turn__summary.md ul,
.turn__summary.md ol {
  margin: 8px 0 8px 18px;
  padding: 0;
}
.turn__summary.md blockquote {
  margin: 8px 0;
  padding: 6px 10px;
  border-left: 3px solid rgba(106,169,255,.45);
  background: rgba(106,169,255,.08);
  border-radius: 10px;
}
.turn__summary.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
}
.turn__summary.md pre {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(11,13,18,.92);
  border: 1px solid var(--border);
  overflow: auto;
}
.turn__summary.md pre code {
  border: none;
  background: transparent;
  padding: 0;
  display: block;
  white-space: pre;
}
.turn__summary.md a {
  color: rgba(106,169,255,.95);
  text-decoration: none;
}
.turn__summary.md a:hover {
  text-decoration: underline;
}

.turn__detail {
  margin: 10px 0 0 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(11,13,18,.9);
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  white-space: pre;
  word-break: normal;
  max-height: 320px;
  overflow: auto;
}
.turn__detail--hidden { display: none; }

.progressItem {
  width: 100%;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.02);
  border-radius: 12px;
  overflow: hidden;
}
.progressItem__row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
}
.progressItem__icon {
  width: 16px;
  color: rgba(230,232,239,.75);
  flex: 0 0 auto;
}
.progressItem__btn {
  flex: 1;
  border: none;
  background: transparent;
  color: rgba(230,232,239,.92);
  text-align: left;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.progressItem__btn:hover {
  color: rgba(230,232,239,1);
}
.progressItem__detail {
  margin: 0;
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,0.06);
  background: rgba(11,13,18,.92);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  white-space: pre;
  overflow: auto;
  max-height: 360px;
}
.progressItem__detail--hidden { display: none; }

.plan {
  margin: 12px 14px;
  border: 1px solid rgba(155,140,255,.35);
  background: rgba(155,140,255,.10);
  border-radius: 16px;
  padding: 10px 12px;
  flex: 0 0 auto;
}
.plan--hidden { display: none; }
.plan__header {
  font-size: 12px;
  color: rgba(230,232,239,.85);
  margin-bottom: 6px;
}
.plan__steps {
  margin: 0;
  padding-left: 0;
  color: rgba(230,232,239,.9);
  list-style: none;
}
.plan__step {
  display: grid;
  grid-template-columns: 20px 16px 1fr;
  align-items: baseline;
  gap: 10px;
  margin: 4px 0;
}
.plan__num {
  color: rgba(230,232,239,.7);
}
.plan__icon {
  width: 16px;
  display: inline-block;
  color: rgba(230,232,239,.8);
}
.plan__icon--spin {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  animation: planSpin 1.1s linear infinite;
}
@keyframes planSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.plan__text--done {
  text-decoration: line-through;
  opacity: .85;
}

.composer {
  border-top: 1px solid var(--border);
  background: var(--panel2);
  padding: 10px 12px;
}
.composer__input {
  position: relative;
}
.composer textarea {
  width: 100%;
  box-sizing: border-box;
  resize: none;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 46px 40px 12px;
  outline: none;
  max-height: 180px;
  overflow-y: auto;
}
.composer__send {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 32px;
  height: 32px;
  border-radius: 12px;
  border-color: rgba(106,169,255,.35);
  background: rgba(106,169,255,.14);
}
.composer__send:hover {
  border-color: rgba(106,169,255,.55);
  background: rgba(106,169,255,.20);
}
.composer__send:active {
  transform: translateY(1px);
}
.composer__actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 12px;
  cursor: pointer;
}
.btn--primary {
  background: linear-gradient(90deg, rgba(106,169,255,.9), rgba(155,140,255,.9));
  border: none;
  color: #0b0d12;
  font-weight: 600;
}
.btn--ghost {
  background: transparent;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
}
.icon-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.03);
  color: rgba(230,232,239,.92);
  cursor: pointer;
}
.icon-btn--sm {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  font-size: 12px;
}
.icon-btn:hover {
  border-color: rgba(106,169,255,.35);
  background: rgba(106,169,255,0.10);
}
.icon-btn--ghost {
  background: transparent;
}
.icon-btn[data-signed-in="1"] {
  border-color: rgba(106,169,255,.55);
  box-shadow: 0 0 0 1px rgba(106,169,255,.18) inset;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal--hidden { display: none; }
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}
.modal__card {
  position: relative;
  width: min(640px, calc(100% - 28px));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 18px 48px rgba(0,0,0,.45);
  overflow: hidden;
}
.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel2);
}
.modal__title {
  font-size: 13px;
  font-weight: 600;
  color: rgba(230,232,239,.95);
}
.modal__body {
  padding: 12px 12px 14px 12px;
}
.sub {
  margin: 0 0 12px 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.form-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 12px;
  align-items: center;
  margin: 10px 0;
}
.form-row label {
  color: var(--muted);
  font-size: 12px;
}
.form-row input[type="text"],
.form-row input[type="password"] {
  width: 100%;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 10px;
  outline: none;
}
.form-row input[type="text"]:focus,
.form-row input[type="password"]:focus {
  border-color: rgba(106,169,255,.7);
}
.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}
.status {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
}
.status--error {
  color: #ffd7d7;
}
