/* Global Theme (Light & Dark) and UX Improvements */

/* Base Light Theme */
:root {
  --app-bg: #f8fafc;
  --panel-bg: #ffffff;
  --panel-border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-glow: 0 0 15px rgba(37, 99, 235, 0.15);
  --sidebar-bg: #f1f5f9;
  --danger: #ef4444;
  --success: #10b981;
  --line: var(--panel-border);
  --muted: var(--text-muted);
  --surface-soft: var(--sidebar-bg);
  --text: var(--text-main);
}

/* CRM main navigation: keep the working modules as top tabs so chats have more width. */
.crm-workbench .modular-shell.dashboard-layout-expanded {
  grid-template-columns: minmax(0, 1fr) !important;
  gap: 14px !important;
}

.crm-workbench .crm-top-tabs.dashboard-side-nav {
  position: sticky !important;
  top: 0;
  z-index: 30;
  display: grid !important;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  padding: 10px 12px !important;
  border: 1px solid var(--panel-border, #e2e8f0);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96) !important;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(14px);
}

.crm-workbench .crm-top-tabs .module-brand {
  display: flex !important;
  align-items: center;
  gap: 8px;
  min-width: max-content;
  margin: 0 !important;
}

.crm-workbench .crm-top-tabs .module-brand span {
  width: 34px !important;
  height: 34px !important;
  min-width: 34px !important;
}

.crm-workbench .crm-top-tabs .module-brand strong {
  font-size: 14px !important;
  white-space: nowrap;
}

.crm-workbench .crm-top-tabs .dashboard-brand-caption,
.crm-workbench .crm-top-tabs .dashboard-brand-subtitle,
.crm-workbench .crm-top-tabs .module-brand small,
.crm-workbench .crm-top-tabs > div[style*="flex-grow"] {
  display: none !important;
}

.crm-workbench .crm-top-tabs .dashboard-nav-grid {
  display: flex !important;
  align-items: center;
  gap: 8px;
  width: 100% !important;
  overflow-x: auto;
  scrollbar-width: thin;
}

.crm-workbench .crm-top-tabs.dashboard-side-nav.module-launcher .dashboard-nav-grid a {
  min-width: 118px !important;
  min-height: 42px !important;
  grid-template-columns: auto 1fr !important;
  justify-content: center;
  padding: 8px 10px !important;
  border-radius: 8px !important;
}

.crm-workbench .crm-top-tabs.dashboard-side-nav.module-launcher .dashboard-nav-grid a span {
  width: 26px !important;
  height: 26px !important;
}

.crm-workbench .crm-top-tabs .module-sidebar-form {
  margin: 0 !important;
}

.crm-workbench .crm-top-tabs .module-sidebar-form button {
  min-height: 40px;
  white-space: nowrap;
}

.dashboard-shell .dashboard-scene-grid {
  align-items: start;
}

.dashboard-shell .dashboard-left-rail,
.dashboard-shell .dashboard-right-rail {
  align-content: start;
}

@media (max-width: 760px) {
  .crm-workbench .crm-top-tabs.dashboard-side-nav {
    grid-template-columns: minmax(0, 1fr);
    position: sticky !important;
    top: 0;
  }

  .crm-workbench .crm-top-tabs .module-brand,
  .crm-workbench .crm-top-tabs .module-sidebar-form {
    display: none !important;
  }

  .crm-workbench .crm-top-tabs .dashboard-nav-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    overflow: visible;
  }

  .crm-workbench .crm-top-tabs.dashboard-side-nav.module-launcher .dashboard-nav-grid a {
    min-width: 0 !important;
  }
}



