*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
* { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

body {
  font-family: system-ui, sans-serif;
  background: #f5f5f5;
  color: #111;
  overflow: hidden;
}

#app {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 100dvh; /* JS overrides this when visualViewport is available */
  display: flex;
  flex-direction: column;
}

/* --- Entry screen --- */
.center-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 1rem;
}
.center-wrap h1 { font-size: 2rem; }
.center-wrap p { color: #555; }
.center-wrap form { display: flex; gap: 0.5rem; }

/* --- Layout: sidebar + main --- */
.layout {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #1a1d23;
  color: #c9cdd6;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-header {
  display: flex;
  align-items: center;
  padding-top: max(0.875rem, env(safe-area-inset-top));
  justify-content: space-between;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid #2e3239;
}

.sidebar-title {
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
}


.channels-label {
  padding: 1rem 1rem 0.375rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7b8290;
}

#channel-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 0 0.5rem;
}

.channel-item {
  margin-bottom: 1px;
  display: flex;
  align-items: center;
  border-radius: 4px;
}

.channel-item:has(.channel-btn.active) { background: #3a3f4a; }

.channel-btn {
  flex: 1;
  text-align: left;
  padding: 0.4rem 0.625rem;
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  color: #c9cdd6;
  outline: none;
}

@media (hover: hover) {
  .channel-item:hover { background: #2e3239; }
  .channel-item:hover .channel-btn { color: #fff; }
  .channel-btn:hover { background: none; } /* override the generic blue button:hover */
}

.channel-btn.active { color: #fff; }

.channel-delete-btn {
  /* Always laid out (space reserved) so revealing it on hover doesn't resize the channel name. */
  display: flex;
  visibility: hidden;
  background: none;
  border: none;
  color: #7b8290;
  cursor: pointer;
  padding: 0.5rem 0.625rem;
  min-width: 44px;
  min-height: 44px;
  font-size: 1.1rem;
  line-height: 1;
  border-radius: 4px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}

@media (hover: hover) {
  .channel-item:hover .channel-delete-btn { visibility: visible; }
  .channel-delete-btn:hover { color: #ff5555; background: rgba(255,85,85,0.1); }
}

@media (hover: none) {
  .channel-delete-btn { visibility: visible; }
  .channel-delete-btn:active { color: #ff5555; background: rgba(255,85,85,0.15); }
}

.add-channel-btn {
  margin: 0.5rem 0.75rem 0.75rem;
  width: calc(100% - 1.5rem);
  padding: 0.45rem 0.75rem;
  background: #2e3239;
  color: #c9cdd6;
  border: none;
  border-radius: 4px;
  font-size: 0.85rem;
  text-align: left;
  cursor: pointer;
}

.add-channel-btn:hover { background: #3a3f4a; color: #fff; }

/* --- Hamburger (mobile only) --- */
.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.375rem;
  border-radius: 4px;
  font-size: 1rem;
  color: inherit;
}

#close-sidebar { color: #7b8290; }
#close-sidebar:hover { color: #fff; background: #2e3239; }

/* On wide screens, hide close button and hamburger */
@media (min-width: 600px) {
  #hamburger { display: none; }
  #close-sidebar { display: none; }
}

/* On narrow screens, sidebar overlays */
@media (max-width: 599px) {
  .sidebar {
    position: fixed;
    left: -240px;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: left 0.2s ease;
  }
  .sidebar.open { left: 0; }
}

/* --- Main area --- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
}

.main-header {
  display: flex;
  align-items: center;
  padding-top: max(0.75rem, env(safe-area-inset-top));
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: #fff;
  border-bottom: 1px solid #ddd;
  flex-shrink: 0;
}

#hamburger { color: #555; }
#hamburger:hover { background: #f0f0f0; color: #111; }

.room-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #111;
  flex: 1;
}

.profile-wrap { position: relative; flex-shrink: 0; }

.profile-badge {
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #0066ff;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}

@media (hover: hover) {
  .profile-badge:hover { background: #0052cc; }
}

.profile-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  min-width: 12rem;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.12);
  padding: 0.35rem;
  z-index: 150;
}
.profile-menu[hidden] { display: none; }

.profile-menu-name {
  padding: 0.4rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #111;
  border-bottom: 1px solid #f0f0f0;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-menu-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.45rem 0.55rem;
}
.profile-menu-field label {
  font-size: 0.85rem;
  color: #333;
}
.profile-menu-field select {
  width: 100%;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
  color: #111;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  cursor: pointer;
  outline: none;
}
.profile-menu-field select:focus { border-color: #0066ff; }

.profile-menu-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  font-size: 0.85rem;
  color: #333;
  cursor: pointer;
}
.profile-menu-check input { width: 1rem; height: 1rem; accent-color: #0066ff; cursor: pointer; }

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.welcome-state {
  align-items: center;
  justify-content: center;
  color: #999;
  font-size: 0.95rem;
}

/* --- Room --- */
.room-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Live draft bubble --- */
.draft-bubble .msg-text {
  border-style: dashed;
  border-color: #aac4ff;
  background: #f0f5ff;
  color: #333;
  font-style: italic;
}

.live-badge {
  display: inline-block;
  margin-left: 0.375rem;
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #fff;
  background: #0066ff;
  border-radius: 3px;
  padding: 0.05rem 0.3rem;
  vertical-align: middle;
  animation: pulse-badge 1.5s ease-in-out infinite;
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

.history {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overscroll-behavior: contain;
}

.time-header {
  align-self: center;
  margin: 0.6rem 0 0.1rem;
  font-size: 0.7rem;
  color: #9aa0a6;
  letter-spacing: 0.02em;
}
.time-header strong { color: #6b7075; font-weight: 600; }

.message { display: flex; flex-direction: column; max-width: 70%; }
.message.mine  { align-self: flex-end;  align-items: flex-end; }
.message.theirs { align-self: flex-start; align-items: flex-start; }

/* Your own messages support long-press-to-delete on touch — suppress the iOS callout/selection. */
.message.own { -webkit-touch-callout: none; }
@media (hover: none) { .message.own { -webkit-user-select: none; user-select: none; } }

/* Right-click / long-press delete menu */
.msg-menu {
  position: fixed;
  z-index: 250;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
  padding: 0.25rem;
  min-width: 9rem;
}
.msg-menu-del {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: #c00;
  font-size: 0.85rem;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
}
@media (hover: hover) { .msg-menu-del:hover { background: #fdecec; } }

/* Voice clips all render at the same (max) width, regardless of transcript length. */
.message:has(.audio-bubble) { width: 70%; }

.msg-name { font-size: 0.72rem; color: #aaa; margin-bottom: 0.15rem; }

.msg-text {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  padding: 0.45rem 0.75rem;
  font-size: 0.95rem;
  word-break: break-word;
  color: #111;
}

.message.mine .msg-text {
  background: #0066ff;
  color: #fff;
  border-color: #0066ff;
}

.msg-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.75rem 1rem max(0.75rem, env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid #ddd;
  flex-shrink: 0;
}

/* --- Push-to-talk button --- */
.ptt-btn {
  flex-shrink: 0;
  padding: 0;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: #eef1f5;
  color: #333;
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none; /* let pointerdown/up drive hold without scroll/gesture interference */
  user-select: none;
  -webkit-user-select: none;   /* stop iOS long-press text selection */
  -webkit-touch-callout: none; /* stop iOS long-press callout menu */
}

.ptt-btn.recording {
  background: #ff3b30;
  color: #fff;
  animation: ptt-pulse 1s ease-in-out infinite;
}

@keyframes ptt-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,59,48,0.5); }
  50%      { box-shadow: 0 0 0 0.5rem rgba(255,59,48,0); }
}

/* --- Voice-first composer: big centered record button over the message box --- */
.msg-form.voice-first {
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding-top: 1rem;
}
.msg-form.voice-first .ptt-btn {
  width: 7.5rem;
  height: 7.5rem;
  font-size: 3.3rem;
  background: #0066ff;
  color: #fff;
  box-shadow: 0 2px 14px rgba(0, 102, 255, 0.35);
}
.msg-form.voice-first .ptt-btn.recording {
  background: #ff3b30;
  box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.5);
}
.msg-form.voice-first .ptt-hint {
  font-size: 0.72rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.msg-form.voice-first .compose-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

@media (hover: hover) {
  .ptt-btn:hover { background: #e2e6ec; }
  .ptt-btn.recording:hover { background: #ff3b30; }
}

/* --- Audio clip bubble --- */
.msg-text.audio-bubble {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  align-self: stretch; /* fill the fixed-width audio message */
  gap: 0.35rem;
  padding: 0.4rem 0.6rem;
}
.audio-row { display: flex; align-items: center; gap: 0.5rem; min-width: 11rem; }
.audio-bubble audio { display: none; }

.ap-play {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #0066ff;
  color: #fff;
  font-size: 0.7rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
@media (hover: hover) { .ap-play:hover { background: #0052cc; } }

.ap-track {
  flex: 1;
  height: 5px;
  min-width: 4rem;
  background: rgba(0, 0, 0, 0.13);
  border-radius: 3px;
  cursor: pointer;
  overflow: hidden;
}
.ap-progress {
  display: block;
  height: 100%;
  width: 0%;
  background: #0066ff;
  border-radius: 3px;
}

.audio-dur { font-size: 0.72rem; color: #888; white-space: nowrap; }
.audio-error { font-size: 0.8rem; color: #c00; font-style: italic; }

/* Transcript lives inside the bubble, under the player, with a subtle divider. */
.audio-transcript {
  font-size: 0.8rem;
  line-height: 1.3;
  color: #444;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  padding-top: 0.3rem;
}
.audio-transcript:empty { display: none; }
.message.mine .audio-bubble { background: #eef4ff; border-color: #cfe0ff; }
.message.mine .audio-bubble .audio-dur { color: #5b6b8c; }
.message.mine .audio-transcript { color: #3a4a66; border-top-color: rgba(0, 0, 0, 0.12); }

/* --- Live "transmitting" indicator (reuses .draft-bubble) --- */
.msg-text.ptt-live { display: flex; align-items: center; gap: 0.4rem; }
.ptt-bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 0.9rem; }
.ptt-bars i {
  width: 3px;
  background: #0066ff;
  border-radius: 1px;
  animation: ptt-bars 0.9s ease-in-out infinite;
}
.ptt-bars i:nth-child(1) { height: 40%; animation-delay: 0s; }
.ptt-bars i:nth-child(2) { height: 100%; animation-delay: 0.15s; }
.ptt-bars i:nth-child(3) { height: 60%; animation-delay: 0.3s; }

@keyframes ptt-bars {
  0%, 100% { transform: scaleY(0.4); }
  50%      { transform: scaleY(1); }
}

/* --- Toast --- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(4rem + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(1rem);
  background: #1a1d23;
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- Inputs & buttons (global) --- */
input[type="text"] {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 1rem;
  outline: none;
  color: #111;
}

input[type="text"]:focus { border-color: #0066ff; }

button {
  padding: 0.5rem 1rem;
  background: #0066ff;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  white-space: nowrap;
}

@media (hover: hover) {
  button:hover { background: #0052cc; }
}
