/* ============================================================
   Tutor AI — Shared Theme
   All dashboard + app pages link this single stylesheet.
   ============================================================ */

@font-face {
  font-family: 'BukhariScript';
  src: url('/fonts/BukhariScript.ttf') format('truetype');
  font-display: swap;
}

/* --- Reset & Base --- */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: #f5f5f5; color: #333; min-height: 100vh; }

/* --- Auth Section (hidden by default — guest browse mode) --- */
#auth-section { display: none; align-items: center; justify-content: center; min-height: 100vh; background: #fafafa; }
.auth-card { background: #fff; border-radius: 16px; padding: 40px 36px 32px; box-shadow: 0 2px 12px rgba(0,0,0,0.08); max-width: 380px; width: 100%; }
.auth-brand { text-align: center; margin-bottom: 28px; }
.auth-brand .wordmark { font-size: 2.2rem; font-weight: 800; color: #1a1a2e; text-decoration: none; display: block; margin-bottom: 2px; }
.auth-brand .wordmark-accent { font-family: 'BukhariScript', cursive; font-weight: normal; }
.auth-brand .wordmark-sub { font-size: 0.8rem; color: #999; }
#auth-section input { width: 100%; padding: 11px 14px; border: 1px solid #ddd; border-radius: 10px; font-size: 0.95rem; margin-bottom: 12px; outline: none; box-sizing: border-box; }
#auth-section .name-row { display: none; gap: 8px; }
#auth-section input:focus { border-color: #b84840; }
#login-btn { width: 100%; padding: 12px; border: none; border-radius: 10px; font-size: 0.95rem; cursor: pointer; font-weight: 600; background: #b84840; color: #fff; margin-top: 4px; }
#login-btn:hover { background: #a33d36; }
#auth-error { color: #b84840; font-size: 0.85rem; margin-top: 8px; min-height: 20px; text-align: center; }
.auth-footer { text-align: center; font-size: 0.85rem; color: #777; margin-top: 16px; }
.auth-footer a { color: #b84840; text-decoration: none; font-weight: 600; }
.auth-footer a:hover { text-decoration: underline; color: #a33d36; }

/* Forgot password link */
.forgot-password-link { display: block; text-align: center; font-size: 0.85rem; color: #b84840; text-decoration: none; margin-top: 12px; }
.forgot-password-link:hover { text-decoration: underline; color: #a33d36; }

/* Forgot password inline form */
.forgot-password-form { margin-top: 16px; padding-top: 16px; border-top: 1px solid #eee; }
.forgot-password-text { font-size: 0.9rem; color: #555; margin-bottom: 10px; }
.forgot-password-form input { width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 0.95rem; margin-bottom: 10px; outline: none; }
.forgot-password-form input:focus { border-color: #b84840; }
.forgot-password-form .btn-primary { width: 100%; }
.forgot-message { font-size: 0.85rem; margin-top: 8px; min-height: 20px; }
.forgot-message.error { color: #b84840; }
.forgot-message.success { color: #16a766; }

/* Reset password page */
.reset-section { background: #fff; border-radius: 12px; padding: 32px; box-shadow: 0 1px 4px rgba(0,0,0,0.08); max-width: 400px; margin: 60px auto; }
.reset-section h2 { font-size: 1.2rem; margin-bottom: 8px; color: #1a1a2e; }
.reset-subtitle { font-size: 0.9rem; color: #555; margin-bottom: 16px; }
.reset-section input { width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 0.95rem; margin-bottom: 12px; outline: none; }
.reset-section input:focus { border-color: #b84840; }
.reset-section .btn-primary { width: 100%; }
.reset-message { font-size: 0.85rem; margin-top: 10px; min-height: 20px; }
.reset-message.error { color: #b84840; }
.reset-message.success { color: #16a766; }

/* --- App Section (visible by default — guest browse mode) --- */
#app-section { display: block; }

/* --- Layout Shell --- */
.app-layout { display: flex; min-height: 100vh; }

/* --- Sidebar --- */
.sidebar {
  width: 320px;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  background: #fff;
  border-right: 1px solid #eee;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 10;
  transition: width 0.2s ease;
}
.wordmark { font-size: 2rem; font-weight: 800; color: #1a1a2e; margin-bottom: 2px; text-decoration: none; display: block; }
.wordmark-accent { font-family: 'BukhariScript', cursive; font-weight: normal; }
.wordmark-sub { font-size: 0.75rem; color: #999; margin-bottom: 20px; }
.sidebar-divider { border: none; border-top: 1px solid #eee; margin: 16px 0; }

/* Sidebar nav (Home / Projects) */
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px;
  font-size: 0.9rem; font-weight: 500; color: #555;
  text-decoration: none; transition: background 0.15s;
}
.sidebar-nav-item:hover { background: #f5f5f5; color: #1a1a2e; }
.sidebar-nav-item.active { background: #fdf0f1; color: #b84840; font-weight: 600; }
.sidebar-nav-item svg { flex-shrink: 0; }
.sidebar-nav-item span { white-space: nowrap; overflow: hidden; }
.sidebar.collapsed .sidebar-nav-item span { display: none; }
.sidebar.collapsed .sidebar-nav-item { justify-content: center; padding: 9px; }

/* Sidebar toggle button */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}
.sidebar-toggle {
  background: none;
  border: 1px solid #eee;
  border-radius: 8px;
  width: 36px; height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: #f5f5f5; color: #1a1a2e; }

/* Sidebar app info (app pages only) */
.sidebar-app-info { margin-bottom: 4px; }
.sidebar-app-title { font-size: 1.1rem; font-weight: 700; color: #1a1a2e; margin-bottom: 4px; }
.sidebar-app-desc { font-size: 0.82rem; color: #888; line-height: 1.4; }

/* Sidebar bottom area */
.sidebar-bottom { margin-top: auto; padding-top: 12px; }
.sidebar-dashboard-link { font-size: 0.85rem; color: #b84840; text-decoration: none; font-weight: 500; display: block; padding: 8px; border-radius: 8px; }
.sidebar-dashboard-link:hover { background: #fdf0f1; text-decoration: none; }
.sidebar-guide-link { font-size: 0.7rem; color: #b84840; text-decoration: none; display: block; padding: 2px 0; margin-top: -2px; }

/* --- Sidebar Collapse --- */
.sidebar.collapsed {
  width: 64px;
  padding: 24px 14px;
  overflow: hidden;
}
.sidebar.collapsed .hide-collapsed { display: none; }
.sidebar.collapsed .sidebar-header { justify-content: center; }
.sidebar.collapsed .wordmark { display: none; }
.sidebar.collapsed .sidebar-divider { display: none; }

body.sidebar-collapsed .main-content { margin-left: 64px; }

/* --- Main Content --- */
.main-content {
  margin-left: 320px;
  flex: 1;
  padding: 40px clamp(24px, 8vw, 240px);
  transition: margin-left 0.2s ease;
}

/* --- Messages & Chat --- */
#chat-section { display: none; }
.message { background: #fff; border-radius: 12px; padding: 20px; box-shadow: 0 1px 4px rgba(0,0,0,0.08); margin-bottom: 12px; }
.message.user { background: #f0f0f0; }
.message-role { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: #999; margin-bottom: 8px; letter-spacing: 0.5px; }
.message-content { font-size: 0.9rem; line-height: 1.6; white-space: pre-line; word-wrap: break-word; }
.message-content table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 0.85rem; }
.message-content th, .message-content td { border: 1px solid #ddd; padding: 8px 10px; text-align: left; vertical-align: top; }
.message-content th { background: #f5f5f5; font-weight: 600; }
.message-content ul, .message-content ol { white-space: normal; }
.message-content li { margin-bottom: 4px; }

/* Messages spacing */
#messages { padding-bottom: 8px; }

/* --- Form Shared Styles --- */
.app-form { background: #fff; border-radius: 12px; padding: 24px; box-shadow: 0 1px 4px rgba(0,0,0,0.08); margin-bottom: 20px; }
.app-form label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; color: #1a1a2e; }
.app-form .hint { font-size: 0.8rem; color: #999; margin-bottom: 12px; }
.app-form textarea { width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 0.9rem; resize: vertical; font-family: inherit; outline: none; margin-bottom: 16px; min-height: 100px; }
.app-form textarea:focus { border-color: #b84840; }
.app-form select { width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 0.9rem; font-family: inherit; outline: none; margin-bottom: 16px; }
.app-form select:focus { border-color: #b84840; }
.app-form input[type="number"] { width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 0.95rem; margin-bottom: 16px; outline: none; }
.app-form input[type="number"]:focus { border-color: #b84840; }
.app-form input[type="file"] { margin-bottom: 16px; font-size: 0.9rem; }

/* --- Buttons --- */
.btn-primary {
  background: #b84840; color: #fff; border: none; border-radius: 8px;
  padding: 12px 32px; font-size: 1rem; font-weight: 600; cursor: pointer; width: 100%;
}
.btn-primary:hover { background: #a33d36; }
.btn-primary:disabled { background: #ccc; cursor: not-allowed; }

.btn-outline {
  background: none; border: 1px solid #b84840; border-radius: 8px;
  padding: 8px 16px; color: #b84840; font-size: 0.9rem; cursor: pointer; font-weight: 600; margin-bottom: 16px;
}
.btn-outline:hover { background: #fdf0f1; }

/* --- Follow-up Input --- */
.followup-floating {
  position: sticky;
  bottom: 0;
  z-index: 20;
  padding: 16px 0;
  background: linear-gradient(transparent, #f5f5f5 16px);
}
.followup-floating.hidden { display: none; }

.followup-floating-inner {
  display: flex;
  gap: 8px;
  background: #fff;
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: 0 -2px 16px rgba(0,0,0,0.1);
}
.followup-floating-inner input[type="text"] {
  flex: 1; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px;
  font-size: 0.9rem; outline: none; font-family: inherit;
}
.followup-floating-inner input[type="text"]:focus { border-color: #b84840; }
.followup-floating-inner .btn-primary {
  width: auto; padding: 10px 20px; font-size: 0.9rem; white-space: nowrap;
}
.followup-floating::after {
  content: 'Tutor AI is a study aid and may make mistakes. Always verify important information.';
  display: block;
  text-align: center;
  font-size: 0.7rem;
  color: #999;
  padding-top: 6px;
}

/* --- Loading Spinner --- */
.loading { text-align: center; padding: 24px; color: #999; font-size: 0.9rem; }
.loading::after {
  content: ''; display: inline-block; width: 16px; height: 16px;
  border: 2px solid #ddd; border-top-color: #b84840; border-radius: 50%;
  animation: spin 0.8s linear infinite; margin-left: 8px; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Chat History (sidebar panel) --- */
#sidebar-chat-history { flex: 1; overflow-y: auto; min-height: 0; }
.history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.history-header h3 { font-size: 0.8rem; text-transform: uppercase; color: #999; letter-spacing: 0.5px; font-weight: 600; margin: 0; }
.new-chat-btn { background: none; border: 1px solid #b84840; border-radius: 8px; padding: 4px 10px; color: #b84840; font-size: 0.8rem; cursor: pointer; font-weight: 600; }
.new-chat-btn:hover { background: #fdf0f1; }
.history-list { max-height: none; overflow-y: auto; }
.history-item { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 8px; cursor: pointer; font-size: 0.85rem; }
.history-item:hover { background: #f5f5f5; }
.history-item.active { background: #fdf0f1; }
.history-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #333; }
.history-pin-icon { font-size: 0.7rem; flex-shrink: 0; opacity: 0.6; }
.history-project-icon { flex-shrink: 0; color: #b84840; opacity: 0.5; display: inline-flex; align-items: center; cursor: default; }
.history-project-icon:hover { opacity: 1; }
.project-tooltip {
  position: fixed; background: #f5cad0; color: #1a1a2e; font-size: 0.7rem; font-weight: 500;
  padding: 4px 10px; border-radius: 20px; white-space: nowrap; z-index: 999; pointer-events: none;
  opacity: 0; transition: opacity 0.15s;
}
.project-tooltip.show { opacity: 1; }
.history-time { color: #777; font-size: 0.75rem; white-space: nowrap; flex-shrink: 0; }
.history-empty { color: #999; font-size: 0.8rem; font-style: italic; margin: 4px 0; }

/* History item — position relative for the dropdown menu */
.history-item { position: relative; }

/* Ellipsis menu button */
.history-menu-btn {
  background: none; border: none; cursor: pointer; color: #777;
  font-size: 1rem; padding: 2px 4px; line-height: 1; flex-shrink: 0;
  border-radius: 4px;
}
.history-menu-btn:hover { color: #444; background: #eee; }

/* Dropdown menu */
.history-menu {
  display: none; position: fixed;
  background: #fff; border: 1px solid #eee; border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12); z-index: 100;
  min-width: 140px; padding: 4px;
}
.history-menu.show { display: block; }
.history-action {
  display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 6px 10px; font-size: 0.82rem; cursor: pointer; border-radius: 4px; color: #333;
}
.history-action:hover { background: #f5f5f5; }
.history-action-delete { color: #b84840; }
.history-action-delete:hover { background: #fdf0f1; }

/* Inline rename input */
.history-rename-input {
  flex: 1; min-width: 0; padding: 4px 6px; border: 1px solid #b84840; border-radius: 4px;
  font-size: 0.85rem; outline: none; font-family: inherit;
}

/* --- Dashboard-Specific --- */
.greeting { font-size: 1.5rem; font-weight: 700; color: #1a1a2e; margin-bottom: 4px; }
.main-subtitle { color: #777; font-size: 0.95rem; margin-bottom: 24px; }

/* Tier / Credit card */
.tier-card { background: #fdf0f1; border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; }
.tier-label { font-size: 0.75rem; text-transform: uppercase; color: #999; letter-spacing: 0.5px; margin-bottom: 6px; }
.tier-value { font-size: 0.95rem; font-weight: 700; color: #1a1a2e; }
.tier-card.no-tier { background: #f5f5f5; }
.tier-card.no-tier .tier-value { color: #b84840; }
.tier-pct-sub { font-size: 0.75rem; color: #999; margin-top: 6px; }
.tier-bar { height: 6px; background: #e8d5d7; border-radius: 3px; overflow: hidden; margin-top: 8px; }
.tier-bar-fill { height: 100%; background: #b84840; border-radius: 3px; transition: width 0.4s ease; min-width: 3px; }
.tier-bar-fill.tier-bar-low { background: #e05050; }
.tier-upsell { font-size: 0.78rem; color: #888; margin-top: 8px; line-height: 1.4; }
.tier-upsell-link { color: #b84840; font-weight: 600; text-decoration: none; }
.tier-upsell-link:hover { text-decoration: underline; color: #a33d36; }

/* Credit action buttons */
.credit-actions { display: flex; gap: 8px; margin-top: 10px; }
.credit-btn { flex: 1; padding: 8px 12px; border: none; border-radius: 20px; font-size: 0.8rem; font-weight: 600; cursor: pointer; text-align: center; transition: background 0.2s; }
.credit-btn-primary { background: #b84840; color: #fff; }
.credit-btn-primary:hover { background: #a33d36; }
.credit-btn-secondary { background: #fdf0f1; color: #b84840; border: 1px solid #f5cad0; }
.credit-btn-secondary:hover { background: #f5cad0; }

/* Sidebar section title */
.sidebar-section-title { font-size: 0.8rem; text-transform: uppercase; color: #999; letter-spacing: 0.5px; margin-bottom: 8px; font-weight: 600; }

/* Recent list */
.recent-list { margin-bottom: 16px; }
.recent-item { display: flex; align-items: flex-start; gap: 10px; padding: 8px 8px; border-radius: 8px; cursor: pointer; font-size: 0.85rem; text-decoration: none; color: inherit; position: relative; }
.recent-item:hover { background: #f5f5f5; }
.recent-icon { color: #b84840; font-size: 1rem; flex-shrink: 0; margin-top: 1px; }
.recent-info { flex: 1; min-width: 0; }
.recent-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.recent-meta { font-size: 0.75rem; color: #999; }
.recent-empty { font-size: 0.82rem; color: #bbb; font-style: italic; padding: 8px; }


/* Filter row (pills + search) */
.filter-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.filter-search input { padding: 8px 12px; border: 1px solid #ddd; border-radius: 8px; font-size: 0.85rem; outline: none; width: 180px; }
.filter-search input:focus { border-color: #b84840; }

/* Filter pills */
.filter-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { padding: 6px 16px; border-radius: 20px; border: 1px solid #ddd; background: #fff; font-size: 0.85rem; cursor: pointer; font-weight: 500; color: #555; }
.pill:hover { border-color: #b84840; color: #b84840; }
.pill.active { background: #b84840; color: #fff; border-color: #b84840; }

/* Tool grid */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.tool-card { background: #fff; border-radius: 14px; padding: 24px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); cursor: pointer; transition: box-shadow 0.15s, transform 0.15s; text-decoration: none; color: inherit; display: block; }
.tool-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.1); transform: translateY(-2px); }
.tool-card-icon { width: 100%; aspect-ratio: 1; border-radius: 12px; background: #f3cad0; display: flex; align-items: center; justify-content: center; margin-bottom: 12px; overflow: hidden; }
.tool-card-icon img { width: 100%; height: 100%; object-fit: contain; filter: grayscale(100%); transition: filter 0.3s; }
.tool-card:hover .tool-card-icon img { filter: grayscale(0%); }
.tool-card-title { font-size: 1.05rem; font-weight: 600; color: #1a1a2e; margin-bottom: 4px; }
.tool-card-desc { font-size: 0.82rem; color: #888; line-height: 1.5; }

/* Profile menu */
.sidebar-bottom-group { margin-top: auto; }
.sidebar-bottom-group .sidebar-profile { margin-top: 0; }
.sidebar-profile { margin-top: auto; padding-top: 12px; border-top: 1px solid #eee; position: relative; }
.profile-trigger { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 8px; border-radius: 8px; }
.profile-trigger:hover { background: #f5f5f5; }
.profile-avatar { width: 32px; height: 32px; border-radius: 50%; background: #b84840; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; flex-shrink: 0; }
.profile-name { font-size: 0.85rem; font-weight: 500; color: #333; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-menu { position: absolute; bottom: 100%; left: 0; right: 0; background: #fff; border: 1px solid #eee; border-radius: 10px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); padding: 12px; display: none; margin-bottom: 4px; }
.profile-menu.show { display: block; }
.profile-menu-email { font-size: 0.8rem; color: #999; margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; }
.profile-menu-btn { background: none; border: 1px solid #ddd; border-radius: 6px; padding: 6px 12px; cursor: pointer; font-size: 0.82rem; color: #777; width: 100%; margin-bottom: 6px; }
.profile-menu-btn:hover { background: #fdf0f1; color: #b84840; border-color: #b84840; }
.profile-menu-btn:last-child { margin-bottom: 0; }
.profile-edit-form { display: none; margin-bottom: 8px; }
.profile-edit-form input { width: 100%; padding: 7px 10px; border: 1px solid #ddd; border-radius: 6px; font-size: 0.82rem; outline: none; margin-bottom: 6px; }
.profile-edit-form input:focus { border-color: #b84840; }
.profile-edit-actions { display: flex; gap: 6px; }
.profile-edit-actions button { flex: 1; padding: 6px; border-radius: 6px; font-size: 0.82rem; font-weight: 600; cursor: pointer; }
.profile-edit-save { background: #b84840; color: #fff; border: none; }
.profile-edit-save:hover { background: #a33d36; }
.profile-edit-cancel { background: #eee; color: #333; border: none; }
.profile-edit-cancel:hover { background: #ddd; }

/* --- Toast Notifications --- */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #fff;
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  border-left: 4px solid #b84840;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 380px;
  pointer-events: auto;
  animation: toast-in 0.3s ease;
}
.toast.toast-out { animation: toast-out 0.3s ease forwards; }
.toast-icon { flex-shrink: 0; color: #b84840; margin-top: 1px; }
.toast-body { flex: 1; font-size: 0.88rem; color: #333; line-height: 1.5; }
.toast-close {
  background: none; border: none; cursor: pointer; color: #bbb; font-size: 1.1rem;
  padding: 0; margin-left: 4px; flex-shrink: 0;
}
.toast-close:hover { color: #666; }
@keyframes toast-in { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toast-out { from { transform: translateX(0); opacity: 1; } to { transform: translateX(100%); opacity: 0; } }

/* --- Chat Error Message --- */
.message.error {
  background: #fdf0f1;
  border-left: 4px solid #b84840;
  animation: error-fade-in 0.3s ease;
}
.error-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.error-icon { flex-shrink: 0; color: #b84840; }
.error-title { font-size: 0.85rem; font-weight: 600; color: #b84840; }
.error-detail { font-size: 0.88rem; color: #555; line-height: 1.5; }
@keyframes error-fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* --- Form Error (upgraded) --- */
#form-error {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #b84840;
  font-size: 0.85rem;
  margin-top: 8px;
  min-height: 20px;
}
#form-error:not(:empty) { animation: error-fade-in 0.25s ease; }
#form-error .error-icon { flex-shrink: 0; }

/* --- Modal Overlay --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modal-fade-in 0.2s ease;
}
@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #fff;
  border-radius: 14px;
  padding: 24px;
  width: 90%;
  max-width: 440px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.modal h3 { font-size: 1.05rem; font-weight: 700; color: #1a1a2e; margin-bottom: 16px; }
.modal-close {
  float: right;
  background: none; border: none; font-size: 1.3rem; cursor: pointer; color: #999;
  padding: 0; line-height: 1;
}
.modal-close:hover { color: #333; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }
.modal-actions button { padding: 8px 16px; border-radius: 8px; font-size: 0.9rem; font-weight: 600; cursor: pointer; }
.modal-actions .cancel { background: #eee; color: #333; border: none; }
.modal-actions .cancel:hover { background: #ddd; }
.modal-actions .save { background: #b84840; color: #fff; border: none; }
.modal-actions .save:hover { background: #a33d36; }
.modal-actions .delete-btn { background: none; border: 1px solid #b84840; color: #b84840; }
.modal-actions .delete-btn:hover { background: #fdf0f1; }
.modal-btn-danger { background: #b84840; color: #fff; border: none; }
.modal-btn-danger:hover { background: #a33d36; }

/* Prompt modal input */
.modal-prompt-input {
  width: 100%; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px;
  font-size: 0.9rem; outline: none; font-family: inherit; margin-bottom: 4px;
}
.modal-prompt-input:focus { border-color: #b84840; }

/* --- Project Picker (checkbox list in modal) --- */
.project-check-list { list-style: none; padding: 0; margin: 0; }
.project-check-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  font-size: 0.9rem; color: #333;
}
.project-check-item:hover { background: #f5f5f5; }
.project-check-item input[type="checkbox"] { accent-color: #b84840; width: 16px; height: 16px; cursor: pointer; }
.project-check-item label { cursor: pointer; flex: 1; }
.project-new-inline {
  display: flex; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid #eee;
}
.project-new-inline input {
  flex: 1; padding: 8px 10px; border: 1px solid #ddd; border-radius: 8px;
  font-size: 0.88rem; outline: none; font-family: inherit;
}
.project-new-inline input:focus { border-color: #b84840; }
.project-new-inline button {
  background: #b84840; color: #fff; border: none; border-radius: 8px;
  padding: 8px 14px; font-size: 0.85rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.project-new-inline button:hover { background: #a33d36; }

/* --- Sidebar Projects Section (dashboard) --- */
.sidebar-projects { margin-bottom: 8px; }
.sidebar-projects .sidebar-section-title { display: flex; align-items: center; justify-content: space-between; }
.sidebar-project-list { list-style: none; padding: 0; margin: 0; }
.sidebar-project-item {
  display: block; padding: 6px 8px; border-radius: 8px; cursor: pointer;
  font-size: 0.85rem; color: #333; text-decoration: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-project-item:hover { background: #f5f5f5; }
.sidebar-project-item.active { background: #fdf0f1; color: #b84840; font-weight: 500; }
.sidebar-project-new {
  background: none; border: none; color: #b84840; font-size: 0.8rem;
  cursor: pointer; font-weight: 600; padding: 0;
}
.sidebar-project-new:hover { text-decoration: underline; }

/* --- Projects List Page --- */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.project-card {
  background: #fff; border-radius: 12px; padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06); cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
  text-decoration: none; color: inherit; display: block;
}
.project-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.1); transform: translateY(-2px); }
.project-card-icon { color: #b84840; margin-bottom: 10px; }
.project-card-name { font-size: 0.95rem; font-weight: 600; color: #1a1a2e; margin-bottom: 4px; }
.project-card-meta { font-size: 0.78rem; color: #999; }

/* --- Project View Page --- */
.project-header { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }
.project-header h2 {
  font-size: 1.4rem; font-weight: 700; color: #1a1a2e; margin: 0;
  cursor: pointer; border-bottom: 2px dashed transparent; padding-bottom: 2px;
}
.project-header h2:hover { border-bottom-color: #ddd; }
.project-header .btn-outline { margin-bottom: 0; }

.project-chat-list { display: flex; flex-direction: column; gap: 8px; }
.project-chat-item {
  display: flex; align-items: center; gap: 12px;
  background: #fff; border-radius: 10px; padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06); cursor: pointer;
  text-decoration: none; color: inherit; position: relative;
}
.project-chat-item:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.project-chat-icon { font-size: 1.2rem; flex-shrink: 0; }
.project-chat-info { flex: 1; min-width: 0; }
.project-chat-app { font-size: 0.75rem; color: #999; text-transform: uppercase; letter-spacing: 0.3px; }
.project-chat-title { font-size: 0.9rem; font-weight: 500; color: #333; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-chat-time { font-size: 0.75rem; color: #bbb; flex-shrink: 0; }
.project-grid:has(.project-empty) { display: flex; align-items: center; justify-content: center; flex: 1; min-height: 50vh; }
.project-empty { text-align: center; padding: 40px 20px; color: #999; font-size: 0.9rem; }

.btn-danger {
  background: none; border: 1px solid #b84840; color: #b84840; border-radius: 8px;
  padding: 8px 16px; font-size: 0.85rem; cursor: pointer; font-weight: 500;
}
.btn-danger:hover { background: #fdf0f1; }
.btn-icon-danger {
  background: none; border: 1px solid #ddd; color: #999; border-radius: 8px;
  width: 36px; height: 36px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.btn-icon-danger:hover { color: #b84840; border-color: #b84840; background: #fdf0f1; }

/* Add-chats modal — chat items grouped by app */
.add-chats-group { margin-bottom: 16px; }
.add-chats-group-title { font-size: 0.75rem; text-transform: uppercase; color: #999; letter-spacing: 0.5px; margin-bottom: 6px; font-weight: 600; }

/* --- Resource Cards (More Resources page) --- */
.resource-group { margin-bottom: 32px; }
.resource-group-title { font-size: 0.8rem; text-transform: uppercase; color: #999; letter-spacing: 0.5px; font-weight: 600; margin-bottom: 12px; }
.resource-grid { display: flex; flex-direction: column; gap: 10px; }
.resource-card {
  display: flex; align-items: center; gap: 16px;
  background: #fff; border-radius: 12px; padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  text-decoration: none; color: inherit;
  transition: box-shadow 0.15s, transform 0.15s;
}
.resource-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.1); transform: translateY(-1px); }
.resource-card-icon {
  width: 52px; height: 52px; border-radius: 12px; background: #fdf0f1;
  display: flex; align-items: center; justify-content: center;
  color: #b84840; flex-shrink: 0;
}
.resource-card-body { flex: 1; min-width: 0; }
.resource-card-title { font-size: 0.95rem; font-weight: 600; color: #1a1a2e; margin-bottom: 2px; }
.resource-card-desc { font-size: 0.82rem; color: #888; line-height: 1.4; }
.resource-card-arrow { color: #ccc; flex-shrink: 0; transition: color 0.15s, transform 0.15s; }
.resource-card:hover .resource-card-arrow { color: #b84840; transform: translateX(3px); }

/* --- Login Modal (guest browse gate) --- */
.login-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modal-fade-in 0.2s ease;
}
.login-modal {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px 32px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  max-width: 380px;
  width: 90%;
  position: relative;
}
.login-modal .auth-brand { text-align: center; margin-bottom: 20px; }
.login-modal .auth-brand .wordmark { font-size: 2.2rem; font-weight: 800; color: #1a1a2e; display: block; margin-bottom: 2px; }
.login-modal .auth-brand .wordmark-accent { font-family: 'BukhariScript', cursive; font-weight: normal; }
.login-modal .auth-brand .wordmark-sub { font-size: 0.8rem; color: #999; }
.login-modal-prompt { text-align: center; font-size: 0.9rem; color: #555; margin-bottom: 20px; }
.login-modal input[type="email"],
.login-modal input[type="password"],
.login-modal input[type="text"] { width: 100%; padding: 11px 14px; border: 1px solid #ddd; border-radius: 10px; font-size: 0.95rem; margin-bottom: 12px; outline: none; box-sizing: border-box; }
.login-modal .name-row { display: none; gap: 8px; }
.login-modal input:focus { border-color: #b84840; }
.login-modal .btn-login { width: 100%; padding: 12px; border: none; border-radius: 10px; font-size: 0.95rem; cursor: pointer; font-weight: 600; background: #b84840; color: #fff; margin-top: 4px; }
.login-modal .btn-login:hover { background: #a33d36; }
.login-modal .login-modal-error { color: #b84840; font-size: 0.85rem; margin-top: 8px; min-height: 20px; text-align: center; }
.login-modal .login-modal-footer { text-align: center; font-size: 0.85rem; color: #777; margin-top: 16px; }
.login-modal .login-modal-footer a { color: #b84840; text-decoration: none; font-weight: 600; cursor: pointer; }
.login-modal .login-modal-footer a:hover { text-decoration: underline; color: #a33d36; }
.login-modal-close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; font-size: 1.4rem; cursor: pointer; color: #999; line-height: 1;
}
.login-modal-close:hover { color: #333; }

/* Guest sidebar profile placeholder */
.guest-login-prompt {
  padding: 12px; text-align: center;
}
.guest-login-btn {
  display: block; width: 100%; padding: 10px; border: 1px solid #b84840;
  border-radius: 10px; background: none; color: #b84840; font-size: 0.9rem;
  font-weight: 600; cursor: pointer; text-align: center; text-decoration: none;
}
.guest-login-btn:hover { background: #fdf0f1; }

/* --- Mobile hamburger button (hidden on desktop) --- */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 16px; left: 16px;
  z-index: 50;
  background: #fff;
  border: 1px solid #eee;
  border-radius: 10px;
  width: 42px; height: 42px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  color: #333;
}
.mobile-menu-btn:hover { background: #f5f5f5; }

/* Mobile sidebar backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 9;
}
.sidebar-backdrop.show { display: block; }

/* --- Demo Signup Modal --- */
.demo-signup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modal-fade-in 0.2s ease;
}
.demo-signup-modal {
  background: #fff;
  border-radius: 16px;
  padding: 40px 36px 32px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  max-width: 400px;
  width: 90%;
  text-align: center;
  position: relative;
}
.demo-signup-close {
  position: absolute; top: 12px; right: 14px;
  background: none; border: none; font-size: 1.4rem; cursor: pointer; color: #999; line-height: 1;
}
.demo-signup-close:hover { color: #333; }
.demo-signup-icon-wrap {
  width: 56px; height: 56px; border-radius: 50%; background: #fdf0f1;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.demo-signup-heading {
  font-size: 1.15rem; font-weight: 700; color: #1a1a2e; margin-bottom: 8px;
}
.demo-signup-desc {
  font-size: 0.88rem; color: #555; line-height: 1.5; margin-bottom: 20px;
}
.demo-signup-cta {
  display: block; width: 100%; padding: 12px; border: none; border-radius: 99px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
  background: #b84840; color: #fff; text-decoration: none; text-align: center;
}
.demo-signup-cta:hover { background: #a33d36; }
.demo-signup-login {
  font-size: 0.85rem; color: #777; margin-top: 14px;
}
.demo-signup-login a {
  color: #b84840; text-decoration: none; font-weight: 600;
}
.demo-signup-login a:hover { text-decoration: underline; color: #a33d36; }

/* Demo back button */
.demo-back-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 8px;
  color: #555; text-decoration: none; margin-bottom: 16px;
  border: 1px solid #eee;
}
.demo-back-btn:hover { color: #1a1a2e; background: #f5f5f5; }

/* --- Mobile --- */
@media (max-width: 768px) {
  /* Hamburger menu visible */
  .mobile-menu-btn { display: flex; }

  /* Sidebar: off-screen drawer instead of hidden */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 20;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  /* Override collapsed state on mobile — always show full sidebar when open */
  .sidebar.mobile-open.collapsed {
    width: 320px;
    padding: 24px 16px;
  }
  .sidebar.mobile-open.collapsed .hide-collapsed { display: block; }
  .sidebar.mobile-open.collapsed .wordmark { display: block; }
  .sidebar.mobile-open.collapsed .sidebar-divider { display: block; }
  .sidebar.mobile-open.collapsed .sidebar-nav-item span { display: inline; }
  .sidebar.mobile-open.collapsed .sidebar-nav-item { justify-content: flex-start; padding: 9px 10px; }

  /* Main content: no sidebar offset */
  .main-content { margin-left: 0 !important; padding: 32px 16px; padding-top: 68px; }

  /* Tool grid: single column on very small screens */
  .tool-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }

  /* Filter row: stack vertically */
  .filter-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .filter-pills { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .filter-search input { width: 100%; }

  /* Tables: horizontal scroll */
  .message-content table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Auth card: add horizontal margin */
  .auth-card { margin: 0 16px; }

  /* Greeting / heading */
  .greeting { font-size: 1.2rem; }

  /* Toast: full width */
  #toast-container { left: 16px; right: 16px; }
  .toast { max-width: none; }

  /* Follow-up input: tighter padding */
  .followup-floating { padding: 12px 0; }
  .followup-floating-inner { padding: 10px 12px; }
}
