/* === Avatar anti-aliasing === */
.mate-sidebar-avatar,
.mate-collapsed-avatar,
.dm-bubble-avatar,
.dm-bubble-avatar-me,
.home-hub-mate-avatar {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: smooth;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

/* === Mate Chat Title Bar === */

.title-bar-content.mate-dm-active {
  border-bottom: none;
  background: var(--mate-color);
}

.title-bar-content.mate-dm-active #header-left,
.title-bar-content.mate-dm-active #header-left * {
  color: #fff !important;
}

.title-bar-content.mate-dm-active .status,
.title-bar-content.mate-dm-active .status *:not(.rate-limit-popover) {
  color: rgba(255, 255, 255, 0.85) !important;
}

.title-bar-content.mate-dm-active .status svg,
.title-bar-content.mate-dm-active #header-left svg {
  stroke: #fff !important;
  opacity: 0.9;
}

.title-bar-content.mate-dm-active .status button,
.title-bar-content.mate-dm-active #header-left button {
  color: #fff !important;
}

.title-bar-content.mate-dm-active .status button:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* Hide session info button in mate DM (white circle issue) */
.title-bar-content.mate-dm-active #header-info-btn {
  display: none;
}

/* === Mate Wizard === */

#mate-wizard {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
#mate-wizard.hidden { display: none; }

