/* Pearl AI Hub — Chat Playground Styles */

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-hover: #22263a;
  --border: #2a2e3d;
  --text: #e4e6ef;
  --text-muted: #8b8fa3;
  --primary: #6c5ce7;
  --primary-hover: #7c6ff7;
  --green: #00b894;
  --red: #e74c3c;
  --yellow: #fdcb6e;
  --blue: #0984e3;
  --radius: 10px;
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: "SF Mono", "Fira Code", "Cascadia Code", monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  height: 100vh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ── App Layout ── */
.app-layout {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 1.2rem 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), #a29bfe);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.sidebar-header .subtitle {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.sidebar-section {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}
.sidebar-section label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0.6rem 0 0.25rem;
}

/* Model List */
.model-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.model-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.85rem;
  text-align: left;
  transition: all 0.15s;
}
.model-btn:hover {
  border-color: var(--primary);
  background: var(--surface-hover);
}
.model-btn.active {
  border-color: var(--primary);
  background: rgba(108, 92, 231, 0.12);
}
.model-btn.loading {
  opacity: 0.6;
  cursor: wait;
}
.model-btn .model-name {
  font-weight: 600;
}
.model-btn .model-size {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 8px;
  background: rgba(108, 92, 231, 0.15);
  color: var(--primary);
  margin-left: auto;
}
.model-btn .model-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
}
.model-btn.active .model-dot {
  background: var(--green);
}

.switch-status {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  background: rgba(253, 203, 110, 0.1);
  color: var(--yellow);
}

/* Sidebar inputs */
.sidebar-section input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}
.range-value {
  font-size: 0.8rem;
  color: var(--text-muted);
  float: right;
  margin-top: -1.4rem;
}
.sidebar-section textarea {
  width: 100%;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
  resize: vertical;
}
.sidebar-section textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Status Badge */
.status-badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.status-badge.online {
  background: rgba(0, 184, 148, 0.15);
  color: var(--green);
}
.status-badge.offline {
  background: rgba(231, 76, 60, 0.15);
  color: var(--red);
}
.status-badge.loading {
  background: rgba(253, 203, 110, 0.15);
  color: var(--yellow);
}

/* API / Nav Links */
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  transition: all 0.15s;
}
.nav-link:hover {
  color: var(--text);
  background: var(--surface-hover);
}
.nav-link svg {
  opacity: 0.6;
  flex-shrink: 0;
}
.nav-link:hover svg {
  opacity: 1;
}

/* ── Chat Area ── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.chat-header span {
  font-weight: 600;
  font-size: 0.95rem;
}
.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.35rem 0.8rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: var(--font);
}
.btn-secondary:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.welcome-message {
  text-align: center;
  margin: auto;
  max-width: 400px;
}
.welcome-message h2 {
  font-size: 1.3rem;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--primary), #a29bfe);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.welcome-message p {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.welcome-message .hint {
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

.message {
  max-width: 75%;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.6;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.message.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.message.assistant .msg-content {
  white-space: normal;
}

/* ── Markdown inside messages ── */
.msg-content p {
  margin: 0 0 0.5em;
}
.msg-content p:last-child {
  margin-bottom: 0;
}
.msg-content h1,
.msg-content h2,
.msg-content h3,
.msg-content h4,
.msg-content h5,
.msg-content h6 {
  margin: 0.8em 0 0.3em;
  line-height: 1.3;
}
.msg-content h1 {
  font-size: 1.2em;
}
.msg-content h2 {
  font-size: 1.1em;
}
.msg-content h3 {
  font-size: 1em;
}
.msg-content ul,
.msg-content ol {
  margin: 0.3em 0;
  padding-left: 1.5em;
}
.msg-content code {
  background: rgba(255, 255, 255, 0.08);
  padding: 0.15em 0.4em;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.85em;
}
.msg-content pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  overflow-x: auto;
  margin: 0.5em 0;
}
.msg-content pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 0.85em;
  white-space: pre;
}
.msg-content blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 0.8em;
  margin: 0.5em 0;
  color: var(--text-muted);
}
.msg-content table {
  border-collapse: collapse;
  margin: 0.5em 0;
  width: 100%;
}
.msg-content th,
.msg-content td {
  border: 1px solid var(--border);
  padding: 0.4em 0.6em;
  font-size: 0.85em;
}
.msg-content th {
  background: var(--bg);
  font-weight: 600;
}
.msg-content a {
  color: var(--primary);
  text-decoration: underline;
}
.msg-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8em 0;
}

/* ── Collapsible Think Block ── */
.think-block {
  margin: 0.4em 0 0.6em;
  border: 1px solid rgba(108, 92, 231, 0.25);
  border-radius: 8px;
  background: rgba(108, 92, 231, 0.06);
  overflow: hidden;
}
.think-block summary {
  cursor: pointer;
  padding: 0.5rem 0.8rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.think-block summary::-webkit-details-marker {
  display: none;
}
.think-block summary::after {
  content: "▸";
  margin-left: auto;
  transition: transform 0.2s;
  font-size: 0.75rem;
}
.think-block[open] summary::after {
  transform: rotate(90deg);
}
.think-block summary:hover {
  color: var(--text);
  background: rgba(108, 92, 231, 0.1);
}
.think-content {
  padding: 0.5rem 0.8rem 0.7rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  border-top: 1px solid rgba(108, 92, 231, 0.15);
  line-height: 1.5;
}
.think-content p {
  margin: 0 0 0.4em;
}
.think-content p:last-child {
  margin-bottom: 0;
}
.message .msg-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}
.message.user .msg-meta {
  color: rgba(255, 255, 255, 0.6);
}

.message.thinking {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-style: italic;
}
.thinking-dots::after {
  content: "";
  animation: dots 1.5s infinite;
}
@keyframes dots {
  0%,
  20% {
    content: ".";
  }
  40% {
    content: "..";
  }
  60%,
  100% {
    content: "...";
  }
}

.streaming-cursor {
  display: inline-block;
  color: var(--primary);
  animation: blink 0.8s step-end infinite;
  font-weight: 400;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* ── Loading Indicator (before first token) ── */
.loading-indicator {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.2rem 0;
}
.loading-text {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}
.loading-dots {
  display: flex;
  gap: 4px;
}
.loading-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  animation: loadPulse 1.4s ease-in-out infinite;
}
.loading-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.loading-dots span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes loadPulse {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1.1);
  }
}

/* ── Live Think Block (streaming) ── */
.think-placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.82rem;
}

/* ── Chat Input ── */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.chat-input-area textarea {
  flex: 1;
  padding: 0.7rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
}
.chat-input-area textarea:focus {
  outline: none;
  border-color: var(--primary);
}

#send-btn {
  width: 40px;
  height: 40px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
#send-btn:hover {
  background: var(--primary-hover);
}
#send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Responsive ── */
@media (max-width: 700px) {
  .app-layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .message {
    max-width: 90%;
  }
}
