/* ─────────────────────────────────────────────────────────────
 *  Sessions — Session List, Chat View, Diff Viewer styles
 * ────────────────────────────────────────────────────────────── */

/* ═══ Session Layout ═══ */
.session-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.session-pane {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  min-width: 0;
}

.session-detail {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

.session-split {
  position: relative;
}

.session-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 8, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 140;
}

.session-drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

@media (min-width: 769px) {
  .session-split {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: var(--space-md);
    min-height: 500px;
  }

  .session-split > * {
    min-height: 0;
  }
}

@media (min-width: 1200px) {
  .app-shell[data-has-rail="true"] .session-split {
    grid-template-columns: 1fr;
  }

  .app-shell[data-has-rail="true"] .session-pane {
    display: none;
  }

  .app-shell[data-has-rail="true"] .chat-shell-header .session-drawer-btn {
    display: none;
  }
}

@media (max-width: 768px) {
  .session-split {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    height: 100%;
  }
  .session-list {
    height: 100%;
    max-height: none;
  }
  .session-list-scroll {
    max-height: none;
  }
  /* Hide sidebar on mobile when a session is selected (ChatGPT-like) */
  .session-pane {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: calc(var(--nav-height) + var(--safe-bottom));
    width: min(88vw, 360px);
    transform: translateX(-100%);
    transition: transform 0.24s ease;
    z-index: 160;
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.35);
  }
  .session-split.drawer-open .session-pane {
    transform: translateX(0);
  }
  .session-split.has-active-session > .session-detail {
    flex: 1;
    height: 100%;
  }
}

/* ─── Detail tabs ─── */
.session-detail-tabs {
  display: flex;
  gap: 2px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  padding: 3px;
  margin-bottom: var(--space-md);
}

.session-detail-tab {
  flex: 1;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  font-family: inherit;
}

.session-detail-tab:hover {
  color: var(--text-primary);
  background: var(--glass-highlight);
}

.session-detail-tab.active {
  background: var(--gradient-accent);
  color: var(--accent-text);
  box-shadow: var(--shadow-glow-sm);
}

/* Back button (mobile) */
/* ─── Chat shell header ─── */
.chat-shell-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  padding: 0;
  border-bottom: 1px solid var(--border, var(--glass-border));
  background: var(--bg-primary);
  flex-shrink: 0;
}

.chat-shell-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 12px 12px;
}

.session-drawer-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.session-drawer-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}

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

.chat-shell-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-shell-meta {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-shell-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.chat-mobile-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

@media (max-width: 768px) {
  .chat-shell-header {
    padding-left: calc(var(--safe-left));
    padding-right: calc(var(--safe-right));
  }

  .chat-shell-inner {
    padding-left: 12px;
    padding-right: 12px;
  }
}

/* ═══ Session List ═══ */
.session-list {
  background: var(--sidebar-bg, var(--bg-secondary));
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.session-rail .session-list {
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.session-rail .session-list-header {
  padding: 8px 6px 10px;
  border-bottom: 1px solid var(--border);
}

.session-rail .session-list-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-hint);
}

.session-rail .session-list-header .btn {
  padding: 4px 8px;
  font-size: 11px;
  min-height: 28px;
}

.session-rail .session-search {
  padding: 6px 6px 8px;
}

.session-rail .session-search-input {
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 10px;
}

.session-rail .session-list-scroll {
  max-height: none;
}

.session-rail .session-group-label {
  padding: 8px 6px 4px;
  font-size: 10px;
}

.session-rail .session-item {
  padding: 8px 8px;
}

.session-rail .session-item.active {
  padding-left: 6px;
}

.session-rail .session-item-title {
  font-size: 12px;
}

.session-rail .session-item-preview {
  font-size: 11px;
}

.session-rail .session-item-type {
  font-size: 8px;
  padding: 2px 4px;
}

.session-rail .session-item-time {
  font-size: 10px;
}

.session-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.session-list-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.session-search {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg, var(--bg-secondary));
}

.session-search-input {
  width: 100%;
  font-size: 13px;
  padding: 6px 10px;
  box-sizing: border-box;
}

.session-list-scroll {
  overflow-y: auto;
  flex: 1;
  max-height: 460px;
}

.session-group-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-hint);
  padding: 10px 14px 4px;
}

