:root {
  color-scheme: dark;
  /* Dark theme: softer near-black (warm slate), green accents */
  --bg: #1a1f2a;
  --surface: #232938;
  --surface-strong: #1a1f2a;
  --surface-soft: #2d3441;
  --input-bg: #1f2531;
  --code-bg: #262d3a;
  --border: #2d3441;
  --border-strong: #3d4756;
  --text: #e6eaf2;
  --muted: #98a2b8;
  --accent: #22c55e;
  --accent-strong: #15803d;
  --accent-soft: #4ade80;
  --scroll-track: #1a1f2a;
  --scroll-thumb: #3d4756;
}

:root[data-theme="light"] {
  color-scheme: light;
  /* Light theme: warm beige surfaces, soft warm-black text, green accents */
  --bg: #f1ead8;
  --surface: #faf6ec;
  --surface-strong: #ece4cf;
  --surface-soft: #e3d9bf;
  --input-bg: #fdfaf2;
  --code-bg: #e8dec5;
  --border: #e0d6bd;
  --border-strong: #c8bca0;
  --text: #2b2620;
  --muted: #7a6f5d;
  --accent: #16a34a;
  --accent-strong: #15803d;
  --accent-soft: #22c55e;
  --scroll-track: #ece4cf;
  --scroll-thumb: #c8bca0;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  /* 10% smaller than the browser default (16px -> 14.4px). */
  font-size: 14.4px;
}

* {
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  height: 0.7rem;
  width: 0.7rem;
}

*::-webkit-scrollbar-track {
  background: var(--scroll-track);
}

*::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border: 2px solid var(--scroll-track);
  border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 0.65rem;
  background: var(--accent);
  color: white;
  cursor: pointer;
  padding: 0.65rem 0.85rem;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.layout {
  display: grid;
  grid-template-columns: var(--left-column, 20%) 8px minmax(0, var(--chat-column, 45%)) 8px var(--right-column, 35%);
  grid-template-rows: 100vh;
  height: 100vh;
  overflow: hidden;
}

.resizeHandle {
  background: var(--bg);
  cursor: col-resize;
  position: relative;
}

