/* ============================================================
   Fundrm CRM — Shared Styles
   Replicates the Dynamics-style CRM layout from screenshots.
   ============================================================ */

:root {
  /* Colour palette — derived from Fundrm screenshots */
  --fm-sidebar-bg:       #f1f4f8;  /* neutral blue-grey - de-VO restyle 2026-06 (was pink #fbe9ec) */
  --fm-sidebar-active:   #d0dcea;
  --fm-sidebar-text:     #333;
  --fm-sidebar-heading:  #1a1a1a;
  --fm-header-bg:        #fff;
  --fm-header-border:    #d8dce0;
  --fm-body-bg:          #fff;
  --fm-border:           #dfe2e6;
  --fm-border-light:     #eaecef;
  --fm-text:             #222;
  --fm-text-muted:       #666;
  --fm-label:            #444;
  --fm-link:             #1160a8;
  --fm-link-hover:       #0d4a85;
  --fm-accent:           #2e78c7;
  --fm-brand:            #1b3f66;  /* deep navy — FundRM wordmark + brand chrome */
  --fm-brand-accent:     #2f6fb0;  /* mid blue — wordmark "RM", logo gradient top */
  --fm-row-hover:        #f0f4fa;
  --fm-row-selected:     #cfe0f5;
  --fm-section-bg:       #fafbfc;
  --fm-section-border:   #e0e3e7;
  --fm-red:              #c42b1c;
  --fm-green:            #107c10;
  --fm-timeline-bg:      #f9fafb;
  --fm-toolbar-icon:     #555;
  --fm-input-border:     #b3b8bd;
  --fm-input-bg:         #fff;

  /* Typography */
  --fm-font:             'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  --fm-font-mono:        'Cascadia Code', 'Consolas', monospace;

  /* Layout */
  --fm-sidebar-width:    180px;
  --fm-toolbar-height:   42px;
  --fm-timeline-width:   380px;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 13px; }
body {
  font-family: var(--fm-font);
  color: var(--fm-text);
  background: var(--fm-body-bg);
  line-height: 1.45;
  overflow: hidden;          /* page-level scroll handled by panels */
  height: 100vh;
}
a { color: var(--fm-link); text-decoration: none; }
a:hover { color: var(--fm-link-hover); text-decoration: underline; }
table { border-collapse: collapse; width: 100%; }
input, select, textarea {
  font-family: var(--fm-font);
  font-size: 13px;
  color: var(--fm-text);
}

/* ================================================================
   LAYOUT SHELL
   .fm-app
     .fm-sidebar
     .fm-main
       .fm-toolbar          (top bar, optional)
       .fm-content-wrapper  (scrollable)
         .fm-content
       .fm-timeline         (right panel, optional)
   ================================================================ */

.fm-app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ---- Sidebar ---- */
.fm-sidebar {
  width: var(--fm-sidebar-width);
  min-width: var(--fm-sidebar-width);
  background: var(--fm-sidebar-bg);
  border-right: 1px solid var(--fm-border);
  overflow-y: auto;
  padding: 8px 0;
  flex-shrink: 0;
}
/* ---- Sidebar brand header (logo mark + FundRM wordmark) ---- */
.fm-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--fm-border);
  text-decoration: none;
  color: var(--fm-brand);
}
.fm-sidebar-brand:hover { text-decoration: none; }
.fm-sidebar-brand .fm-logo-mark { flex-shrink: 0; display: block; }

/* ---- Wordmark (shared: sidebar + login + passkey pages) ---- */
.fm-wordmark {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--fm-brand);
  line-height: 1;
  white-space: nowrap;
}
.fm-wordmark-accent { color: var(--fm-brand-accent); }

.fm-sidebar-group { margin-bottom: 6px; }
.fm-sidebar-group-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--fm-text-muted);
  padding: 14px 14px 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.fm-sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 14px 5px 18px;
  font-size: 13px;
  color: var(--fm-sidebar-text);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s;
}
.fm-sidebar-item:hover {
  background: rgba(0,0,0,0.04);
}
.fm-sidebar-item.active {
  background: var(--fm-sidebar-active);
  border-left-color: var(--fm-accent);
  font-weight: 600;
}
.fm-sidebar-item .icon {
  width: 18px;
  text-align: center;
  color: var(--fm-toolbar-icon);
  font-size: 14px;
  flex-shrink: 0;
}

/* ---- Main area ---- */
.fm-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ---- Toolbar ---- */
.fm-toolbar {
  /* min-height (not fixed height) + wrap: a crowded toolbar (e.g. Companies
     with the country/type/status/sort/FBG filters) drops to a second line
     instead of forcing a whole-page horizontal scrollbar. Stays single-line
     at normal widths. */
  min-height: var(--fm-toolbar-height);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 12px;
  background: var(--fm-header-bg);
  border-bottom: 1px solid var(--fm-header-border);
  font-size: 13px;
  flex-shrink: 0;
}
.fm-toolbar .entity-selector {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
}
.fm-toolbar .entity-selector select,
.fm-toolbar select {
  padding: 3px 6px;
  border: 1px solid var(--fm-input-border);
  border-radius: 2px;
  background: #fff;
  font-size: 13px;
}
.fm-toolbar .divider {
  width: 1px;
  height: 22px;
  background: var(--fm-border);
  margin: 0 4px;
}
.fm-toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: none;
  background: transparent;
  font-size: 13px;
  color: var(--fm-text);
  cursor: pointer;
  border-radius: 2px;
}
.fm-toolbar-btn:hover { background: rgba(0,0,0,0.06); }
.fm-toolbar-btn .icon { font-size: 14px; color: var(--fm-toolbar-icon); }
.fm-toolbar .search-box {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}
.fm-toolbar .search-box input {
  padding: 4px 8px;
  border: 1px solid var(--fm-input-border);
  border-radius: 2px;
  width: 160px;
}

/* ---- Content wrapper (scrollable area below toolbar) ---- */
.fm-content-wrapper {
  flex: 1;
  display: flex;
  overflow: hidden;
}
.fm-content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  min-width: 0;
}

/* ================================================================
   DATA GRID (list views)
   ================================================================ */
.fm-grid {
  width: 100%;
  font-size: 13px;
}
.fm-grid thead {
  position: sticky;
  top: 0;
  z-index: 2;
}
.fm-grid th {
  background: var(--fm-section-bg);
  border-bottom: 1px solid var(--fm-border);
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  color: var(--fm-label);
  user-select: none;
}
.fm-grid th .sort-icon { font-size: 10px; margin-left: 2px; color: #999; }
.fm-grid th .filter-icon { font-size: 11px; margin-left: 4px; color: #bbb; cursor: pointer; }
.fm-grid td {
  padding: 5px 10px;
  border-bottom: 1px solid var(--fm-border-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}
.fm-grid tr:hover td { background: var(--fm-row-hover); }
.fm-grid tr.selected td { background: var(--fm-row-selected); }
.fm-grid td a { color: var(--fm-link); }
.fm-grid td .row-icon {
  display: inline-block;
  width: 18px;
  text-align: center;
  margin-right: 4px;
  color: var(--fm-accent);
  font-size: 14px;
}
.fm-grid td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.fm-grid .checkbox-col { width: 32px; text-align: center; }

/* ================================================================
   DETAIL FORM (record views)
   ================================================================ */

/* Record header (icon + type label + name) */
.fm-record-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--fm-border);
}
.fm-record-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--fm-section-bg);
  border: 1px solid var(--fm-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--fm-accent);
  flex-shrink: 0;
}
.fm-record-header .type-label {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--fm-text-muted);
  letter-spacing: 0.3px;
}
.fm-record-header .record-name {
  font-size: 20px;
  font-weight: 600;
  color: var(--fm-text);
}

