/* CrumAtlas — Shell design language (flat, monochrome, square corners). */

:root {
  --font-sans: "Plus Jakarta Sans", system-ui, sans-serif;
  --bg: #14060b;
  --bg-elevated: #1d0a12;
  --bg-hover: #2a1019;
  --border: #3c1723;
  --text: #f4eef1;
  --text-muted: #a28c95;
  --icon-color: #f4eef1;
  --danger: #e5484d;
  --danger-hover: #f2555a;
  --accent: #ff725b;
  --accent-strong: #ff9078;
  --overlay: rgba(8, 2, 5, 0.66);
  --titlebar-h: 36px;
  --control-size: 46px;
  --logo-size: 24px;
  --activitybar-active-bg: #f4eef1;
  --activitybar-active-text: #1d0a12;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #faf6f7;
  --bg-elevated: #ffffff;
  --bg-hover: #f2e9ec;
  --border: #e6d9dd;
  --text: #27161e;
  --text-muted: #7e6b73;
  --icon-color: #27161e;
  --danger: #d03f45;
  --danger-hover: #ba353c;
  --accent: #e05a41;
  --accent-strong: #c04430;
  --overlay: rgba(39, 22, 30, 0.4);
  --activitybar-active-bg: #27161e;
  --activitybar-active-text: #faf6f7;
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

/* Scrollbars are hidden everywhere; wheel input is forwarded to the chat
   thread across the whole view (see panels.ts), so scrolling stays easy
   without any visible bar. */
* {
  scrollbar-width: none;
}
*::-webkit-scrollbar {
  display: none;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  cursor: default;
}

body {
  height: 100dvh;
}

img,
svg {
  -webkit-user-drag: none;
  pointer-events: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg);
}

/* —— Titlebar (desktop app only) —— */

.titlebar {
  display: flex;
  align-items: stretch;
  height: var(--titlebar-h);
  flex-shrink: 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.titlebar__drag {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 10px 0 0;
  -webkit-app-region: drag;
  app-region: drag;
  min-width: 0;
}

.titlebar__logo {
  width: 48px;
  height: var(--titlebar-h);
  padding: calc((var(--titlebar-h) - var(--logo-size)) / 2) calc((48px - var(--logo-size)) / 2);
  display: block;
  flex-shrink: 0;
}

.titlebar__menu {
  display: flex;
  align-items: stretch;
  align-self: stretch;
  gap: 1px;
  flex-shrink: 0;
  height: 100%;
  -webkit-app-region: no-drag;
  app-region: no-drag;
}

.titlebar__menu-item {
  margin: 0;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  cursor: default;
  outline: none;
  transition: background-color 0.05s ease;
}

.titlebar__menu-item:hover,
.titlebar__menu-item.is-open {
  background: var(--bg-hover);
}

/* —— Menubar dropdown / context menu —— */

.menubar__dropdown {
  position: fixed;
  z-index: 1000;
  min-width: 240px;
  max-width: min(320px, calc(100vw - 16px));
  padding: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-family: var(--font-sans);
  -webkit-app-region: no-drag;
  app-region: no-drag;
}

.menubar__dropdown[hidden] {
  display: none !important;
}

.context-menu {
  z-index: 2100;
}

.menubar__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.3;
  text-align: left;
  cursor: default;
  outline: none;
  transition: background-color 0.05s ease;
}

.menubar__item:hover {
  background: var(--bg-hover);
}

.menubar__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menubar__shortcut {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}

.menubar__separator {
  height: 1px;
  margin: 5px 6px;
  background: var(--border);
}

.titlebar__controls {
  display: flex;
  -webkit-app-region: no-drag;
  app-region: no-drag;
}

.titlebar__btn {
  width: var(--control-size);
  height: var(--titlebar-h);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: default;
  outline: none;
  transition: background-color 0.05s ease, color 0.05s ease;
}

.titlebar__btn i {
  font-size: 14px;
  line-height: 1;
}

.titlebar__btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.titlebar__btn--close:hover {
  background: var(--danger);
  color: #ffffff;
}

/* —— App body —— */

.app-body {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
  position: relative;
}

/* —— Activity bar —— */

.activitybar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 48px;
  background: var(--bg);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.activitybar__top,
