:root {
  /* Same palette as crych_desktop (see src/qml/Theme.qml there) -- kept in sync by hand across
     the two codebases since they don't share a build; this is the single source of truth here. */
  --bg: #E9E6DD;
  --surface: #FFFFFF;
  --surface-alt: #F3EFE4;
  --text: #232320;
  --text-muted: #8C8C86;
  --text-subtle: #A6A69E;
  --accent: #5A7A63;
  --accent-hover: #4F6B57;
  --accent-tint: #E0F0E4;
  --accent-tint-strong: #DCE3C6;
  --danger: #C0392B;
  --danger-hover: #a5311f;
  --online: #9BB98A;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 18px;
  --space-2xl: 24px;

  --shadow-sm: 0 1px 3px rgba(35,35,32,0.08);
  --shadow-md: 0 4px 16px rgba(35,35,32,0.10);
  --shadow-lg: 0 8px 32px rgba(35,35,32,0.14);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}
.hidden { display: none !important; }
.screen { height: 100vh; }

/* Icons -- inline sprite (see index.html's #icon-sprite), one consistent 24x24 stroke style.
   `.icon` sizes/colors via currentColor so a button's own `color` drives the icon color. */
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon-lg { width: 22px; height: 22px; }

/* Login */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: var(--surface);
  padding: var(--space-2xl) 32px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 360px;
}
.login-brand { display: flex; align-items: center; gap: var(--space-sm); margin-bottom: var(--space-xs); }
.login-brand .logo-mark { width: 30px; height: 30px; }
.login-card h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.subtitle { margin: 0 0 var(--space-xl); color: var(--text-muted); font-size: 13px; }
label { display: block; font-size: 13px; font-weight: 600; margin: var(--space-md) 0 var(--space-xs); }
.hint { font-weight: 400; color: var(--text-subtle); font-size: 12px; }
.hint.small { font-size: 11px; margin: var(--space-xs) 0 var(--space-sm); }
input[type="text"], input[type="tel"] {
  width: 100%;
  padding: 10px var(--space-md);
  border: 1px solid var(--accent-tint-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus, input[type="tel"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
button {
  margin-top: var(--space-lg);
  width: 100%;
  padding: 10px var(--space-md);
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background-color .15s, transform .1s, box-shadow .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
}
button:hover { background: var(--accent-hover); }
button:active { transform: scale(0.98); }
button.secondary { background: var(--surface-alt); color: var(--text); margin-top: var(--space-sm); }
button.secondary:hover { background: var(--accent-tint-strong); }
.error {
  background: #FBEAE7; color: var(--danger); padding: 10px var(--space-md);
  border-radius: var(--radius-sm); font-size: 13px; margin-bottom: var(--space-md);
}

/* Main app */
#app-screen { display: flex; }
.sidebar {
  width: 300px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-lg);
}
.sidebar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-lg); }
.sidebar-header .brand { display: flex; align-items: center; gap: var(--space-sm); }
.sidebar-header .brand .logo-mark { width: 22px; height: 22px; }
.me-name { font-weight: 700; font-size: 14px; }
.me-sub { font-size: 11px; color: var(--text-subtle); }
.icon-btn {
  width: auto; margin: 0; padding: var(--space-sm);
  background: transparent; color: var(--text-muted);
  border-radius: var(--radius-sm);
}
.icon-btn:hover { background: var(--surface-alt); color: var(--text); }
.copy-id-btn { width: 100%; justify-content: flex-start; text-align: left; margin-bottom: var(--space-md); background: var(--surface-alt); color: var(--text); padding: 10px var(--space-md); }
.copy-id-btn:hover { background: var(--accent-tint-strong); }
.new-chat { display: flex; gap: var(--space-sm); }
.new-chat input { flex: 1; margin: 0; }
.new-chat button { width: auto; margin: 0; padding: 10px 14px; }
.new-group { display: flex; flex-direction: column; gap: var(--space-sm); margin-top: var(--space-md); }
.new-group input { margin: 0; }
.new-group button { margin: 0; }
.error.small { margin: var(--space-sm) 0 0; padding: 6px 10px; font-size: 12px; }
.conversation-list { flex: 1; overflow-y: auto; margin-top: var(--space-md); }
.conversation-item {
  padding: 10px; border-radius: var(--radius-sm); cursor: pointer; margin-bottom: var(--space-xs);
  transition: background-color .15s;
}
.conversation-item:hover { background: var(--surface-alt); }
.conversation-item.active { background: var(--accent-tint); }
.conversation-item .peer-name { font-weight: 600; font-size: 14px; }
.conversation-item .peer-id { font-size: 11px; color: var(--text-subtle); word-break: break-all; }

.chat-panel { flex: 1; display: flex; flex-direction: column; background: var(--bg); }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-subtle); }
.chat-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header {
  padding: var(--space-lg); background: var(--surface); box-shadow: var(--shadow-sm);
  position: relative; z-index: 1;
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 700;
  gap: var(--space-md);
}
.chat-header-actions { display: flex; gap: var(--space-xs); flex: 1; justify-content: flex-end; }
.ws-status { display: flex; align-items: center; }
.ws-status .icon { width: 10px; height: 10px; stroke: none; fill: var(--danger); }
.ws-status.connected .icon { fill: var(--online); }