.resizeHandle::after {
  background: var(--border-strong);
  border-radius: 999px;
  content: "";
  inset: 0.75rem 3px;
  opacity: 0.65;
  position: absolute;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.resizeHandle:hover::after {
  background: var(--accent-soft);
  opacity: 1;
}

.sidebar,
.rightPanel {
  padding: 1rem;
  background: var(--surface);
  border-color: var(--border);
  height: 100%;
  min-height: 0;
  overflow: auto;
}

.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

.rightPanel {
  border-left: 1px solid var(--border);
}

.chat {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100vh;
  overflow: hidden;
}

.header,
.messages,
.inputBar {
  padding: 1rem;
}

.header {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.modelPicker {
  align-items: center;
  display: flex;
  gap: 0.5rem;
}

.headerControls {
  align-items: center;
  display: flex;
  gap: 0.5rem;
}

.iconToggle,
.languageToggle,
.newChatToggle {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--border-strong);
  color: var(--text);
  display: inline-flex;
  height: 2rem;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 2rem;
}

.languageToggle {
  font-size: 0.75rem;
  font-weight: 700;
  width: 2.4rem;
}

.modelPicker select {
  border: 1px solid var(--border-strong);
  border-radius: 0.65rem;
  background: var(--input-bg);
  color: var(--text);
  padding: 0.45rem 0.65rem;
}

.userBadge {
  display: inline-block;
  color: var(--text);
  font-size: 0.82rem;
  padding: 0;
  background: transparent;
}

.sidebarFooter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: auto;
  padding: 0.75rem 0.75rem 1.25rem;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

.sidebarFooter .userBadge {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settingsModal {
  width: min(540px, 92vw);
}

.deleteAllModal {
  width: min(480px, 92vw);
  border-color: var(--accent);
}

.deleteAllModal .docModalHeader {
  border-bottom-color: var(--accent);
  background: var(--accent-soft);
}

.deleteAllModal h1 {
  color: var(--accent);
}

.deleteAllInput {
  width: 100%;
  font: inherit;
  background: var(--input-bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 0.45rem;
  padding: 0.6rem 0.75rem;
  letter-spacing: 0.04em;
}

.deleteAllInput:focus-visible {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-strong);
}

.iconToggle.danger,
.formActions button.danger {
  color: white;
  border-color: var(--accent);
  background: var(--accent);
}

.iconToggle.danger:hover,
.formActions button.danger:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: white;
}

.formActions button.danger:disabled,
.iconToggle.danger:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.header small,
.muted,
.empty {
  color: var(--muted);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  overflow: auto;
}

.message {
  border: 1px solid var(--border);
  border-radius: 1rem;
  max-width: min(68ch, 88%);
  padding: 0.85rem 1rem;
}

.messageMeta {
  align-items: center;
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}

.messageMeta span {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.messageMeta button {
  background: var(--surface-soft);
  font-size: 0.72rem;
  padding: 0.25rem 0.45rem;
}

.messageMeta .repeatButton {
  align-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  display: inline-flex;
  font-size: 1rem;
  height: 1.8rem;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 1.8rem;
}

.markdownBody {
  line-height: 1.55;
}

.markdownBody > :first-child {
  margin-top: 0;
}

.messageStats {
  display: block;
  margin-top: 0.4rem;
  padding-top: 0.25rem;
  border-top: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
}

.markdownBody > :last-child {
  margin-bottom: 0;
}

.markdownBody p {
  margin: 0;
}

.markdownBody h1,
.markdownBody h2,
.markdownBody h3,
.markdownBody h4 {
  line-height: 1.25;
  margin: 0.85rem 0 0.45rem;
}

.markdownBody h1 {
  font-size: 1.35rem;
}

.markdownBody h2 {
  font-size: 1.2rem;
}

.markdownBody h3,
.markdownBody h4 {
  font-size: 1rem;
}

.markdownBody p + p,
.markdownBody ul,
.markdownBody ol,
.markdownBody pre,
.markdownBody blockquote,
.markdownBody table {
  margin-top: 0.65rem;
}

.markdownBody ul,
.markdownBody ol {
  padding-left: 1.25rem;
}

.markdownBody li + li {
  margin-top: 0.25rem;
}

.markdownBody code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
  padding: 0.08rem 0.25rem;
}

.markdownBody pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  overflow: auto;
  padding: 0.75rem;
}

.codeBlock {
  position: relative;
}

.codeCopy {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 1.8rem;
  height: 1.8rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 0.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.codeCopy:hover,
.codeCopy:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--surface-strong);
}

.codeCopy.copied {
  color: var(--accent);
  border-color: var(--accent);
}

.tableBlock {
  position: relative;
  margin: 0.5rem 0;
}

.tableBlockActions {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  display: inline-flex;
  gap: 0.35rem;
  z-index: 1;
}

.tableCopy,
.tableDownload {
  width: 1.8rem;
  height: 1.8rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 0.4rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
  padding: 0;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.tableCopy:hover,
.tableCopy:focus-visible,
.tableDownload:hover,
.tableDownload:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--surface-strong);
}

.tableCopy.copied {
  color: var(--accent);
  border-color: var(--accent);
}

.tableScroll {
  overflow: auto;
}

.markdownBody pre code {
  background: transparent;
  border: 0;
  padding: 0;
}

.markdownBody a {
  color: var(--accent-soft);
}

.markdownBody blockquote {
  border-left: 3px solid var(--border-strong);
  color: var(--text);
  margin-left: 0;
  padding-left: 0.75rem;
}

.markdownBody table {
  border-collapse: collapse;
  display: block;
  overflow: auto;
  width: 100%;
}

.markdownBody th,
.markdownBody td {
  border: 1px solid var(--border-strong);
  padding: 0.35rem 0.5rem;
}

.markdownBody th {
  background: var(--surface-soft);
}

.message.user {
  align-self: flex-end;
  background: var(--accent-strong);
  border-color: var(--accent);
  color: white;
}

