.thread-files-sidebar {
  --thread-files-width-ratio: 0.5;
  --thread-files-sidebar-width: clamp(
    280px,
    calc(var(--thread-files-width-ratio) * 100%),
    min(70%, calc(100% - 320px))
  );
  --thread-files-list-ratio: 0.25;
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  width: var(--thread-files-sidebar-width);
  min-width: var(--thread-files-sidebar-width);
  max-width: 100%;
  height: 100%;
  box-sizing: border-box;
  border-left: 1px solid var(--border-subtle);
  background: var(--bg-surface-1);
  color: var(--text-main);
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
  overflow: hidden;
  transition:
    width 0.18s ease,
    min-width 0.18s ease,
    max-width 0.18s ease;
}

.thread-files-sidebar.is-resizing {
  transition: none;
  user-select: none;
}

.thread-files-sidebar.is-collapsed {
  width: 0;
  min-width: 0;
  max-width: 0;
  border-left: 0;
  overflow: hidden;
  pointer-events: none;
  box-shadow: none;
}

.thread-files-sidebar:not(.is-collapsed) {
  width: min(var(--thread-files-sidebar-width), 100%);
  min-width: min(280px, 100%);
  max-width: 100%;
  box-shadow: -16px 0 32px rgba(15, 23, 42, 0.12);
}

.thread-files-resizer {
  position: absolute;
  inset: 0 auto 0 -4px;
  width: 8px;
  cursor: col-resize;
  z-index: 2;
}

.thread-files-resizer::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 3px;
  width: 2px;
  border-radius: 0;
  background: transparent;
}

.thread-files-resizer:hover::before,
.thread-files-sidebar.is-resizing .thread-files-resizer::before {
  background: var(--accent-main);
}

.thread-files-sidebar.is-collapsed .thread-files-resizer {
  display: none;
}

.thread-files-panel {
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.thread-files-sidebar.is-collapsed .thread-files-panel {
  display: none;
}

.thread-files-resizer:focus,
.thread-files-resizer:focus-visible {
  outline: none;
}

.thread-files-open-anchor {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 18;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.background-tasks-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-1);
  color: var(--text-dim);
  font-size: var(--font-size-caption);
  box-shadow: 0 6px 18px rgb(15 23 42 / 10%);
  white-space: nowrap;
}

.background-tasks-badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--info);
}

.thread-files-open-btn {
  position: relative;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-1);
  color: var(--text-dim);
  box-shadow: 0 6px 18px rgb(15 23 42 / 10%);
}

.thread-files-open-btn:hover {
  color: var(--text-main);
  background: var(--bg-surface-hover);
}

.thread-files-open-btn__count {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent-main);
  color: var(--accent-text);
  font-size: 10px;
  line-height: 16px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  text-align: center;
}

.thread-files-header__actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
}

.thread-files-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.thread-files-header__title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.thread-files-header__toggle {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-1);
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.thread-files-header__toggle:hover {
  color: var(--text-main);
  background: var(--bg-surface-hover);
}

.thread-files-header h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.2;
}

.thread-file-preview__header h3 {
  margin: 0;
  font-size: var(--font-size-title-xs);
}

.thread-files-header__badge {
  flex: none;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent-main);
  color: var(--accent-text);
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.thread-files-header p,
.thread-file-preview__header p {
  margin: 2px 0 0;
  color: var(--text-dim);
  font-size: var(--font-size-body-sm);
  line-height: 1.35;
  display: flex;
  align-items: center;
  gap: 6px;
}

.thread-file-preview__meta-check {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--complete) 18%, transparent);
  color: var(--complete);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.thread-files-list {
  flex: 0 1 auto;
  height: auto;
  min-height: 72px;
  max-height: max(72px, calc(var(--thread-files-list-ratio) * 100%));
  min-width: 0;
  padding: 8px 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  overflow: auto;
  scrollbar-gutter: stable;
}

