:root {
  --navy-950: #081321;
  --navy-900: #0d1c30;
  --navy-850: #10233f;
  --navy-800: #17345d;
  --navy-700: #214776;
  --white: #ffffff;
  --surface: #f4f8fd;
  --surface-soft: #edf3fb;
  --line: #d7e3f2;
  --text: #142845;
  --muted: #647995;
  --success: #12805a;
  --danger: #c43c3c;
  --shadow: 0 24px 60px rgba(6, 19, 38, 0.16);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: 'Plus Jakarta Sans', 'Inter', Arial, Helvetica, sans-serif;
  background: radial-gradient(circle at top, #183b67, var(--navy-950));
  color: var(--text);
}
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; }
a { text-decoration: none; color: inherit; }
img { max-width: 100%; }

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 13px 15px;
  background: var(--white);
  color: var(--text);
  outline: none;
}
input:focus, select:focus {
  border-color: #6b91c9;
  box-shadow: 0 0 0 4px rgba(33, 71, 118, 0.12);
}
label {
  display: block;
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.app-shell { min-height: 100vh; }
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: min(480px, 100%);
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 32px;
  padding: 30px;
  box-shadow: var(--shadow);
}
.install-card-xl { width: min(720px, 100%); }
.brand-block { margin-bottom: 24px; text-align: center; }
.brand-block.left { text-align: left; }
.brand-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(16, 35, 63, 0.08);
  color: var(--navy-850);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 12px;
}
.brand-chip.small { padding: 6px 10px; margin-bottom: 10px; }
.brand-block h1, .brand-block h2 {
  margin: 0 0 8px;
  color: var(--navy-950);
}
.brand-block p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}
.tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 24px 0 18px;
}
.tab-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 16px;
  padding: 13px 14px;
  cursor: pointer;
  font-weight: 700;
}
.tab-button.active {
  background: linear-gradient(135deg, var(--navy-850), var(--navy-700));
  color: var(--white);
  border-color: transparent;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.wide-btn { width: 100%; justify-content: center; }

.primary-btn, .ghost-btn, .danger-btn, .icon-btn {
  border: 0;
  cursor: pointer;
  border-radius: 16px;
  transition: transform .15s ease, opacity .15s ease, background .15s ease;
}
.primary-btn:hover, .ghost-btn:hover, .danger-btn:hover, .icon-btn:hover {
  transform: translateY(-1px);
}
.primary-btn {
  background: linear-gradient(135deg, var(--navy-850), var(--navy-700));
  color: var(--white);
  padding: 13px 18px;
  font-weight: 700;
}
.ghost-btn {
  background: rgba(255,255,255,0.15);
  color: var(--white);
  padding: 12px 14px;
  font-weight: 700;
}
.ghost-btn-sm, .danger-btn-sm { padding: 9px 12px; border-radius: 12px; }
.danger-btn {
  background: #fdecec;
  color: var(--danger);
  padding: 11px 14px;
  font-weight: 700;
}
.icon-btn {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(16, 35, 63, 0.08);
  color: var(--navy-850);
}
.only-mobile { display: none; }

.form-message {
  margin-top: 12px;
  font-size: 14px;
  min-height: 20px;
}
.form-message.success { color: var(--success); }
.form-message.error { color: var(--danger); }

.dashboard {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  background: rgba(255,255,255,0.08);
}
.sidebar {
  background: rgba(255,255,255,0.94);
  border-right: 1px solid rgba(255,255,255,0.45);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
}
.sidebar-top {
  padding: 20px;
  background: linear-gradient(180deg, var(--navy-900), var(--navy-850));
  color: var(--white);
  box-shadow: inset 0 -1px 0 rgba(255,255,255,0.08);
}
.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.sidebar-brand h2 { margin: 0; font-size: 20px; }
.current-user-card {
  margin-top: 18px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 24px;
  padding: 16px;
  display: flex;
  gap: 14px;
  align-items: center;
}
.current-user-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.current-user-info strong, .user-meta strong { font-size: 15px; }
.current-user-info span {
  color: rgba(255,255,255,0.82);
  overflow: hidden;
  text-overflow: ellipsis;
}
.inline-badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.top-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
}
.badge-soft {
  background: rgba(255,255,255,0.16);
  color: var(--white);
}

