* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "DM Sans", sans-serif;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
  padding: 20px;
  min-height: 100vh;
}

a {
  text-decoration: none;
  color: var(--primary);
}
a:hover {
  text-decoration: underline;
}

/* ── CONTAINER ── */
.container {
  background-color: var(--surface);
  border-radius: 20px;
  max-width: 1400px;
  margin: 0 auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  border: 3px solid var(--accent-dark);
  overflow: hidden;
}

/* ── MODE BADGE (in global header title) ── */
.mode-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.16);
  color: var(--surface);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 9px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  vertical-align: middle;
}

.mode-badge.insurance {
  background: rgba(233, 30, 140, 0.35);
  border-color: rgba(233, 30, 140, 0.55);
}

/* ── MAIN CONTENT ── */
.main-content {
  padding: 20px;
  background: var(--surface-alt);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* =========================================================
   ERP TOOLBAR (record actions)
   ========================================================= */
.erp-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--accent-dark);
  border: 1px solid var(--accent-dark);
  border-radius: 4px;
  padding: 9px 16px;
}

.erp-toolbar-label {
  color: rgba(255, 255, 255, 0.9);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  gap: 7px;
}

.erp-toolbar-icon {
  font-size: 13px;
}

.action-buttons {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 7px 16px;
  border-radius: 3px;
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2px;
  cursor: pointer;
  font-family: inherit;
  transition: filter 0.15s;
}

.btn:hover {
  filter: brightness(1.08);
}
.btn:active {
  filter: brightness(0.95);
}

.btn-edit {
  background: var(--accent-dark);
  color: var(--surface);
  border-color: var(--accent-dark);
}
.btn-remove {
  background: var(--danger);
  color: var(--surface);
  border-color: var(--danger);
}
.btn-clear {
  background: var(--surface-alt);
  color: var(--accent-dark);
  border-color: var(--surface-alt);
}

/* =========================================================
   MODE TOGGLE (Cash / Insurance) — segmented ERP control
   ========================================================= */
.mode-toggle {
  display: flex;
  width: fit-content;
  border: 1px solid var(--surface-alt);
  border-radius: 4px;
  overflow: hidden;
  background: var(--surface);
}

.mode-tab {
  padding: 7px 22px;
  border: none;
  border-right: 1px solid var(--surface-alt);
  background: var(--surface-alt);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  cursor: pointer;
  font-family: inherit;
  transition:
    background 0.15s,
    color 0.15s;
}

.mode-tab:last-child {
  border-right: none;
}

.mode-tab:hover {
  background: var(--surface-alt);
}

.mode-tab.active {
  background: var(--accent-dark);
  color: var(--surface);
}

/* =========================================================
   INSURANCE PROVIDER TABS
   ========================================================= */
.insurance-tabs {
  background: var(--surface-alt);
  border: 1px solid var(--surface-alt);
  border-left: 4px solid var(--accent-dark);
  border-radius: 4px;
  padding: 9px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.ins-tabs-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent);
  white-space: nowrap;
}

.ins-tabs-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.ins-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 15px;
  border-radius: 3px;
  border: 1.5px solid var(--accent-light);
  background: var(--surface-alt);
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition:
    background 0.15s,
    border-color 0.15s,
    box-shadow 0.15s;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.ins-tab:hover {
  border-color: var(--accent-light);
  background: var(--surface-alt);
  color: var(--accent-dark);
}

.ins-tab.active {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: var(--surface);
}

.ins-tab.active .ins-tab-dot {
  border: 1.5px solid rgba(255, 255, 255, 0.6);
}

/* Override active bg per-provider (muted, still recognisable) */
.ins-tab[data-provider="RSSB"].active {
  background: var(--warning);
  border-color: var(--warning);
}
.ins-tab[data-provider="MMI"].active {
  background: var(--success);
  border-color: var(--success);
}
.ins-tab[data-provider="Sanlam"].active {
  background: var(--primary);
  border-color: var(--primary);
}
.ins-tab[data-provider="Old Mutual UAP"].active {
  background: var(--danger);
  border-color: var(--danger);
}

.ins-tab-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.ins-tab-all {
  margin-left: 2px;
  border-style: dashed;
  color: var(--accent-dark);
  border-color: var(--accent-light);
  background: var(--surface);
}

.ins-tab-all.active {
  background: var(--accent-dark) !important;
  border-style: solid;
  color: var(--surface);
}

/* =========================================================
   FORM PANEL — "New Record" entry (dense ERP form)
   ========================================================= */
.form-card {
  background: var(--surface);
  border: 1px solid var(--surface-alt);
  border-radius: 4px;
  overflow: hidden;
}

.form-card-header {
  background: var(--accent-dark);
  padding: 9px 16px;
  color: var(--surface);
  font-size: 12.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.3px;
}

.form-card-body {
  padding: 16px;
  background: var(--surface-alt);
}

