/* ===== AI multi-thread sidebar — modern UX redesign 2026-05-04 ===== */
/* Design language inspired by Claude.ai / ChatGPT — calm, minimal, gold accents only on active */

/* Force flex layout — overrides platfound base .sub-tab-panel { display: block } */
#subtab-claude.ai-with-threads {
  display: flex !important;
  gap: 0 !important;
  height: 100% !important;
  align-items: stretch !important;
  background: #0a0e1a;
  flex-direction: row !important;
}

/* ───── Sidebar (left thread list) — collapsible drawer ───── */
#ai-thread-sidebar {
  width: 60px;
  min-width: 60px;
  max-width: 60px;
  flex-shrink: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.25);
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden;
  transition: width 0.22s ease, min-width 0.22s ease, max-width 0.22s ease;
  position: relative;
}
#ai-thread-sidebar.expanded {
  width: 260px;
  min-width: 260px;
  max-width: 260px;
}
/* Toggle button (always visible at top of sidebar) */
#ai-thread-toggle {
  position: absolute;
  top: 12px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  z-index: 5;
  transition: background 0.15s ease, transform 0.22s ease;
}
#ai-thread-toggle:hover { background: rgba(255, 255, 255, 0.10); color: #fff; }
#ai-thread-sidebar.expanded #ai-thread-toggle { transform: rotate(180deg); }
/* Collapsed state: hide head + list content, show only toggle */
#ai-thread-sidebar:not(.expanded) .ai-thread-head,
#ai-thread-sidebar:not(.expanded) #ai-thread-list { display: none; }
#ai-thread-sidebar:not(.expanded)::after {
  content: "对话历史";
  position: absolute;
  top: 56px;
  left: 50%;
  transform: translateX(-50%) rotate(180deg);
  writing-mode: vertical-rl;
  text-orientation: upright;
  letter-spacing: 6px;
  font-size: 11px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.35);
  pointer-events: none;
  white-space: nowrap;
}
.ai-thread-head {
  padding: 12px 12px 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

/* "+ 新对话" — clean, minimal — overrides the legacy ID rule */
button#ai-thread-new.ai-thread-new,
.ai-thread-new {
  flex: 1;
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 600;
  background: transparent !important;
  background-image: none !important;
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: rgba(255, 255, 255, 0.85);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button#ai-thread-new.ai-thread-new:hover,
.ai-thread-new:hover {
  background: rgba(255, 255, 255, 0.05) !important;
  border-color: rgba(255, 255, 255, 0.18);
  color: #fff;
}

/* Sort dropdown — minimal pill */
.ai-thread-sort {
  flex-shrink: 0;
  padding: 6px 8px;
  font-size: 11px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: rgba(255, 255, 255, 0.65);
  border-radius: 8px;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'><path d='M3 4.5l3 3 3-3' stroke='%23999' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 22px;
}
.ai-thread-sort:hover {
  border-color: rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.85);
}

#ai-thread-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px 12px;
}
#ai-thread-list::-webkit-scrollbar { width: 4px; }
#ai-thread-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.10);
  border-radius: 2px;
}

.ai-thread-empty {
  padding: 24px 14px;
  color: rgba(255, 255, 255, 0.4);
  font-size: 12px;
  text-align: center;
  line-height: 1.7;
}

/* Thread row — clean ChatGPT-style */
.ai-thread-row {
  position: relative;
  padding: 10px 30px 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.12s ease;
}
.ai-thread-row:hover { background: rgba(255, 255, 255, 0.04); }
.ai-thread-row.active {
  background: rgba(255, 255, 255, 0.07);
}
.ai-thread-row-title {
  font-size: 13px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.92);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.1px;
}
.ai-thread-row.active .ai-thread-row-title {
  font-weight: 600;
  color: #fff;
}
.ai-thread-row.active::before {
  content: "";
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 2px;
  border-radius: 2px;
  background: #fbbf24;
}

.ai-thread-row-meta { display: block; }
.ai-thread-row-preview {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.42);
  line-height: 1.5;
  margin-top: 3px;
}
.ai-thread-row-time {
  display: block;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.35);
  margin-top: 4px;
}

/* Menu button — only on hover */
.ai-thread-row-menu {
  position: absolute;
  right: 6px;
  top: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.5);
  font-size: 16px;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ai-thread-row:hover .ai-thread-row-menu { opacity: 0.7; }
.ai-thread-row-menu:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.10);
  color: #fff;
}

/* ───── Main pane (right side: title + messages + input) ───── */
.ai-thread-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}
/* Force flex children to allow shrinking — fixes input being pushed off screen */
.ai-thread-main > * { min-height: 0; }
.ai-thread-main > .messages-wrapper,
.ai-thread-main > #claude-messages,
.ai-thread-main > #ai-empty-state { flex: 1 1 0; min-height: 0; overflow-y: auto; }
.ai-thread-main > #ai-thread-title-bar,
.ai-thread-main > .input-area,
.ai-thread-main > .search-bar { flex: 0 0 auto; }
/* Input area always visible at bottom */
.ai-thread-main .input-area {
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.2);
}

