@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&family=JetBrains+Mono:wght@400;500;600&family=Space+Grotesk:wght@500;600;700&display=swap");

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-canvas: #f5f3f0;
  --bg-shell: #efece8;
  --bg-sidebar: #eae7e2;
  --bg-sidebar-2: #e5e2dc;
  --bg-surface: #ffffff;
  --bg-surface-2: #f8f6f3;
  --bg-surface-3: #f0ede9;
  --text-main: #1a1a1a;
  --text-soft: #3d3d3d;
  --text-dim: #7a7a7a;
  --line: #d9d5cf;
  --line-strong: #c4bfb7;
  --accent: #c0392b;
  --accent-strong: #a93226;
  --accent-soft: rgba(192, 57, 43, 0.12);
  --danger: #c0392b;
  --warning: #b8860b;
  --ok: #27864a;
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 24px;
  --shadow-1: 0 10px 24px rgba(0, 0, 0, 0.08);
  --shadow-2: 0 18px 36px rgba(0, 0, 0, 0.1);
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(1200px 600px at -8% -14%, rgba(192, 57, 43, 0.06), transparent 58%),
    radial-gradient(980px 540px at 108% -4%, rgba(192, 57, 43, 0.04), transparent 62%),
    var(--bg-canvas);
  overflow: hidden;
}

body.claude-auth-gated #app {
  pointer-events: none;
  user-select: none;
  filter: blur(1.5px);
}

body.signin-page {
  min-height: 100vh;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.signin-shell {
  width: min(100%, 420px);
}

.signin-card {
  border-radius: 24px;
  padding: 1.2rem 1.15rem 1rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(245, 242, 238, 0.97));
  box-shadow: var(--shadow-2);
}

.signin-title {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  font-size: 1.25rem;
  font-weight: 650;
}

.signin-subtitle {
  color: var(--text-dim);
  margin-top: 0.35rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

#signin-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

#signin-form label {
  display: flex;
  flex-direction: column;
  gap: 0.32rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

#signin-form input {
  border: none;
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-main);
  border-radius: 12px;
  padding: 0.62rem 0.68rem;
  font-size: 0.92rem;
  font-family: inherit;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

#signin-form input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.15);
}

#signin-btn {
  margin-top: 0.25rem;
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 0.78rem;
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #ffffff;
  font-size: 0.92rem;
  font-weight: 600;
}

#signin-btn:hover {
  filter: brightness(1.05);
}

#magic-link-btn {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 0.78rem;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-soft);
  font-size: 0.9rem;
  font-weight: 560;
}

#magic-link-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
}

.signin-info {
  margin-top: 0.7rem;
  color: #a8d2ff;
  font-size: 0.84rem;
}

.signin-error {
  margin-top: 0.7rem;
  color: #c0392b;
  font-size: 0.84rem;
}

#app {
  height: 100vh;
  display: flex;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.01), rgba(0, 0, 0, 0));
}

* {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.25);
}

/* Sidebar */
aside#sidebar {
  width: 336px;
  min-width: 290px;
  max-width: 388px;
  background: linear-gradient(180deg, rgba(234, 231, 226, 0.96), rgba(229, 226, 220, 0.98));
  padding: 1rem 0.85rem 1rem 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.62rem;
  overflow: hidden;
  box-shadow: inset -22px 0 36px rgba(0, 0, 0, 0.03);
  transition: width 0.2s ease, min-width 0.2s ease, max-width 0.2s ease, padding 0.2s ease;
}

aside#sidebar.collapsed {
  width: 42px !important;
  min-width: 42px !important;
  max-width: 42px !important;
  padding: 0.6rem 0.24rem;
}

aside#sidebar.collapsed .sidebar-top,
aside#sidebar.collapsed .sidebar-actions,
aside#sidebar.collapsed #sidebar-view-switch,
aside#sidebar.collapsed #new-chat-form,
aside#sidebar.collapsed #new-project-form,
aside#sidebar.collapsed #tag-toolbar,
aside#sidebar.collapsed #project-list {
  display: none;
}

.sidebar-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 0.25rem;
}

.sidebar-brand {
  min-width: 0;
}

aside#sidebar h2 {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  font-size: 1.1rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.sidebar-subtitle {
  margin-top: 0.22rem;
  color: var(--text-dim);
  font-size: 0.83rem;
}

.sidebar-user {
  margin-top: 0.2rem;
  color: rgba(0, 0, 0, 0.5);
  font-size: 0.74rem;
}

.sidebar-top-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.14rem;
}

button {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.86rem;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, opacity 140ms ease;
}

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

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border-color: transparent;
  color: var(--text-soft);
  opacity: 0.8;
}

.icon-btn:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-main);
  opacity: 1;
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
  padding: 0 0.1rem 0.35rem;
}

#claude-auth-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1400;
  background: rgba(10, 18, 32, 0.48);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

#claude-auth-modal {
  width: min(500px, calc(100vw - 1.5rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.52rem;
  padding: 0.82rem 0.8rem 0.76rem;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(245, 242, 236, 0.98), rgba(238, 234, 227, 0.98));
  box-shadow: 0 24px 56px rgba(12, 17, 27, 0.28);
}

