:root {
  /* "Aurora": white background, violet/teal accents. */
  --pg:#faf9fc; --card:#ffffff; --bd:#e8e4f0; --bd-strong:#d4cce3;
  --t1:#211c31; --t2:#655d78; --tm:#9891a8;
  --nav-bg:#1a1329; --nav-bg2:#2a1f42;

  --primary:#7c3aed; --primary-dark:#6d28d9; --primary-soft:rgba(124,58,237,.09);

  --success:#0d9488; --success-dark:#0f766e;
  --warning:#d97706; --warning-dark:#b45309;
  --danger:#dc2626;  --danger-dark:#b91c1c;

  --r:10px; --r-sm:6px;
  --sh:0 1px 3px rgba(33,28,49,.07), 0 1px 2px rgba(33,28,49,.04);
  --sh-md:0 8px 20px rgba(33,28,49,.10);
}
@media (prefers-color-scheme: dark) {
  :root {
    /* Only the page/card surface and text switch to dark — nav bar, the "+ Add"
       button (success/teal), active-tab (primary/violet) and every other accent
       stay exactly the same color as light mode, per explicit request. */
    --pg:#0f1117; --card:#1a1d27; --bd:#2a2e3d; --bd-strong:#3d4257;
    --t1:#f1f2f6; --t2:#a8adc0; --tm:#767c93;
    --sh:0 1px 3px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.35);
    --sh-md:0 10px 28px rgba(0,0,0,.5);
  }
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--pg); color: var(--t1); line-height: 1.5; -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); }

