/* Alice — mobile-first, follows system light/dark */
:root {
  color-scheme: light dark;
  --bg: #0e0e14;
  --bg-2: #16161f;
  --bg-3: #1e1e2a;
  --border: #2a2a3a;
  --text: #ececf4;
  --text-dim: #9a9ab0;
  --accent: #7C5CFF;
  --accent-soft: rgba(124, 92, 255, 0.18);
  --danger: #ff5c7a;
  --radius: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f6fa;
    --bg-2: #ffffff;
    --bg-3: #ececf2;
    --border: #d8d8e4;
    --text: #17171f;
    --text-dim: #6a6a80;
    --accent: #6a48f2;
    --accent-soft: rgba(106, 72, 242, 0.14);
    --danger: #d92b4e;
  }
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea { font-size: 16px; } /* prevent iOS zoom-on-focus */

/* ---------- Auth ---------- */
.auth-screen {
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px calc(16px + var(--sar)) calc(24px + var(--sab)) calc(16px + var(--sal));
}
.auth-card {
  width: 100%; max-width: 340px; text-align: center;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 20px; padding: 36px 24px;
  display: flex; flex-direction: column; gap: 14px; align-items: center;
}
.auth-logo { width: 72px; height: 72px; border-radius: 18px; }
.auth-card h1 { font-size: 26px; }
.auth-msg { color: var(--text-dim); font-size: 15px; }
.auth-error { color: var(--danger); font-size: 14px; }

.btn {
  border-radius: 12px; padding: 13px 20px; font-size: 16px; font-weight: 600;
  width: 100%;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { filter: brightness(0.85); }
.btn-ghost { color: var(--text-dim); font-size: 14px; width: auto; padding: 8px 10px; }

/* ---------- Layout ---------- */
.app { display: flex; height: 100dvh; overflow: hidden; }

.sidebar {
  width: 280px; flex-shrink: 0;
  background: var(--bg-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding-top: var(--sat); padding-bottom: var(--sab); padding-left: var(--sal);
}
.sidebar-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px;
}
.sidebar-logo { width: 32px; height: 32px; border-radius: 9px; }
.sidebar-title { font-size: 19px; font-weight: 700; }

.channel-list { flex: 1; overflow-y: auto; padding: 4px 10px; }
.channel-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 12px 12px; border-radius: 10px; font-size: 16px;
  color: var(--text-dim); text-align: left;
}
.channel-item.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.channel-hash { color: var(--accent); font-weight: 700; }

.sidebar-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-top: 1px solid var(--border);
}
.me-name { font-size: 14px; color: var(--text-dim); }

.main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  padding-top: var(--sat); padding-bottom: var(--sab); padding-right: var(--sar);
}

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.channel-title { font-size: 17px; font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); flex-shrink: 0;
}
.icon-btn:active { background: var(--bg-3); }
#btn-menu { display: none; }

.conn-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--text-dim); flex-shrink: 0; transition: background 0.3s;
}
.conn-dot.online { background: #4cd97b; }
.conn-dot.offline { background: var(--danger); }

/* ---------- Messages ---------- */
.message-list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px;
}
.msg { display: flex; gap: 10px; padding: 6px 0; }
.msg-avatar {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px; color: #fff;
  overflow: hidden;
}
.msg-avatar img {
  width: 100%; height: 100%; object-fit: cover; border-radius: 10px; display: block;
}
.msg-body { flex: 1; min-width: 0; }
.push-banner {
  margin: 8px 14px 0; padding: 10px 14px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 14px; font-weight: 600; text-align: center;
}
.msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-name { font-weight: 700; font-size: 15px; }
.msg-time { color: var(--text-dim); font-size: 12px; }
.msg-text { font-size: 15.5px; line-height: 1.45; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; }
.msg-text a { color: var(--accent); }
.msg-text code {
  background: var(--bg-3); border-radius: 5px; padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px;
}
.msg-text pre {
  background: var(--bg-3); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; margin: 6px 0; overflow-x: auto; white-space: pre;
}
.msg-text pre code { background: none; padding: 0; }

.msg-actions { margin-top: 4px; display: flex; gap: 8px; align-items: center; }
.reply-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 600;
}
.reply-btn { color: var(--text-dim); font-size: 13px; padding: 4px 6px; border-radius: 8px; }
.reply-btn:active { background: var(--bg-3); }
.reply-last { color: var(--text-dim); font-weight: 400; }

.day-divider {
  text-align: center; color: var(--text-dim); font-size: 12px;
  margin: 14px 0 6px; position: relative;
}

/* attachments */
.msg-attachments { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.att-image { max-width: min(320px, 80%); border-radius: 12px; display: block; cursor: pointer; }
.msg-attachments audio { width: min(320px, 100%); }
.msg-attachments video { max-width: min(320px, 90%); border-radius: 12px; }
.att-chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; font-size: 14px;
  color: var(--text); text-decoration: none; width: fit-content;
}
.att-chip .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-chip .att-size { color: var(--text-dim); font-size: 12px; flex-shrink: 0; }

/* ---------- Composer ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + var(--sab));
  border-top: 1px solid var(--border); background: var(--bg);
}
.thread-panel .composer, .main .composer { padding-bottom: calc(8px + var(--sab)); }
.composer-input {
  flex: 1; resize: none; max-height: 120px;
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--border); border-radius: 18px;
  padding: 10px 14px; line-height: 1.35; outline: none;
}
.composer-input:focus { border-color: var(--accent); }
.send-btn {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent); color: #fff; font-size: 17px;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:disabled { opacity: 0.4; }

.pending-files {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 6px 12px calc(10px + var(--sab)); background: var(--bg);
}
.pending-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-3); border: 1px solid var(--accent);
  border-radius: 999px; padding: 4px 10px; font-size: 13px; max-width: 220px;
}
.pending-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-chip button { color: var(--text-dim); font-size: 15px; }

/* ---------- Thread panel ---------- */
.thread-panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(420px, 100%);
  background: var(--bg); border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(105%); transition: transform 0.25s ease;
  z-index: 30;
  padding-top: var(--sat); padding-bottom: var(--sab); padding-right: var(--sar);
}
.thread-panel.open { transform: translateX(0); }
.thread-root { border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 8px; }

/* ---------- Sidebar as drawer on mobile ---------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 19;
}
@media (max-width: 800px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 20;
    transform: translateX(-105%); transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  #btn-menu { display: flex; }
}
@media (min-width: 801px) {
  .backdrop { display: none !important; }
}

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  padding: calc(10px + var(--sat)) 10px calc(10px + var(--sab));
}
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
