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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #1c2a4a;
  --accent: #e94560;
  --accent-glow: rgba(233, 69, 96, 0.3);
  --text: #eee;
  --text-dim: #888;
  --success: #4ade80;
  --sent-bg: #0f3460;
  --radius: 12px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

#app { height: 100dvh; display: flex; flex-direction: column; }

.hidden { display: none !important; }

/* ===== LOGIN ===== */
#login-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; padding: 1.5rem;
  overflow-y: auto;
}
#login-screen h1 { font-size: 2rem; margin-bottom: 0.25rem; }
.subtitle { color: var(--text-dim); margin-bottom: 2rem; }

.login-form {
  width: 100%; max-width: 400px;
  display: flex; flex-direction: column; gap: 1.25rem;
}
.form-group { display: flex; flex-direction: column; gap: 0.35rem; }
.form-group label { font-size: 0.85rem; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.form-group input {
  width: 100%; padding: 0.85rem 1rem;
  background: var(--surface); border: 1px solid #333;
  border-radius: var(--radius); color: var(--text);
  font-size: 1rem; outline: none; transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--accent); }
.hint { font-size: 0.8rem; color: var(--text-dim); }
.link-btn {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-size: 0.8rem; padding: 0; text-decoration: underline;
}
.warning {
  font-size: 0.8rem; color: #f59e0b; background: rgba(245, 158, 11, 0.1);
  padding: 0.75rem; border-radius: var(--radius); line-height: 1.4;
}

#login-btn {
  padding: 1rem; background: var(--accent);
  border: none; border-radius: var(--radius);
  color: white; font-size: 1.1rem; font-weight: 600;
  cursor: pointer; transition: opacity 0.2s;
}
#login-btn:active { opacity: 0.8; }

/* ===== MAIN SCREEN ===== */
#main-screen { display: flex; flex-direction: column; height: 100%; }

header {
  padding: 0.75rem 1rem; display: flex; justify-content: space-between;
  align-items: center; border-bottom: 1px solid #333;
  flex-shrink: 0;
}
.header-left h1 { font-size: 1.1rem; }
.header-right { display: flex; align-items: center; gap: 0.75rem; }

#status { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text-dim); }
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; flex-shrink: 0;
}
.dot.connected { background: var(--success); box-shadow: 0 0 6px var(--success); }
.dot.disconnected { background: var(--accent); }

.toggle { display: flex; align-items: center; gap: 0.3rem; cursor: pointer; font-size: 1.1rem; }
.toggle input { display: none; }
.toggle-label { opacity: 0.5; transition: opacity 0.2s; }
.toggle input:checked + .toggle-label { opacity: 1; }

.icon-btn {
  background: none; border: none; color: var(--text-dim);
  font-size: 1.2rem; cursor: pointer; padding: 0.25rem;
}
.icon-btn:active { color: var(--text); }

/* ===== MESSAGES ===== */
#messages {
  flex: 1; overflow-y: auto; padding: 1rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  -webkit-overflow-scrolling: touch;
}
.empty-state {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); text-align: center; font-size: 0.95rem;
}

.message {
  padding: 0.6rem 0.85rem; border-radius: var(--radius);
  max-width: 85%; font-size: 0.95rem; line-height: 1.4;
  word-wrap: break-word;
}
.message.sent { background: var(--sent-bg); align-self: flex-end; border-bottom-right-radius: 4px; }
.message.received { background: var(--surface2); align-self: flex-start; border-bottom-left-radius: 4px; }
.message .meta { font-size: 0.7rem; color: var(--text-dim); margin-top: 0.2rem; }
.message .voice-row { display: flex; align-items: center; gap: 0.5rem; }
.message .voice-row .play-btn {
  background: var(--accent); border: none; color: white;
  width: 36px; height: 36px; border-radius: 50%;
  font-size: 1rem; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.message .voice-row .play-btn:active { opacity: 0.7; }
.message .voice-row .voice-info { font-size: 0.85rem; color: var(--text-dim); }
.message audio {
  width: 100%; max-width: 250px; margin-top: 0.4rem;
  height: 32px;
}

/* ===== CONTROLS ===== */
#controls {
  padding: 1rem 1rem 1.5rem; display: flex; flex-direction: column;
  align-items: center; gap: 0.75rem;
  border-top: 1px solid #333; flex-shrink: 0;
  background: var(--bg);
}

.ptt-button {
  width: 130px; height: 130px; border-radius: 50%;
  background: var(--surface); border: 4px solid var(--accent);
  color: var(--text); cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 0.15rem;
  transition: all 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
.ptt-button:active, .ptt-button.recording {
  background: var(--accent);
  box-shadow: 0 0 50px var(--accent-glow);
  transform: scale(1.08);
}
.ptt-icon { font-size: 2.5rem; pointer-events: none; }
.ptt-label { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; pointer-events: none; }

#recording-indicator {
  color: var(--accent); font-weight: 600; font-size: 0.9rem;
  display: flex; align-items: center; gap: 0.5rem;
  height: 1.5rem;
}
#recording-indicator.hidden { visibility: hidden; }

.pulse {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 0.8s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.4); }
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 2px; }

/* Safe area for notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #controls { padding-bottom: calc(1.5rem + env(safe-area-inset-bottom)); }
}