.claude-auth-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.claude-auth-modal-head h3 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 640;
  color: var(--text-main);
}

.sidebar-auth-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 0.76rem;
  font-weight: 550;
  padding-left: 0.1rem;
}

.sidebar-auth-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem;
}

#claude-profile-select {
  min-width: 0;
  border: none;
  background: rgba(0, 0, 0, 0.045);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.5rem;
  font-size: 0.84rem;
  font-family: inherit;
}

#claude-profile-select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.12);
}

#set-default-claude-profile-btn {
  padding: 0.42rem 0.55rem;
  font-size: 0.76rem;
  white-space: nowrap;
}

#claude-auth-connect-btn {
  padding: 0.45rem 0.5rem;
}

#claude-auth-cancel-btn {
  width: 100%;
  padding: 0.4rem 0.55rem;
  font-size: 0.8rem;
}

.claude-auth-link-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.42rem;
  align-items: center;
}

.sidebar-auth-link {
  color: var(--accent);
  font-size: 0.76rem;
  text-decoration: none;
  padding: 0 0.1rem;
}

.sidebar-auth-link:hover {
  text-decoration: underline;
}

.claude-auth-code-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.42rem;
}

#claude-auth-code-input {
  min-width: 0;
  border: none;
  background: rgba(0, 0, 0, 0.045);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.55rem;
  font-size: 0.84rem;
  font-family: inherit;
}

#claude-auth-code-input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.12);
}

#claude-auth-submit-btn {
  padding: 0.45rem 0.6rem;
  font-size: 0.8rem;
  white-space: nowrap;
}

#claude-auth-copy-link-btn {
  padding: 0.4rem 0.58rem;
  font-size: 0.76rem;
  white-space: nowrap;
}

.sidebar-auth-status {
  color: var(--text-dim);
  font-size: 0.74rem;
  line-height: 1.35;
  padding: 0 0.1rem;
}

.sidebar-auth-status.ok {
  color: #0f7a45;
}

.sidebar-auth-status.error {
  color: #9a281f;
}

.sidebar-auth-status.pending {
  color: var(--text-dim);
}

.sidebar-auth-status.pending::before {
  content: " ";
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.38rem;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.25);
  animation: claude-auth-pulse 1.2s ease-in-out infinite;
}

.claude-auth-reconnect-btn {
  margin-top: 0.2rem;
  align-self: flex-end;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-dim);
  font-size: 0.72rem;
  font-weight: 560;
  padding: 0.28rem 0.54rem;
}

.claude-auth-reconnect-btn:hover {
  background: rgba(0, 0, 0, 0.1);
  color: var(--text-main);
}

@keyframes claude-auth-pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

.view-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.25rem;
  padding: 0.05rem 0.22rem 0.2rem;
}

.view-switch-btn {
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-dim);
  font-size: 0.76rem;
  font-weight: 560;
  padding: 0.28rem 0.48rem;
}

.view-switch-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-main);
}

.view-switch-btn.active {
  background: rgba(192, 57, 43, 0.12);
  color: #7a1a12;
}

.sidebar-action-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.52rem 0.54rem;
  border-color: transparent;
  background: transparent;
  color: var(--text-soft);
  font-weight: 500;
  text-align: left;
  border-radius: 10px;
}

.sidebar-action-btn:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-main);
}

.btn-icon {
  display: inline-flex;
  flex-shrink: 0;
}

.form-card {
  border: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(245, 242, 238, 0.9));
  border-radius: var(--radius-md);
  padding: 0.68rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.form-card label {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  color: var(--text-dim);
  font-size: 0.78rem;
}

.form-card input,
.form-card select,
#msg-input,
.inline-edit-input {
  border: none;
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.62rem;
  font-size: 0.9rem;
  font-family: inherit;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.02);
}

.form-card input:focus,
.form-card select:focus,
#msg-input:focus,
.inline-edit-input:focus {
  outline: none;
  border-color: rgba(192, 57, 43, 0.6);
  box-shadow: 0 0 0 3px rgba(192, 57, 43, 0.15);
}

.row-actions {
  display: flex;
  gap: 0.45rem;
}

.row-actions button {
  flex: 1;
  padding: 0.55rem 0.7rem;
  font-weight: 550;
}

#tag-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.42rem;
  padding: 0.35rem 0.24rem 0.12rem;
}

.tag-toolbar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-dim);
  font-size: 0.78rem;
  padding: 0 0.16rem;
}

#new-tag-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.32rem;
}

#new-tag-form input[type="text"] {
  min-width: 0;
  border: none;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.04);
  padding: 0.42rem 0.52rem;
  font-size: 0.82rem;
}

#new-tag-form input[type="color"] {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: none;
  background: transparent;
  padding: 0;
}

#new-tag-form button {
  border: none;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-soft);
  padding: 0.42rem 0.56rem;
  font-size: 0.78rem;
}

#tag-filter-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
}

.tag-filter-item {
  display: inline-flex;
  align-items: center;
  gap: 0.22rem;
}

.tag-filter-chip {
  border: none;
  border-radius: 999px;
  padding: 0.2rem 0.54rem;
  font-size: 0.75rem;
  color: var(--text-soft);
  background: rgba(0, 0, 0, 0.04);
}