/* ── Top nav ─────────────────────────────────────────────────────────── */
.topnav {
  background: linear-gradient(180deg, var(--nav-bg2), var(--nav-bg)); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 56px; box-shadow: var(--sh);
}
.topnav-left { display: flex; align-items: center; gap: 26px; height: 100%; }
.topnav .brand { font-weight: 700; font-size: 1.02rem; letter-spacing: -.01em; }
.topnav .navtab {
  color: #cbd5e1; text-decoration: none; font-size: .87rem; font-weight: 500;
  height: 100%; display: flex; align-items: center; padding: 0 4px; transition: color .15s;
}
.topnav .navtab:hover { color: #fff; }
.topnav .navtab.active {
  color: #fff; font-weight: 600; background: var(--primary);
  border-radius: 6px; padding: 7px 16px; height: auto;
}
.topnav-right { display: flex; align-items: center; gap: 16px; }
.topsearch input {
  border: 1px solid rgba(255,255,255,.15); border-radius: var(--r-sm); padding: 7px 12px; font-size: .85rem;
  width: 220px; background: rgba(255,255,255,.08); color: #fff;
}
.topsearch input::placeholder { color: #94a3b8; }
.topsearch input:focus { outline: none; background: rgba(255,255,255,.14); }
.topnav-user { font-size: .85rem; color: #cbd5e1; }
.topnav-logout { color: #cbd5e1; text-decoration: none; font-size: .85rem; }
.topnav-logout:hover { color: #fff; }
.role-badge {
  font-size: .7rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 20px; line-height: 1.4;
}
.role-badge.role-admin { background: rgba(255,255,255,.16); color: #fff; }
.role-badge.role-user { background: rgba(255,255,255,.08); color: #cbd5e1; }

main { padding: 24px; max-width: 1400px; margin: 0 auto; }

.card {
  background: var(--card); border: 1px solid var(--bd); border-radius: var(--r);
  box-shadow: var(--sh); padding: 22px; margin-bottom: 20px;
}
h1 { font-size: 1.4rem; margin-bottom: 16px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: .92rem; margin: 14px 0 8px; font-weight: 600; color: var(--t1); }
h2:first-child { margin-top: 0; }
table { width: 100%; border-collapse: collapse; font-size: .87rem; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--bd); white-space: nowrap; }
th { color: var(--t2); font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; background: var(--pg); font-weight: 600; }
tbody tr:hover { background: var(--primary-soft); }
a.row-link { color: var(--t1); text-decoration: none; font-weight: 600; }
a.row-link:hover { color: var(--primary); text-decoration: underline; }
tbody tr:last-child td { border-bottom: none; }
.table-card { padding: 0; overflow-x: auto; margin-bottom: 20px; }
.table-card table { margin: 0; }

/* ── Quick-filter tabs ───────────────────────────────────────────────── */
.quick-filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.qf-tab {
  display: inline-block; padding: 8px 16px; border-radius: 20px; font-size: .83rem; font-weight: 500;
  text-decoration: none; color: var(--t2); background: var(--card); border: 1px solid var(--bd); transition: all .15s;
}
.qf-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.qf-tab:hover:not(.active) { border-color: var(--primary); color: var(--primary); }

/* ── Toolbar (pagination / page size / total / filter) ──────────────── */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-wrap: wrap; gap: 12px;
}
.toolbar-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pagination { display: flex; gap: 4px; align-items: center; font-size: .85rem; }
.page-num {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; border-radius: var(--r-sm); text-decoration: none;
  color: var(--t2); border: 1px solid var(--bd); background: var(--card); font-size: .84rem; transition: all .15s;
}
.page-num.current { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.page-num.ellipsis { border: none; background: none; color: var(--tm); }
.page-num:hover:not(.current) { border-color: var(--primary); color: var(--primary); }
.page-size-form select {
  border: 1px solid var(--bd); border-radius: var(--r-sm); padding: 6px 8px;
  font-size: .85rem; background: var(--card); color: var(--t1);
}
.badge.total-badge {
  background: var(--primary-soft); color: var(--primary); border: none; font-weight: 600;
  padding: 6px 14px; border-radius: 20px; font-size: .8rem;
}
.toolbar-right { position: relative; display: flex; align-items: center; gap: 10px; }
.filter-toggle summary {
  list-style: none; cursor: pointer; font-size: .85rem; padding: 7px 14px;
  border: 1px solid var(--bd); border-radius: var(--r-sm); background: var(--card); color: var(--t1);
}
.filter-toggle summary::-webkit-details-marker { display: none; }
.filter-panel {
  position: absolute; right: 0; top: 42px; z-index: 10; width: 260px;
  background: var(--card); border: 1px solid var(--bd); border-radius: var(--r);
  box-shadow: var(--sh-md); padding: 16px;
}
.filter-panel .fg { margin-bottom: 12px; }
.filter-panel label { display: block; font-size: .72rem; font-weight: 700; text-transform: uppercase; color: var(--t2); margin-bottom: 4px; }
.filter-panel input, .filter-panel select {
  width: 100%; border: 1px solid var(--bd); border-radius: var(--r-sm); padding: 7px 9px;
  font-size: .85rem; background: var(--pg); color: var(--t1);
}
.filter-panel button {
  border: none; background: var(--primary); color: #fff; border-radius: var(--r-sm);
  padding: 8px 16px; font-size: .85rem; cursor: pointer; width: 100%; font-weight: 600;
}
.filter-panel button:hover { background: var(--primary-dark); }

/* ── Buttons (semantic, not arbitrary) ──────────────────────────────── */
.btn {
  display: inline-block; text-decoration: none; font-size: .8rem; font-weight: 600;
  padding: 7px 15px; border-radius: var(--r-sm); color: #fff; border: none; cursor: pointer;
  transition: filter .15s, box-shadow .15s;
}
.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); }
.btn-success:hover { background: var(--success-dark); }
.btn-warning { background: var(--warning); }
.btn-warning:hover { background: var(--warning-dark); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-dark); }
.btn-save-lead {
  background: var(--success); color: #fff; border: none; font-size: .88rem; font-weight: 600;
  padding: 10px 30px; border-radius: var(--r-sm); cursor: pointer; display: block; margin: 14px auto 0;
}
.btn-save-lead:hover { background: var(--success-dark); }

.meta { color: var(--t2); font-size: .85rem; margin-bottom: 4px; }
.badge {
  display: inline-block; background: var(--pg); border: 1px solid var(--bd);
  border-radius: 20px; padding: 3px 11px; font-size: .75rem; color: var(--t2); font-weight: 500;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 16px; }
@media (max-width: 720px) { .grid-3 { grid-template-columns: 1fr 1fr; } }

/* ── Lead detail: info panel + pipeline + tabs ──────────────────────── */
.lead-layout { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
.info-card .avatar {
  width: 72px; height: 72px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  margin-bottom: 14px;
}
.info-card h3 { font-size: 1.15rem; margin-bottom: 4px; font-weight: 700; }
.info-card .associate { color: var(--t2); font-size: .83rem; margin-bottom: 10px; }
.status-badge {
  display: inline-block; background: var(--success); color: #fff; font-size: .72rem;
  font-weight: 600; padding: 4px 12px; border-radius: 20px; margin-bottom: 16px;
}
.info-card .info-row { font-size: .86rem; margin-bottom: 12px; }
.info-card .info-row .label { color: var(--tm); display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }

.pipeline { display: flex; margin-bottom: 18px; flex-wrap: wrap; gap: 6px; }
.pipeline-step {
  padding: 8px 18px; font-size: .8rem; font-weight: 500; background: var(--card); border: 1px solid var(--bd);
  color: var(--t2); border-radius: 20px;
}
.pipeline-step.done { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.pipeline-step.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 700; }

.quick-actions { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }

.detail-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--bd); margin-bottom: 20px; flex-wrap: wrap; }
.detail-tabs a {
  padding: 10px 16px; font-size: .85rem; font-weight: 500; text-decoration: none; color: var(--t2);
  border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s;
}
.detail-tabs a:hover { color: var(--primary); }
.detail-tabs a.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }

.info-table { width: 100%; border-collapse: collapse; margin-bottom: 20px; border: 1px solid var(--bd); border-radius: var(--r); overflow: hidden; }
.info-table th {
  width: 170px; text-align: left; background: var(--pg); color: var(--t2); font-size: .72rem;
  text-transform: uppercase; letter-spacing: .04em; padding: 11px 14px; border-bottom: 1px solid var(--bd); font-weight: 600;
}
.info-table td { padding: 11px 14px; border-bottom: 1px solid var(--bd); font-size: .87rem; }
.info-table tr:last-child th, .info-table tr:last-child td { border-bottom: none; }
.field-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--bd); font-size: .87rem; }
.field-row .label { color: var(--t2); }
.empty { color: var(--tm); font-size: .85rem; padding: 16px 0; text-align: center; }
.back-link { display: inline-block; margin-bottom: 14px; font-size: .85rem; color: var(--primary); text-decoration: none; font-weight: 500; }
.back-link:hover { text-decoration: underline; }
.section-actions { float: right; }
.section-actions a { font-size: .8rem; }
.flash { background: var(--primary-soft); color: var(--primary); font-size: .85rem; padding: 12px 16px; border-radius: var(--r-sm); margin-bottom: 18px; font-weight: 500; }

