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

:root {
  --primary: #4a90d9;
  --primary-dark: #357abd;
  --bg: #f5f5f5;
  --sidebar-bg: #2c3e50;
  --sidebar-text: #ecf0f1;
  --msg-bg: #ffffff;
  --msg-self: #4a90d9;
  --msg-system: #95a5a6;
  --text: #333333;
  --text-light: #666666;
  --border: #e0e0e0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

#app {
  height: 100vh;
}

.hidden {
  display: none !important;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-content {
  background: white;
  padding: 40px;
  border-radius: 12px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 400px;
}

.modal-content h2 {
  margin-bottom: 10px;
  color: var(--primary);
}

.modal-content p {
  color: var(--text-light);
  margin-bottom: 20px;
}

.modal-content input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 16px;
  margin-bottom: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.modal-content input:focus {
  border-color: var(--primary);
}

.modal-content button {
  width: 100%;
  padding: 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.modal-content button:hover {
  background: var(--primary-dark);
}

#chat-container {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 200px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header h3 {
  font-size: 14px;
  font-weight: 500;
}

.sidebar-header span {
  background: var(--primary);
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
}

#user-list {
  list-style: none;
  padding: 8px;
  flex: 1;
  overflow-y: auto;
}

#user-list li {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 4px;
  word-break: break-all;
}

#user-list li:hover {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.1);
}

.user-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-info span {
  font-size: 13px;
  color: var(--sidebar-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

#rename-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.2s;
}

#rename-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.admin-menu {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-btn {
  padding: 6px 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--sidebar-text);
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
  text-align: center;
}

.admin-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.admin-btn.active {
  background: #e74c3c;
  border-color: #e74c3c;
}

.admin-btn.danger {
  background: rgba(231, 76, 60, 0.3);
  border-color: rgba(231, 76, 60, 0.5);
}

.admin-btn.danger:hover {
  background: rgba(231, 76, 60, 0.5);
}

.message {
  position: relative;
}

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

.is-admin .message:hover .message-actions {
  display: flex;
}

.msg-action-btn {
  padding: 2px 8px;
  border: none;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  cursor: pointer;
  font-size: 11px;
  transition: background 0.2s;
}

.msg-action-btn:hover {
  background: rgba(0, 0, 0, 0.8);
}

.msg-action-btn.delete {
  background: rgba(231, 76, 60, 0.8);
}

.msg-action-btn.delete:hover {
  background: rgba(231, 76, 60, 1);
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

.chat-header h1 {
  font-size: 18px;
  font-weight: 600;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-light);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot.connected {
  background: #2ecc71;
}

.dot.disconnected {
  background: #e74c3c;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.message {
  max-width: 70%;
  animation: fadeIn 0.3s ease;
}

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

.message.other {
  align-self: flex-start;
}

.message.self {
  align-self: flex-end;
}

.message.system {
  align-self: center;
  max-width: 100%;
}

.message-header {
  font-size: 11px;
  color: var(--text-light);
  margin-bottom: 4px;
  padding: 0 4px;
}

.message.other .message-header {
  text-align: left;
}

.message.self .message-header {
  text-align: right;
}

.message-content {
  padding: 10px 14px;
  border-radius: 12px;
  word-break: break-word;
  line-height: 1.5;
}

.message.other .message-content {
  background: var(--msg-bg);
  border-bottom-left-radius: 4px;
}

.message.self .message-content {
  background: var(--msg-self);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.system .message-content {
  background: transparent;
  color: var(--msg-system);
  font-size: 12px;
  padding: 4px;
}

.message-content img {
  max-width: 300px;
  max-height: 200px;
  border-radius: 8px;
  cursor: pointer;
}

.message-error {
  color: #e74c3c;
  font-size: 12px;
  padding: 4px 8px;
  background: #fdeaea;
  border-radius: 4px;
  align-self: center;
}

.input-area {
  padding: 16px 20px;
  background: white;
  border-top: 1px solid var(--border);
}

.input-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.mode-btn {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: white;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
}

.mode-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.proxy-toggle-wrapper {
  margin-left: auto;
}

.proxy-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.proxy-label input[type="checkbox"] {
  display: none;
}

.proxy-slider {
  position: relative;
  width: 36px;
  height: 20px;
  background: #ccc;
  border-radius: 10px;
  transition: background 0.3s;
}

.proxy-slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s;
}

.proxy-label input[type="checkbox"]:checked + .proxy-slider {
  background: var(--primary);
}

.proxy-label input[type="checkbox"]:checked + .proxy-slider::after {
  transform: translateX(16px);
}

.proxy-text {
  font-size: 12px;
  color: var(--text-light);
}

.input-row {
  display: flex;
  gap: 12px;
}

#message-input {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  resize: none;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s;
  min-height: 42px;
  max-height: 120px;
}

#message-input:focus {
  border-color: var(--primary);
}

#send-btn {
  padding: 0 24px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

#send-btn:hover {
  background: var(--primary-dark);
}

#send-btn:disabled {
  background: #bdc3c7;
  cursor: not-allowed;
}

.admin-settings-panel {
  background: white;
  border-radius: 12px;
  width: 380px;
  max-height: 80vh;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.admin-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  background: var(--primary);
  color: white;
}