/* Collapsible sections */
.fm-section {
  margin: 0 0 0 0;
  border-bottom: 1px solid var(--fm-border-light);
}
.fm-section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.fm-section-title .chevron {
  font-size: 11px;
  transition: transform 0.2s;
}

/* Form grid */
.fm-form {
  padding: 8px 20px 16px;
}
.fm-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 40px;
}
.fm-form-field {
  /* Labels stack above inputs so each input gets the full column width.
     Switched from inline labels (130-150px label + flex input) on
     2026-05-26 because narrow column layouts (e.g. the 3-way grid on
     company-detail) squished inputs to ~50px. Stacking is one row taller
     per field but gives ~4x the input width on narrow columns. */
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 4px 0;
  min-height: 32px;
}
.fm-form-field label {
  font-size: 11px;
  color: var(--fm-label);
  font-weight: 500;
}
.fm-form-field label .required { color: var(--fm-red); }
.fm-form-field .field-value {
  flex: 1;
  min-width: 0;
}
.fm-form-field input[type="text"],
.fm-form-field input[type="date"],
.fm-form-field input[type="number"],
.fm-form-field select,
.fm-form-field textarea {
  width: 100%;
  /* Cap field width so 2-column form rows don't stretch inputs across the
     whole box — Riya wanted tighter CO1 fields. Wide boxes still get two
     fields per row, but each field stops growing past 240px. */
  max-width: 240px;
  padding: 4px 6px;
  border: 1px solid var(--fm-input-border);
  border-radius: 2px;
  background: var(--fm-input-bg);
}
/* Readonly inputs should read as plain text, not pretend-editable fields.
   Strips border/background so e.g. Created date and Company ID in CO1 look
   like the static values they are. */
.fm-form-field input[readonly] {
  border: 1px solid transparent;
  background: transparent;
  padding-left: 0;
  padding-right: 0;
  cursor: default;
}
.fm-form-field input[readonly]:focus { outline: none; }
.fm-form-field textarea { min-height: 60px; resize: vertical; }
.fm-form-field .lookup {
  display: flex;
  align-items: center;
  gap: 4px;
}
.fm-form-field .lookup input { flex: 1; }
.fm-form-field .lookup-btn {
  padding: 4px 6px;
  border: 1px solid var(--fm-input-border);
  background: #fff;
  cursor: pointer;
  border-radius: 2px;
  font-size: 13px;
}

/* Sub-grid inside a detail page */
.fm-subgrid {
  margin: 12px 20px 20px;
}
.fm-subgrid-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
}
.fm-subgrid-actions {
  display: flex;
  gap: 6px;
  font-size: 13px;
  font-weight: 400;
  align-items: center;
}
.fm-subgrid-actions .action {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--fm-text);
  cursor: pointer;
}
.fm-subgrid-actions .action:hover { text-decoration: underline; }

/* Inline "+ New" toggle forms - hidden by default, revealed by :target.
   Used on contacts.php, companies.php, and company-detail.php box headers. */
.fm-new-form {
  display: none;
  margin: 8px 0;
  padding: 12px;
  border: 1px solid var(--fm-border);
  background: #f7f9fc;
  border-radius: 3px;
}
.fm-new-form:target { display: block; }
.fm-new-form .row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.fm-new-form .field {
  display: flex;
  flex-direction: column;
}
.fm-new-form .field label {
  font-size: 11px;
  color: var(--fm-label);
}

/* ================================================================
   TIMELINE PANEL (right side)
   ================================================================ */
.fm-timeline {
  width: var(--fm-timeline-width);
  min-width: var(--fm-timeline-width);
  border-left: 1px solid var(--fm-border);
  background: var(--fm-timeline-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.fm-timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--fm-border);
  font-size: 15px;
  font-weight: 600;
}
.fm-timeline-header .actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.fm-timeline-header input {
  padding: 3px 6px;
  border: 1px solid var(--fm-input-border);
  border-radius: 2px;
  font-size: 12px;
  width: 120px;
}
.fm-timeline-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}
.fm-timeline-item {
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--fm-border-light);
}
.fm-timeline-item:hover { background: rgba(0,0,0,0.02); }
.fm-timeline-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--fm-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 15px;
  color: var(--fm-accent);
  background: #fff;
}
.fm-timeline-item .tl-subject {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 1px;
}
.fm-timeline-item .tl-meta {
  font-size: 11px;
  color: var(--fm-text-muted);
  margin-bottom: 4px;
}
.fm-timeline-item .tl-meta .tag {
  display: inline-block;
  background: var(--fm-section-bg);
  border: 1px solid var(--fm-border);
  border-radius: 2px;
  padding: 0 5px;
  font-size: 10px;
  margin-left: 4px;
}
.fm-timeline-item .tl-body {
  font-size: 12px;
  color: var(--fm-text-muted);
  line-height: 1.4;
}

/* ================================================================
   DASHBOARD WIDGETS
   ================================================================ */
.fm-dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0;
  height: 100%;
}
.fm-widget {
  border: 1px solid var(--fm-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.fm-widget-title {
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  border-bottom: 1px solid var(--fm-border);
  background: var(--fm-section-bg);
  flex-shrink: 0;
}
.fm-widget-body {
  flex: 1;
  overflow-y: auto;
}
.fm-widget .fm-grid th { font-size: 12px; padding: 4px 8px; }
.fm-widget .fm-grid td { font-size: 12px; padding: 3px 8px; }
.fm-widget .paging {
  padding: 4px 8px;
  font-size: 11px;
  color: var(--fm-text-muted);
  border-top: 1px solid var(--fm-border-light);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

/* ================================================================
   TABS (Activity page)
   ================================================================ */
.fm-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--fm-border);
  padding: 0 10px;
  background: var(--fm-section-bg);
}
.fm-tab {
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: var(--fm-text-muted);
}
.fm-tab:hover { color: var(--fm-text); }
.fm-tab.active {
  color: var(--fm-accent);
  border-bottom-color: var(--fm-accent);
  font-weight: 600;
}

/* ================================================================
   EMAIL TEMPLATE EDITOR
   ================================================================ */
.fm-editor-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 12px;
  background: var(--fm-section-bg);
  border-bottom: 1px solid var(--fm-border);
}
.fm-editor-toolbar button {
  background: transparent;
  border: none;
  padding: 4px 6px;
  font-size: 14px;
  cursor: pointer;
  border-radius: 2px;
  color: var(--fm-text);
}
.fm-editor-toolbar button:hover { background: rgba(0,0,0,0.06); }
.fm-editor-toolbar select {
  padding: 3px 6px;
  border: 1px solid var(--fm-input-border);
  border-radius: 2px;
  font-size: 12px;
}
.fm-editor-body {
  padding: 20px 24px;
  min-height: 400px;
  line-height: 1.6;
  overflow-y: auto;
  flex: 1;
}
.fm-editor-body table {
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 12px;
}
.fm-editor-body table th,
.fm-editor-body table td {
  border: 1px solid #999;
  padding: 4px 10px;
  text-align: center;
}
.fm-editor-body table th {
  background: #e8edf2;
  font-weight: 700;
}

/* ================================================================
   CHART (used in Investor Summary)
   ================================================================ */
.fm-chart-area {
  padding: 12px 20px;
}
.fm-chart-area h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
}
.fm-chart-placeholder {
  width: 100%;
  height: 200px;
  background: var(--fm-section-bg);
  border: 1px solid var(--fm-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fm-text-muted);
  font-size: 13px;
  border-radius: 2px;
}

/* ================================================================
   RIBBON BAR (template editor top icons)
   ================================================================ */
