/* IPTinCan Web Client — Clean sage green design */

:root {
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --surface-hover: #F5F5F5;
  --primary: #5B8C5A;
  --primary-hover: #4A7A49;
  --primary-light: #E8F0E8;
  --primary-lightest: #F2F7F2;
  --text-primary: #1A1A2E;
  --text-secondary: #6B7280;
  --text-tertiary: #9CA3AF;
  --border: #E5E5EA;
  --border-light: #F0F0F0;
  --danger: #EF4444;
  --danger-hover: #DC2626;
  --success: #5B8C5A;
  --selected-blue: #3B82F6;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

input, button, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9CA3AF; }

/* ─── Login Screen ─── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
  background: linear-gradient(135deg, var(--primary-lightest) 0%, var(--bg) 50%, #F0F4FF 100%);
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-card .logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.login-card .logo-icon {
  width: 36px;
  height: 36px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 16px;
}

.login-card .logo-text {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.login-card .subtitle {
  color: var(--text-tertiary);
  font-size: 13px;
  margin-bottom: 28px;
}

.login-card .divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-tertiary);
  font-size: 12px;
}

.login-card .divider::before,
.login-card .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.form-group {
  margin-bottom: 14px;
  text-align: left;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(91, 140, 90, 0.15);
}

.form-input::placeholder {
  color: var(--text-tertiary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
  outline: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: white;
  width: 100%;
  padding: 12px;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  background: #B0C4AF;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--surface-hover);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-full);
  border: none;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  font-size: 18px;
}

.btn-icon:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.btn-icon.active {
  background: var(--primary);
  color: white;
}

.btn-icon.danger:hover {
  background: #FEE2E2;
  color: var(--danger);
}

.login-error {
  background: #FEF2F2;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}

.login-error.visible {
  display: block;
}

.login-mode-toggle {
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

.login-mode-toggle a {
  color: var(--primary);
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
}

.login-mode-toggle a:hover {
  text-decoration: underline;
}

/* ─── Call Screen ─── */
.call-screen {
  display: none;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
}

.call-screen.active {
  display: flex;
}

/* ─── Top Bar ─── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 52px;
  flex-shrink: 0;
}

.top-bar .server-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-bar .server-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--text-primary);
}

.top-bar .channel-name {
  color: var(--text-secondary);
  font-size: 13px;
}

.top-bar .channel-name::before {
  content: '#';
  color: var(--text-tertiary);
  margin-right: 2px;
}

.top-bar .user-count {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-tertiary);
  font-size: 12px;
}

.top-bar .user-count .dot {
  width: 8px;
  height: 8px;
  background: var(--success);
  border-radius: 50%;
}

/* ─── Main Content (users + chat) ─── */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── User Sidebar ─── */
.user-sidebar {
  width: 200px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.user-sidebar-header {
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border-light);
}

.user-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: default;
}

.user-item:hover {
  background: var(--surface-hover);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: white;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 11px;
  color: var(--text-tertiary);
}

.user-item .muted-icon {
  color: var(--text-tertiary);
  font-size: 12px;
}

/* ─── Voice Talking Indicator ─── */
.user-avatar.talking {
  box-shadow: 0 0 0 3px var(--success);
  animation: talk-pulse 0.8s ease-in-out infinite alternate;
}

@keyframes talk-pulse {
  from { box-shadow: 0 0 0 2px var(--success); }
  to { box-shadow: 0 0 0 4px rgba(91, 140, 90, 0.4); }
}

.control-bar .btn-icon.active {
  background: var(--danger);
  color: white;
}

.control-bar .btn-icon.active:hover {
  background: var(--danger-hover);
}

/* ─── Chat Area ─── */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.chat-group {
  margin-bottom: 16px;
}

.chat-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.chat-group-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
}

.chat-group-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
}

.chat-group-time {
  font-size: 11px;
  color: var(--text-tertiary);
}

.chat-msg {
  padding: 2px 0 2px 46px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  word-wrap: break-word;
}

.chat-msg:hover {
  background: var(--surface-hover);
  border-radius: var(--radius-sm);
}

.chat-system {
  padding: 6px 0;
  font-size: 12px;
  color: var(--text-tertiary);
  font-style: italic;
  text-align: center;
}

/* ─── Chat Input ─── */
.chat-input-area {
  padding: 12px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  gap: 10px;
}

.chat-input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input:focus {
  border-color: var(--primary);
}

.chat-input::placeholder {
  color: var(--text-tertiary);
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  border: none;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: background-color 0.2s;
  flex-shrink: 0;
}

