/* crm.css — shell styles for the CRM view (Wave C integration · UX-03 redesign).
 * Prefixed crm- throughout. All colors/spacing via styles.css tokens (UX-01).
 * The entity-list / entity-form / entity-kanban / company360 module visuals
 * ship in their own CSS files; this file owns the CRM view chrome (tabs,
 * toolbar, mount) and the detail/edit SLIDE-OVER PANEL that replaced the old
 * centered modal.
 */

/* ─── CRM view container ──────────────────────────────────────────────────── */
.crm-view {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height) - 4px);
  overflow: hidden;
}

/* ─── Type tab bar ────────────────────────────────────────────────────────── */
.crm-tabs {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-3) 0;
  border-bottom: 2px solid var(--border-color);
  background: var(--bg-card);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.crm-tabs::-webkit-scrollbar { display: none; }

.crm-tab {
  padding: var(--space-2) var(--space-4);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--text-sm);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.crm-tab:hover {
  color: var(--text-primary);
  background: var(--bg-light);
}
.crm-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.crm-tab i {
  margin-right: var(--space-1);
  font-size: 0.8em;
}

/* ─── Toolbar row ─────────────────────────────────────────────────────────── */
.crm-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  flex-wrap: wrap;
}
.crm-toolbar.hidden { display: none; }

/* View-mode toggle: List | Kanban */
.crm-mode-toggle {
  display: flex;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.crm-mode-btn {
  padding: var(--space-1) var(--space-4);
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--text-sm);
  transition: background 0.18s ease, color 0.18s ease;
}
.crm-mode-btn:hover {
  background: var(--bg-light);
  color: var(--text-primary);
}
.crm-mode-btn.active {
  background: var(--accent);
  color: var(--bg-dark);
  font-weight: 600;
}

/* Spacer pushes Fields button to the right */
.crm-toolbar-spacer {
  flex: 1;
}

/* ─── Content mount area ──────────────────────────────────────────────────── */
.crm-mount {
  flex: 1;
  overflow: auto;
  padding: var(--space-3);
  background: var(--bg-dark);
  min-height: 0;
}

/* Board parity (UX-w7): when the mount hosts the entity KANBAN, drop the solid
 * --bg-dark fill so the #app HugoAI backdrop shows through the board's gaps —
 * exactly like the main KanMail board, whose columns are transparent over the
 * same #app backdrop. List mode keeps the solid --bg-dark (tables need it).
 * Scoped via :has() so only the kanban board triggers the transparency. */
.crm-mount:has(.ek-board) {
  background: transparent;
}

/* ─────────────────────────────────────────────────────────────────────────
 * Detail / edit CENTERED MODAL (CRM redesign W2)
 * The shell users already know from the mail-card editor: centered, wide
 * (880px) so line-item tables get a real table — not a squeezed side panel —
 * capped to the viewport with the form scrolling internally between a sticky
 * header and footer. Scrim-click / Esc / × close (wired in app.js, unchanged).
 * Below 768px it becomes a full-screen sheet (see the phone block below).
 * ─────────────────────────────────────────────────────────────────────── */
.crm-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.66);
  z-index: var(--z-modal);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--space-5);
  animation: crm-overlay-fade 0.16s ease;
}
.crm-modal-overlay.hidden {
  display: none;
}

/* Centered shell — flex column, header/footer fixed, body scrolls. The entry
 * animation plays whenever the overlay is shown (it only exists DOM-visible
 * when not .hidden), so no JS state change is needed — keeps the app.js wiring
 * contract unchanged. */
.crm-modal-shell {
  background: var(--bg-dark);
  border: 1px solid var(--border-soft);
  box-shadow: 0 30px 80px rgba(2, 6, 23, 0.7);
  border-radius: 16px;
  width: min(880px, 100%);
  max-height: min(90vh, 900px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: crm-modal-in 0.16s ease;
}

@keyframes crm-overlay-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes crm-modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .crm-modal-overlay,
  .crm-modal-shell { animation: none; }
}

/* Sticky header — deep chrome bar */
.crm-modal-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-deep);
  flex-shrink: 0;
}
.crm-modal-title {
  flex: 1;
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  line-height: var(--leading-tight);
}
.crm-modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: var(--text-xl);
  line-height: 1;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  transition: color 0.18s ease, background 0.18s ease;
  min-width: 44px;
  min-height: 44px;
}
.crm-modal-close:hover {
  color: var(--text-primary);
  background: var(--bg-light);
}

/* Modal body — owns NO scroll; the mounted form/admin scrolls internally.
 * For admin/send-policy (which don't manage their own scroll) we allow it. */
.crm-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Admin / send-policy studio: same centered shell, scrollable padded body
 * (these modules don't provide an internal scroll area like the entity form). */
.crm-modal-shell.crm-modal-admin {
  width: min(820px, 100%);
}
.crm-modal-shell.crm-modal-admin .crm-modal-body {
  overflow-y: auto;
  padding: var(--space-5);
  display: block;
}

/* Compose panel mounts bare in the centered body (no admin override) and has
   no internal scroll of its own — let it fill the capped body and scroll, so a
   tall draft never pushes Send/Cancel out of reach on a short viewport. */
.crm-modal-body > .ec-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

/* Phone (≤768): the modal becomes a full-screen sheet — no scrim gutter, no
 * radius, edge-to-edge. The form's sticky footer becomes the bottom action bar
 * and the line table re-stacks (entity-form.css). */
@media (max-width: 768px) {
  .crm-modal-overlay {
    padding: 0;
  }
  .crm-modal-shell,
  .crm-modal-shell.crm-modal-admin {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border: none;
    border-radius: 0;
  }
}

/* ─────────────────────────────────────────────────────────────────────────
 * Tabbed editor (UX-w7 · Finding 2) — entityFormTabs.js enhancer.
 * The enhancer reuses the card modal's .card-modal-tabs / .card-modal-tab
 * classes (defined in card-modal.css) for exact visual parity, and wraps each
 * .ef-section in an .eft-pane that this file shows/hides. Scoped to the CRM
 * slide-over so it never affects the card modal itself.
 * ─────────────────────────────────────────────────────────────────────── */

/* Tab bar sits flush at the top of the scrollable form body; it scrolls WITH
 * the body (the form owns the scroll), so it gets a sticky top to stay put. */
.ef-form-body .eft-tabs {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: calc(var(--space-5) * -1) calc(var(--space-5) * -1) var(--space-4);
  /* solid so form content doesn't show through while scrolling under it */
  background: var(--bg-dark);
}

/* Panes — only the active one is shown (mirrors .card-tab-pane). A pane may
   hold several folded sections (e.g. Overview = status + core), so the active
   pane is a column with section spacing. */
.eft-pane {
  display: none;
}
.eft-pane.active {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

/* The section's own heading is redundant once it's a tab — hide it. */
.eft-hidden-title {
  display: none;
}

/* ─── Company 360 back bar ────────────────────────────────────────────────── */
.c360-back-bar {
  display: flex;
  align-items: center;
  padding: var(--space-2) var(--space-4);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.c360-back-btn {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