.message.assistant {
  align-self: flex-start;
  background: var(--surface-strong);
}

.inputBar {
  display: flex;
  gap: 0.5rem;
  border-top: 1px solid var(--border);
}

.inputBar input {
  flex: 1;
  border: 1px solid var(--border-strong);
  border-radius: 0.75rem;
  background: var(--input-bg);
  color: var(--text);
  padding: 0.75rem 0.9rem;
}

.sendButton {
  align-items: center;
  background: var(--accent);
  border: 0;
  border-radius: 0.75rem;
  color: var(--surface-strong);
  cursor: pointer;
  display: inline-flex;
  height: 2.85rem;
  justify-content: center;
  padding: 0;
  transition: background 0.15s ease, transform 0.15s ease;
  width: 2.85rem;
}

.sendButton:hover:not(:disabled) {
  background: var(--accent-strong);
  transform: translateY(-1px);
}

.sendButton:active:not(:disabled) {
  transform: translateY(0);
}

.sendButton:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.sendButton.sending {
  background: var(--surface-soft);
  color: var(--accent);
}

.sendButton svg {
  fill: currentColor;
  height: 1.25rem;
  width: 1.25rem;
}

.errorBoundary {
  align-items: center;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 2rem;
  position: fixed;
  z-index: 2000;
}

.errorBoundaryCard {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-width: 32rem;
  padding: 1.25rem 1.4rem;
  width: 100%;
}

.errorBoundaryMessage {
  background: var(--code-bg);
  border-radius: 0.5rem;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  margin: 0;
  max-height: 12rem;
  overflow: auto;
  padding: 0.7rem 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.errorBoundaryActions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.errorBoundaryActions button {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--text);
  cursor: pointer;
  padding: 0.45rem 0.9rem;
}

.errorBoundaryActions button.primaryAction {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface-strong);
}

.errorBoundaryActions button:hover {
  filter: brightness(1.05);
}

.inputStatus {
  display: block;
  padding: 0.3rem 1rem 0.65rem;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

.sidebarHeader {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
  padding-bottom: 0.5rem;
}

.sidebarHeaderActions {
  display: flex;
  gap: 0.4rem;
}

.sidebarHeaderActions label {
  position: relative;
  cursor: pointer;
}

.sidebarHeaderActions label input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.brand {
  align-items: center;
  display: flex;
  gap: 0.65rem;
  min-width: 0;
}

.brandLogo {
  border-radius: 0.6rem;
  flex: 0 0 auto;
  height: 2.4rem;
  object-fit: contain;
  width: 2.4rem;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  letter-spacing: 0.08em;
}

.brand span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.1;
}

.sidebarHeader h1,
.rightPanel h2 {
  margin-top: 0;
}