.mate-wizard-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(var(--shadow-rgb, 0,0,0), 0.5);
}
.mate-wizard-card {
  position: relative;
  background: var(--bg-alt, #0d0d1a);
  border: 1px solid var(--border, #333);
  border-radius: 14px;
  width: 520px;
  max-width: 95vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(var(--shadow-rgb, 0,0,0), 0.4);
}
.mate-wizard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border, #333);
  font-weight: 700;
  font-size: 15px;
  color: var(--text, #fff);
}
.mate-wizard-header button {
  background: none;
  border: none;
  color: var(--text-secondary, #999);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.mate-wizard-header button:hover {
  color: var(--text, #fff);
}

/* Progress dots */
.mate-wizard-progress {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px 6px;
}
.mate-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border, #333);
  transition: background 0.2s ease;
}
.mate-dot.active {
  background: var(--accent, #6c5ce7);
}
.mate-dot.done {
  background: var(--text-secondary, #999);
}

/* Steps container */
.mate-wizard-steps {
  padding: 16px 20px 8px;
  flex: 1;
  overflow-y: auto;
}
.mate-step {
  display: none;
}
.mate-step.active {
  display: block;
  animation: mateFadeIn 0.2s ease;
}
@keyframes mateFadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.mate-step h3 {
  margin: 0 0 6px;
  font-size: 16px;
  color: var(--text);
}
.mate-hint {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-muted, #9ea8c7);
  line-height: 1.4;
}

/* Step 0: Intro landing */
.mate-intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 8px 12px 16px;
  gap: 12px;
}
.mate-intro-icon {
  font-size: 48px;
  line-height: 1;
}

.mate-intro-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text, #fff);
  margin: 0;
}
.mate-intro-tagline {
  font-size: 15px;
  color: var(--accent, #6c5ce7);
  font-weight: 600;
  margin: 0;
  line-height: 1.4;
}
.mate-intro-body {
  font-size: 14px;
  color: var(--text-secondary, #aaa);
  line-height: 1.6;
  margin: 0;
  max-width: 400px;
}
.mate-intro-privacy {
  font-size: 13px;
  color: var(--text-muted, #9ea8c7);
  line-height: 1.5;
  margin: 0;
  max-width: 400px;
  padding: 10px 16px;
  background: rgba(108, 92, 231, 0.08);
  border-radius: 8px;
}
.mate-intro-steps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 340px;
  margin-top: 4px;
}
.mate-intro-step {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--text-secondary, #aaa);
  text-align: left;
}
.mate-intro-step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent, #6c5ce7);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Step 1: Relationship cards */
.mate-card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.mate-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  background: var(--input-bg, #1a1a2e);
  border: 2px solid var(--border, #333);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  color: var(--text, #fff);
  font-family: inherit;
  font-size: 13px;
}
.mate-card:hover {
  border-color: var(--text-dimmer, #6272a4);
}
.mate-card.selected {
  border-color: var(--accent, #6c5ce7);
  background: var(--accent-bg, rgba(108,92,231,0.12));
}
.mate-card-emoji {
  font-size: 24px;
  line-height: 1;
}
.mate-card-label {
  font-weight: 600;
  font-size: 13px;
}
.mate-card-desc {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  line-height: 1.3;
}

/* Custom input (shared) */
.mate-custom-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--input-bg, #1a1a2e);
  border: 1px solid var(--border, #333);
  border-radius: 6px;
  color: var(--text, #fff);
  font-size: 13px;
  font-family: inherit;
  box-sizing: border-box;
}
.mate-custom-input:focus {
  border-color: var(--accent, #6c5ce7);
  outline: none;
}
.mate-custom-input::placeholder {
  color: var(--text-dimmer, #6272a4);
}
.mate-custom-input.hidden {
  display: none;
}

/* Step 2: Activity tags */
.mate-tag-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.mate-tag {
  padding: 7px 14px;
  background: var(--input-bg, #1a1a2e);
  border: 2px solid var(--border, #333);
  border-radius: 20px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  color: var(--text, #fff);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
}
.mate-tag:hover {
  border-color: var(--text-dimmer, #6272a4);
}
.mate-tag.selected {
  border-color: var(--accent, #6c5ce7);
  background: var(--accent-bg, rgba(108,92,231,0.12));
}

/* Step 3: Sliders */
.mate-slider-group {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 8px 0 16px;
}
.mate-slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.mate-slider-label-left,
.mate-slider-label-right {
  font-size: 13px;
  color: var(--text-muted, #9ea8c7);
  min-width: 60px;
  font-weight: 500;
}
.mate-slider-label-left {
  text-align: right;
}
.mate-slider-label-right {
  text-align: left;
}
.mate-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--border, #333);
  outline: none;
}
.mate-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent, #6c5ce7);
  cursor: pointer;
  border: 2px solid var(--bg-alt, #0d0d1a);
}
.mate-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent, #6c5ce7);
  cursor: pointer;
  border: 2px solid var(--bg-alt, #0d0d1a);
}

/* Step 3: Communication style cards */
.mate-style-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.mate-style-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 12px 14px;
  background: var(--input-bg, #1a1a2e);
  border: 2px solid var(--border, #333);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  color: var(--text, #fff);
  font-family: inherit;
}
.mate-style-card:hover {
  border-color: var(--text-dimmer, #6272a4);
}
.mate-style-card.selected {
  border-color: var(--accent, #6c5ce7);
  background: var(--accent-bg, rgba(108,92,231,0.12));
}
.mate-style-label {
  font-weight: 600;
  font-size: 13px;
}
.mate-style-example {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  font-style: italic;
  line-height: 1.4;
}

/* Step 4: Vendor options */
.mate-vendor-option-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.mate-vendor-option-btn {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px;
  background: var(--input-bg, #1a1a2e);
  border: 2px solid var(--border, #333);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  color: var(--text, #fff);
  font-family: inherit;
  width: 100%;
}
.mate-vendor-option-btn:hover {
  border-color: var(--text-dimmer, #6272a4);
}
.mate-vendor-option-btn.active {
  border-color: var(--accent, #6c5ce7);
  background: var(--accent-bg, rgba(108,92,231,0.12));
}
.mate-vendor-option-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  flex-shrink: 0;
  object-fit: cover;
}
.mate-vendor-option-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.mate-vendor-option-title {
  font-weight: 600;
  font-size: 14px;
}
.mate-vendor-option-desc {
  font-size: 12px;
  color: var(--text-muted, #9ea8c7);
  line-height: 1.4;
}

/* Footer */
.mate-wizard-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-top: 1px solid var(--border, #333);
}
.mate-wizard-footer > div {
  display: flex;
  gap: 8px;
}

/* Buttons */
.mate-btn {
  padding: 7px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: opacity 0.15s;
}
.mate-btn.primary {
  background: var(--accent, #6c5ce7);
  color: #fff;
}
.mate-btn.primary:hover {
  opacity: 0.9;
}
.mate-btn.secondary {
  background: var(--input-bg, #2a2a3e);
  color: var(--text, #fff);
  border: 1px solid var(--border, #333);
}
.mate-btn.secondary:hover {
  background: var(--border, #333);
}

/* === Mate avatar in user strip: squircle + desaturate === */
.icon-strip-mate .icon-strip-user-avatar {
  border-radius: 8px;
  filter: saturate(0.65);
}
.icon-strip-mate:hover .icon-strip-user-avatar,
.icon-strip-mate.mention-active .icon-strip-user-avatar {
  filter: saturate(1);
}
.icon-strip-mate.active .icon-strip-user-avatar {
  filter: saturate(1);
  box-shadow: 0 0 0 2px var(--accent);
  border-radius: 8px;
}

/* Hide legacy bot badge (replaced by squircle shape) */
.icon-strip-user-mate-badge {
  display: none;
}

/* Mate item in DM picker */
.dm-user-picker-section {
  padding: 6px 10px 2px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dimmer, #6272a4);
}
.dm-user-picker-create-mate {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.12s;
  color: var(--accent, #6c5ce7);
  font-size: 13px;
  font-weight: 600;
}
.dm-user-picker-create-mate:hover {
  background: var(--accent-bg, rgba(108,92,231,0.12));
}
.dm-user-picker-create-mate svg {
  width: 16px;
  height: 16px;
}

/* DM header mate indicator */
.dm-header-mate-tag {
  display: inline-block;
  padding: 1px 6px;
  background: var(--accent-bg, rgba(108,92,231,0.12));
  color: var(--accent, #6c5ce7);
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-left: 6px;
}

/* Responsive */
@media (max-width: 560px) {
  .mate-wizard-card {
    width: 100%;
    max-width: 100vw;
    border-radius: 14px 14px 0 0;
    max-height: 90vh;
  }
  .mate-card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* === Mate Profile Popover === */

.mate-profile-popover {
  position: fixed !important;
  bottom: auto !important;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  overflow: visible;
  width: 280px;
}

/* === Mate Sidebar === */

#mate-sidebar-column {
  display: flex;
  flex-direction: column;
  width: 260px;
  min-width: 200px;
  max-width: 360px;
  background: var(--sidebar-bg, var(--bg-secondary, #1a1a2e));
  border-right: none;
  overflow: hidden;
  flex-shrink: 0;
  -webkit-user-select: none;
  user-select: none;
}
/* Inputs inside the mate sidebar remain selectable. */
#mate-sidebar-column input,
#mate-sidebar-column textarea,
#mate-sidebar-column [contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
}

#mate-sidebar-column.hidden {
  display: none !important;
}

.mate-sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 48px;
  padding: 0 12px;
  border-bottom: none;
  flex-shrink: 0;
}

.mate-sidebar-header {
  cursor: pointer;
}

.mate-sidebar-header .mate-sidebar-name {
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  flex: 1;
  font-size: 15px;
  font-weight: 600;
}

/* Vendor toggle in mate header (split pill) */
.mate-vendor-toggle {
  display: flex;
  align-items: center;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 6px;
  overflow: hidden;
  height: 24px;
}
.mate-vendor-btn {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0 6px;
  height: 100%;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.mate-vendor-btn:first-child { border-right: 1px solid rgba(255,255,255,0.4); }
.mate-vendor-btn.active {
  background: rgba(255,255,255,0.25);
  color: #fff;
  font-weight: 600;
}
.mate-vendor-btn.disabled {
  opacity: 0.3;
  cursor: default;
}
.mate-vendor-icon {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: #fff;
}
.mate-vendor-label {
  pointer-events: none;
}

/* Collapse button inside mate header: white to match header style */
.mate-sidebar-header .sidebar-collapse-btn {
  color: rgba(255,255,255,0.7);
}
.mate-sidebar-header .sidebar-collapse-btn:hover {
  color: #fff;
  background: rgba(255,255,255,0.15);
}

/* When collapsed, mate sidebar fully hidden (same as project sidebar) */
#layout.sidebar-collapsed #mate-sidebar-column {
  width: 0 !important;
  min-width: 0 !important;
  overflow: hidden;
}

/* Mate info shown in header when sidebar is collapsed */
.mate-collapsed-info {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 3px;
  background: rgba(var(--overlay-rgb), 0.08);
  border-radius: 999px;
  margin-right: 8px;
  flex-shrink: 0;
}
body.mate-dm-active #layout.sidebar-collapsed .mate-collapsed-info {
  display: flex;
}
.mate-collapsed-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
}
.mate-collapsed-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.mate-sidebar-header .mate-sidebar-avatar {
  border: 2px solid rgba(255,255,255,0.3);
}

/* Engrave effect (Ten Commandments style) */
@keyframes engrave-char {
  0% {
    opacity: 0;
    transform: scale(2.5) translateY(-4px);
    color: #fff700;
    text-shadow: 0 0 20px #fff700, 0 0 40px #ff8c00, 0 0 60px #ff4500;
  }
  30% {
    opacity: 1;
    transform: scale(1.3) translateY(-1px);
    color: #fffbe6;
    text-shadow: 0 0 14px #fff700, 0 0 28px #ff8c00;
  }
  60% {
    transform: scale(1.05);
    color: #fff;
    text-shadow: 0 0 8px rgba(255,255,255,0.6);
  }
  100% {
    opacity: 1;
    transform: scale(1);
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  }
}

.mate-engrave-spark {
  position: fixed;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 99999;
  animation: engrave-spark 0.6s ease-out forwards;
}

@keyframes engrave-spark {
  0% {
    opacity: 1;
    transform: translate(0, 0) scale(1.5);
    box-shadow: 0 0 6px 2px var(--spark-color, #fff700);
  }
  50% {
    opacity: 0.8;
    box-shadow: 0 0 3px 1px var(--spark-color, #ff8c00);
  }
  100% {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) scale(0);
    box-shadow: none;
  }
}

/* Flash the header background on engrave */
@keyframes engrave-header-flash {
  0% { filter: brightness(1); }
  15% { filter: brightness(1.6); }
  100% { filter: brightness(1); }
}

/* Seed data hover tooltip */
.mate-seed-tooltip {
  position: absolute;
  top: 100%;
  left: 12px;
  right: 12px;
  margin-top: 4px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 100;
  pointer-events: none;
}
.mate-seed-tooltip.hidden {
  display: none;
}
.mate-sidebar-header {
  position: relative;
}
.mate-sidebar-name {
  cursor: default;
}
.mate-sidebar-seed-row {
  display: flex;
  gap: 6px;
  align-items: baseline;
}
.mate-sidebar-seed-label {
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  min-width: 70px;
  flex-shrink: 0;
}
.mate-sidebar-seed-value {
  font-size: 12px;
  color: var(--text);
}
.mate-sidebar-seed-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.mate-sidebar-seed-tag {
  font-size: 10px;
  padding: 1px 6px;
  background: var(--bg-alt);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-secondary);
}

/* Primary mate (System Agent) badge */
.mate-sidebar-primary-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  margin-bottom: 4px;
  background: linear-gradient(135deg, rgba(0, 184, 148, 0.08), rgba(9, 132, 227, 0.08));
  border: 1px solid rgba(0, 184, 148, 0.25);
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #00b894;
  letter-spacing: 0.02em;
}
.mate-sidebar-primary-badge svg {
  flex-shrink: 0;
  color: #00b894;
}
.mate-sidebar-primary-desc {
  display: block;
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: auto;
}

/* Mate session delete confirm overlay */
.mate-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mate-confirm-box {
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 20px 24px;
  max-width: 340px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.mate-confirm-text {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 16px;
}
.mate-confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.mate-confirm-cancel, .mate-confirm-delete {
  padding: 6px 16px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  font-size: 13px;
  cursor: pointer;
  background: var(--bg);
  color: var(--text);
}
.mate-confirm-delete {
  background: #e74c3c;
  color: #fff;
  border-color: #e74c3c;
}
.mate-confirm-delete:hover {
  background: #c0392b;
}

/* --- Mate onboarding modal --- */
.mate-onboarding-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}
.mate-onboarding-overlay.visible {
  background: rgba(0,0,0,0.45);
}
.mate-onboarding-card {
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 32px 36px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 12px 48px rgba(0,0,0,0.2);
  text-align: center;
  transform: translateY(20px) scale(0.96);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.mate-onboarding-overlay.visible .mate-onboarding-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}
.mate-onboarding-icon {
  font-size: 40px;
  margin-bottom: 8px;
}
.mate-onboarding-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 10px;
}
.mate-onboarding-desc {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin: 0 0 18px;
}
.mate-onboarding-features {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
  text-align: left;
}
.mate-onboarding-features li {
  font-size: 13px;
  color: var(--text);
  padding: 8px 0;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  line-height: 1.4;
}
.mate-onboarding-sub {
  color: var(--text-muted);
  font-size: 12px;
}
.mate-onboarding-bullet {
  font-size: 16px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}
.mate-onboarding-note {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin: 0 0 16px;
}
.mate-onboarding-btn {
  width: 100%;
  padding: 10px 0;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.mate-onboarding-btn:hover {
  filter: brightness(1.08);
}
.mate-onboarding-btn:active {
  transform: scale(0.98);
}

.mate-sidebar-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.mate-sidebar-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary, #e0e0e0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Mate sidebar tools: icon+caption grid, matches #session-actions.
   Tile styling comes from .palette-tile in sidebar.css. */
#mate-sidebar-tools-wrap {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 4px;
}
#mate-sidebar-tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 0 8px 4px;
}

/* Knowledge editor panel (overlays main content) */
#mate-knowledge-editor {
  position: absolute;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#mate-knowledge-editor.hidden {
  display: none;
}

/* --- Knowledge viewer (side panel, mirrors #file-viewer) --- */
@media (min-width: 1024px) {
  #mate-knowledge-viewer {
    width: 50%;
    max-width: 720px;
    min-width: 360px;
    border-left: 1px solid var(--border);
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
  }
  #mate-knowledge-viewer.hidden { display: none; }
}
@media (max-width: 1023px) {
  #mate-knowledge-viewer {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 300;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  #mate-knowledge-viewer.hidden { display: none; }
}
.mate-knowledge-viewer-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  min-height: 44px;
}
.mate-knowledge-viewer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
}

/* Knowledge editor (full overlay) */
.mate-knowledge-editor {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.mate-knowledge-editor.hidden {
  display: none;
}

/* Header bar (matches title-bar-content height/style) */
.mate-knowledge-header-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 48px;
  padding: 0 8px 0 16px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.mate-knowledge-header-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}
.mate-knowledge-header-btn:hover {
  background: rgba(var(--overlay-rgb), 0.08);
  color: var(--text);
}
.mate-knowledge-header-btn:disabled {
  opacity: 0.3;
  cursor: default;
}
.mate-knowledge-header-btn:disabled:hover {
  background: none;
  color: var(--text-muted);
}
.mate-knowledge-header-btn .lucide {
  width: 16px;
  height: 16px;
}
.mate-knowledge-header-icon {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}
#mate-knowledge-editor-delete:hover {
  color: var(--error, #ff5555);
}

/* 2-panel layout: editor | preview */
.mate-knowledge-body {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
  overflow: hidden;
}

/* Sidebar file list */
#mate-sidebar-knowledge.hidden,
#mate-sidebar-memory.hidden,
#mate-sidebar-conversations.hidden {
  display: none;
}
.mate-knowledge-file-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 6px;
}
.mate-knowledge-file-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}
.mate-knowledge-file-item:hover {
  background: var(--sidebar-hover);
  color: var(--text);
}
.mate-knowledge-file-item.active {
  background: var(--sidebar-active);
  color: var(--text);
  font-weight: 600;
}
.mate-knowledge-file-icon {
  display: flex;
  flex-shrink: 0;
}
.mate-knowledge-file-icon .lucide {
  width: 14px;
  height: 14px;
}
.mate-knowledge-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mate-knowledge-file-badge {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-alt, #2a2a3a);
  color: var(--text-dimmer);
  margin-left: auto;
  flex-shrink: 0;
}

/* Common knowledge section headers */
.mate-knowledge-section-header {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dimmer);
  padding: 10px 12px 4px;
}
.mate-knowledge-file-badge.common {
  background: rgba(0, 184, 148, 0.15);
  color: #00b894;
}
.mate-knowledge-file-badge.promoted {
  background: rgba(0, 184, 148, 0.15);
  color: #00b894;
}
.mate-knowledge-dots-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px;
  margin-left: auto;
  color: var(--text-dimmer);
  flex-shrink: 0;
  opacity: 0.5;
  transition: opacity 0.15s;
}
.mate-knowledge-dots-btn .lucide {
  width: 14px;
  height: 14px;
}
.mate-knowledge-file-item:hover .mate-knowledge-dots-btn {
  display: flex;
}
.mate-knowledge-dots-btn:hover {
  opacity: 1;
}
.mate-knowledge-file-menu {
  position: fixed;
  z-index: 9999;
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 0;
  min-width: 140px;
  box-shadow: 0 4px 16px rgba(var(--shadow-rgb), 0.4);
}
.mate-knowledge-file-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  font-family: inherit;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
  transition: background 0.15s;
}
.mate-knowledge-file-menu-item:hover {
  background: rgba(var(--overlay-rgb), 0.05);
}
.mate-knowledge-file-menu-item .lucide {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.mate-knowledge-file-menu-item.menu-item-danger {
  color: var(--error);
}
.mate-knowledge-file-menu-item.menu-item-danger:hover {
  background: var(--error-8);
}

/* JSONL table view */
.mate-knowledge-jsonl-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  line-height: 1.5;
}
.mate-knowledge-jsonl-table th {
  text-align: left;
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dimmer);
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-panel, var(--bg));
}
.mate-knowledge-jsonl-table td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--border-subtle, rgba(128,128,128,0.1));
  color: var(--text);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mate-knowledge-jsonl-table tbody tr:hover td {
  background: var(--bg-hover, rgba(128,128,128,0.06));
}

.mate-knowledge-empty {
  padding: 20px 12px;
  text-align: center;
  font-size: 12px;
  color: var(--text-dimmer);
}

/* --- Memory panel --- */
/* Memory viewer */
@media (min-width: 1024px) {
  #mate-memory-viewer {
    width: 50%;
    max-width: 720px;
    min-width: 360px;
    border-left: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
  }
  #mate-memory-viewer.hidden { display: none; }
}
@media (max-width: 1023px) {
  #mate-memory-viewer {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 1100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  #mate-memory-viewer.hidden { display: none; }
}
.mate-memory-viewer-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-bottom: none;
  flex-shrink: 0;
  min-height: 44px;
}
.mate-memory-danger-btn:hover {
  color: var(--error, #ff5555) !important;
}

/* Tabs */
.mate-memory-viewer-tabs {
  display: flex;
  gap: 0;
  padding: 0 12px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.mate-memory-tab {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dimmer);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.mate-memory-tab:hover {
  color: var(--text-secondary);
}
.mate-memory-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent, #6c5ce7);
  font-weight: 600;
}

/* Tab bodies */
.mate-memory-tab-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.mate-memory-tab-body.hidden {
  display: none;
}

/* Summary tab */
#mate-memory-summary-content h1 {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 12px;
  color: var(--text);
}
#mate-memory-summary-content h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 16px 0 8px;
  color: var(--text);
}
#mate-memory-summary-content ul {
  margin: 0 0 8px;
  padding-left: 20px;
}
#mate-memory-summary-content li {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 2px;
}

/* Digest list */
.mate-memory-digest-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.mate-memory-digest-list.hidden {
  display: none;
}
.mate-memory-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
}
.mate-memory-item:hover {
  background: rgba(var(--overlay-rgb), 0.05);
}
.mate-memory-item-top {
  display: flex;
  align-items: center;
  gap: 6px;
}
.mate-memory-date {
  font-size: 11px;
  color: var(--text-dimmer);
}
.mate-memory-type-badge {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(var(--overlay-rgb), 0.08);
  color: var(--text-dimmer);
}
.mate-memory-tag {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(var(--accent-rgb, 108, 92, 231), 0.1);
  color: var(--accent, #6c5ce7);
}
.mate-memory-delete-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-dimmer);
  cursor: pointer;
  padding: 2px;
  display: none;
  align-items: center;
}
.mate-memory-delete-btn svg { width: 13px; height: 13px; }
.mate-memory-item:hover .mate-memory-delete-btn { display: flex; }
.mate-memory-delete-btn:hover { color: var(--error, #ff5555); }
.mate-memory-topic {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mate-memory-position {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mate-memory-empty {
  padding: 24px 12px;
  text-align: center;
  font-size: 13px;
  color: var(--text-dimmer);
  line-height: 1.6;
}

/* Digest detail view */
.mate-memory-digest-detail {
  display: flex;
  flex-direction: column;
}
.mate-memory-digest-detail.hidden {
  display: none;
}
.mate-memory-detail-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}
.mate-memory-detail-back {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.12s;
}
.mate-memory-detail-back:hover {
  background: rgba(var(--overlay-rgb), 0.06);
  color: var(--text);
}
.mate-memory-detail-back svg { width: 14px; height: 14px; }
.mate-memory-detail-delete {
  background: none;
  border: none;
  color: var(--text-dimmer);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
}
.mate-memory-detail-delete svg { width: 15px; height: 15px; }
.mate-memory-detail-body {
  padding: 0 4px;
}

/* Memory detail fields */
.mate-memory-detail {
  margin-bottom: 16px;
}
.mate-memory-detail-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-dimmer);
  margin-bottom: 4px;
  font-weight: 600;
}
.mate-memory-detail-value {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
}

/* Memory delete confirmation */
.mate-memory-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mate-memory-confirm-dialog {
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 20px 24px;
  min-width: 260px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}
.mate-memory-confirm-msg {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 16px;
  text-align: center;
}
.mate-memory-confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.mate-memory-confirm-cancel {
  padding: 6px 16px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: none;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}
.mate-memory-confirm-cancel:hover {
  background: rgba(var(--overlay-rgb), 0.06);
}
.mate-memory-confirm-delete {
  padding: 6px 16px;
  border-radius: 6px;
  border: none;
  background: var(--error, #ff5555);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.mate-memory-confirm-delete:hover {
  opacity: 0.85;
}

/* Active file name in editor toolbar */
.mate-knowledge-active-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mate-knowledge-active-name.hidden {
  display: none;
}

/* Name input group for new files */
.mate-knowledge-name-group {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 4px 10px;
  max-width: 280px;
}
.mate-knowledge-name-group:focus-within {
  border-color: var(--accent);
}
.mate-knowledge-name-group.hidden {
  display: none;
}
#mate-knowledge-editor-name {
  background: none;
  border: none;
  padding: 0;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text);
  outline: none;
  min-width: 0;
  width: 160px;
}
#mate-knowledge-editor-name::placeholder {
  color: var(--text-dimmer);
  font-weight: 500;
}
.mate-knowledge-editor-ext {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dimmer);
  user-select: none;
  flex-shrink: 0;
}

.mate-knowledge-toolbar-spacer {
  flex: 1;
}

/* Editor pane (left) */
.mate-knowledge-editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--border-subtle);
}

