
:root {
  color-scheme: dark;
  --bg: #09101f;
  --panel: #0f1930;
  --panel-2: #152240;
  --panel-3: #1a2a4d;
  --text: #e8eefc;
  --muted: #9aadd6;
  --line: #24375f;
  --accent: #6a86ff;
  --accent-strong: #7f98ff;
  --danger: #ff6c7d;
  --shadow: 0 20px 40px rgba(0,0,0,0.22);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, Arial, sans-serif;
  background: linear-gradient(180deg, #08101e 0%, #0b1224 100%);
  color: var(--text);
}
button, input, select, textarea {
  font: inherit;
}
button {
  cursor: pointer;
  border: 0;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #0b1530;
  color: var(--text);
  border-radius: 14px;
  padding: 12px 14px;
}
textarea {
  resize: vertical;
  min-height: 100px;
}
label {
  display: block;
  margin: 10px 0 6px;
  color: var(--muted);
  font-size: 0.9rem;
}
.muted { color: var(--muted); }
.eyebrow {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.74rem;
}
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(106, 134, 255, 0.18);
  color: #bfd0ff;
  font-size: 0.8rem;
}
.primary-btn, .secondary-btn, .icon-btn {
  border-radius: 14px;
  padding: 12px 14px;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}
.primary-btn:hover, .secondary-btn:hover, .icon-btn:hover { transform: translateY(-1px); }
.primary-btn {
  background: var(--accent);
  color: white;
  font-weight: 700;
}
.secondary-btn, .icon-btn {
  background: #18284b;
  color: var(--text);
}
.full-width { width: 100%; }
.mobile-only { display: none; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 20px;
  border-right: 1px solid rgba(255,255,255,0.06);
  background: rgba(7, 13, 25, 0.9);
  backdrop-filter: blur(10px);
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 30;
}
.brand-block {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.brand-block h1 {
  margin: 6px 0 4px;
  font-size: 2rem;
}
.panel {
  background: rgba(15, 25, 48, 0.92);
  border: 1px solid rgba(120, 150, 220, 0.16);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.compact-panel {
  padding: 16px;
  margin-top: 16px;
}
.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.panel-title-row h2, .compact-panel h2 {
  margin: 0;
  font-size: 1.08rem;
}
.session-list {
  display: grid;
  gap: 10px;
}
.session-item {
  width: 100%;
  text-align: left;
  background: #0d1730;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  display: grid;
  gap: 6px;
}
.session-item strong {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-item span {
  color: var(--muted);
  font-size: 0.78rem;
}
.session-item.active {
  border-color: rgba(126, 151, 255, 0.85);
  background: #132244;
}
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.checkbox-row input { width: auto; }

.main-area {
  min-width: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(9, 16, 31, 0.88);
  backdrop-filter: blur(12px);
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.topbar-title {
  font-size: 1.08rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-layout {
  padding: 22px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 20px;
  min-width: 0;
}
.chat-card, .side-tools-card {
  padding: 18px;
  background: rgba(15, 25, 48, 0.92);
  border: 1px solid rgba(120, 150, 220, 0.16);
  border-radius: 22px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.chat-card {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: calc(100vh - 110px);
}
.messages {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-right: 4px;
}
.messages.empty-state {
  display: grid;
  place-items: center;
}
.empty-card {
  max-width: 560px;
  width: 100%;
  text-align: center;
  padding: 28px;
  border: 1px dashed rgba(146,168,230,0.24);
  border-radius: 18px;
  background: rgba(12, 20, 39, 0.72);
}
.empty-card h2 {
  margin-top: 0;
  margin-bottom: 10px;
}
.message {
  max-width: min(84%, 780px);
  padding: 14px 16px;
  line-height: 1.55;
  border-radius: 18px;
  border: 1px solid var(--line);
  white-space: pre-wrap;
  word-break: break-word;
}
.message.user {
  align-self: flex-end;
  background: linear-gradient(180deg, #20325b 0%, #1a2a4d 100%);
}
.message.assistant {
  align-self: flex-start;
  background: #0e1831;
}
.composer-wrap {
  display: grid;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.06);
  margin-top: 16px;
}
.composer-actions {
  display: grid;
  grid-template-columns: 1fr 160px;
  gap: 12px;
}
#toolOutput {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: calc(100vh - 180px);
  overflow: auto;
  color: #d9e4ff;
}

@media (max-width: 1180px) {
  .chat-layout {
    grid-template-columns: 1fr;
  }
  .chat-card {
    min-height: 65vh;
  }
  #toolOutput {
    max-height: 260px;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    bottom: 0;
    width: min(88vw, 340px);
    height: 100dvh;
    z-index: 40;
    transition: left 0.2s ease;
  }
  .sidebar.open {
    left: 0;
  }
  .sidebar-overlay.open {
    display: block;
  }
  .mobile-only {
    display: inline-flex;
  }
  .chat-layout {
    padding: 14px;
    gap: 14px;
  }
  .topbar {
    padding: 14px;
  }
  .chat-card, .side-tools-card {
    padding: 14px;
    border-radius: 18px;
  }
  .chat-card {
    min-height: calc(100dvh - 100px);
  }
  .message {
    max-width: 100%;
  }
  .composer-actions {
    grid-template-columns: 1fr;
  }
  .mobile-topbar-btn {
    padding: 10px 12px;
  }
}
