:root {
  --bg:      #0a0a0b;
  --bg2:     #111113;
  --bg3:     #18181c;
  --border:  #222228;
  --yellow:  #ffe033;
  --yellow2: #d4b800;
  --danger:  #ff4466;
  --text:    #e8e8f0;
  --text2:   #888899;
  --text3:   #44444f;
  --mono:    'Space Mono', monospace;
  --sans:    'DM Sans', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 15px; -webkit-font-smoothing: antialiased; }

.hidden { display: none !important; }

/* ── SCREENS ── */
.screen { position: fixed; inset: 0; }
#auth { display: flex; align-items: center; justify-content: center; }
#app  { display: flex; }

/* ── AUTH ── */
.auth-bg { position: absolute; inset: 0; z-index: 0; }
.grid {
  position: absolute; inset: 0;
  background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(ellipse 80% 80% at 50% 50%, black, transparent);
}

.auth-box {
  position: relative; z-index: 1;
  width: 100%; max-width: 380px;
  padding: 0 24px;
  display: flex; flex-direction: column; gap: 20px;
}

.logo { text-align: center; }
.logo-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 64px; height: 64px;
  border: 2px solid var(--yellow); border-radius: 50%;
  font-family: var(--mono); font-size: 30px; font-weight: 700; color: var(--yellow);
  margin-bottom: 14px;
  box-shadow: 0 0 30px rgba(255,224,51,0.15);
  animation: glow 3s ease-in-out infinite;
}
@keyframes glow {
  0%,100% { box-shadow: 0 0 20px rgba(255,224,51,0.15); }
  50%      { box-shadow: 0 0 40px rgba(255,224,51,0.35); }
}
.logo h1 { font-family: var(--mono); font-size: 26px; font-weight: 700; }
.logo p  { font-size: 13px; color: var(--text3); margin-top: 6px; }

.tabs { display: flex; background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 4px; gap: 4px; }
.tab { flex: 1; padding: 9px; background: transparent; border: none; border-radius: 7px; color: var(--text2); font-family: var(--sans); font-size: 14px; font-weight: 500; cursor: pointer; transition: 150ms; }
.tab.active { background: var(--bg3); color: var(--text); }

.tab-pane { display: none; flex-direction: column; gap: 12px; }
.tab-pane.active { display: flex; }

input[type=text], input[type=password] {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; color: var(--text); font-family: var(--sans); font-size: 15px;
  outline: none; width: 100%; transition: 150ms;
}
input:focus { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(255,224,51,0.08); }
input::placeholder { color: var(--text3); }

.btn {
  width: 100%; padding: 13px; background: var(--yellow); color: #111;
  border: none; border-radius: 8px; font-family: var(--sans); font-size: 15px; font-weight: 600;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: 150ms;
}
.btn:hover { background: var(--yellow2); transform: translateY(-1px); }

.error { padding: 12px 14px; background: rgba(255,68,102,0.1); border: 1px solid rgba(255,68,102,0.3); border-radius: 8px; color: var(--danger); font-size: 13px; }

/* ── APP LAYOUT ── */
.sidebar {
  width: 300px; min-width: 300px;
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; height: 100%;
}

.sidebar-top {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg3); border: 1.5px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 14px; color: var(--yellow); flex-shrink: 0;
}
.username { font-family: var(--mono); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 34px; height: 34px; background: transparent; border: none; border-radius: 7px;
  color: var(--text2); cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 14px; transition: 150ms;
}
.icon-btn:hover { background: var(--bg3); color: var(--text); }

.search {
  margin: 10px 12px; width: calc(100% - 24px);
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px;
  color: var(--text); font-family: var(--sans); font-size: 14px; outline: none;
}
.search:focus { border-color: var(--yellow); }

.search-results {
  margin: 0 12px 8px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.search-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; cursor: pointer; transition: 150ms;
}
.search-item:hover { background: var(--bg); }
.search-item .name { font-size: 14px; }