.fm-ribbon {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  padding: 8px 16px 10px;
  background: var(--fm-section-bg);
  border-bottom: 1px solid var(--fm-border);
}
.fm-ribbon-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  color: var(--fm-text);
  cursor: pointer;
  border: none;
  background: transparent;
  padding: 4px 8px;
}
.fm-ribbon-btn:hover { background: rgba(0,0,0,0.06); border-radius: 3px; }
.fm-ribbon-btn .ribbon-icon { font-size: 22px; color: var(--fm-accent); }
.fm-ribbon-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
}
.fm-ribbon-group a { display: flex; align-items: center; gap: 4px; cursor: pointer; }

/* ================================================================
   UTILITY CLASSES
   ================================================================ */
.text-right { text-align: right; }
.text-muted { color: var(--fm-text-muted); }
.text-red { color: var(--fm-red); }
.text-green { color: var(--fm-green); }
.font-bold { font-weight: 600; }
.nowrap { white-space: nowrap; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-4 { gap: 4px; }
.items-center { align-items: center; }
.ml-auto { margin-left: auto; }
.p-20 { padding: 20px; }
.mt-12 { margin-top: 12px; }

/* Scrollbar styling */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c8ccd0; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a0a5aa; }

/* ============================================================
   v3 additions — investor summary, addresses, compliance pills,
   inline-add details, mailings audience builder, helper buttons.
   ============================================================ */