/* Highlight overlay container */
.mate-editor-highlight-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
}
.mate-editor-highlight-pre {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 12px 14px;
  font-size: 13px;
  font-family: var(--font-mono, "Roboto Mono", monospace);
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-y: auto;
  pointer-events: none;
  color: var(--text);
  background: none;
  border: none;
}
.mate-editor-highlight-pre code {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  background: none !important;
  padding: 0;
}
#mate-knowledge-editor-content {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 12px 14px;
  background: none;
  border: none;
  color: transparent;
  caret-color: var(--text);
  font-size: 13px;
  font-family: var(--font-mono, "Roboto Mono", monospace);
  line-height: 1.6;
  resize: none;
  outline: none;
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  z-index: 1;
}
#mate-knowledge-editor-content::placeholder {
  color: var(--text-dimmer);
}
#mate-knowledge-editor-content::selection {
  background: rgba(var(--overlay-rgb), 0.2);
}

/* Preview pane (right) */
.mate-knowledge-preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.mate-knowledge-preview-content {
  flex: 1;
  padding: 16px 20px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}
.mate-knowledge-preview-content em {
  font-style: italic;
  font-synthesis: style;
}
.mate-knowledge-preview-content strong {
  font-weight: 700;
}

/* --- Format Popover --- */
.mate-format-popover {
  position: fixed;
  z-index: 10000;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transform: translateX(-50%) translateY(-100%);
}
.mate-format-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 5px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}
.mate-format-btn:hover {
  background: rgba(var(--overlay-rgb), 0.1);
  color: var(--text);
}
.mate-format-btn .lucide {
  width: 15px;
  height: 15px;
}

