/* Grid Column Utilities */
.grid { display: grid; }
.grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (min-width: 640px) {
  .sm\:grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
  .sm\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sm\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .sm\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 768px) {
  .md\:grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
  .md\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .md\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .md\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 1024px) {
  .lg\:grid-cols-1 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
  .lg\:grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lg\:grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lg\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .lg\:col-span-1 { grid-column: span 1 / span 1; }
  .lg\:col-span-2 { grid-column: span 2 / span 2; }
  .lg\:col-span-3 { grid-column: span 3 / span 3; }
  .lg\:col-span-4 { grid-column: span 4 / span 4; }
}

.col-span-1 { grid-column: span 1 / span 1; }
.col-span-2 { grid-column: span 2 / span 2; }
.col-span-3 { grid-column: span 3 / span 3; }
.col-span-4 { grid-column: span 4 / span 4; }
.col-span-full { grid-column: 1 / -1; }

/* Toasts */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.crm-toast {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 280px;
  max-width: 380px;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  background: #ffffff;
  border: 1px solid rgba(226, 232, 240, 0.9);
  box-shadow: 0 10px 30px -8px rgba(2, 6, 23, 0.18);
  font-weight: 500;
  color: #0f172a;
}

/* Toggle switch (shared by settings, automations, roles) */
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 9999px;
  background: #cbd5e1;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
  transition: transform 0.2s;
}
.toggle-switch.on {
  background: #5048e5;
}
.toggle-switch.on::after {
  transform: translateX(20px);
}

/* User dropdown in topbar */
.user-dropdown {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  min-width: 220px;
  padding: 0.5rem;
  border-radius: 0.875rem;
  background: #ffffff;
  border: 1px solid rgba(226, 232, 240, 0.9);
  box-shadow: 0 16px 40px -12px rgba(2, 6, 23, 0.2);
  z-index: 60;
}
.user-dropdown.open {
  display: block;
  animation: fadeIn .18s ease-out;
}
.user-dropdown a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.83rem;
  font-weight: 500;
  color: hsl(var(--foreground));
  text-decoration: none;
  transition: background-color .15s ease;
}
.user-dropdown a:hover {
  background: hsl(var(--muted));
}

/* Mobile sidebar */
#mobileSidebarBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity .3s ease;
}
#mobileSidebar {
  transform: translateX(-100%);
  transition: transform .3s ease;
}
#mobileSidebarWrap.open #mobileSidebar {
  transform: translateX(0);
}
#mobileSidebarWrap.open #mobileSidebarBackdrop {
  opacity: 1;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Slight scrollbar styling */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 6px;
}
::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}
::-webkit-scrollbar-track {
  background: transparent;
}

/* ===== GMAIL 3-COLUMN LAYOUT & SIDEBAR ===== */
.mailbox-container {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  align-items: flex-start;
  width: 100%;
}

@media (min-width: 1024px) {
  .mailbox-container {
    flex-direction: row;
    align-items: stretch;
  }
}

.mailbox-middle-sidebar {
  width: 100%;
  flex-shrink: 0;
}

@media (min-width: 1024px) {
  .mailbox-middle-sidebar {
    width: 230px;
    min-width: 230px;
    max-width: 230px;
  }
}

.mailbox-main-area {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

/* Iconic Gmail Compose Pill Button */
.gmail-compose-pill {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.35rem;
  border-radius: 1rem;
  background: #ffffff;
  color: #1e293b;
  font-size: 0.875rem;
  font-weight: 700;
  border: 1px solid #e2e8f0;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  width: fit-content;
}

.gmail-compose-pill:hover {
  background: #f8fafc;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.12);
  transform: translateY(-1px);
}

/* Gmail Sidebar Folder Items */
.gmail-folder-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.625rem;
  border-radius: 9999px;
  padding: 0.45rem 0.85rem;
  transition: all 0.15s ease;
  color: #334155;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.8125rem;
}

.gmail-folder-item:hover {
  background-color: #f1f5f9;
  color: #0f172a;
}

.gmail-folder-item.active {
  background-color: #d3e3fd !important;
  color: #041e49 !important;
  font-weight: 700 !important;
}

.gmail-folder-item.active svg {
  color: #041e49 !important;
  stroke: #041e49 !important;
}

.gmail-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.45rem;
  border-radius: 9999px;
  background-color: #e2e8f0;
  color: #475569;
}

/* ===== GMAIL ROW & TABLE LAYOUT ===== */
.gmail-table-container {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
}

