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

:root {
  --header-height: 50px;
  --color-bg: #ffffff;
  --color-sidebar-hover: #f0f0f0;
  --color-card-bg: #ffffff;
  --color-primary: #4f6ef7;
  --color-primary-hover: #3b5de7;
  --color-text: #1c1e24;
  --color-text-secondary: #6b7280;
  --color-border: #e5e7eb;
  --color-message-hover: #f8f9ff;
  --color-message-unread: #eef1ff;
  --color-success: #10b981;
  --color-danger: #ef4444;
  --color-danger-hover: #dc2626;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.15);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --transition: 0.2s ease;
}

html, body {
  height: 100%;
  font-family: "Google Sans Flex", -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
}

/* ─── LAYOUT ─── */
#app {
  height: 100vh;
}

#app-body {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

#app-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

/* ─── HEADER ─── */
#app-header {
  height: var(--header-height);
  min-height: var(--header-height);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  z-index: 20;
  border-bottom: 1px solid var(--color-border);
}

.header-left {
  display: flex;
  align-items: center;
}

.header-logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--color-text);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}

.header-menu-btn {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  background: none;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition);
}

.header-menu-btn:hover {
  background: #f3f4f6;
  color: var(--color-text);
}

.settings-logout-btn {
  width: 100%;
  padding: 10px 14px;
  background: none;
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition);
}

.settings-logout-btn:hover {
  background: #fef2f2;
}

.header-login-btn {
  display: inline-flex;
  align-items: center;
  padding: 5px 16px;
  background: #000;
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition);
}

.header-login-btn:hover {
  background: #333;
}

/* ─── MAIN CONTENT ─── */
#main-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#main-content::-webkit-scrollbar {
  display: none;
}

/* ─── TOP BAR (SUBHEADER) ─── */
#topbar {
  height: 250px;
  min-height: 250px;
  background: transparent;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 24px 24px 0;
  position: relative;
  z-index: 5;
}

.subheader-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.subheader-welcome {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.subheader-hero {
  font-size: 35px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--color-text);
  letter-spacing: -1px;
  max-width: 700px;
}

.subheader-right {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  padding-top: 4px;
}

.subheader-btn {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.subheader-btn:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

/* ─── CARD GRID ─── */
#card-grid {
  padding: 20px 24px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 18px;
  align-content: start;
}

/* ─── CARD ─── */
.conversation-card {
  background: var(--color-card-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: box-shadow var(--transition), transform var(--transition);
  min-height: 320px;
}

.conversation-card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.card-header h3 {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.card-header .card-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin-left: 8px;
}

.card-header .card-time {
  font-size: 11px;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.card-hero {
  position: relative;
  width: 100%;
  height: 140px;
  flex-shrink: 0;
  overflow: hidden;
}

.card-hero-time {
  position: absolute;
  bottom: 6px;
  right: 10px;
  font-size: 11px;
  color: rgba(255,255,255,0.8);
  flex-shrink: 0;
}

.card-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Thread list */
.card-threads {
  flex: 1;
  overflow-y: auto;
  min-width: 0;
}

.card-threads::-webkit-scrollbar {
  width: 4px;
}

.card-threads::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 2px;
}

.thread-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f3f4f6;
  transition: background var(--transition);
  min-height: 44px;
}

.thread-row:hover {
  background: var(--color-message-hover);
}

.thread-row.has-new {
  background: var(--color-message-unread);
}

.thread-icon {
  flex-shrink: 0;
  width: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thread-icon-read {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #d1d5db;
  margin: 0 auto;
}

.thread-icon-unread {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-primary);
  margin: 0 auto;
}

.thread-content {
  flex: 1;
  min-width: 0;
}

.thread-subject {
  font-size: 12.5px;
  font-weight: 400;
  color: var(--color-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread-row.has-new .thread-subject {
  font-weight: 600;
  color: var(--color-primary);
}

.thread-options-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
  color: #d1d5db;
  transition: color var(--transition), background var(--transition);
}

.thread-options-btn:hover {
  background: var(--color-sidebar-hover);
  color: var(--color-text-secondary);
}

.thread-row.has-new .thread-options-btn {
  color: var(--color-primary);
}

.thread-row.has-new .thread-options-btn:hover {
  color: var(--color-primary);
}

/* ─── NEW MESSAGE CARD ─── */
.new-message-card {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  background: var(--color-card-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 2px dashed var(--color-border);
  transition: all var(--transition);
}

.new-message-card:hover {
  border-color: var(--color-primary);
  background: #f8f9ff;
  box-shadow: var(--shadow-md);
}

.new-message-card .new-msg-content {
  text-align: center;
}

.new-message-card .new-msg-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
}

.new-message-card h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
}

.new-message-card p {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 4px;
}

