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

html, body {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, #2d2d44, #1e1e32);
  border-radius: 8px;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 1.4rem;
  color: #a78bfa;
  font-weight: 600;
}

.connection-status {
  font-size: 0.75rem;
  padding: 0.3rem 0.6rem;
  border-radius: 12px;
  background: #3a3a5a;
  color: #8e8ea0;
}

.connection-status.connected {
  background: #1e3a2f;
  color: #4ade80;
}

.app-main {
  display: grid;
  grid-template-columns: 220px 1fr 280px;
  gap: 1rem;
  flex: 1;
  min-height: 0;
}

section {
  background: #25253a;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

section h2 {
  font-size: 0.9rem;
  color: #8e8ea0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
  flex-shrink: 0;
}

.users-panel {
  min-width: 0;
}

.users-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.user-item {
  padding: 0.5rem 0.75rem;
  background: #2d2d48;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.user-item:hover {
  background: #3a3a5a;
}

.user-item.selected {
  background: #4c3d8f;
}

.user-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  flex-shrink: 0;
}

.user-dot.offline {
  background: #6b7280;
}

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

.all-users-section {
  margin-top: 0.75rem;
  flex-shrink: 0;
}

.toggle-all-btn {
  width: 100%;
  padding: 0.5rem;
  background: #2d2d48;
  border: 1px dashed #4a4a6a;
  border-radius: 6px;
  color: #8e8ea0;
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.15s;
}

.toggle-all-btn:hover {
  background: #3a3a5a;
  color: #a78bfa;
}

.all-users-list {
  margin-top: 0.5rem;
  max-height: 150px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.compose-panel {
  min-width: 0;
}

.compose-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex: 1;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-group label {
  font-size: 0.8rem;
  color: #8e8ea0;
}

.form-group input,
.form-group textarea,
.form-group select {
  padding: 0.6rem 0.75rem;
  background: #1e1e32;
  border: 1px solid #3a3a5a;
  border-radius: 6px;
  color: #e0e0e0;
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: #a78bfa;
}

.form-group textarea {
  resize: none;
  flex: 1;
  min-height: 80px;
}

.form-group select {
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: auto;
}

.send-btn,
.broadcast-btn {
  flex: 1;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.send-btn {
  background: #7c3aed;
  color: white;
}

.send-btn:hover {
  background: #6d28d9;
}

.send-btn:disabled {
  background: #4a4a6a;
  cursor: not-allowed;
}

.broadcast-btn {
  background: #2d4a5a;
  color: #67e8f9;
  flex: 0 0 auto;
  padding-left: 1.2rem;
  padding-right: 1.2rem;
}

.broadcast-btn:hover {
  background: #3a5a6a;
}

.send-status {
  font-size: 0.8rem;
  padding: 0.5rem;
  text-align: center;
  min-height: 1.8rem;
}

.send-status.success {
  color: #4ade80;
}

.send-status.error {
  color: #f87171;
}

.history-panel {
  min-width: 0;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  padding: 0.6rem 0.75rem;
  background: #2d2d48;
  border-radius: 6px;
  border-left: 3px solid #7c3aed;
}

.history-item.sent {
  border-left-color: #4ade80;
}

.history-item.broadcast {
  border-left-color: #67e8f9;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: #6b7280;
  margin-bottom: 0.3rem;
}

.history-recipient {
  color: #a78bfa;
}

.history-msg {
  font-size: 0.85rem;
  word-break: break-word;
  color: #c4c4d4;
}

.empty-state,
.loading {
  color: #6b7280;
  font-size: 0.85rem;
  text-align: center;
  padding: 2rem 1rem;
}

.app-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  background: #25253a;
  border-radius: 8px;
  margin-top: 1rem;
  flex-shrink: 0;
  font-size: 0.85rem;
}

.user-info {
  color: #8e8ea0;
}

.user-info strong {
  color: #a78bfa;
}

.back-link {
  color: #67e8f9;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

@media (max-width: 900px) {
  .app-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }

  .users-panel {
    max-height: 150px;
  }

  .users-list {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .user-item {
    flex: 0 0 auto;
  }

  .history-panel {
    max-height: 200px;
  }
}