.gmail-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 1rem;
  border-bottom: 1px solid #f1f5f9;
  transition: background-color 0.12s ease, box-shadow 0.12s ease;
  cursor: pointer;
  position: relative;
}

.gmail-row:last-child {
  border-bottom: none;
}

.gmail-row.is-unread {
  background-color: #ffffff;
  font-weight: 600;
}

.gmail-row.is-read {
  background-color: #f8fafc;
}

.gmail-row:hover {
  background-color: #f1f5f9;
  box-shadow: inset 1px 0 0 #cbd5e1, 0 1px 4px rgba(0, 0, 0, 0.05);
}

.gmail-row.selected {
  background-color: #c2e7ff !important;
}

.gmail-star-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.gmail-star-btn.is-starred svg {
  fill: #f59e0b !important;
  stroke: #f59e0b !important;
}

/* Hover Quick Actions on Row */
.gmail-row-hover-actions {
  display: none;
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  background: #f1f5f9;
  padding: 0.15rem 0.35rem;
  border-radius: 9999px;
  align-items: center;
  gap: 0.25rem;
  z-index: 10;
}

.gmail-row:hover .gmail-row-hover-actions {
  display: flex;
}

.gmail-row:hover .gmail-date-cell {
  visibility: hidden;
}

.gmail-hover-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 9999px;
  color: #64748b;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}

.gmail-hover-btn:hover {
  background-color: #e2e8f0;
  color: #0f172a;
}

/* Quick Filter Dropdown */
.quick-filter-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 210px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 0.875rem;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
  padding: 0.4rem;
  z-index: 50;
}

.quick-filter-dropdown.open {
  display: block;
}

.quick-filter-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.55rem 0.75rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #334155;
  text-decoration: none;
  transition: background-color 0.15s;
}

.quick-filter-item:hover {
  background-color: #f8fafc;
  color: #0f172a;
}

.quick-filter-item.active {
  background-color: #eff6ff;
  color: #2563eb;
  font-weight: 600;
}

/* ===== GMAIL FLOATING COMPOSE WINDOW ===== */
.floating-compose-box {
  position: fixed;
  bottom: 0;
  right: 1.5rem;
  width: 580px;
  max-width: calc(100vw - 2rem);
  height: 560px;
  max-height: calc(100vh - 4rem);
  background: #ffffff;
  border-radius: 1rem 1rem 0 0;
  box-shadow: 0 -6px 30px rgba(15, 23, 42, 0.2);
  border: 1px solid #cbd5e1;
  border-bottom: none;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.floating-compose-box .compose-header {
  flex-shrink: 0;
}

.floating-compose-box .compose-body-wrap {
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #ffffff;
}

.floating-compose-box form#composeEmailForm {
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0;
}

.floating-compose-box .compose-fields-section {
  flex-shrink: 0;
}

.floating-compose-box .compose-editor-area {
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.floating-compose-box #quillEditor {
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: none !important;
}

.floating-compose-box #quillEditor .ql-toolbar {
  flex-shrink: 0;
  border-left: none !important;
  border-right: none !important;
  border-top: none !important;
  border-bottom: 1px solid #e2e8f0 !important;
  background: #f8fafc;
  padding: 4px 8px;
}

.floating-compose-box #quillEditor .ql-container {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  border: none !important;
  font-family: inherit;
  font-size: 13px;
}

.floating-compose-box #quillEditor .ql-editor {
  min-height: 100%;
  height: auto;
  padding: 12px 16px;
  line-height: 1.6;
}

.floating-compose-box .compose-bottom-toolbar {
  flex-shrink: 0;
  border-top: 1px solid #f1f5f9;
  background: #ffffff;
  z-index: 10;
}

.floating-compose-box.hidden,
.floating-compose-box[style*="display: none"] {
  display: none !important;
}

.floating-compose-box.minimized {
  height: 44px !important;
  overflow: hidden;
}

.floating-compose-box.minimized .compose-body-wrap {
  display: none;
}

.floating-compose-box.maximized {
  width: calc(100vw - 3rem) !important;
  height: calc(100vh - 3rem) !important;
  max-height: calc(100vh - 3rem) !important;
  right: 1.5rem !important;
  bottom: 1.5rem !important;
  border-radius: 1rem !important;
  border-bottom: 1px solid #cbd5e1;
}

