/* ─── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f17;
  --surface: #1a1a2e;
  --surface-hover: #222240;
  --border: #2a2a4a;
  --accent: #6c63ff;
  --accent-hover: #7b73ff;
  --text: #e8e8f0;
  --text-dim: #8888a8;
  --text-bright: #ffffff;
  --user-bubble: #2d2b55;
  --assistant-bubble: #1e1e36;
  --danger: #ff6b6b;
  --success: #51cf66;
  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

/* ─── Screens ─────────────────────────────────────────────────────────────── */
.screen { display: flex; flex-direction: column; height: 100%; }
.hidden { display: none !important; }

/* ─── Pairing / Denied ────────────────────────────────────────────────────── */
#pairing-screen, #denied-screen {
  align-items: center;
  justify-content: center;
  padding: 2em;
}

.pairing-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5em;
  text-align: center;
  max-width: 440px;
  width: 100%;
}

.pairing-icon { font-size: 3em; margin-bottom: 0.3em; }

.pairing-card h2 {
  color: var(--text-bright);
  margin-bottom: 0.6em;
  font-size: 1.4em;
}

.pairing-card p { color: var(--text-dim); line-height: 1.5; margin-bottom: 1em; }

.code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8em 1.2em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5em;
  margin-bottom: 1em;
}

.code-block code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 1.05em;
  color: var(--accent);
}

.code-block button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1em;
  padding: 0.2em;
  opacity: 0.7;
  transition: opacity 0.2s;
}
.code-block button:hover { opacity: 1; }

.hint { font-size: 0.85em; }

.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 1em auto 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Chat layout ─────────────────────────────────────────────────────────── */
#chat-screen { background: var(--bg); }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8em 1.2em;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

header h1 {
  font-size: 1.1em;
  font-weight: 600;
  color: var(--text-bright);
}

.status {
  font-size: 0.8em;
  padding: 0.25em 0.7em;
  border-radius: 12px;
  font-weight: 500;
}
.status.connected { background: rgba(81, 207, 102, 0.15); color: var(--success); }
.status.disconnected { background: rgba(255, 107, 107, 0.15); color: var(--danger); }
.status.reconnecting { background: rgba(255, 193, 7, 0.15); color: #ffc107; }

main {
  flex: 1;
  overflow-y: auto;
  padding: 1em;
  scroll-behavior: smooth;
}

#messages-inner {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.5em;
}

/* ─── Messages ────────────────────────────────────────────────────────────── */
.message {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

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

.message .bubble {
  padding: 0.7em 1em;
  border-radius: var(--radius);
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  position: relative;
}

.message.user .bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}

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

.message .reply-quote {
  font-size: 0.8em;
  color: var(--text-dim);
  border-left: 2px solid var(--accent);
  padding: 0.2em 0.6em;
  margin-bottom: 0.4em;
  max-height: 2.4em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message .meta {
  font-size: 0.72em;
  color: var(--text-dim);
  margin-top: 0.3em;
  padding: 0 0.3em;
}
.message.user .meta { text-align: right; }

.message .reaction {
  position: absolute;
  bottom: -8px;
  right: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 0.4em;
  font-size: 0.85em;
  line-height: 1.6;
}

.message .edited {
  font-size: 0.75em;
  color: var(--text-dim);
  font-style: italic;
}

.message .file-attachment {
  margin-top: 0.5em;
}

.message .file-attachment img {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.message .file-attachment a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9em;
}
.message .file-attachment a:hover { text-decoration: underline; }

/* ─── Compose ─────────────────────────────────────────────────────────────── */
footer {
  padding: 0.8em 1em;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.compose {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 0.5em;
}

.compose-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5em 0.8em;
  display: flex;
  flex-direction: column;
}

.compose-input textarea {
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.5;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  background: var(--surface-hover);
  border-radius: 6px;
  padding: 0.2em 0.5em;
  font-size: 0.85em;
  color: var(--accent);
  margin-top: 0.3em;
}

.file-chip .remove {
  cursor: pointer;
  opacity: 0.7;
  font-size: 1.1em;
}
.file-chip .remove:hover { opacity: 1; }

#attach-btn, #send-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.2em;
  padding: 0.4em;
  border-radius: 8px;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
#attach-btn:hover { color: var(--text); background: var(--surface-hover); }
#send-btn { color: var(--accent); }
#send-btn:hover { color: var(--accent-hover); background: var(--surface-hover); }

/* ─── Permission modal ────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1em;
}

.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5em;
  max-width: 500px;
  width: 100%;
}

.modal-content h3 { color: var(--text-bright); margin-bottom: 0.8em; }

.permission-tool {
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--accent);
  margin-bottom: 0.5em;
}

.permission-desc { color: var(--text-dim); margin-bottom: 0.8em; }

.permission-input {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 0.8em;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.85em;
  max-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-dim);
}

details { margin-bottom: 1em; }
details summary {
  cursor: pointer;
  color: var(--text-dim);
  font-size: 0.9em;
}

.modal-actions {
  display: flex;
  gap: 0.8em;
  justify-content: flex-end;
}

.btn {
  padding: 0.5em 1.5em;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-allow { background: var(--success); color: #000; }
.btn-allow:hover { filter: brightness(1.1); }
.btn-deny { background: var(--danger); color: #fff; }
.btn-deny:hover { filter: brightness(1.1); }

/* ─── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .message { max-width: 90%; }
  header { padding: 0.6em 0.8em; }
  footer { padding: 0.5em; }
}
