/* ══════════════════════════════════════════════════════
   FocalCodec Walkie-Talkie — Layout & Components
   ══════════════════════════════════════════════════════ */

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

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--crust);
  color: var(--text);
  height: 100vh;
  display: flex;
  overflow: hidden;
}

/* ── App Shell ──────────────────────────────────────── */
.app {
  width: min(96vw, 960px);
  height: min(94vh, 740px);
  margin: auto;
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: 46px 1fr;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--surface0);
  background: var(--base);
}

/* ── Header ─────────────────────────────────────────── */
.hdr {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  background: var(--mantle);
  border-bottom: 1px solid var(--surface0);
}
.hdr h1 { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.hdr .badge {
  font-size: 0.55rem; padding: 2px 8px;
  background: var(--surface0); color: var(--overlay);
  border-radius: 10px; font-weight: 600; letter-spacing: 0.06em;
}
.hdr .spacer { flex: 1; }
.hdr-stats {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem; color: var(--overlay);
  display: flex; gap: 12px;
}
.hdr-stats b { color: var(--accent); font-weight: 600; }

/* Theme dots */
.themes {
  display: flex; gap: 4px;
  margin-left: 10px; padding-left: 10px;
  border-left: 1px solid var(--surface0);
}
.themes button {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.themes button:hover { transform: scale(1.15); }
.themes button.active { border-color: var(--text); }

/* ── Sidebar ────────────────────────────────────────── */
.side {
  display: flex; flex-direction: column;
  background: var(--mantle);
  border-right: 1px solid var(--surface0);
  overflow-y: auto;
}
.sec {
  padding: 12px 14px;
  border-bottom: 1px solid var(--surface0);
}
.sec:last-child { border-bottom: none; flex: 1; }
.sec-title {
  font-size: 0.6rem; color: var(--overlay);
  text-transform: uppercase; letter-spacing: 0.1em;
  font-weight: 600; margin-bottom: 6px;
}

/* ── Form elements ──────────────────────────────────── */
.row { display: flex; gap: 5px; }
.row + .row { margin-top: 5px; }
input, select {
  flex: 1; min-width: 0;
  padding: 7px 10px;
  background: var(--crust); border: 1px solid var(--surface0);
  border-radius: 7px; color: var(--text);
  font-family: 'JetBrains Mono', monospace; font-size: 0.78rem;
}
input:focus, select:focus { outline: none; border-color: var(--surface1); }
select { cursor: pointer; appearance: none; padding-right: 24px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236c7086'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center;
}

.btn {
  padding: 7px 14px;
  border: 1px solid var(--surface0); background: var(--surface0);
  color: var(--subtext); border-radius: 7px; cursor: pointer;
  font-family: 'Inter', sans-serif; font-size: 0.75rem;
  font-weight: 500; transition: all 0.1s;
  white-space: nowrap; flex-shrink: 0;
}
.btn:hover { background: var(--surface1); color: var(--text); }
.btn:disabled { opacity: 0.25; cursor: not-allowed; }
.btn-full { width: 100%; margin-top: 4px; }
.btn-dim { opacity: 0.4; font-size: 0.65rem; padding: 4px 10px; }
.btn-dim:hover { opacity: 0.7; }

/* ── Status ─────────────────────────────────────────── */
.status {
  display: flex; align-items: center; gap: 7px;
  font-size: 0.75rem; color: var(--subtext); margin-top: 6px;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--surface2); flex-shrink: 0;
}
.dot.on { background: var(--green); }
.dot.loading { background: var(--yellow); animation: pulse 1.2s ease infinite; }
.dot.err { background: var(--red); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.3} }

.prog {
  width: 100%; height: 2px;
  background: var(--surface0); border-radius: 1px;
  overflow: hidden; margin-top: 6px;
}
.prog-fill {
  height: 100%; width: 0%;
  background: var(--accent); transition: width 0.25s;
}

/* ── Pipeline info ──────────────────────────────────── */
.pipe {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem; color: var(--overlay); line-height: 1.9;
}
.pipe .hi { color: var(--green); font-weight: 600; }
.pipe .dm { opacity: 0.35; }
.pipe hr { border: none; border-top: 1px solid var(--surface0); margin: 6px 0; }