.tag-filter-chip.active {
  background: rgba(192, 57, 43, 0.13);
  color: #7a1a12;
}

.tag-filter-action {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tag-filter-action:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.05);
}

.tag-inline-input {
  min-width: 120px;
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-main);
  font-size: 0.75rem;
  padding: 0.2rem 0.52rem;
}

.tag-inline-color {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 999px;
  background: transparent;
  padding: 0;
}

#create-session-btn,
#create-project-btn {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  border-color: rgba(192, 57, 43, 0.4);
  color: #ffffff;
}

#create-session-btn:hover,
#create-project-btn:hover {
  filter: brightness(1.06);
}

.ghost-btn {
  background: rgba(0, 0, 0, 0.02);
  border-color: transparent;
  color: var(--text-soft);
}

.ghost-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-main);
}

#project-list {
  flex: 1;
  overflow-y: auto;
  padding-right: 0.12rem;
  padding-left: 0.08rem;
  display: flex;
  flex-direction: column;
  gap: 0.24rem;
}

#sidebar-collapsed-tab {
  width: 42px;
  min-width: 42px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.52rem;
  padding: 0.85rem 0;
  background: linear-gradient(180deg, rgba(234, 231, 226, 0.95), rgba(229, 226, 220, 0.97));
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}

#sidebar-collapsed-tab:hover {
  color: var(--text-main);
  background: linear-gradient(180deg, rgba(215, 212, 207, 0.97), rgba(225, 222, 216, 0.98));
}

#sidebar-collapsed-tab svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

#sidebar-collapsed-tab span {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 0.8rem;
  font-weight: 560;
  letter-spacing: 0.04em;
}

.project-card {
  border: none;
  background: transparent;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: none;
}

.project-header {
  display: flex;
  align-items: center;
  gap: 0.42rem;
  padding: 0.32rem 0.36rem 0.2rem;
  border-bottom: none;
}

.project-header .toggle-btn {
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.project-header .toggle-btn:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-main);
}

.project-name {
  flex: 1;
  min-width: 0;
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  font-size: 0.93rem;
  font-weight: 580;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-inline-input {
  flex: 1;
  min-width: 0;
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.34rem 0.5rem;
}

.project-count {
  font-size: 0.74rem;
  color: var(--text-dim);
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  line-height: 1.1;
}

.project-actions,
.session-actions {
  display: flex;
  gap: 0.2rem;
}

.project-action-btn,
.session-action-btn {
  width: 26px;
  height: 24px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.18;
}

.project-card:hover .project-action-btn,
.session-item:hover .session-action-btn,
.project-action-btn.active,
.session-action-btn.active {
  opacity: 1;
}

.project-action-btn:hover,
.session-action-btn:hover,
.project-action-btn.active,
.session-action-btn.active {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-main);
}

.project-action-btn.active,
.session-action-btn.active {
  background: rgba(192, 57, 43, 0.12);
  color: #7a1a12;
  box-shadow: none;
}

.project-dropzone {
  padding: 0.18rem 0.2rem 0.34rem;
  min-height: 20px;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
}

.project-dropzone.drag-over {
  background: rgba(192, 57, 43, 0.06);
  box-shadow: inset 0 0 24px rgba(192, 57, 43, 0.15);
  border-radius: 12px;
}

.project-card.collapsed .project-dropzone {
  display: none;
}

.project-archive {
  margin-top: 0.5rem;
  border-top: 1px solid rgba(0, 0, 0, 0.07);
  padding-top: 0.3rem;
}

.project-archive .project-header .archive-icon {
  width: 14px;
  height: 14px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.project-archive .project-name {
  font-weight: 500;
  color: var(--text-dim);
  font-size: 0.88rem;
}

.project-archive .session-item {
  opacity: 0.7;
}

.project-archive .session-item:hover {
  opacity: 1;
}

.session-item {
  border: none;
  border-radius: 14px;
  background: transparent;
  padding: 0.42rem 0.52rem 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  transition: background 130ms ease, color 130ms ease;
}

.session-item:hover {
  background: rgba(0, 0, 0, 0.04);
}

.session-item.active {
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.07), rgba(0, 0, 0, 0.05));
  box-shadow: none;
}

.session-item.locked {
  opacity: 0.68;
}

.session-item.dragging {
  opacity: 0.32;
}

.session-main {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.16rem;
}

.session-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.22rem;
}

.session-tag-chip {
  border: none;
  border-radius: 999px;
  padding: 0.08rem 0.4rem;
  font-size: 0.69rem;
  color: #111827;
  background: rgba(0, 0, 0, 0.06);
  cursor: pointer;
}

.session-label {
  font-size: 0.87rem;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-inline-input {
  width: 100%;
  font-size: 0.84rem;
  padding: 0.34rem 0.5rem;
}

.session-subline {
  font-size: 0.76rem;
  color: var(--text-dim);
}

.session-empty {
  color: var(--text-dim);
  font-size: 0.82rem;
  padding: 0.6rem 0.25rem;
}

.session-status {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
}

.empty-project {
  border: none;
  background: transparent;
  border-radius: 8px;
  color: var(--text-dim);
  text-align: center;
  font-size: 0.72rem;
  padding: 0.46rem;
}

/* Main chat */
main#chat-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.02), rgba(0, 0, 0, 0.01));
}

