/* App-specific overrides on top of Tabler/CoreUI theme (BRD Section 12, FR-83, FR-87) */

/* ---------- Global shell ---------- */
body { background: #f4f6fb; }

/* Full-width layout: this is an internal, desktop-first LAN tool typically
   used on wide monitors (Browser Support NFR), so the navbar and page
   content should span the full viewport instead of being centered in
   Tabler's fixed-width `.container-xl` (capped at 1140px/1320px+ at larger
   breakpoints). Both `_navbar.html` and `base.html` use `.container-xl` for
   consistent left/right gutters, so overriding its max-width here (rather
   than removing the class from two templates) keeps that gutter/padding
   behavior while removing the centered-column cap everywhere at once. */
.navbar .container-xl,
.page-body.container-xl {
  max-width: none;
}

/* Tabler's `.page-body` rule (`margin-top: var(--tblr-page-padding-y)`, i.e.
   1.5rem/24px) adds a large gap between the sticky navbar and the first
   heading on every page ("My Dashboard", etc.) — reduce it to a tighter,
   more typical top gap while leaving the bottom margin untouched. */
.page-body.container-xl {
  margin-top: 0.25rem;
  --crm-page-top-gap: 0.25rem;
  --crm-section-gap: 1.5rem;
}

/* Sticky navbar (`sticky-top` utility class on <header> in _navbar.html) —
   give it an explicit opaque background + shadow-on-scroll so page content
   doesn't show through/behind it while scrolled, and keep it above page
   content (but native <dialog>/its backdrop still render above everything
   via the browser's top layer, regardless of z-index). */
.navbar.sticky-top {
  z-index: 1030;
  background-color: #fff;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

/* Alpine-driven navbar dropdowns (Leads, Reports submenus) — hide until
   Alpine has initialized so `x-show` doesn't flash unstyled content. */
[x-cloak] {
  display: none !important;
}

/* Tabler's `.dropdown-menu[data-bs-popper] { top:100%; left:0; margin-top:... }`
   positioning rule only applies once Bootstrap's JS adds a `data-bs-popper`
   attribute (its Popper.js integration) — which never happens here since we
   don't vendor Bootstrap's JS bundle (Alpine drives the `.show` class
   instead, see _navbar.html). Without that attribute, the plain
   `.dropdown-menu { position:absolute }` has no `top`/`left` of its own, so
   it falls back to its original in-flow position instead of dropping below
   the toggle — this is set explicitly here instead. */
.navbar-nav-crm .dropdown-menu {
  top: 100%;
  left: 0;
  margin-top: 0.125rem;
}

.navbar-brand-crm {
  font-weight: 700;
  letter-spacing: 0.01em;
  margin-right: 1.25rem;
  color: #1d3557 !important;
}

.navbar-nav-crm {
  gap: 0.25rem;
}

.navbar-nav-crm .nav-link {
  font-weight: 500;
  color: #475467;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}

.navbar-nav-crm .nav-link.active,
.navbar-nav-crm .nav-link:hover {
  color: #1d3557;
  background: #eef2ff;
}

.navbar-search-crm {
  max-width: 320px;
}

/* ---------- Consistent page-section rhythm (UX audit, FR-87) ---------- */
/* Tabler's own `.page-header` rule only sets a top margin
   (`.page-wrapper .page-header { margin: var(--tblr-page-padding-y) 0 0 }`)
   and leaves zero bottom margin, so the gap before the first card/row on a
   page ended up depending on whichever ad-hoc utility class (`mb-3`, `mb-4`,
   none at all) that page's first section happened to use — inconsistent
   from page to page. This normalizes the vertical rhythm for every page
   built from base.html's `{% block content %}` (a direct child of
   `.page-body`), so authors don't need to hand-pick a spacing utility for
   section-to-section gaps — only for spacing *within* a section (row
   gutters, card internals) does a manual utility still make sense. */
.page-body > .page-header {
  margin-top: 0;
  margin-bottom: var(--crm-section-gap);
}

.page-body > *:not(:last-child) {
  margin-bottom: var(--crm-section-gap);
}

/* ---------- Page header: title + actions side-by-side (UX audit) ---------- */
/* Tabler's `.page-header` defaults to `flex-direction: column` — correct
   for its *real* markup, where `.page-title` and `.page-actions` are meant
   to sit inside their own `.row > .col` / `.col-auto` wrapper. Every
   page-header in this app instead puts `.page-title` and `.page-actions`
   directly under `.page-header` (no row/col wrapper — see leads/list.html,
   leads/kanban.html, customers/detail.html, communications/thread.html,
   reports/dashboard.html, accounts/admin/user_list.html), so they stacked
   vertically with almost no gap on every page that has action buttons,
   while title-only pages looked fine — an inconsistency across the app
   rather than within one page. This makes that plain two-child structure
   behave like Tabler's row/col version everywhere, without having to
   hand-wrap six-plus templates individually. */
.page-header {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  row-gap: 0.75rem;
  column-gap: 1rem;
}

.page-header .page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

/* Bottom-right toast messages from Django's messages framework. */
.crm-toast-container {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  width: min(92vw, 360px);
}

.crm-toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 0.875rem;
  border-radius: 10px;
  border: 1px solid #dbe2ef;
  background: #ffffff;
  box-shadow: 0 10px 24px -14px rgba(15, 23, 42, 0.45);
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.crm-toast.is-hiding {
  opacity: 0;
  transform: translateY(8px);
}

.crm-toast-body {
  flex: 1;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: #1f2937;
}

.crm-toast .btn-close {
  opacity: 0.75;
  margin-top: 0.1rem;
}

.crm-toast .btn-close:hover {
  opacity: 1;
}

.crm-toast-success {
  border-color: color-mix(in srgb, #2fb344 35%, #ffffff);
  background: color-mix(in srgb, #2fb344 8%, #ffffff);
}

.crm-toast-warning {
  border-color: color-mix(in srgb, #f59f00 35%, #ffffff);
  background: color-mix(in srgb, #f59f00 10%, #ffffff);
}

.crm-toast-error,
.crm-toast-danger {
  border-color: color-mix(in srgb, #d63939 35%, #ffffff);
  background: color-mix(in srgb, #d63939 10%, #ffffff);
}

.crm-toast-info,
.crm-toast-debug {
  border-color: color-mix(in srgb, #066fd1 30%, #ffffff);
  background: color-mix(in srgb, #066fd1 8%, #ffffff);
}

/* Agent Skill form: keep active switch visually tied to Skill Name label. */
.agent-skill-name-header {
  display: inline-flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.35rem;
}

.agent-skill-active-toggle {
  display: inline-flex;
  align-items: center;
  padding-left: 2.25rem;
}

.agent-skill-active-toggle .form-check-input {
  margin-top: 0;
}

.agent-skill-active-toggle .form-check-label {
  font-size: 0.8125rem;
  color: #667085;
  font-weight: 500;
}

/* Unified table card: toolbar header + table + footer as one flush block. */
.datatable-card {
  overflow: hidden;
}

/* Datatable toolbar: icon-driven search + filter + sort bar above the table. */
.datatable-toolbar {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #eef0f4;
}

.datatable-toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: nowrap;
}

.datatable-search-group {
  position: relative;
  flex: 1 1 260px;
  max-width: 360px;
  display: flex;
  align-items: center;
}

.datatable-search-btn {
  position: absolute;
  left: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: #98a2b3;
  padding: 0.25rem;
  cursor: pointer;
}

.datatable-search-btn:hover { color: #467fcf; }

.datatable-search-input {
  padding-left: 2rem;
}

.datatable-toolbar-icons {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 0.5rem;
}

.datatable-filter-toggle {
  position: relative;
}

.datatable-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  background: #ffffff;
  color: #667085;
  cursor: pointer;
  list-style: none;
}

.datatable-icon-btn::-webkit-details-marker { display: none; }
.datatable-icon-btn::marker { content: ""; }

.datatable-icon-btn:hover { color: #467fcf; border-color: #bcd2f7; }

.datatable-filter-toggle[open] .datatable-icon-btn {
  color: #467fcf;
  border-color: #467fcf;
  background: #edf2ff;
}

.datatable-filter-panel {
  position: absolute;
  top: calc(100% + 0.6rem);
  right: 0;
  z-index: 30;
  width: min(44rem, calc(100vw - 4rem));
  padding: 0.75rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.65rem;
  background: #ffffff;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}

.datatable-filter-actions {
  justify-content: flex-end;
}

.form-multiselect-dropdown {
  position: relative;
}

.form-multiselect-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 2.5rem;
  cursor: pointer;
  list-style: none;
  background-image: none;
  padding-right: 2.25rem;
}

.form-multiselect-summary::-webkit-details-marker { display: none; }
.form-multiselect-summary::marker { content: ""; }

.form-multiselect-summary::after {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid #98a2b3;
  border-bottom: 2px solid #98a2b3;
  transform: rotate(45deg) translateY(-2px);
  transition: transform 0.15s ease;
}

.form-multiselect-dropdown[open] .form-multiselect-summary {
  border-color: #467fcf;
  box-shadow: 0 0 0 0.2rem rgba(70, 127, 207, 0.15);
}

.form-multiselect-dropdown[open] .form-multiselect-summary::after {
  transform: rotate(-135deg) translateY(-1px);
}

.form-multiselect-menu {
  position: absolute;
  z-index: 15;
  left: 0;
  right: 0;
  margin-top: 0.35rem;
  border: 1px solid #dfe3ea;
  border-radius: 0.5rem;
  background: #ffffff;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
  max-height: 12rem;
  overflow: auto;
  padding: 0.4rem;
}

.form-multiselect-option {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.55rem;
  padding: 0.4rem 0.45rem;
  border-radius: 0.35rem;
  cursor: pointer;
  text-align: left;
}

.form-multiselect-option:hover {
  background: #f5f8ff;
}

.form-multiselect-option input {
  margin: 0;
  width: 0.95rem;
  height: 0.95rem;
}

.form-multiselect-option span {
  flex: 1 1 auto;
  text-align: left;
}

.datatable-sort-group {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0 0.5rem;
  height: 2.25rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  color: #667085;
}

.datatable-sort-select {
  border: none;
  background: transparent;
  box-shadow: none;
  padding-left: 0.25rem;
  padding-right: 1.5rem;
  min-width: 8.5rem;
}

.datatable-sort-select:focus { box-shadow: none; }

/* Sortable column headers. */
.datatable-sort-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: inherit;
  text-decoration: none;
}

.datatable-sort-link:hover { color: #467fcf; }

.datatable-sort-icon {
  font-size: 0.65rem;
  color: #c1c9d2;
}

.datatable-sort-icon.is-active { color: #467fcf; }

.datatable-actions-col {
  width: 6.5rem;
  text-align: right;
}

/* Template Management uses text buttons (View/Edit/Submit/Enable-Disable),
   so this table needs a wider actions column to prevent wrapping. */
.template-actions-col {
  width: 15rem;
}

.datatable-row-actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
}

.datatable-row-actions form {
  display: inline-flex;
  margin: 0;
}

.datatable-row-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  flex: none;
  border-radius: 0.375rem;
  color: #98a2b3;
}

button.datatable-row-action {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.datatable-row-action:hover { color: #467fcf; background: #edf2ff; }

.datatable-row-action.is-danger:hover { color: #d63939; background: #fdeeee; }

/* Uppercase, muted table header styling to match the dashboard's data-grid look. */
table.datatable thead th {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: #98a2b3;
  background: #f8fafc;
  border-bottom: 1px solid #eef0f4;
}

@media (max-width: 767px) {
  .datatable-toolbar-row {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: wrap;
  }

  .datatable-search-group {
    max-width: none;
  }

  .datatable-toolbar-icons {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .datatable-filter-panel {
    position: static;
    width: 100%;
    margin-top: 0.5rem;
    box-shadow: none;
  }

  .datatable-filter-actions {
    justify-content: flex-start;
  }

  .form-multiselect-menu {
    position: static;
    margin-top: 0.5rem;
    box-shadow: none;
  }
}

/* Datatable footer: rows-per-page + range + pager controls. */
.datatable-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  background: #ffffff;
}

/* When nested inside a unified .datatable-card, the footer is a flush
   bottom section (divider only) rather than its own bordered card. */
.datatable-card-footer {
  margin-top: 0;
  padding: 0.75rem 1rem;
  border: none;
  border-top: 1px solid #eef0f4;
  border-radius: 0;
  background: transparent;
}

.datatable-footer-left,
.datatable-footer-right {
  min-width: 0;
}

.datatable-rows-form {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.datatable-rows-form .form-label {
  color: #667085;
  font-size: 0.875rem;
  white-space: nowrap;
}

.datatable-rows-form .form-select {
  min-width: 4.5rem;
}

/* Segmented radio "chips" (Tabler's form-selectgroup) used for the Customer
   Type choice (FR-100) on the customer create/edit forms — a clearer, more
   tappable alternative to plain radio bubbles. */
.form-selectgroup-boxes {
  width: 100%;
}

.form-selectgroup-boxes .form-selectgroup-item {
  flex: 1 1 0;
}

.form-selectgroup-boxes .form-selectgroup-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.6rem 1rem;
  text-align: center;
  font-weight: 500;
}

.datatable-footer-center {
  text-align: center;
  white-space: nowrap;
}

.datatable-footer-right {
  justify-self: end;
}

.datatable-page-indicator .page-link {
  color: #111827;
  border: none;
  background: transparent;
  pointer-events: none;
}

@media (max-width: 991px) {
  .datatable-footer {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .datatable-footer-center {
    text-align: left;
  }

  .datatable-footer-right {
    justify-self: start;
  }
}

/* ---------- Show/hide password toggle (Admin Portal reset-password, FR-94) ---------- */
.password-field-wrap { position: relative; }
.password-field-wrap input { padding-right: 2.5rem; }
.password-toggle-btn {
  position: absolute; top: 50%; right: 0.4rem; transform: translateY(-50%);
  border: none; background: transparent; cursor: pointer; font-size: 1rem;
  line-height: 1; padding: 0.25rem 0.35rem; border-radius: 4px;
}
.password-toggle-btn:hover { background: #f1f3f5; }

/* ---------- Popup form modal (Admin Portal add/edit/reset-password) ---------- */
/* Native <dialog> styled to match Tabler's .modal-content card, so the same
   .modal-header/.modal-body/.btn-close classes from tabler.min.css apply
   without needing Bootstrap's JS bundle vendored just for the modal widget.
   Note: Tabler's `.modal-body { padding: var(--tblr-modal-padding) }` only
   gets that custom property from the `.modal` class, which this <dialog>
   deliberately doesn't carry (it would also set `display:none`, fighting
   the native <dialog> open/close). So modal-body/footer spacing is set
   explicitly here instead of relying on that undefined variable. */
.app-modal {
  border: none;
  border-radius: 8px;
  padding: 0;
  width: 100%;
  max-width: 825px;
  max-height: calc(100vh - 4rem);
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.175);
}

.app-modal::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.app-modal .modal-header {
  border-bottom: 1px solid #e5e7eb;
}

.app-modal .modal-body {
  padding: 1.5rem;
  max-height: calc(100vh - 4rem - 3.5rem);
  overflow-y: auto;
}

/* ---------- Stat / widget cards (FR-80, FR-83) ---------- */
.stat-card {
  border: none;
  border-radius: 14px;
  box-shadow: 0 6px 18px -12px rgba(29, 53, 87, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px -12px rgba(29, 53, 87, 0.3); }

.stat-card .stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.stat-card .subheader { color: #98a2b3; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }

/* ---------- Entity cards: leads / customers / tasks (FR-82) ---------- */
.entity-card {
  border: 1px solid #eef0f4;
  border-radius: 12px;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  height: 100%;
}

.entity-card.entity-card-fit-content {
  height: auto;
}

.entity-card.entity-card-scroll {
  height: auto;
  max-height: 620px;
  overflow: hidden;
}

.entity-card.entity-card-scroll .card-body {
  min-height: 0;
  overflow-y: auto;
}

.customer-detail-layout .entity-card {
  height: auto;
}

.customer-profile-card .entity-meta {
  font-size: 0.95rem;
  line-height: 1.55;
}

.customer-profile-grid {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 0.45rem 1rem;
}

.customer-profile-label {
  color: #667085;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 600;
}

.customer-profile-value {
  color: #1d2939;
  font-size: 0.95rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.customer-profile-owner {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}

@media (max-width: 767.98px) {
  .customer-profile-grid {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }

  .customer-profile-label {
    margin-top: 0.5rem;
  }
}

.entity-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px -16px rgba(29, 53, 87, 0.35);
  border-color: #d6dfff;
}

.entity-card .entity-title { font-weight: 600; color: #1d2939; }
.entity-card .entity-meta { color: #667085; font-size: 0.825rem; }

.avatar-chip {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #eef2ff;
  color: #3a6ea5;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* Status/priority color coding (FR-82) */
.status-badge { font-weight: 600; }
.status-new { background: #e0f2fe; color: #075985; }
.status-contacted { background: #fef3c7; color: #92400e; }
.status-qualified { background: #ede9fe; color: #5b21b6; }
.status-proposal { background: #ffedd5; color: #9a3412; }
.status-won { background: #dcfce7; color: #166534; }
.status-lost { background: #fee2e2; color: #991b1b; }

/* ---------- Kanban board (FR-81) ---------- */
.kanban-board { display: flex; gap: 1rem; overflow-x: auto; padding-bottom: 0.5rem; }

.kanban-column {
  flex: 0 0 270px;
  background: #eef1f8;
  border-radius: 12px;
  padding: 0.65rem;
  min-height: 220px;
}

.kanban-column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0.35rem 0.6rem;
  font-weight: 600;
  color: #344054;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.kanban-card {
  background: #fff;
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  margin-bottom: 0.6rem;
  box-shadow: 0 2px 6px rgba(29, 53, 87, 0.08);
  cursor: grab;
  border: 1px solid transparent;
}

.kanban-card:active { cursor: grabbing; }
.kanban-card.sortable-ghost { opacity: 0.4; border: 1px dashed #3a6ea5; }
.kanban-card .kanban-card-title { font-weight: 600; font-size: 0.9rem; color: #1d2939; }
.kanban-card .kanban-card-meta { font-size: 0.75rem; color: #667085; }

/* ---------- Chat / communication thread (WhatsApp-Web-like palette) ---------- */
.chat-bubble {
  max-width: 65%;
  border-radius: 8px;
  padding: 0.45rem 0.6rem 0.35rem;
  margin-bottom: 0.45rem;
  font-size: 0.9rem;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  position: relative;
  word-wrap: break-word;
}

.chat-bubble-outbound { background: #d9fdd3; color: #111b21; margin-left: auto; border-top-right-radius: 2px; }
.chat-bubble-inbound { background: #ffffff; color: #111b21; margin-right: auto; border-top-left-radius: 2px; border: 1px solid #e9edef; }
.chat-bubble-meta { font-size: 0.68rem; color: #667781; margin-top: 0.2rem; text-align: right; }
.wa-ticks { color: #667781; font-size: 0.7rem; letter-spacing: -0.06em; margin-left: 0.2rem; vertical-align: baseline; }
.wa-ticks-read { color: #53bdeb; }
.wa-ticks-failed { color: #d63939; letter-spacing: 0; }

/* Inline attachment previews within a chat bubble (FR-51) */
.chat-bubble-attachment { margin-top: 0.4rem; }
.chat-bubble-attachment-image { max-width: 160px; max-height: 160px; border-radius: 8px; display: block; object-fit: cover; cursor: zoom-in; }
.chat-bubble-attachment-audio { max-width: 100%; }
.chat-bubble-attachment-file { display: inline-flex; align-items: center; gap: 0.3rem; text-decoration: underline; }

/* Full-size click-to-preview overlay for chat attachment thumbnails (FR-51) */
.attachment-lightbox {
  border: none;
  border-radius: 8px;
  padding: 0;
  background: transparent;
  max-width: 90vw;
  max-height: 90vh;
}
.attachment-lightbox::backdrop { background: rgba(0, 0, 0, 0.8); }
.attachment-lightbox img { display: block; max-width: 90vw; max-height: 90vh; border-radius: 4px; }
.attachment-lightbox-close {
  position: absolute;
  top: -0.75rem;
  right: -0.75rem;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: #1d2939;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* ---------- Messaging Workspace (FR-52A..F) ---------- */
/* WhatsApp-Web-style layout: a fixed-width contacts sidebar plus a thread
   panel that fills the remaining width (FR-52B). The former always-visible
   3rd column (Templates/Products/Standard Attachments) is now an on-demand
   slide-in drawer (`.ws-drawer`) toggled from the thread header instead of
   permanently occupying 40% of the row, so the 2 primary panels get the
   WhatsApp-Web-like full-width chat experience by default. */
.ws-page { margin-top: 0; margin-bottom: 0; }
.ws-row {
  display: flex;
  align-items: stretch;
  height: calc(100dvh - 4.25rem);
  max-height: calc(100dvh - 4.25rem);
  min-height: 55vh;
  border: 1px solid #e9edef;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 1px 3px rgba(11, 20, 26, 0.08);
}
.ws-col-contacts { flex: 0 0 30%; max-width: 380px; min-width: 260px; border-right: 1px solid #e9edef; display: flex; flex-direction: column; background: #fff; }
#workspace-main { flex: 1 1 auto; min-width: 0; display: flex; }
.ws-main-wrapper { display: flex; flex: 1 1 auto; min-width: 0; position: relative; }
.ws-col-thread { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; background: #f0f2f5; }
.ws-col-contacts .card, .ws-col-thread .card { height: 100%; border: none; border-radius: 0; display: flex; flex-direction: column; }
.ws-col-contacts .card-header {
  height: 3rem;
  min-height: 3rem;
  padding: 0 0.875rem;
  flex-wrap: nowrap !important;
}
.ws-col-contacts .card-header strong {
  line-height: 1.2;
}
.ws-col-contacts .ws-tabs {
  margin-bottom: 0;
  border-bottom: none;
  flex: 0 0 auto;
}
.ws-col-contacts .ws-tabs .btn {
  min-height: 2rem;
}
/* The HTMX swap target that wraps messages+composer must itself grow to
   fill the remaining card height (flex item -> flex container) so the
   inner .ws-messages can size/scroll correctly instead of growing
   unbounded (a common flex `min-height: auto` gotcha). */
#workspace-thread-panel { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }

/* Contacts sidebar (Panel 1) */
.ws-contact-search { padding: 0.5rem 0.75rem; border-bottom: 1px solid #e9edef; display: flex; align-items: center; gap: 0.5rem; }
.ws-contact-search input { border-radius: 20px; background: #f0f2f5; border: none; flex: 1 1 auto; min-width: 0; }
.ws-filter-toggle { position: relative; flex: 0 0 auto; }
.ws-filter-toggle .datatable-icon-btn { width: auto; height: auto; padding: 0.3rem 0.6rem; white-space: nowrap; }
.ws-bulk-trigger { border-radius: 999px; white-space: nowrap; }
.ws-filter-panel {
  position: absolute; top: calc(100% + 0.4rem); right: 0; z-index: 30; width: 260px;
  background: #fff; border: 1px solid #e5e7eb; border-radius: 0.5rem;
  box-shadow: 0 4px 16px rgba(11, 20, 26, 0.18); padding: 0.75rem; margin-top: 0;
}
.ws-col-contacts .card > #ws-contact-lists {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}
.ws-contact-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: scroll;
  scrollbar-gutter: stable;
}
.ws-contact-item { display: flex; align-items: center; gap: 0.75rem; padding: 0.65rem 0.9rem; border-bottom: 1px solid #f4f6fb; text-decoration: none; color: inherit; }
.ws-contact-item:hover { background: #f5f6f6; }
.ws-contact-item.active { background: #f0f2f5; }
.ws-contact-avatar { flex: 0 0 auto; width: 2.75rem; height: 2.75rem; border-radius: 50%; background: #3a6ea5; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 1rem; text-transform: uppercase; }
.ws-contact-info { min-width: 0; flex: 1 1 auto; display: flex; flex-direction: column; gap: 0.05rem; }
.ws-contact-info-top { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; }
.ws-contact-info .fw-bold { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-contact-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.8rem; color: #667781; }
.ws-contact-time { font-size: 0.7rem; color: #667781; flex: 0 0 auto; }
/* WhatsApp-style unread badge (Panel 1 contact/lead rows) */
.ws-contact-info-bottom { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.ws-contact-info-bottom .ws-contact-preview { flex: 1 1 auto; min-width: 0; }
.ws-unread-name, .ws-unread-time { color: #111b21; font-weight: 700; }
.ws-unread-preview { color: #111b21; font-weight: 600; }
.ws-unread-badge {
  flex: 0 0 auto; min-width: 1.15rem; height: 1.15rem; padding: 0 0.3rem; border-radius: 999px;
  background: #25d366; color: #fff; font-size: 0.68rem; font-weight: 700; line-height: 1.15rem;
  text-align: center;
}

/* Thread header (Panel 2) */
.ws-thread-header { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.6rem 1rem; background: #f0f2f5; border-bottom: 1px solid #e9edef; }
.ws-thread-header-identity { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.ws-thread-header-text { min-width: 0; }
.ws-thread-header-text .fw-bold { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-thread-title-link { color: inherit; text-decoration: none; }
.ws-thread-title-link:hover { text-decoration: underline; }
.ws-messages { max-height: 60vh; overflow-y: auto; padding: 1rem; }
.ws-col-thread .ws-messages { max-height: none; min-height: 0; flex: 1 1 auto; background: #efeae2; }

/* Drawer toggle + composer */
.ws-drawer-toggle { flex: 0 0 auto; }
.ws-composer-bar { background: #f0f2f5; border-top: 1px solid #e9edef; padding: 0.6rem 1rem; }

/* Composer bar restyled as a single WhatsApp-Web-style pill row: a "+"
   icon opens a small popover menu to switch to Template/Attachment mode
   (their fields expand in a card above the row), an emoji icon is a
   decorative placeholder, and a circular green button submits the form. */
.ws-composer-row { display: flex; align-items: flex-end; gap: 0.4rem; }
.ws-composer-plus-wrap { position: relative; flex: 0 0 auto; }
.ws-composer-icon-btn {
  width: 2.25rem; height: 2.25rem; border-radius: 50%; border: none; background: transparent;
  color: #54656f; font-size: 1.15rem; display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex: 0 0 auto;
}
.ws-composer-icon-btn:hover { background: #e9edef; }
.ws-composer-icon-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.ws-composer-menu {
  position: absolute; bottom: 2.75rem; left: 0; background: #fff; border-radius: 8px;
  box-shadow: 0 2px 12px rgba(11, 20, 26, 0.25); padding: 0.35rem; display: flex;
  flex-direction: column; min-width: 175px; z-index: 20;
}
.ws-composer-menu-item { background: none; border: none; text-align: left; padding: 0.5rem 0.65rem; border-radius: 6px; font-size: 0.85rem; }
.ws-composer-menu-item:hover { background: #f0f2f5; }
.ws-composer-menu-item:disabled { opacity: 0.45; cursor: not-allowed; }
.ws-composer-emoji-wrap { position: relative; flex: 0 0 auto; }
.ws-emoji-picker {
  position: absolute; bottom: 2.75rem; left: 0; background: #fff; border-radius: 8px;
  box-shadow: 0 2px 12px rgba(11, 20, 26, 0.25); padding: 0.5rem; display: grid;
  grid-template-columns: repeat(6, 1fr); gap: 0.15rem; width: 15rem; max-height: 12rem;
  overflow-y: auto; z-index: 20;
}
.ws-emoji-item { background: none; border: none; font-size: 1.25rem; padding: 0.25rem; border-radius: 6px; line-height: 1; cursor: pointer; }
.ws-emoji-item:hover { background: #f0f2f5; }
.ws-composer-input {
  flex: 1 1 auto; border-radius: 20px; border: 1px solid #d7dbdd; background: #fff;
  padding: 0.5rem 1rem; resize: none; max-height: calc(1.4285714286em * 5 + 1rem); overflow-y: auto; font-size: 0.9rem;
}
.ws-composer-input:focus { outline: none; border-color: #8696a0; box-shadow: none; }
.ws-composer-input-hint { display: flex; align-items: center; color: #667781; font-style: italic; font-size: 0.85rem; }
.ws-composer-language {
  flex: 0 0 auto;
  width: 7.6rem;
  border-radius: 18px;
  border: 1px solid #d7dbdd;
  background: #fff;
  color: #223046;
  font-size: 0.82rem;
  padding: 0.42rem 0.6rem;
}
.ws-composer-language:focus { outline: none; border-color: #8696a0; box-shadow: none; }
.ws-composer-ai {
  flex: 0 0 auto;
  height: 2.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border-radius: 18px;
  border: 1px solid #b9d4ff;
  background: #edf4ff;
  color: #2457a6;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0 0.75rem;
  cursor: pointer;
}
.ws-composer-ai:hover { background: #ddeaff; }
.ws-composer-ai:disabled { opacity: 0.45; cursor: not-allowed; }
.ws-composer-ai-icon {
  font-size: 0.9rem;
  line-height: 1;
}
.ws-composer-ai-label {
  line-height: 1;
}
.ws-composer-ai-spinner {
  width: 0.8rem;
  height: 0.8rem;
  border: 2px solid rgba(36, 87, 166, 0.25);
  border-top-color: #2457a6;
  border-radius: 50%;
  animation: ws-composer-ai-spin 0.7s linear infinite;
}
.ws-composer-ai-label-loading,
.ws-composer-ai-spinner {
  display: none;
}
.ws-composer-ai.htmx-request {
  pointer-events: none;
  opacity: 0.92;
}
.ws-composer-ai.htmx-request .ws-composer-ai-icon-default,
.ws-composer-ai.htmx-request .ws-composer-ai-label-default {
  display: none;
}
.ws-composer-ai.htmx-request .ws-composer-ai-spinner,
.ws-composer-ai.htmx-request .ws-composer-ai-label-loading {
  display: inline-flex;
}
@keyframes ws-composer-ai-spin {
  to {
    transform: rotate(360deg);
  }
}
.ws-composer-send {
  flex: 0 0 auto; width: 2.5rem; height: 2.5rem; border-radius: 50%; border: none;
  background: #00a884; color: #fff; font-size: 1.05rem; display: flex; align-items: center;
  justify-content: center; cursor: pointer;
}
.ws-composer-send:hover { background: #029677; }
.ws-composer-panel { background: #fff; border-radius: 10px; padding: 0.75rem; margin-bottom: 0.5rem; box-shadow: 0 1px 4px rgba(11, 20, 26, 0.15); }
.ws-composer-panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.5rem; }
.ws-composer-template-tabs { display: inline-flex; gap: 0.3rem; margin-bottom: 0.6rem; }
.ws-composer-template-tabs .btn { border-radius: 999px; }
.ws-template-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(5.8rem, auto);
  gap: 0.5rem;
  max-height: 12.25rem;
  overflow-y: auto;
  padding-right: 0.1rem;
}
.ws-template-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid #e5e7eb;
  border-radius: 0.6rem;
  background: #ffffff;
  cursor: pointer;
}
.ws-template-card:hover {
  border-color: #bcd2f7;
  background: #f8fbff;
}
.ws-template-card.is-selected {
  border-color: #467fcf;
  background: #edf2ff;
  box-shadow: 0 0 0 0.15rem rgba(70, 127, 207, 0.12);
}
.ws-template-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.ws-template-card-name {
  font-weight: 600;
  color: #223046;
  font-size: 0.95rem;
  line-height: 1.2;
}
.ws-template-card-badges {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.ws-template-card-body {
  color: #5f6b7a;
  font-size: 0.76rem;
  line-height: 1.25;
  flex: 1 1 auto;
}
.ws-template-card-content {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
}
.ws-template-card-thumb {
  width: 4rem;
  height: 4rem;
  flex: 0 0 4rem;
  object-fit: cover;
  border-radius: 0.45rem;
  border: 1px solid #e5e7eb;
}
.ws-template-card .badge {
  font-size: 0.68rem;
  line-height: 1.1;
}
.ws-bulk-template-picker {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  max-height: 14rem;
}

@media (max-width: 1200px) {
  .ws-template-picker {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: 18rem;
  }
}

@media (max-width: 767px) {
  .ws-template-picker {
    grid-template-columns: 1fr;
    max-height: 16rem;
  }
}

/* Panel 3 content is reused inside the drawer (FR-52E, FR-52F) */
.ws-drawer-body .ws-tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid #eef1f8; margin-bottom: 0.75rem; }
.ws-tab-item { max-height: calc(100% - 3rem); overflow-y: auto; }
.ws-standard-attachment-row, .ws-template-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.5rem 0; border-bottom: 1px solid #f4f6fb; }

/* Slide-in drawer for Templates / Products / Standard Attachments (FR-52E,
   FR-52F): fixed to the viewport's right edge, overlaying the thread panel,
   opened on demand via the header button instead of a permanent column. */
.ws-drawer-backdrop { position: fixed; inset: 0; background: rgba(11, 20, 26, 0.35); z-index: 1040; }
.ws-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100vw);
  background: #fff;
  z-index: 1041;
  box-shadow: -2px 0 12px rgba(11, 20, 26, 0.2);
  transform: translateX(100%);
  transition: transform 0.22s ease-out;
  display: flex;
  flex-direction: column;
}
.ws-drawer.ws-drawer-open { transform: translateX(0); }
.ws-drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 0.85rem 1rem; border-bottom: 1px solid #e9edef; background: #f0f2f5; }
.ws-drawer-body { flex: 1 1 auto; overflow-y: auto; padding: 1rem; }

/* Responsive: tablet/desktop (FR-87) — stack panels on narrower screens */
@media (max-width: 991px) {
  .ws-row { flex-direction: column; height: auto; }
  .ws-col-contacts { max-width: 100%; flex: 1 1 auto; border-right: none; border-bottom: 1px solid #e9edef; }
  .ws-drawer { width: 100vw; }
}

/* Responsive: tablet/desktop (FR-87) */
@media (max-width: 767px) {
  .kanban-column { flex: 0 0 82vw; }
}