.session-item {
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.session-item:hover {
  background: var(--sidebar-hover, var(--bg-card-hover));
}

.session-item.active {
  background: var(--sidebar-active, rgba(255, 255, 255, 0.06));
  border-left: 3px solid var(--accent);
  padding-left: 11px;
}

.session-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.session-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.session-item-title {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item-type {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-hint);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 999px;
  text-transform: uppercase;
  background: var(--surface-1);
}

.session-item-preview {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 3px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item-time {
  font-size: 11px;
  color: var(--text-hint);
  margin-left: auto;
  line-height: 1.3;
}

.session-item-menu {
  border: none;
  background: transparent;
  color: var(--text-hint);
  font-size: 18px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  opacity: 0.6;
}

.session-item:hover .session-item-menu {
  opacity: 1;
}

.session-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  gap: var(--space-sm);
}

.session-empty-icon {
  font-size: 32px;
  opacity: 0.6;
}

.session-empty-text {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

.session-empty-subtext {
  font-size: 11px;
  color: var(--text-hint);
  margin-top: 4px;
}

.session-empty-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 4px;
}

/* ═══ Chat View ═══ */
.chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  position: relative;
}

@media (min-width: 1024px) {
  .chat-view {
    min-height: 560px;
  }
}

.chat-view.chat-empty-state {
  align-items: center;
  justify-content: center;
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--glass-border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.chat-toolbar-left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.chat-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/* ─── Embedded stream status (ChatTab) ─── */
.chat-stream-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 6px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.chat-stream-status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat-stream-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--text-hint);
  box-shadow: 0 0 0 4px rgba(218, 119, 86, 0.1);
}

.chat-stream-dot.thinking,
.chat-stream-dot.executing,
.chat-stream-dot.streaming {
  background: var(--accent);
}

.chat-stream-dot.paused {
  background: var(--color-inreview);
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.18);
}

.chat-stream-dot.idle {
  background: var(--text-hint);
  box-shadow: none;
}

.chat-stream-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.chat-stream-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-hint);
}

.chat-stream-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-stream-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-stream-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 12px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.chat-stream-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-stream-events {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-stream-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.chat-stream-chip.error {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.chat-stream-chip-sub {
  color: var(--text-hint);
  font-weight: 500;
}

.chat-stream-chip-time {
  color: var(--text-hint);
  font-size: 10px;
}

@media (max-width: 768px) {
  .chat-stream-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .chat-stream-actions {
    width: 100%;
  }
}

.chat-filter-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-filter-chip {
  border: 1px solid var(--glass-border);
  background: var(--glass-bg);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chat-filter-chip:hover {
  color: var(--text-primary);
  border-color: rgba(148, 163, 184, 0.4);
}

.chat-filter-chip.active {
  color: var(--text-primary);
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
}

.chat-filter-count {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.15);
  color: var(--text-hint);
}

.chat-paused-pill {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: var(--color-error);
  background: rgba(248, 113, 113, 0.12);
}

.chat-header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.chat-header-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.chat-header-meta {
  font-size: 12px;
  color: var(--text-hint);
  margin-top: 2px;
  line-height: 1.4;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  align-items: stretch;
}

.chat-load-earlier {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-1);
  color: var(--text-secondary);
  font-size: 11px;
}

.chat-load-count {
  color: var(--text-hint);
  font-size: 11px;
}

.chat-error-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 12px;
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  font-size: 12px;
}

.chat-empty-state-inline {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  gap: var(--space-sm);
  border: 1px dashed var(--glass-border);
  border-radius: var(--radius-md);
  background: rgba(8, 12, 20, 0.35);
  text-align: center;
}

.chat-loading {
  text-align: center;
  color: var(--text-hint);
  padding: var(--space-lg);
  font-size: 13px;
}

/* ─── Bubbles ─── */
.chat-bubble {
  width: 100%;
  max-width: min(760px, 100%);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
  border: 1px solid transparent;
  background: var(--bg-card);
  align-self: flex-start;
  box-shadow: var(--shadow-sm);
}

.chat-bubble.user {
  align-self: flex-end;
  width: auto;
  max-width: min(560px, 100%);
  background: rgba(218, 119, 86, 0.16);
  border-color: rgba(218, 119, 86, 0.35);
  color: var(--text-primary);
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}

.chat-bubble.system {
  align-self: center;
  max-width: 90%;
  background: transparent;
  padding: 6px 12px;
  box-shadow: none;
}

.chat-bubble.tool {
  align-self: center;
  background: rgba(218, 119, 86, 0.08);
  border: 1px solid rgba(218, 119, 86, 0.28);
  color: var(--text-primary);
  font-family: var(--font-mono);
}

