/* ================================
   ClawHall — Design System
   ================================ */
:root {
  /* Colors */
  --bg-primary: #0a0a1a;
  --bg-secondary: #111128;
  --bg-tertiary: #1a1a3e;
  --bg-surface: rgba(255, 255, 255, 0.04);
  --bg-surface-hover: rgba(255, 255, 255, 0.08);
  --bg-glass: rgba(255, 255, 255, 0.06);
  --bg-glass-strong: rgba(255, 255, 255, 0.1);

  --text-primary: #e8e8f0;
  --text-secondary: #9090b0;
  --text-muted: #606080;
  --text-accent: #a78bfa;

  --accent-purple: #a78bfa;
  --accent-cyan: #06b6d4;
  --accent-green: #34d399;
  --accent-orange: #fb923c;
  --accent-pink: #f472b6;

  --gradient-primary: linear-gradient(135deg, #a78bfa 0%, #06b6d4 100%);
  --gradient-bg: linear-gradient(160deg, #0a0a1a 0%, #111128 40%, #0f0f2a 100%);

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(167, 139, 250, 0.3);

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px rgba(167, 139, 250, 0.15);

  /* Spacing */
  --sidebar-width: 280px;
  --members-width: 220px;

  /* Typography */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ================================
   Reset & Base
   ================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--gradient-bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

input, textarea, button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  outline: none;
}

.hidden {
  display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ================================
   Login Screen
   ================================ */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gradient-bg);
  z-index: 100;
}

.login-card {
  position: relative;
  z-index: 2;
  width: 380px;
  max-width: 90vw;
  padding: 48px 36px;
  background: var(--bg-glass-strong);
  backdrop-filter: blur(40px);
  border: 1px solid var(--border-subtle);
  border-radius: 24px;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  text-align: center;
  animation: cardIn 0.6s var(--ease) both;
}

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

.login-logo {
  margin-bottom: 32px;
}

.logo-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.login-logo h1 {
  font-size: 28px;
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-group {
  text-align: left;
}

.input-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 15px;
  transition: all 0.2s var(--ease);
  outline: none;
}

.input-group input:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.15);
  background: var(--bg-surface-hover);
}

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

.btn-primary {
  padding: 12px 24px;
  background: var(--gradient-primary);
  color: white;
  font-weight: 600;
  font-size: 15px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  position: relative;
  overflow: hidden;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 20px rgba(167, 139, 250, 0.3);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-secondary {
  padding: 10px 20px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-weight: 500;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  transition: all 0.2s var(--ease);
}

.btn-secondary:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text-secondary);
  transition: all 0.2s var(--ease);
}

.btn-icon:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

/* Login particles */
.login-particles {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 1;
}

.login-particles::before,
.login-particles::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.3;
  animation: drift 8s ease-in-out infinite alternate;
}

.login-particles::before {
  width: 400px;
  height: 400px;
  background: var(--accent-purple);
  top: -100px;
  right: -100px;
}

.login-particles::after {
  width: 300px;
  height: 300px;
  background: var(--accent-cyan);
  bottom: -80px;
  left: -80px;
  animation-delay: -4s;
}

@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(40px, 30px) scale(1.1); }
}

/* ================================
   App Layout
   ================================ */
.app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ================================
   Sidebar
   ================================ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s var(--ease);
  z-index: 20;
}

.sidebar-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-toggle {
  color: var(--text-muted);
  transition: color 0.2s;
}

.sidebar-toggle:hover {
  color: var(--text-primary);
}

.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 20px 12px;
}

.sidebar-section-header h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.rooms-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 8px;
}

.room-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s var(--ease);
  color: var(--text-secondary);
}

.room-item:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.room-item.active {
  background: rgba(167, 139, 250, 0.12);
  color: var(--text-accent);
  border: 1px solid rgba(167, 139, 250, 0.15);
}

.room-item .room-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.room-item .room-name {
  flex: 1;
  font-weight: 500;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-item .room-badge {
  background: var(--accent-purple);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: white;
  flex-shrink: 0;
}

#user-display-name {
  font-weight: 500;
  font-size: 13px;
  color: var(--text-primary);
}

/* ================================
   Mobile sidebar
   ================================ */
.mobile-sidebar-btn {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 15;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--bg-glass-strong);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

/* ================================
   Main Content
   ================================ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* Empty state */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 12px;
}

.empty-icon {
  font-size: 56px;
  animation: float 3s ease-in-out infinite;
}

.empty-state h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 14px;
}

/* Chat view */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Chat header */
.chat-header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
}

.chat-header-info h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.chat-room-desc {
  font-size: 12px;
  color: var(--text-muted);
}

