/* ABHS Messenger — light theme.
   Tokens first, then components in page order. Layout: the sidebar sits beside the
   open thread; at ≤760px it becomes a two-view flow driven by .shell[data-view]. */

:root {
  color-scheme: light;
  --bg: #eef2f4;
  --surface: #ffffff;
  --surface-2: #f6f8f9;
  --surface-3: #eceff2;
  --hover: #e9eef1;
  --text: #121b22;
  --text-2: #36414b;
  --text-muted: #69747f;
  --border: #e1e6ea;
  --border-strong: #ccd4da;
  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-soft: #dff2ee;
  --accent-text: #0b5c55;
  --on-accent: #ffffff;
  --bubble: #f0f3f5;
  --danger: #d0362b;
  --danger-hover: #b32b21;
  --danger-soft: #fdecea;
  --voice: #23a55a;
  --voice-hover: #1c8d4c;
  --voice-soft: #e3f6ea;
  --radius-lg: 18px;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 18px 44px -22px rgba(16, 24, 40, .3);
  --font: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
img { display: block; max-width: 100%; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon { width: 20px; height: 20px; flex: none; }

#app { height: 100%; height: 100dvh; display: flex; flex-direction: column; }
.screen { flex: 1; min-height: 0; }

/* ---------- Boot ---------- */
.boot { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 24px; color: var(--text-muted); text-align: center; }
.spinner {
  width: 18px; height: 18px; flex: none; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 700; letter-spacing: -.015em; }
.brand-mark {
  position: relative; width: 28px; height: 28px; flex: none; border-radius: 9px;
  background: linear-gradient(140deg, #2dd4bf, var(--accent) 70%);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .12);
}
.brand-mark::after {
  content: ""; position: absolute; left: 7px; right: 7px; top: 8px; bottom: 9px;
  border-radius: 5px 5px 5px 2px; background: #fff;
}

/* ---------- Access code & sign-in ---------- */
.center {
  display: flex; padding: 32px 16px; overflow-y: auto;
  background: radial-gradient(1100px 520px at 50% -12%, #d4efe9 0%, rgba(212, 239, 233, 0) 65%), var(--bg);
}
.center > .card { margin: auto; }   /* margin:auto (not align-items) so a tall card can still scroll to its top */
.card {
  width: 100%; max-width: 384px; padding: 30px 26px 26px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow);
}
.card .brand { margin-bottom: 24px; }
.card-title { margin: 0 0 4px; font-size: 23px; font-weight: 700; letter-spacing: -.02em; }
.card-sub { margin-bottom: 22px; color: var(--text-muted); }
.card-foot { margin-top: 14px; text-align: center; font-size: 14px; }
.card-note { margin-top: 16px; font-size: 13px; color: var(--text-muted); }

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.input {
  width: 100%; padding: 10px 12px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: #9aa4ad; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { min-height: 20px; margin-bottom: 10px; font-size: 13.5px; color: var(--danger); }
.form-error:empty { min-height: 0; margin-bottom: 0; }
.form-error.is-success { color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border: 1px solid transparent; border-radius: var(--radius-sm);
  font-weight: 600; transition: background-color .15s, border-color .15s, transform .1s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn .icon { width: 17px; height: 17px; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-success { background: var(--voice); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--voice-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn:disabled { opacity: .55; }
.btn-block { width: 100%; margin-top: 4px; }
.btn-sm { padding: 6px 12px; font-size: 13.5px; }
.link { padding: 0; background: none; border: none; color: var(--accent); font-weight: 600; }
.link:hover { text-decoration: underline; }

.tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  margin-bottom: 22px; padding: 4px; background: var(--surface-3); border-radius: 11px;
}
.tab { padding: 8px; border: none; border-radius: 8px; background: none; font-weight: 600; color: var(--text-muted); transition: background-color .15s, color .15s; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Shell & sidebar ---------- */
.shell { display: flex; background: var(--surface); }
.sidebar {
  width: 304px; flex: none; min-height: 0; display: flex; flex-direction: column;
  background: var(--surface-2); border-right: 1px solid var(--border);
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 12px 12px 18px; }
.search { position: relative; margin: 0 12px 4px; }
.search-icon { position: absolute; left: 11px; top: 50%; width: 17px; height: 17px; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search-input { padding: 8px 12px 8px 36px; background: var(--surface); border-color: var(--border); font-size: 14px; }
.sidebar-body { flex: 1; min-height: 0; overflow-y: auto; padding: 2px 8px 12px; }
.section-label {
  margin: 16px 10px 6px; font-size: 11.5px; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase; color: var(--text-muted);
}

.icon-btn {
  width: 36px; height: 36px; flex: none; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--radius-sm); background: none; color: var(--text-muted);
  transition: background-color .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--danger); background: var(--danger-soft); }
.icon-btn-danger { color: var(--danger); }
.icon-btn-danger:hover { background: var(--danger-soft); color: var(--danger-hover); }

.conv-list { margin: 0; padding: 0; list-style: none; }
.conv {
  width: 100%; display: flex; align-items: center; gap: 11px;
  padding: 6px 10px; border: none; border-radius: 10px;
  background: none; text-align: left; color: var(--text-2); font-weight: 500;
  transition: background-color .12s;
}
.conv:hover { background: var(--hover); color: var(--text); }
.conv.is-active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.conv-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-voice { display: inline-flex; color: var(--voice); }
.conv-voice .icon { width: 16px; height: 16px; }
.list-empty { padding: 6px 10px; font-size: 13.5px; color: var(--text-muted); }
.conv-skeleton {
  height: 44px; margin: 2px 0; border-radius: 10px;
  background: linear-gradient(90deg, var(--surface-3) 0%, #f7f9fa 50%, var(--surface-3) 100%) 0 0 / 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.room-badge {
  width: 32px; height: 32px; flex: none; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-3); color: var(--text-muted);
}
.room-badge .icon { width: 16px; height: 16px; }
.conv.is-active .room-badge { background: var(--surface); color: var(--accent); }

/* Who's in each room's voice channel, nested under the room (Discord-style). */
.voice-members { margin: 0 0 4px 38px; padding: 0; list-style: none; }
.voice-member { display: flex; align-items: center; gap: 8px; padding: 3px 8px; border-radius: 8px; font-size: 13.5px; color: var(--text-2); }
.voice-member-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-member-state { width: 15px; height: 15px; color: var(--danger); }

/* ---------- Avatars ---------- */
.avatar {
  width: 32px; height: 32px; flex: none; border-radius: 50%; object-fit: cover;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; font-weight: 700; user-select: none;
  transition: box-shadow .12s;
}
.avatar-xs { width: 22px; height: 22px; font-size: 10px; }
.avatar-sm { width: 28px; height: 28px; font-size: 12px; }
.avatar-lg { width: 44px; height: 44px; font-size: 17px; }
.avatar-xl { width: 88px; height: 88px; font-size: 34px; }
/* Speaking ring, set by voice/speaking.js on [data-voice-uid] elements. */
.is-speaking .avatar, .avatar.is-speaking { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--voice); }

/* ---------- Voice panel ---------- */
.voice-panel {
  display: flex; align-items: center; gap: 8px; margin: 0 8px; padding: 10px 6px 10px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.voice-panel-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; }
.voice-panel-text { min-width: 0; }
.voice-panel-status { font-size: 13.5px; font-weight: 700; color: var(--text-muted); }
.voice-panel.is-connected .voice-panel-status { color: var(--voice); }
.voice-panel-channel {
  display: block; max-width: 100%; padding: 0; border: none; background: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12.5px; color: var(--text-muted); text-align: left;
}
.voice-panel-channel:hover { color: var(--text); text-decoration: underline; }
.voice-panel-actions { display: flex; }
.voice-panel-actions .icon-btn { width: 32px; height: 32px; }
.voice-signal { display: inline-flex; align-items: flex-end; gap: 2px; height: 16px; flex: none; }
.voice-signal i { width: 3px; border-radius: 2px; background: var(--border-strong); }
.voice-signal i:nth-child(1) { height: 6px; }
.voice-signal i:nth-child(2) { height: 11px; }
.voice-signal i:nth-child(3) { height: 16px; }
.voice-panel.is-connected .voice-signal i { background: var(--voice); }

/* ---------- Sidebar footer ---------- */
.sidebar-foot { display: flex; align-items: center; gap: 6px; padding: 10px 10px 10px 8px; }
.me {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  padding: 6px; border: none; border-radius: var(--radius-sm); background: none; text-align: left;
}
.me:hover { background: var(--hover); }
.me-avatar { display: inline-flex; }
.me-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.me-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.me-hint { font-size: 12px; color: var(--text-muted); }

/* ---------- Conversation ---------- */
.conversation { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--surface); }
.empty-state { margin: auto; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 6px; color: var(--text-muted); text-align: center; }
.empty-icon {
  width: 64px; height: 64px; margin-bottom: 8px; border-radius: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
}
.empty-icon .icon { width: 28px; height: 28px; }
.empty-title { font-size: 18px; font-weight: 700; color: var(--text); }

.voice-bar .icon-btn { width: 32px; height: 32px; color: #17633a; }
.voice-bar .icon-btn:hover { background: rgba(35, 165, 90, .14); color: #0f4a2a; }
.voice-bar .icon-btn[aria-pressed="true"] { color: var(--danger); background: var(--danger-soft); }

.thread { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px 12px 20px; border-bottom: 1px solid var(--border); }
.thread-icon { display: inline-flex; }
.thread-titles { flex: 1; min-width: 0; }
.thread-title { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 700; }
.thread-sub { font-size: 12.5px; color: var(--text-muted); }
.thread-actions { display: flex; gap: 2px; }
.back { display: none; }

.voice-bar {
  display: flex; align-items: center; gap: 12px; padding: 8px 16px 8px 20px;
  background: var(--voice-soft); border-bottom: 1px solid #cdebd8; color: #17633a;
}
.voice-bar-icon { width: 18px; height: 18px; }
.voice-bar-people { display: flex; }
.voice-face { display: inline-flex; margin-right: -6px; border-radius: 50%; }
.voice-face .avatar { box-shadow: 0 0 0 2px var(--voice-soft); }
.voice-face.is-speaking .avatar { box-shadow: 0 0 0 2px var(--voice-soft), 0 0 0 4px var(--voice); }
.voice-bar-text { flex: 1; min-width: 0; margin-left: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; font-weight: 600; }

.messages { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; padding: 8px 20px 12px; }
.day { display: flex; align-items: center; gap: 12px; margin: 18px 0 6px; font-size: 12px; font-weight: 600; color: var(--text-muted); }
.day::before, .day::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.msg { display: flex; align-items: flex-end; gap: 8px; max-width: min(76%, 640px); margin-top: 12px; }
.msg-grouped { margin-top: 2px; }
.msg-grouped > .avatar { visibility: hidden; }
.msg-mine { align-self: flex-end; }
.msg-body { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.msg-mine .msg-body { align-items: flex-end; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; padding: 0 4px; font-size: 12px; color: var(--text-muted); }
.msg-author { font-weight: 600; color: var(--text); }
.bubble {
  padding: 8px 12px; border-radius: 16px 16px 16px 5px;
  background: var(--bubble); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-mine .bubble { border-radius: 16px 16px 5px 16px; background: var(--accent); color: var(--on-accent); }
.msg-photo {
  display: block; width: min(280px, 62vw); max-height: 360px; padding: 0; overflow: hidden;
  border: none; border-radius: 14px; cursor: zoom-in;
  background: linear-gradient(90deg, var(--surface-3) 0%, #f7f9fa 50%, var(--surface-3) 100%) 0 0 / 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.msg-photo img { width: 100%; height: 100%; object-fit: cover; }
.msg-photo:disabled { cursor: default; }
.msg-photo:has(img), .msg-photo.is-missing { animation: none; background: var(--surface-3); }
.msg-photo.is-missing { display: flex; align-items: center; justify-content: center; font-size: 13px; color: var(--text-muted); }
.thread-empty { margin: auto; max-width: 300px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; color: var(--text-muted); }
.thread-empty .room-badge { width: 56px; height: 56px; border-radius: 18px; margin-bottom: 6px; }
.thread-empty .room-badge .icon { width: 26px; height: 26px; }
.thread-empty .avatar { margin-bottom: 6px; }
.thread-empty-title { font-size: 18px; font-weight: 700; color: var(--text); }

.attachment { display: flex; align-items: center; gap: 12px; margin: 0 16px; padding: 8px 8px 8px 10px; border: 1px solid var(--border); border-bottom: none; border-radius: var(--radius) var(--radius) 0 0; background: var(--surface-2); }
.attachment-thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; }
.attachment-label { flex: 1; font-size: 13.5px; font-weight: 600; color: var(--text-2); }

.composer {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 12px 16px max(12px, env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1; min-width: 0; max-height: 140px; resize: none;
  padding: 9px 14px; line-height: 1.45;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px;
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}
.composer textarea:focus { outline: none; background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer .icon-btn { width: 40px; height: 40px; border-radius: 50%; }
.send {
  width: 40px; height: 40px; flex: none; border: none; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--on-accent); transition: background-color .15s, opacity .15s;
}
.send .icon { width: 18px; height: 18px; }
.send:hover:not(:disabled) { background: var(--accent-hover); }
.send:disabled { opacity: .35; }

.drop-hint {
  position: absolute; inset: 10px; z-index: 2;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  border: 2px dashed var(--accent); border-radius: var(--radius-lg);
  background: rgba(223, 242, 238, .9); color: var(--accent-text); font-weight: 700; pointer-events: none;
}

/* ---------- Dialogs ---------- */
.dialog {
  width: min(420px, calc(100vw - 32px)); padding: 0; border: none; border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text); box-shadow: 0 28px 70px -18px rgba(16, 24, 40, .45);
}
.dialog::backdrop { background: rgba(14, 22, 28, .45); backdrop-filter: blur(2px); }
.dialog[open] { animation: pop .18s var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.dialog-body { padding: 22px 22px 20px; }
.dialog-title { margin: 0 0 18px; font-size: 18px; font-weight: 700; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.profile-photo { display: flex; align-items: center; gap: 18px; margin-bottom: 18px; }
.profile-photo-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }

.lightbox {
  width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0; padding: 0;
  border: none; background: rgba(8, 12, 15, .92);
}
.lightbox[open] { display: flex; align-items: center; justify-content: center; }
.lightbox::backdrop { background: transparent; }
.lightbox-img { max-width: calc(100vw - 32px); max-height: calc(100vh - 96px); border-radius: 10px; object-fit: contain; }
.lightbox-close { position: absolute; top: 16px; right: 16px; color: #fff; background: rgba(255, 255, 255, .14); }
.lightbox-close:hover { color: #fff; background: rgba(255, 255, 255, .26); }

/* ---------- Incoming call ---------- */
.ring {
  position: fixed; top: max(16px, env(safe-area-inset-top, 0px)); right: 16px; z-index: 40;
  width: min(360px, calc(100vw - 32px)); display: flex; align-items: center; gap: 14px; padding: 14px 14px 14px 16px;
  background: #14201f; color: #fff; border-radius: var(--radius-lg); box-shadow: 0 24px 60px -16px rgba(0, 0, 0, .5);
  animation: slide-in .25s var(--ease);
}
@keyframes slide-in { from { opacity: 0; transform: translateY(-12px); } }
.ring-avatar { display: inline-flex; border-radius: 50%; animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { from { box-shadow: 0 0 0 0 rgba(35, 165, 90, .6); } to { box-shadow: 0 0 0 16px rgba(35, 165, 90, 0); } }
.ring-text { flex: 1; min-width: 0; }
.ring-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 16px; font-weight: 700; }
.ring-sub { font-size: 13px; color: rgba(255, 255, 255, .7); }
.ring-actions { display: flex; gap: 10px; }
.round-btn {
  width: 44px; height: 44px; padding: 0; border: none; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; color: #fff;
  transition: background-color .15s, transform .1s;
}
.round-btn:active { transform: scale(.95); }
.round-btn-success { background: var(--voice); }
.round-btn-success:hover { background: var(--voice-hover); }
.round-btn-danger { background: var(--danger); }
.round-btn-danger:hover { background: var(--danger-hover); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 50;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 10px;
  background: var(--text); color: #fff; font-size: 14px; font-weight: 500; text-align: center;
  box-shadow: 0 12px 32px -12px rgba(0, 0, 0, .45);
  opacity: 0; pointer-events: none; transform: translate(-50%, 8px);
  transition: opacity .2s, transform .2s var(--ease);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Phone ---------- */
@media (max-width: 760px) {
  .sidebar { width: 100%; border-right: none; }
  .shell[data-view="chat"] .sidebar { display: none; }
  .shell[data-view="list"] .conversation { display: none; }
  .back { display: inline-flex; margin-left: -6px; }
  .thread-head { gap: 8px; padding: 10px 10px 10px 12px; }
  .voice-bar { padding: 8px 12px; gap: 8px; }
  .messages { padding: 4px 12px 10px; }
  .msg { max-width: 86%; }
  .attachment { margin: 0 10px; }
  .composer { padding-left: 10px; padding-right: 10px; }
  .ring { right: 16px; left: 16px; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}