.chat-bubble.error {
  align-self: center;
  background: rgba(229, 83, 75, 0.12);
  border: 1px solid rgba(229, 83, 75, 0.4);
  color: var(--text-primary);
}

.chat-system-text {
  font-size: 12px;
  color: var(--text-hint);
  text-align: center;
  font-style: italic;
}

.chat-bubble-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-hint);
  margin-bottom: 4px;
}

.chat-bubble-content {
  white-space: pre-wrap;
}

.chat-bubble-time {
  font-size: 10px;
  opacity: 0.6;
  margin-top: 4px;
}

.chat-jump-latest {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 16px;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 6;
}

.chat-jump-latest .btn {
  pointer-events: auto;
}

/* ─── Code blocks ─── */
.chat-code-block {
  position: relative;
  background: #1b1a18;
  border-radius: var(--radius-sm);
  margin: 6px 0;
  overflow: hidden;
  border: 1px solid var(--border);
}

.chat-code-block pre {
  margin: 0;
  padding: 10px 12px;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.5;
}

.chat-code-block code {
  font-family: var(--font-mono);
  color: #e2e8f0;
}

.chat-code-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #aaa;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
}

.chat-code-copy:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ─── Markdown rendering ─── */
.md-rendered {
  white-space: normal;
  word-wrap: break-word;
}

.md-heading {
  font-weight: 600;
  margin: 4px 0;
}

.md-h1 { font-size: 1.3em; }
.md-h2 { font-size: 1.15em; }
.md-h3 { font-size: 1.05em; }

.md-blockquote {
  border-left: 3px solid var(--accent);
  background: var(--glass-bg);
  padding: 6px 12px;
  margin: 4px 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.md-list {
  margin: 4px 0;
  padding-left: 20px;
}

.md-list li {
  margin: 2px 0;
}

ul.md-list {
  list-style: none;
  padding-left: 16px;
}

ul.md-list li::before {
  content: "•";
  color: var(--accent);
  font-weight: bold;
  display: inline-block;
  width: 12px;
  margin-left: -12px;
}

.md-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.md-link:hover {
  opacity: 0.8;
}

.md-inline-code {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  padding: 1px 6px;
  border-radius: 10px;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.9em;
}

.md-hr {
  border: none;
  border-top: 1px solid var(--glass-border);
  margin: 8px 0;
}

/* ─── Typing indicator ─── */
.chat-typing {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.chat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-hint);
  animation: chat-typing-bounce 1.4s infinite ease-in-out;
}

.chat-typing-dot:nth-child(2) {
  animation-delay: 0.16s;
}

.chat-typing-dot:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes chat-typing-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ─── Input bar ─── */
.chat-input-bar {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  flex-shrink: 0;
}

.chat-resume-btn {
  width: 100%;
  margin-bottom: var(--space-sm);
}

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  resize: none;
  font-size: 13px;
  min-height: 36px;
  max-height: 100px;
  line-height: 1.4;
  padding: 8px 12px;
  box-sizing: border-box;
}

.chat-send-btn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  border-radius: var(--radius-md);
}

/* ═══ Diff Viewer ═══ */
.diff-viewer {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 200px;
}

.diff-viewer.diff-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
}

.diff-loading {
  text-align: center;
  color: var(--text-hint);
  padding: var(--space-lg);
  font-size: 13px;
}

.diff-summary {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  border-bottom: 1px solid var(--glass-border);
  background: var(--glass-bg);
}

.diff-stat-add {
  color: var(--color-done);
  font-weight: 600;
  font-size: 12px;
}

.diff-stat-del {
  color: var(--color-error);
  font-weight: 600;
  font-size: 12px;
}

.diff-file-list {
  display: flex;
  flex-direction: column;
}

.diff-file-item {
  border-bottom: 1px solid var(--border);
}

.diff-file-item:last-child {
  border-bottom: none;
}

.diff-file-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background var(--transition-fast);
  font-size: 13px;
}

.diff-file-header:hover {
  background: var(--bg-card-hover);
}

.diff-file-header.added {
  border-left: 3px solid var(--color-done);
  padding-left: 11px;
}

.diff-file-header.deleted {
  border-left: 3px solid var(--color-error);
  padding-left: 11px;
}

.diff-file-header.modified {
  border-left: 3px solid var(--color-inreview);
  padding-left: 11px;
}

.diff-file-icon {
  font-size: 14px;
  flex-shrink: 0;
}