/* Responsive: stack on narrow screens */
@media (max-width: 768px) {
  .mate-knowledge-body {
    flex-direction: column;
  }
  .mate-knowledge-editor-pane {
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }
}

.mate-sidebar-sessions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 6px;
  flex-shrink: 0;
}

.mate-sidebar-sessions-header > span {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.mate-sidebar-actions {
  display: flex;
  gap: 4px;
}

.mate-sidebar-actions button {
  background: none;
  border: none;
  color: var(--text-secondary, #888);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.mate-sidebar-actions button:hover {
  background: var(--bg-hover, rgba(255,255,255,0.06));
  color: var(--text-primary, #e0e0e0);
}

.mate-sidebar-actions button svg {
  width: 16px;
  height: 16px;
}

.mate-sidebar-actions button.active {
  background: var(--bg-hover, rgba(255,255,255,0.1));
  color: var(--text-primary, #fff);
}

.mate-session-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 6px;
}

.mate-session-empty {
  padding: 24px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary, #888);
  opacity: 0.6;
}

.mate-session-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 36px 0 12px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0;
  transition: background 0.35s ease, color 0.35s ease;
}

.mate-session-item:hover {
  background: var(--sidebar-hover);
  color: var(--text-secondary);
}

.mate-session-item.active {
  background: var(--sidebar-active);
  color: var(--text);
  font-weight: 600;
}

.mate-session-item-text {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.mate-session-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  position: absolute;
  right: 8px;
}

/* Session search */
.mate-session-search {
  position: relative;
  padding: 0 8px 6px;
}
.mate-session-search.hidden {
  display: none;
}
#mate-session-search-input {
  width: 100%;
  padding: 7px 28px 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}
#mate-session-search-input:focus {
  border-color: var(--accent);
}
#mate-session-search-clear {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--text-dimmer);
  cursor: pointer;
}
#mate-session-search-clear:hover {
  color: var(--text);
  background: var(--sidebar-hover);
}
#mate-session-search-clear .lucide {
  width: 14px;
  height: 14px;
}
#mate-search-session-btn.active {
  color: var(--accent);
}