.form-row {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

.form-row.four-col {
  grid-template-columns: repeat(5, 1fr);
}
.form-row.five-col {
  grid-template-columns: repeat(6, 1fr);
}
.form-row.three-col {
  grid-template-columns: repeat(3, 1fr);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--accent-dark);
}

.form-input {
  padding: 7px 10px;
  border: 1px solid var(--surface-alt);
  border-radius: 3px;
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  height: 34px;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent-dark);
  box-shadow: 0 0 0 2px rgba(74, 91, 36, 0.15);
}

select.form-input {
  cursor: pointer;
}

.form-footer {
  display: flex;
  justify-content: flex-end;
  padding-top: 2px;
}

.add-new-btn {
  background: var(--accent-dark);
  color: var(--surface);
  padding: 8px 22px;
  border-radius: 3px;
  border: 1px solid var(--accent-dark);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
  cursor: pointer;
  font-family: inherit;
  transition: filter 0.15s;
}

.add-new-btn:hover {
  filter: brightness(1.08);
}
.add-new-btn:active {
  filter: brightness(0.95);
}

/* =========================================================
   TABLE PANEL — ERP spreadsheet-style client list
   ========================================================= */
.table-card {
  background: var(--surface);
  border: 1px solid var(--surface-alt);
  border-radius: 4px;
  overflow: visible; /* allow filter panel to overflow */
}

.table-card-header {
  background: var(--accent-dark);
  border-radius: 4px 4px 0 0;
  padding: 9px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--accent-dark);
  gap: 14px;
  flex-wrap: wrap;
}

.table-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--surface);
}

.client-count-badge {
  background: rgba(255, 255, 255, 0.18);
  color: var(--surface);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 9px;
  border-radius: 3px;
  min-width: 24px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.table-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative; /* needed to anchor filter panel */
}

.filter-dropdown {
  background: rgba(255, 255, 255, 0.92);
  padding: 6px 14px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-dark);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
  user-select: none;
}

.filter-dropdown:hover {
  background: var(--surface);
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 3px;
  padding: 0 10px;
  transition: box-shadow 0.15s;
}

.search-wrap:focus-within {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.search-icon {
  font-size: 12px;
  color: var(--text-muted);
}

.search-input {
  border: none;
  outline: none;
  background: transparent;
  font-size: 12.5px;
  font-family: inherit;
  padding: 7px 0;
  width: 200px;
  color: var(--text);
}

/* =========================================================
   ERP QUICK FILTER / SORT ROW
   ========================================================= */
.erp-filter-row {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 14px;
  padding: 10px 16px;
  background: var(--surface-alt);
  border-top: 1px solid var(--surface-alt);
  border-bottom: 1px solid var(--surface-alt);
}

.erp-filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.erp-filter-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--accent-dark);
}

.erp-filter-select {
  padding: 6px 9px;
  border: 1px solid var(--surface-alt);
  border-radius: 3px;
  font-size: 12px;
  font-family: inherit;
  background: var(--surface);
  color: var(--accent-dark);
  height: 32px;
  min-width: 140px;
  cursor: pointer;
}

.erp-filter-select:focus {
  outline: none;
  border-color: var(--accent-dark);
  box-shadow: 0 0 0 2px rgba(74, 91, 36, 0.15);
}

.erp-filter-sort {
  margin-left: auto;
}

.erp-filter-clear-btn {
  height: 32px;
  padding: 0 16px;
  border-radius: 3px;
  border: 1px solid var(--surface-alt);
  background: var(--surface-alt);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.erp-filter-clear-btn:hover {
  background: var(--surface-alt);
}

/* ── TABLE BODY ── */
.table-body-wrapper {
  padding: 0;
  background: var(--surface-alt);
  overflow-x: auto;
}

/* Cash Mode — 5 equal-width columns */
.clients-table.cash-mode {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  min-width: 100%;
  width: auto;
}

/* Insurance Mode — 8 equal-width columns (9 with provider) */
.clients-table.insurance-mode {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: auto;
  min-width: 100%;
}

.clients-table {
  max-height: 440px;
  overflow-y: auto;
  width: auto;
}

/* Custom scrollbar */
.clients-table::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.clients-table::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.06);
}
.clients-table::-webkit-scrollbar-thumb {
  background: var(--accent-light);
}
.clients-table::-webkit-scrollbar-thumb:hover {
  background: var(--accent-dark);
}
.clients-table {
  scrollbar-width: thin;
  scrollbar-color: var(--accent-light) rgba(0, 0, 0, 0.06);
}

.table-header {
  display: contents;
}

/* Sticky two-tone ERP header row (JS creates these as .header-cell) */
.header-cell {
  background: var(--accent-dark);
  color: rgba(255, 255, 255, 0.92);
  padding: 8px 10px;
  font-weight: 700;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border: 1px solid var(--accent-dark);
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: left;
  white-space: nowrap;
  display: flex;
  align-items: center;
}