.diff-file-name {
  flex: 1;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.diff-file-stats {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.diff-file-toggle {
  color: var(--text-hint);
  font-size: 12px;
  flex-shrink: 0;
}

/* ─── Diff hunks ─── */
.diff-hunk {
  background: rgba(6, 8, 16, 0.9);
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 12px;
  line-height: 1.6;
  overflow-x: auto;
}

.diff-line {
  padding: 1px 14px;
  white-space: pre;
}

.diff-line.addition {
  background: rgba(16, 185, 129, 0.1);
  color: #6ee7b7;
}

.diff-line.deletion {
  background: rgba(248, 113, 113, 0.1);
  color: #fca5a5;
}

.diff-line.context {
  color: #94a3b8;
}

.diff-line.hunk-header {
  color: #7c3aed;
  background: rgba(124, 58, 237, 0.08);
  font-weight: 500;
}

.diff-line-text {
  display: inline;
}

@media (min-width: 1200px) {
  .app-shell[data-has-rail="true"] .session-detail {
    min-height: 520px;
  }
}

/* ═══ Slash Command Autocomplete ═══ */
.slash-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg-card, var(--glass-bg));
  border: 1px solid var(--border, var(--glass-border));
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg, 0 4px 24px rgba(0,0,0,.35));
  z-index: 50;
}

.slash-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.slash-menu-item:hover,
.slash-menu-item.active {
  background: var(--bg-card-hover, rgba(255,255,255,.06));
}

.slash-menu-item-icon {
  font-size: 16px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.slash-menu-item-cmd {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  font-family: var(--font-mono, monospace);
}

.slash-menu-item-desc {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ═══ Chat Welcome Screen ═══ */
.chat-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 300px;
  padding: 32px;
  text-align: center;
  gap: 16px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
}

.chat-welcome-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.chat-welcome-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.chat-welcome-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 400px;
  line-height: 1.5;
}

.chat-welcome-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  justify-content: center;
}

.chat-welcome-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* ═══ Chat Input Area (bottom bar) ═══ */
.chat-input-area {
  position: relative;
  padding: 16px 16px;
  border-top: 1px solid var(--border, var(--glass-border));
  background: var(--bg-surface, var(--glass-bg));
  flex-shrink: 0;
}

