/* WebBrain Side Panel Styles */

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f3460;
  --bg-input: #1e2746;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0b8;
  --text-muted: #6b6b80;
  --accent: #6c63ff;
  --accent-hover: #5a52d5;
  --accent-dim: rgba(108, 99, 255, 0.15);
  --success: #4caf50;
  --warning: #ff9800;
  --error: #f44336;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 13px;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transition: background 0.3s;
}

.status-dot.online { background: var(--success); }
.status-dot.offline { background: var(--error); }
.status-dot.connecting { background: var(--warning); animation: pulse 1.5s infinite; }

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

#provider-select {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  max-width: 180px;
  min-width: 0;
}

/* Globe language selector. Native select overlaid on a globe icon so it
   keeps the header icon-button look while staying accessible. */
.language-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}
.language-wrapper:hover { color: var(--text-primary); background: var(--accent-dim); }
.language-wrapper .language-icon { pointer-events: none; }
.language-wrapper select {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  border: none;
  background: transparent;
  appearance: none;
}

#header button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: color 0.2s, background 0.2s;
}

#header button:hover {
  color: var(--text-primary);
  background: var(--accent-dim);
}

#header button.active {
  color: var(--accent);
  background: var(--accent-dim);
}

/* Sticky badge above the input area when /allow-api is set. */
.api-badge {
  margin: 0 12px 6px 12px;
  padding: 6px 10px;
  background: rgba(255, 152, 0, 0.12);
  border: 1px solid rgba(255, 152, 0, 0.45);
  border-radius: var(--radius);
  font-size: 11px;
  color: var(--text);
  text-align: center;
}
.api-badge span { font-weight: 600; }

/* Page Inspection Banner */
#inspection-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: rgba(108, 99, 255, 0.08);
  border-bottom: 1px solid rgba(108, 99, 255, 0.15);
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
  flex-shrink: 0;
  animation: fadeIn 0.2s ease;
}

#inspection-banner.hidden {
  display: none;
}

.inspection-dot {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1.5s infinite;
  flex-shrink: 0;
}

/* Chat Container */
#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  scroll-behavior: smooth;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Messages */
.message {
  display: flex;
  flex-direction: column;
  max-width: 95%;
  animation: fadeIn 0.2s ease;
}

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

.message.user {
  align-self: flex-end;
}

.message.assistant, .message.system {
  align-self: flex-start;
}

.message-content {
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.5;
  word-wrap: break-word;
  white-space: normal;
}

