/* ============================================================
   AChat Enterprise — Design System
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

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

:root {
  --sidebar-bg:       #0f172a;
  --sidebar-header:   #1e293b;
  --sidebar-hover:    #1e293b;
  --sidebar-active:   #2563eb;
  --sidebar-text:     #94a3b8;
  --sidebar-text-hl:  #f1f5f9;
  --sidebar-border:   #1e293b;

  --main-bg:          #f8fafc;
  --main-header:      #ffffff;
  --main-border:      #e2e8f0;

  --accent:           #2563eb;
  --accent-hover:     #1d4ed8;
  --accent-light:     #eff6ff;

  --bubble-out-bg:    #2563eb;
  --bubble-out-text:  #ffffff;
  --bubble-in-bg:     #ffffff;
  --bubble-in-text:   #1e293b;

  --text-primary:     #1e293b;
  --text-secondary:   #64748b;
  --text-muted:       #94a3b8;

  --danger:           #ef4444;
  --success:          #22c55e;
  --warning:          #f59e0b;

  --radius-sm:        6px;
  --radius-md:        10px;
  --radius-lg:        16px;
  --radius-xl:        24px;

  --shadow-sm:        0 1px 3px rgba(0,0,0,.08);
  --shadow-md:        0 4px 16px rgba(0,0,0,.12);
  --shadow-lg:        0 8px 32px rgba(0,0,0,.16);

  --transition:       150ms ease;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--main-bg);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   SCROLLBARS
   ============================================================ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ============================================================
   UTILITIES
   ============================================================ */