.admin-panel-header h2 {
  font-size: 16px;
  margin: 0;
}

.admin-close-btn {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.admin-close-btn:hover {
  opacity: 0.8;
}

.admin-panel-body {
  padding: 16px 20px;
  overflow-y: auto;
  max-height: calc(80vh - 60px);
}

.admin-section {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.admin-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.admin-section h3 {
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-label {
  font-size: 14px;
  color: var(--text);
}

.admin-badge {
  background: var(--primary);
  color: white;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: normal;
}

.admin-action-btn {
  padding: 6px 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.2s;
}

.admin-action-btn:hover {
  background: var(--primary-dark);
}

.admin-danger-btn {
  width: 100%;
  padding: 10px;
  background: #e74c3c;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.2s;
}

.admin-danger-btn:hover {
  background: #c0392b;
}

.admin-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.admin-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.admin-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ccc;
  transition: 0.3s;
  border-radius: 24px;
}

.admin-slider::before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  transition: 0.3s;
  border-radius: 50%;
}

.admin-switch input:checked + .admin-slider {
  background: #e74c3c;
}

.admin-switch input:checked + .admin-slider::before {
  transform: translateX(20px);
}

.admin-status {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 8px;
  padding: 6px 10px;
  background: #f5f5f5;
  border-radius: 4px;
}

.admin-status.muted {
  background: #fdeaea;
  color: #e74c3c;
}

.admin-users {
  list-style: none;
  padding: 0;
  margin: 0;
  max-height: 200px;
  overflow-y: auto;
}

.admin-users li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 4px;
  background: #f9f9f9;
}

.admin-users li:hover {
  background: #f0f0f0;
}

.admin-user-name {
  display: flex;
  align-items: center;
  gap: 6px;
}

.admin-user-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--primary);
  color: white;
}

.admin-user-tag.admin {
  background: #f39c12;
}

.admin-quick-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-quick-actions .admin-action-btn {
  flex: 1;
  min-width: calc(50% - 4px);
}

.image-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  cursor: pointer;
}

.image-overlay img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
}

.message-content img {
  cursor: pointer;
  transition: opacity 0.2s;
}

.message-content img:hover {
  opacity: 0.85;
}

@media (max-width: 480px) {
  .modal-content {
    padding: 24px;
  }

  .modal-content h2 {
    font-size: 18px;
  }

  .modal-content input {
    padding: 10px 12px;
    font-size: 15px;
  }

  .modal-content button {
    padding: 10px;
    font-size: 15px;
  }

  .chat-header {
    padding: 12px 16px;
  }

  .chat-header h1 {
    font-size: 15px;
  }

  .connection-status {
    font-size: 11px;
  }

  .messages {
    padding: 12px;
    gap: 10px;
  }

  .message {
    max-width: 88%;
  }

  .message-header {
    font-size: 10px;
  }

  .message-content {
    padding: 8px 12px;
    font-size: 14px;
  }

  .message-content img {
    max-width: 220px;
    max-height: 160px;
  }

  .input-area {
    padding: 10px 12px;
  }

  .input-toolbar {
    gap: 6px;
    margin-bottom: 6px;
  }

  .mode-btn {
    padding: 4px 10px;
    font-size: 13px;
  }

  .proxy-text {
    display: none;
  }

  .proxy-slider {
    width: 32px;
    height: 18px;
  }

  .proxy-slider::after {
    width: 14px;
    height: 14px;
  }

  .proxy-label input[type="checkbox"]:checked + .proxy-slider::after {
    transform: translateX(14px);
  }

  #message-input {
    padding: 8px 12px;
    font-size: 14px;
    min-height: 38px;
  }

  #send-btn {
    padding: 0 16px;
    font-size: 13px;
  }

  .admin-settings-panel {
    width: 100%;
    max-height: 100vh;
    border-radius: 0;
  }

  .admin-panel-body {
    padding: 12px 16px;
    max-height: calc(100vh - 56px);
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  .sidebar {
    width: 180px;
  }

  .sidebar-header {
    padding: 12px;
  }

  .sidebar-header h3 {
    font-size: 13px;
  }

  #user-list {
    padding: 6px;
  }

  #user-list li {
    padding: 6px 10px;
    font-size: 13px;
  }

  .sidebar-footer {
    padding: 10px;
  }

  .user-info span {
    font-size: 12px;
  }

  .chat-header {
    padding: 14px 16px;
  }

  .chat-header h1 {
    font-size: 16px;
  }

  .messages {
    padding: 16px;
  }

  .message {
    max-width: 80%;
  }

  .message-content img {
    max-width: 260px;
    max-height: 180px;
  }

  .input-area {
    padding: 14px 16px;
  }

  .admin-settings-panel {
    width: 360px;
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -200px;
    top: 0;
    bottom: 0;
    z-index: 50;
    transition: left 0.3s ease;
    width: 200px;
  }

  .sidebar.open {
    left: 0;
  }

  .chat-header {
    position: relative;
  }

  .sidebar-toggle {
    display: block;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    margin-right: 8px;
  }
}

@media (min-width: 769px) {
  .sidebar-toggle {
    display: none;
  }

  .sidebar {
    position: static;
  }
}
