:root {
  --bg: #0e1116;
  --bg-elevated: #161a21;
  --bg-elevated-2: #1d222b;
  --border: #2a303c;
  --text: #e8eaed;
  --text-dim: #9aa3b2;
  --text-faint: #666f7e;
  --accent: #6366f1;
  --accent-hover: #7477f3;
  --accent-soft: #6366f11f;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ---------- buttons ---------- */
.btn-primary, .btn-secondary, .btn-danger {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-elevated-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #262c37; }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: #ef44441a; }
.link-btn { background: none; border: none; color: var(--accent); font-size: 13px; padding: 0; }
.icon-btn {
  background: none; border: none; color: var(--text-dim); font-size: 16px;
  width: 34px; height: 34px; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; transition: background 0.15s;
}
.icon-btn:hover { background: var(--bg-elevated-2); color: var(--text); }

/* ---------- toasts ---------- */
.toast-root { position: fixed; top: 16px; right: 16px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-elevated-2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; max-width: 320px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4); animation: toast-in 0.2s ease-out;
}
.toast.error { border-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- auth ---------- */
.auth-screen {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, #1b1f2a, var(--bg) 60%);
  padding: 24px; gap: 22px;
  position: relative; overflow: hidden;
}
/* The "converge" node graph — every device/thread converging to one hub,
   drawn instead of a stock gradient/pattern. Kept faint and slow so it
   reads as ambiance, not decoration competing with the form. */
.auth-bg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; }
.auth-bg-lines line { stroke: var(--accent); stroke-width: 1; opacity: 0.16; }
.auth-bg-nodes circle { fill: var(--accent); opacity: 0.35; }
.auth-bg-hub { fill: var(--accent); opacity: 0.5; animation: hub-pulse 3.5s ease-in-out infinite; }
.auth-bg-pulse { fill: #fff; opacity: 0; }
@keyframes hub-pulse {
  0%, 100% { r: 7; opacity: 0.5; }
  50% { r: 10; opacity: 0.85; }
}
@media (prefers-reduced-motion: reduce) {
  .auth-bg-hub { animation: none !important; }
  .auth-bg-pulses { display: none; }
}

.auth-card, .auth-features-strip { position: relative; z-index: 1; }
.auth-card { width: 100%; max-width: 400px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 16px; padding: 32px; }
.auth-features-strip {
  width: 100%; max-width: 400px; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 20px;
}
.auth-feature-chip { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-faint); }
.auth-feature-chip span { font-size: 14px; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.brand-mark { width: 44px; height: 44px; border-radius: 12px; background: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px; }
.brand h1 { margin: 0; font-size: 20px; }
.brand-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--text-dim); }
.auth-tabs { display: flex; gap: 4px; background: var(--bg-elevated-2); border-radius: var(--radius-sm); padding: 4px; margin-bottom: 20px; }
.auth-tab { flex: 1; background: none; border: none; color: var(--text-dim); padding: 8px; border-radius: 6px; font-weight: 600; font-size: 13px; }
.auth-tab.active { background: var(--accent); color: white; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { font-size: 12.5px; color: var(--text-dim); display: flex; flex-direction: column; gap: 6px; }
.auth-form input {
  background: var(--bg-elevated-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px;
}
.auth-form input:focus { outline: none; border-color: var(--accent); }
.auth-forgot-link { align-self: flex-start; margin-top: -6px; }
.auth-error { color: var(--danger); font-size: 13px; min-height: 16px; margin: 0; }
.auth-footnote { margin: 20px 0 0; font-size: 12px; color: var(--text-faint); line-height: 1.5; text-align: center; }
.verify-panel-icon { font-size: 32px; text-align: center; }

/* ---------- app layout ---------- */
.app-screen { display: flex; height: 100vh; }
.sidebar { width: 320px; flex-shrink: 0; background: var(--bg-elevated); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.me { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.sidebar-actions { display: flex; gap: 2px; }
.new-chat-row { display: flex; gap: 8px; padding: 12px 16px; }
.new-chat-row .btn-secondary { flex: 1; font-size: 12.5px; padding: 8px; }

.conversation-list { flex: 1; overflow-y: auto; }
.conversation-item { display: flex; align-items: center; gap: 10px; padding: 10px 16px; cursor: pointer; border-left: 3px solid transparent; }
.conversation-item:hover { background: var(--bg-elevated-2); }
.conversation-item.active { background: var(--accent-soft); border-left-color: var(--accent); }
.conversation-item-body { flex: 1; min-width: 0; }
.conversation-item-title { font-size: 14px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conversation-item-title time { font-weight: 400; font-size: 11px; color: var(--text-faint); }
.conversation-item-preview { font-size: 12.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.unread-badge { background: var(--accent); color: white; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.empty-list-hint { padding: 24px 16px; color: var(--text-faint); font-size: 13px; text-align: center; }

/* ---------- chat pane ---------- */
.chat-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-faint); }
.empty-state-emoji { font-size: 40px; margin-bottom: 8px; }
.empty-state h2 { margin: 0 0 4px; color: var(--text-dim); font-size: 17px; }

.conversation-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.conversation-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.conversation-header h2 { margin: 0; font-size: 15px; }
.conversation-subtitle { margin: 2px 0 0; font-size: 12px; color: var(--text-faint); }
.conversation-header-actions { display: flex; align-items: center; gap: 10px; }
.translate-toggle { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-dim); }
.lang-select { background: var(--bg-elevated-2); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 6px 8px; font-size: 12.5px; }
.lang-select.full { width: 100%; margin-top: 6px; padding: 10px; }

.summary-panel { background: var(--bg-elevated); border-bottom: 1px solid var(--border); padding: 14px 20px; max-height: 260px; overflow-y: auto; }
.summary-panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 13px; }
.summary-content { font-size: 13.5px; line-height: 1.6; color: var(--text-dim); white-space: pre-wrap; }
.summary-content strong { color: var(--text); }

.message-list { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; }

.message-row { display: flex; gap: 10px; max-width: 640px; margin: 6px 0; }
.message-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.message-row .avatar { margin-top: 2px; }
.message-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.message-row.mine .message-body { align-items: flex-end; }
.message-meta { font-size: 11.5px; color: var(--text-faint); display: flex; gap: 6px; }
.bubble { background: var(--bg-elevated-2); border: 1px solid var(--border); border-radius: 14px; padding: 9px 13px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.message-row.mine .bubble { background: var(--accent); border-color: var(--accent); color: white; }
.message-row.system { align-self: center; max-width: 80%; }
.message-row.system .bubble { background: transparent; border: 1px dashed var(--border); color: var(--text-dim); font-size: 12.5px; }
.translation-line { font-size: 12.5px; color: var(--text-dim); font-style: italic; padding: 0 4px; cursor: pointer; }
.translation-line:hover { color: var(--text); }

.voice-note { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.voice-note button { background: none; border: none; color: inherit; font-size: 18px; }
.voice-note-wave { flex: 1; height: 22px; background: repeating-linear-gradient(90deg, currentColor 0 2px, transparent 2px 5px); opacity: 0.35; border-radius: 4px; }
.voice-note-duration { font-size: 11.5px; opacity: 0.85; }
.voice-transcript { font-size: 12.5px; opacity: 0.9; margin-top: 4px; border-top: 1px solid rgba(255,255,255,0.15); padding-top: 4px; }

.meeting-card { border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; max-width: 340px; margin: 8px 0; align-self: center; }
.meeting-card-title { font-weight: 700; font-size: 13.5px; display: flex; align-items: center; gap: 6px; }
.meeting-card-sub { font-size: 12px; color: var(--text-dim); margin: 4px 0 10px; }
.meeting-card-actions { display: flex; gap: 8px; }
.meeting-card-actions button { flex: 1; font-size: 12px; padding: 7px 10px; }
.meeting-card.status-confirmed { border-color: var(--success); background: #22c55e14; }
.meeting-card.status-dismissed { opacity: 0.5; }

.composer { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); position: relative; }
.composer-input, #composer-input { flex: 1; background: var(--bg-elevated-2); border: 1px solid var(--border); color: var(--text); border-radius: 999px; padding: 11px 16px; font-size: 14px; }
.composer-input:focus, #composer-input:focus { outline: none; border-color: var(--accent); }
.record-btn.recording { color: var(--danger); }
.recording-indicator { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--danger); flex: 1; background: var(--bg-elevated-2); border-radius: 999px; padding: 9px 16px; }
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
.send-btn { border-radius: 999px; padding: 10px 20px; }

/* ---------- modals ---------- */
.modal-root { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.modal { position: relative; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 14px; padding: 24px; width: 100%; max-width: 380px; max-height: 80vh; overflow-y: auto; }
.modal.modal-wide { max-width: 480px; }
.modal h3 { margin: 0 0 6px; font-size: 16px; }
.modal-hint { font-size: 12.5px; color: var(--text-dim); margin: 0 0 14px; line-height: 1.5; }
.modal input, .modal .lang-select.full { width: 100%; background: var(--bg-elevated-2); border: 1px solid var(--border); color: var(--text); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; margin-bottom: 8px; }
.modal-label { font-size: 12.5px; color: var(--text-dim); display: block; margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.suggestions { display: flex; flex-direction: column; gap: 4px; max-height: 140px; overflow-y: auto; margin-bottom: 8px; }
.suggestion-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.suggestion-item:hover { background: var(--bg-elevated-2); }

.devices-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.device-item { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: var(--bg-elevated-2); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.device-item.current { border-color: var(--accent); }
.device-item-name { font-size: 13.5px; font-weight: 600; }
.device-item-meta { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; }
.device-item button { font-size: 11.5px; padding: 5px 10px; }

.search-results { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.search-result-item { background: var(--bg-elevated-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; }
.search-result-item:hover { border-color: var(--accent); }
.search-result-meta { font-size: 11.5px; color: var(--text-faint); margin-bottom: 3px; }
.search-result-text { font-size: 13px; }

@media (max-width: 760px) {
  .sidebar { width: 100%; position: absolute; inset: 0; z-index: 5; }
  .app-screen.has-active .sidebar { display: none; }
  .chat-pane { width: 100%; }
}