/* Mate datastore inspector */
#mate-datastore-panel {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#mate-datastore-panel.hidden {
  display: none !important;
}

#main-column.mate-datastore-open > .title-bar-content,
#main-column.mate-datastore-open > .dm-header-bar,
#main-column.mate-datastore-open > #main-panels {
  display: none !important;
}

.mate-datastore-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 48px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.mate-datastore-top-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}

.mate-datastore-top-title .lucide {
  width: 14px;
  height: 14px;
  color: var(--accent);
  opacity: 0.85;
}

.mate-datastore-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mate-db-status {
  padding: 10px 14px 0;
  font-size: 12px;
  color: var(--text-secondary, #8e8e8e);
}

.mate-db-status[data-kind="error"] {
  color: var(--error, #ff6b6b);
}

.mate-db-status[data-kind="warn"] {
  color: var(--warning, #f5a524);
}

.mate-db-status[data-kind="ok"] {
  color: var(--success, #36b37e);
}

.mate-db-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 10px;
  padding: 12px 10px 10px;
  min-height: 0;
  flex: 1;
}

.mate-db-table-column,
.mate-db-detail {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.mate-db-table-list {
  overflow-y: auto;
  border: 1px solid var(--border-subtle, rgba(255,255,255,0.06));
  border-radius: 12px;
  background: var(--sidebar-bg, rgba(255,255,255,0.03));
  padding: 6px;
  flex: 1;
}

.mate-db-table-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #aaa);
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
}

.mate-db-table-item:hover,
.mate-db-table-item.active {
  background: var(--sidebar-active, rgba(255,255,255,0.08));
  color: var(--text, #fff);
}

.mate-db-table-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.mate-db-table-item-type {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.7;
  flex-shrink: 0;
}

.mate-db-empty {
  padding: 16px 10px;
  color: var(--text-secondary, #8e8e8e);
  font-size: 12px;
}

.mate-db-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted, #9aa0a6);
  margin: 0 0 6px;
}

.mate-db-detail {
  gap: 8px;
  min-width: 0;
}

.mate-db-table-schema,
.mate-db-result {
  margin: 0;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle, rgba(255,255,255,0.08));
  background: var(--bg-alt, rgba(255,255,255,0.03));
  color: var(--text-secondary, #b8b8b8);
  font-size: 11px;
  line-height: 1.5;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 0;
}

.mate-db-table-schema {
  max-height: 180px;
}

@media (max-width: 900px) {
  .mate-db-layout {
    grid-template-columns: 1fr;
  }
}

body.mate-dm-active .mate-datastore-top-bar {
  background: var(--mate-color);
  color: #fff;
}

body.mate-dm-active .mate-datastore-top-title,
body.mate-dm-active .mate-datastore-top-title .lucide {
  color: #fff;
}

body.mate-dm-active .mate-datastore-top-bar .scheduler-close-btn {
  color: rgba(255, 255, 255, 0.85);
}

body.mate-dm-active .mate-datastore-top-bar .scheduler-close-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
}

.mate-session-item.search-match {
  background: var(--accent-12, rgba(108, 92, 231, 0.12));
}
.mate-session-item.search-match .mate-session-item-text {
  color: var(--accent);
}
.mate-session-item.search-dimmed {
  opacity: 0.35;
}

.mate-session-item .icon-strip-status {
  position: static;
  display: inline-block;
  width: 6px;
  height: 6px;
  border: none;
  margin-right: 8px;
  vertical-align: middle;
  opacity: 1;
}

/* --- Debate group (mate sidebar) --- */
.mate-debate-wrapper {
  margin-bottom: 2px;
}

.mate-debate-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
  height: 34px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  transition: background 0.35s ease, color 0.35s ease;
}

.mate-debate-group:hover {
  background: var(--sidebar-hover);
  color: var(--text-secondary);
}

.mate-debate-group.active {
  background: var(--sidebar-active);
  color: var(--text);
}

.mate-debate-chevron {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-dimmer);
  display: flex;
  align-items: center;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.mate-debate-chevron svg {
  width: 14px;
  height: 14px;
}

.mate-debate-group.expanded .mate-debate-chevron {
  transform: rotate(90deg);
}

.mate-debate-icon {
  display: inline-flex;
  align-items: center;
  color: var(--accent);
  flex-shrink: 0;
}

.mate-debate-icon svg {
  width: 14px;
  height: 14px;
}

.mate-debate-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.mate-debate-count {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-dimmer);
  background: rgba(var(--overlay-rgb), 0.06);
  padding: 1px 6px;
  border-radius: 8px;
}

.mate-debate-children {
  padding-left: 20px;
}

.mate-debate-child {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  transition: background 0.2s ease;
}

.mate-debate-child:hover {
  background: var(--sidebar-hover);
}

.mate-debate-child.active {
  background: var(--sidebar-active);
  color: var(--text);
}

.mate-debate-child-role {
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  padding: 1px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}

.mate-debate-child-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* --- Mate color theming for panels --- */

/* Match panel header heights to sidebar header (48px) */
body.mate-dm-active .mate-knowledge-header-bar,
body.mate-dm-active .mate-knowledge-viewer-header,
body.mate-dm-active .mate-memory-viewer-header,
body.mate-dm-active .scheduler-top-bar,
body.mate-dm-active .notes-archive-header {
  height: 48px;
  box-sizing: border-box;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

/* Knowledge editor header bar (full mate color, overrides whole area) */
body.mate-dm-active .mate-knowledge-header-bar {
  background: var(--mate-color);
  color: #fff;
  border-bottom-color: transparent;
}
body.mate-dm-active .mate-knowledge-header-bar .mate-knowledge-header-icon,
body.mate-dm-active .mate-knowledge-header-bar .mate-knowledge-active-name {
  color: #fff;
}
body.mate-dm-active .mate-knowledge-header-bar #mate-knowledge-editor-name {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.3);
}
body.mate-dm-active .mate-knowledge-header-bar #mate-knowledge-editor-name::placeholder {
  color: rgba(255, 255, 255, 0.5);
}
body.mate-dm-active .mate-knowledge-header-bar .mate-knowledge-header-btn {
  color: rgba(255, 255, 255, 0.85);
}
body.mate-dm-active .mate-knowledge-header-bar .mate-knowledge-header-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
}
body.mate-dm-active .mate-knowledge-header-bar .mate-knowledge-header-btn:disabled {
  color: rgba(255, 255, 255, 0.4);
}
body.mate-dm-active .mate-knowledge-header-bar .mate-knowledge-header-btn:disabled:hover {
  background: none;
  color: rgba(255, 255, 255, 0.4);
}
body.mate-dm-active .mate-knowledge-header-bar #mate-knowledge-editor-delete:hover {
  color: #ff5555;
  background: rgba(255, 85, 85, 0.15);
}