.message.user .message-content {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.user .message-text {
  white-space: pre-wrap;
}

.message.assistant .message-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message.system .message-content {
  background: var(--accent-dim);
  border: 1px solid rgba(108, 99, 255, 0.2);
  font-size: 12px;
}

.message-content p {
  margin-bottom: 6px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.hint {
  color: var(--text-muted);
  font-size: 11px;
  font-style: italic;
}


/* Verbose mode: each turn's reasoning blurb is appended as its own dim
   paragraph instead of overwriting the previous one, so the full chain
   of intermediate thinking is preserved alongside the steps log. */
.reasoning-step {
  border-left: 2px solid var(--border);
  padding: 4px 0 4px 8px;
  margin: 6px 0;
  opacity: 0.85;
  font-size: 13px;
}
.reasoning-step + .reasoning-step {
  margin-top: 4px;
}
.reasoning-step:last-child {
  opacity: 1;
  border-left-color: var(--accent, var(--border));
}


/* ==========================================================================
   COMPACT TOOL STEPS (default mode) — human-friendly activity trail
   ========================================================================== */

.steps-container {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin: 6px 0 8px 0;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 3px 0;
  transition: color 0.2s;
}

.step-item.active {
  color: var(--text-secondary);
}

.step-item.done {
  color: var(--text-muted);
}

.step-icon {
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 10px;
}

.step-icon.spinning {
  border: 1.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.step-icon.check {
  color: var(--success);
  font-size: 12px;
}

.step-icon.fail {
  color: var(--error);
  font-size: 12px;
}

.step-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Collapsible details toggle — for showing verbose info on a per-step basis */
.step-details-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 9px;
  padding: 2px 4px;
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.2s;
}

.step-item:hover .step-details-toggle {
  opacity: 1;
}

.step-details-toggle:hover {
  background: var(--accent-dim);
  color: var(--text-secondary);
}

.step-details {
  display: none;
  margin: 2px 0 4px 20px;
  padding: 6px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 10px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text-secondary);
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.step-details.open {
  display: block;
}

.step-details .detail-label {
  color: var(--accent);
  font-weight: 600;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.step-details .detail-result {
  margin-top: 4px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}


/* ==========================================================================
   VERBOSE TOOL CALLS (opt-in via settings) — full debug output
   ========================================================================== */

.tool-call {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin: 4px 0;
  font-size: 11px;
}

.tool-call-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}

.tool-call-header .icon {
  font-size: 12px;
}

.tool-call-body {
  color: var(--text-secondary);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 10px;
  max-height: 80px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.tool-result {
  background: rgba(76, 175, 80, 0.08);
  border-left: 2px solid var(--success);
  padding: 4px 8px;
  margin-top: 4px;
  border-radius: 0 4px 4px 0;
  font-size: 10px;
  color: var(--text-secondary);
  font-family: monospace;
  max-height: 60px;
  overflow-y: auto;
  white-space: pre-wrap;
}


/* ==========================================================================
   AGENT ACTIVITY BAR
   ========================================================================== */

#agent-activity {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

#agent-activity.hidden {
  display: none;
}

#btn-stop {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(244, 67, 54, 0.12);
  border: 1px solid rgba(244, 67, 54, 0.3);
  color: var(--error);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}

#btn-stop:hover {
  background: rgba(244, 67, 54, 0.22);
}

#btn-stop svg {
  flex-shrink: 0;
}

.activity-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ==========================================================================
   ACT MODE WARNING BANNER
   ========================================================================== */

#act-warning {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: rgba(255, 152, 0, 0.1);
  border-top: 1px solid rgba(255, 152, 0, 0.25);
  font-size: 10px;
  color: var(--warning);
  flex-shrink: 0;
  line-height: 1.3;
}

#act-warning.hidden {
  display: none;
}

#act-warning svg {
  flex-shrink: 0;
}


/* ==========================================================================
   ASK / ACT MODE TOGGLE
   ========================================================================== */

#mode-toggle {
  display: flex;
  gap: 2px;
  margin-bottom: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}

.mode-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.mode-btn:hover {
  color: var(--text-secondary);
}

.mode-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.mode-btn.active.act {
  background: rgba(255, 152, 0, 0.12);
  color: var(--warning);
}


/* Input Area */
#input-area {
  padding: 10px 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 8px 6px 14px;
  transition: border-color 0.2s;
}

#input-wrapper:focus-within {
  border-color: var(--accent);
}

#input-area.act-mode #input-wrapper {
  border-color: rgba(255, 152, 0, 0.3);
}

#input-area.act-mode #input-wrapper:focus-within {
  border-color: var(--warning);
}

#user-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
  outline: none;
}

#user-input::placeholder {
  color: var(--text-muted);
}

#btn-send {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
  flex-shrink: 0;
}

#btn-send:hover {
  background: var(--accent-hover);
}

#btn-send:active {
  transform: scale(0.95);
}

#btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Code blocks */
.message-content code {
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 4px;
  border-radius: 3px;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 11px;
}

.message-content pre {
  background: rgba(0, 0, 0, 0.3);
  padding: 8px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  overflow-x: auto;
  margin: 0;
  white-space: pre;
}

.message-content pre code {
  background: none;
  padding: 0;
  white-space: pre;
}

/* Fenced code block wrapper with header */
.code-block-wrapper {
  margin: 6px 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.4);
  border-bottom: 1px solid var(--border);
  font-size: 10px;
}

.code-lang {
  color: var(--text-muted);
  font-family: 'SF Mono', 'Fira Code', monospace;
  text-transform: lowercase;
}