.activitybar__bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.activitybar__brand {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.activitybar__logo {
  width: 24px;
  height: 24px;
  display: block;
}

.activitybar__action {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--icon-color);
  cursor: pointer;
  outline: none;
  transition: color 0.06s ease, background-color 0.06s ease;
}

.activitybar__action i {
  font-size: 20px;
}

.activitybar__action:hover {
  color: var(--icon-color);
  background-color: var(--bg-hover);
}

.activitybar__action.is-active,
.activitybar__action.is-active:hover {
  color: var(--activitybar-active-text);
  background-color: var(--activitybar-active-bg);
}

/* —— Floating panels (Profile / Settings) —— */

.floating-panel {
  position: absolute;
  left: 48px;
  bottom: 0;
  width: 280px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: none;
  box-shadow: 4px 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.floating-panel.hidden {
  display: none !important;
}

.floating-panel__header {
  padding: 12px 16px;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.floating-panel__content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Profile panel */

.profile-avatar {
  width: 64px;
  height: 64px;
  background: var(--bg-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  color: var(--text-muted);
  border: 1px solid var(--border);
  overflow: hidden;
}

.profile-avatar i {
  font-size: 32px;
}

.profile-details {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  text-align: center;
  width: 100%;
}

.profile-view {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.profile-name-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
  padding: 2px 4px;
}

.profile-email-text {
  font-size: 12.5px;
  color: var(--text-muted);
  word-break: break-all;
  width: 100%;
  margin-top: -2px;
}

/* Settings panel */

.settings-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.theme-toggle {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.theme-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 0;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: background-color 0.06s ease, color 0.06s ease;
}

.theme-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.theme-btn.is-active {
  background: var(--activitybar-active-bg);
  color: var(--activitybar-active-text);
}

/* Edition read-only value row (which build this is) */

.settings-value {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

.settings-value i {
  font-size: 14px;
  color: var(--icon-color);
  flex-shrink: 0;
}

/* —— Buttons —— */

.crum-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: background-color 0.06s ease, color 0.06s ease, border-color 0.06s ease;
  text-decoration: none;
}

.crum-btn:hover {
  background: var(--bg-hover);
}

.crum-btn.primary-btn {
  background: var(--text);
  color: var(--bg);
  border-color: transparent;
}

.crum-btn.primary-btn:hover {
  background: var(--activitybar-active-bg);
  color: var(--activitybar-active-text);
}

/* —— Workspace —— */

.workspace {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.workspace-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 28px;
  padding: 24px 32px 32px;
}

.workspace-view.has-messages {
  justify-content: flex-start;
  gap: 16px;
  overflow: hidden;
}

/* Empty state: the hero title rests just above the composer in the middle
   of the page; after the first message the title moves into the topbar. */
.workspace-view:not(.has-messages) {
  gap: 16px;
}

.workspace-view:not(.has-messages) .chat-topbar {
  display: none;
}

.workspace-view:not(.has-messages) .chat-thread {
  flex: 0 0 auto;
}

.workspace-view:not(.has-messages) .chat-hero-title {
  margin-top: auto;
}

.workspace-view:not(.has-messages) .chat-composer {
  margin-bottom: auto;
}

.workspace-view.has-messages .chat-hero-title {
  display: none;
}

.chat-hero-title {
  max-width: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.workspace-view.has-messages .workspace-hero {
  width: min(640px, 100%);
  align-items: center;
  gap: 8px;
  margin: 0 auto;
  text-align: center;
}

.workspace-view.has-messages .workspace-hero__logo {
  width: 44px;
  height: 44px;
}

.workspace-view.has-messages .workspace-hero h1 {
  font-size: 16px;
}

.workspace-view.has-multiple-messages .workspace-hero {
  display: none;
}

.workspace-view.hidden {
  display: none !important;
}

.workspace-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.workspace-hero__logo {
  width: 112px;
  height: 112px;
  object-fit: contain;
}

.workspace-hero h1 {
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
}

.workspace-hero h1.is-typing {
  animation: workspace-title-type 360ms steps(var(--title-steps), end) both;
}

@keyframes workspace-title-type {
  from {
    clip-path: inset(0 100% 0 0);
  }
  to {
    clip-path: inset(0 0 0 0);
  }
}

.chat-composer {
  width: min(680px, 100%);
  min-height: 52px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  transition: border-color 0.06s ease;
}

.chat-composer:hover {
  border-color: var(--text-muted);
}

.chat-composer:focus-within {
  border-color: var(--text);
}

.chat-composer.is-loading {
  opacity: 0.72;
}

.chat-composer.is-loading .chat-composer__row button {
  cursor: wait;
}

.chat-composer__row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  min-width: 0;
}

.chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 10px 0;
}

.chat-attachments:empty {
  display: none;
}

.chat-attachment {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  width: min(196px, 100%);
  padding: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.06s ease;
}

.chat-attachment:hover {
  border-color: var(--text-muted);
}

.chat-attachment__media {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  background: var(--bg-hover);
  color: var(--text-muted);
  overflow: hidden;
}

.chat-attachment__media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.chat-attachment__media i {
  font-size: 17px;
}

.chat-attachment__meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-attachment__name {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-attachment__info {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-attachment__remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
  cursor: pointer;
  transition: color 0.06s ease, border-color 0.06s ease;
}

.chat-attachment:hover .chat-attachment__remove {
  color: var(--text);
}

.chat-attachment__remove:hover,
.chat-attachment__remove:focus-visible {
  color: var(--danger);
  border-color: var(--danger);
}

.chat-attachment__remove i {
  font-size: 11px;
}

.chat-attachment-status {
  padding: 0 2px;
  color: var(--danger);
  font-size: 11px;
}

.chat-attachment-status:empty {
  display: none;
}

.chat-thread {
  width: min(640px, 100%);
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.chat-thread:empty {
  display: none;
}

.chat-message {
  /* Avatar (28px) + gap (10px): the user side mirrors this gutter so both
     bubbles share the exact same max width and stay aligned. */
  --chat-gutter: 38px;
  flex-shrink: 0;
  width: 100%;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  animation: chat-message-in 0.09s cubic-bezier(0.2, 0, 0, 1) both;
}

@keyframes chat-message-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.chat-message--user {
  justify-content: flex-end;
}

.chat-message--assistant {
  color: var(--text);
}

.chat-message__avatar {
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  object-fit: contain;
  margin-top: 2px;
}

.chat-message__body {
  max-width: min(620px, 85%);
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
}

.chat-message--user .chat-message__body {
  margin-right: var(--chat-gutter);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
}

.chat-message__text,
.chat-message__text * {
  user-select: text;
  -webkit-user-select: text;
}

.chat-message__text::selection,
.chat-message__text *::selection,
.file-preview__body::selection,
.file-preview__body *::selection,
.chat-composer textarea::selection,
.chat-message__edit-input::selection {
  background: var(--accent);
  color: var(--bg);
}

.chat-message__text {
  min-width: 0;
  cursor: text;
}

/* Make AI responses easy to select, even when starting the drag on padding,
   tables, or math — the whole assistant bubble opts back into text selection. */
.chat-message--assistant .chat-message__body,
.chat-message--assistant .chat-message__body * {
  user-select: text;
  -webkit-user-select: text;
}

.chat-message--user .chat-message__text {
  white-space: pre-wrap;
}

.chat-message__text p,
.chat-message__text ul,
.chat-message__text ol,
.chat-message__text pre,
.chat-message__text blockquote,
.chat-message__text .table-scroll {
  margin: 0 0 10px;
}

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

.chat-message__text p:last-child,
.chat-message__text ul:last-child,
.chat-message__text ol:last-child,
.chat-message__text pre:last-child,
.chat-message__text blockquote:last-child,
.chat-message__text .table-scroll:last-child {
  margin-bottom: 0;
}

.chat-message__text h1,
.chat-message__text h2,
.chat-message__text h3,
.chat-message__text h4 {
  margin: 14px 0 8px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}

.chat-message__text > h1:first-child,
.chat-message__text > h2:first-child,
.chat-message__text > h3:first-child,
.chat-message__text > h4:first-child {
  margin-top: 0;
}

.chat-message__text h1 { font-size: 17px; }
.chat-message__text h2 { font-size: 15px; }
.chat-message__text h3 { font-size: 14px; }
.chat-message__text h4 { font-size: 13px; }

.chat-message__text ul,
.chat-message__text ol {
  padding-left: 18px;
}

.chat-message__text li {
  margin: 3px 0;
}

.chat-message__text li::marker {
  color: var(--text-muted);
}

/* Tables keep their natural ("long form") width and swipe horizontally inside
   the wrapper instead of being squeezed into the bubble. */
.chat-message__text .table-scroll {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.chat-message__text table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.chat-message__text th,
.chat-message__text td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
  max-width: 240px;
}

.chat-message__text th {
  background: var(--bg-hover);
  font-weight: 600;
}

/* Wide LaTeX display formulas scroll horizontally instead of breaking the bubble. */
.chat-message__text .katex-display {
  margin: 10px 0;
  padding: 2px 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.chat-message__text hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.chat-message__text code {
  padding: 1px 5px;
  border: 1px solid var(--border);
  background: var(--bg-hover);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.92em;
}

.chat-message__text pre {
  overflow-x: auto;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  white-space: pre;
}

.chat-message__text pre code {
  padding: 0;
  border: 0;
  background: transparent;
}

.chat-message__text blockquote {
  padding-left: 12px;
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
}

.chat-message__text a {
  color: var(--accent-strong);
  text-decoration: none;
}

.chat-message__text a:hover {
  text-decoration: underline;
}

.chat-message__attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.chat-message__attachment {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 240px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.06s ease, color 0.06s ease;
}

.chat-message__attachment:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.chat-message__attachment-media {
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  display: grid;
  place-items: center;
  background: var(--bg-hover);
  overflow: hidden;
}

.chat-message__attachment-media i {
  font-size: 14px;
}

.chat-message__attachment-thumb {
  width: 26px;
  height: 26px;
  object-fit: cover;
}

.chat-message__attachment-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* —— File preview popup (images, PDF, DOCX, XLSX, HTML, text, fallback) —— */

.file-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--overlay);
  animation: overlay-fade-in 0.08s ease-out both;
}

@keyframes overlay-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.file-preview {
  width: min(860px, 96vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  animation: file-preview-in 0.09s cubic-bezier(0.2, 0, 0, 1) both;
}

@keyframes file-preview-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.file-preview__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.file-preview__title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.file-preview__title > i {
  font-size: 20px;
  color: var(--icon-color);
  flex-shrink: 0;
}

.file-preview__name {
  display: block;
  max-width: min(420px, 46vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.file-preview__meta {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
}

.file-preview__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.file-preview__download {
  padding: 6px 12px;
  font-size: 12px;
}

.file-preview__close {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: background-color 0.06s ease;
}

.file-preview__close:hover {
  background: var(--bg-hover);
}

.file-preview__body {
  flex: 1;
  min-height: 160px;
  overflow: auto;
  background: var(--bg);
}

.file-preview__body,
.file-preview__body * {
  user-select: text;
  -webkit-user-select: text;
}

.file-preview__body > img {
  display: block;
  max-width: 100%;
  max-height: 76vh;
  margin: 0 auto;
  padding: 12px;
  object-fit: contain;
}

.file-preview__body iframe {
  display: block;
  width: 100%;
  height: min(76vh, 760px);
  border: 0;
  background: #ffffff;
}

.file-preview__doc,
.file-preview__text {
  padding: 18px 20px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
}

.file-preview__text {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.file-preview__doc p,
.file-preview__doc ul,
.file-preview__doc ol {
  margin: 0 0 10px;
}

.file-preview__table {
  padding: 14px;
  display: grid;
  gap: 12px;
  width: max-content;
  min-width: 100%;
}

.file-preview__sheet-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.file-preview__table table {
  border-collapse: collapse;
  font-size: 12px;
  color: var(--text);
}

.file-preview__table td,
.file-preview__table th {
  border: 1px solid var(--border);
  padding: 4px 10px;
  text-align: left;
  white-space: nowrap;
}

.file-preview__loading,
.file-preview__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 220px;
  padding: 32px 24px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.chat-message__text.is-loading {
  color: var(--text-muted);
}

/* Typing indicator: label plus three dots that type in one by one. */

.chat-thinking {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  line-height: 1.45;
}

.chat-thinking__label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.chat-thinking__dots {
  display: inline-flex;
  gap: 3px;
  height: 4px;
  flex: 0 0 auto;
  overflow: hidden;
  width: 0;
  animation: chat-typing-dots 1.6s steps(1, end) infinite;
}

.chat-thinking__dots span {
  width: 4px;
  height: 4px;
  flex: 0 0 4px;
  background: var(--text-muted);
}

@keyframes chat-typing-dots {
  0% {
    width: 0;
  }
  20% {
    width: 4px;
  }
  40% {
    width: 11px;
  }
  60% {
    width: 18px;
  }
  100% {
    width: 18px;
  }
}

.chat-message__text.is-streaming::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 13px;
  margin-left: 3px;
  vertical-align: -1px;
  background: var(--accent);
  animation: chat-caret-blink 0.9s steps(2, start) infinite;
}

@keyframes chat-caret-blink {
  to {
    visibility: hidden;
  }
}

.chat-message__actions {
  display: flex;
  gap: 4px;
  height: 0;
  min-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: height 0.06s ease, opacity 0.06s ease;
}

.chat-message--user .chat-message__actions {
  justify-content: flex-end;
}

.chat-message:hover .chat-message__actions,
.chat-message:focus-within .chat-message__actions {
  height: 24px;
  opacity: 1;
}

.chat-message__action {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.chat-message__action:hover,
.chat-message__action.is-copied {
  color: var(--text);
  background: var(--bg-hover);
}

.chat-message__action i {
  font-size: 14px;
}

.chat-message__body--editing {
  width: min(620px, 86%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--text-muted);
}

.chat-message__edit-input {
  width: 100%;
  min-height: 44px;
  max-height: 240px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
  caret-color: var(--accent);
  user-select: text;
  -webkit-user-select: text;
}

.chat-message__edit-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-message__edit-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 200px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 11px;
}

.chat-message__edit-file i {
  font-size: 13px;
  flex-shrink: 0;
}

.chat-message__edit-file span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-message__actions--editor {
  height: 24px;
  opacity: 1;
  justify-content: flex-end;
}

/* —— Attach sheet (mobile: take a photo or upload a file) —— */

.attach-menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 1300;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  background: var(--overlay);
  animation: overlay-fade-in 0.06s ease-out both;
}

.attach-menu {
  width: min(440px, 100%);
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  animation: file-preview-in 0.09s cubic-bezier(0.2, 0, 0, 1) both;
}

.attach-menu__title {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.attach-menu__option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.06s ease;
}

.attach-menu__option:hover {
  background: var(--bg-hover);
}

.attach-menu__option i {
  font-size: 18px;
  color: var(--icon-color);
}

.attach-menu__option--cancel {
  justify-content: center;
  border-bottom: 0;
  color: var(--text-muted);
}

.chat-composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 30px;
  max-height: 120px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.45;
  caret-color: var(--accent);
  user-select: text;
  -webkit-user-select: text;
}

.chat-composer textarea::placeholder {
  color: var(--text-muted);
}

.chat-composer__row button {
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.06s ease, color 0.06s ease, opacity 0.06s ease;
}

.chat-composer__row button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.chat-composer__row button i {
  font-size: 16px;
}

.chat-composer.is-ready .chat-send-button {
  background: var(--text);
  color: var(--bg);
}

.chat-composer.is-ready .chat-send-button:hover {
  background: var(--activitybar-active-bg);
  color: var(--activitybar-active-text);
}

.chat-composer.is-loading .chat-attach-button {
  opacity: 0.55;
}

/* While CrumAtlas is thinking/typing, the send button becomes a square stop button. */
.chat-send-button.is-stop,
.chat-composer.is-ready .chat-send-button.is-stop {
  background: var(--danger);
  color: #fff;
}

.chat-send-button.is-stop:hover,
.chat-composer.is-ready .chat-send-button.is-stop:hover {
  background: var(--danger-hover);
  color: #fff;
}

@media (prefers-reduced-motion: reduce) {
  .workspace-hero h1.is-typing,
  .chat-topbar__title.is-typing,
  .chat-message,
  .chat-thinking__dots,
  .file-preview-overlay,
  .file-preview,
  .attach-menu-overlay,
  .attach-menu,
  .dev-note,
  .session-notice {
    animation: none;
  }

  .chat-message__text.is-streaming::after {
    animation: none;
  }

  .chat-thinking__dots {
    width: 18px;
  }
}

/* —— Auth callback card —— */

.auth-card {
  position: fixed;
  inset: 0;
  margin: auto;
  width: 320px;
  height: max-content;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
}

/* —— Responsive behavior (web edition on phones and narrow split views) —— */

@media (max-width: 900px) {
  .workspace-view {
    gap: 20px;
    padding: 24px 20px;
  }

  .chat-thread,
  .chat-composer {
    width: 100%;
  }
}

@media (max-width: 600px) {
  .activitybar,
  .activitybar__brand,
  .activitybar__action {
    width: 44px;
  }

  .activitybar__brand,
  .activitybar__action {
    height: 44px;
  }

  .activitybar__logo {
    width: 22px;
    height: 22px;
  }

  .floating-panel {
    left: 44px;
    width: min(320px, calc(100vw - 44px));
    max-width: calc(100vw - 44px);
    max-height: calc(100% - 8px);
    overflow-y: auto;
  }

  .floating-panel__content {
    padding: 12px;
    gap: 12px;
  }

  .auth-card {
    width: calc(100vw - 32px);
    max-width: 320px;
  }

  .workspace-view {
    gap: 16px;
    padding: 0 12px 16px;
  }

  .chat-topbar {
    margin: 0 -12px;
    padding: 14px 12px 8px;
  }

  .workspace-hero__logo {
    width: 88px;
    height: 88px;
  }

  .workspace-hero h1 {
    font-size: 18px;
  }

  .chat-composer {
    min-height: 48px;
    padding: 8px;
  }

  /* 16px keeps iOS from zooming the page when the input is focused. */
  .chat-composer textarea {
    font-size: 16px;
  }

  .chat-message__body--editing {
    max-width: 100%;
  }

  .chat-message__avatar {
    width: 24px;
    height: 24px;
    flex-basis: 24px;
  }

  /* Keep the user-bubble gutter in sync with the smaller avatar (24px + 10px gap). */
  .chat-message {
    --chat-gutter: 34px;
  }

  .file-preview-overlay {
    padding: 10px;
  }

  .file-preview {
    width: 100%;
    max-height: 94vh;
  }

  .file-preview__name {
    max-width: 52vw;
  }
}

/* Touch devices have no hover: keep actions visible and tap targets comfortable. */

@media (hover: none), (pointer: coarse) {
  .chat-message__actions {
    height: 24px;
    opacity: 1;
  }

  .chat-attachment__remove {
    width: 28px;
    height: 28px;
    top: -11px;
    right: -11px;
  }

  .chat-attachment__remove i {
    font-size: 13px;
  }

  .chat-composer__row button {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  .chat-message__action {
    width: 28px;
    height: 28px;
  }
}

@media (max-width: 720px) {
  .titlebar__menu {
    max-width: calc(100vw - 48px - (var(--control-size) * 3));
    overflow: hidden;
  }

  .titlebar__menu-item:nth-child(n + 5) {
    display: none;
  }
}

/* ── Chat topbar: mode select · title · chats button ─────────────────────── */
.workspace {
  position: relative;
}

.chat-topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  /* Full-bleed inside the padded view so the buttons hug the top corners. */
  margin: 0 -32px;
  padding: 20px 16px 10px;
}

/* The topbar is an empty spacer strip now (the title was removed), keeping
   the conversation a comfortable distance from the window edge. */

.composer-mode {
  position: relative;
  flex-shrink: 0;
}

/* Beats the generic .chat-composer__row button sizing so the label fits. */
.chat-composer__row .composer-mode__button {
  width: auto;
  flex: 0 0 auto;
}

.composer-mode__button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.06s ease, color 0.06s ease;
}

.composer-mode__button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.composer-mode__button .ph {
  font-size: 15px;
}

.composer-mode__button .ph-caret-up {
  font-size: 10px;
}

/* The menu opens inside the composer box, above the input row. */
.composer-mode__menu {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 0 0 6px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg-elevated);
  animation: menu-pop 0.06s linear both;
}

.composer-mode__menu.hidden {
  display: none;
}

.composer-mode__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.composer-mode__item:hover {
  background: var(--bg-hover);
}

.composer-mode__item .ph {
  font-size: 15px;
}

.composer-mode__item.is-locked {
  color: var(--text-muted);
}

.composer-mode__check {
  display: none;
  margin-left: auto;
  color: var(--accent);
}

.composer-mode__item.is-selected .composer-mode__check {
  display: block;
}

/* ── Session notice popup (chats are not saved) ──────────────────────── */
.session-notice-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  background: var(--overlay);
}

.session-notice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(340px, calc(100vw - 48px));
  padding: 22px 22px 18px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg-elevated);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
  text-align: center;
  animation: dev-note-in 100ms cubic-bezier(0.22, 0.9, 0.3, 1);
}