/* Knowledge viewer header bar (side panel, light tint via --mate-color + 0a) */
body.mate-dm-active .mate-knowledge-viewer-header {
  background: var(--mate-color-tint, var(--bg-secondary));
  color: var(--text-main);
  border-bottom: 1px solid var(--border-subtle);
}
body.mate-dm-active .mate-knowledge-viewer-header .mate-knowledge-header-icon,
body.mate-dm-active .mate-knowledge-viewer-header .mate-knowledge-active-name {
  color: var(--text-main);
}
body.mate-dm-active .mate-knowledge-viewer-header .file-viewer-btn {
  color: var(--text-dim);
}
body.mate-dm-active .mate-knowledge-viewer-header .file-viewer-btn:hover {
  color: var(--text-main);
  background: rgba(var(--overlay-rgb), 0.08);
}

/* Scheduler top bar (main header) */
body.mate-dm-active .scheduler-top-bar {
  background: var(--mate-color);
  color: #fff;
}
body.mate-dm-active .scheduler-top-title,
body.mate-dm-active .scheduler-top-title .lucide {
  color: #fff;
}
body.mate-dm-active .scheduler-close-btn {
  color: rgba(255, 255, 255, 0.85);
}
body.mate-dm-active .scheduler-close-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
}
body.mate-dm-active .scheduler-scope-toggle {
  color: rgba(255, 255, 255, 0.7);
}
body.mate-dm-active .scheduler-scope-label {
  color: rgba(255, 255, 255, 0.7);
}
body.mate-dm-active .scheduler-scope-label[data-side="off"],
body.mate-dm-active .scheduler-scope-toggle.active .scheduler-scope-label[data-side="on"] {
  color: #fff;
}

/* Scheduler: breathing room below top-bar */
body.mate-dm-active .scheduler-sidebar,
body.mate-dm-active .scheduler-content {
  padding-top: 12px;
}

/* Sticky Notes header */
body.mate-dm-active .notes-archive-header {
  background: var(--mate-color);
  color: #fff;
}
body.mate-dm-active .notes-archive-header .lucide,
body.mate-dm-active .notes-archive-header h2 {
  color: #fff;
}
body.mate-dm-active .notes-archive-count {
  color: rgba(255, 255, 255, 0.7);
}
body.mate-dm-active .notes-archive-header button {
  color: rgba(255, 255, 255, 0.85);
}
body.mate-dm-active .notes-archive-header button:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
}

/* ==========================================================================
   Mate DM: Chat bubble style (messenger feel)
   ========================================================================== */

/* --- Avatar (injected by JS into .msg-user / .msg-assistant) --- */
.dm-bubble-avatar {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  flex-shrink: 0;
  display: none;
  object-fit: cover;
  margin-top: 2px;
}
body.mate-dm-active .dm-bubble-avatar,
body.wide-view .dm-bubble-avatar {
  display: block;
}

/* --- DM bubble header (name + time) --- */
/* Content wrapper: full width by default so child % sizing works,
   becomes flex child in DM/wide modes */
.dm-bubble-content {
  width: 100%;
}
.msg-user .dm-bubble-content {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
body.mate-dm-active .msg-user .dm-bubble-content,
body.wide-view .msg-user .dm-bubble-content {
  align-items: flex-start;
}
.dm-bubble-header {
  display: none;
  align-items: baseline;
  gap: 8px;
}
body.mate-dm-active .dm-bubble-header,
body.wide-view .dm-bubble-header {
  display: flex;
}
body.mate-dm-active .dm-bubble-content,
body.wide-view .dm-bubble-content {
  width: auto;
  flex: 1;
  min-width: 0;
}
.dm-bubble-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}
.dm-bubble-time {
  font-size: 12px;
  color: var(--text-dimmer);
}

/* --- Shared: Slack-style flat layout for both user & assistant --- */
body.mate-dm-active .msg-user,
body.mate-dm-active .msg-assistant {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  max-width: 100%;
  padding: 4px 16px;
  margin: 0;
  border-radius: 0;
}
body.mate-dm-active .msg-user:hover,
body.mate-dm-active .msg-assistant:hover {
  background: var(--bg-alt);
}

/* --- User messages --- */
body.mate-dm-active .msg-user {
  justify-content: flex-start; /* left-aligned like DM */
}
body.mate-dm-active .msg-user .dm-bubble-avatar-me {
  order: -1; /* avatar first (left) */
}
body.mate-dm-active .msg-user .bubble {
  background: none;
  border-radius: 0;
  padding: 0;
  max-width: 100%;
  font-size: 15px;
  line-height: 1.46;
  white-space: pre-wrap;
  word-wrap: break-word;
}
body.mate-dm-active .msg-user .msg-actions {
  display: none;
}

/* --- Assistant messages --- */
body.mate-dm-active .msg-assistant .dm-bubble-content {
  flex: 1;
  min-width: 0;
}
body.mate-dm-active .msg-assistant .md-content {
  background: none;
  border-radius: 0;
  padding: 0;
}

/* Hide turn meta in mate DM */
body.mate-dm-active .turn-meta {
  display: none;
}

/* ==========================================================================
   Mate DM: Humanized thinking / tools / permissions
   ========================================================================== */