/* Authentic Gmail Compose Action Buttons */
.gmail-send-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 0.45rem !important;
  padding: 0.55rem 1.45rem !important;
  background-color: #0b57d0 !important;
  color: #ffffff !important;
  font-size: 0.8125rem !important;
  font-weight: 700 !important;
  line-height: 1 !important;
  border-radius: 9999px !important;
  border: none !important;
  box-shadow: 0 2px 6px rgba(11, 87, 208, 0.3) !important;
  cursor: pointer !important;
  transition: all 0.15s ease !important;
  text-decoration: none !important;
  min-height: 36px !important;
}

.gmail-send-btn:hover {
  background-color: #0842a0 !important;
  box-shadow: 0 4px 10px rgba(11, 87, 208, 0.4) !important;
  transform: translateY(-1px);
}

.gmail-send-btn svg {
  stroke: #ffffff !important;
  color: #ffffff !important;
  width: 14px !important;
  height: 14px !important;
}

.gmail-draft-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0.45rem 1rem !important;
  background-color: #f1f5f9 !important;
  color: #334155 !important;
  font-size: 0.75rem !important;
  font-weight: 600 !important;
  border-radius: 9999px !important;
  border: 1px solid #cbd5e1 !important;
  cursor: pointer !important;
  transition: all 0.15s ease !important;
  min-height: 34px !important;
}

.gmail-draft-btn:hover {
  background-color: #e2e8f0 !important;
  color: #0f172a !important;
}

.gmail-toolbar-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 34px !important;
  height: 34px !important;
  border-radius: 9999px !important;
  color: #475569 !important;
  background: transparent !important;
  border: none !important;
  cursor: pointer !important;
  transition: all 0.15s ease !important;
}

.gmail-toolbar-btn:hover {
  background-color: #f1f5f9 !important;
  color: #0f172a !important;
}

.gmail-discard-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 34px !important;
  height: 34px !important;
  border-radius: 9999px !important;
  color: #94a3b8 !important;
  background: transparent !important;
  border: none !important;
  cursor: pointer !important;
  transition: all 0.15s ease !important;
}

.gmail-discard-btn:hover {
  background-color: #ffe4e6 !important;
  color: #e11d48 !important;
}

/* Emoji Picker & Template Popover Styling */
#composeEmojiPicker, #composeTemplatePopover {
  box-shadow: 0 12px 36px -4px rgba(15, 23, 42, 0.25), 0 4px 14px -2px rgba(15, 23, 42, 0.12) !important;
  border-radius: 1rem !important;
}

#composeEmojiPicker {
  width: 356px !important;
  max-width: calc(100vw - 2.5rem) !important;
  background: #ffffff !important;
  border: 1px solid #e2e8f0 !important;
}

#emojiGrid, .emoji-grid-container {
  display: grid !important;
  grid-template-columns: repeat(8, 1fr) !important;
  gap: 3px !important;
  max-height: 215px !important;
  overflow-y: auto !important;
  padding: 6px !important;
  align-content: start !important;
}

.emoji-grid-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 36px !important;
  height: 36px !important;
  font-size: 1.35rem !important;
  line-height: 1 !important;
  border-radius: 8px !important;
  background: transparent !important;
  border: none !important;
  cursor: pointer !important;
  user-select: none !important;
  transition: transform 0.1s ease, background-color 0.15s ease !important;
}

.emoji-grid-btn:hover {
  background-color: #f1f5f9 !important;
  transform: scale(1.24) !important;
  z-index: 5 !important;
}

.emoji-grid-btn:active {
  transform: scale(0.92) !important;
}

.emoji-category-tabs-bar {
  display: flex !important;
  align-items: center !important;
  gap: 3px !important;
  overflow-x: auto !important;
  padding: 4px 6px !important;
  border-bottom: 1px solid #f1f5f9 !important;
  white-space: nowrap !important;
}

.emoji-cat-tab {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 4px 8px !important;
  border-radius: 9999px !important;
  font-size: 11px !important;
  font-weight: 600 !important;
  border: none !important;
  background: transparent !important;
  color: #64748b !important;
  cursor: pointer !important;
  flex-shrink: 0 !important;
  transition: all 0.15s ease !important;
}

.emoji-cat-tab:hover {
  background-color: #f1f5f9 !important;
  color: #0f172a !important;
}

.emoji-cat-tab.active {
  background-color: #eff6ff !important;
  color: #2563eb !important;
  font-weight: 700 !important;
}

#emojiGrid::-webkit-scrollbar, #composeTemplateList::-webkit-scrollbar {
  width: 5px;
}

#emojiGrid::-webkit-scrollbar-thumb, #composeTemplateList::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 9999px;
}

.no-scrollbar::-webkit-scrollbar {
  display: none;
}
.no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}