.session-notice__icon {
  font-size: 26px;
  color: var(--accent);
}

.session-notice__title {
  color: var(--text);
  font-size: 14.5px;
  font-weight: 700;
}

.session-notice__body {
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.session-notice__confirm {
  width: 100%;
  margin-top: 8px;
  padding: 8px 12px;
  border: 1px solid var(--accent);
  border-radius: 0;
  background: var(--accent);
  color: #ffffff;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

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


/* ── "In development" note popup ──────────────────────────────────────────── */
.dev-note-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  background: var(--overlay);
}

.dev-note {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(300px, calc(100vw - 48px));
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg-elevated);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
  text-align: center;
  animation: dev-note-in 100ms cubic-bezier(0.22, 0.9, 0.3, 1);
}

.dev-note__icon {
  font-size: 26px;
  color: var(--accent);
}

.dev-note__title {
  color: var(--text);
  font-size: 14.5px;
  font-weight: 700;
}

.dev-note__body {
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.5;
}

@keyframes dev-note-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 720px) {
  .chat-topbar {
    gap: 8px;
  }

  .chat-topbar__title {
    font-size: 14px;
  }
}

/* ── Composer workspace footer (desktop folder attach) ──────────────── */

.composer-workspace {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 4px;
}

.workspace-folder-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.06s ease, color 0.06s ease;
}