/* Apply Theme to Global Backgrounds */
body, .dashboard-body, .page, .modular-crm, .dashboard-shell {
  background-color: var(--app-bg) !important;
  color: var(--text-main) !important;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Fix grid layouts due to removed elements */
.dashboard-scene-grid {
  grid-template-columns: minmax(360px, 1fr) minmax(360px, 1fr) !important;
  grid-template-areas: "left right" !important;
}

.settings-workbench.modular-shell {
  grid-template-columns: 1fr !important;
}

/* Specific Panel/Card Overrides for Theme */
.module-panel, .dashboard-card, .integration-panel, .settings-panel, .large-client-card, .workspace-panel {
  background-color: var(--panel-bg) !important;
  border-color: var(--panel-border) !important;
  box-shadow: var(--shadow-sm) !important;
  color: var(--text-main) !important;
}

.integration-panel:hover, .settings-panel:hover {
  box-shadow: var(--shadow-glow) !important;
  border-color: rgba(59, 130, 246, 0.4) !important;
}

/* Sidebar overrides */
.module-launcher, .dashboard-side-nav, .compact-rail, .chats-sidebar {
  background-color: var(--sidebar-bg) !important;
  border-right-color: var(--panel-border) !important;
}

.module-launcher nav a, .dashboard-side-nav nav a {
  color: var(--text-muted) !important;
}

.module-launcher nav a:hover {
  background-color: rgba(128, 128, 128, 0.1) !important;
  color: var(--text-main) !important;
}

.module-launcher nav a strong, .module-launcher .module-brand strong {
  color: var(--text-main) !important;
}

/* Typography Overrides */
h1, h2, h3, h4, h5, h6, strong, dt, .big-table-row span:first-child,
.modular-hero h1, .module-stage-head h2, .section-title-row h2 {
  color: var(--text-main) !important;
}

p, small, span, dd, .empty-line, .empty-chat-hint {
  color: var(--text-muted);
}

.message-delivery-read,
.message-delivery-read .message-delivery-tick,
.message-delivery[data-delivery-status="read"],
.message-delivery[data-delivery-status="read"] .message-delivery-tick {
  color: #dc2626 !important;
}

.message-delivery-sent,
.message-delivery-sent .message-delivery-tick,
.message-delivery[data-delivery-status="sent"],
.message-delivery[data-delivery-status="sent"] .message-delivery-tick,
.message-delivery[data-delivery-status="delivered"],
.message-delivery[data-delivery-status="delivered"] .message-delivery-tick {
  color: #dc2626 !important;
}

.message-delivery-read .message-delivery-tick:last-child,
.message-delivery[data-delivery-status="read"] .message-delivery-tick:last-child,
.message-delivery-sent .message-delivery-tick:last-child,
.message-delivery[data-delivery-status="sent"] .message-delivery-tick:last-child,
.message-delivery[data-delivery-status="delivered"] .message-delivery-tick:last-child {
  color: #b91c1c !important;
  text-shadow: 0 0 7px rgba(220, 38, 38, 0.22);
}

/* Inputs, Textareas, Selects */
input, textarea, select {
  background-color: var(--input-bg) !important;
  border-color: var(--input-border) !important;
  color: var(--text-main) !important;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2) !important;
  outline: none;
}



/* --- CHANNEL CARDS HIGHLIGHTING --- */
.channel-highlight-card {
  padding: 24px !important;
  border-radius: 16px !important;
  border-width: 2px !important;
}

.whatsapp-card { border-color: rgba(37, 211, 102, 0.3) !important; }
.whatsapp-card:hover { border-color: rgba(37, 211, 102, 0.8) !important; box-shadow: 0 0 20px rgba(37, 211, 102, 0.15) !important; }
.whatsapp-card .channel-icon { color: #25D366; }

.telegram-card { border-color: rgba(0, 136, 204, 0.3) !important; }
.telegram-card:hover { border-color: rgba(0, 136, 204, 0.8) !important; box-shadow: 0 0 20px rgba(0, 136, 204, 0.15) !important; }
.telegram-card .channel-icon { color: #0088cc; }

.max-card { border-color: rgba(139, 92, 246, 0.3) !important; }
.max-card:hover { border-color: rgba(139, 92, 246, 0.8) !important; box-shadow: 0 0 20px rgba(139, 92, 246, 0.15) !important; }
.max-card .channel-icon { color: #8b5cf6; }

.channel-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.channel-icon svg {
  width: 36px;
  height: 36px;
}

.channel-title h2 {
  font-size: 1.5rem !important;
  margin: 0 0 4px 0 !important;
}

.channel-title p {
  margin: 0 !important;
  font-size: 0.95rem !important;
}

/* UX Cleanup / Spoilers styling */
details.clean-spoiler {
  background: var(--sidebar-bg);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 12px;
  margin-top: 16px;
}

details.clean-spoiler summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-main);
  outline: none;
}

details.clean-spoiler summary:hover {
  color: var(--accent);
}

.button-primary, button[type="submit"]:not(.secondary-action):not(.button-muted):not(.button-danger) {
  background-color: var(--accent) !important;
  color: #ffffff !important;
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 600;
  border: none;
}

.button-primary:hover, button[type="submit"]:not(.secondary-action):not(.button-muted):not(.button-danger):hover {
  background-color: var(--accent-hover) !important;
}

/* --- HORIZONTAL TABS --- */
.settings-tabs-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--panel-border);
  padding-bottom: 12px;
}