#chat-topbar {
  height: 64px;
  background: rgba(245, 242, 238, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  padding: 0.9rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 5;
}

.chat-title-wrap {
  min-width: 0;
}

.topbar-actions {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

#active-chat-title {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  font-size: 1.04rem;
  font-weight: 640;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#active-chat-meta {
  display: block;
  margin-top: 0.14rem;
  font-size: 0.76rem;
  color: var(--text-dim);
}

#review-panel {
  width: 360px;
  min-width: 320px;
  max-width: 460px;
  background: linear-gradient(180deg, rgba(245, 242, 238, 0.94), rgba(239, 236, 232, 0.96));
  display: flex;
  flex-direction: column;
  gap: 0.44rem;
  padding: 0.9rem 0.8rem;
  box-shadow: inset 1px 0 0 rgba(0, 0, 0, 0.06);
}

#review-panel.hidden {
  display: none;
}

#review-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

#review-panel-header h3 {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  font-size: 1rem;
  font-weight: 620;
}

#review-anchor {
  font-size: 0.78rem;
  color: var(--text-dim);
  min-height: 1.1rem;
}

#review-compose {
  display: flex;
  flex-direction: column;
  gap: 0.42rem;
}

#review-comment-input {
  border: none;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.88rem;
  padding: 0.58rem 0.62rem;
  resize: vertical;
}

#review-comments-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.34rem;
}

.review-comment {
  border: none;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.03);
  padding: 0.52rem 0.58rem;
}

.review-comment-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.72rem;
  color: var(--text-dim);
}

.review-comment-body {
  margin-top: 0.3rem;
  font-size: 0.84rem;
  color: var(--text-main);
  white-space: pre-wrap;
}

.review-comment-actions {
  margin-top: 0.34rem;
  display: flex;
  justify-content: flex-end;
  gap: 0.26rem;
}

.review-comment-actions button {
  border: none;
  border-radius: 999px;
  padding: 0.16rem 0.52rem;
  font-size: 0.72rem;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-soft);
}

.review-comment.resolved {
  opacity: 0.72;
}

#context-menu {
  position: fixed;
  z-index: 1200;
  min-width: 170px;
  border: none;
  border-radius: 12px;
  background: rgba(247, 244, 239, 0.98);
  box-shadow: var(--shadow-1);
  padding: 0.28rem;
}

#context-menu.hidden {
  display: none;
}

#context-menu button {
  width: 100%;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-main);
  padding: 0.45rem 0.5rem;
  font-size: 0.83rem;
  display: flex;
  align-items: center;
  gap: 0.42rem;
  justify-content: flex-start;
}

#context-menu button:hover {
  background: rgba(0, 0, 0, 0.05);
}

#toggle-review-btn.active {
  background: rgba(192, 57, 43, 0.12);
  color: #7a1a12;
}

.session-tag-picker {
  position: fixed;
  z-index: 1300;
  width: 250px;
  max-height: 280px;
  overflow: auto;
  border: none;
  border-radius: 12px;
  background: rgba(247, 244, 239, 0.99);
  box-shadow: var(--shadow-1);
  padding: 0.45rem;
}

.session-tag-picker-title {
  font-size: 0.74rem;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}

.session-tag-picker-list {
  display: flex;
  flex-direction: column;
  gap: 0.16rem;
}

.session-tag-picker-item {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  padding: 0.22rem 0.2rem;
  border-radius: 8px;
}

.session-tag-picker-item:hover {
  background: rgba(0, 0, 0, 0.04);
}

.session-tag-picker-empty {
  font-size: 0.78rem;
  color: var(--text-dim);
  padding: 0.25rem 0.12rem;
}

.tag-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-flex;
}

#lock-banner {
  background: rgba(184, 134, 11, 0.12);
  color: #8b6914;
  text-align: center;
  padding: 0.45rem 1rem;
  font-size: 0.82rem;
}

#no-session {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 1.02rem;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0 1.2rem;
}

#messages > * {
  width: min(920px, calc(100% - 2.2rem));
  margin-left: auto;
  margin-right: auto;
}

.message {
  border: none;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.02);
  padding: 0.82rem 0.96rem;
  line-height: 1.58;
  word-break: break-word;
  margin-bottom: 0.68rem;
  box-shadow: none;
}

.message.comment-target {
  box-shadow: inset 0 0 0 2px rgba(192, 57, 43, 0.26);
}

.message.user {
  max-width: min(760px, 88%);
  margin-left: auto;
  margin-right: 0;
  background: rgba(192, 57, 43, 0.08);
}

.message.assistant {
  background: rgba(0, 0, 0, 0.015);
}

.message-meta {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.42rem;
}

.message-comment-count {
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-dim);
  font-size: 0.68rem;
  padding: 0.08rem 0.42rem;
}

.message-text {
  white-space: pre-wrap;
}

.markdown-body {
  font-size: 0.97rem;
  line-height: 1.62;
}

.markdown-body p {
  margin: 0.5rem 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  line-height: 1.28;
  margin: 0.88rem 0 0.42rem;
  color: #1a1a1a;
}