.workspace-folder-button:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.workspace-folder-button .ph {
  font-size: 14px;
}

.workspace-folder-button.hidden {
  display: none;
}

.workspace-folder-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: min(320px, 100%);
  height: 28px;
  padding: 0 6px 0 10px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg-hover);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}

.workspace-folder-chip.hidden {
  display: none;
}

.workspace-folder-chip .ph-folder {
  color: var(--text-muted);
  font-size: 14px;
}

.workspace-folder-chip__name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.workspace-folder-chip__remove {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.workspace-folder-chip__remove:hover {
  color: var(--danger);
}

.workspace-folder-chip__remove .ph {
  font-size: 12px;
}

.composer-workspace__hint {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 11.5px;
}

/* ── @-mention file menu (desktop workspace) ─────────────────────────── */

.mention-menu {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 264px;
  overflow-y: auto;
  margin: 0 0 4px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--bg-elevated);
  animation: menu-pop 0.06s linear both;
}

.mention-menu__item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 6px 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}

.mention-menu__item:hover,
.mention-menu__item.is-selected {
  background: var(--bg-hover);
}

.mention-menu__item .ph {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 14px;
}

.mention-menu__name {
  flex-shrink: 0;
  font-weight: 600;
}

.mention-menu__path {
  min-width: 0;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 11.5px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* ── Agent tool steps (desktop workspace) ─────────────────────────────── */

.chat-tool-step {
  flex-shrink: 0;
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}

.chat-tool-step__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

.chat-tool-step__header > .ph {
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 15px;
}

.chat-tool-step__label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-tool-step__status {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: var(--text-muted);
}

.chat-tool-step.is-ok .chat-tool-step__status {
  color: var(--accent);
}

.chat-tool-step.is-error .chat-tool-step__status {
  color: var(--danger);
}

.chat-tool-step__output {
  max-height: 200px;
  overflow-y: auto;
  margin: 0;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
  -webkit-user-select: text;
}

.chat-tool-step__output.hidden {
  display: none;
}

@keyframes tool-spin {
  to {
    transform: rotate(360deg);
  }
}

.chat-tool-step__status .ph-spinner {
  animation: tool-spin 0.9s linear infinite;
}

@keyframes menu-pop {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}