.chat-send-btn:hover {
  background: var(--primary-hover);
}

.typing-indicator {
  font-size: 12px;
  color: var(--text-tertiary);
  height: 18px;
  padding: 2px 0;
}

/* ─── Control Bar ─── */
.control-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.control-bar .btn-icon {
  width: 44px;
  height: 44px;
  font-size: 20px;
  box-shadow: var(--shadow-sm);
}

.control-bar .end-call {
  background: var(--danger);
  color: white;
}

.control-bar .end-call:hover {
  background: var(--danger-hover);
}

/* ─── Invite Panel ─── */
.invite-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.invite-overlay.visible {
  display: flex;
}

.invite-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px;
  width: 100%;
  max-width: 420px;
  margin: 20px;
}

.invite-panel h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.invite-panel .desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.invite-link-box {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.invite-link-box input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
}

.invite-link-box .btn {
  flex-shrink: 0;
}

.invite-full-url {
  margin-top: 8px;
  font-size: 0.75rem;
  color: #888;
  word-break: break-all;
}

.invite-full-label {
  margin-right: 4px;
}

.invite-full-link {
  color: #5B8C5A;
  text-decoration: underline;
}

.invite-panel .close-btn {
  margin-top: 12px;
  width: 100%;
}

/* ─── Voice Message Recording ─── */
.vm-record-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: #5B8C5A;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.vm-record-btn:hover {
  background: rgba(91, 140, 90, 0.1);
}

.vm-recording {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(231, 76, 60, 0.06);
  border-radius: 8px;
  margin-top: 6px;
}

.vm-rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e74c3c;
  animation: rec-pulse 1s ease-in-out infinite;
}

@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.vm-rec-text {
  font-size: 13px;
  color: #e74c3c;
  font-weight: 500;
  flex: 1;
}

.vm-rec-stop {
  padding: 4px 14px;
  border-radius: 6px;
  border: none;
  background: #5B8C5A;
  color: white;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.vm-rec-stop:hover { background: #4a7a49; }

.vm-rec-cancel {
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid #ddd;
  background: transparent;
  color: #999;
  font-size: 12px;
  cursor: pointer;
}

.vm-rec-cancel:hover { color: #e74c3c; border-color: #e74c3c; }

/* ─── Voice Message Bubbles ─── */
.voice-msg-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(91, 140, 90, 0.08);
  border: 1px solid rgba(91, 140, 90, 0.2);
  border-radius: 12px;
  padding: 8px 12px;
  max-width: 320px;
}

.vm-play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #5B8C5A;
  color: white;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.vm-play-btn:hover {
  background: #4a7a49;
}

.vm-play-btn.playing {
  background: #e67e22;
}

.vm-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.vm-bar {
  height: 4px;
  background: rgba(91, 140, 90, 0.2);
  border-radius: 2px;
}

.vm-duration {
  font-size: 11px;
  color: rgba(91, 140, 90, 0.7);
  font-weight: 500;
}

.vm-dismiss {
  background: none;
  border: none;
  color: #999;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}

.vm-dismiss:hover {
  color: #e74c3c;
}

/* ─── Toast Notifications ─── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 12px 18px;
  font-size: 13px;
  color: var(--text-primary);
  border-left: 4px solid var(--primary);
  animation: toast-in 0.3s ease-out;
  max-width: 320px;
}

.toast.error {
  border-left-color: var(--danger);
}

.toast.fade-out {
  animation: toast-out 0.3s ease-in forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(40px); }
}

/* ─── Connection Status ─── */
.conn-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-tertiary);
}

.conn-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.conn-status .dot.disconnected {
  background: var(--danger);
}

/* ─── Loading spinner ─── */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Empty state ─── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-tertiary);
  gap: 8px;
  font-size: 14px;
}

.empty-state .icon {
  font-size: 48px;
  opacity: 0.3;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  .user-sidebar {
    display: none;
  }

  .top-bar {
    padding: 10px 14px;
  }

  .chat-messages {
    padding: 12px 14px;
  }

  .chat-input-area {
    padding: 10px 14px;
  }

  .control-bar {
    padding: 10px 14px;
  }

  .login-card {
    padding: 28px 24px;
  }
}

@media (max-width: 480px) {
  .login-card {
    box-shadow: none;
    background: transparent;
    padding: 20px 16px;
  }

  .control-bar .btn-icon {
    width: 38px;
    height: 38px;
    font-size: 16px;
  }
}

/* ─── Utility ─── */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}