/* --- Mate Thinking: flex layout matching msg-assistant --- */
/* Applies in both Mate DM and channel project chat */
body.mate-dm-active .mate-thinking,
body.wide-view .mate-thinking {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 16px;
  margin: 0;
  max-width: 100%;
}
body.mate-dm-active .mate-thinking:hover,
body.wide-view .mate-thinking:hover {
  background: var(--bg-alt);
}
body.mate-dm-active .mate-thinking > .dm-bubble-avatar,
body.wide-view .mate-thinking > .dm-bubble-avatar {
  display: block;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  flex-shrink: 0;
  margin-top: 2px;
}
body.mate-dm-active .mate-thinking > .dm-bubble-content,
body.wide-view .mate-thinking > .dm-bubble-content {
  flex: 1;
  min-width: 0;
}
.mate-thinking-row {
  display: none;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 4px 0;
}
body.mate-dm-active .mate-thinking:not(.done) .mate-thinking-row,
body.wide-view .mate-thinking:not(.done) .mate-thinking-row {
  display: flex;
}
.mate-thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.mate-thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: mate-dot-bounce 1.4s ease-in-out infinite;
}
.mate-thinking-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.mate-thinking-dots span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes mate-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* When done, hide mate row (JS does this too), show compact expandable header */
body.mate-dm-active .mate-thinking.done .mate-thinking-row,
body.wide-view .mate-thinking.done .mate-thinking-row {
  display: none;
}
body.mate-dm-active .mate-thinking.done .mate-thinking-activity,
body.wide-view .mate-thinking.done .mate-thinking-activity {
  display: none;
}
body.mate-dm-active .mate-thinking.done .thinking-header,
body.wide-view .mate-thinking.done .thinking-header {
  display: inline-flex !important;
  font-size: 12px;
  padding: 4px 10px;
  background: rgba(var(--overlay-rgb), 0.04);
  border-radius: 6px;
  opacity: 0.7;
  transition: opacity 0.15s;
}
body.mate-dm-active .mate-thinking.done .thinking-header:hover,
body.wide-view .mate-thinking.done .thinking-header:hover {
  opacity: 1;
  background: rgba(var(--overlay-rgb), 0.08);
}
body.mate-dm-active .mate-thinking .thinking-content,
body.wide-view .mate-thinking .thinking-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
}
body.mate-dm-active .mate-thinking.expanded .thinking-content,
body.wide-view .mate-thinking.expanded .thinking-content {
  max-height: 2000px;
}

/* --- Mate Tool Group: flex layout matching msg-assistant --- */
body.mate-dm-active .mate-tool-group {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 16px;
  margin: 0;
  max-width: 100%;
}
body.mate-dm-active .mate-tool-group:hover {
  background: var(--bg-alt);
}
body.mate-dm-active .mate-tool-group > .dm-bubble-avatar {
  display: block;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  flex-shrink: 0;
  margin-top: 2px;
}
body.mate-dm-active .mate-tool-group > .dm-bubble-content {
  flex: 1;
  min-width: 0;
  padding-top: 6px;
}
body.mate-dm-active .mate-tool-group .tool-group-header {
  font-size: 12px;
  padding: 4px 10px;
  background: rgba(var(--overlay-rgb), 0.04);
  border-radius: 6px;
  opacity: 0.7;
  transition: opacity 0.15s;
}
body.mate-dm-active .mate-tool-group .tool-group-header:hover {
  opacity: 1;
  background: rgba(var(--overlay-rgb), 0.08);
}
body.mate-dm-active .mate-tool-group .tool-group-label {
  font-size: 12px;
}
body.mate-dm-active .mate-tool-group .tool-item {
  border: none;
  background: none;
  padding: 2px 0;
}
body.mate-dm-active .mate-tool-group .tool-name {
  font-size: 13px;
  color: var(--text-muted);
}