.user-search {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.84);
}
.user-list {
  flex: 1;
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(255,255,255,0.82), rgba(244,248,253,0.96));
}
.user-row {
  width: 100%;
  border: 0;
  background: transparent;
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(215, 227, 242, 0.65);
  cursor: pointer;
  text-align: left;
}
.user-row:hover, .user-row.active {
  background: rgba(23, 52, 93, 0.06);
}
.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}
.unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1f6fda, #3ea0ff);
  color: var(--white);
  font-size: 11px;
  font-weight: 800;
  border: 2px solid var(--white);
}
.avatar {
  width: 48px;
  height: 48px;
  border-radius: 18px;
  object-fit: cover;
  background: #dce8f5;
  box-shadow: 0 8px 20px rgba(16,35,63,0.08);
}
.avatar.xl {
  width: 64px;
  height: 64px;
  border-radius: 22px;
}
.user-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.user-meta.grow { flex: 1; }
.user-meta-top, .user-meta-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.message-preview, .meta-time, .current-user-info span, .chat-user-meta span, .modal-subtitle, .admin-user-main span, .message-time, .edited-label {
  color: var(--muted);
  font-size: 13px;
}
.message-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.meta-time {
  flex-shrink: 0;
  font-size: 12px;
}

.chat-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(248,251,255,0.85), rgba(234,242,251,0.76));
}
.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}
.empty-hero {
  text-align: center;
  max-width: 460px;
  padding: 34px;
  border-radius: 32px;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(255,255,255,0.65);
  box-shadow: var(--shadow);
}
.empty-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 18px;
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy-850), var(--navy-700));
  color: var(--white);
  font-size: 28px;
}
.chat-box { display: flex; flex-direction: column; flex: 1; min-height: 100vh; }
.chat-header {
  padding: 18px 22px;
  background: rgba(255,255,255,0.9);
  border-bottom: 1px solid rgba(215,227,242,0.9);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  backdrop-filter: blur(10px);
}
.chat-header-left, .chat-user-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(16, 35, 63, 0.08);
  color: var(--navy-850);
  font-size: 12px;
  font-weight: 800;
}
.mobile-back { display: none; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px;
  background:
    radial-gradient(circle at top left, rgba(33,71,118,0.08), transparent 32%),
    radial-gradient(circle at bottom right, rgba(33,71,118,0.08), transparent 28%),
    linear-gradient(180deg, #f7fbff, #eef4fb);
}
.message-row {
  display: flex;
  margin-bottom: 14px;
}
.message-row.mine { justify-content: flex-end; }
.message-row.theirs { justify-content: flex-start; }
.message-stack { display: flex; flex-direction: column; gap: 6px; max-width: min(78%, 560px); }
.message-bubble {
  padding: 14px 16px;
  border-radius: 22px;
  box-shadow: 0 10px 24px rgba(16,35,63,0.08);
  border: 1px solid rgba(16,35,63,0.04);
}
.message-row.mine .message-bubble {
  background: linear-gradient(135deg, var(--navy-850), var(--navy-700));
  color: var(--white);
  border-bottom-right-radius: 8px;
}
.message-row.theirs .message-bubble {
  background: var(--white);
  color: var(--text);
  border-bottom-left-radius: 8px;
}
.message-bubble.deleted {
  background: #eef3f8 !important;
  color: var(--muted) !important;
}
.message-text { white-space: pre-wrap; word-break: break-word; line-height: 1.55; }
.message-image {
  display: block;
  margin-top: 10px;
  border-radius: 16px;
  max-width: 100%;
}
.message-meta-line {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.edited-label {
  font-style: italic;
}
.message-deleted {
  font-style: italic;
  color: var(--muted);
}
.message-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.tiny-btn {
  border: 0;
  background: rgba(16,35,63,0.08);
  color: var(--navy-850);
  border-radius: 999px;
  padding: 7px 11px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}
.tiny-btn.danger {
  background: #fdecec;
  color: var(--danger);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 18px 22px;
  background: rgba(255,255,255,0.92);
  border-top: 1px solid rgba(215,227,242,0.85);
  backdrop-filter: blur(10px);
}
.composer-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 8px;
}
.composer-box input[type="text"] {
  border: 0;
  box-shadow: none;
  padding: 12px 14px;
}
.file-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-soft);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 700;
  color: var(--navy-850);
}
.file-label input { display: none; }
.send-btn { min-width: 102px; }