.markdown-body h1 {
  font-size: 1.54rem;
}

.markdown-body h2 {
  font-size: 1.31rem;
}

.markdown-body h3 {
  font-size: 1.14rem;
}

.markdown-body h4 {
  font-size: 1.02rem;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0.55rem 0;
  padding-left: 1.35rem;
}

.markdown-body li {
  margin: 0.22rem 0;
}

.markdown-body .markdown-table-wrap {
  overflow-x: auto;
  margin: 0.62rem 0;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.03);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.markdown-body table {
  width: 100%;
  min-width: 520px;
  border-collapse: collapse;
  font-size: 0.9rem;
  line-height: 1.45;
}

.markdown-body th,
.markdown-body td {
  padding: 0.42rem 0.56rem;
  vertical-align: top;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  text-align: left;
}

.markdown-body thead th {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  font-size: 0.82rem;
  letter-spacing: 0.01em;
  color: var(--text-soft);
  background: rgba(0, 0, 0, 0.04);
}

.markdown-body tbody tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.015);
}

.markdown-body tbody tr:last-child td {
  border-bottom: none;
}

.markdown-body strong {
  color: #1a1a1a;
}

.markdown-body a {
  color: #c0392b;
  text-decoration-color: rgba(192, 57, 43, 0.4);
}

.markdown-body a:hover {
  color: #e74c3c;
}

.markdown-body hr {
  border: none;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  margin: 0.9rem 0;
}

.markdown-body blockquote {
  border-left: 3px solid rgba(192, 57, 43, 0.3);
  padding-left: 0.72rem;
  color: var(--text-soft);
  margin: 0.6rem 0;
}

.markdown-body pre {
  background: rgba(0, 0, 0, 0.04);
  border: none;
  border-radius: 14px;
  padding: 0.72rem;
  overflow-x: auto;
  margin: 0.62rem 0;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.015);
}

.markdown-body code {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.84em;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 6px;
  padding: 0.14rem 0.32rem;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
}

.markdown-body button {
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-soft);
  padding: 0.14rem 0.5rem;
  font-size: 0.82rem;
  font-weight: 500;
}

.markdown-body button:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-main);
}

.message.error {
  box-shadow: inset 0 0 0 1px rgba(192, 57, 43, 0.3);
  background: rgba(192, 57, 43, 0.08);
  color: #c0392b;
  font-size: 0.86rem;
}

.citation-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.18rem;
  border: none;
  background: rgba(0, 0, 0, 0.05);
  color: #7a1a12;
  border-radius: 999px;
  padding: 0.04rem 0.44rem;
  margin: 0 0.08rem;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.78em;
  line-height: 1.35;
  cursor: pointer;
}

.citation-chip:hover {
  background: rgba(0, 0, 0, 0.08);
}

.markdown-body .article-ref-chip {
  border: none;
  background: transparent;
  color: #c0392b;
  text-decoration: underline;
  text-decoration-color: rgba(192, 57, 43, 0.35);
  border-radius: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  cursor: pointer;
}

.markdown-body .article-ref-chip:hover {
  color: #e74c3c;
  text-decoration-color: rgba(192, 57, 43, 0.6);
  background: transparent;
}

.tool-group {
  margin-bottom: 0.6rem;
  color: var(--text-dim);
  font-size: 0.74rem;
}

.tool-group-summary {
  display: inline-block;
  padding: 0.1rem 0;
  border-radius: 0;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}

.tool-group-summary:hover {
  color: var(--text-soft);
}

.tool-group-summary::before {
  content: "\25B6 ";
  font-size: 0.62rem;
}

.tool-group:not(.collapsed) .tool-group-summary::before {
  content: "\25BC ";
}

.tool-group-details {
  margin-top: 0.24rem;
  margin-left: 0.1rem;
  padding-left: 0.68rem;
  border-left: 1px solid rgba(0, 0, 0, 0.08);
}

.tool-group.collapsed .tool-group-details {
  display: none;
}

.tool-use-item {
  font-size: 0.72rem;
  padding: 0.05rem 0;
}

.cost-info {
  color: var(--text-dim);
  text-align: right;
  font-size: 0.74rem;
  margin-bottom: 0.62rem;
}

.status-info {
  color: var(--text-dim);
  text-align: right;
  font-size: 0.74rem;
  margin-bottom: 0.62rem;
}

#input-bar {
  width: min(920px, calc(100% - 2.2rem));
  margin: 0.15rem auto 0.95rem;
  padding: 0.52rem 0.54rem;
  border: none;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.015);
  display: flex;
  gap: 0.45rem;
  box-shadow: none;
}

#msg-input {
  flex: 1;
  resize: none;
  min-height: 43px;
  max-height: 220px;
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.03);
  box-shadow: none;
}

.composer-btn {
  align-self: center;
}

#voice-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  color: var(--text-dim);
}

#voice-btn:hover {
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-main);
}

#voice-btn.active {
  background: rgba(192, 57, 43, 0.12);
  color: #c0392b;
}

#stop-btn {
  padding: 0.4rem 0.65rem;
  border-radius: 999px;
  border: none;
  background: rgba(192, 57, 43, 0.1);
  color: #a93226;
  font-weight: 520;
}

