* {
  box-sizing: border-box;
}

.hidden { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  color: #111;
  background: #fff;
  -webkit-font-smoothing: antialiased;
}

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

button {
  font: inherit;
  cursor: pointer;
}

input, textarea, button {
  font-family: inherit;
}

/* ---------- Login pages ---------- */

.auth-shell {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: #f9fafb;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 28px 24px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.auth-card h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 4px;
}

.auth-card .subtitle {
  font-size: 14px;
  color: #6b7280;
  margin: 0 0 20px;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #374151;
  margin-bottom: 6px;
}

.field input,
.field textarea {
  width: 100%;
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  color: #111;
  outline: none;
}

.field input:focus,
.field textarea:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 15px;
  font-weight: 500;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: #2563eb;
  color: #fff;
  transition: background-color 120ms ease;
}

.btn:hover { background: #1d4ed8; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-block { width: 100%; }

.btn-secondary {
  background: #fff;
  color: #111;
  border-color: #d1d5db;
}
.btn-secondary:hover { background: #f3f4f6; }

.btn-ghost {
  background: transparent;
  color: #2563eb;
  border-color: transparent;
  padding: 6px 8px;
}
.btn-ghost:hover { background: #eff6ff; text-decoration: none; }

.error-banner {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  margin-bottom: 14px;
}

.error-banner.hidden { display: none; }

/* ---------- User chat ---------- */

.chat-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}

.chat-header .title {
  font-size: 16px;
  font-weight: 600;
}

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

.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f9fafb;
}

.chat-empty {
  text-align: center;
  color: #6b7280;
  font-size: 14px;
  margin: auto 0;
  padding: 32px 8px;
}

.bubble {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 14px;
  word-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.4;
  font-size: 15px;
}

.bubble .meta {
  display: block;
  font-size: 11px;
  margin-top: 2px;
  opacity: 0.7;
}

.bubble.from-user {
  background: #2563eb;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.bubble.from-admin {
  background: #fff;
  color: #111;
  align-self: flex-start;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}

.day-divider {
  align-self: center;
  font-size: 11px;
  color: #6b7280;
  background: #fff;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid #e5e7eb;
  margin: 4px 0;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 12px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
  position: sticky;
  bottom: 0;
}

.chat-input-row textarea {
  flex: 1 1 auto;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 20px;
  font-size: 16px;
  line-height: 1.4;
  outline: none;
}

.chat-input-row textarea:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.chat-input-row .send-btn {
  flex: 0 0 auto;
  padding: 10px 16px;
  border-radius: 20px;
}

.connection-banner {
  background: #fef9c3;
  color: #713f12;
  font-size: 13px;
  text-align: center;
  padding: 6px 8px;
  border-bottom: 1px solid #fde68a;
}

.connection-banner.hidden { display: none; }

/* ---------- Admin inbox ---------- */

.admin-shell {
  height: 100%;
  display: flex;
  flex-direction: row;
  background: #f9fafb;
}

.sidebar {
  width: 320px;
  flex: 0 0 320px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #e5e7eb;
  background: #fff;
}

.sidebar-header {
  padding: 12px 14px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
}

.conversation-list {
  flex: 1 1 auto;
  overflow-y: auto;
}

.sidebar-footer {
  padding: 10px 14px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: flex-end;
}

.thread-view {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.conversation-empty {
  text-align: center;
  color: #6b7280;
  font-size: 14px;
  padding: 32px 16px;
}

.conversation-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
  background: transparent;
  border-left: 3px solid transparent;
  text-align: left;
  width: 100%;
  border-top: 0;
  border-right: 0;
  border-bottom: 1px solid #f3f4f6;
  font-family: inherit;
  color: inherit;
}

.conversation-item:hover { background: #f9fafb; }
.conversation-item.active { background: #eff6ff; border-left-color: #2563eb; }

.conversation-item .name {
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.conversation-item.unread .name { font-weight: 700; }

.conversation-item .name .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2563eb;
  flex: 0 0 8px;
}

.conversation-item .phone {
  font-size: 13px;
  color: #6b7280;
}

.conversation-item .time {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 2px;
}

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

.main-pane .empty-state {
  margin: auto;
  text-align: center;
  color: #6b7280;
  font-size: 14px;
  padding: 32px;
}

.thread-header {
  padding: 12px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.thread-header .who { display: flex; flex-direction: column; min-width: 0; }
.thread-header .who .name { font-weight: 600; font-size: 16px; }
.thread-header .who .phone { font-size: 13px; color: #6b7280; }

.thread-header .actions { display: flex; gap: 8px; }

.thread-mobile-back {
  display: none;
  background: none;
  border: 0;
  font-size: 18px;
  color: #2563eb;
  cursor: pointer;
  padding: 4px 6px;
  margin-right: 4px;
}

.bubble.from-admin-side {
  background: #2563eb;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.bubble.from-user-side {
  background: #fff;
  color: #111;
  align-self: flex-start;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17,24,39,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-backdrop.hidden { display: none; }

.modal {
  background: #fff;
  width: 100%;
  max-width: 420px;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.15);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.modal h2 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 600;
}

.modal .subtitle {
  font-size: 13px;
  color: #6b7280;
  margin: 0 0 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.password-with-generate {
  display: flex;
  gap: 6px;
}

.password-with-generate input {
  flex: 1 1 auto;
}

.invite-card {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 12px;
}

.invite-card pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 0 0 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px;
  color: #111;
}

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

.copy-status {
  font-size: 12px;
  color: #047857;
  margin-left: 8px;
}

/* ---------- Mobile admin ---------- */

@media (max-width: 768px) {
  .admin-shell { flex-direction: column; }

  .sidebar {
    width: 100%;
    flex: 1 1 auto;
    border-right: 0;
    border-bottom: 1px solid #e5e7eb;
  }

  .main-pane { display: none; }

  body.thread-open .sidebar { display: none; }
  body.thread-open .main-pane { display: flex; }
  body.thread-open .thread-mobile-back { display: inline-block; }
}
