/* ============================================
   Minimal Clean Theme
   Ultra-clean dark UI with green accent
   ============================================ */

:root {
  --bg-deep: #0f0f17;
  --bg-primary: #16161f;
  --bg-secondary: #1c1c28;
  --bg-tertiary: #222230;
  --bg-hover: #26263a;
  --bg-active: #2a2a42;
  --text-primary: #e8e8ed;
  --text-secondary: #8b8b9e;
  --text-muted: #5c5c72;
  --accent: #00d26a;
  --accent-hover: #00b85c;
  --accent-soft: rgba(0, 210, 106, 0.12);
  --accent-glow: rgba(0, 210, 106, 0.2);
  --danger: #ff4d6a;
  --danger-hover: #e0435c;
  --border: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.03);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.5);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --bubble-own: #1a3a2a;
  --bubble-other: #1c1c28;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#root {
  height: 100%;
  width: 100%;
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar {
  width: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* ---- Buttons ---- */
button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  transition: all var(--transition);
  letter-spacing: 0.01em;
}

button:active {
  transform: scale(0.97);
}

/* ---- Inputs ---- */
input[type="text"],
input[type="email"],
input[type="password"],
textarea {
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

/* ============================================
   Auth Page
   ============================================ */
.auth-page {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  background-image: radial-gradient(ellipse at 50% 0%, rgba(0, 210, 106, 0.04) 0%, transparent 60%);
}

.auth-card {
  width: 90%;
  max-width: 400px;
  padding: 40px 36px;
  border-radius: var(--radius-xl);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xl);
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
  text-align: center;
  letter-spacing: -0.02em;
}

.auth-card p {
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 28px;
  font-size: 14px;
}

.auth-card .error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 16px;
  text-align: center;
  padding: 10px;
  background: rgba(255, 77, 106, 0.08);
  border-radius: var(--radius-sm);
}

.auth-card input {
  width: 100%;
  padding: 13px 16px;
  margin-bottom: 12px;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn-primary:disabled {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  width: 100%;
  background: transparent;
  color: var(--accent);
  margin-top: 10px;
}

.btn-secondary:hover {
  background: var(--accent-soft);
}

.btn-danger {
  background: var(--danger);
  color: white;
  font-weight: 500;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-icon {
  background: transparent;
  color: var(--text-muted);
  padding: 6px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

/* ============================================
   Main App Layout
   ============================================ */
.app {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
  width: 300px;
  min-width: 260px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header h2 {
  margin: 0 0 14px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.user-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-secondary);
  font-size: 13px;
  gap: 10px;
}

.user-info span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.room-item {
  padding: 12px 20px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background var(--transition);
  margin: 0 8px;
  border-radius: var(--radius-md);
}

.room-item:hover {
  background: var(--bg-hover);
}

.room-item.active {
  background: var(--accent-soft);
}

.room-item.active .room-name {
  color: var(--accent);
}

.room-name {
  font-weight: 500;
  font-size: 14px;
  color: var(--text-primary);
}

.room-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.new-room {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.new-room input {
  flex: 1;
  padding: 10px 14px;
  margin: 0;
  font-size: 13px;
}

.new-room button {
  padding: 0 16px;
  font-size: 16px;
  border-radius: var(--radius-md);
  min-width: 44px;
}

/* ============================================
   Chat Area
   ============================================ */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-deep);
  min-width: 0;
}

.chat-header {
  padding: 16px 24px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.chat-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.chat-header .actions {
  display: flex;
  gap: 8px;
}

.chat-header .actions .btn-danger {
  font-size: 12px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
}

/* ============================================
   Messages
   ============================================ */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 20px;
}

/* ---- Message Bubbles ---- */
.message {
  max-width: 65%;
  min-width: 80px;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  position: relative;
  word-wrap: break-word;
  animation: msgIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.message.own {
  align-self: flex-end;
  background: var(--bubble-own);
  border-bottom-right-radius: 4px;
}

.message.other {
  align-self: flex-start;
  background: var(--bubble-other);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message-sender {
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 3px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.message-text {
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--text-primary);
}

/* ---- Media ---- */
.message-media {
  margin-top: 6px;
}

.message-media img {
  max-width: 280px;
  max-height: 320px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: block;
  transition: opacity var(--transition);
}

.message-media img:hover {
  opacity: 0.9;
}

.message-media video,
.message-media audio {
  max-width: 280px;
  border-radius: var(--radius-md);
  display: block;
}

.message-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  text-decoration: none;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition);
}

.message-file:hover {
  background: rgba(255, 255, 255, 0.08);
}

.message-download {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  padding: 5px 10px;
  background: rgba(255, 255, 255, 0.05);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--accent);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition);
}

.message-download:hover {
  background: var(--accent-soft);
}

.message-time {
  font-size: 10px;
  color: var(--text-muted);
  text-align: right;
  margin-top: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}

.message:hover .message-time {
  opacity: 1;
}

.message-actions {
  position: absolute;
  top: -8px;
  right: -8px;
  display: none;
}

.message:hover .message-actions {
  display: block;
}

/* ============================================
   Input Area
   ============================================ */