#stop-btn:hover {
  background: rgba(192, 57, 43, 0.18);
  color: #7a1a12;
}

#send-btn {
  width: auto;
  min-width: 0;
  align-self: center;
  padding: 0.42rem 0.34rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-weight: 520;
  letter-spacing: 0.01em;
}

#send-btn:hover {
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-main);
}

/* Source panel + resizer */
#source-resizer {
  width: 5px;
  cursor: col-resize;
  border-left: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.04), transparent);
}

aside#source-panel {
  width: 420px;
  min-width: 300px;
  max-width: 760px;
  border-left: none;
  background: linear-gradient(180deg, rgba(240, 237, 233, 0.97), rgba(235, 232, 227, 0.98));
  display: flex;
  flex-direction: column;
  box-shadow: inset 24px 0 34px rgba(0, 0, 0, 0.03);
  transition: width 0.2s ease, min-width 0.2s ease;
}

aside#source-panel.collapsed {
  width: 42px !important;
  min-width: 42px !important;
  max-width: 42px !important;
  overflow: hidden;
}

aside#source-panel.collapsed #source-panel-header,
aside#source-panel.collapsed #source-panel-toolbar,
aside#source-panel.collapsed #source-breadcrumbs,
aside#source-panel.collapsed #source-navigator,
aside#source-panel.collapsed #source-panel-body {
  display: none;
}

#source-collapsed-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 0;
  cursor: pointer;
  color: var(--text-dim);
  transition: color 0.15s;
  height: 100%;
}

#source-collapsed-tab:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.03);
}

#source-collapsed-tab svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

#source-collapsed-tab span {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 0.8rem;
  font-weight: 560;
  letter-spacing: 0.04em;
}

#source-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1rem;
  background: rgba(240, 237, 233, 0.9);
}

#source-panel-header h3 {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  font-size: 0.95rem;
  font-weight: 620;
}

#source-panel-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.42rem 0.92rem 0.3rem;
}

.source-toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.18rem;
}

.source-tool-btn {
  height: 28px;
  min-width: 28px;
  border: none;
  border-radius: 9px;
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-dim);
  padding: 0 0.56rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 540;
}

.source-tool-btn:hover:not(:disabled) {
  background: rgba(0, 0, 0, 0.07);
  color: var(--text-main);
}

.source-tool-btn.active {
  background: rgba(192, 57, 43, 0.15);
  color: #7a1a12;
}

.source-tool-btn:disabled {
  opacity: 0.42;
}

.source-view-toggle .source-tool-btn {
  min-width: 72px;
}

#source-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0 0.92rem 0.45rem;
  overflow-x: auto;
  white-space: nowrap;
}

#source-navigator {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0 0.92rem 0.56rem;
  min-height: 0;
}

#source-doc-switch {
  display: flex;
  align-items: center;
  gap: 0.24rem;
  flex-wrap: wrap;
}

.source-doc-btn {
  border: none;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 560;
  padding: 0.2rem 0.56rem;
}

.source-doc-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-main);
}

.source-doc-btn.active {
  background: rgba(192, 57, 43, 0.15);
  color: #7a1a12;
}

.source-search-wrap {
  display: flex;
  align-items: center;
  gap: 0.34rem;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 999px;
  padding: 0.22rem 0.46rem;
  color: var(--text-dim);
}

.source-search-wrap svg {
  width: 13px;
  height: 13px;
  stroke-width: 1.9;
  flex-shrink: 0;
}

#source-search-input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-size: 0.8rem;
  font-family: inherit;
  padding: 0.08rem 0;
}

#source-search-input:focus {
  outline: none;
}

#source-search-input::placeholder {
  color: rgba(0, 0, 0, 0.3);
}

#source-nav-list {
  max-height: min(34vh, 320px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.06rem;
  padding-right: 0.12rem;
  scrollbar-width: thin;
}

#source-panel.no-active-file #source-panel-body {
  display: none;
}

#source-panel.no-active-file #source-navigator {
  flex: 1;
  padding-bottom: 0.86rem;
}

#source-panel.no-active-file #source-nav-list {
  max-height: none;
  flex: 1;
  min-height: 0;
}

#source-panel.has-active-file #source-panel-body {
  order: 4;
  flex: 1;
  display: block;
  padding: 0 0.95rem 0.95rem;
}

#source-panel.has-active-file #source-panel-toolbar {
  order: 5;
}

#source-panel.has-active-file #source-breadcrumbs {
  order: 6;
}

#source-panel.has-active-file #source-navigator {
  order: 7;
  flex: 0 0 auto;
  padding-top: 0.34rem;
  border-top: 1px solid rgba(0, 0, 0, 0.04);
}

#source-panel.has-active-file #source-nav-list {
  max-height: min(26vh, 260px);
}

.source-nav-empty {
  font-size: 0.78rem;
  color: var(--text-dim);
  padding: 0.3rem 0.2rem;
}

.source-nav-title-group {
  display: flex;
  flex-direction: column;
  gap: 0.04rem;
}

.source-nav-title-btn {
  width: 100%;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-soft);
  display: flex;
  align-items: center;
  gap: 0.24rem;
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  font-size: 0.74rem;
  text-align: left;
  padding: 0.18rem 0.24rem;
}