.table-row {
  display: contents;
}

.table-cell {
  background: var(--surface);
  padding: 0 10px;
  height: 38px;
  display: flex;
  align-items: center;
  font-size: 12.5px;
  color: var(--accent-dark);
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid var(--surface-alt);
  cursor: pointer;
  transition: background 0.1s;
}

/* Zebra striping: every other data row */
.table-row:nth-child(even) .table-cell {
  background: var(--surface-alt);
}

.table-cell:hover {
  background: var(--surface-alt);
}

.table-row.selected .table-cell {
  background: var(--surface-alt);
  font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* Empty placeholder rows */
.table-cell.empty-cell {
  background: var(--surface-alt);
  cursor: default;
  color: var(--text-muted);
  font-weight: 400;
}

.table-cell.empty-cell:hover {
  background: var(--surface-alt);
}

/* ── RESPONSIVE ── */
@media (max-width: 1100px) {
  .form-row.four-col,
  .form-row.five-col {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .form-row.four-col,
  .form-row.five-col {
    grid-template-columns: 1fr;
  }
  .erp-toolbar {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }
  .erp-filter-row {
    flex-direction: column;
    align-items: stretch;
  }
  .erp-filter-sort {
    margin-left: 0;
  }
  .erp-filter-select {
    min-width: 0;
    width: 100%;
  }
}

/* =============================================
   FILTER PANEL — CHIP BASED
   ============================================= */
.filter-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 380px;
  background: var(--surface);
  border-radius: 4px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--accent-light);
  z-index: 200;
  overflow: hidden;
}
.filter-panel.open {
  display: block;
}

.fp-header {
  background: var(--accent-dark);
  padding: 9px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.fp-title {
  color: var(--surface);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.fp-close {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: var(--surface);
  width: 20px;
  height: 20px;
  border-radius: 3px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.fp-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.fp-body {
  padding: 12px 14px;
  background: var(--surface-alt);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.fp-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fp-group-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--accent-dark);
}

.fp-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.fp-chip {
  padding: 4px 12px;
  border-radius: 3px;
  border: 1px solid var(--accent-light);
  background: var(--surface);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  color: var(--text-muted);
  transition: all 0.12s;
}
.fp-chip:hover {
  border-color: var(--accent-dark);
  color: var(--accent-dark);
  background: var(--surface-alt);
}
.fp-chip.active {
  background: var(--accent-dark);
  color: var(--surface);
  border-color: var(--accent-dark);
}

/* Compact square style for single-letter alphabet chips */
.fp-chip[data-value="A"],
.fp-chip[data-value="B"],
.fp-chip[data-value="C"],
.fp-chip[data-value="D"],
.fp-chip[data-value="E"],
.fp-chip[data-value="F"],
.fp-chip[data-value="G"],
.fp-chip[data-value="H"],
.fp-chip[data-value="I"],
.fp-chip[data-value="J"],
.fp-chip[data-value="K"],
.fp-chip[data-value="L"],
.fp-chip[data-value="M"],
.fp-chip[data-value="N"],
.fp-chip[data-value="O"],
.fp-chip[data-value="P"],
.fp-chip[data-value="Q"],
.fp-chip[data-value="R"],
.fp-chip[data-value="S"],
.fp-chip[data-value="T"],
.fp-chip[data-value="U"],
.fp-chip[data-value="V"],
.fp-chip[data-value="W"],
.fp-chip[data-value="X"],
.fp-chip[data-value="Y"],
.fp-chip[data-value="Z"] {
  padding: 3px 0;
  width: 26px;
  text-align: center;
  font-size: 10.5px;
}

/* Insurance provider chips get their brand colours when active */
.fp-chip[data-value="RSSB"].active {
  background: var(--warning);
  border-color: var(--warning);
}
.fp-chip[data-value="MMI"].active {
  background: var(--success);
  border-color: var(--success);
}
.fp-chip[data-value="Sanlam"].active {
  background: var(--primary);
  border-color: var(--primary);
}
.fp-chip[data-value="Old Mutual UAP"].active {
  background: var(--danger);
  border-color: var(--danger);
}

.fp-footer {
  padding: 8px 14px;
  background: var(--surface-alt);
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid var(--accent-light);
}

.fp-btn {
  padding: 6px 16px;
  border-radius: 3px;
  border: 1px solid var(--surface-alt);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.fp-clear {
  background: var(--surface-alt);
  color: var(--text-muted);
}
.fp-clear:hover {
  background: var(--surface-alt);
}

/* Insurance mode: provider column badge in table */
.ins-provider-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 3px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--surface);
  white-space: nowrap;
}
.ins-provider-badge.badge-rssb {
  background: var(--warning);
}
.ins-provider-badge.badge-mmi {
  background: var(--success);
}
.ins-provider-badge.badge-sanlam {
  background: var(--primary);
}
.ins-provider-badge.badge-uap {
  background: var(--danger);
}