/* --- Conversational Permission: flex layout matching msg-assistant --- */
/* Applies in both Mate DM and channel project chat */
body.mate-dm-active .mate-permission,
body.wide-view .mate-permission {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  border: none;
  border-radius: 0;
  background: none;
  box-shadow: none;
  padding: 4px 16px;
  margin: 0;
  max-width: 100%;
}
body.mate-dm-active .mate-permission:hover,
body.wide-view .mate-permission:hover {
  background: var(--bg-alt);
}
body.mate-dm-active .mate-permission > .dm-bubble-avatar,
body.wide-view .mate-permission > .dm-bubble-avatar {
  display: block;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  flex-shrink: 0;
  margin-top: 2px;
}
body.mate-dm-active .mate-permission > .dm-bubble-content,
body.wide-view .mate-permission > .dm-bubble-content {
  flex: 1;
  min-width: 0;
}
/* Permission ask text */
.mate-perm-ask {
  font-size: 15px;
  line-height: 1.46;
  color: var(--text);
  margin-bottom: 4px;
}
/* Details toggle */
.mate-perm-details {
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.mate-perm-details summary {
  cursor: pointer;
  user-select: none;
}
.mate-perm-details pre {
  font-size: 11px;
  margin: 4px 0 0;
  padding: 8px;
  background: rgba(var(--overlay-rgb), 0.04);
  border-radius: 6px;
  overflow-x: auto;
  max-height: 200px;
}
/* Reply buttons (override rewind.css .permission-actions) */
.mate-permission-actions {
  display: flex;
  gap: 6px;
  border: none;
  border-radius: 0;
  background: none;
  padding: 0;
}
.mate-permission-reply {
  padding: 5px 14px;
  border-radius: 16px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.mate-permission-reply:hover {
  border-color: var(--text-dimmer);
  background: rgba(var(--overlay-rgb), 0.06);
}
.mate-permission-allow {
  background: var(--accent, #6c5ce7);
  color: #fff;
  border-color: var(--accent, #6c5ce7);
}
.mate-permission-allow:hover {
  opacity: 0.9;
  background: var(--accent, #6c5ce7);
  border-color: var(--accent, #6c5ce7);
}
.mate-permission-deny {
  color: var(--text-muted);
}
/* Resolved state (works in both Mate DM and channel project chat) */
.mate-permission.resolved .mate-permission-actions {
  pointer-events: none;
}
.mate-permission.resolved .mate-permission-reply {
  display: none;
}
.mate-permission.resolved .permission-decision-label {
  font-size: 12px;
  color: var(--text-dimmer);
}

/* --- Mate Activity: avatar + text --- */

/* --- Mate AskUserQuestion: avatar + content layout (matches msg-assistant) --- */
body.mate-dm-active .mate-ask-user {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 16px;
  margin: 0;
  max-width: 100%;
}
body.mate-dm-active .mate-ask-user:hover {
  background: var(--bg-alt);
}
body.mate-dm-active .mate-ask-user > .dm-bubble-avatar {
  display: block;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  flex-shrink: 0;
  margin-top: 2px;
}
body.mate-dm-active .mate-ask-user > .dm-bubble-content {
  flex: 1;
  min-width: 0;
}

/* --- DM / Mate DM: full-width input like Slack --- */
body.mate-dm-active #input-wrapper,
#main-column.dm-mode #input-wrapper {
  max-width: 100%;
}

/* --- Interstitial elements: indent to align with message content (16px pad + 36px avatar + 8px gap = 60px) --- */
body.mate-dm-active .thinking-item:not(.mate-thinking),
body.mate-dm-active .tool-item,
body.mate-dm-active .tool-group:not(.mate-tool-group),
body.mate-dm-active .plan-card,
body.mate-dm-active .permission-container:not(.mate-permission),
body.mate-dm-active .ask-user-container:not(.mate-ask-user),
body.mate-dm-active .subagent-log,
body.mate-dm-active .conflict-msg,
body.mate-dm-active .context-overflow-msg,
body.mate-dm-active .sys-msg {
  display: none;
}
body.mate-dm-active .activity-inline:not(.mention-activity-bar):not(.mate-pre-activity):not(.mate-thinking-activity) {
  padding-left: 60px;
  margin-left: 0;
  margin-right: 0;
}
.mate-thinking > .dm-bubble-content > .mate-thinking-activity,
.mate-thinking > .dm-bubble-content > .mate-pre-activity {
  margin: 4px 0 0;
  padding: 0;
  max-width: none;
}

/* ==========================================================================
   Mobile Mate DM Title Bar
   ========================================================================== */
.mate-mobile-title {
  display: none !important;
}

@media (max-width: 768px) {
  /* Mobile mate DM: revert user messages to default bubble layout */
  body.mate-dm-active .msg-user,
  body.mate-dm-active .msg-assistant {
    display: flex !important;
    flex-direction: column !important;
    align-items: initial !important;
    gap: initial !important;
    max-width: var(--content-width) !important;
    padding: 0 20px !important;
    margin: 0 auto 8px !important;
    border-radius: initial !important;
  }
  body.mate-dm-active .msg-user {
    align-items: flex-end !important;
  }
  body.mate-dm-active .msg-assistant {
    margin-bottom: 12px !important;
    padding: 4px 20px !important;
  }
  body.mate-dm-active .msg-user:hover {
    background: initial !important;
  }
  body.mate-dm-active .msg-user .dm-bubble-avatar-me {
    display: none !important;
  }
  body.mate-dm-active .msg-user .dm-bubble-content {
    align-items: flex-end !important;
    flex: initial !important;
    width: 100% !important;
  }
  body.mate-dm-active .msg-user .dm-bubble-header {
    display: none !important;
  }
  body.mate-dm-active .msg-user .bubble {
    background: var(--user-bubble) !important;
    border-radius: 20px 20px 4px 20px !important;
    padding: 12px 18px !important;
    max-width: 85% !important;
    width: fit-content !important;
    font-size: 15px !important;
    line-height: 1.55 !important;
    white-space: pre-wrap !important;
    word-wrap: break-word !important;
  }
  body.mate-dm-active .msg-user .msg-actions {
    display: flex !important;
  }
  body.mate-dm-active .msg-assistant .dm-bubble-content {
    flex: initial !important;
    width: 100% !important;
  }
  body.mate-dm-active .msg-assistant .md-content {
    background: initial !important;
    border-radius: initial !important;
    padding: initial !important;
  }

  .mate-mobile-title:not(.hidden) {
    display: flex !important;
  }
  /* Show mobile mate title, hide everything else in title bar */
  body.mate-dm-active #header-left #sidebar-expand-btn,
  body.mate-dm-active #header-left #hamburger-btn,
  body.mate-dm-active #header-left #header-title,
  body.mate-dm-active #header-left #header-info-btn,
  body.mate-dm-active #header-left #header-rename-btn,
  body.mate-dm-active .title-bar-content #todo-sticky,
  body.mate-dm-active .title-bar-content #ralph-sticky,
  body.mate-dm-active .dm-header-bar,
  body.mate-dm-active .title-bar-content .status #sticky-notes-toggle-btn,
  body.mate-dm-active .title-bar-content .status #terminal-toggle-btn {
    display: none !important;
  }

  .mate-mobile-title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }

  .mate-mobile-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
  }

  .mate-mobile-name {
    font-size: 15px;
    font-weight: 500;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
  }

  .mate-mobile-status {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
    white-space: nowrap;
    flex-shrink: 0;
  }

  .mate-mobile-more {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    padding: 0;
    margin-left: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .mate-mobile-more svg {
    width: 20px;
    height: 20px;
  }

  .mate-mobile-more:active {
    color: #fff;
  }
}

/* ==========================================================================
   Mobile Knowledge Editor Tabs
   ========================================================================== */
.mate-knowledge-tab-bar {
  display: none;
}

@media (max-width: 768px) {
  .mate-knowledge-tab-bar {
    display: flex;
    gap: 0;
    padding: 0 12px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
  }

  .mate-knowledge-tab-btn {
    flex: 1;
    padding: 10px 0;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s, border-color 0.15s;
  }

  .mate-knowledge-tab-btn.active {
    color: var(--text);
    border-bottom-color: var(--accent);
  }

  /* Hide both panes by default on mobile, show only .mobile-active */
  .mate-knowledge-editor-pane,
  .mate-knowledge-preview-pane {
    display: none !important;
  }

  .mate-knowledge-editor-pane.mobile-active,
  .mate-knowledge-preview-pane.mobile-active {
    display: flex !important;
    flex: 1;
  }
}

/* === Mates UI gate === */
/* body.mates-disabled is set when the user flips the Mates toggle off in
   User Settings → Mates. body.is-multi-user is set when the deploy hosts
   more than one user. Single-user collapses the whole Mates surface;
   multi-user keeps Mates-adjacent containers visible (they still host
   other users) but greys out and disables the Mates-specific bits. */

/* Always hide pure-Mates UI: rotating switch hint, individual mate
   avatars in the icon strip, the home-hub mates strip, and the
   "Ask Mate" button in the chat input. These never contain anything
   but mates, so they collapse in both modes. */
body.mates-disabled .icon-strip-mate,
body.mates-disabled #icon-strip-hint-mate,
body.mates-disabled #home-hub-mates,
body.mates-disabled #ask-mate-btn {
  display: none !important;
}

/* Single-user only: collapse the whole icon-strip mate wrapper since it
   shares space with the user-strip but has no other users to display in
   single-user mode. The DM picker stays visible in both modes so the
   user always has a way to discover the toggle (single-user can't reach
   the picker today since the + button lives inside the wrapper, but if
   that ever changes the same disabled UX applies). */
body.mates-disabled:not(.is-multi-user) #icon-strip-mate-section {
  display: none !important;
}

/* === Mates discovery promo (DM picker, disabled state) === */
/* Shown in both modes when Mates is off. Replaces the old "greyed mate
   list with trash icons" pattern with a softer invitation: section
   label, an animated avatar marquee that loops left, a value-prop
   sentence, and a CTA that deep-links into User Settings → Mates. */

.dm-picker-mates-promo {
  padding: 0 12px 8px;
}

.dm-picker-mates-promo .dm-user-picker-section {
  margin-top: 0;
}

.dm-picker-mates-marquee {
  position: relative;
  height: 28px;
  margin: 4px -12px;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to right, transparent, black 12%, black 88%, transparent);
  mask-image: linear-gradient(to right, transparent, black 12%, black 88%, transparent);
}

.dm-picker-mates-marquee-track {
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  height: 100%;
  padding: 0 12px;
  animation: dm-picker-mates-marquee-flow 22s linear infinite;
}

.dm-picker-mates-marquee-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  opacity: 0.85;
  background: var(--bg-alt, rgba(255, 255, 255, 0.04));
}

@keyframes dm-picker-mates-marquee-flow {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}

.dm-picker-mates-promo-text {
  font-size: 11px;
  color: var(--text-dimmer, #888);
  line-height: 1.5;
  margin: 4px 0 8px;
}

.dm-picker-mates-promo-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border, #2a2a2a);
  background: var(--bg-alt, rgba(255, 255, 255, 0.04));
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s, border-color 0.15s;
}

.dm-picker-mates-promo-cta:hover {
  background: var(--bg-hover, rgba(255, 255, 255, 0.08));
  border-color: var(--accent, #6366f1);
}