.source-nav-title-btn:hover {
  background: rgba(0, 0, 0, 0.04);
}

.source-nav-title-btn svg {
  width: 12px;
  height: 12px;
  stroke-width: 1.9;
  flex-shrink: 0;
}

.source-nav-title-btn small {
  color: var(--text-dim);
  font-weight: 420;
  margin-left: 0.12rem;
}

.source-nav-title-group.collapsed .source-nav-title-body {
  display: none;
}

.source-nav-title-body {
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  margin-left: 0.14rem;
}

.source-nav-chapter-btn {
  width: 100%;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-soft);
  display: flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.76rem;
  text-align: left;
  padding: 0.17rem 0.24rem;
}

.source-nav-chapter-btn:hover {
  background: rgba(0, 0, 0, 0.04);
}

.source-nav-chapter-btn svg {
  width: 12px;
  height: 12px;
  stroke-width: 1.9;
  flex-shrink: 0;
}

.source-nav-group.collapsed .source-nav-items {
  display: none;
}

.source-nav-items {
  margin-left: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.02rem;
}

.source-nav-item {
  display: flex;
  align-items: center;
  gap: 0.32rem;
  padding: 0.02rem 0.02rem 0.02rem 0.04rem;
}

.source-nav-item.active {
  background: rgba(192, 57, 43, 0.12);
  color: #7a1a12;
}

.source-nav-open-btn {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 0.2rem 0.22rem;
}

.source-nav-open-btn:hover {
  background: rgba(0, 0, 0, 0.04);
}

.source-nav-open-btn.active {
  color: #7a1a12;
}

.source-nav-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.04rem;
}

.source-nav-item-token {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.66rem;
  color: #c0392b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-nav-item-label {
  font-size: 0.75rem;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-nav-copy-btn {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.2;
}

.source-nav-item:hover .source-nav-copy-btn,
.source-nav-copy-btn:focus-visible {
  opacity: 1;
}

.source-nav-copy-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: var(--text-main);
}

.source-nav-copy-btn svg {
  width: 12px;
  height: 12px;
  stroke-width: 1.95;
}

.source-crumb {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.76rem;
  padding: 0.16rem 0.2rem;
  border-radius: 7px;
}

.source-crumb:hover:not(:disabled) {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.04);
}

.source-crumb.active {
  color: var(--text-soft);
  background: rgba(0, 0, 0, 0.03);
}

.source-crumb-sep {
  color: rgba(0, 0, 0, 0.2);
  font-size: 0.72rem;
}

#collapse-source-btn {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  border: none;
  background: rgba(0, 0, 0, 0.03);
  color: var(--text-dim);
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#collapse-source-btn:hover {
  color: var(--text-main);
  background: rgba(0, 0, 0, 0.08);
}

#collapse-source-btn svg {
  width: 16px;
  height: 16px;
}

#source-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.95rem;
  scrollbar-width: none;
  scrollbar-color: transparent transparent;
}

#source-panel-body::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.source-empty,
.source-loading,
.source-error {
  font-size: 0.9rem;
  line-height: 1.5;
}

.source-empty {
  color: var(--text-dim);
}

.source-loading {
  color: var(--warning);
}

.source-error {
  color: #c0392b;
}

.source-meta {
  border: none;
  background: transparent;
  padding: 0.08rem 0.12rem;
  margin-bottom: 0.44rem;
}

.source-meta.minimal {
  position: sticky;
  top: 0;
  z-index: 3;
  margin-top: 0;
  padding: 0.24rem 0.18rem 0.3rem;
  margin-bottom: 0.4rem;
  background: rgba(245, 243, 240, 0.98);
}

.source-meta.compact {
  margin-top: 0.72rem;
}

.source-meta p {
  margin: 0.14rem 0;
  font-size: 0.82rem;
}

.source-ref {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  color: #c0392b;
  font-size: 0.8rem;
  letter-spacing: 0.01em;
}

.source-rel-path {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  color: rgba(0, 0, 0, 0.4);
  font-size: 0.74rem;
}

.source-match-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.source-match-btn {
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.03), rgba(0, 0, 0, 0.015));
  color: var(--text-main);
  text-align: left;
  padding: 0.62rem 0.72rem;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.015);
}

.source-match-btn:hover {
  background: rgba(192, 57, 43, 0.1);
  box-shadow: inset 0 0 0 1px rgba(192, 57, 43, 0.2);
}

.source-match-btn span {
  color: var(--text-dim);
  font-size: 0.8rem;
}

#source-content-host {
  min-height: 180px;
}

.source-markdown-box {
  position: relative;
  z-index: 1;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.03);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.06);
  padding: 0.72rem 0.78rem;
}

.source-pdf-wrap {
  width: 100%;
  min-height: min(74vh, 780px);
  background: rgba(0, 0, 0, 0.03);
  border-radius: 12px;
  overflow: hidden;
}

.source-pdf-frame {
  width: 100%;
  min-height: min(74vh, 780px);
  border: none;
  background: #f0ede9;
}

.source-pdf-empty {
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.02);
  padding: 0.78rem 0.82rem;
}