.sessionList,
.panelList {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.session {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 0.5rem;
  color: var(--text);
  display: grid;
  gap: 0.25rem;
  grid-template-columns: 1fr auto;
  padding: 0.15rem 0.25rem;
  text-align: left;
}

.session.active {
  background: var(--surface-soft);
}

.session:hover {
  background: var(--surface-soft);
}

.sessionOpen {
  background: transparent;
  color: var(--text);
  display: block;
  min-width: 0;
  padding: 0.35rem 0.45rem;
  text-align: left;
}

.sessionOpen strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sessionActions {
  align-items: center;
  display: flex;
  flex: 0 0 auto;
  gap: 0.15rem;
  justify-content: flex-end;
  padding-right: 0.25rem;
}

.sessionActions button {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 0.85rem;
  height: 1.6rem;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 1.6rem;
}

.sessionActions button:hover {
  background: var(--border-strong);
  color: var(--text);
}

.newChatToggle {
  background: var(--accent);
  color: white;
  font-size: 1.2rem;
  line-height: 1;
}

.newChatToggle:hover {
  background: var(--accent-strong);
}

.showMore {
  background: transparent;
  border: 1px dashed var(--border-strong);
  color: var(--muted);
  font-size: 0.78rem;
  padding: 0.4rem;
}

.showMore:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.authTokenBox {
  border-top: 1px solid var(--border);
  display: grid;
  gap: 0.85rem;
  padding: 1.25rem 1.5rem 1.5rem;
}

.authTokenBox p {
  margin: 0;
  line-height: 1.45;
}

.authTokenBox > strong {
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 0.15rem;
}

.authTokenBox textarea {
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  border-radius: 0.75rem;
  color: var(--text);
  min-height: 5.5rem;
  padding: 0.65rem;
  resize: vertical;
}

.authTokenBox button {
  background: var(--accent-strong);
}

.authTokenBox small {
  color: var(--muted);
  font-size: 0.78rem;
}

.formActions {
  display: flex;
  gap: 0.65rem;
  margin-top: 0.35rem;
}

.formActions button {
  flex: 1 1 auto;
}

.formActions button[type="button"] {
  background: var(--surface-strong);
  color: var(--text);
}

.hasContext {
  color: var(--accent);
}

.session span,
.panelCard span,
.panelCard small {
  color: var(--muted);
  font-size: 0.78rem;
}

.panelCard {
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 0.45rem 0.75rem;
  padding: 0.8rem;
}

.panelCard p {
  margin: 0;
}

.panelCardBody {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.panelCardTitle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.panelCardTitle strong {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suggestedBadge {
  flex: 0 0 auto;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}

.panelCardAction {
  width: 2rem;
  height: 2rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  border-radius: 999px;
}

.panelCardAction.actionExecute {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.panelCardAction.actionExecute:hover,
.panelCardAction.actionExecute:focus-visible {
  background: var(--accent);
  color: var(--surface);
}

.docViewer {
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  border-radius: 1rem;
  display: grid;
  gap: 0.65rem;
  margin-bottom: 1.25rem;
  padding: 0.9rem;
}

.docViewerHeader {
  align-items: start;
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
}

.docViewerHeader h2 {
  margin: 0;
}

.docViewerHeader button {
  background: var(--surface-soft);
  padding: 0.45rem 0.65rem;
}

.docViewer span,
.docViewer small {
  color: var(--muted);
  font-size: 0.78rem;
}

.docViewer pre {
  background: var(--surface-strong);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.45;
  margin: 0;
  max-height: 42vh;
  overflow: auto;
  padding: 0.75rem;
  white-space: pre-wrap;
}

.rightPanel > h2:not(:first-child) {
  margin-top: 1.25rem;
}

.rightPanel > .panelList + h2,
.rightPanel > .panelList + .panelList,
.rightPanel > .panelList + .panelList + strong,
.rightPanel > .panelList + .docViewer,
.rightPanel > .docViewer + h2,
.rightPanel > .docViewer + .panelList,
.rightPanel > .docViewer + .panelHeading {
  margin-top: 1.25rem;
}

.panelSection + .panelSection {
  margin-top: 0.25rem;
}

.panelHeading {
  display: block;
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 0;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

.panelHeadingRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.usageBadge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.6rem;
  height: 1.45rem;
  padding: 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent-strong);
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 0.5rem;
}

.panelSection:first-child .panelHeading {
  margin-top: 0;
}

.panelCard.run {
  border-left: 4px solid #64748b;
}

.panelCard.run.success {
  border-left-color: #22c55e;
}

.panelCard.run.error {
  border-left-color: #ef4444;
}

/* Doc modal — fixed overlay on top of layout */
.docModalBackdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  padding: 2rem;
  box-sizing: border-box;
}

.docModal {
  position: relative;
  z-index: 1001;
  display: flex;
  flex-direction: column;
  width: min(900px, 100%);
  max-height: calc(100vh - 4rem);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.docModalHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-strong);
}

.docModalHeader h2 {
  margin: 0 0 0.25rem 0;
  font-size: 1.25rem;
}

.docModalHeader small {
  color: var(--muted);
  font-size: 0.85rem;
  word-break: break-all;
}

.docMeta {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 1.5rem;
  margin: 0;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
  font-size: 0.85rem;
}

.docMeta > div {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.docMeta dt {
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.docMeta dd {
  margin: 0;
  color: var(--text);
}

.docModalBody {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1.5rem;
}
