body:has(.workspace-page) .page-wrap {
  width: 100% !important;
  max-width: 100vw !important;
  min-width: 0 !important;
  height: 100vh !important;
  height: 100dvh !important;
  max-height: 100vh !important;
  max-height: 100dvh !important;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
}

body:has(.workspace-page) header {
  flex-shrink: 0;
}

body:has(.workspace-page) footer {
  position: relative;
  flex-shrink: 0;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 44px 6px 10px;
  box-sizing: border-box;
  background: var(--bg);
  border-top: 1px solid var(--border);
}

body:has(.workspace-page) footer .theme-toggle {
  position: absolute;
  right: 10px;
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
}

body:has(.workspace-page) .container {
  min-width: 0;
  max-width: 100%;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  padding: 10px 20px 0;
}

.workspace-page {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  flex: 1 1 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.workspace-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 280px;
  gap: 0;
  flex: 1 1 0;
  min-height: 0;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
}

.left-panel,
.center-panel,
.right-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.left-panel {
  border-radius: 12px 0 0 12px;
  padding: 16px;
  gap: 12px;
  overflow-y: auto;
}

.center-panel {
  padding: 16px 20px 12px;
  border-left: none;
  border-right: none;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  align-content: stretch;
}

.bottom-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  flex-shrink: 0;
  overflow: hidden;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
}

.right-panel {
  border-radius: 0 12px 12px 0;
  padding: 16px;
  overflow-y: auto;
}

.panel-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-text);
  margin: 0 0 8px;
}

.auth-banner {
  background: var(--surface-alt);
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 10px;
  font-size: 0.9rem;
  color: var(--muted-text);
}

.session-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.session-card:hover,
.session-card.active {
  border-color: var(--link);
}

.session-card-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.session-card-meta,
.muted {
  color: var(--muted-text);
  font-size: 0.82rem;
}

.file-preview-tag {
  display: inline-block;
  font-size: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  margin: 4px 4px 0 0;
}

.session-card-actions {
  margin-top: 6px;
  display: flex;
  gap: 8px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--link);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0;
}

.link-btn.danger {
  color: #dc3545;
}

.session-meta-box {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}

.session-meta-box code {
  font-size: 0.78rem;
  word-break: break-all;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

#chat-box {
  min-height: 0;
  max-height: 100%;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 10px;
  font-size: 0.875rem;
  line-height: 1.45;
}

.message {
  margin: 10px 0;
  max-width: 100%;
  min-width: 0;
}

.message.user {
  display: flex;
  justify-content: flex-end;
}

.message.llm {
  display: flex;
  justify-content: flex-start;
}

.bubble {
  display: block;
  padding: 9px 12px;
  border-radius: 12px;
  max-width: min(920px, 100%);
  box-sizing: border-box;
  text-align: left;
  overflow-wrap: anywhere;
  word-break: break-word;
  overflow-x: auto;
  font-size: 0.875rem;
  line-height: 1.45;
}

.bubble pre,
.bubble code {
  max-width: 100%;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble pre {
  padding: 7px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface-alt) 80%, var(--border));
  font-size: 0.82rem;
}

.bubble pre code {
  white-space: pre-wrap;
}

.bubble table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}

.bubble img,
.bubble svg {
  max-width: 100%;
  height: auto;
}

.bubble mjx-container {
  max-width: 100% !important;
  overflow-x: auto;
  overflow-y: hidden;
}

.chat-bubble-user {
  background: var(--header-bg);
  color: var(--header-text);
}

.message.llm .bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  flex-shrink: 0;
}

.composer-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
}

.composer-files:empty {
  display: none;
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-alt);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.composer-row.drag-over {
  border-color: var(--link);
  background: color-mix(in srgb, var(--link) 8%, var(--surface-alt));
}

.composer-attach {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.composer-attach:hover {
  border-color: var(--link);
  background: color-mix(in srgb, var(--link) 8%, var(--surface));
}

.composer textarea {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 36px;
  max-height: 120px;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  resize: none;
  box-sizing: border-box;
  background: transparent;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
}

.composer textarea:focus {
  outline: none;
}

.composer-send {
  flex-shrink: 0;
  min-width: 64px;
  height: 36px;
  padding: 0 14px;
  border: none;
  border-radius: 8px;
  background: var(--header-bg);
  color: var(--header-text);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

.composer-send:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.selected-file {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  max-width: 100%;
}

.selected-file span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remove-file {
  background: none;
  border: none;
  color: #dc3545;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
}

.btn-primary {
  background: var(--header-bg);
  color: var(--header-text);
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.prompt-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
  min-height: 0;
  max-height: 4.5rem;
  overflow-x: hidden;
  overflow-y: auto;
  flex-shrink: 0;
  padding: 2px 2px 0;
  scrollbar-width: thin;
}

.prompt-row:empty {
  display: none;
}

.quick-buttons,
.prompt-shortcuts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.quick-btn {
  border: none;
  background: var(--header-bg, #007bff);
  color: var(--header-text, #fff);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1.2;
  flex-shrink: 0;
}

.quick-btn:hover {
  filter: brightness(0.92);
}

.prompt-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 0;
  max-height: 4.5rem;
  overflow-x: hidden;
  overflow-y: auto;
  flex-shrink: 0;
  padding: 2px 2px 0;
  scrollbar-width: thin;
}

.prompt-bar:empty {
  display: none;
}

.prompt-chip-wrap {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.prompt-chip {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1.2;
}

.prompt-chip.add {
  border-style: dashed;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  opacity: 0.7;
}

.file-section {
  margin-bottom: 12px;
}

.file-section summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 6px 0;
}

.file-tree {
  list-style: none;
  padding: 0;
  margin: 4px 0 0;
}

.file-tree-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
}

.file-tree-item:hover {
  background: var(--surface-alt);
}

.file-size {
  color: var(--muted-text);
  font-size: 0.75rem;
}

.artifact-preview {
  max-width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.think-block,
.step-block {
  background: var(--surface-alt);
  border-left: 3px solid var(--link);
  padding: 7px 9px;
  margin: 6px 0;
  font-size: 0.82rem;
  max-width: 100%;
  overflow-x: auto;
}

.loading-spinner {
  display: none;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--link);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-status {
  font-size: 0.8rem;
  color: var(--muted, #666);
  white-space: nowrap;
}

.ingest-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 600;
  vertical-align: middle;
  line-height: 1.3;
}

.ingest-badge.indexed {
  background: #d4edda;
  color: #155724;
}

.ingest-badge.ocr {
  background: #cce5ff;
  color: #004085;
}

.ingest-badge.partial {
  background: #fff3cd;
  color: #856404;
}

.ingest-badge.tabular {
  background: #e2e3f3;
  color: #383d7c;
}

.ingest-badge.raw {
  background: var(--surface-alt, #eee);
  color: #555;
}

.ingest-badge.error {
  background: #f8d7da;
  color: #721c24;
}

.file-tree-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#toggle-files-btn {
  display: none;
}

@media (max-width: 1024px) {
  .workspace-shell {
    grid-template-columns: 240px minmax(0, 1fr);
  }
  .right-panel {
    display: none;
    position: fixed;
    right: 0;
    top: 60px;
    bottom: 0;
    width: min(320px, 90vw);
    z-index: 100;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.12);
  }
  .right-panel.open {
    display: flex;
  }
  #toggle-files-btn {
    display: inline-block;
  }
}

@media (max-width: 768px) {
  .workspace-shell {
    grid-template-columns: 1fr;
  }
  .left-panel {
    border-radius: 12px 12px 0 0;
    max-height: 200px;
  }
  .center-panel {
    border-radius: 0;
  }
}