.modal {
  position: fixed;
  inset: 0;
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 19, 33, 0.55);
  z-index: 20;
}
.hidden { display: none !important; }
.modal-card {
  width: min(720px, 100%);
  background: var(--white);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-card.wide { width: min(940px, 100%); }
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.modal-head h3, .admin-create-form h4, .admin-users-wrap h4 { margin: 0 0 6px; }
.grid-two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.full-width { grid-column: 1 / -1; }
.stack-form { display: grid; gap: 16px; }
.form-actions { display: flex; justify-content: flex-start; }
.admin-users-wrap { margin-top: 24px; }
.admin-user-row {
  padding: 14px 0;
  border-bottom: 1px solid #edf2f8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.admin-user-main {
  display: flex;
  align-items: center;
  gap: 12px;
}
.admin-user-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.install-message {
  padding: 14px 16px;
  border-radius: 18px;
  margin-bottom: 18px;
}
.install-message.success { background: #e9f8ef; color: var(--success); }
.install-message.error { background: #fdecec; color: var(--danger); }
.placeholder-row {
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 980px) {
  .dashboard { grid-template-columns: 320px minmax(0, 1fr); }
  .top-actions { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 860px) {
  .dashboard { grid-template-columns: 1fr; }
  .sidebar { width: 100%; }
  .chat-panel { display: none; }
  body.chat-open-mobile .sidebar { display: none; }
  body.chat-open-mobile .chat-panel { display: flex; min-height: 100vh; }
  .chat-box { min-height: 100vh; }
  .mobile-back, .only-mobile { display: inline-flex; }
}

@media (max-width: 640px) {
  .auth-card, .modal-card { padding: 20px; border-radius: 24px; }
  .grid-two, .top-actions, .composer { grid-template-columns: 1fr; }
  .message-stack { max-width: 90%; }
  .chat-header { padding: 16px; }
  .messages { padding: 16px; }
  .composer { padding: 14px 16px; }
  .user-row { padding: 13px 14px; }
}

@media (max-width: 420px) {
  .current-user-card { align-items: flex-start; }
  .avatar.xl { width: 56px; height: 56px; }
  .chat-header { align-items: flex-start; }
}


textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 15px;
  background: var(--white);
  color: var(--text);
  outline: none;
  resize: vertical;
  min-height: 120px;
}
textarea:focus {
  border-color: #6b91c9;
  box-shadow: 0 0 0 4px rgba(33, 71, 118, 0.12);
}
.message-stack { position: relative; }
.message-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  opacity: 1;
}
.message-row.theirs .message-actions { display: none; }
.tiny-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(16,35,63,0.10);
  box-shadow: 0 6px 18px rgba(8,19,33,0.08);
}
.tiny-btn:hover { transform: translateY(-1px); }
.admin-user-actions { display:flex; gap:8px; align-items:center; }
.profile-photo-preview {
  margin-top: 10px;
  width: 72px;
  height: 72px;
  border-radius: 20px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: var(--surface);
}