/* ═══ Embedded ChatView (inside ChatTab — clean ChatGPT-like) ═══ */
.chat-view-embedded {
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.chat-view-embedded .chat-messages {
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 16px 12px;
}

/* ═══ Session Detail as flex column (messages grow, input pinned) ═══ */
.session-detail > .chat-view-embedded {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.session-detail > .chat-welcome {
  flex: 1;
  min-height: 0;
}

.session-detail > .chat-input-area {
  flex-shrink: 0;
}

.app-shell[data-tab="chat"] .chat-view-embedded .chat-messages {
  padding: 0 0 16px;
}

.app-shell[data-tab="chat"] .chat-input-area {
  padding: 0 0 calc(12px + var(--safe-bottom, 0px));
}

.app-shell[data-tab="chat"] .chat-view-embedded .chat-messages {
  padding: 0 0 16px;
}

.app-shell[data-tab="chat"] .chat-input-area {
  padding: 0 0 calc(12px + var(--safe-bottom, 0px));
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-card, var(--glass-bg));
  border: 1px solid var(--border, var(--glass-border));
  border-radius: 24px;
  padding: 8px 8px 8px 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
  max-width: min(760px, 100%);
  margin: 0 auto;
}

.chat-input-wrapper:focus-within {
  border-color: var(--accent, var(--color-primary, #3b82f6));
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.chat-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  min-height: 24px;
  max-height: 120px;
  padding: 4px 0;
}

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

.chat-input-area .chat-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--gradient-accent, var(--accent, #3b82f6));
  color: var(--accent-text, white);
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
  font-size: 16px;
  padding: 0;
}

.chat-input-area .chat-send-btn:hover {
  opacity: 0.9;
  transform: scale(1.05);
}

.chat-input-area .chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.chat-input-hint {
  display: flex;
  justify-content: space-between;
  padding: 4px 4px 0;
  font-size: 11px;
  color: var(--text-hint);
  max-width: min(760px, 100%);
  margin: 0 auto;
}

/* ═══ Session Rename ═══ */
.session-item-rename {
  background: var(--bg-input, var(--glass-bg));
  border: 1px solid var(--accent, var(--color-primary, #3b82f6));
  border-radius: var(--radius-sm);
  padding: 2px 6px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  width: 100%;
  font-family: inherit;
  box-sizing: border-box;
}

/* ═══ Swipeable Session Items ═══ */

/* Wrapper holds behind-layer and the sliding item */
.session-item-wrapper {
  position: relative;
  overflow: hidden;
}

/* Action buttons behind the session item (revealed on swipe-left) */
.session-item-behind {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: stretch;
  z-index: 0;
}

.session-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  padding: 0 16px;
  min-width: 60px;
  font-size: 11px;
  font-family: inherit;
  gap: 2px;
  transition: background 0.15s, transform 0.15s;
}

.session-action-btn.archive {
  background: var(--color-warning, #f59e0b);
  color: #000;
}

.session-action-btn.resume {
  background: var(--color-primary, #10b981);
  color: #000;
}

.session-action-btn.delete {
  background: var(--color-error, #ef4444);
  color: #fff;
}

.session-action-btn.delete.confirm {
  background: #d1242f;
  animation: session-pulse 0.4s ease;
}

.session-action-btn:active {
  transform: scale(0.95);
}

.session-action-icon {
  font-size: 16px;
  line-height: 1;
}

.session-action-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

@keyframes session-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* The actual session item (slides left) */
.session-item-wrapper .session-item {
  position: relative;
  z-index: 1;
  background: var(--bg-surface, var(--glass-bg));
  touch-action: pan-y;
  user-select: none;
}

.session-item.archived {
  opacity: 0.6;
}

.session-item.archived:hover {
  opacity: 0.85;
}

/* ═══ Inline Action Buttons (desktop hover) ═══ */

.session-item-end {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  margin-left: auto;
}

.session-actions {
  display: flex;
  gap: 1px;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

.session-item:hover .session-actions {
  opacity: 1;
  pointer-events: auto;
}

.session-item.active .session-actions {
  opacity: 1;
  pointer-events: auto;
}

.session-inline-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  opacity: 0.5;
  transition: opacity 0.12s, background 0.12s;
  line-height: 1;
  flex-shrink: 0;
}

.session-inline-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.08);
}

.session-inline-btn.delete:hover {
  opacity: 1;
  background: rgba(239, 68, 68, 0.15);
}

/* ═══ Swipe Hint ═══ */
.session-swipe-hint {
  text-align: center;
  font-size: 10px;
  color: var(--text-hint);
  padding: 6px;
  opacity: 0.5;
  border-top: 1px solid var(--border);
}

/* Hide swipe hint on desktop (hover is the primary UX there) */
@media (hover: hover) and (pointer: fine) {
  .session-swipe-hint {
    display: none;
  }
}

/* On touch devices, hide the inline hover actions (use swipe instead) */
@media (hover: none) {
  .session-actions {
    display: none !important;
  }
}

/* ═══ Legacy rename btn (replaced by inline actions) ═══ */
.session-rename-btn {
  display: none;
}

/* ═══ SDK Badge in Slash Menu ═══ */
.slash-menu-item-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--accent, #6366f1);
  color: #fff;
  margin-left: auto;
  flex-shrink: 0;
}

/* ═══ Pending Messages (Optimistic Rendering) ═══ */
.chat-pending-msg {
  opacity: 0.7;
  position: relative;
}

.chat-pending-msg.sending {
  animation: chat-pending-pulse 2s ease-in-out infinite;
}

.chat-pending-msg.uncertain {
  opacity: 0.55;
  border-left: 3px solid var(--warning-color, #f59e0b);
}

.chat-pending-msg.failed {
  opacity: 0.6;
  border-left: 3px solid var(--error-color, #ef4444);
}

@keyframes chat-pending-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 0.4; }
}

.chat-pending-status {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.chat-pending-warn {
  color: var(--warning-color, #f59e0b);
  font-size: 11px;
  font-weight: 600;
}

.chat-pending-err {
  color: var(--error-color, #ef4444);
  font-size: 11px;
  font-weight: 600;
}

.chat-retry-btn {
  font-size: 11px !important;
  padding: 1px 6px !important;
  min-height: unset !important;
  border: 1px solid rgba(255,255,255,.12) !important;
}

/* ═══ Agent Status Indicator ═══ */
.chat-agent-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px !important;
}

.chat-agent-status-text {
  font-size: 12px;
  color: var(--text-secondary, #aaa);
  font-style: italic;
}

/* ═══ Offline Queue Badge ═══ */
.chat-offline-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--warning-color, #f59e0b);
  font-weight: 600;
  padding: 1px 6px;
  background: rgba(245, 158, 11, 0.1);
  border-radius: 4px;
}
