* { box-sizing: border-box; }
:root { --chat-font-size: 15px; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #121212; color: #EDEDED;
}
.hidden { display: none !important; }

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

/* --- auth --- */
#auth-screen { align-items: center; justify-content: center; }
.auth-card {
  width: 90%; max-width: 320px; display: flex; flex-direction: column; gap: 10px;
  background: #1C1C1E; padding: 24px; border-radius: 14px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
.auth-card h1 { text-align: center; margin: 0 0 8px; color: #2FDE76; }

input[type=text], input[type=password], input[type=number], input[type=file], select, textarea {
  background: #2A2A2C; border: 1px solid #3A3A3C; color: #EDEDED;
  padding: 10px 12px; border-radius: 8px; font-size: 16px; width: 100%;
}
textarea { font-family: inherit; resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #9A9A9A; margin: 8px 0; }
label input[type=checkbox] { width: auto; margin-right: 8px; }
.note { font-size: 12px; color: #7A7A7A; }
.section-label { font-size: 12px; color: #7A7A7A; margin: 10px 0 2px; }

button {
  background: #06C755; color: #08170D; border: none; border-radius: 8px;
  padding: 11px 14px; font-size: 15px; font-weight: 600; cursor: pointer;
}
button.secondary { background: #2C2C2E; color: #EDEDED; }
button.danger { background: #1C1C1E; color: #FF6B60; border: 1px solid #FF6B60; }
button.icon-btn { background: transparent; color: #EDEDED; font-size: 18px; padding: 4px 8px; position: relative; }
button.small { padding: 6px 10px; font-size: 13px; }
.error { color: #FF6B60; font-size: 13px; min-height: 16px; }

/* --- avatars --- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; background: #06C755; color: #08170D; font-weight: 700;
  overflow: hidden; flex-shrink: 0; background-size: cover; background-position: center;
}
.avatar-xs { width: 22px; height: 22px; font-size: 10px; }
.avatar-sm { width: 32px; height: 32px; font-size: 13px; }
.avatar-md { width: 44px; height: 44px; font-size: 16px; }
.avatar-lg { width: 84px; height: 84px; font-size: 28px; }

/* --- topbar --- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 14px; background: #1C1C1E; border-bottom: 1px solid #2C2C2E;
  position: sticky; top: 0; z-index: 2;
}
.topbar span#chat-title, .topbar .me-identity span:last-child { font-weight: 600; }
.me-identity { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.badge-dot {
  position: absolute; top: 0; right: 0; width: 8px; height: 8px; border-radius: 50%;
  background: #FF6B60;
}
.badge-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: #FF6B60; color: #1C1C1E; font-size: 10px; font-weight: 700;
}

/* --- friends bar --- */
#friends-bar {
  display: flex; gap: 14px; overflow-x: auto; padding: 12px 14px;
  background: #1C1C1E; border-bottom: 1px solid #2C2C2E;
}
#friends-bar:empty { display: none; }
.friend-item { display: flex; flex-direction: column; align-items: center; gap: 4px; flex-shrink: 0; width: 56px; }
.friend-item .avatar { cursor: pointer; }
.friend-item.bot .avatar { box-shadow: 0 0 0 2px #06C755; }
.friend-item .friend-name {
  font-size: 11px; color: #9A9A9A; text-align: center; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%;
}

/* --- chat list --- */
#chat-list-view { display: flex; flex-direction: column; height: 100%; }
.list-actions { display: flex; gap: 8px; padding: 10px 14px; flex-wrap: wrap; }
.list-actions button { flex: 1; font-size: 12.5px; padding: 10px 5px; }
#chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; background: #121212; }
#chat-list li {
  padding: 12px 14px; border-bottom: 1px solid #232325; display: flex;
  align-items: center; gap: 10px; cursor: pointer;
}
#chat-list li:active { background: #1C1C1E; }
/* Subtle on purpose (Kuma's explicit call - not a badge, not bold, just
   enough to notice at a glance) - a faint tint of the app's own accent
   green plus a thin left border, nothing that competes with the text. */
#chat-list li.unread { background: rgba(6, 199, 85, 0.07); border-left: 2px solid #06C755; }
.chat-row-text { flex: 1; min-width: 0; }
.chat-row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-badges { display: flex; gap: 4px; margin-top: 2px; }
.badge { font-size: 10.5px; padding: 2px 6px; border-radius: 10px; background: #2C2C2E; color: #9A9A9A; }
.badge.on { background: #06C755; color: #08170D; }

/* --- chat view --- */
#chat-view { display: flex; flex-direction: column; height: 100%; }
#messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: #121212; }
.msg-row { display: flex; align-items: flex-end; gap: 6px; max-width: 100%; }
.msg-row.mine { flex-direction: row-reverse; }
/* calc() against the row's own width, not a fixed vw guess, so the bubble
   always claims exactly "row minus the ~28px avatar+gap" regardless of
   screen size - no leftover slack, and no double-shrinking either. */
.msg { max-width: calc(100% - 28px); padding: 9px 12px; border-radius: 16px; font-size: var(--chat-font-size); line-height: 1.35; }
/* Line breaks in the original text were being silently collapsed into one
   run-on paragraph - `pre-wrap` keeps real newlines/paragraph breaks while
   still wrapping long lines normally. */
.msg .body, .msg .original-text { white-space: pre-wrap; }
.msg .body strong { font-weight: 700; }
.msg-row .avatar { flex-shrink: 0; }
.msg .meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 11px; color: #9A9A9A; margin-bottom: 3px; }
.msg .meta-name { display: flex; align-items: center; }
.msg .meta-time { flex-shrink: 0; opacity: 0.8; }
#typing-indicator { padding: 2px 14px 4px; font-size: 12.5px; color: #9A9A9A; font-style: italic; }
/* Bumped up from the meta text's own 11px and given its own brighter
   color so it actually reads as a tappable control at a glance, without
   making the meta line itself any taller. */
.read-aloud-btn { font-size: 15px; margin-left: 6px; cursor: pointer; color: #7FCB9C; line-height: 1; vertical-align: middle; }
.read-aloud-btn:active { opacity: 0.7; }
.read-aloud-btn.playing { color: #FF6B60; }
/* The translation is the primary .body text (see app.js's _bodyHTML) -
   the original the sender actually typed/said is a small, collapsed
   detail underneath, there to double-check against, not to compete with
   the translation for attention. */
.msg .original-toggle {
  margin-top: 5px; padding-top: 5px; border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 11.5px; opacity: 0.65; cursor: pointer; user-select: none;
}
.msg .original-text { margin-top: 4px; font-size: 12.5px; opacity: 0.75; }
.msg .body.pending-translation { font-style: italic; opacity: 0.6; }
.msg.mine { background: #1E7A42; color: #EAFBE9; border-bottom-right-radius: 4px; }
.msg.theirs { background: #232325; color: #EDEDED; box-shadow: 0 1px 2px rgba(0,0,0,0.3); border-bottom-left-radius: 4px; }
.msg.kappy { background: #3A2A55; color: #E4D2FF; font-style: italic; border-bottom-left-radius: 4px; }
.msg.claude { background: #1F3A5C; color: #BFE0FF; border-bottom-left-radius: 4px; }
.msg.hermes { background: #3D2A1F; color: #FFD9A8; border-bottom-left-radius: 4px; }
.msg.system { align-self: center; background: transparent; color: #7A7A7A; font-size: 13px; text-align: center; margin: 0 auto; }
.msg img.attachment { max-width: 100%; max-height: 260px; border-radius: 10px; display: block; margin-top: 4px; cursor: pointer; }
#image-lightbox {
  position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,0.9);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
#image-lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.msg .attachment-pdf {
  display: flex; align-items: center; gap: 8px; margin-top: 4px;
  padding: 8px 10px; background: rgba(255,255,255,0.08); border-radius: 8px;
  color: inherit; text-decoration: none; font-size: 13.5px;
}

.send-bar {
  display: flex; gap: 6px; padding: 10px; background: #1C1C1E;
  border-top: 1px solid #2C2C2E; position: sticky; bottom: 0; align-items: flex-end;
}
.send-bar textarea {
  flex: 1; resize: none; max-height: 140px; overflow-y: auto;
  line-height: 1.35; font-family: inherit; font-size: 16px;
  padding: 10px 12px; border-radius: 8px; background: #2A2A2C;
  border: 1px solid #3A3A3C; color: #EDEDED;
}
.send-bar button { flex-shrink: 0; }
.send-bar .icon-btn { font-size: 17px; padding: 3px 5px; }
.send-bar button[type=submit] { padding: 9px 12px; font-size: 14px; }
@keyframes mic-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
/* Compose bar collapses to emoji+clip+Send by default; focusing the
   textarea swaps to a single back arrow so the textarea gets more room -
   the back button only shows in that expanded state. */
#btn-compose-back { display: none; }
.send-bar.expanded #btn-emoji, .send-bar.expanded #btn-attach, .send-bar.expanded #btn-mic { display: none; }
.send-bar.expanded #btn-compose-back { display: inline-flex; }
.send-bar.expanded #btn-send { padding: 9px 14px; min-width: 0; }
/* Voice mode: the whole middle of the bar becomes one big surface instead
   of a textarea+separate send button - back arrow (from .expanded,
   reused) is the only other control, and it's the only way out. Sticky
   across multiple record/stop/send cycles (see app.js) - stopping a
   recording does not leave this screen, it just goes back to the ready
   (non-pulsing) look, waiting for the next tap to record again. */
.send-bar.voice-mode #message-input, .send-bar.voice-mode #btn-send { display: none; }
/* Green = ready to tap and start (matches the app's standard "go" green
   used everywhere else), red = actually recording right now - a clear,
   conventional color swap so it's obvious which state you're in at a
   glance. Text itself stays fully opaque at all times in both states (an
   earlier version pulsed the whole surface's opacity, which made small
   text on a dark background nearly disappear mid-pulse); the "live" feel
   comes from the dot instead, and only while actually recording. */
#recording-surface {
  display: none; flex: 1; align-items: center; justify-content: center; gap: 8px;
  padding: 11px; border-radius: 8px; background: #06C755; color: #08170D;
  font-size: 15px; font-weight: 700; cursor: pointer; user-select: none;
}
.send-bar.voice-mode #recording-surface { display: flex; }
#recording-surface.active { background: #FF6B60; color: #1C1C1E; }
#recording-surface .dot { display: none; width: 10px; height: 10px; border-radius: 50%; background: #1C1C1E; }
#recording-surface.active .dot { display: block; animation: mic-pulse 1s ease-in-out infinite; }

#emoji-picker {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px;
  padding: 10px; background: #1C1C1E; border-top: 1px solid #2C2C2E;
  max-height: 160px; overflow-y: auto;
}
#emoji-picker span { font-size: 22px; text-align: center; cursor: pointer; padding: 4px; border-radius: 6px; }
#emoji-picker span:active { background: #2A2A2C; }

/* --- panels / modal --- */
.panel {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end;
  background: rgba(0,0,0,0.5);
}
.panel-inner {
  background: #1C1C1E; width: 100%; max-height: 88vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; padding: 20px; display: flex; flex-direction: column; gap: 4px;
}
.panel-inner h2 { margin: 0 0 8px; }
.panel-inner h3 { margin: 14px 0 4px; font-size: 14px; color: #9A9A9A; }
.panel-inner h3:first-of-type { margin-top: 4px; }
/* Checkbox-only rows (as opposed to a label sitting above a text/select
   field) read better as a compact horizontal row than the generic
   label's stacked column layout. */
label.toggle-row { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
label.toggle-row input[type=checkbox] { margin: 0; }
/* Two-column "cell" layout for the settings panel - short toggles pack
   two per row instead of each claiming the full width; anything that
   needs more room (a select pair, a textarea, a section heading) spans
   both columns via .span-2, like a merged cell. */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; align-items: start; }
.settings-grid > .span-2 { grid-column: 1 / -1; }
.settings-grid > h3 { margin: 10px 0 0; }
.settings-grid > .row { margin: 0; }
.panel-inner .row { display: flex; gap: 10px; align-items: center; }
.panel-inner .row > label { flex: 1; }
.panel-inner .row select, .panel-inner .row input { flex: 1; }
#invite-result { font-size: 13px; word-break: break-all; color: #9A9A9A; margin: 6px 0; }

/* --- profile panel --- */
.profile-header { display: flex; justify-content: center; padding: 8px 0; }
#profile-username { text-align: center; margin: 4px 0; }
.bio { text-align: center; color: #9A9A9A; font-size: 14px; margin-bottom: 8px; }
#profile-action { display: flex; justify-content: center; gap: 8px; margin: 8px 0; }

/* --- requests / member list / search / invite-picker rows --- */
#incoming-requests, #outgoing-requests, #group-invites, #s-member-list,
#friend-search-results, #invite-picker-list {
  list-style: none; margin: 0; padding: 0;
}
#incoming-requests li, #outgoing-requests li, #group-invites li, #s-member-list li,
#friend-search-results li, #invite-picker-list li {
  display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #232325;
}
#s-member-list .avatar, #invite-picker-list .avatar { cursor: pointer; }
.req-name { flex: 1; font-weight: 600; }
.req-actions { display: flex; gap: 6px; }

/* --- QR scan area --- */
#qr-scan-area { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#qr-video {
  width: 100%; max-width: 320px; aspect-ratio: 1 / 1; object-fit: cover;
  border-radius: 12px; background: #000;
}
#qr-status { text-align: center; }

@media (min-width: 640px) {
  .auth-card { max-width: 360px; }
  .panel { align-items: center; justify-content: center; }
  .panel-inner { max-width: 420px; border-radius: 16px; }
}