/* ── Forms ───────────────────────────────────────────────────────────── */
.form .fg { margin-bottom: 10px; }
.form label { display: block; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--t2); margin-bottom: 4px; }
.form input, .form select, .form textarea {
  width: 100%; background: var(--card); border: 1px solid var(--bd-strong); color: var(--t1);
  font-size: .87rem; padding: 7px 10px; border-radius: var(--r-sm); font-family: inherit; transition: border-color .15s, box-shadow .15s;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.form .checkbox-fg label { display: flex; align-items: center; gap: 8px; text-transform: none; font-weight: 400; font-size: .85rem; }
.form .checkbox-fg input { width: auto; }
.form button {
  background: var(--success); border: none; color: #fff; font-size: .85rem; font-weight: 600;
  padding: 9px 22px; border-radius: var(--r-sm); cursor: pointer; transition: background .15s; margin-top: 4px;
}
.form button:hover { background: var(--primary-dark); }
.row-actions { display: flex; gap: 6px; align-items: center; }
.row-actions form { display: inline; margin: 0; }

/* Icon action buttons (view/edit/delete) - compact, so list tables stop needing a
   wide text column just for actions and contribute less to horizontal scroll. */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: var(--r-sm); border: 1px solid var(--bd);
  background: var(--card); cursor: pointer; padding: 0; transition: all .15s;
}
.icon-btn svg { width: 15px; height: 15px; stroke: var(--t2); fill: none; stroke-width: 2; }
.icon-btn:hover { border-color: var(--primary); background: var(--primary-soft); }
.icon-btn:hover svg { stroke: var(--primary); }
.icon-btn.icon-danger:hover { border-color: var(--danger); background: rgba(220,38,38,.08); }
.icon-btn.icon-danger:hover svg { stroke: var(--danger); }

/* Truncate long free-text table cells with an ellipsis; the full value is still on
   the title attribute (hover tooltip), so nothing is actually lost. */