.code-copy-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10px;
  padding: 1px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
}

.code-copy-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
}

.code-copy-btn.copied {
  color: var(--success);
  border-color: var(--success);
}

/* Message-level copy button */
.msg-copy-btn {
  display: block;
  margin-top: 6px;
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10px;
  padding: 2px 10px;
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: all 0.15s;
}

.message-content:hover .msg-copy-btn {
  opacity: 1;
}

.msg-copy-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
}

.msg-copy-btn.copied {
  color: var(--success);
  border-color: var(--success);
  opacity: 1;
}

/* Continue bar (shown when max steps reached) */
.continue-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(108, 99, 255, 0.08);
  border: 1px solid rgba(108, 99, 255, 0.2);
  border-radius: var(--radius);
  margin-top: 8px;
  animation: fadeIn 0.2s ease;
}

.continue-text {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.continue-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 6px 18px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s;
}

.continue-btn:hover {
  background: var(--accent-hover);
}

/* Error messages */
.message.error .message-content {
  background: rgba(244, 67, 54, 0.1);
  border: 1px solid rgba(244, 67, 54, 0.3);
  color: #ff8a80;
}

/* Clarify card — agent paused to ask user a question */
.clarify-card {
  margin: 8px 0;
  padding: 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius, 6px);
  background: var(--accent-dim, rgba(33, 150, 243, 0.08));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.clarify-question {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}

.clarify-reason {
  font-size: 11px;
  color: var(--text-secondary);
  font-style: italic;
  line-height: 1.4;
}

.clarify-options {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.clarify-option {
  text-align: left;
  padding: 8px 10px;
  background: var(--bg-input, rgba(255,255,255,0.04));
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.clarify-option:hover:not(:disabled) {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.clarify-option:disabled {
  opacity: 0.5;
  cursor: default;
}

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

.clarify-input {
  flex: 1;
  padding: 6px 8px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
}

.clarify-input:disabled {
  opacity: 0.5;
}

.clarify-submit {
  padding: 6px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.clarify-submit:disabled {
  opacity: 0.5;
  cursor: default;
}

.clarify-answered {
  border-color: var(--success, #4caf50);
  background: rgba(76, 175, 80, 0.06);
}

.clarify-your-answer {
  font-size: 12px;
  color: var(--text-secondary);
  font-style: italic;
  padding-top: 4px;
  border-top: 1px dashed var(--border);
}


/* ─── Tab Recorder (v7.4) ─────────────────────────────────────────── */

/* (No toolbar button — the live recording banner below carries its own
   Stop control. Recording is started entirely via the agent's
   `record_tab` tool.) */

/* Live recording banner — sits below the inspection banner. Red bg so the
   user can't miss it, with a pulsing dot. */
#recording-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255, 65, 54, 0.12);
  border-bottom: 1px solid rgba(255, 65, 54, 0.3);
  font-size: 12px;
  color: var(--text-primary, #e8e8e8);
}
#recording-banner.hidden { display: none; }
.recording-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff4136;
  animation: rec-pulse 1.4s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}
.recording-label { flex: 1; font-weight: 600; }
.recording-timer { font-variant-numeric: tabular-nums; font-weight: 600; color: #ff4136; }
.recording-stop {
  background: #ff4136;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.recording-stop:hover { background: #e63b32; }

@media (prefers-reduced-motion: reduce) {
  .recording-dot { animation: none; }
}

/* Post-recording status strip — replaces the live banner once recording stops.
   Carries: "saved to Downloads", "transcribing…", "transcript ready + Summarize". */
.recording-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(108, 99, 255, 0.10);
  border-bottom: 1px solid rgba(108, 99, 255, 0.25);
  font-size: 12px;
  color: var(--text-primary, #e8e8e8);
  transition: opacity 0.2s;
}
.recording-status.hidden { display: none; }
.recording-status span { flex: 1; }
.btn-summarize-recording {
  background: var(--accent, #6c63ff);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.btn-summarize-recording:hover { background: var(--accent2, #5a52d5); }