/* ── Room Panel ─────────────────────────────────────── */
.room-sec { position: relative; }

#room-lobby input {
  width: 100%; margin-bottom: 6px;
}

.room-create-row {
  display: flex; gap: 4px;
}
.room-create-btn {
  flex: 1; padding: 8px 12px;
  background: var(--accent); color: var(--crust);
  border: none; border-radius: 7px;
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem; font-weight: 600;
  cursor: pointer; transition: all 0.12s;
  letter-spacing: 0.02em;
}
.room-create-btn:hover { filter: brightness(1.12); }
.room-create-btn:active { transform: scale(0.97); }

.room-shuffle-btn {
  width: 36px; display: flex;
  align-items: center; justify-content: center;
  background: var(--surface0); border: 1px solid var(--surface0);
  border-radius: 7px; color: var(--overlay);
  cursor: pointer; transition: all 0.12s;
}
.room-shuffle-btn:hover { color: var(--accent); border-color: var(--surface1); }

.room-sep {
  height: 1px; background: var(--surface0); margin: 10px 0 8px;
}

.room-join-hdr {
  font-size: 0.52rem; color: var(--overlay);
  text-transform: uppercase; letter-spacing: 0.1em;
  font-weight: 600; margin-bottom: 4px;
}

.room-list {
  display: flex; flex-direction: column; gap: 1px; margin-top: 2px;
}
.room-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 6px;
  cursor: pointer; transition: all 0.12s;
  border: 1px solid transparent;
}
.room-item:hover {
  background: var(--surface0); border-color: var(--surface0);
}
.room-item-dot {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--surface2); flex-shrink: 0;
  transition: background 0.15s;
}
.room-item:hover .room-item-dot { background: var(--accent); }
.room-item-name {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem; color: var(--subtext);
  transition: color 0.12s;
}
.room-item:hover .room-item-name { color: var(--text); }
.room-empty {
  font-size: 0.65rem; color: var(--surface2);
  padding: 4px 0; font-style: italic;
}

/* ── Room Active Card ──────────────────────────────── */
.room-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px; border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 5%, var(--crust));
  border: 1px solid color-mix(in srgb, var(--accent) 12%, var(--surface0));
  transition: all 0.3s;
}
.room-card.connecting {
  border-color: color-mix(in srgb, var(--yellow) 20%, var(--surface0));
  background: color-mix(in srgb, var(--yellow) 4%, var(--crust));
}

.room-beacon {
  position: relative; width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.beacon-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 1.5px solid var(--accent); opacity: 0.25;
  animation: beacon 2.4s ease-in-out infinite;
}
.beacon-core {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 40%, transparent);
  position: relative; z-index: 1;
}
.room-card.connecting .beacon-ring {
  border-color: var(--yellow);
  animation: beacon 1s ease-in-out infinite;
}
.room-card.connecting .beacon-core {
  background: var(--yellow);
  box-shadow: 0 0 10px color-mix(in srgb, var(--yellow) 40%, transparent);
}
@keyframes beacon {
  0%, 100% { transform: scale(0.85); opacity: 0.2; }
  50% { transform: scale(1.15); opacity: 0.4; }
}

.room-card-name {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88rem; font-weight: 600;
  color: var(--text); line-height: 1;
}
.room-card-meta {
  font-size: 0.65rem; color: var(--overlay); margin-top: 3px;
}

.room-leave {
  width: 100%; margin-top: 8px;
  padding: 7px 14px; border-radius: 7px;
  border: 1px solid color-mix(in srgb, var(--red) 12%, var(--surface0));
  background: color-mix(in srgb, var(--red) 5%, var(--surface0));
  color: var(--subtext);
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem; font-weight: 500;
  cursor: pointer; transition: all 0.15s;
}
.room-leave:hover {
  background: color-mix(in srgb, var(--red) 14%, var(--surface0));
  border-color: color-mix(in srgb, var(--red) 25%, var(--surface0));
  color: var(--red);
}

