:root {
  --bg: #0A0A0C;
  --bg-base: #0F0D10;
  --bg-surface: #161218;
  --bg-elevated: #1C1719;
  --bg-card: #221B1E;
  --bg-input: #2A2225;
  --bg-hover: #332528;

  --accent: #FF0033;
  --accent-dark: #8B0020;
  --accent-deep: #5C0015;
  --accent-light: #FF1A5E;
  --accent-muted: #FF4D6D;
  --accent-bright: #FF1744;
  --accent-soft: #FF5252;
  --accent-dim: #6B2033;
  --accent-bg: #4A1525;

  --text-primary: #EAE0E2;
  --text-secondary: #D4C4C8;
  --text-tertiary: #8A7A7E;
  --text-disabled: #5A4F52;

  --success: #00E676;
  --warning: #FFD740;
  --error: #FF1744;
  --info: #448AFF;

  --border: #2A1F22;
  --border-accent: #FF003344;
  --border-accent-full: #FF0033;

  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;

  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'SF Mono', 'Menlo', monospace;

  --green: #00E676;
  --yellow: #FFD740;
  --red: #FF1744;
}

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

body {
  background: var(--bg);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent); color: #fff; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--accent-dim); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dark); }

a { color: var(--accent); text-decoration: none; cursor: pointer; }

/* ── Popup (icon click) ── */
.popup {
  width: 320px;
  padding: 16px;
}

.popup header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.popup .footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-tertiary);
  font-size: 10px;
}

/* ── Panel (side panel) ── */
.panel {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.panel > header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

header img { width: 28px; height: 28px; }
header h1 { font-size: 16px; font-weight: 600; letter-spacing: -0.3px; color: var(--text-primary); }

/* ── Tabs ── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: 0 8px;
}

.tab {
  flex: 1;
  padding: 10px 8px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-tertiary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-sans);
}

.tab:hover { color: var(--text-primary); }

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
}

/* ── Config tab ── */
.status-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
}

.status-row + .status-row {
  border-top: 1px solid var(--border);
  margin-top: 6px;
  padding-top: 10px;
}

.status-label { color: var(--text-tertiary); font-size: 12px; }
.status-value { font-weight: 500; font-size: 12px; color: var(--text-primary); }

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.dot-green { background: var(--success); box-shadow: 0 0 6px var(--success); }
.dot-red { background: var(--error); box-shadow: 0 0 6px var(--error); }
.dot-yellow { background: var(--warning); box-shadow: 0 0 6px var(--warning); }

.actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  font-family: var(--font-sans);
}

.btn:hover { background: var(--accent-bg); border-color: var(--accent-dark); color: var(--text-primary); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-bright);
  border-color: var(--accent-bright);
  box-shadow: 0 0 12px var(--border-accent);
}

.settings-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.settings-section label {
  display: block;
  color: var(--text-tertiary);
  font-size: 11px;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-row { display: flex; gap: 6px; }

.input-row input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color 0.2s;
}

.input-row input:focus { border-color: var(--accent); }

.input-row button {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 11px;
  font-family: var(--font-sans);
}

.input-row button:hover { background: var(--accent-bg); border-color: var(--accent-dark); }

.footer {
  margin-top: auto;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-tertiary);
  font-size: 10px;
  flex-shrink: 0;
}

.footer span { color: var(--accent); }

/* ── Chat offline ── */
.chat-offline {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-tertiary);
  font-size: 13px;
}

/* ── Studio Feed (same classes as Studio.jsx) ── */
.studio-feed-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  flex: 1;
}

.studio-feed {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.feed-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 0;
}

.feed-item {
  display: flex;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  animation: fadeIn 0.15s ease-out;
}

.feed-item:hover { background: var(--bg-card); }

.feed-item.user {
  background: var(--bg-card);
  border-left: 3px solid #FFD740;
}

.feed-item.assistant {
  border-left: 3px solid transparent;
}

.feed-item.assistant:hover {
  border-left-color: var(--accent-dark);
}

.feed-item.system {
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
}

.feed-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
  font-size: 14px;
}

.feed-avatar.user-rank {
  background: rgba(255, 215, 64, 0.15);
}

.feed-avatar.ai-rank {
  background: var(--accent-bg);
}

.feed-body {
  flex: 1;
  min-width: 0;
}

.feed-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.feed-rank-badge {
  font-size: 9px;
  font-weight: 800;
  font-family: var(--font-mono);
  padding: 1px 6px;
  border-radius: 3px;
  border: 1px solid;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  background: rgba(255, 215, 64, 0.08);
}

.feed-role {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.feed-time {
  font-size: 10px;
  color: var(--text-disabled);
  font-family: var(--font-mono);
}

.feed-content {
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  word-break: break-word;
}

.feed-system-badge {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-dim);
  flex-shrink: 0;
}

.feed-system-text {
  font-size: 12px;
  color: var(--text-tertiary);
  font-style: italic;
  flex: 1;
}

.feed-content table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.feed-content th { background: var(--bg-surface); padding: 6px 12px; text-align: left; font-weight: 600; border: 1px solid var(--border); color: var(--text-secondary); }
.feed-content td { padding: 5px 12px; border: 1px solid var(--border); color: var(--text-primary); }
.feed-content tr:nth-child(even) td { background: var(--bg-surface); }
.feed-content hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

.inline-code { background: var(--bg-input); padding: 2px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: 13px; color: var(--accent-muted); }
.msg-h2 { font-size: 17px; font-weight: 700; color: var(--text-primary); margin: 12px 0 6px; display: block; }
.msg-h3 { font-size: 15px; font-weight: 700; color: var(--text-primary); margin: 10px 0 4px; display: block; }
.msg-h4 { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 8px 0 3px; display: block; }
.msg-bullet { display: block; padding-left: 4px; margin: 1px 0; color: var(--text-primary); }
.msg-step { display: flex; gap: 8px; align-items: baseline; margin: 1px 0; }
.msg-step-num { color: var(--accent); font-weight: 700; font-family: var(--font-mono); font-size: 13px; flex-shrink: 0; min-width: 20px; }