.input-area {
  padding: 14px 20px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-shrink: 0;
}

.input-area textarea {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  max-height: 140px;
  width: 100%;
  padding: 12px 18px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  resize: none;
  font-size: 14px;
  line-height: 1.4;
  overflow-y: auto;
  white-space: pre-wrap;
}

.input-area textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input-area textarea::placeholder {
  color: var(--text-muted);
}

.input-area button {
  height: 44px;
  padding: 0 20px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  width: auto;
  flex-shrink: 0;
}

.input-area .btn-primary {
  width: auto;
  min-width: 80px;
}

.file-input {
  display: none;
}

.attach-btn {
  width: 44px;
  min-width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
  transition: all var(--transition);
}

.attach-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.attach-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   Modal
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: overlayIn 0.15s ease;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg-primary);
  padding: 28px;
  border-radius: var(--radius-xl);
  max-width: 420px;
  width: 90%;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xl);
  animation: modalIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal h3 {
  margin: 0 0 10px;
  font-size: 17px;
  font-weight: 600;
}

.modal p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.55;
  font-size: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-actions button {
  width: auto;
}

/* Sidebar toggle — hidden on desktop, visible on mobile */
.sidebar-toggle {
  display: none;
}

/* ============================================
   Mobile
   ============================================ */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    inset: 0;
    z-index: 10;
    width: 100%;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .sidebar.hidden {
    transform: translateX(-100%);
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
  }

  .sidebar-toggle:hover {
    background: var(--bg-secondary);
  }

  .message {
    max-width: 85%;
  }

  .message-media img,
  .message-media video,
  .message-media audio {
    max-width: 220px;
  }
}

/* ============================================
   Admin
   ============================================ */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 14px;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.admin-table th,
.admin-table td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.admin-table th {
  background: var(--bg-secondary);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
}

.admin-table td {
  background: var(--bg-primary);
}

.admin-table tr:last-child td {
  border-bottom: none;
}

.admin-select {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  font-size: 13px;
  font-family: inherit;
  margin-top: 12px;
  min-width: 240px;
}

.admin-messages {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.admin-message {
  background: var(--bg-primary);
  padding: 14px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.admin-meta {
  color: var(--text-muted);
  font-size: 12px;
  margin-left: 6px;
}

.admin-time {
  color: var(--text-muted);
  font-size: 12px;
  float: right;
}

/* ============================================
   Call UI
   ============================================ */

/* Header call buttons */
.call-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all var(--transition);
}

.call-btn:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.call-badge {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-weight: 600;
}

/* Incoming call banner */
.incoming-call-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  animation: slideDown 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.incoming-call-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.incoming-call-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  animation: pulse 1.5s ease infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { box-shadow: 0 0 0 10px transparent; }
}

.incoming-call-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

.incoming-call-type {
  font-size: 12px;
  color: var(--text-secondary);
}

.incoming-call-actions {
  display: flex;
  gap: 8px;
}

.call-accept-btn {
  padding: 8px 20px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
}

.call-accept-btn:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 14px var(--accent-glow);
}

.call-reject-btn {
  padding: 8px 20px;
  border-radius: var(--radius-full);
  background: var(--danger);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
}

.call-reject-btn:hover {
  background: var(--danger-hover);
}

/* Call overlay (full-screen) */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: overlayIn 0.3s ease;
}

.call-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
  max-width: 900px;
  padding: 24px;
}

.call-status {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.call-videos {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  align-items: center;
  width: 100%;
  position: relative;
  min-height: 300px;
}

.call-video-wrapper {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
}

.call-video-wrapper.remote {
  width: 100%;
  max-width: 640px;
  aspect-ratio: 16 / 9;
}

.call-video-wrapper.local.solo {
  width: 100%;
  max-width: 480px;
  aspect-ratio: 16 / 9;
}

.call-video-wrapper.local.pip {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 160px;
  aspect-ratio: 16 / 9;
  z-index: 10;
  box-shadow: var(--shadow-lg);
  border: 2px solid var(--border);
}

.call-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: var(--bg-tertiary);
}

.call-video-label {
  position: absolute;
  bottom: 8px;
  left: 8px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: rgba(0, 0, 0, 0.5);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  backdrop-filter: blur(4px);
}

/* Call controls */
.call-controls {
  display: flex;
  gap: 16px;
  align-items: center;
}

.call-control-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.call-control-btn:hover {
  background: var(--bg-hover);
}

.call-control-btn.active {
  background: var(--danger);
  color: #fff;
}

.call-control-btn.hangup {
  background: var(--danger);
  color: #fff;
  width: 60px;
  height: 60px;
  font-size: 24px;
  transform: rotate(135deg);
}

.call-control-btn.hangup:hover {
  background: var(--danger-hover);
}

/* Mobile adjustments for calls */
@media (max-width: 768px) {
  .call-video-wrapper.local.pip {
    width: 100px;
    bottom: 8px;
    right: 8px;
  }

  .call-control-btn {
    width: 46px;
    height: 46px;
    font-size: 18px;
  }

  .call-control-btn.hangup {
    width: 52px;
    height: 52px;
    font-size: 20px;
  }

  .incoming-call-banner {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }
}