/* Room entrance animation */
.room-enter { animation: roomIn 0.22s ease-out; }
@keyframes roomIn {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

.hidden { display: none !important; }

/* ── Main area ──────────────────────────────────────── */
.main { display: flex; flex-direction: column; }

/* PTT zone */
.ptt {
  flex: 1; display: flex;
  flex-direction: column; align-items: center; justify-content: center;
  position: relative; min-height: 200px;
}
.ptt-btn {
  width: 130px; height: 130px; border-radius: 50%;
  border: 2px solid var(--surface1); background: var(--mantle);
  color: var(--overlay);
  font-family: 'Inter', sans-serif; font-size: 0.8rem; font-weight: 600;
  cursor: pointer; transition: all 0.15s;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  user-select: none; -webkit-user-select: none; touch-action: none;
}
.ptt-btn:hover { border-color: var(--surface2); background: var(--surface0); color: var(--subtext); }
.ptt-btn.recording {
  border-color: var(--red);
  background: color-mix(in srgb, var(--red) 8%, var(--base));
  color: var(--red);
}
.ptt-btn.sending {
  border-color: var(--yellow);
  background: color-mix(in srgb, var(--yellow) 6%, var(--base));
  color: var(--yellow);
}
.ptt-btn.disabled { opacity: 0.15; cursor: not-allowed; }
.ptt-btn .icon { font-size: 1.8rem; }
.ptt-hint { font-size: 0.65rem; color: var(--overlay); opacity: 0.4; margin-top: 8px; }

/* Stats strip */
.stat-row {
  position: absolute; bottom: 10px; left: 12px; right: 12px;
  display: flex; gap: 6px;
}
.stat {
  flex: 1; text-align: center; padding: 7px;
  background: var(--mantle); border-radius: 7px;
  border: 1px solid var(--surface0);
}
.stat-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88rem; font-weight: 600; color: var(--text);
}
.stat-val.green { color: var(--green); }
.stat-val.blue { color: var(--blue); }
.stat-lbl {
  font-size: 0.48rem; color: var(--overlay);
  text-transform: uppercase; letter-spacing: 0.08em; margin-top: 2px;
}

/* ── Log area ───────────────────────────────────────── */
.log-wrap {
  border-top: 1px solid var(--surface0);
  padding: 8px 12px;
  background: var(--mantle);
  flex-shrink: 0;
}
.log {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.68rem; line-height: 1.7;
  height: 140px; overflow-y: auto;
  color: var(--overlay);
}
.log::-webkit-scrollbar { width: 3px; }
.log::-webkit-scrollbar-thumb { background: var(--surface1); border-radius: 2px; }
.log .ok { color: var(--green); }
.log .info { color: var(--blue); }
.log .warn { color: var(--yellow); }
.log .dim { color: var(--surface2); }
.log .recv { color: var(--teal); }
.log .name { color: var(--accent); font-weight: 600; }

/* ── Hex Dump (collapsible token view) ─────────────── */
.hex-entry { margin: 1px 0; }
.hex-hdr {
  display: inline-flex; align-items: center; gap: 5px;
  cursor: pointer; user-select: none;
}
.hex-hdr:hover .hex-arrow { color: var(--accent); }
.hex-arrow {
  font-size: 0.55rem; color: var(--overlay);
  transition: transform 0.15s, color 0.15s;
  display: inline-block;
}
.hex-entry.open .hex-arrow { transform: rotate(90deg); }
.hex-body { display: none; }
.hex-entry.open .hex-body { display: block; }
.hex-grid {
  background: var(--crust);
  border: 1px solid var(--surface0);
  border-radius: 6px;
  padding: 8px 10px;
  margin-top: 3px;
  line-height: 1.9;
  max-height: 110px;
  overflow-y: auto;
}
.hex-grid::-webkit-scrollbar { width: 3px; }
.hex-grid::-webkit-scrollbar-thumb { background: var(--surface1); border-radius: 2px; }
.hx {
  display: inline-block;
  width: 1.7em;
  text-align: center;
  font-size: 0.6rem;
  color: var(--surface2);
}
.hex-sent .hx { color: color-mix(in srgb, var(--green) 40%, var(--surface2)); }
.hex-recv .hx { color: color-mix(in srgb, var(--teal) 40%, var(--surface2)); }