.member-count {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 13px;
}

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
}

.messages-list {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message {
  display: flex;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  transition: background 0.15s var(--ease);
  animation: msgIn 0.25s var(--ease) both;
}

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

.message:hover {
  background: var(--bg-surface);
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: white;
  flex-shrink: 0;
  margin-top: 2px;
}

.message-avatar.human {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

.message-avatar.agent {
  background: linear-gradient(135deg, #06b6d4, #34d399);
  position: relative;
}

.message-avatar.agent::after {
  content: '⚡';
  position: absolute;
  bottom: -2px;
  right: -4px;
  font-size: 11px;
}

.message-body {
  flex: 1;
  min-width: 0;
}

.message-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.message-username {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

.message-username.agent {
  color: var(--accent-cyan);
}

.message-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
}

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

/* System messages */
.message-system {
  text-align: center;
  padding: 8px 0;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
}

/* Chat input */
.chat-input-area {
  padding: 12px 24px 16px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
}

.chat-input-wrapper {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}

.chat-input-wrapper:focus-within {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.1);
}

#message-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.4;
  resize: none;
  max-height: 120px;
  padding: 4px 0;
}

#message-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--gradient-primary);
  color: white;
  transition: all 0.2s var(--ease);
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 2px 12px rgba(167, 139, 250, 0.3);
}

.send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ================================
   Members Panel
   ================================ */
.members-panel {
  width: var(--members-width);
  min-width: var(--members-width);
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  border-left: 1px solid var(--border-subtle);
  overflow-y: auto;
}

.members-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.members-header h3 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.members-list {
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  transition: background 0.15s var(--ease);
}

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

.member-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  color: white;
  flex-shrink: 0;
}

.member-avatar.human {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

.member-avatar.agent {
  background: linear-gradient(135deg, #06b6d4, #34d399);
}

.member-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.member-tag {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-cyan);
  margin-left: auto;
}

/* ================================
   Modal
   ================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: 400px;
  max-width: 90vw;
  padding: 28px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  animation: cardIn 0.3s var(--ease) both;
}

.modal-card h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text-primary);
}

.modal-card .input-group {
  margin-bottom: 14px;
}

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

/* ================================
   Responsive
   ================================ */
@media (max-width: 900px) {
  .members-panel {
    display: none;
  }
}

@media (max-width: 640px) {
  .sidebar {
    position: fixed;
    inset: 0;
    width: 100%;
    min-width: 100%;
    transform: translateX(-100%);
    z-index: 30;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-sidebar-btn {
    display: flex;
  }

  .chat-header {
    padding-left: 56px;
  }

  .messages-list {
    padding: 0 16px;
  }

  .chat-input-area {
    padding: 8px 16px 12px;
  }
}

/* ================================
   Admin Controls
   ================================ */
.msg-del-btn {
  opacity: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: var(--bg-surface-hover);
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  transition: all 0.2s var(--ease);
  margin-left: 6px;
  border: none;
  cursor: pointer;
  padding: 0;
}

.message:hover .msg-del-btn {
  opacity: 1;
}

.msg-del-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.kick-btn {
  opacity: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: var(--bg-surface-hover);
  color: var(--text-muted);
  font-size: 10px;
  margin-left: auto;
  transition: all 0.2s var(--ease);
  border: none;
  cursor: pointer;
  padding: 0;
}

.member-item:hover .kick-btn {
  opacity: 1;
}

.kick-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.room-del-btn {
  opacity: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1;
  transition: all 0.2s var(--ease);
  margin-left: auto;
  border: none;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.room-item:hover .room-del-btn {
  opacity: 1;
}

.room-del-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

/* ================================
   Login Enhancements
   ================================ */
.login-options {
  display: flex;
  align-items: center;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.toggle-label input[type="checkbox"] {
  accent-color: var(--accent-purple);
}

.login-error {
  color: #ef4444;
  font-size: 13px;
  text-align: center;
  padding: 8px;
  background: rgba(239, 68, 68, 0.1);
  border-radius: 8px;
  border: 1px solid rgba(239, 68, 68, 0.2);
}

/* ================================
   Token Display Modal
   ================================ */
.token-display {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  margin-bottom: 16px;
}

.token-display code {
  flex: 1;
  font-size: 13px;
  font-family: 'Courier New', monospace;
  color: var(--accent-cyan);
  word-break: break-all;
  user-select: all;
}

/* ================================
   Sidebar Footer
   ================================ */
.sidebar-footer-actions {
  display: flex;
  gap: 4px;
}

.sidebar-footer-actions .btn-icon:hover {
  color: #ef4444;
}
