* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #eef3ff, #f8fafc 40%, #e2f3ff 100%);
  color: #111827;
}

a {
  text-decoration: none;
  color: #2563eb;
}

.topbar {
  height: 56px;
  background: #0f172a;
  color: #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.5);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-title {
  font-weight: 600;
  letter-spacing: 0.03em;
}

.user-badge {
  margin-right: 16px;
  font-size: 14px;
}

.top-link {
  margin-left: 8px;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.top-link:hover {
  border-color: rgba(148, 163, 184, 0.6);
}

.page {
  padding: 16px;
}

/* Auth */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.auth-card {
  background: rgba(255, 255, 255, 0.9);
  padding: 32px;
  border-radius: 16px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
  max-width: 400px;
  width: 100%;
}

.auth-card h1 {
  margin-top: 0;
  margin-bottom: 4px;
}

.subtitle {
  margin-top: 0;
  margin-bottom: 16px;
  color: #6b7280;
}

.auth-form label {
  display: block;
  font-size: 14px;
  margin-bottom: 12px;
}

.auth-form input {
  width: 100%;
  padding: 8px 10px;
  margin-top: 4px;
  border-radius: 8px;
  border: 1px solid #cbd5f5;
  font-size: 14px;
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  border: none;
  color: white;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 500;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-secondary {
  background: white;
  border: 1px solid #cbd5f5;
  color: #1f2937;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
}

.btn-small {
  background: #e5e7eb;
  border: none;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
}

.alert {
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 14px;
}

.alert-error {
  background: #fee2e2;
  color: #b91c1c;
}

.alert-success {
  background: #dcfce7;
  color: #166534;
}

.hint {
  font-size: 12px;
  color: #6b7280;
}

/* Dashboard layout */

.dashboard {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 16px;
  height: calc(100vh - 90px);
}

.sidebar {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.sidebar-header h2 {
  margin: 0;
  font-size: 18px;
}

.input-search {
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  font-size: 14px;
}

.user-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0 0;
  overflow-y: auto;
}

.user-item {
  display: flex;
  align-items: center;
  padding: 8px;
  border-radius: 12px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s, transform 0.08s;
}

.user-item:hover {
  background: #eff6ff;
  transform: translateY(-1px);
}

.user-item.active {
  background: #dbeafe;
}

.avatar-circle {
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: #1d4ed8;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
  font-size: 14px;
}

.user-info {
  flex: 1;
}

.user-info .name {
  font-size: 14px;
  font-weight: 500;
}

.user-info .username {
  font-size: 12px;
  color: #6b7280;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #22c55e;
}

/* Chat panel */

.chat-panel {
  background: rgba(255, 255, 255, 0.96);
  border-radius: 16px;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
  padding: 0;
}

.chat-empty {
  margin: auto;
  text-align: center;
  color: #6b7280;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-container.hidden {
  display: none;
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid #e5e7eb;
}

.chat-header h2 {
  margin: 0;
}

.chat-subtitle {
  margin: 0;
  font-size: 12px;
  color: #6b7280;
}

.chat-messages {
  flex: 1;
  padding: 12px 16px;
  overflow-y: auto;
  background: linear-gradient(to bottom, #eef2ff, #f9fafb);
}

.message-row {
  display: flex;
  margin-bottom: 8px;
}

.message-bubble {
  max-width: 70%;
  padding: 8px 10px;
  border-radius: 14px;
  font-size: 14px;
  position: relative;
}

.message-row.self {
  justify-content: flex-end;
}

.message-row.self .message-bubble {
  background: #2563eb;
  color: white;
  border-bottom-right-radius: 4px;
}

.message-row.other .message-bubble {
  background: white;
  color: #111827;
  border-bottom-left-radius: 4px;
  border: 1px solid #e5e7eb;
}

.message-meta {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 2px;
}

.message-urgent {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 2px;
  color: #f97316;
}

.chat-form {
  border-top: 1px solid #e5e7eb;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#chat-input {
  resize: none;
  min-height: 60px;
  max-height: 120px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid #d1d5db;
  font-size: 14px;
}

.chat-form-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.checkbox-inline {
  font-size: 13px;
  color: #4b5563;
}

.checkbox-inline input {
  margin-right: 4px;
}

/* Settings, admin */

.settings-page, .admin-page {
  max-width: 900px;
  margin: 0 auto;
}

.settings-form label {
  display: block;
  margin-bottom: 10px;
  font-size: 14px;
}

.settings-form input[type="text"] {
  width: 100%;
  padding: 6px 8px;
  margin-top: 4px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
}

.settings-test {
  margin-top: 16px;
}

.admin-stats {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  flex: 1;
  background: white;
  padding: 10px 12px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.1);
}

.stat-label {
  font-size: 12px;
  color: #6b7280;
}

.stat-value {
  font-size: 20px;
  font-weight: 600;
}

.admin-section {
  margin-top: 24px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th, .table td {
  border-bottom: 1px solid #e5e7eb;
  padding: 6px 4px;
  text-align: left;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.inline-form input[type="text"],
.inline-form input[type="password"],
.inline-form select {
  padding: 4px 6px;
  border-radius: 8px;
  border: 1px solid #d1d5db;
  font-size: 12px;
}

/* Toast */

#toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
}

.toast {
  background: #111827;
  color: white;
  padding: 10px 12px;
  border-radius: 12px;
  margin-top: 8px;
  min-width: 220px;
  max-width: 280px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.4);
  font-size: 13px;
}

.toast-title {
  font-weight: 600;
  margin-bottom: 2px;
}

/* Responsive */

@media (max-width: 800px) {
  .dashboard {
    grid-template-columns: 1fr;
    height: auto;
  }
  .chat-panel {
    min-height: 400px;
  }
}