.convos { flex: 1; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.convo {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: 150ms;
}
.convo:hover, .convo.active { background: var(--bg3); }
.convo .info { flex: 1; min-width: 0; }
.convo .name { font-size: 14px; font-weight: 600; }
.convo .preview { font-size: 12px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.convo .time { font-size: 11px; color: var(--text3); font-family: var(--mono); }
.unread-badge {
  background: var(--yellow); color: #111; border-radius: 50%;
  width: 18px; height: 18px; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

.sidebar-footer { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 11px; color: var(--yellow); font-family: var(--mono); display: flex; align-items: center; gap: 6px; }

.empty-convos { padding: 40px 20px; text-align: center; color: var(--text3); font-size: 13px; line-height: 1.6; }

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

.no-chat { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 12px; color: var(--text3); text-align: center; }
.big-q { font-family: var(--mono); font-size: 80px; color: var(--border); line-height: 1; }
.no-chat h2 { font-family: var(--mono); font-size: 20px; color: var(--text2); }
.no-chat p { font-size: 13px; line-height: 1.6; max-width: 280px; }

.active-chat { display: flex; flex-direction: column; height: 100%; }

.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--bg2);
}
.chat-name { font-weight: 600; font-size: 15px; }
.chat-status { font-size: 12px; color: var(--text3); font-family: var(--mono); }

.messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 4px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

.msg { display: flex; flex-direction: column; max-width: 65%; animation: pop 120ms ease; }
@keyframes pop { from { opacity:0; transform: translateY(5px); } to { opacity:1; transform: translateY(0); } }
.msg.mine   { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; align-items: flex-start; }
.bubble {
  padding: 10px 14px; border-radius: 16px;
  font-size: 14px; line-height: 1.5; word-break: break-word;
}
.msg.mine   .bubble { background: var(--yellow); color: #111; border-bottom-right-radius: 4px; }
.msg.theirs .bubble { background: var(--bg3); color: var(--text); border-bottom-left-radius: 4px; }
.msg-time { font-size: 10px; color: var(--text3); font-family: var(--mono); margin-top: 3px; padding: 0 4px; }

.composer {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 16px; border-top: 1px solid var(--border); background: var(--bg2);
}
.composer input { flex: 1; background: var(--bg3); border: 1px solid var(--border); border-radius: 20px; padding: 10px 16px; color: var(--text); font-family: var(--sans); font-size: 14px; outline: none; transition: 150ms; }
.composer input:focus { border-color: var(--yellow); }
.send-btn {
  width: 38px; height: 38px; background: var(--yellow); color: #111;
  border: none; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 14px; transition: 150ms; flex-shrink: 0;
}
.send-btn:hover { background: var(--yellow2); }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── PHASE 2 ADDITIONS ── */
.msg-sender { font-size:11px; color:var(--yellow); font-family:var(--mono); margin-bottom:3px; padding: 0 4px; }

.tone-bar {
  display:flex; align-items:flex-start; gap:10px;
  margin:0 16px 8px; padding:12px 14px;
  background:var(--bg3); border:1px solid var(--border); border-radius:8px;
  font-size:13px; animation:pop 150ms ease;
}
.tone-rewrite {
  background:var(--bg2); border-radius:6px; padding:8px 10px;
  margin-top:6px; font-style:italic; color:var(--text); font-size:13px;
}
.tone-use {
  padding:5px 12px; background:var(--yellow); color:#111;
  border:none; border-radius:5px; font-size:12px; font-weight:600; cursor:pointer;
}
.tone-dismiss, .tone-close {
  padding:5px 12px; background:transparent; color:var(--text3);
  border:1px solid var(--border); border-radius:5px; font-size:12px; cursor:pointer;
}
.tone-close { border:none; font-size:14px; }
.btn-tone.tone-on { color:var(--yellow) !important; }

.modal {
  position:fixed; inset:0; background:rgba(0,0,0,.7);
  display:flex; align-items:center; justify-content:center;
  z-index:100; backdrop-filter:blur(4px);
}
.modal-box {
  background:var(--bg2); border:1px solid var(--border); border-radius:12px;
  padding:24px; width:100%; max-width:400px; display:flex; flex-direction:column; gap:12px;
}
.modal-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:4px; }
.modal-header h3 { font-family:var(--mono); font-size:14px; }

.chips { display:flex; flex-wrap:wrap; gap:6px; min-height:0; }
.chip {
  display:flex; align-items:center; gap:6px;
  background:var(--bg3); border:1px solid var(--border); border-radius:20px;
  padding:4px 10px; font-size:13px;
}
.chip button { background:none; border:none; color:var(--text3); cursor:pointer; font-size:11px; padding:0; }
.chip button:hover { color:var(--danger); }

.chat-header { justify-content:flex-start; }
