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

:root {
  --bg: #0a0a0a;
  --bg-secondary: #111111;
  --border: rgba(255,255,255,0.08);
  --text: #ffffff;
  --text-muted: #666666;
  --text-dim: #444444;
  --input-bg: #1a1a1a;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%; width: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', 'Inter', sans-serif;
  font-size: 16px; overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ─── Login ──────────────────────────────────────── */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100%; background: var(--bg);
}
.login-card {
  text-align: center; padding: 40px 32px; width: 100%; max-width: 340px;
}
.login-logo {
  width: 72px; height: 72px; border-radius: 18px;
  margin: 0 auto 24px; display: block;
}
.login-card h1 {
  font-size: 24px; font-weight: 400; margin-bottom: 28px; color: var(--text);
}
.login-card h1 strong {
  font-weight: 700;
}
.login-title-thin {
  font-weight: 300; color: var(--text-muted);
}
.login-error {
  color: #ff4444; font-size: 13px; margin-bottom: 12px; min-height: 18px;
}
.login-card input {
  width: 100%; padding: 14px 16px; background: var(--input-bg);
  border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); font-size: 16px; outline: none;
  margin-bottom: 12px;
}
.login-card input:focus { border-color: #333; }
.login-card button {
  width: 100%; padding: 14px; background: #fff; color: #000;
  border: none; border-radius: 12px; font-size: 16px;
  font-weight: 600; cursor: pointer;
}
.login-card button:active { opacity: 0.8; }

/* ─── Chat screen ────────────────────────────────── */
#chat-screen {
  display: flex; flex-direction: column; height: 100%;
}

/* ─── Header ─────────────────────────────────────── */
#header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
}
#header-left { display: flex; align-items: center; gap: 12px; }
.header-avatar {
  width: 38px; height: 38px; border-radius: 10px;
}
.header-info { display: flex; flex-direction: column; gap: 1px; }
.header-title { font-size: 17px; font-weight: 400; }
.header-title strong { font-weight: 700; }
.header-title-thin { font-weight: 300; color: var(--text-muted); }
#header-status { font-size: 12px; color: var(--text-muted); }
#header-right { display: flex; gap: 8px; }
#header-right button {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 6px; border-radius: 8px;
}
#header-right button:hover { color: var(--text); background: var(--input-bg); }

/* ─── Messages ───────────────────────────────────── */
#messages {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 4px;
  -webkit-overflow-scrolling: touch;
  max-width: 800px; margin: 0 auto; width: 100%;
}

.msg {
  padding: 12px 16px;
  font-size: 15px; line-height: 1.5;
  word-break: break-word; white-space: pre-wrap;
}
.msg-user {
  background: #1a1a1a; border-radius: 12px;
  margin-top: 16px;
}
.msg-agent {
  color: #ccc;
}

/* Status badges */
.msg-badge {
  display: inline-block; padding: 2px 10px;
  border-radius: 999px; font-size: 13px;
  font-weight: 600; margin-bottom: 6px;
}
.msg-badge.done { background: #1a1a1a; color: #888; }
.msg-badge.sent { background: #1a1a1a; color: #888; }
.msg-badge.working { background: #1a1a1a; color: #666; }
.msg-badge.error { background: #1a1a1a; color: #888; }

/* Chat link */
.msg-link {
  display: block; margin-top: 8px; padding: 8px 12px;
  background: #111; border: 1px solid var(--border);
  border-radius: 10px; color: #888;
  font-size: 14px; text-decoration: none;
}
.msg-link:active { background: #1a1a1a; color: #fff; }

/* Typing indicator */
.typing-indicator {
  padding: 12px 16px;
}
.typing-dots { display: flex; gap: 4px; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.4s infinite both;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

/* Date divider */
.date-divider {
  align-self: center; padding: 6px 16px;
  background: #161616; border-radius: 999px;
  font-size: 13px; color: var(--text-dim);
  margin: 8px 0;
}

/* ─── Input area — exact Bridge styling ──────────── */
#input-area {
  padding: 12px 16px;
  padding-bottom: calc(28px + var(--safe-bottom));
  background: #000000;
}
.input-bar-inner {
  display: flex; gap: 8px; align-items: flex-end;
  max-width: 800px; margin: 0 auto;
}
.input-bar-row {
  flex: 1; display: flex; align-items: flex-end;
  background: var(--input-bg); border: 1px solid #444444;
  border-radius: 24px; padding: 4px 4px 4px 12px;
  gap: 2px;
}
.input-bar-row textarea {
  flex: 1; padding: 8px 4px; background: transparent;
  border: none; color: var(--text);
  font-size: 16px; font-family: inherit; resize: none; outline: none;
  max-height: 120px; line-height: 1.4;
}
.input-bar-action {
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: #ffffff; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.input-bar-action svg { stroke: #000000; }
.input-bar-action.recording { background: #ff3333; }
.input-bar-action.recording svg { stroke: #ffffff; }
.input-icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: transparent; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.input-icon-btn:hover svg { stroke: #ffffff !important; }
.attach-wrapper { position: relative; }
.attach-menu {
  display: none; position: absolute; bottom: 44px; right: 0;
  background: #1a1a1a; border: 1px solid #333; border-radius: 10px;
  overflow: hidden; min-width: 160px; z-index: 100;
}
.attach-menu.open { display: block; }
.attach-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 12px 16px; border: none; background: none; color: #ccc;
  font-size: 14px; cursor: pointer; text-align: left;
}
.attach-menu button:hover { background: #222; }
.attach-menu button + button { border-top: 1px solid #2a2a2a; }
#abort-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: #333333; color: #ffffff; font-size: 20px;
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}

/* Image preview */
#image-preview {
  background: #000;
}
#image-preview img {
  width: 60px; height: 60px; object-fit: cover; border-radius: 8px;
}
.preview-thumb {
  position: relative; display: inline-block;
}
.preview-thumb button {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: #333; color: #fff; border: none;
  font-size: 12px; cursor: pointer; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}

/* ─── Markdown in messages ───────────────────────── */
.msg-agent p { margin: 0 0 8px; }
.msg-agent p:last-child { margin-bottom: 0; }
.msg-agent code {
  background: rgba(255,255,255,0.08); padding: 2px 6px;
  border-radius: 4px; font-size: 14px;
  font-family: 'SF Mono', 'Fira Code', monospace;
}
.msg-agent pre {
  background: rgba(0,0,0,0.4); padding: 10px;
  border-radius: 8px; overflow-x: auto;
  margin: 8px 0; font-size: 13px;
}
.msg-agent a { color: #888; }
.msg-agent a:hover { color: #fff; }
.msg-agent ul, .msg-agent ol { padding-left: 20px; margin: 4px 0; }
.msg-agent strong { color: #fff; }

/* Activity indicator */
.activity-indicator {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; color: var(--text-muted);
  font-size: 13px;
}
.activity-spinner {
  width: 14px; height: 14px; border: 2px solid transparent;
  border-top-color: #ffffff; border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