/* ─── MODAL ─── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

#modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

#modal {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 780px;
  max-width: 94vw;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  transform: translateY(10px);
  transition: transform 0.25s ease;
  overflow: hidden;
}

#modal-overlay.open #modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  transition: all var(--transition);
}

.modal-close:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.modal-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-body-main {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.modal-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-y: auto;
}

.modal-right {
  width: 240px;
  min-width: 240px;
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.modal-message {
  padding: 20px 24px;
  border-bottom: 1px solid var(--color-border);
}

.modal-message .msg-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
}

.modal-message .msg-meta-row {
  display: flex;
  gap: 8px;
  font-size: 13px;
}

.modal-message .msg-meta-label {
  color: var(--color-text-secondary);
  width: 48px;
  flex-shrink: 0;
}

.modal-message .msg-subject-line {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 12px;
}

.modal-message .msg-body {
  font-size: 14px;
  line-height: 1.8;
  color: var(--color-text);
  white-space: pre-wrap;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 24px;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.modal-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--color-text);
}

.modal-action-btn:hover {
  background: var(--color-bg);
  border-color: #d1d5db;
}

.modal-action-btn.primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.modal-action-btn.primary:hover {
  background: var(--color-primary-hover);
}

/* Reply editor */
.modal-reply {
  padding: 16px 24px;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
  display: none;
}

.modal-reply.open {
  display: block;
}

.modal-reply textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition);
}

.modal-reply textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79,110,247,0.12);
}

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

/* Modal right panel */
.modal-about-section, .modal-search-section {
  padding: 16px 18px;
  flex: 1;
  overflow-y: auto;
}

.modal-about-section {
  border-bottom: 1px solid var(--color-border);
}

.modal-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

.modal-about-section p, .modal-search-section p {
  font-size: 12.5px;
  color: var(--color-text-secondary);
  line-height: 1.7;
}

.modal-about-section::-webkit-scrollbar,
.modal-search-section::-webkit-scrollbar {
  width: 3px;
}

.modal-about-section::-webkit-scrollbar-thumb,
.modal-search-section::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 2px;
}

/* Compose new message (shown in modal for New Message card) */
.compose-form {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.compose-form input, .compose-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
}

.compose-form input:focus, .compose-form textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79,110,247,0.12);
}

.compose-form textarea {
  min-height: 180px;
  resize: vertical;
  line-height: 1.6;
}

.compose-form .compose-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Empty state for trash / no conversations */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--color-text-secondary);
  grid-column: 1 / -1;
}

.empty-state .empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 4px;
}

.empty-state p {
  font-size: 13px;
}

/* ─── SETTINGS PANEL ─── */
#settings-panel {
  position: fixed;
  top: 0;
  right: -400px;
  width: 400px;
  max-width: 90vw;
  height: 100vh;
  background: #fff;
  box-shadow: var(--shadow-lg);
  z-index: 1001;
  display: flex;
  flex-direction: column;
  transition: right 0.3s ease;
}

#settings-panel.open {
  right: 0;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.settings-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.settings-section {
  margin-bottom: 28px;
}

.settings-section h3 {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid #f3f4f6;
}

.settings-row .label {
  font-size: 13.5px;
}

.settings-row .value {
  font-size: 13px;
  color: var(--color-text-secondary);
}

/* Toggle switch */
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  cursor: pointer;
}

.toggle input {
  display: none;
}

.toggle .slider {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 11px;
  transition: background var(--transition);
}

.toggle .slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 2px;
  bottom: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
}

.toggle input:checked + .slider {
  background: var(--color-primary);
}

.toggle input:checked + .slider::before {
  transform: translateX(18px);
}

/* ─── SCROLL TO TOP BUTTON ─── */
#scroll-top-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #000;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease;
}

#scroll-top-btn.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

#scroll-top-btn:hover {
  background: #222;
}

/* ─── TOAST ─── */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--color-text);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 2000;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ─── AUTH PAGES ─── */
.auth-page {
  display: flex;
  flex-direction: row;
  min-height: 100vh;
}

.auth-form-section {
  flex: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  background: #fff;
}

.auth-card {
  width: 100%;
  max-width: 440px;
}

.auth-card h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--color-text);
}

.auth-card .subtitle {
  font-size: 15px;
  color: var(--color-text-secondary);
  margin-bottom: 36px;
}

.auth-hero {
  flex: 3;
  position: relative;
  overflow: hidden;
}

.auth-hero img,
.auth-hero video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.auth-hero .overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(79,110,247,0.3), rgba(79,110,247,0.05));
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-form .form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-form label {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}

.auth-form input {
  padding: 12px 16px;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.auth-form input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79,110,247,0.12);
}

.auth-form .btn-submit {
  padding: 13px 20px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  margin-top: 4px;
}

.auth-form .btn-submit:hover {
  background: var(--color-primary-hover);
}

.auth-footer {
  margin-top: 24px;
  text-align: center;
  font-size: 14px;
  color: var(--color-text-secondary);
}

.auth-footer a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 600;
}

.auth-footer a:hover {
  text-decoration: underline;
}

.auth-error {
  background: #fef2f2;
  color: var(--color-danger);
  font-size: 13px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  display: none;
}

.auth-error.show {
  display: block;
}