/* Compliance / status pills (extend existing fm-pill scheme) */
.fm-pill-green { background: #e3f4e3; color: var(--fm-green); border-radius: 10px; padding: 1px 8px; font-size: 11px; }
.fm-pill-red   { background: #fbe6e3; color: var(--fm-red);   border-radius: 10px; padding: 1px 8px; font-size: 11px; }
.fm-pill-amber { background: #fff4d6; color: #946000;         border-radius: 10px; padding: 1px 8px; font-size: 11px; }
.fm-pill-grey  { background: #ececef; color: #555;            border-radius: 10px; padding: 1px 8px; font-size: 11px; }

/* Investor summary block — three side-by-side mini-tables */
.fm-summary-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, 1.2fr);
  gap: 12px;
  padding: 8px 12px 14px;
}
.fm-summary-block { background: #fff; border: 1px solid var(--fm-border-light); border-radius: 4px; overflow: hidden; }
.fm-summary-block-title { padding: 6px 10px; font-size: 12px; font-weight: 600; color: var(--fm-label); background: #f6f8fa; border-bottom: 1px solid var(--fm-border-light); }
.fm-summary-block .fm-grid { font-size: 12px; }
.fm-grid-total td { background: #f9fafb; }
.fm-grid-group td {
  background: var(--fm-accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #fff;
  padding: 7px 10px;
  border-bottom: 1px solid var(--fm-accent);
  border-top: 1px solid var(--fm-accent);
}
.fm-grid-group:hover td { background: var(--fm-accent); }

/* Address / employment / list sub-grid affordances */
.fm-inline-add { margin-top: 8px; }
.fm-inline-add > summary {
  cursor: pointer;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--fm-link);
  background: #f6f8fa;
  border: 1px dashed var(--fm-border);
  border-radius: 3px;
  display: inline-block;
}
.fm-inline-add[open] > summary { background: #eef3f8; border-style: solid; }
.fm-inline-add .fm-form { padding: 10px; background: #fafbfc; border: 1px solid var(--fm-border); border-top: 0; border-radius: 0 0 3px 3px; }

.fm-form-inline { display: inline-flex; gap: 6px; align-items: center; }
.fm-form-inline select { font-size: 12px; max-width: 220px; }

/* Inline link-style button for ✕ actions inside grid cells */
.fm-link-btn { background: none; border: none; color: var(--fm-red); cursor: pointer; font-size: 12px; padding: 0 4px; }
.fm-link-btn:hover { text-decoration: underline; }

/* Primary / secondary form buttons */
.fm-btn-primary, .fm-btn-secondary {
  font: inherit; font-size: 12px;
  padding: 5px 12px; border-radius: 3px; border: 1px solid transparent; cursor: pointer;
}
.fm-btn-primary { background: var(--fm-accent); color: #fff; border-color: var(--fm-accent); }
.fm-btn-primary:hover { background: var(--fm-link-hover); border-color: var(--fm-link-hover); }
.fm-btn-secondary { background: #fff; color: var(--fm-text); border-color: var(--fm-border); }
.fm-btn-secondary:hover { background: var(--fm-row-hover); }

/* ===== Mailings audience builder ===== */
.fm-audience-sources { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; }
.fm-pill-source { background: #eef3f8; color: var(--fm-link); border-radius: 10px; padding: 2px 8px; font-size: 11px; }
.fm-pill-source-list     { background: #eef3f8; color: #0c4a85; }
.fm-pill-source-investor { background: #f0eafa; color: #5128a3; }
.fm-pill-source-company  { background: #e9f4ec; color: #1a6e36; }
.fm-pill-source-fund     { background: #fff4d6; color: #946000; }
.fm-pill-source-person   { background: #ececef; color: #444; }

.fm-audience-picker { padding: 8px 12px; }
.fm-audience-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--fm-border); margin-bottom: 8px; }
.fm-aud-tab {
  background: none; border: 0; padding: 6px 10px; cursor: pointer;
  font-size: 12px; color: var(--fm-text-muted);
  border-bottom: 2px solid transparent;
}
.fm-aud-tab:hover { color: var(--fm-link); }
.fm-aud-tab.active { color: var(--fm-link); border-bottom-color: var(--fm-accent); font-weight: 600; }

.fm-aud-panel { display: none; }
.fm-aud-panel.active { display: block; }

/* ============================================================
   v4 additions — investor balances mini-card, status pills, num cell
   ============================================================ */

/* Investor balances headline card */
.fm-balances-card {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  padding: 12px;
  margin: 8px 12px;
  background: linear-gradient(135deg, #f8fafc 0%, #eef3f8 100%);
  border: 1px solid var(--fm-border);
  border-radius: 4px;
}
.fm-balances-item { padding: 4px 8px; }
.fm-balances-label {
  font-size: 11px;
  color: var(--fm-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.fm-balances-value {
  font-size: 20px;
  font-weight: 600;
  color: var(--fm-accent);
  margin-top: 2px;
}
.fm-balances-ccy {
  font-size: 12px;
  font-weight: 400;
  color: var(--fm-text-muted);
}

/* Numeric-right cell convenience */
.num { text-align: right; }

/* fm-pill (default plain) used by fund/feeder tags in tables */
.fm-pill { background: #ececef; color: #444; border-radius: 10px; padding: 1px 8px; font-size: 11px; }

/* Group boundary in mappings.php — subtle top border on each new company */
.fm-row-newgroup td { border-top: 2px solid var(--fm-border); }

/* v5: document group pills (re-uses fm-pill-grey/amber/green base colours) */
/* (G1 = grey, G2 = amber, G3 = green per the upload-form copy) */

/* v6: mailings step-up additions */

/* Kind-filter tabs on mailings.php */
.fm-tabs {
  display: flex; gap: 4px; border-bottom: 1px solid var(--fm-border);
  padding-bottom: 0; margin-bottom: 8px;
}
.fm-tab {
  display: inline-block; padding: 6px 12px;
  border: 1px solid transparent; border-bottom: 0;
  border-radius: 4px 4px 0 0;
  font-size: 12px; color: var(--fm-text-muted);
  text-decoration: none; cursor: pointer;
}
.fm-tab:hover { color: var(--fm-link); background: var(--fm-row-hover); }
.fm-tab.active {
  color: var(--fm-link); font-weight: 600;
  background: #fff;
  border-color: var(--fm-border); border-bottom-color: #fff;
  position: relative; top: 1px;
}

/* Mail history collapsible — use summary as the section title hook */
details.fm-section > summary { cursor: pointer; list-style: none; }
details.fm-section > summary::-webkit-details-marker { display: none; }
details.fm-section[open] > summary .chevron { transform: rotate(90deg); display: inline-block; }

/* ============================================================
   Responsive — iPhone landscape primarily, then narrower
   Breakpoints: 1024 / 768 / 480
   No existing rule modified — these are additive overrides.
   ============================================================ */

/* Hamburger button — only visible on narrow viewports (overridden below) */
.fm-hamburger { display: none; }

/* ≤ 1024px — iPhone landscape, small tablets */
@media (max-width: 1024px) {
  /* Sidebar shrinks to icon rail */
  :root { --fm-sidebar-width: 48px; }
  .fm-sidebar { padding-top: 4px; }
  /* Icon rail: keep the logo mark, drop the wordmark text */
  .fm-sidebar-brand { justify-content: center; padding: 8px 4px 10px; gap: 0; }
  .fm-sidebar-brand .fm-wordmark { display: none; }
  .fm-sidebar-group-title { display: none; }
  .fm-sidebar-item { padding: 8px 4px; justify-content: center; gap: 0; }
  .fm-sidebar-item .icon { font-size: 18px; margin: 0; }
  /* Hide label text on non-active items */
  .fm-sidebar-item:not(.active) > :not(.icon) { display: none; }
  /* Active item keeps its label so user knows context */
  .fm-sidebar-item.active { padding-left: 8px; padding-right: 8px; justify-content: flex-start; }

  /* Timeline column stacks below main on detail pages */
  .fm-content-wrapper { flex-direction: column; }
  .fm-timeline { width: 100%; min-width: 0; max-width: 100%;
                  border-left: 0; border-top: 1px solid var(--fm-border); }

  /* Tables get horizontal scroll on narrow viewports */
  .fm-content > table.fm-grid,
  .fm-section table.fm-grid,
  .fm-subgrid table.fm-grid { display: block; overflow-x: auto; max-width: 100%; }

  /* Investor Summary 3-col grid collapses to 1 */
  .fm-summary-grid { grid-template-columns: 1fr; }
}

/* ≤ 768px — small phones in landscape, small tablets portrait */
@media (max-width: 768px) {
  /* Sidebar becomes hamburger drawer */
  :root { --fm-sidebar-width: 0px; }
  .fm-sidebar {
    position: fixed; top: 0; left: 0; height: 100vh;
    width: 220px; min-width: 220px;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    z-index: 100; box-shadow: 2px 0 8px rgba(0,0,0,0.15);
    overflow-y: auto;
  }
  body.fm-sidebar-open .fm-sidebar { transform: translateX(0); }
  body.fm-sidebar-open::after {
    content: ''; position: fixed; inset: 0;
    background: rgba(0,0,0,0.3); z-index: 99;
  }
  /* Inside the drawer, restore full labels + wordmark */
  .fm-sidebar-brand { justify-content: flex-start; padding: 10px 14px 12px; gap: 9px; }
  .fm-sidebar-brand .fm-wordmark { display: inline; }
  .fm-sidebar-group-title { display: block; }
  .fm-sidebar-item { padding: 10px 14px; justify-content: flex-start; }
  .fm-sidebar-item > :not(.icon) { display: inline !important; }

  /* Hamburger button visible */
  .fm-hamburger {
    display: inline-block;
    position: fixed; top: 8px; left: 8px;
    padding: 6px 10px;
    border: 1px solid var(--fm-border); border-radius: 3px;
    background: #fff; cursor: pointer; font-size: 16px; line-height: 1;
    z-index: 101;
  }
  /* Make room at the top for the hamburger */
  .fm-main { padding-top: 44px; }

  /* Toolbar wraps cleanly on narrow viewports */
  .fm-toolbar { flex-wrap: wrap; gap: 6px; height: auto; padding: 6px; }
  .fm-toolbar > form { flex-wrap: wrap; }

  /* Forms — one field per row */
  .fm-form-row { flex-direction: column; gap: 8px; }
  .fm-form-field { width: 100%; }

  /* Tabs wrap */
  .fm-tabs { flex-wrap: wrap; }
  .fm-tab { padding: 4px 8px; font-size: 11px; }

  /* Balances card grid: smaller minmax */
  .fm-balances-card { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
                       padding: 8px; gap: 8px; }
  .fm-balances-value { font-size: 16px; }

  /* Dashboard KPI cards: 2-up at this width */
  .fm-content > .fm-balances-card { grid-template-columns: repeat(2, 1fr); }
}

/* ≤ 480px — phone portrait. Functional but not optimised. */
@media (max-width: 480px) {
  .fm-content > .fm-balances-card { grid-template-columns: 1fr; }
  .fm-record-header { flex-wrap: wrap; }
  .fm-record-header .record-name { font-size: 16px; }
  .fm-section-title { font-size: 13px; }
  .fm-content { padding: 8px; }
}

/* Mobile: dashboard summary-block tables (Recent mailings / tracked emails /
   fund + feeder breakdowns) are far wider than a phone. The card itself has
   overflow:hidden, so without this the extra columns are clipped and
   unreachable. Make each table a scroll container so it swipes sideways
   *inside its own card* instead of clipping. Desktop/tablet grids untouched
   (scoped to phones). */
@media (max-width: 768px) {
  .fm-summary-block > table.fm-grid {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
}

/* Always-on opt-in horizontal-scroll wrapper for very wide tables */
.fm-table-scroll {
  width: 100%; overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ------------------------------------------------------------------
   Mobile column priority (phones, <=600px). The list/detail tables are
   far wider than a phone, so by default you see only Name + part of the
   next column and must swipe the table sideways. On phones, hide the
   low-priority columns so the essentials fit without horizontal scroll.
   Scoped by data-box-id (added 2026-06-12) + nth-child, so desktop and
   landscape (>600px) keep every column. Rotate to landscape / use
   desktop for the full grid, merge, and delete.
   ------------------------------------------------------------------ */
@media (max-width: 600px) {
  /* Stacked-card rows. A wide CRM table can't fit a phone, and table-layout
     can't be relied on inside the shrink-to-fit scroll container, so each row
     becomes a small card: the kept fields stack vertically and always fit the
     width. Low-priority columns are hidden (below); the kept fields are the
     ones an IR person glances at. Full grid / merge / delete on desktop or
     landscape (>600px). */
  table[data-box-id="CO-LIST"], table[data-box-id="CN-LIST"],
  table[data-box-id="CO-LIST"] tbody, table[data-box-id="CN-LIST"] tbody,
  table[data-box-id="CO-LIST"] tr, table[data-box-id="CN-LIST"] tr,
  table[data-box-id="CO-LIST"] td, table[data-box-id="CN-LIST"] td { display: block; width: auto; }
  table[data-box-id="CO-LIST"] > colgroup, table[data-box-id="CN-LIST"] > colgroup { display: none; }
  table[data-box-id="CO-LIST"] thead, table[data-box-id="CN-LIST"] thead { display: none; }
  table[data-box-id="CO-LIST"] tr, table[data-box-id="CN-LIST"] tr {
    border-bottom: 1px solid var(--fm-border);
    padding: 7px 0;
  }
  table[data-box-id="CO-LIST"] td, table[data-box-id="CN-LIST"] td {
    border: none !important;
    padding: 1px 14px;
    white-space: normal;
    text-align: left !important;
  }
  /* Name (first cell): the row's anchor - bigger + bold. */
  table[data-box-id="CO-LIST"] td:nth-child(1), table[data-box-id="CN-LIST"] td:nth-child(1) {
    font-size: 14px; font-weight: 600; padding-bottom: 2px;
  }
  /* Companies: keep Name(1), Status(2), Holdings(6). Holdings gets a label. */
  table[data-box-id="CO-LIST"] td:nth-child(6)::before { content: "Holdings: "; color: var(--fm-text-muted); }
  table[data-box-id="CO-LIST"] td:nth-child(3),
  table[data-box-id="CO-LIST"] td:nth-child(4),
  table[data-box-id="CO-LIST"] td:nth-child(5),
  table[data-box-id="CO-LIST"] td:nth-child(7),
  table[data-box-id="CO-LIST"] td:nth-child(8),
  table[data-box-id="CO-LIST"] td:nth-child(9),
  table[data-box-id="CO-LIST"] td:nth-child(10) { display: none; }

  /* Contacts: keep Name(1), Company(2), Title(6). */
  table[data-box-id="CN-LIST"] td:nth-child(3),
  table[data-box-id="CN-LIST"] td:nth-child(4),
  table[data-box-id="CN-LIST"] td:nth-child(5),
  table[data-box-id="CN-LIST"] td:nth-child(7),
  table[data-box-id="CN-LIST"] td:nth-child(8),
  table[data-box-id="CN-LIST"] td:nth-child(9),
  table[data-box-id="CN-LIST"] td:nth-child(10),
  table[data-box-id="CN-LIST"] td:nth-child(11),
  table[data-box-id="CN-LIST"] td:nth-child(12),
  table[data-box-id="CN-LIST"] td:nth-child(13) { display: none; }
}

/* Touch hit targets — bump links/buttons to 36px+ on touch devices */
@media (pointer: coarse) {
  .fm-sidebar-item,
  .fm-tab,
  .fm-btn-primary, .fm-btn-secondary,
  .fm-toolbar-btn { min-height: 36px; }
  .fm-link-btn { padding: 6px 10px; }
}

/* ============================================================
   Dashboard omnibox (cross-entity search)
   ============================================================ */
.fm-search-wrap {
  position: relative;
  max-width: 1100px;
  margin: 8px auto 24px;
  padding: 4px 16px 0;
}
.fm-search {
  display: flex; align-items: center; gap: 12px;
  background: #fff;
  border: 2px solid var(--fm-border);
  border-radius: 28px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  padding: 12px 22px;
  font-size: 17px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.fm-search:hover {
  border-color: var(--fm-accent);
}
.fm-search:focus-within {
  border-color: var(--fm-accent);
  box-shadow: 0 2px 16px rgba(46,120,199,0.22);
}
.fm-search-icon { font-size: 20px; color: var(--fm-text-muted); }
.fm-search input {
  flex: 1; border: 0; outline: none;
  font: inherit; font-size: 17px;
  background: transparent;
}
.fm-search input::placeholder { color: #8a8a8a; }
.fm-search-hint {
  font-size: 12px; color: var(--fm-text-muted);
  white-space: nowrap;
}
.fm-search-results {
  position: absolute;
  left: 12px; right: 12px;
  top: 100%;
  margin-top: 4px;
  background: #fff;
  border: 1px solid var(--fm-border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  max-height: 480px; overflow-y: auto;
  z-index: 50;
}
.fm-search-empty {
  padding: 14px 16px;
  color: var(--fm-text-muted); font-size: 13px;
}
.fm-search-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  grid-template-rows: auto auto;
  column-gap: 12px;
  padding: 8px 14px;
  text-decoration: none;
  color: var(--fm-text);
  border-bottom: 1px solid var(--fm-border-light);
  cursor: pointer;
}
.fm-search-row:last-child { border-bottom: 0; }
.fm-search-row:hover, .fm-search-row.active { background: var(--fm-row-hover); }
.fm-search-kind {
  grid-row: 1 / 3;
  align-self: center;
  font-size: 11px; color: var(--fm-text-muted);
  text-transform: lowercase; letter-spacing: 0.4px;
  background: var(--fm-section-bg);
  border: 1px solid var(--fm-border-light);
  border-radius: 4px;
  padding: 4px 6px;
  display: flex; align-items: center; gap: 6px;
}
.fm-search-kind-icon { font-size: 14px; }
.fm-search-name { grid-column: 2; font-weight: 600; font-size: 14px; }
.fm-search-secondary {
  grid-column: 2;
  font-size: 11px; color: var(--fm-text-muted);
}
.fm-search-row mark {
  background: #fff4b8; color: inherit; padding: 0 1px; border-radius: 2px;
}

/* Mobile: omnibox a bit tighter */
@media (max-width: 768px) {
  .fm-search-wrap { padding: 4px 8px 0; }
  .fm-search { padding: 6px 12px; font-size: 13px; max-width: 100%; }
  /* flex items default to min-width:auto, so the input refuses to shrink
     below its (long) placeholder and pushes the pill past the viewport.
     Let it shrink so the search fits the phone width. */
  .fm-search input { min-width: 0; }
  .fm-search-row { grid-template-columns: 90px 1fr; padding: 8px 10px; }
}

/* Very narrow phones: drop the "type 2+ chars..." hint — it clips off the
   right edge and the placeholder already conveys intent. Mobile-only. */
@media (max-width: 480px) {
  .fm-search-hint { display: none; }
}

/* ============================================================
   Box-ID badges + dashboard-wide summary grid
   ============================================================ */

/* Dashboard variant — auto-fits cards at ≥360px so they don't crunch */
.fm-summary-grid-dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 14px;
  padding: 8px 12px 14px;
}

/* Box-ID badges: any element with data-box-id gets a small monospace tag
   in the top-right corner. Used to give staff stable references like "D2". */
[data-box-id] { position: relative; }
[data-box-id]::before {
  content: attr(data-box-id);
  position: absolute;
  top: 4px; right: 6px;
  font: 600 10px/1 'Cascadia Code', 'Consolas', monospace;
  color: var(--fm-text-muted);
  background: #fff;
  border: 1px solid var(--fm-border-light);
  border-radius: 3px;
  padding: 2px 5px;
  letter-spacing: 0.3px;
  z-index: 2;
  pointer-events: none;
  opacity: 0.55;
  transition: opacity 0.12s ease;
}
[data-box-id]:hover::before { opacity: 1; }

/* Test-mode banner — sit at the very top of mailing UI pages */
.fm-test-mode-banner {
  background: #fff4d6;
  border: 1px solid #946000;
  color: #6b4400;
  padding: 10px 16px;
  padding-right: 64px;   /* clear the data-box-id (!TEST) badge in the corner */
  margin: 8px 12px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.4;
  position: relative;
}
.fm-test-mode-banner code {
  background: #fff;
  border: 1px solid #ddd;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
}

/* ---------------------------------------------------------------------
   Staff auth: login page (login.php) + sidebar signed-in footer.
   See scripts/functions-fundrm-auth.php.
   --------------------------------------------------------------------- */
.fm-login-body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px 16px;
  /* Restrained, professional gradient backdrop in the brand navy family. */
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(47,111,176,0.14), transparent 60%),
    linear-gradient(180deg, #eef2f7 0%, #e3e9f1 100%);
  font-family: var(--fm-font);
  color: var(--fm-text);
}
.fm-login-card {
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--fm-body-bg);
  border: 1px solid var(--fm-border);
  border-radius: 12px;
  box-shadow: 0 10px 34px rgba(19, 42, 68, 0.14);
  padding: 30px 30px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  /* Thin brand accent bar across the top of the card. */
  border-top: 3px solid var(--fm-brand-accent);
}
.fm-login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.fm-login-logo .fm-wordmark { font-size: 26px; }
.fm-login-tagline {
  margin-top: -4px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fm-brand);
}
.fm-login-sub {
  margin-top: -8px;
  font-size: 13px;
  color: var(--fm-text-muted);
}
.fm-login-values {
  list-style: none;
  margin: 8px 0 0;
  padding: 14px 0 0;
  border-top: 1px solid var(--fm-border-light);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.fm-login-values li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--fm-text-muted);
  line-height: 1.35;
}
.fm-login-value-ic {
  flex-shrink: 0;
  font-size: 13px;
  line-height: 1.35;
  filter: grayscale(0.1);
}
.fm-login-footer {
  font-size: 11px;
  color: var(--fm-text-muted);
  letter-spacing: 0.02em;
}
.fm-login-error {
  background: #fde8e6;
  border: 1px solid var(--fm-red);
  color: var(--fm-red);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 13px;
}
.fm-login-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--fm-label);
}
.fm-login-field input {
  padding: 8px 10px;
  border: 1px solid var(--fm-input-border);
  background: var(--fm-input-bg);
  border-radius: 4px;
  font-size: 14px;
  font-family: var(--fm-font);
}
.fm-login-field input:focus {
  outline: none;
  border-color: var(--fm-accent);
  box-shadow: 0 0 0 2px rgba(46, 120, 199, 0.20);
}
.fm-login-btn {
  margin-top: 4px;
  padding: 9px 12px;
  border: none;
  border-radius: 4px;
  background: var(--fm-accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.fm-login-btn:hover { background: var(--fm-link-hover); }

/* Passkey (WebAuthn) sign-in + registration. See www/js/fundrm-passkey.js,
   www/passkey-auth.php, www/passkey-register.php. */
.fm-login-or {
  display: flex;
  align-items: center;
  text-align: center;
  gap: 8px;
  font-size: 11px;
  color: var(--fm-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.fm-login-or::before,
.fm-login-or::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--fm-border);
}
.fm-login-passkey-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.fm-login-btn-passkey {
  background: var(--fm-body-bg);
  color: var(--fm-accent);
  border: 1px solid var(--fm-accent);
}
.fm-login-btn-passkey:hover { background: var(--fm-section-bg); }
.fm-login-btn-passkey:disabled { opacity: 0.6; cursor: default; }
.fm-login-link {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--fm-accent);
  text-decoration: none;
}
.fm-login-link:hover { text-decoration: underline; }
.fm-passkey-card { width: 360px; }
.fm-passkey-intro {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--fm-text);
}
.fm-passkey-msg {
  min-height: 16px;
  font-size: 12px;
  color: var(--fm-text-muted);
}
.fm-passkey-msg-error { color: var(--fm-red); }
.fm-passkey-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.fm-passkey-table th,
.fm-passkey-table td {
  text-align: left;
  padding: 6px 6px;
  border-bottom: 1px solid var(--fm-border-light);
  vertical-align: middle;
}
.fm-passkey-table th { color: var(--fm-label); font-weight: 600; }
.fm-passkey-rename {
  display: flex;
  gap: 4px;
  align-items: center;
}
.fm-passkey-rename input {
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid var(--fm-input-border);
  background: var(--fm-input-bg);
  border-radius: 4px;
  font-size: 12px;
  font-family: var(--fm-font);
}
.fm-passkey-mini {
  padding: 4px 8px;
  border: 1px solid var(--fm-border);
  background: var(--fm-section-bg);
  color: var(--fm-text);
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}
.fm-passkey-mini:hover { background: var(--fm-body-bg); }
.fm-passkey-danger { color: var(--fm-red); border-color: var(--fm-red); }

/* Sidebar footer: signed-in user + logout */
.fm-sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-top: 1px solid var(--fm-border-light);
  background: var(--fm-section-bg);
  font-size: 11px;
  color: var(--fm-sidebar-text);
}
.fm-sidebar-user {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fm-sidebar-user .icon { opacity: 0.7; }
.fm-sidebar-logout {
  flex: none;
  color: var(--fm-link);
  text-decoration: none;
  font-weight: 600;
}
.fm-sidebar-logout:hover { color: var(--fm-link-hover); text-decoration: underline; }

/* Excel-green download/export button. Use class="fm-btn-excel" with an
   <img src="/grf/icons/excel.png" width="14" height="14"> for the icon.
   Riya 2026-06-02: distinguish Excel exports from neutral toolbar
   buttons so the affordance is obvious at a glance. */
.fm-btn-excel {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 3px;
    text-decoration: none;
    background: #1d6f42;
    color: #fff !important;
    border: 1px solid #155832;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    line-height: 1.2;
}
.fm-btn-excel:hover { background: #155832; color: #fff; }
.fm-btn-excel img   { display: inline-block; vertical-align: middle; }

/* ---- README / Help page (readme.php) ---------------------------------- */
.fm-doc            { max-width: 820px; line-height: 1.55; color: var(--fm-text); }
.fm-doc h2         { font-size: 18px; margin: 28px 0 8px; color: var(--fm-sidebar-heading); }
.fm-doc h2:first-child { margin-top: 4px; }
.fm-doc h3         { font-size: 14px; margin: 20px 0 6px; color: var(--fm-label); }
.fm-doc p          { margin: 0 0 10px; }
.fm-doc ul         { margin: 0 0 12px; padding-left: 22px; }
.fm-doc li         { margin: 3px 0; }
.fm-doc code       { font-family: var(--fm-font-mono); font-size: 12px;
                     background: var(--fm-section-bg); border: 1px solid var(--fm-border-light);
                     border-radius: 3px; padding: 1px 4px; }
.fm-doc .fm-doc-lead { font-size: 13px; color: var(--fm-text-muted); margin-bottom: 18px; }
/* Side-by-side concept cards (Contacts vs Investors). */
.fm-doc-cols       { display: flex; gap: 16px; flex-wrap: wrap; margin: 14px 0 4px; }
.fm-doc-card       { flex: 1 1 320px; background: var(--fm-section-bg);
                     border: 1px solid var(--fm-section-border); border-radius: 6px; padding: 14px 16px; }
.fm-doc-card h3    { margin-top: 0; }
.fm-doc-card .src  { font-size: 11px; color: var(--fm-text-muted); margin-top: 8px; }

/* CO-DOCS subject search box (company-detail linked-documents card). */
.fm-doc-search {
    width: 100%; max-width: 320px;
    padding: 4px 8px;
    border: 1px solid var(--fm-input-border);
    border-radius: 2px;
    font-size: 12px;
}

/* ---- In-app HELP system (help.php + per-page "?" drawer) -------------- */
/* One block governs the look of ALL help, in both the drawer and the
   full-page viewer. Edit here to restyle every help page at once. */

/* The "?" button injected into every toolbar (fundrm_help_inject_html). */
.fm-help-btn {
    width: 22px; height: 22px; flex-shrink: 0;
    border: 1px solid var(--fm-input-border); border-radius: 50%;
    background: #fff; color: var(--fm-accent);
    font-size: 13px; font-weight: 700; line-height: 1; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
}
.fm-help-btn:hover { background: var(--fm-accent); color: #fff; border-color: var(--fm-accent); }

/* Shared help content styling (used inside .fm-help-page and the drawer). */
.fm-help               { max-width: 760px; line-height: 1.55; color: var(--fm-text); }
.fm-help-page          { padding: 20px 24px; }
.fm-help-head          { display: flex; align-items: baseline; gap: 12px;
                         border-bottom: 1px solid var(--fm-border); padding-bottom: 8px; margin-bottom: 4px; }
.fm-help-head h1       { font-size: 19px; color: var(--fm-sidebar-heading); margin: 0; }
.fm-help-reviewed      { font-size: 11px; color: var(--fm-text-muted); margin-left: auto; white-space: nowrap; }
.fm-help-sec           { margin: 16px 0; }
.fm-help-sec h2        { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em;
                         color: var(--fm-label); margin: 0 0 6px; }
.fm-help-sec p         { margin: 0 0 8px; }
.fm-help code          { font-family: var(--fm-font-mono); font-size: 12px;
                         background: var(--fm-section-bg); border: 1px solid var(--fm-border-light);
                         border-radius: 3px; padding: 1px 4px; }
.fm-help-fns           { margin: 0; }
.fm-help-fns dt        { font-weight: 600; color: var(--fm-text); margin-top: 8px; }
.fm-help-fns dt:first-child { margin-top: 0; }
.fm-help-fns dd        { margin: 1px 0 0; padding-left: 14px; color: var(--fm-text-muted); }
.fm-help-links         { margin: 0; padding-left: 20px; }
.fm-help-links li      { margin: 3px 0; }
.fm-help-readonly      { color: var(--fm-text-muted); }
.fm-help-empty,
.fm-help-loading       { color: var(--fm-text-muted); padding: 12px 0; }
.fm-help-idx td        { white-space: normal; }
.fm-help-idx-group td  { background: var(--fm-section-bg); font-weight: 700;
                         color: var(--fm-sidebar-heading); text-transform: none; }

/* Slide-in drawer (per-page "?" help). */
.fm-help-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.28); z-index: 90;
}
.fm-help-drawer {
    position: fixed; top: 0; right: 0; bottom: 0; width: 460px; max-width: 92vw;
    background: #fff; border-left: 1px solid var(--fm-border);
    box-shadow: -4px 0 22px rgba(0,0,0,0.16); z-index: 91;
    display: flex; flex-direction: column;
}
/* The explicit display above would otherwise beat the [hidden] UA rule, so the
   drawer/backdrop must opt back out when hidden. */
.fm-help-drawer[hidden], .fm-help-backdrop[hidden] { display: none; }
.fm-help-drawer-bar {
    display: flex; align-items: center; gap: 8px;
    height: var(--fm-toolbar-height); min-height: var(--fm-toolbar-height);
    padding: 0 10px 0 16px; border-bottom: 1px solid var(--fm-header-border);
    background: var(--fm-header-bg);
}
.fm-help-drawer-link  { font-size: 12px; }
.fm-help-drawer-close {
    margin-left: auto; border: none; background: transparent;
    font-size: 22px; line-height: 1; color: var(--fm-text-muted); cursor: pointer; padding: 0 4px;
}
.fm-help-drawer-close:hover { color: var(--fm-text); }
.fm-help-drawer-body  { overflow-y: auto; padding: 16px 18px; }
.fm-help-drawer-body .fm-help { max-width: none; }
.fm-help-drawer-body .fm-help-idx td { font-size: 12px; }

/* ============================================================
   Email-detail linker (omni-linker) + linked-entity chips
   Used by www/email-detail.php to attach an email to a
   contact / company / activity / meeting and show what is linked.
   ============================================================ */
.fm-linkchip          { display: inline-flex; align-items: center; gap: 4px; }
.fm-linkchip-action,
.fm-linkchip-x        { background: none; border: none; padding: 0 2px; cursor: pointer;
                        font-size: 11px; line-height: 1; }
.fm-linkchip-action   { color: #1f4985; }
.fm-linkchip-action:hover { text-decoration: underline; }
.fm-linkchip-x        { color: #a80000; font-size: 14px; font-weight: 600; }
.fm-linkchip-x:hover  { color: #d40000; }

.fm-omnilink-results {
  position: absolute;
  left: 0; right: 0; top: 100%;
  margin-top: 4px;
  background: #fff;
  border: 1px solid var(--fm-border);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  max-height: 320px; overflow-y: auto;
  z-index: 50;
}
.fm-omnilink-row {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; cursor: pointer;
  border-bottom: 1px solid var(--fm-border-light);
  font-size: 12px;
}
.fm-omnilink-row:last-child { border-bottom: none; }
.fm-omnilink-row:hover      { background: #eef4fb; }
.fm-omnilink-kind {
  flex: 0 0 auto;
  color: #fff; font-size: 10px; text-transform: uppercase; letter-spacing: .4px;
  padding: 1px 6px; border-radius: 9px;
}
.fm-omnilink-sec   { color: var(--fm-text-muted); font-size: 11px; }
.fm-omnilink-empty { padding: 6px 10px; color: #777; font-size: 12px; }

/* Tracked-email HTML body viewer: sandboxed iframe (email-body.php).
   Isolates the email's own CSS from the FUNDRM UI; parent JS auto-sizes height. */
.fm-email-frame {
  width: 100%;
  max-width: 920px;
  min-height: 200px;
  border: 1px solid var(--fm-border);
  border-radius: 3px;
  background: #fff;
  margin: 16px 24px;
  display: block;
}

/* ===== DEV TRACKER (fundrm-issues.js + issues.php) ======================= */
.fm-issues-fab {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 9000;
  border: 1px solid var(--fm-border);
  border-radius: 18px;
  background: #fff;
  padding: 7px 12px;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.fm-issues-fab.armed {
  background: #fff4d6;
  border-color: #d6b800;
  font-size: 12px;
}
body.fm-issues-arming * { cursor: crosshair !important; }
.fm-issues-dialog[hidden] { display: none; }   /* beat the class's display:flex so .hidden actually hides */
.fm-issues-dialog {
  position: fixed;
  inset: 0;
  z-index: 9500;
  background: rgba(31,58,79,.35);
  display: flex;
  align-items: center;
  justify-content: center;
}
.fm-issues-card {
  width: min(560px, 92vw);
  background: #fff;
  border: 1px solid var(--fm-border);
  border-radius: 6px;
  padding: 14px 16px;
  box-shadow: 0 6px 30px rgba(0,0,0,.25);
}
.fm-issues-head {
  font-weight: 600;
  color: var(--fm-text);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
}
.fm-issues-close { text-decoration: none; color: #a80000; font-size: 18px; line-height: 1; }
.fm-issues-refs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  align-items: center;
  margin-bottom: 8px;
  font-size: 11px;
}
.fm-issues-domhint {
  color: var(--fm-text-muted);
  font-size: 11px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fm-issues-text { width: 100%; font-size: 13px; padding: 8px; box-sizing: border-box; }
/* Cash-flows / capital-activity: cap the widest text columns so the detail
   table fits common screens (Riya CF-LIST friction). Full value on hover via
   the title attr; the .fm-table-scroll container still scrolls as a fallback. */
.cf-ellip {
  display: inline-block;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
.fm-issues-stored { margin-top: 8px; font-size: 11px; }
.fm-issues-stored > summary { cursor: pointer; color: var(--fm-text-muted); }
.fm-issues-stored-tbl { width: 100%; border-collapse: collapse; margin-top: 6px; }
.fm-issues-stored-tbl th {
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
  padding: 2px 8px 2px 0;
  color: var(--fm-text-muted);
  font-weight: 600;
  width: 1%;
}
.fm-issues-stored-tbl td {
  padding: 2px 0;
  word-break: break-word;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.fm-issues-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}
.fm-issues-status { font-size: 12px; color: var(--fm-text-muted); }
.fm-issue-detail td { background: #fbfcfe; }
.fm-issue-comment {
  border-left: 3px solid var(--fm-border);
  padding: 4px 10px;
  margin: 6px 0;
  font-size: 12px;
}
.fm-issue-comment .who { font-weight: 600; margin-right: 6px; }
.fm-issue-comment.claude { border-left-color: #7a5fbf; }

/* Audience picker (mailing wizards) - checkbox list + live deduped readout.
   Replaces the old native multi-select (Ctrl/Cmd-click) audience control. */
.fm-aud-list {
  max-height: 200px;
  overflow: auto;
  border: 1px solid var(--fm-border);
  border-radius: 3px;
  padding: 4px 8px;
  background: #fff;
}
.fm-aud-row {
  display: block;
  padding: 3px 2px;
  font-size: 13px;
  cursor: pointer;
}
.fm-aud-row:hover { background: #f3f6fa; }
.fm-aud-row input { margin-right: 8px; }
.fm-aud-readout { font-size: 12px; margin-top: 6px; }

/* Canonical email-preview surface - the ONE base style shared by the TinyMCE
   editor (content_style), the step-2 live preview and the step-4 preview, so
   "what you compose" == "what both previews show". The email body's own inline
   styles still win; this only sets the base font + default table borders. */
.fm-email-preview {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  color: #222;
  line-height: 1.4;
}
.fm-email-preview table { border-collapse: collapse; }
.fm-email-preview td, .fm-email-preview th { border: 1px solid #ccc; padding: 3px 6px; }

/* Step-3 right pane: resolved recipients of the chosen audience lists. */
.fm-aud-members {
  border: 1px solid var(--fm-border);
  border-radius: 3px;
  background: #fff;
  max-height: 320px;
  overflow: auto;
  font-size: 12px;
}
.fm-aud-member-head {
  position: sticky;
  top: 0;
  background: #f6f8fa;
  border-bottom: 1px solid var(--fm-border-light);
  padding: 5px 10px;
  font-weight: 600;
  color: var(--fm-label);
}
.fm-aud-member {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 10px;
  border-bottom: 1px solid #f0f2f5;
}
.fm-aud-member:hover { background: #f3f6fa; }

/* Step-4 audience rows: click to bake the preview as that recipient. */
.fm-recipient-row { cursor: pointer; }
.fm-recipient-row:hover { background: #f3f6fa; }
.fm-recipient-row.sel { background: #dbe6f3; }

/* ===== D1: omnibox + in-house LLM chat (dashboard) ===== */
.fm-d1-row { display: flex; gap: 14px; align-items: stretch; padding: 8px 12px 0; }
.fm-d1-left  { flex: 1.3 1 0; min-width: 0; transition: flex-grow .28s ease; }
.fm-d1-right { flex: 1 1 0; min-width: 0; transition: flex-grow .28s ease; }
.fm-d1-left.fm-search-wrap { margin: 0; }

/* Until first use the chat sits beside the omnibox; on first message it expands to ~66%
   (shrinking the omnibox) and grows taller. The head's shrink button reverts it. */
.fm-d1-row.fm-d1-expanded .fm-d1-left  { flex-grow: 1; }
.fm-d1-row.fm-d1-expanded .fm-d1-right { flex-grow: 2; }
.fm-d1-row.fm-d1-expanded .fm-chat     { height: 440px; }

.fm-chat { display: flex; flex-direction: column; height: 300px; background: #fff;
  border: 1px solid var(--fm-border-light); border-radius: 6px; overflow: hidden; transition: height .28s ease; }
.fm-chat-head { display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px; background: #f6f8fa; border-bottom: 1px solid var(--fm-border-light); }
.fm-chat-title { font-size: 12px; font-weight: 600; color: var(--fm-label, #555); }
.fm-chat-sub { font-weight: 400; color: var(--fm-text-muted, #888); font-size: 11px; }
.fm-chat-model { font-size: 11px; border: 1px solid var(--fm-border); border-radius: 4px; padding: 1px 4px; background: #fff; }
.fm-chat-head-r { display: flex; align-items: center; gap: 6px; }
.fm-chat-collapse { display: none; border: 1px solid var(--fm-border-light); background: #fff; cursor: pointer;
  font-size: 13px; line-height: 1; color: var(--fm-text-muted, #888); border-radius: 4px; padding: 2px 6px; }
.fm-chat-collapse:hover { color: var(--fm-text, #222); background: #eef1f4; }
.fm-d1-row.fm-d1-expanded .fm-chat-collapse { display: inline-flex; }

.fm-chat-thread { flex: 1 1 auto; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.fm-chat-empty { color: var(--fm-text-muted, #888); font-size: 12px; margin: auto; text-align: center; padding: 0 16px; }

.fm-chat-msg { display: flex; flex-direction: column; max-width: 92%; }
.fm-chat-user { align-self: flex-end; align-items: flex-end; }
.fm-chat-assistant { align-self: flex-start; align-items: flex-start; }
.fm-chat-bubble { font-size: 13px; line-height: 1.45; padding: 7px 10px; border-radius: 10px; word-wrap: break-word; }
.fm-chat-user .fm-chat-bubble { background: var(--fm-accent, #2e78c7); color: #fff; border-bottom-right-radius: 3px; }
.fm-chat-assistant .fm-chat-bubble { background: #f1f3f5; color: var(--fm-text, #222); border-bottom-left-radius: 3px; }
.fm-chat-thinking .fm-chat-bubble { color: var(--fm-text-muted, #888); font-style: italic; }
.fm-chat-err .fm-chat-bubble { background: #fde7e9; color: #a80000; }
.fm-chat-meta { font-size: 10px; color: var(--fm-text-muted, #999); margin-top: 2px; padding: 0 4px; }

.fm-chat-input { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--fm-border-light); }
.fm-chat-input textarea { flex: 1 1 auto; resize: none; font: inherit; font-size: 13px; line-height: 1.35;
  border: 1px solid var(--fm-input-border, #ccc); border-radius: 6px; padding: 6px 8px; max-height: 90px; overflow-y: auto; }
.fm-chat-input button { flex: 0 0 auto; border: none; border-radius: 6px; padding: 0 12px;
  background: var(--fm-accent, #2e78c7); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; }
.fm-chat-input button:disabled { opacity: .55; cursor: default; }

@media (max-width: 860px) { .fm-d1-row { flex-direction: column; } .fm-chat { height: 260px; } }

/* ---------------------------------------------------------------------------
   Mobile card-view for wide data tables (Riya round-7: dense tables clipped /
   side-scroll on phone). fundrm-tableops.js adds .fm-cards to a .fm-table-scroll
   wrapper + a data-label on every cell ONLY on narrow screens; if JS is off the
   table stays a normal horizontal-scroll table (graceful fallback).
--------------------------------------------------------------------------- */
@media (max-width: 640px) {
  .fm-table-scroll.fm-cards { overflow-x: visible; }
  .fm-table-scroll.fm-cards table.fm-grid,
  .fm-table-scroll.fm-cards table.fm-grid > tbody { display: block; width: 100%; }
  .fm-table-scroll.fm-cards table.fm-grid > thead,
  .fm-table-scroll.fm-cards table.fm-grid > colgroup { display: none; }
  .fm-table-scroll.fm-cards table.fm-grid > tbody > tr {
      display: block; margin: 0 0 10px; padding: 6px 10px;
      border: 1px solid var(--fm-border); border-radius: 8px; background: #fff;
  }
  .fm-table-scroll.fm-cards table.fm-grid > tbody > tr > td {
      display: flex; justify-content: space-between; gap: 12px;
      padding: 3px 0; border: none; text-align: right;
      white-space: normal; width: auto !important; min-height: 0;
  }
  .fm-table-scroll.fm-cards table.fm-grid > tbody > tr > td::before {
      content: attr(data-label); font-weight: 600; color: var(--fm-text-muted);
      text-align: left; flex: 0 0 40%; white-space: nowrap;
  }
  .fm-table-scroll.fm-cards table.fm-grid > tbody > tr > td:empty { display: none; }
  /* full-width "no rows" / colspan cells: no label, centred */
  .fm-table-scroll.fm-cards table.fm-grid > tbody > tr > td[colspan] { justify-content: center; text-align: center; }
  .fm-table-scroll.fm-cards table.fm-grid > tbody > tr > td[colspan]::before { content: none; }
}