.hidden   { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex     { display: flex; }
.items-center { align-items: center; }
.gap-2    { gap: 8px; }
.gap-3    { gap: 12px; }

/* ============================================================
   AVATAR
   ============================================================ */
.avatar {
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  user-select: none;
  overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm  { width: 32px; height: 32px; font-size: 12px; }
.avatar-md  { width: 40px; height: 40px; font-size: 15px; }
.avatar-lg  { width: 48px; height: 48px; font-size: 18px; }

/* ============================================================
   BADGE
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent);
  color: #fff;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 16px;
  height: 36px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  outline: none;
  transition: background var(--transition), box-shadow var(--transition), transform var(--transition);
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: var(--accent-hover); box-shadow: 0 2px 8px rgba(37,99,235,.3); }
.btn-ghost    { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover    { background: var(--main-bg); color: var(--text-primary); }
.btn-danger   { background: #fee2e2; color: var(--danger); }
.btn-danger:hover   { background: var(--danger); color: #fff; }
.btn-icon {
  width: 36px; height: 36px; padding: 0;
  border-radius: var(--radius-md);
  background: transparent; border: none;
  color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.btn-icon:hover { background: var(--main-bg); color: var(--text-primary); }
.btn-icon svg { width: 18px; height: 18px; }

/* ============================================================
   INPUTS
   ============================================================ */
.input-field {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  border: 1.5px solid #e2e8f0;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  background: #fff;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.input-field::placeholder { color: var(--text-muted); }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
#login-page {
  position: fixed; inset: 0;
  display: flex;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
}

.login-brand-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px;
  gap: 40px;
}

.login-logo-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.login-logo-icon {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px rgba(37,99,235,.4);
}
.login-logo-icon svg { width: 40px; height: 40px; color: #fff; }

.login-brand-name {
  font-size: 36px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.5px;
}
.login-brand-name span { color: #60a5fa; }

.login-tagline {
  font-size: 16px;
  color: #94a3b8;
  text-align: center;
  max-width: 320px;
  line-height: 1.6;
}

.login-features {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 320px;
}

.login-feature-item {
  display: flex;
  align-items: center;
  gap: 14px;
  color: #cbd5e1;
  font-size: 14px;
}
.login-feature-icon {
  width: 36px; height: 36px;
  background: rgba(37,99,235,.2);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.login-feature-icon svg { width: 18px; height: 18px; color: #60a5fa; }

.login-form-panel {
  width: 460px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background: rgba(255,255,255,.03);
  backdrop-filter: blur(20px);
  border-left: 1px solid rgba(255,255,255,.08);
}

.login-card {
  width: 100%;
  max-width: 380px;
}

.login-card-header {
  margin-bottom: 32px;
}
.login-card-title {
  font-size: 24px;
  font-weight: 700;
  color: #f1f5f9;
  margin-bottom: 6px;
}
.login-card-subtitle {
  font-size: 14px;
  color: #64748b;
}

.form-group {
  margin-bottom: 18px;
}
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #94a3b8;
  margin-bottom: 7px;
}
.form-hint {
  font-size: 12px;
  color: #64748b;
  margin-top: 5px;
}
.login-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  background: rgba(255,255,255,.06);
  border: 1.5px solid rgba(255,255,255,.1);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 14px;
  color: #f1f5f9;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.login-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,.2);
}
.login-input::placeholder { color: #475569; }

.login-btn {
  width: 100%;
  height: 46px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition), box-shadow var(--transition), transform var(--transition);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 8px;
  box-shadow: 0 4px 16px rgba(37,99,235,.35);
}
.login-btn:hover:not(:disabled) { opacity: .92; box-shadow: 0 6px 20px rgba(37,99,235,.45); }
.login-btn:active:not(:disabled) { transform: scale(0.98); }
.login-btn:disabled { opacity: .5; cursor: not-allowed; }

.login-error {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(239,68,68,.12);
  border: 1px solid rgba(239,68,68,.25);
  border-radius: var(--radius-md);
  color: #fca5a5;
  font-size: 13px;
  margin-bottom: 16px;
}
.login-error svg { width: 16px; height: 16px; flex-shrink: 0; }

.login-divider {
  height: 1px;
  background: rgba(255,255,255,.06);
  margin: 24px 0;
}

.login-footer {
  text-align: center;
  font-size: 12px;
  color: #475569;
}

/* ============================================================
   SPINNER
   ============================================================ */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   CHAT APP LAYOUT
   ============================================================ */
#chat-app {
  position: fixed; inset: 0;
  display: flex;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: 300px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255,255,255,.05);
}

.sidebar-header {
  padding: 0 16px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--sidebar-header);
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
}
.sidebar-logo-icon svg { width: 18px; height: 18px; color: #fff; }
.sidebar-logo-text {
  font-size: 16px;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: -.3px;
}
.sidebar-logo-text span { color: #60a5fa; }

.sidebar-actions {
  display: flex;
  gap: 4px;
}
.sidebar-icon-btn {
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: #64748b;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.sidebar-icon-btn:hover { background: rgba(255,255,255,.07); color: #94a3b8; }
.sidebar-icon-btn svg { width: 17px; height: 17px; }

.sidebar-search {
  padding: 12px 16px;
  flex-shrink: 0;
}
.search-wrap {
  position: relative;
}
.search-wrap svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: #475569; pointer-events: none;
}
.search-input {
  width: 100%;
  height: 34px;
  padding: 0 10px 0 32px;
  background: rgba(255,255,255,.06);
  border: 1.5px solid rgba(255,255,255,.06);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 13px;
  color: #e2e8f0;
  outline: none;
  transition: border-color var(--transition), background var(--transition);
}
.search-input:focus { border-color: #3b82f6; background: rgba(255,255,255,.09); }
.search-input::placeholder { color: #475569; }

.sidebar-section-label {
  padding: 6px 16px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: #334155;
}

.room-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.room-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}
.room-item:hover { background: var(--sidebar-hover); }
.room-item.active { background: rgba(37,99,235,.2); }
.room-item.active .room-name { color: #e0eaff; }

.room-info { flex: 1; min-width: 0; }
.room-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--sidebar-text-hl);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.room-last-msg {
  font-size: 12px;
  color: var(--sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.room-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.room-time {
  font-size: 11px;
  color: #475569;
}
.room-item.active .room-time { color: #93c5fd; }

.room-list-empty {
  padding: 40px 16px;
  text-align: center;
  color: #334155;
}
.room-list-empty svg { width: 36px; height: 36px; color: #1e3a5f; margin-bottom: 10px; }
.room-list-empty p { font-size: 13px; }

.sidebar-user {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid rgba(255,255,255,.06);
  background: rgba(0,0,0,.2);
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: 13px;
  font-weight: 500;
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-status {
  font-size: 11px;
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 4px;
}
.status-dot {
  width: 7px; height: 7px;
  background: var(--success);
  border-radius: 50%;
}

/* ---- MAIN AREA ---- */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--main-bg);
}

/* Empty state */
.main-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  gap: 16px;
}
.main-empty-icon {
  width: 80px; height: 80px;
  background: var(--accent-light);
  border-radius: 24px;
  display: flex; align-items: center; justify-content: center;
}
.main-empty-icon svg { width: 40px; height: 40px; color: var(--accent); }
.main-empty h3 { font-size: 18px; font-weight: 600; color: var(--text-primary); }
.main-empty p  { font-size: 14px; color: var(--text-secondary); text-align: center; max-width: 280px; }

/* Chat header */
.chat-header {
  height: 60px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--main-header);
  border-bottom: 1px solid var(--main-border);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.chat-room-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-room-sub {
  font-size: 12px;
  color: var(--text-muted);
}
.chat-header-actions {
  display: flex;
  gap: 4px;
}

/* Messages area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.messages-date-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0;
  color: var(--text-muted);
  font-size: 12px;
}
.messages-date-sep::before,
.messages-date-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--main-border);
}

/* Message bubble */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 70%;
}
.msg-row.out {
  flex-direction: row-reverse;
  align-self: flex-end;
}
.msg-row.in {
  align-self: flex-start;
}

.msg-bubble-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.msg-row.out .msg-bubble-wrap { align-items: flex-end; }
.msg-row.in  .msg-bubble-wrap { align-items: flex-start; }

.msg-sender-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  padding: 0 4px;
  margin-bottom: 2px;
}

.msg-bubble {
  padding: 9px 13px;
  border-radius: var(--radius-lg);
  max-width: 100%;
  line-height: 1.5;
  word-break: break-word;
  position: relative;
}
.msg-row.out .msg-bubble {
  background: var(--bubble-out-bg);
  color: var(--bubble-out-text);
  border-bottom-right-radius: 4px;
}
.msg-row.in .msg-bubble {
  background: var(--bubble-in-bg);
  color: var(--bubble-in-text);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 4px;
}
.msg-row.out .msg-meta { color: rgba(255,255,255,.55); justify-content: flex-end; }

.msg-status svg { width: 14px; height: 14px; }
.msg-status.read { color: #60a5fa; }

/* System message */
.msg-system {
  align-self: center;
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(0,0,0,.04);
  padding: 4px 12px;
  border-radius: 99px;
  margin: 4px 0;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  font-size: 12px;
  color: var(--text-muted);
  min-height: 28px;
  flex-shrink: 0;
}
.typing-dots { display: flex; gap: 3px; }
.typing-dots span {
  width: 6px; height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* Message input */
.input-area {
  padding: 12px 20px 16px;
  background: #fff;
  border-top: 1px solid var(--main-border);
  flex-shrink: 0;
}
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--main-bg);
  border: 1.5px solid var(--main-border);
  border-radius: var(--radius-xl);
  padding: 8px 8px 8px 16px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
#msg-input {
  flex: 1;
  min-height: 24px;
  max-height: 120px;
  resize: none;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
  outline: none;
  overflow-y: auto;
}
#msg-input::placeholder { color: var(--text-muted); }
.send-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 2px 8px rgba(37,99,235,.3);
}
.send-btn:hover { background: var(--accent-hover); box-shadow: 0 4px 12px rgba(37,99,235,.4); }
.send-btn:active { transform: scale(0.94); }
.send-btn svg { width: 17px; height: 17px; }

/* ============================================================
   NEW CHAT MODAL
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 440px;
  background: #fff;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: slideUp .2s ease;
}
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--main-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--main-border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ============================================================
   TOAST
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #1e293b;
  color: #f1f5f9;
  border-radius: var(--radius-md);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: slideInRight .25s ease;
  min-width: 240px;
  max-width: 360px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.info    { border-left: 3px solid var(--accent); }
@keyframes slideInRight {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ============================================================
   RESPONSIVE: hide brand panel on small screens
   ============================================================ */
@media (max-width: 900px) {
  .login-brand-panel { display: none; }
  .login-form-panel { width: 100%; border-left: none; }
  .sidebar { width: 260px; }
}
@media (max-width: 600px) {
  .sidebar { display: none; }
}
