:root {
  --bg: #2B2A27;
  --bg-sidebar: #201D18;
  --bg-input: #1F1E1B;
  --bg-deepest: #1A1815;
  --bg-user-msg: #393937;
  --text: #E8E6E3;
  --text-muted: #9A9893;
  --text-dim: #6B6A68;
  --accent: #AE5630;
  --accent-hover: #BD5D3A;
  --accent-deep: #A14A2F;
  --green: #5C8A4D;
  --red: #C0392B;
  --border: rgba(255,255,255,0.08);
  --radius: 16px;
  --ease: cubic-bezier(0.165, 0.85, 0.45, 1);
}

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

body {
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Layout */
.app { display: flex; height: 100%; }

.sidebar {
  width: 280px;
  background: var(--bg-sidebar);
  border-right: 0.5px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header h2 {
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.lock-icon {
  color: var(--green);
  font-size: 16px;
}

.sidebar-actions {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
}

.sidebar-actions button {
  flex: 1;
  padding: 8px 12px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 12px;
  cursor: pointer;
  transition: all 300ms var(--ease);
}

.sidebar-actions button:hover { background: rgba(255,255,255,0.05); }
.sidebar-actions button:active { transform: scale(0.98); }

.sidebar-actions button.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.sidebar-actions button.primary:hover { background: var(--accent-hover); }

.room-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.room-item {
  padding: 12px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 300ms var(--ease);
  margin-bottom: 2px;
}

.room-item:hover { background: rgba(255,255,255,0.04); }
.room-item.active { background: rgba(174,86,48,0.15); }

.room-item-name {
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.room-item-code {
  font-family: monospace;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 0.5px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}

.user-nickname {
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  color: var(--text);
}

.user-id {
  font-family: monospace;
  font-size: 10px;
  color: var(--text-dim);
}

/* Main chat area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  padding: 16px 24px;
  border-bottom: 0.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header h3 {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
}

.chat-header-code {
  font-family: monospace;
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(255,255,255,0.05);
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}

.chat-header-code:hover { background: rgba(255,255,255,0.1); }

.chat-header-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 0.5px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 300ms var(--ease);
  font-size: 14px;
}

.icon-btn:hover { background: rgba(255,255,255,0.05); color: var(--text); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: 75%;
  animation: fadeIn 300ms var(--ease);
}

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

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

.message.received {
  align-self: flex-start;
}

.msg-bubble {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

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

.message.received .msg-bubble {
  background: transparent;
  border-bottom-left-radius: 4px;
}

.msg-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  color: var(--text-dim);
}

.message.sent .msg-meta { justify-content: flex-end; }

.msg-sender {
  font-weight: 600;
  color: var(--text-muted);
}

.msg-encrypt-badge {
  color: var(--green);
}

.typing-indicator {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 0;
  min-height: 20px;
}

/* Chat input */
.chat-input-wrap {
  margin: 12px 24px 20px;
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  box-shadow: 0 0.25rem 1.25rem rgba(0,0,0,0.035);
  transition: border-color 300ms var(--ease);
}

.chat-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(174,86,48,0.12);
}

.chat-input-wrap textarea {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: ui-serif, Georgia, serif;
  font-size: 14px;
  line-height: 1.6;
  padding: 12px 16px 4px;
  resize: none;
  outline: none;
  max-height: 120px;
}

.chat-input-wrap textarea::placeholder { color: var(--text-dim); }

.chat-input-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 8px;
}

.input-left { display: flex; gap: 4px; }

.input-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 300ms var(--ease);
}

.input-btn:hover { background: rgba(255,255,255,0.05); color: var(--text); }

.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 6px 14px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 300ms var(--ease);
}

.send-btn:hover { background: var(--accent-hover); }
.send-btn:active { transform: scale(0.98); }
.send-btn:disabled { opacity: 0.4; cursor: default; }

/* Welcome/Setup screens */
.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px;
  text-align: center;
}

.screen.active { display: flex; }

.screen h1 {
  font-family: 'Inter', sans-serif;
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}

.screen p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
  max-width: 400px;
}

.screen input {
  width: 100%;
  max-width: 320px;
  padding: 12px 16px;
  border: 0.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  outline: none;
  transition: border-color 300ms var(--ease);
  margin-bottom: 12px;
}

.screen input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(174,86,48,0.12);
}

.screen .btn {
  padding: 10px 28px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 300ms var(--ease);
}

.screen .btn:hover { background: var(--accent-hover); }
.screen .btn:active { transform: scale(0.98); }

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-dim);
  gap: 12px;
}

.empty-state svg {
  width: 48px;
  height: 48px;
  opacity: 0.3;
}

.empty-state p {
  font-size: 14px;
  color: var(--text-dim);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 400px;
  width: 90%;
}

.modal h3 {
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  margin-bottom: 12px;
}

.modal input {
  width: 100%;
  padding: 10px 14px;
  border: 0.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  outline: none;
  margin-bottom: 12px;
}

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

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.modal-actions button {
  padding: 8px 16px;
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  cursor: pointer;
  transition: all 300ms var(--ease);
}

.modal-actions .cancel {
  background: transparent;
  border: 0.5px solid var(--border);
  color: var(--text);
}

.modal-actions .confirm {
  background: var(--accent);
  border: none;
  color: #fff;
}

.fingerprint-display {
  font-family: monospace;
  font-size: 12px;
  color: var(--green);
  background: var(--bg-deepest);
  padding: 12px;
  border-radius: 8px;
  word-break: break-all;
  line-height: 1.8;
  margin-bottom: 12px;
}

.ephemeral-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  color: var(--text-muted);
}

.toggle-switch {
  width: 36px;
  height: 20px;
  background: var(--bg-deepest);
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: background 300ms var(--ease);
}

.toggle-switch.on { background: var(--green); }

.toggle-switch::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 300ms var(--ease);
}

.toggle-switch.on::after { transform: translateX(16px); }

.system-msg {
  align-self: center;
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(255,255,255,0.03);
  padding: 4px 12px;
  border-radius: 12px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

/* Mobile */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    z-index: 50;
    transition: left 300ms var(--ease);
  }

  .sidebar.open { left: 0; }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 49;
    display: none;
  }

  .sidebar-overlay.active { display: block; }

  .chat-header { padding: 12px 16px; }
  .messages { padding: 16px; }
  .chat-input-wrap { margin: 8px 12px calc(env(safe-area-inset-bottom, 0px) + 12px); }
  .chat-input-wrap textarea { font-size: 16px; }
  .message { max-width: 85%; }
}