td.truncate { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.truncate-lg { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Choices.js tag-multiselect skin (Part C) ───────────────────────── */
.choices { font-size: .9rem; }
.choices__inner {
  background: var(--card) !important; border: 1px solid var(--bd-strong) !important;
  border-radius: var(--r-sm) !important; min-height: 42px; padding: 6px 8px !important;
}
.choices__list--multiple .choices__item {
  background: var(--primary) !important; border: none !important; border-radius: 20px !important;
  padding: 4px 10px !important; font-size: .82rem !important; color: #fff !important;
}
/* The remove-item "×" is a dark SVG in Choices' default theme — invisible on our
   colored pill background in both themes, not just dark mode. Invert it to white. */
.choices__list--multiple .choices__item .choices__button {
  filter: brightness(0) invert(1); opacity: .7;
  border-inline-start-color: rgba(255,255,255,.35) !important;
}
.choices__list--multiple .choices__item .choices__button:hover { opacity: 1; }
.choices__list--dropdown, .choices__list[aria-expanded] {
  background: var(--card) !important; border-color: var(--bd) !important; color: var(--t1) !important;
}
.choices__list--dropdown .choices__item--selectable { color: var(--t1) !important; }
.choices__list--dropdown .choices__item--selectable.is-highlighted {
  background: var(--primary-soft) !important; color: var(--t1) !important;
}
.choices__input { background: var(--card) !important; color: var(--t1) !important; }
.choices__input::placeholder { color: var(--tm) !important; }
.choices__placeholder { color: var(--tm) !important; opacity: 1 !important; }
/* Default theme draws the dropdown caret as a CSS border-triangle in a fixed dark
   color — invisible against a dark .choices__inner. */
.choices[data-type*="select-multiple"] .choices__inner:after,
.choices[data-type*="select-one"] .choices__inner:after {
  border-color: var(--t2) transparent transparent !important;
}

/* ── Theme customizer ────────────────────────────────────────────────── */
.theme-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 200;
  width: 48px; height: 48px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--primary); color: #fff; font-size: 1.2rem;
  box-shadow: var(--sh-md); display: flex; align-items: center; justify-content: center;
  transition: transform .15s;
}
.theme-fab:hover { transform: scale(1.07); }
.theme-panel {
  position: fixed; right: 22px; bottom: 82px; z-index: 200;
  width: 260px; background: var(--card); border: 1px solid var(--bd);
  border-radius: var(--r); box-shadow: var(--sh-md); padding: 16px;
  display: none;
}
.theme-panel.open { display: block; }
.theme-panel h3 { font-size: .95rem; margin-bottom: 10px; color: var(--t1); }
.theme-panel .swatch-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.theme-panel .swatch-row label { font-size: .84rem; color: var(--t2); }
.theme-panel .swatch-row input[type="color"] {
  width: 40px; height: 28px; border: 1px solid var(--bd-strong); border-radius: 6px;
  padding: 0; cursor: pointer; background: none;
}
.theme-panel .theme-actions {
  display: flex; gap: 8px; margin-top: 12px;
}
.theme-panel .theme-actions button {
  flex: 1; padding: 7px 0; border-radius: var(--r-sm); border: 1px solid var(--bd-strong);
  background: var(--pg); color: var(--t1); font-size: .82rem; cursor: pointer;
}
.theme-panel .theme-actions button:hover { border-color: var(--primary); }
.theme-panel .theme-presets { display: flex; gap: 6px; margin-bottom: 12px; }
.theme-panel .preset-dot {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--bd);
  cursor: pointer; padding: 0;
}
.theme-panel .preset-dot:hover { border-color: var(--t2); }

/* ── Info dialog (full Feedback/Comment popup for truncated table cells) ─── */
.info-dialog {
  border: 1px solid var(--bd); border-radius: var(--r); box-shadow: var(--sh-md);
  padding: 20px; width: 90%; max-width: 480px; background: var(--card); color: var(--t1);
  /* The global `* { margin: 0 }` reset strips the UA stylesheet's default
     `dialog:modal { margin: auto }`, which is what centers it - restore it. */
  position: fixed; inset: 0; margin: auto;
}
.info-dialog::backdrop { background: rgba(0,0,0,.45); }
.info-dialog-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.info-dialog-head h3 { font-size: 1rem; font-weight: 700; }
.info-dialog-field { margin-bottom: 14px; }
.info-dialog-field:last-child { margin-bottom: 0; }
.info-dialog-field .label {
  display: block; font-size: .7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--t2); margin-bottom: 4px;
}
.info-dialog-field p { font-size: .9rem; white-space: pre-wrap; word-break: break-word; }

/* Cells that open the info dialog on click */
td.cell-popup { cursor: pointer; }
td.cell-popup:hover { color: var(--primary); text-decoration: underline; text-decoration-style: dotted; }