/* 1-1 call (WebRTC, native RTCPeerConnection -- see docs/architecture/call-signaling.md) */
.call-banner {
  display: flex; align-items: center; gap: var(--space-md); padding: 10px var(--space-lg);
  background: var(--accent-tint); font-size: 13px;
}
.call-banner button { width: auto; margin: 0; padding: 6px 14px; font-size: 12px; }
#call-status-text { flex: 1; font-weight: 600; }
#call-end-btn { background: var(--danger); }
#call-end-btn:hover { background: var(--danger-hover); }
.call-video-view {
  position: relative; background: #1A1A18; height: 260px; flex-shrink: 0;
}
.call-video-view #remote-video { width: 100%; height: 100%; object-fit: cover; }
.local-video-pip {
  position: absolute; bottom: 10px; right: 10px; width: 110px; height: 82px;
  object-fit: cover; border-radius: var(--radius-sm); border: 1px solid rgba(255,255,255,0.3);
  background: black; box-shadow: var(--shadow-md);
}

/* Group call (LiveKit SFU) */
.group-call-view {
  position: relative; background: #1A1A18; padding: 10px; flex-shrink: 0;
}
.group-call-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-sm); max-height: 300px;
}
.group-call-tile {
  position: relative; background: #000; border-radius: var(--radius-sm); aspect-ratio: 4 / 3;
  overflow: hidden; display: flex; align-items: center; justify-content: center;
}
.group-call-tile video, .group-call-tile audio { width: 100%; height: 100%; object-fit: cover; }
.group-call-tile-label {
  position: absolute; left: 6px; bottom: 4px; color: white; font-size: 11px;
  text-shadow: 0 0 4px rgba(0,0,0,0.8);
}
.group-call-controls { display: flex; align-items: center; gap: var(--space-sm); margin-top: 10px; }
.group-call-controls button { width: auto; margin: 0; padding: 8px 14px; font-size: 12px; background: #3A3A36; }
.group-call-controls button:hover { background: #4a4a44; }
.group-call-controls button.is-off { background: var(--danger); }
.group-call-controls button.is-off:hover { background: var(--danger-hover); }
.group-call-controls .secondary { background: var(--danger); color: white; }
.group-call-controls .secondary:hover { background: var(--danger-hover); }
.btn-icon-off { display: none; }
button.is-off .btn-icon-on { display: none; }
button.is-off .btn-icon-off { display: inline-flex; }

.messages { flex: 1; overflow-y: auto; padding: var(--space-lg); display: flex; flex-direction: column; gap: var(--space-sm); }
.load-more {
  width: auto; align-self: center; background: var(--surface-alt); color: var(--text);
  font-size: 12px; padding: 6px 12px; margin: 0 0 var(--space-sm);
}
.load-more:hover { background: var(--accent-tint-strong); }
.bubble {
  max-width: 60%; padding: 8px var(--space-md); border-radius: var(--radius-md); font-size: 14px;
  word-wrap: break-word;
  box-shadow: var(--shadow-sm);
  animation: bubble-in .18s ease-out;
}
@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.bubble.mine { align-self: flex-end; background: var(--accent); color: white; border-bottom-right-radius: 4px; }
.bubble.theirs { align-self: flex-start; background: var(--surface); color: var(--text); border-bottom-left-radius: 4px; }
.bubble .meta { font-size: 10px; opacity: 0.7; margin-top: 4px; }
.send-form { display: flex; align-items: center; gap: var(--space-sm); padding: var(--space-lg); background: var(--surface); box-shadow: 0 -1px 3px rgba(35,35,32,0.06); }
.send-form input { flex: 1; margin: 0; }
.send-form button {
  width: 40px; height: 40px; flex-shrink: 0; margin: 0; padding: 0;
  border-radius: 50%;
}

/* "Đang nhập" indicator -- zero-height anchor + absolutely positioned pill, so showing/hiding it
   never resizes .messages (same reason crych_desktop floats it over the list instead of giving it
   its own layout row: a row that appears/disappears shifts the whole list mid-typing). */
.typing-anchor { position: relative; height: 0; flex-shrink: 0; }
.typing-indicator {
  position: absolute; left: var(--space-lg); bottom: var(--space-sm); z-index: 1;
  padding: 4px var(--space-md); border-radius: 999px;
  background: rgba(243, 239, 228, 0.94); color: var(--accent);
  font-size: 12px; font-style: italic; box-shadow: var(--shadow-sm);
  pointer-events: none;
}

/* Phones. `100vh` on mobile browsers includes the area under the collapsing address/tool bar, so
   the bottom of a 100vh page (the message input) sits off-screen -- 100dvh is the actually-visible
   height (unsupported browsers ignore it and keep the 100vh above). And the 300px sidebar can't
   sit beside the chat on a ~390px-wide screen (it left the chat ~90px: input crushed, text
   wrapping one character per line), so below 768px only ONE of {conversation list, chat} shows at
   a time; opening a conversation adds .chat-open to #app-screen (see openConversation), the back
   button removes it. */
body, .screen { height: 100dvh; }
.back-btn { display: none; }

@media (max-width: 768px) {
  .sidebar { width: 100%; overflow-y: auto; box-shadow: none; }
  .conversation-list { flex: none; overflow: visible; }
  .chat-panel { display: none; width: 100%; }
  #app-screen.chat-open .sidebar { display: none; }
  #app-screen.chat-open .chat-panel { display: flex; }
  .back-btn { display: inline-flex; }
  .chat-header { padding: var(--space-md); }
  .bubble { max-width: 82%; }
  .send-form {
    padding: var(--space-md);
    padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
  }
  /* iOS Safari zooms the whole page in when focusing any input under 16px, which also shifts
     the layout -- another way the compose box ends up half off-screen. */
  input[type="text"], input[type="tel"] { font-size: 16px; }
}

button:disabled { opacity: 0.6; cursor: default; }
button:disabled:hover { background: var(--accent); }
.fatal-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  padding: 10px var(--space-lg); background: var(--danger); color: white; font-size: 13px;
}