/* Title bar — clean, no gold underline */
#ai-thread-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
  gap: 16px;
  background: transparent;
}
.ai-tt-left { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.ai-tt-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#ai-thread-title-text {
  font-size: 15px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.95);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.1px;
}
#ai-thread-title-meta {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 0.3px;
}
.ai-tt-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.ai-tt-right select {
  padding: 6px 28px 6px 10px;
  font-size: 11px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: rgba(255, 255, 255, 0.75);
  border-radius: 8px;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'><path d='M3 4.5l3 3 3-3' stroke='%23999' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.ai-tt-right select:hover { border-color: rgba(255, 255, 255, 0.18); color: #fff; }

/* Persona chip — subtle, no fancy gradients */
.ai-persona-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  border: 1px solid;
  line-height: 1.4;
}
.ai-persona-chip.persona-mz {
  background: rgba(251, 191, 36, 0.10);
  border-color: rgba(251, 191, 36, 0.30);
  color: #fbbf24;
}
.ai-persona-chip.persona-boleh {
  background: rgba(34, 197, 94, 0.08);
  border-color: rgba(34, 197, 94, 0.30);
  color: #6ee7b7;
}
.ai-persona-chip.persona-demogroup {
  background: rgba(59, 130, 246, 0.08);
  border-color: rgba(59, 130, 246, 0.30);
  color: #93c5fd;
}
.ai-persona-chip.persona-inb {
  background: rgba(168, 85, 247, 0.08);
  border-color: rgba(168, 85, 247, 0.30);
  color: #d8b4fe;
}
.ai-persona-chip.persona-generic {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.55);
}

/* B1: hide PM dropdown + old panel-header on AI tab */
body.ai-mode #pm-header-slot { display: none !important; }
body.ai-mode .panel-header { display: none !important; }

/* ───── Empty state hero ───── */
#ai-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  gap: 14px;
}
.ai-empty-mascot {
  font-size: 48px;
  opacity: 0.85;
  animation: ai-empty-bob 4s ease-in-out infinite;
}
@keyframes ai-empty-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
.ai-empty-title {
  font-size: 18px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.92);
  letter-spacing: 0.2px;
}
.ai-empty-sub {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.45);
  margin-bottom: 12px;
}
.ai-empty-chips {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px;
  width: 100%;
  max-width: 640px;
}
.ai-empty-chip {
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.85);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
  white-space: normal;
  line-height: 1.4;
}
.ai-empty-chip:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.18);
  color: #fff;
  transform: translateY(-1px);
}
.ai-empty-chip:active { transform: scale(0.98); }

/* ───── Modal (rename / delete confirm) ───── */
.ai-modal-back {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: ai-modal-fade 0.15s ease;
}
@keyframes ai-modal-fade { from { opacity: 0; } to { opacity: 1; } }
.ai-modal {
  background: #14171c;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 12px;
  padding: 22px;
  min-width: 360px;
  max-width: 480px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  animation: ai-modal-pop 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes ai-modal-pop { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
.ai-modal-title {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 14px;
}
.ai-modal-body {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 16px;
  line-height: 1.5;
}
.ai-modal-input {
  width: 100%;
  padding: 10px 12px;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: #fff;
  border-radius: 8px;
  outline: none;
  margin-bottom: 16px;
  box-sizing: border-box;
}
.ai-modal-input:focus { border-color: rgba(251, 191, 36, 0.4); }
.ai-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.ai-modal-btn {
  padding: 8px 18px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  transition: all 0.15s ease;
}
.ai-modal-btn:hover { background: rgba(255, 255, 255, 0.05); color: #fff; }
.ai-modal-btn.primary {
  background: #fbbf24;
  border-color: #fbbf24;
  color: #1a0f06;
}
.ai-modal-btn.primary:hover { background: #f59e0b; }
.ai-modal-btn.danger {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}
.ai-modal-btn.danger:hover { background: #b91c1c; }

.ai-modal-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai-modal-choice {
  padding: 12px 14px;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}
.ai-modal-choice:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.16);
}
.ai-modal-choice.danger:hover {
  background: rgba(220, 38, 38, 0.10);
  border-color: rgba(220, 38, 38, 0.4);
  color: #fca5a5;
}

/* Home button hover */
header .logo {
  transition: opacity 0.15s ease, color 0.15s ease;
}
header .logo:hover { opacity: 0.85; color: #fbbf24; }
header .logo:active { transform: scale(0.97); }
header .logo::after {
  content: " 🏠";
  opacity: 0;
  font-size: 12px;
  transition: opacity 0.15s ease;
}
header .logo:hover::after { opacity: 0.6; }

/* Mobile responsive */
@media (max-width: 768px) {
  #ai-thread-sidebar { width: 60px; min-width: 60px; }
  .ai-thread-row-title, .ai-thread-row-meta, .ai-thread-sort { display: none; }
  .ai-thread-row { padding: 10px; height: 36px; }
  .ai-thread-row::before { content: '💬'; font-size: 14px; }
  button#ai-thread-new.ai-thread-new { font-size: 0; padding: 8px; }
  button#ai-thread-new.ai-thread-new::before { content: "+"; font-size: 18px; }
}

/* ── Memory editor button + tabs ── */
.ai-memory-btn {
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: rgba(255, 255, 255, 0.75);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.ai-memory-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.20);
  color: #fff;
}
.ai-mem-tab {
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.55);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s ease;
}
.ai-mem-tab:hover { color: #fff; }
.ai-mem-tab.active {
  color: #fbbf24;
  border-bottom-color: #fbbf24;
}
