:root {
  --bg: #212121;
  --panel: #18181b;
  --panel-soft: #222226;
  --text: #f5f5f7;
  --muted: #a1a1aa;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #2f2f34;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.casea-glow-text {
  background: linear-gradient(90deg, #00f2fe 0%, #4facfe 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: bold;
  text-shadow: 0 0 20px rgba(0, 242, 254, 0.4);
}

.fade-in-up {
  animation: fadeInUp 0.8s ease-out forwards;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.welcome-screen {
  transition: opacity 0.5s ease;
}

.thinking-dots::after {
  content: '';
  animation: thinkingDots 1.5s infinite steps(4, end);
}

@keyframes thinkingDots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 77, 79, 0.7); }
  100% { box-shadow: 0 0 15px 5px rgba(255, 77, 79, 0); }
}

.chat-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  transition: grid-template-columns 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.chat-shell.sidebar-collapsed {
  grid-template-columns: 0px 1fr;
}

.chat-sidebar {
  border-right: 1px solid var(--line);
  background: #151518;
  padding: 18px 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 260px; /* Fixed content width for smooth transition */
  transition: all 0.35s ease;
  visibility: visible;
  opacity: 1;
}

.chat-sidebar.collapsed {
  padding: 18px 0;
  border-right-width: 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.sidebar-header {
  min-height: 40px;
  margin-bottom: 8px;
}

.sidebar-toggle-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.sidebar-toggle-btn:hover {
  background: #222226;
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.2);
}

.main-sidebar-toggle-wrap {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 100;
  transition: transform 0.35s ease, opacity 0.35s ease;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-20px);
}

.sidebar-collapsed .main-sidebar-toggle-wrap {
  pointer-events: auto;
  opacity: 1;
  transform: translateX(0);
}

.main-sidebar-toggle-btn {
  background: rgba(30, 30, 35, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  transition: all 0.2s ease;
}

.main-sidebar-toggle-btn:hover {
  background: rgba(45, 45, 50, 0.9);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.2);
}