/* ── Room item live badge ──────────────────────────── */
.room-item-dot.on { background: var(--green); }
.room-item-count {
  margin-left: auto;
  font-size: 0.55rem;
  padding: 1px 7px;
  background: var(--surface0);
  border-radius: 8px;
  color: var(--overlay);
  font-family: 'JetBrains Mono', monospace;
}
.room-item-join {
  margin-left: auto;
  font-size: 0.55rem;
  padding: 1px 8px;
  border-radius: 6px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 8%, transparent);
  opacity: 0;
  transition: opacity 0.12s;
  font-weight: 500;
}
.room-item-count + .room-item-join { margin-left: 4px; }
.room-item:hover .room-item-join { opacity: 1; }

/* ── Mobile ────────────────────────────────────────── */
@media (max-width: 640px) {
  body { overflow: hidden; height: 100dvh; }
  .app {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
    border: none;
    grid-template-columns: 1fr;
    grid-template-rows: 42px auto 1fr;
    overflow: hidden;
  }

  /* ── Header ── */
  .hdr { padding: 0 12px; gap: 8px; }
  .hdr h1 { font-size: 0.85rem; }
  .hdr-stats { font-size: 0.6rem; gap: 6px; }
  .themes { display: none; }

  /* ── Sidebar → compact setup strip ── */
  .side {
    border-right: none;
    border-bottom: 1px solid var(--surface0);
    overflow: visible;
    max-height: none;
  }
  .sec { padding: 6px 12px; }
  .sec:last-child { flex: initial; border-bottom: none; display: none; } /* hide Pipeline */

  /* Hide username on mobile — auto-generated is fine */
  .sec:first-child { display: none; }

  /* ── Room section — compact ── */
  .room-sec { padding: 8px 12px 6px !important; }
  .room-sec .sec-title { margin-bottom: 4px; }
  #room-lobby input { padding: 6px 8px; font-size: 0.72rem; margin-bottom: 4px; }
  .room-create-btn { padding: 6px 10px; font-size: 0.68rem; }
  .room-shuffle-btn { width: 32px; }
  .room-sep { margin: 6px 0 4px; }
  .room-join-hdr { font-size: 0.48rem; margin-bottom: 2px; }

  /* Room list: max 2 items visible, scrollable */
  .room-list {
    max-height: 58px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .room-item { padding: 4px 8px; }
  .room-item-name { font-size: 0.65rem; }
  .room-item-join { opacity: 1; font-size: 0.5rem; padding: 1px 6px; }

  /* Connected card — compact */
  .room-card { padding: 10px; gap: 10px; border-radius: 8px; }
  .room-beacon { width: 24px; height: 24px; }
  .beacon-core { width: 8px; height: 8px; }
  .room-card-name { font-size: 0.78rem; }
  .room-card-meta { font-size: 0.6rem; }
  .room-leave { padding: 5px 12px; font-size: 0.65rem; margin-top: 6px; }

  /* ── Codec section — inline strip ── */
  .sec:nth-child(3) {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 6px 12px !important;
  }
  .sec:nth-child(3) .sec-title { margin-bottom: 0; }
  .sec:nth-child(3) .status { margin: 0; font-size: 0.68rem; }
  .sec:nth-child(3) .btn-full {
    width: auto; margin: 0;
    padding: 5px 12px; font-size: 0.65rem;
  }
  .sec:nth-child(3) .btn {
    background: var(--accent);
    color: var(--crust);
    font-weight: 600;
    border-color: var(--accent);
  }
  .sec:nth-child(3) .btn-dim { display: none; }
  .sec:nth-child(3) .prog {
    width: 100%; margin-top: 0;
    order: 99; /* push progress bar to end */
  }

  /* ── PTT — hero element on mobile ── */
  .ptt { min-height: 160px; }
  .ptt-btn { width: 120px; height: 120px; font-size: 0.75rem; }
  .ptt-btn .icon { font-size: 1.6rem; }
  .ptt-hint { font-size: 0.58rem; margin-top: 6px; }
  .stat-row { left: 6px; right: 6px; bottom: 6px; gap: 4px; }
  .stat { padding: 4px; }
  .stat-val { font-size: 0.72rem; }
  .stat-lbl { font-size: 0.4rem; }

  /* ── Log — compact ── */
  .log-wrap { padding: 4px 10px; }
  .log { height: 80px; font-size: 0.58rem; line-height: 1.6; }
}