.settings-crm-mobile-nav {
  display: none;
}

.tab-btn {
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  background-color: var(--sidebar-bg);
  color: var(--text-main);
}

.tab-btn.active {
  background-color: var(--accent);
  color: #fff;
}

/* --- VISUAL CALENDAR --- */
.calendar-visual-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.calendar-weekdays, .calendar-days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
}

.calendar-weekdays span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.calendar-days span {
  padding: 8px 0;
  font-size: 14px;
  border-radius: 6px;
  background-color: var(--app-bg);
  color: var(--text-main);
  border: 1px solid var(--panel-border);
}

.calendar-days span.other-month {
  color: #cbd5e1;
  background-color: transparent;
  border-color: transparent;
}

.calendar-days span.weekend {
  color: var(--danger);
}

.calendar-days span.today {
  background-color: var(--accent);
  color: #fff;
  font-weight: bold;
  border-color: var(--accent);
}

/* --- CHAT CHANNEL TABS --- */
.chat-channel-tabs {
  display: flex;
  gap: 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}
.chat-channel-tabs button {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: none;
  font-size: 12px;
  padding: 6px 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  min-height: auto;
}
.chat-channel-tabs button:hover {
  background: var(--surface-soft);
}
.chat-channel-tabs button.active {
  background: var(--surface-soft);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

/* --- UNIFIED SIDEBAR LAYOUT OVERRIDES --- */
.modular-shell, .modular-shell.crm-board, .dashboard-layout-expanded {
  grid-template-columns: 260px minmax(0, 1fr) !important;
  display: grid !important;
}

.module-launcher, .crm-side-nav, .dashboard-side-nav {
  width: 260px !important;
  min-width: 260px !important;
  max-width: 260px !important;
  box-sizing: border-box !important;
  padding: 24px 16px !important;
  display: flex !important;
  flex-direction: column !important;
  border-radius: 0 !important;
  border: none !important;
  border-right: 1px solid var(--panel-border) !important;
  margin: 0 !important;
}

.compact-rail .module-brand {
  grid-template-columns: 46px minmax(0, 1fr) !important;
  justify-items: start !important;
  gap: 12px !important;
  padding-bottom: 16px !important;
  margin-bottom: 14px !important;
}

.compact-rail .module-brand strong,
.compact-rail .module-brand small {
  position: static !important;
  width: auto !important;
  height: auto !important;
  overflow: visible !important;
  clip: auto !important;
  white-space: normal !important;
}

.compact-rail.module-launcher nav {
  display: grid !important;
  gap: 10px !important;
}

.compact-rail.module-launcher nav a {
  grid-template-columns: 42px minmax(0, 1fr) !important;
  justify-items: start !important;
  gap: 10px !important;
  min-height: 72px !important;
  padding: 12px !important;
  text-align: left !important;
}

.compact-rail.module-launcher nav a span {
  width: 42px !important;
  height: 42px !important;
  border-radius: 50% !important;
  font-size: 18px !important;
  display: grid !important;
  place-items: center !important;
}

.compact-rail.module-launcher nav a strong {
  font-size: 17px !important;
  line-height: 1.15 !important;
}

.compact-rail.module-launcher nav a small {
  display: block !important;
  font-size: 13px !important;
}

/* --- COLLAPSIBLE BOXES UX IMPROVEMENTS --- */
details.clean-spoiler {
  background-color: var(--sidebar-bg) !important;
  border: 1px solid var(--panel-border) !important;
  border-radius: 12px !important;
  padding: 12px 16px !important;
  margin-top: 16px !important;
  transition: all 0.2s ease;
}

details.clean-spoiler[open] {
  background-color: var(--panel-bg) !important;
  box-shadow: var(--shadow-md) !important;
}

details.clean-spoiler summary {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  color: var(--text-main);
  outline: none;
}

details.clean-spoiler summary::-webkit-details-marker {
  display: none;
}

details.clean-spoiler summary::after {
  content: "▼";
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

details.clean-spoiler[open] summary::after {
  transform: rotate(180deg);
}

.max-mapping-details {
  border-left: 3px solid var(--accent) !important;
}
.max-mapping-details[open] {
  border-left-width: 3px !important;
}

/* --- OPERATOR UX SIMPLIFICATION / RESPONSIVE LAST PASS --- */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

.modular-crm,
.modular-shell,
.module-stage,
.module-panel,
.workspace-panel,
.settings-panel,
.integration-panel,
.dashboard-card,
.big-table,
.large-client-card,
.chat-module-grid,
.campaign-detail-workspace,
.campaign-create-grid,
.settings-grid,
.account-auth-grid {
  min-width: 0 !important;
}

.module-stage-head p,
.modular-hero p:last-child,
.campaign-preview-card,
.settings-inline-note,
.dashboard-brand-subtitle {
  max-width: 760px;
}

.operator-secondary-panel {
  margin-bottom: 18px;
}

.operator-secondary-panel .campaign-quick-send {
  margin: 14px 0 0;
}

.big-table-row,
.big-table-head,
.module-actions,
.section-title-row,
.inline-actions,
.campaign-hero-actions,
.module-header-actions,
.settings-savebar,
.knowledge-upload-form,
.campaign-reply-form,
.large-input-form,
.chat-reply-form {
  min-width: 0 !important;
}

.big-table-row span,
.big-table-row strong,
.big-table-row small,
.big-table-row em,
.crm-item strong,
.crm-item small,
.module-panel p,
.module-panel small {
  overflow-wrap: anywhere;
}

@media (max-width: 1180px) {
  .modular-shell,
  .modular-shell.crm-board,
  .dashboard-layout-expanded,
  .campaign-create-shell,
  .campaign-detail-shell,
  .settings-workbench {
    width: 100% !important;
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .module-launcher,
  .crm-side-nav,
  .dashboard-side-nav,
  .campaign-flow-sidebar {
    position: static !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    min-height: auto !important;
    border-right: 0 !important;
    border-bottom: 1px solid var(--panel-border) !important;
  }

  .compact-rail.module-launcher nav,
  .dashboard-side-nav.module-launcher .dashboard-nav-grid,
  .module-launcher nav {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }

  .compact-rail.module-launcher nav a,
  .dashboard-side-nav.module-launcher .dashboard-nav-grid a,
  .module-launcher nav a {
    min-height: 64px !important;
    grid-template-columns: minmax(0, 1fr) !important;
    justify-items: center !important;
    text-align: center !important;
  }

  .compact-rail.module-launcher nav a span,
  .dashboard-side-nav.module-launcher .dashboard-nav-grid a span,
  .module-launcher nav a span {
    grid-row: auto !important;
  }

  .compact-rail.module-launcher nav a small,
  .dashboard-side-nav.module-launcher .dashboard-nav-grid a small,
  .module-launcher nav a small,
  .dashboard-hidden-copy,
  .dashboard-brand-caption,
  .dashboard-brand-subtitle {
    display: none !important;
  }

  .module-metrics,
  .campaign-safe-flow-grid,
  .settings-summary-metrics,
  .integration-grid,
  .account-auth-grid,
  .settings-guide-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 760px) {
  .modular-crm {
    padding: 10px !important;
  }

  .modular-hero {
    display: none !important;
  }

  .module-stage {
    padding: 0 !important;
  }

  .module-stage-head {
    margin-bottom: 10px !important;
    padding: 14px !important;
    border-radius: 8px !important;
    background: var(--panel-bg) !important;
    border: 1px solid var(--panel-border) !important;
  }

  .module-stage-head span,
  .module-stage-head p,
  .inline-home-link {
    display: none !important;
  }

  .module-stage-head h2 {
    margin: 0 !important;
    font-size: 24px !important;
    line-height: 1.15 !important;
  }

  .module-panel,
  .settings-panel,
  .integration-panel,
  .workspace-panel,
  .large-client-card aside,
  .large-client-card main,
  .chat-module-grid aside,
  .chat-module-grid main {
    padding: 14px !important;
    border-radius: 8px !important;
  }

  .compact-rail.module-launcher nav,
  .dashboard-side-nav.module-launcher .dashboard-nav-grid,
  .module-launcher nav {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 8px !important;
  }

  .compact-rail.module-launcher nav a,
  .dashboard-side-nav.module-launcher .dashboard-nav-grid a,
  .module-launcher nav a {
    min-height: 58px !important;
    padding: 8px 6px !important;
  }

  .compact-rail.module-launcher nav a span,
  .dashboard-side-nav.module-launcher .dashboard-nav-grid a span,
  .module-launcher nav a span {
    width: 34px !important;
    height: 34px !important;
  }

  .compact-rail.module-launcher nav a strong,
  .dashboard-side-nav.module-launcher .dashboard-nav-grid a strong,
  .module-launcher nav a strong {
    font-size: 12px !important;
    line-height: 1.15 !important;
  }

  .module-brand,
  .module-sidebar-form,
  .campaign-step-list,
  .campaign-first-message,
  .campaign-preview-panel,
  .settings-guide-grid,
  .settings-summary-metrics,
  .module-metrics {
    display: none !important;
  }

  .section-title-row,
  .module-actions,
  .campaign-hero-actions,
  .module-header-actions,
  .settings-savebar,
  .campaign-safe-flow-note {
    align-items: stretch !important;
    flex-direction: column !important;
  }

  .module-actions > *,
  .module-header-actions > *,
  .campaign-hero-actions > *,
  .settings-savebar button,
  .knowledge-upload-form input,
  .knowledge-upload-form button {
    width: 100% !important;
  }

  .module-metrics,
  .campaign-safe-flow-grid,
  .settings-summary-metrics,
  .integration-grid,
  .account-auth-grid,
  .settings-guide-grid,
  .settings-grid,
  .operator-settings-grid,
  .scenario-fields-grid,
  .campaign-create-grid,
  .campaign-detail-workspace,
  .calendar-grid,
  .large-client-card,
  .chat-module-grid,
  .telegram-auth-grid,
  .whatsapp-connect-layout,
  .whatsapp-qr-box,
  .campaign-quick-send {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .big-table-head {
    display: none !important;
  }

  .big-table-row,
  .campaigns-big-table .big-table-row,
  .clients-big-table .big-table-row,
  .campaign-recipients-table .big-table-row,
  .leads-table .big-table-row {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 6px !important;
    padding: 14px !important;
    border: 1px solid var(--panel-border) !important;
    border-radius: 8px !important;
    background: var(--panel-bg) !important;
  }

  .big-table,
  .task-stack,
  .campaign-events,
  .knowledge-documents-list {
    display: grid !important;
    gap: 10px !important;
  }

  .inline-actions,
  .campaign-reply-form,
  .large-input-form,
  .chat-reply-form,
  .max-mapping-actions,
  .account-connect-actions {
    align-items: stretch !important;
    flex-direction: column !important;
  }

  .inline-actions > *,
  .inline-actions form,
  .inline-actions button,
  .inline-actions input,
  .campaign-reply-form > *,
  .large-input-form > *,
  .chat-reply-form > *,
  .max-mapping-actions > *,
  .account-connect-actions > * {
    width: 100% !important;
    max-width: none !important;
  }

  .settings-tabs-nav {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 8px !important;
    border-bottom: 0 !important;
  }

  .tab-btn {
    width: 100% !important;
    padding: 10px 8px !important;
  }

  .whatsapp-connect-layout {
    align-items: start !important;
  }

  .whatsapp-connect-form,
  .telegram-auth-grid .settings-fields {
    align-content: start !important;
    align-self: start !important;
  }

  .whatsapp-connect-form .account-connect-actions > button,
  .telegram-auth-grid .settings-fields > button {
    flex: 0 0 auto !important;
    min-height: 44px !important;
    height: auto !important;
    padding-top: 11px !important;
    padding-bottom: 11px !important;
  }

  .integration-admin-details:not([open]),
  .max-observability-panel,
  .campaign-safe-flow p,
  .campaign-safe-flow-note,
  .settings-inline-note,
  .campaign-preview-card {
    margin-top: 10px !important;
  }
}

@media (max-width: 900px) {
  .big-table-head {
    display: none !important;
  }

  .big-table-row,
  .campaigns-big-table .big-table-row,
  .clients-big-table .big-table-row,
  .campaign-recipients-table .big-table-row,
  .leads-table .big-table-row {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 6px !important;
    padding: 14px !important;
    border: 1px solid var(--panel-border) !important;
    border-radius: 8px !important;
    background: var(--panel-bg) !important;
  }

  .big-table,
  .campaigns-big-table,
  .clients-big-table,
  .campaign-recipients-table,
  .leads-table {
    display: grid !important;
    gap: 10px !important;
    overflow: visible !important;
  }

  .big-table-row > *,
  .campaign-recipients-table.has-max-column .big-table-row > span,
  .clients-big-table .big-table-row > span,
  .campaigns-big-table .big-table-row > span,
  .leads-table .big-table-row > span {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .status-pill,
  .integration-status {
    width: fit-content !important;
    max-width: 100% !important;
    white-space: normal !important;
  }

  .campaign-submit-actions {
    align-items: stretch !important;
    flex-direction: column !important;
  }

  .campaign-submit-actions > *,
  .campaign-submit-actions button,
  .campaign-submit-actions a {
    width: 100% !important;
    max-width: none !important;
  }

  .campaign-recipients-table form {
    display: inline-flex !important;
    max-width: 100% !important;
    vertical-align: middle !important;
  }

  .retry-precheck-btn {
    box-sizing: border-box !important;
    max-width: 100% !important;
    min-width: 34px !important;
    margin-left: 4px !important;
    padding: 5px 8px !important;
  }

  .campaign-send-box,
  .test-box.campaign-send-box,
  .campaign-test-panel {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .integration-panel-head,
  .settings-panel-head,
  .webhook-log-row {
    align-items: flex-start !important;
    flex-wrap: wrap !important;
    gap: 10px !important;
  }

  .integration-panel-head .integration-status,
  .settings-panel-head .integration-status,
  .webhook-log-row .integration-status {
    margin-left: 0 !important;
  }
}

@media (max-width: 760px) {
  body.dashboard-body,
  body:has(.crm-workbench) {
    margin: 0 !important;
  }

  body.dashboard-body .page,
  body:has(.crm-workbench) .page {
    padding: 8px !important;
  }

  .dashboard-shell,
  .dashboard-hud,
  .dashboard-hud-copy,
  .dashboard-hud-tools,
  .dashboard-scene-grid,
  .dashboard-left-rail,
  .dashboard-right-rail,
  .dashboard-funnel-card {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .dashboard-hud {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    padding: 0 !important;
  }

  .dashboard-hud-copy h2 {
    max-width: 100% !important;
    overflow-wrap: anywhere !important;
    font-size: 28px !important;
    line-height: 1.12 !important;
  }

  .dashboard-hud-copy p,
  .dashboard-hud-tools,
  .dashboard-hidden-copy {
    display: none !important;
  }

  .dashboard-scene-grid {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    grid-template-areas: none !important;
    gap: 12px !important;
  }

  .dashboard-left-rail,
  .dashboard-right-rail,
  .dashboard-funnel-card {
    grid-area: auto !important;
  }

  .dashboard-left-rail,
  .dashboard-right-rail {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .settings-crm-mobile-nav {
    position: sticky;
    top: 0;
    z-index: 20;
    width: min(100%, 1540px);
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 0 auto 12px;
    padding: 10px 12px;
    background: var(--surface, #ffffff);
    border: 1px solid var(--panel-border, #e2e8f0);
    border-radius: 8px;
    box-shadow: 0 12px 26px rgba(15, 23, 42, 0.12);
  }

  .settings-crm-mobile-nav a {
    min-width: 0;
    min-height: 42px;
    display: grid;
    place-items: center;
    padding: 8px 6px;
    border: 1px solid var(--panel-border, #e2e8f0);
    border-radius: 8px;
    background: var(--panel, #f8fafc);
    color: var(--text, #0f172a);
    font-size: 12px;
    font-weight: 800;
    line-height: 1.15;
    text-align: center;
    text-decoration: none;
    overflow-wrap: anywhere;
  }

  .module-launcher,
  .crm-side-nav,
  .dashboard-side-nav,
  .compact-rail.module-launcher,
  .dashboard-side-nav.module-launcher {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    overflow: hidden !important;
  }

  .module-launcher nav,
  .crm-side-nav nav,
  .dashboard-side-nav .dashboard-nav-grid {
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
  }

  .module-launcher nav a,
  .crm-side-nav nav a,
  .dashboard-side-nav .dashboard-nav-grid a {
    box-sizing: border-box !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }
}

@media (max-width: 430px) {
  .compact-rail.module-launcher nav,
  .crm-side-nav.module-launcher .dashboard-nav-grid,
  .dashboard-side-nav.module-launcher .dashboard-nav-grid,
  .module-launcher nav {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .crm-side-nav.module-launcher,
  .crm-side-nav.module-launcher .dashboard-nav-grid {
    overflow: visible !important;
  }

  .settings-tabs-nav {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .settings-crm-mobile-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .module-stage-head h2 {
    font-size: 21px !important;
  }
}

/* Final CRM top-tabs override. Keep this at the end: legacy dashboard sidebar rules are very specific. */
.crm-workbench > .modular-shell.crm-board.dashboard-layout-expanded {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) !important;
  grid-template-rows: auto minmax(0, 1fr) !important;
  grid-template-areas:
    "crmnav"
    "crmstage" !important;
  align-items: start !important;
  gap: 12px !important;
  width: 100% !important;
}

.crm-workbench > .modular-shell.crm-board.dashboard-layout-expanded > .crm-top-tabs.dashboard-side-nav {
  grid-area: crmnav !important;
  position: sticky !important;
  top: 0 !important;
  z-index: 50 !important;
  display: block !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  min-height: 0 !important;
  height: auto !important;
  padding: 8px !important;
  margin: 0 !important;
  border: 1px solid var(--panel-border, #e2e8f0) !important;
  border-radius: 8px !important;
  background: rgba(255, 255, 255, 0.96) !important;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.08) !important;
  overflow: visible !important;
}

.crm-workbench > .modular-shell.crm-board.dashboard-layout-expanded > .module-stage {
  grid-area: crmstage !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
}

.crm-top-tabs .module-brand,
.crm-top-tabs .dashboard-brand-caption,
.crm-top-tabs .dashboard-brand-subtitle,
.crm-top-tabs .module-sidebar-form,
.crm-top-tabs > div[style*="flex-grow"] {
  display: none !important;
}

.crm-top-tabs.module-launcher .dashboard-nav-grid,
.crm-top-tabs.dashboard-side-nav.module-launcher .dashboard-nav-grid,
.crm-top-tabs.module-launcher nav {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: 8px !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  margin: 0 !important;
  overflow-x: auto !important;
  overflow-y: hidden !important;
  scrollbar-width: thin;
}

.crm-top-tabs.dashboard-side-nav.module-launcher .dashboard-nav-grid a,
.crm-top-tabs.module-launcher nav a {
  flex: 0 0 auto !important;
  width: auto !important;
  min-width: 112px !important;
  max-width: 180px !important;
  min-height: 42px !important;
  display: inline-grid !important;
  grid-template-columns: 24px auto !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  padding: 8px 12px !important;
  border-radius: 8px !important;
  text-align: center !important;
}

.crm-top-tabs.dashboard-side-nav.module-launcher .dashboard-nav-grid a span,
.crm-top-tabs.module-launcher nav a span {
  width: 24px !important;
  height: 24px !important;
  min-width: 24px !important;
  border-radius: 6px !important;
}

.crm-top-tabs.dashboard-side-nav.module-launcher .dashboard-nav-grid a strong,
.crm-top-tabs.module-launcher nav a strong {
  display: block !important;
  min-width: 0 !important;
  font-size: 13px !important;
  line-height: 1.1 !important;
  white-space: nowrap !important;
}

@media (max-width: 720px) {
  .crm-workbench > .modular-shell.crm-board.dashboard-layout-expanded {
    gap: 8px !important;
  }

  .crm-workbench > .modular-shell.crm-board.dashboard-layout-expanded > .crm-top-tabs.dashboard-side-nav {
    top: 0 !important;
    padding: 7px !important;
    border-radius: 8px !important;
  }

  .crm-top-tabs.dashboard-side-nav.module-launcher .dashboard-nav-grid,
  .crm-top-tabs.module-launcher nav {
    display: flex !important;
    grid-template-columns: none !important;
    gap: 6px !important;
    overflow-x: auto !important;
  }

  .crm-top-tabs.dashboard-side-nav.module-launcher .dashboard-nav-grid a,
  .crm-top-tabs.module-launcher nav a {
    min-width: 104px !important;
    min-height: 38px !important;
    padding: 7px 9px !important;
    grid-template-columns: 20px auto !important;
  }

  .crm-top-tabs.dashboard-side-nav.module-launcher .dashboard-nav-grid a span,
  .crm-top-tabs.module-launcher nav a span {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
  }

  .crm-top-tabs.dashboard-side-nav.module-launcher .dashboard-nav-grid a strong,
  .crm-top-tabs.module-launcher nav a strong {
    font-size: 12px !important;
  }
}

/* Late overrides for the CRM cleanup pass. */
.dashboard-side-nav .module-brand,
.crm-side-nav .module-brand {
  display: none !important;
}

.large-chat p,
.card-chat p,
.big-chat p,
.dialog-row-title,
.dialog-row-desc,
.chat-module-client-bar,
.status-pill,
.channel-badge,
.dialog-row-badge,
.module-launcher nav a strong,
.module-launcher nav a small {
  word-break: normal !important;
  overflow-wrap: break-word !important;
  hyphens: none !important;
  text-wrap: pretty;
}

.status-pill,
.channel-badge,
.dialog-row-badge,
.view-control-btn {
  white-space: normal !important;
  line-height: 1.15 !important;
}

.settings-tabs-nav {
  position: sticky !important;
  top: 0 !important;
  z-index: 5 !important;
}

.crm-top-tabs .module-brand,
.crm-top-tabs .dashboard-brand-caption,
.crm-top-tabs .dashboard-brand-subtitle,
.dashboard-side-nav .module-brand,
.crm-side-nav .module-brand {
  display: none !important;
}

.dashboard-simple-grid {
  display: grid !important;
  grid-template-columns: minmax(320px, 0.95fr) minmax(320px, 1.05fr) !important;
  gap: 18px !important;
  align-items: start !important;
}

.dialog-row-large.status-hot_lead,
.dialog-row-large.needs-manager,
.dialog-row-large.status-human_takeover {
  background: var(--surface, #fff) !important;
  box-shadow: none !important;
}

.dialog-priority-badge.priority-hot {
  background: #fff7ed !important;
  color: #9a3412 !important;
  box-shadow: inset 0 0 0 1px #fed7aa !important;
}

.dialog-priority-badge.priority-manager {
  background: #eff6ff !important;
  color: #1d4ed8 !important;
  box-shadow: inset 0 0 0 1px #bfdbfe !important;
}

@media (max-width: 900px) {
  .dashboard-simple-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}