.thread-files-panel-body {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.thread-files-panel-section {
  margin: 0;
  padding: 0;
}

.thread-files-panel-section + .thread-files-panel-section {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
}

.thread-files-list button.thread-files-panel-section__toggle {
  box-sizing: border-box;
  width: 100%;
  min-height: 28px;
  margin: 0;
  padding: 4px 2px 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.thread-files-panel-section__chevron {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  transition: transform 0.15s ease;
}

.thread-files-panel-section.is-collapsed .thread-files-panel-section__chevron {
  transform: rotate(-90deg);
}

.thread-files-panel-section__title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.thread-files-panel-section__count {
  flex: none;
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}

.thread-files-panel-section.is-collapsed .thread-files-panel-section__body {
  display: none;
}

.thread-files-panel-section__body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-left: 2px;
}

.thread-files-panel-section[data-panel-id="files"] .thread-files-section {
  padding-left: 6px;
}

.thread-files-section {
  margin: 0;
  padding: 0;
}

.thread-files-section + .thread-files-section {
  margin-top: 2px;
  padding-top: 0;
  border-top: 0;
}

.thread-files-list button.thread-files-section__toggle {
  box-sizing: border-box;
  width: 100%;
  min-height: 22px;
  margin: 0;
  padding: 2px 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font: inherit;
  color: inherit;
  text-align: left;
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.thread-files-section__toggle:hover {
  background: var(--bg-surface-hover);
}

.thread-files-section__toggle:focus,
.thread-files-section__toggle:focus-visible {
  outline: none;
  background: var(--bg-surface-hover);
}

.thread-files-section__chevron {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  transition: transform 0.15s ease;
}

.thread-files-section.is-collapsed .thread-files-section__chevron {
  transform: rotate(-90deg);
}

.thread-files-section__chevron svg {
  width: 12px;
  height: 12px;
}

.thread-files-section__title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: var(--font-size-caption);
  font-weight: 600;
  line-height: 16px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: left;
}

.thread-files-section__count {
  flex: 0 0 auto;
  min-width: 0;
  height: auto;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: var(--font-size-caption);
  line-height: 16px;
  font-variant-numeric: tabular-nums;
  opacity: 0.75;
}

.thread-files-section.is-collapsed .thread-files-section__body {
  display: none;
}

.thread-files-section__empty {
  padding: 2px 8px 4px 26px;
  color: var(--text-dim);
  font-size: var(--font-size-body-sm);
  line-height: 16px;
}

.thread-files-section__items {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0;
  padding: 0;
}

.thread-file-tree {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.thread-files-list button.thread-file-folder__toggle,
.thread-files-panel-body button.thread-file-folder__toggle {
  box-sizing: border-box;
  width: 100%;
  min-height: 22px;
  margin: 0;
  padding: 0 8px 0 calc(10px + var(--tree-depth, 0) * 16px);
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font: inherit;
  color: inherit;
  text-align: left;
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.thread-file-folder__toggle:hover {
  background: var(--bg-surface-hover);
}

.thread-file-folder__toggle:focus,
.thread-file-folder__toggle:focus-visible {
  outline: none;
  background: var(--bg-surface-hover);
}

.thread-file-folder__chevron {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  transition: transform 0.15s ease;
}

.thread-file-folder.is-collapsed .thread-file-folder__chevron {
  transform: rotate(-90deg);
}

.thread-file-folder.is-collapsed .thread-file-folder__body {
  display: none;
}

.thread-file-folder__body {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin: 2px 0 4px;
  padding: 0;
}

.thread-file-folder__name {
  flex: 1 1 auto;
  min-width: 0;
  font-family: inherit;
  font-size: var(--font-size-body-md);
  font-weight: 500;
  line-height: 22px;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-file-folder__count {
  flex: 0 0 auto;
  min-width: 4.5em;
  text-align: right;
  color: var(--text-dim);
  font-size: var(--font-size-caption);
  line-height: 22px;
  font-variant-numeric: tabular-nums;
  opacity: 0.82;
}

.thread-files-empty {
  padding: 6px 8px;
  color: var(--text-dim);
  font-size: var(--font-size-body-md);
  line-height: 16px;
}

.thread-file-preview__image {
  display: block;
  max-width: 100%;
  max-height: 320px;
  margin: 0 auto;
  border-radius: 10px;
  object-fit: contain;
}

.thread-files-list button.thread-file-row {
  box-sizing: border-box;
  width: 100%;
  min-height: 0;
  height: 22px;
  margin: 0;
  padding: 0 8px 0 calc(10px + var(--tree-depth, 0) * 14px);
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font: inherit;
  color: inherit;
  text-align: left;
  appearance: none;
  -webkit-appearance: none;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
}

.thread-files-list button.thread-file-row:hover:not(.is-active) {
  background: var(--bg-surface-hover);
}

.thread-files-list button.thread-file-row.is-active {
  background: var(--bg-surface-accent-selected);
  box-shadow: inset 3px 0 0 var(--accent-main);
}

.thread-files-list button.thread-file-row.is-active .thread-file-row__path {
  font-weight: 500;
  color: var(--text-main);
}

.thread-file-row:focus,
.thread-file-row:focus-visible {
  outline: none;
}

.thread-files-list button.thread-file-row:focus-visible:not(.is-active),
.thread-files-list button.thread-file-row:hover:focus-visible:not(.is-active) {
  background: var(--bg-surface-hover);
}

.thread-files-list button.thread-file-row.is-active:focus-visible {
  background: var(--bg-surface-accent-selected);
  box-shadow: inset 3px 0 0 var(--accent-main);
}

.thread-file-row__path {
  flex: 1 1 auto;
  min-width: 0;
  font-family: inherit;
  color: var(--text-main);
  font-size: var(--font-size-body-md);
  font-weight: 400;
  line-height: 22px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-file-row__meta {
  flex: 0 0 auto;
  min-width: 4.5em;
  text-align: right;
  color: var(--text-dim);
  font-size: var(--font-size-caption);
  line-height: 22px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  opacity: 0.82;
}

.thread-file-preview {
  min-height: 96px;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  padding: 10px 12px 0;
  gap: 10px;
  overflow: hidden;
}

.thread-file-preview.hidden {
  display: none;
}

.thread-file-preview__header {
  display: grid;
  gap: 10px;
}

.thread-file-preview__actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.thread-file-preview__content.document-viewer-text {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  white-space: normal;
  word-break: normal;
  overflow-wrap: normal;
  padding: 16px 18px;
  background: var(--doc-paper);
  color: var(--doc-text);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  /* color-scheme comes from .document-viewer-text (theme-aware). */
}

.thread-file-preview__content.document-viewer-text .document-viewer-markdown {
  flex: 1;
  min-height: 0;
  padding: 0;
}

.thread-file-preview__content.document-viewer-text .document-viewer-pre,
.thread-file-preview__content.document-viewer-text .thread-file-preview__code {
  margin: 0;
  border: 0;
  border-radius: 0;
  flex: 1 1 auto;
  min-height: 0;
  background: var(--doc-paper);
  color: var(--doc-text);
}

.thread-file-preview__content.document-viewer-text {
  display: flex;
  flex-direction: column;
}

.thread-file-preview__content .document-viewer-frame {
  min-height: 0;
  flex: 1;
  height: 100%;
}

.thread-file-preview__content .document-viewer-image-wrap {
  min-height: 0;
}

.thread-file-preview__content .document-viewer-docx-canvas {
  min-height: 0;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
}

.thread-file-preview__content {
  min-height: 0;
  flex: 1;
  margin: 0;
  padding: 16px 18px;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  overflow: auto;
  scrollbar-gutter: stable;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: var(--font-size-body-sm);
  background: var(--doc-paper);
  color: var(--doc-text);
}

.thread-file-preview__editor {
  min-height: 0;
  flex: 1;
  width: 100%;
  margin: 0;
  padding: 16px 18px;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  resize: none;
  overflow: auto;
  box-sizing: border-box;
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--font-size-body-sm);
  line-height: 1.45;
  background: var(--doc-paper, var(--bg-surface-1));
  color: var(--doc-text, var(--text-main));
  color-scheme: inherit;
}

html[data-theme="dark"] .thread-file-preview__editor {
  --doc-paper: var(--bg-surface-1);
  --doc-text: var(--text-main);
  color-scheme: dark;
}

.thread-file-preview__editor:focus {
  outline: 2px solid color-mix(in srgb, var(--accent, #2563eb) 40%, transparent);
  outline-offset: -1px;
}

.thread-file-preview__content.is-editing-hidden {
  display: none;
}

.thread-file-preview__content--markdown {
  padding: 16px 18px;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  white-space: normal;
  background: var(--doc-paper);
  color: var(--doc-text);
}

.thread-file-preview__content--binary {
  flex: 0 0 auto;
  min-height: auto;
  overflow: visible;
}

.thread-file-preview__message {
  box-sizing: border-box;
  width: 100%;
}

.thread-file-preview__content--code {
  padding: 0;
  border: 0;
  border-radius: 0;
  white-space: normal;
  background: transparent;
}

.thread-file-preview__code code.hljs {
  background: transparent;
}

.thread-file-preview__code {
  margin: 0;
  padding: 16px 18px;
  overflow: auto;
  border-radius: 0;
  border: 0;
  background: var(--doc-paper, var(--bg-surface-2));
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
}

.thread-file-preview__code code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

@media (max-width: 480px) {
  .main {
    padding-right: 0;
  }

  .chat-input-area {
    right: 0;
  }

  .app:has(.thread-files-sidebar:not(.is-collapsed)) .main {
    padding-right: var(--thread-files-rail, 0px);
  }

  .app:has(.thread-files-sidebar:not(.is-collapsed)) .chat-input-area {
    right: var(--thread-files-rail, 0px);
  }

  .thread-files-sidebar.is-collapsed {
    width: 0;
    min-width: 0;
    max-width: 0;
  }
}

.thread-files-sidebar.has-active-preview .thread-files-list {
  display: none;
}

.thread-files-sidebar.has-active-preview .thread-files-header__search {
  display: none;
}

.thread-files-sidebar.is-preview-expanded {
  position: absolute;
  inset: 0;
  width: 100% !important;
  min-width: 0 !important;
  max-width: none !important;
  z-index: 30;
  box-shadow: 0 0 60px rgb(15 23 42 / 18%);
}

.thread-files-header__search {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-1);
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.thread-files-header__search:hover {
  color: var(--text-main);
  background: var(--bg-surface-hover);
}

.thread-files-list {
  max-height: none;
  flex: 1 1 auto;
  border-bottom: 0;
  padding: 12px 14px 14px;
}

.thread-files-section__heading {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.thread-files-section__title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.thread-files-section__count {
  font-size: 11px;
  color: var(--text-muted);
}

.thread-files-section__items {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 2px 0 6px 8px;
}

.thread-file-card {
  display: flex;
  gap: 8px;
  align-items: center;
  box-sizing: border-box;
  width: calc(100% - var(--tree-depth, 0) * 16px);
  max-width: 100%;
  margin: 0 0 0 calc(var(--tree-depth, 0) * 16px);
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-surface-1);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.thread-file-card:hover,
.thread-file-card.is-active {
  border-color: var(--border-strong);
  background: color-mix(in srgb, var(--bg-surface-2, var(--bg-surface-1)) 80%, var(--accent-main) 8%);
}

.thread-file-card__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.thread-file-card__title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.thread-file-card__name {
  min-width: 0;
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-file-card__final {
  flex: none;
  padding: 1px 7px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--complete, #22c55e) 18%, transparent);
  color: var(--complete, #16a34a);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: lowercase;
}

.thread-file-card__chevron {
  flex: none;
  color: var(--text-dim);
  opacity: 0.7;
}

.thread-file-card__desc,
.thread-file-card__meta {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-participant-card,
.thread-kb-card {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-surface-1);
  color: inherit;
  box-sizing: border-box;
}

.thread-participant-card__avatar {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
  background: oklch(55% 0.12 250);
}

.thread-participant-card--agent .thread-participant-card__avatar {
  background: oklch(40% 0.02 260);
}

.thread-participant-card--reader .thread-participant-card__avatar {
  background: oklch(55% 0.12 150);
}

.thread-participant-card__body,
.thread-kb-card__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.thread-participant-card__name,
.thread-kb-card__title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-participant-card__role,
.thread-kb-card__subtitle,
.thread-participant-card__time,
.thread-kb-card__meta {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-participant-card__time,
.thread-kb-card__meta {
  flex: none;
}

.thread-kb-card__icon {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  background: color-mix(in srgb, var(--bg-surface-2, var(--bg-surface-1)) 70%, var(--border-subtle));
}

.thread-file-ext {
  width: 27px;
  height: 27px;
  border-radius: 7px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.thread-file-ext--xlsx { background: oklch(52% 0.1 148); }
.thread-file-ext--pdf { background: oklch(50% 0.14 25); }
.thread-file-ext--docx { background: oklch(50% 0.11 255); }
.thread-file-ext--pptx { background: oklch(56% 0.12 55); }
.thread-file-ext--md { background: oklch(48% 0.04 250); }
.thread-file-ext--bin { background: oklch(55% 0.01 90); }

.thread-file-preview__top {
  display: flex;
  align-items: flex-start;
  gap: 4px;
}

.thread-file-preview__titles {
  flex: 1;
  min-width: 0;
  padding: 2px 4px 0;
}

.thread-file-preview__titles h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.3;
  word-break: break-word;
}

.thread-file-preview__rename {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.thread-file-preview__rename-input {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  margin: 0;
  padding: 2px 6px;
  border: 1px solid var(--border-strong, var(--border-subtle));
  border-radius: 6px;
  background: var(--bg-surface-0, var(--bg-surface-1));
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.3;
  box-sizing: border-box;
}

.thread-file-preview__rename-ext {
  flex: none;
  padding: 2px 2px 2px 0;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 650;
  line-height: 1.3;
  user-select: none;
}

.thread-file-preview__rename-input:focus {
  outline: 2px solid color-mix(in srgb, var(--accent, #2563eb) 45%, transparent);
  outline-offset: 1px;
}

.thread-file-preview__icon-btn {
  width: 28px;
  height: 28px;
  flex: none;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-1);
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.thread-file-preview__more {
  position: relative;
  flex: none;
}

.thread-file-preview__more-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 5;
  min-width: 140px;
  padding: 4px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-surface-1);
  box-shadow: 0 10px 28px rgb(15 23 42 / 14%);
}

.thread-file-preview__more-menu button {
  display: block;
  width: 100%;
  margin: 0;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-main);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}

.thread-file-preview__more-menu button:hover:not(:disabled) {
  background: var(--bg-surface-hover);
}

.thread-file-preview__more-menu button:disabled {
  opacity: 0.45;
  cursor: default;
}

.thread-file-preview__icon-btn--ghost {
  border-color: transparent;
  background: transparent;
}

.thread-file-preview__icon-btn--ghost:hover {
  background: var(--bg-surface-hover);
}

.thread-file-preview__actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.thread-file-preview__action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-1);
  color: var(--text-main);
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}

.thread-file-preview__action:hover {
  border-color: var(--border-strong);
}

.thread-file-preview__action.is-active {
  background: var(--text-main);
  color: var(--bg-surface-1);
  border-color: var(--text-main);
}

.document-viewer-xlsx-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.document-viewer-xlsx-footer a {
  color: var(--info);
  font-weight: 600;
  text-decoration: none;
}

.document-viewer-xlsx-footer a:hover {
  text-decoration: underline;
}

.thread-file-preview__header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface-1);
}

.file-search-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: oklch(25% 0.01 90 / 32%);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 80px;
  backdrop-filter: blur(2px);
}

.file-search-panel {
  width: 720px;
  max-width: 86vw;
  max-height: 76vh;
  background: var(--bg-surface-1);
  border-radius: 14px;
  box-shadow: 0 24px 70px oklch(25% 0.02 90 / 28%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--text-main);
}

.file-search-panel__header {
  display: flex;
  flex-direction: column;
  padding: 15px 17px;
  border-bottom: 1px solid var(--border-subtle);
  flex: none;
}

.file-search-panel__search {
  display: flex;
  align-items: center;
  gap: 10px;
}

.file-search-panel__field {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-surface-1);
}

.file-search-panel__field svg {
  flex: none;
  color: var(--text-muted);
}

.file-search-panel__header input,
.file-search-panel__header input:focus,
.file-search-panel__header input:focus-visible {
  flex: 1;
  min-width: 0;
  min-height: 0;
  height: auto;
  margin: 0;
  padding: 0;
  border: 0 !important;
  outline: none;
  box-shadow: none !important;
  background: transparent !important;
  font: inherit;
  font-size: 15px;
  color: var(--text-main);
}

.file-search-filters {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex: none;
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-1);
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
}

.file-search-filters svg {
  color: currentColor;
}

.file-search-filters.is-active {
  background: var(--text-main);
  border-color: var(--text-main);
  color: var(--bg-surface-1);
}

.file-search-facets {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.file-search-facet-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.file-search-facet-row > span {
  width: 124px;
  flex: none;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.file-search-facet-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.file-search-facet-chips button {
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 16px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-1);
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
}

.file-search-facet-chips button.is-active {
  background: var(--text-main);
  border-color: var(--text-main);
  color: var(--bg-surface-1);
}

.file-search-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 17px 20px;
}

.file-search-group {
  margin-bottom: 20px;
}

.file-search-group__title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 9px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.file-search-group__title.is-final {
  color: oklch(44% 0.1 200);
}

.file-search-group__title.is-final svg {
  flex: none;
  color: oklch(55% 0.11 200);
}

.file-search-group__count {
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

.file-search-group__cards {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.file-search-card {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-surface-1);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.file-search-card:hover {
  border-color: color-mix(in srgb, var(--info, oklch(58% 0.1 200)) 45%, var(--border-subtle));
}

.file-search-card .thread-file-card__body {
  flex: 1;
}

.file-search-card .thread-file-card__desc {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.file-search-card--thread .file-search-card__thread-icon {
  width: 28px;
  height: 28px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--bg-surface-2);
  color: var(--text-muted);
}

.file-search-empty {
  text-align: center;
  padding: 44px 0;
}

.file-search-empty__title {
  font-size: 13px;
  color: var(--text-dim);
}

.file-search-empty__hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}