.sidebar-logo-text {
  transition: opacity 0.2s ease, width 0.2s ease;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  background: transparent;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.sidebar-nav-item:hover {
  background: #1d1d22;
  color: var(--text);
}

.sidebar-nav-item.primary {
  background: #1d1d22;
  border: 1px solid var(--line);
  color: var(--text);
}

.sidebar-nav-item.primary:hover {
  background: #25252b;
  border-color: rgba(255, 255, 255, 0.2);
}

.collapsed .nav-text {
  opacity: 0;
  width: 0;
  pointer-events: none;
}

.history-list-wrapper {
  flex: 1;
  overflow-y: auto;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.history-group-title {
  font-size: 11px;
  font-weight: 700;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-left: 12px;
  margin-bottom: 8px;
}

.collapsed .history-group-title {
  display: none;
}

.history-item {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: #1d1d22;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-item:hover {
  background: #2a2a30;
  border-color: var(--line);
}

.sidebar-profile {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  background: #1b1b20;
  padding: 10px;
  border-radius: 14px;
}

.avatar-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #2a2a30;
  font-weight: 700;
}

.profile-meta {
  display: flex;
  flex-direction: column;
}

.profile-meta strong {
  font-size: 0.88rem;
}

.profile-meta span {
  font-size: 0.75rem;
  color: var(--muted);
}

.chat-main {
  min-width: 0;
  width: 100%;
  display: flex !important;
  flex-direction: column !important;
  height: 100vh !important;
  overflow: hidden !important;
  position: relative;
}

.chat-stage {
  flex: 1 1 auto !important;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto !important;
  max-height: calc(100vh - 150px) !important;
  padding: 24px;
  display: grid;
  place-items: center;
}

/* Main transcript area: scrollable column */
.chat-messages {
  flex: 1 !important;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  overflow-y: auto !important;
  max-height: 80vh !important;
  padding: 24px;
  display: flex;
  flex-direction: column;
}

.intro-title {
  max-width: 760px;
  text-align: center;
  font-size: clamp(1.5rem, 3.8vw, 2.4rem);
  line-height: 1.25;
  color: #f4f4f5;
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.message {
  display: flex;
  margin: 0 0 14px;
  opacity: 0;
  transform: translateY(10px);
  animation: riseIn 0.25s ease forwards;
}

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

.bubble {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 16px;
  background: #222228;
  border: 1px solid var(--line);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  line-height: 1.5;
}

.message.user .bubble {
  background: #2e2e34;
}

.chat-input-wrap {
  max-width: 960px;
  width: 100%;
  margin: 0 auto 24px;
  padding: 0 24px;
}

.input-box {
  background: #1d1d22;
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 8px;
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  align-items: center;
  gap: 8px;
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.input-box:hover {
  border-color: rgba(255, 255, 255, 0.16);
}

.input-box:focus-within {
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #27272d;
  color: #d4d4d8;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.new-inline-btn {
  font-size: 1.25rem;
  font-weight: 700;
}

.mic-active {
  color: #9dfad8 !important;
  animation: micPulse 1.5s infinite;
}

@keyframes micPulse {
  0%,
  100% {
    filter: drop-shadow(0 0 0 rgba(0, 255, 204, 0.35));
  }
  50% {
    filter: drop-shadow(0 0 8px rgba(0, 255, 204, 0.75));
  }
}

.chat-input-wrap input {
  width: 100%;
  border-radius: 14px;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  font-size: 0.98rem;
}

.send-btn {
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  color: white;
  background: #2f2f36;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.legacy-mic {
  display: none;
}

@keyframes riseIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-messages.chat-stream {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  padding: 18px 24px;
}

.message-row {
  width: 100%;
  margin: 10px 0;
}

.user-row {
  display: flex;
  justify-content: flex-end;
}

.ai-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.message-content-wrapper {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.message-avatar {
  width: 25px;
  height: 25px;
  border-radius: 50%;
  margin-top: 2px;
  object-fit: cover;
}

.user-message {
  background: #2c2c2e;
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  max-width: 70%;
  word-wrap: break-word;
}

.ai-message {
  color: #fff;
  max-width: 80%;
  line-height: 1.6;
  word-wrap: break-word;
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
}

/* Markdown-rendered assistant text (marked.js + DOMPurify) */
.ai-message.casea-md,
.message-content.casea-md {
  line-height: 1.55;
}

.ai-message.casea-md p,
.message-content.casea-md p {
  margin: 0.5em 0;
}

.ai-message.casea-md p:first-child,
.message-content.casea-md p:first-child {
  margin-top: 0;
}

.ai-message.casea-md p:last-child,
.message-content.casea-md p:last-child {
  margin-bottom: 0;
}

.ai-message.casea-md h3,
.message-content.casea-md h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 1em 0 0.4em;
  color: #e8e8ec;
}

.ai-message.casea-md ul,
.ai-message.casea-md ol,
.message-content.casea-md ul,
.message-content.casea-md ol {
  margin: 0.4em 0 0.6em 1.1em;
  padding-left: 0.2em;
}

.ai-message.casea-md li,
.message-content.casea-md li {
  margin: 0.25em 0;
}

.ai-message.casea-md hr,
.message-content.casea-md hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  margin: 1em 0;
}

.ai-message.casea-md strong,
.message-content.casea-md strong {
  color: #fff;
  font-weight: 600;
}

.ai-message.casea-md code,
.message-content.casea-md code {
  font-size: 0.9em;
  background: rgba(255, 255, 255, 0.08);
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

.ai-message.casea-md pre,
.message-content.casea-md pre {
  background: rgba(0, 0, 0, 0.35);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.6em 0;
}

.ai-message.casea-md pre code,
.message-content.casea-md pre code {
  background: none;
  padding: 0;
}

.ai-message.casea-md a,
.message-content.casea-md a {
  color: #6ec8ff;
  text-decoration: underline;
}

@media (max-width: 900px) {
  .chat-shell {
    grid-template-columns: 1fr;
  }

  .chat-sidebar {
    display: none;
  }
}

/* --- Casea chat polish: scrollbar, sidebar flow, history context menu (additive) --- */

.chat-messages {
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(100, 100, 100, 0.3);
  border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(140, 140, 140, 0.45);
}

.history-list-container-scroll {
  flex: 1 1 0 !important;
  min-height: 0 !important;
  margin-top: 8px !important;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.history-list-container-scroll::-webkit-scrollbar {
  width: 6px;
}

.history-list-container-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.history-list-container-scroll::-webkit-scrollbar-thumb {
  background: rgba(100, 100, 100, 0.3);
  border-radius: 10px;
}

.history-list-container-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(140, 140, 140, 0.45);
}

.chat-casea-page .chat-sidebar {
  justify-content: flex-start;
}

.chat-casea-page .chat-sidebar .history-list-wrapper {
  flex: 0 0 auto !important;
  flex-grow: 0 !important;
  min-height: 0;
  overflow: visible;
  margin-top: 4px;
}

.history-list-root {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  align-items: stretch;
}

.history-group-items {
  list-style: none;
  padding: 0;
  margin: 0 0 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-sidebar-li {
  list-style: none;
  margin: 0;
  padding: 0;
}

.history-sidebar-li-inner {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
}

.history-sidebar-li .history-item {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
}

.history-item-more {
  flex: 0 0 28px;
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.history-sidebar-li:hover .history-item-more {
  opacity: 1;
  pointer-events: auto;
}

.history-item-more:hover,
.history-item-more:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  outline: none;
}

.history-empty-placeholder {
  padding: 16px 12px;
  text-align: center;
  color: #555;
  font-size: 13px;
  margin: 0;
  align-self: flex-start;
  width: 100%;
}

.casea-chat-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding: 12px 24px 0;
  flex-wrap: wrap;
}

.casea-toolbar-btn {
  border: 1px solid #3c3c40;
  background: #202024;
  color: #d5d5da;
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.casea-toolbar-btn:hover {
  background: #2a2a30;
  border-color: rgba(255, 255, 255, 0.14);
}

.casea-toolbar-btn--primary {
  border-color: #2b4f8e;
  background: #15315a;
  color: #d6e6ff;
}

.casea-toolbar-btn--primary:hover {
  background: #1a3d6e;
}

.casea-stop-chat-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 12px;
  min-height: 38px;
  border-radius: 20px;
  border: 1px solid rgba(255, 77, 79, 0.45);
  background: rgba(255, 77, 79, 0.12);
  color: #ffb4b4;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.casea-stop-chat-btn:hover {
  background: rgba(255, 77, 79, 0.22);
  border-color: rgba(255, 77, 79, 0.65);
}

.casea-stop-chat-btn[hidden] {
  display: none !important;
}

.casea-history-menu-emoji {
  font-size: 15px;
  line-height: 1;
  flex-shrink: 0;
}

.casea-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.casea-modal-overlay[hidden] {
  display: none !important;
}

.casea-modal {
  width: 100%;
  max-width: 400px;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(165deg, #2a2a30 0%, #1c1c22 100%);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
  padding: 22px 22px 18px;
}

.casea-modal-title {
  margin: 0 0 14px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.casea-modal-body {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--muted);
}

.casea-modal-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #151518;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 18px;
}

.casea-modal-input:focus {
  outline: none;
  border-color: rgba(79, 172, 254, 0.5);
}

.casea-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.casea-modal-btn {
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.casea-modal-btn--ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.casea-modal-btn--ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.casea-modal-btn--primary {
  background: #2563eb;
  border-color: #3b82f6;
  color: #fff;
}

.casea-modal-btn--primary:hover {
  background: #1d4ed8;
}

.casea-modal-btn--danger {
  background: rgba(185, 28, 28, 0.35);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fecaca;
}

.casea-modal-btn--danger:hover {
  background: rgba(185, 28, 28, 0.5);
}

.casea-history-menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10750;
  background: transparent;
  cursor: default;
}

.casea-history-menu-backdrop[hidden] {
  display: none !important;
}

.casea-history-context-menu {
  position: fixed;
  z-index: 10800;
  min-width: 220px;
  padding: 6px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(32, 32, 38, 0.72);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  box-shadow:
    0 12px 40px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.casea-history-context-menu[hidden] {
  display: none !important;
}

.casea-history-menu-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  margin: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: rgba(245, 245, 247, 0.92);
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease;
}

.casea-history-menu-row:hover,
.casea-history-menu-row:focus-visible {
  background: rgba(255, 255, 255, 0.08);
  outline: none;
}

.casea-history-menu-icon {
  flex-shrink: 0;
  opacity: 0.85;
}