.source-pdf-empty p {
  margin: 0.16rem 0;
}

.source-pdf-hint {
  color: var(--text-dim);
  font-size: 0.82rem;
}

#source-panel .markdown-body {
  font-size: 0.94rem;
}

#source-panel .markdown-body h1 {
  font-size: 1.05rem;
}

#source-panel .markdown-body h2 {
  font-size: 0.98rem;
}

#source-panel .markdown-body h3 {
  font-size: 0.92rem;
}

#source-panel .markdown-body p {
  margin: 0.42rem 0;
}

.sidebar-action-btn svg,
.icon-btn svg {
  width: 16px;
  height: 16px;
  stroke-width: 1.9;
}

.project-action-btn svg,
.session-action-btn svg {
  width: 14px;
  height: 14px;
  stroke-width: 1.95;
}

.project-header .toggle-btn svg {
  width: 14px;
  height: 14px;
  stroke-width: 1.9;
}

.source-tool-btn svg {
  width: 14px;
  height: 14px;
  stroke-width: 1.9;
}

.session-status svg {
  width: 12px;
  height: 12px;
  stroke-width: 2;
}

.hidden {
  display: none !important;
}

.source-truncation-notice {
  margin-top: 1.2rem;
  padding: 0.65rem 0.8rem;
  border-radius: 12px;
  background: rgba(184, 134, 11, 0.08);
  border: 1px solid rgba(184, 134, 11, 0.2);
  color: var(--warning);
  font-size: 0.82rem;
  line-height: 1.45;
}

.source-truncation-notice p {
  margin: 0;
}

/* Mobile-only elements hidden on desktop */
.mobile-only {
  display: none !important;
}

.desktop-only {
  display: inline-flex;
}

#mobile-overlay {
  display: none;
}

@media (max-width: 1260px) {
  aside#sidebar {
    width: 312px;
    min-width: 270px;
  }
}

@media (max-width: 980px) {
  aside#sidebar {
    width: 100%;
    max-width: 360px;
  }

  #messages > *,
  #input-bar {
    width: calc(100% - 1rem);
  }

  #source-resizer {
    display: none !important;
  }

  aside#source-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: min(92vw, 460px) !important;
    z-index: 35;
    box-shadow: var(--shadow-2);
  }

  aside#source-panel.collapsed {
    display: none !important;
  }

  #review-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: min(92vw, 420px);
    z-index: 34;
    box-shadow: var(--shadow-2);
  }
}

/* ── Mobile: single-pane layout ── */
@media (max-width: 640px) {
  .mobile-only {
    display: inline-flex !important;
  }

  .desktop-only {
    display: none !important;
  }

  #app {
    flex-direction: column;
    position: relative;
    height: 100dvh;
  }

  /* Sidebar: off-screen by default, slides in as overlay */
  aside#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: 100vh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: none;
  }

  aside#sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-2);
  }

  aside#sidebar.collapsed {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    padding: 1rem 0.85rem 1rem 0.95rem;
  }

  #sidebar-collapsed-tab {
    display: none !important;
  }

  /* Scrim behind sidebar when open */
  #mobile-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 45;
  }

  #mobile-overlay.active {
    display: block;
  }

  /* Chat area fills the screen */
  main#chat-area {
    flex: 1;
    width: 100%;
    min-height: 0;
    height: 100dvh;
  }

  #chat-topbar {
    gap: 0.45rem;
    padding: 0.6rem 0.75rem;
    height: auto;
    min-height: 52px;
    justify-content: space-between;
  }

  .chat-title-wrap {
    flex: 1;
    min-width: 0;
  }

  #active-chat-title {
    font-size: 0.92rem;
  }

  #messages > * {
    width: calc(100% - 0.8rem);
  }

  #input-bar {
    width: calc(100% - 0.6rem);
    margin: 0.15rem auto;
    margin-bottom: max(0.4rem, env(safe-area-inset-bottom, 0.4rem));
    padding: 0.35rem 0.4rem;
    border-radius: 14px;
  }

  #msg-input {
    font-size: 16px; /* prevents iOS zoom on focus */
    min-height: 40px;
    padding: 0.45rem 0.55rem;
  }

  #send-btn {
    padding: 0.38rem 0.5rem;
  }

  .message {
    padding: 0.65rem 0.72rem;
  }

  .message.user {
    max-width: 95%;
  }

  /* Source panel: full-screen overlay on mobile */
  aside#source-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    height: 100vh;
    z-index: 40;
    box-shadow: none;
  }

  aside#source-panel.collapsed {
    display: none !important;
  }

  #review-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    height: 100vh;
    z-index: 45;
    box-shadow: none;
  }

  /* Hide the thin collapsed tab on mobile — use just collapsed class to hide entirely */
  #source-collapsed-tab {
    display: none !important;
  }

  #source-resizer {
    display: none !important;
  }

  /* Tighter source panel spacing on mobile */
  #source-panel-header {
    padding: 0.6rem 0.75rem;
  }

  #source-navigator {
    padding: 0 0.75rem 0.4rem;
  }

  #source-panel-body {
    padding: 0.65rem 0.75rem;
  }

  #source-breadcrumbs {
    padding: 0 0.75rem 0.3rem;
  }
}