/* ── Studio Code Blocks ── */
.studio-code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin: 8px 0;
}

.studio-code-header {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.studio-code-block pre {
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  overflow-x: auto;
  color: var(--text-primary);
  margin: 0;
}

.studio-code-lang {
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: var(--bg-surface);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.studio-copy-btn {
  padding: 3px 10px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  background: transparent;
  border: none;
  border-left: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-sans);
  white-space: nowrap;
}

.studio-copy-btn:hover { background: var(--accent-bg); color: var(--accent); }
.studio-copy-btn.copied { background: var(--accent-bg); color: var(--accent); }

/* ── Studio Thinking ── */
.feed-thinking-block {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent-dim);
  border-radius: var(--radius);
  margin: 6px 0 8px;
  overflow: hidden;
  max-height: 200px;
  overflow-y: auto;
}

.feed-thinking-block.done { border-left-color: var(--text-disabled); opacity: 0.7; }

.feed-thinking-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.feed-thinking-header svg { color: var(--warning); }

.feed-thinking-dots { display: inline-flex; gap: 2px; margin-left: 4px; }
.feed-thinking-dots span { width: 4px; height: 4px; border-radius: 50%; background: var(--warning); animation: bounce 1.2s ease-in-out infinite; }
.feed-thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.feed-thinking-dots span:nth-child(3) { animation-delay: 0.3s; }

.feed-thinking-content {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--text-tertiary);
  font-style: italic;
  line-height: 1.5;
  max-height: 80px;
  overflow-y: auto;
}

/* ── Studio Tool Blocks ── */
.studio-tool-block {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-dim);
  border-radius: var(--radius);
  margin: 6px 0;
  overflow: hidden;
  transition: all 0.3s ease;
}

.studio-tool-block.running { border-left-color: var(--warning); }
.studio-tool-block.error { border-left-color: var(--error); background: rgba(255, 23, 68, 0.05); }

.studio-tool-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.studio-tool-icon { font-size: 14px; flex-shrink: 0; }

.studio-tool-name {
  color: var(--text-tertiary);
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 12px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.studio-tool-spinner { display: inline-flex; gap: 2px; margin-left: 4px; }
.studio-tool-spinner span { width: 4px; height: 4px; border-radius: 50%; background: var(--warning); animation: bounce 1.2s ease-in-out infinite; }
.studio-tool-spinner span:nth-child(2) { animation-delay: 0.15s; }
.studio-tool-spinner span:nth-child(3) { animation-delay: 0.3s; }

.studio-tool-status { font-weight: 700; font-size: 14px; flex-shrink: 0; }
.studio-tool-status.ok { color: var(--success); }
.studio-tool-status.error { color: var(--error); }

.studio-tool-args {
  padding: 6px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
  white-space: pre-wrap;
  word-break: break-all;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.studio-tool-result { max-height: 200px; overflow-y: auto; }
.studio-tool-result pre {
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg);
}

/* ── Studio Cursor & Thinking Dots ── */
.studio-cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s step-end infinite;
}

.studio-thinking { display: flex; gap: 4px; padding: 8px 0; }
.studio-thinking span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent-dim); animation: bounce 1.2s ease-in-out infinite; }
.studio-thinking span:nth-child(2) { animation-delay: 0.15s; }
.studio-thinking span:nth-child(3) { animation-delay: 0.3s; }

@keyframes blink { 50% { opacity: 0; } }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.4; } 40% { transform: translateY(-6px); opacity: 1; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Studio Input Area ── */
.studio-input-area {
  padding: 12px 16px 8px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

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

.studio-input-row textarea {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  font-family: var(--font-sans);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.studio-input-row textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--border-accent); }
.studio-input-row textarea::placeholder { color: var(--text-disabled); }

.studio-send-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.studio-send-btn:hover { background: var(--accent-bright); border-color: var(--accent-bright); }
.studio-send-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.studio-stop-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--error);
  color: #fff;
  border: 1px solid var(--error);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.studio-stop-btn:hover { opacity: 0.8; }

.studio-input-hint {
  font-size: 11px;
  color: var(--text-disabled);
  text-align: center;
  margin-top: 6px;
}

/* ── Inject Session ── */
#btn-inject-session {
  background: var(--bg-card);
  border-color: var(--accent-dim);
  color: var(--text-primary);
}

#btn-inject-session:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
}

#btn-inject-session svg {
  flex-shrink: 0;
}

.inject-status {
  font-size: 11px;
  text-align: center;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-tertiary);
  animation: fadeIn 0.2s ease-out;
}

.inject-status.inject-success {
  color: var(--success);
  background: rgba(0, 230, 118, 0.08);
}

.inject-status.inject-error {
  color: var(--error);
  background: rgba(255, 23, 68, 0.08);
}

/* ── Toggle Switch ── */
.toggle-section {
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.toggle-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.toggle-desc {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 6px;
  line-height: 1.4;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 22px;
  transition: all 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 16px;
  width: 16px;
  left: 2px;
  bottom: 2px;
  background: var(--text-tertiary);
  border-radius: 50%;
  transition: all 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--accent-bg);
  border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
  background: var(--accent);
  transform: translateX(18px);
}

/* ── Live Chat Header ── */
.chat-live-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-live-header svg {
  animation: pulse-live 2s ease-in-out infinite;
}

@keyframes pulse-live {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
