/* Cozart Consulting backend: tokens, app shell and the component styles that Bootstrap does not provide.
   Bootstrap 5 and Font Awesome 6 are vendored in /lib. Colors below the top bar come from Bootstrap's own
   variables so light and dark mode need no overrides. See standards-ui.md. */

:root {
  --topnav-bg: #1e2530;
  --topnav-text: #adb5bd;
  --topnav-active-bg: rgba(13, 110, 253, 0.85);
  --topnav-hover-bg: rgba(255, 255, 255, 0.08);
  --topnav-height: 52px;

  /* Names used by the component styles carried over from the earlier stylesheet, mapped onto Bootstrap. */
  --bg: var(--bs-tertiary-bg);
  --bg-alt: var(--bs-secondary-bg);
  --surface: var(--bs-body-bg);
  --border: var(--bs-border-color);
  --text: var(--bs-body-color);
  --muted: var(--bs-secondary-color);
  --accent: var(--bs-primary);
  --grad: var(--bs-primary);
  --radius: 0.5rem;
  --radius-sm: 0.375rem;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.1);
  --danger: var(--bs-danger-text-emphasis);
  --danger-bg: var(--bs-danger-bg-subtle);
  --danger-bd: var(--bs-danger-border-subtle);
}
html { font-size: 14px; }
@media (min-width: 768px) { html { font-size: 16px; } }

/* Links read as links by color; underline appears on hover, as before. */
a { text-decoration: none; }
a:hover { text-decoration: underline; }

/* App shell: only main scrolls. height 100% rather than 100vh, which iOS home-screen apps get wrong. */
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bs-tertiary-bg);
}
main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
}
.public-body main { display: flex; flex-direction: column; }

#topnav {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  height: calc(var(--topnav-height) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  background: var(--topnav-bg);
  color: var(--topnav-text);
}
.topnav-brand {
  display: inline-flex; align-items: center; gap: 8px;
  margin-right: 12px; color: #fff; font-weight: 600; white-space: nowrap;
}
.topnav-brand:hover { color: #fff; text-decoration: none; }
#topnav-links { display: none; align-items: center; gap: 2px; min-width: 0; }
.desktop-only, .wide-only { display: none; }
.below-desktop { display: inline-flex; }
@media (min-width: 1300px) {
  #topnav-links { display: flex; }
  .desktop-only { display: inline-flex; }
  .below-desktop, #mobile-nav { display: none !important; }
}
@media (min-width: 1500px) { .wide-only { display: inline; } }
#topnav .nav-link, #mobile-nav .nav-link {
  display: flex; align-items: center; height: 36px; padding: 0 10px;
  border-radius: 6px; color: var(--topnav-text); font-size: 0.9rem; white-space: nowrap;
}
#topnav .nav-link:hover, #mobile-nav .nav-link:hover { background: var(--topnav-hover-bg); color: #fff; text-decoration: none; }
#topnav .nav-link.active, #mobile-nav .nav-link.active { background: var(--topnav-active-bg); color: #fff; }
.nav-icon { width: 1.15rem; margin-right: 6px; text-align: center; }
.topnav-sep { flex: 1 1 auto; }
.topnav-user { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.85rem; }
.topnav-divider { width: 1px; height: 22px; margin: 0 6px; background: rgba(255, 255, 255, 0.15); }
.topnav-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border: 0; border-radius: 6px;
  background: transparent; color: var(--topnav-text); cursor: pointer;
}
.topnav-btn:hover { background: var(--topnav-hover-bg); color: #fff; }
.topnav-btn:focus-visible, #topnav .nav-link:focus-visible {
  outline: 0; box-shadow: 0 0 0 .1rem #fff, 0 0 0 .25rem #258cfb;
}

#mobile-nav { flex: 0 0 auto; max-height: 70%; overflow-y: auto; background: var(--topnav-bg); border-top: 1px solid rgba(255, 255, 255, 0.08); }
#mobile-nav nav { display: flex; flex-direction: column; padding: 8px 12px; gap: 2px; }
.mobile-nav-account {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-top: 1px solid rgba(255, 255, 255, 0.08); color: var(--topnav-text); font-size: 0.85rem;
}

.btn:focus-visible, .form-control:focus, .form-select:focus { box-shadow: 0 0 0 .1rem #fff, 0 0 0 .25rem #258cfb; }

/* Section pages (Setup): a link column beside the content, a horizontal strip on phones. */
.page-sidebar { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 1.5rem; }
.page-sidebar a {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 6px;
  color: var(--bs-secondary-color); white-space: nowrap;
}
.page-sidebar a:hover { background: var(--bs-secondary-bg); color: var(--bs-body-color); text-decoration: none; }
.page-sidebar a.active { background: var(--bs-primary); color: #fff; }
.page-sidebar i { width: 1.15rem; text-align: center; }
@media (min-width: 992px) {
  .setup-wrap:has(> .page-sidebar) { display: grid; grid-template-columns: 200px minmax(0, 1fr); column-gap: 2rem; align-content: start; max-width: 1100px; }
  .setup-wrap:has(> .page-sidebar) > .page-sidebar { grid-column: 1; grid-row: 1 / span 99; flex-direction: column; overflow: visible; margin-bottom: 0; align-self: start; }
  .setup-wrap:has(> .page-sidebar) > :not(.page-sidebar) { grid-column: 2; }
}

/* Sign-in and first-run pages */
.public-body .auth-main { flex: 1; display: flex; align-items: center; justify-content: center; }
.auth-card { width: 100%; max-width: 400px; padding: 2rem; background: var(--bs-body-bg); border: 1px solid var(--bs-border-color); border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.auth-card .btn-primary { width: 100%; }
.auth-card h1 { font-size: 1.6rem; margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); margin: 0 0 1.5rem; }
.unlock-details { margin-top: 1.5rem; }
.unlock-details summary { cursor: pointer; color: var(--muted); font-size: 0.875rem; }


/* Form fields */
.field { margin-bottom: 1rem; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 0.35rem; text-transform: uppercase; }
.field textarea { min-height: 110px; resize: vertical; }
.field .check { display: flex; align-items: center; gap: 0.6rem; font-size: 0.95rem; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text); cursor: pointer; }
.field .check input { width: auto; margin: 0; cursor: pointer; }
.field .hint, .hint, .card-hint { color: var(--muted); font-size: 0.85rem; margin: 0.4rem 0 0; line-height: 1.55; }
.field span[data-valmsg-for] { display: block; color: var(--bs-danger); font-size: 0.83rem; margin-top: 0.25rem; }
.inline { width: auto; }

/* Cards are Bootstrap's; the earlier markup puts content straight into them. */
.card { padding: 1.25rem 1.5rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card h2 { font-size: 1.05rem; margin-bottom: 0.4rem; }
.card > .hint, .card > .card-hint { margin-bottom: 1rem; }

/* --- Page content wrappers ------------------------------------------------ */
/* Settings / setup (narrow, stacked cards) */
.setup-wrap {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 48px 80px;
}
.setup-wrap > h1 { font-size: 1.875rem; margin-bottom: 4px; }

/* List pages (clients, companies) - full available width */
.data-page {
  padding: 36px 40px 80px;
}

/* CRM record pages (client/company detail) - full available width */
.crm-layout {
  padding: 28px 40px 80px;
}

/* Dashboard */
.dashboard-page {
  padding: 40px 40px 80px;
}

/* --- Documents -------------------------------------------------------------- */
@font-face {
  font-family: "Dancing Script";
  src: url("/fonts/DancingScript-Regular.ttf") format("truetype");
  font-display: swap;
}
.doc-preview { line-height: 1.65; }
.doc-preview h1, .doc-preview h2, .doc-preview h3 { margin-top: 1.2em; }
.doc-preview-signature,
.doc-sign-box {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 16px 0;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.9rem;
}
.doc-sign-name-input {
  font-family: "Dancing Script", cursive;
  font-size: 2rem;
  width: 100%;
  border: none;
  border-bottom: 2px solid var(--border);
  background: transparent;
  padding: 4px 2px;
}
.doc-sign-name-input:focus { outline: none; border-bottom-color: var(--accent); }
.doc-sign-preview-label { font-size: 0.75rem; color: var(--muted); margin-top: 6px; }

/* --- Stat grid ------------------------------------------------------------ */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.stat {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
}
.stat .num { font-size: 2.25rem; font-weight: 800; line-height: 1; color: var(--accent); }
.stat .label { color: var(--muted); font-size: 0.82rem; margin-top: 6px; font-weight: 500; }

/* --- Code ----------------------------------------------------------------- */
code {
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 0.82em;
  background: var(--bg-alt);
  padding: 2px 6px;
  border-radius: 4px;
}
code.snippet {
  display: block;
  background: #0f172a;
  color: #e2e8f0;
  padding: 18px 20px;
  border-radius: var(--radius-sm);
  font-family: "JetBrains Mono", monospace;
  font-size: 0.83rem;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.7;
}

/* --- Misc helpers --------------------------------------------------------- */
.sub, .page-sub { color: var(--muted); font-size: 0.92rem; margin: 0 0 24px; }
.muted-link { color: var(--muted); font-size: 0.88rem; }
.muted-link a { color: var(--muted); }
.muted-link a:hover { color: var(--text); }
.td-name  { font-weight: 600; }
.td-muted { color: var(--muted); }
.td-link  { color: var(--accent); }
.td-link:hover { text-decoration: underline; }

/* --- Tables (settings / simple) ------------------------------------------ */
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; padding: 11px 16px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  font-size: 0.76rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
table.data td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 0.93rem; }
table.data tbody tr:last-child td { border-bottom: 0; }

/* --- Page header (back link + large title + action buttons) --------------- */
.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding-bottom: 20px; margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
  gap: 20px; flex-wrap: wrap;
}
.page-header-left { display: flex; flex-direction: column; gap: 5px; }
.page-header h1 { font-size: 1.875rem; }
.page-back {
  color: var(--muted); font-size: 0.85rem; font-weight: 500;
  display: inline-flex; align-items: center; gap: 5px;
}
.page-back:hover { color: var(--text); text-decoration: none; }
.page-header-actions { display: flex; gap: 10px; align-items: center; padding-bottom: 4px; }

/* --- List page toolbar (search + new button) ------------------------------ */
.data-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; gap: 16px; flex-wrap: wrap;
}
.data-toolbar-left { display: flex; align-items: center; gap: 14px; }
.data-toolbar-left h1 { font-size: 1.875rem; }
.data-count {
  font-size: 0.8rem; color: var(--muted); font-weight: 600;
  background: var(--bg-alt); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 999px;
}
.data-toolbar-right { display: flex; align-items: center; gap: 10px; }

.search-box { position: relative; display: flex; align-items: center; }
.search-box-icon { position: absolute; left: 11px; pointer-events: none; color: var(--muted); width: 16px; height: 16px; }
.search-input {
  padding: 10px 14px 10px 36px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: 0.92rem;
  background: var(--surface); color: var(--text);
  width: 260px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb),0.12); }

/* --- Enterprise list table (clickable rows) ------------------------------- */
.data-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
table.data-ent { width: 100%; border-collapse: collapse; }
table.data-ent th {
  text-align: left; padding: 12px 20px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  font-size: 0.72rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em; white-space: nowrap;
}
table.data-ent td {
  padding: 15px 20px; border-bottom: 1px solid var(--border);
  font-size: 0.93rem; vertical-align: middle;
}
table.data-ent tbody tr:last-child td { border-bottom: 0; }
table.data-ent tbody tr { cursor: pointer; transition: background 0.1s; }
table.data-ent tbody tr:hover { background: var(--bs-tertiary-bg); }

.data-empty { padding: 64px 24px; text-align: center; color: var(--muted); }
.data-empty p { margin: 0 0 6px; font-size: 0.95rem; }
.data-empty .hint { font-size: 0.87rem; margin: 0; }

/* --- Modal/dialog --------------------------------------------------------- */
dialog.app-dialog {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 480px; width: calc(100% - 40px);
}
dialog.app-dialog::backdrop { background: rgba(8,12,22,0.5); backdrop-filter: blur(4px); }
.app-dialog-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.app-dialog-head h2 { font-size: 1.1rem; }
.app-dialog-close {
  background: none; border: 0;
  font-size: 1.5rem; line-height: 1; cursor: pointer;
  color: var(--muted); padding: 2px 8px; border-radius: 6px;
}
.app-dialog-close:hover { background: var(--bg); color: var(--text); }
.app-dialog-body { padding: 22px 24px; }
.app-dialog-body .field { margin-bottom: 16px; }
.app-dialog-body .field:last-child { margin-bottom: 0; }
.app-dialog-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 24px; border-top: 1px solid var(--border);
  background: var(--bg);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* --- CRM record layout ---------------------------------------------------- */
.crm-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding-bottom: 20px; margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
  gap: 20px; flex-wrap: wrap;
}
.crm-back {
  color: var(--muted); font-size: 0.87rem; font-weight: 500;
  display: inline-flex; align-items: center; gap: 5px; margin-bottom: 6px;
}
.crm-back:hover { color: var(--text); text-decoration: none; }
.crm-header-left { display: flex; flex-direction: column; }
.crm-header-title { font-size: 1.875rem; font-weight: 800; }
.crm-header-actions { display: flex; gap: 10px; align-items: center; padding-bottom: 4px; }

/* Two-column record body */
.crm-body {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 24px;
  align-items: start;
}
/* Grid items refuse to shrink below their content's min size by default, so a wide
   table inside the tabs card would push the whole column (details card included) past
   the viewport instead of scrolling inside its .table-scroll wrapper. */
.crm-body > * { min-width: 0; }
.crm-sidebar {
  display: flex; flex-direction: column; gap: 16px;
  position: sticky; top: 24px;
}

/* Identity card (gradient header + form) */
.crm-contact-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.crm-contact-head {
  background: var(--grad);
  padding: 24px 24px 20px;
  display: flex; align-items: center; gap: 18px;
}
.crm-avatar {
  width: 56px; height: 56px; border-radius: 50%; flex-shrink: 0;
  background: rgba(255,255,255,0.18); border: 2px solid rgba(255,255,255,0.4);
  color: #fff; font-size: 1.4rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.crm-avatar.square { border-radius: 14px; }
.crm-contact-head-info h2 { color: #fff; font-size: 1.15rem; font-weight: 700; word-break: break-word; }
.crm-contact-head-info .crm-meta-pill { color: rgba(255,255,255,0.6); font-size: 0.82rem; margin-top: 4px; }

.crm-form-fields { padding: 20px 22px 0; }
.crm-field { margin-bottom: 14px; }
.crm-field:last-child { margin-bottom: 0; }
.crm-field label {
  display: block; font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 5px;
}
.crm-field input,
.crm-field select,
.crm-field textarea {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: 0.92rem; background: var(--bg); color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.crm-field input:focus,
.crm-field select:focus,
.crm-field textarea:focus {
  outline: none; border-color: var(--accent);
  background: var(--surface); box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb),0.1);
}
.crm-field textarea { min-height: 88px; resize: vertical; }
.crm-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.crm-form-footer { padding: 14px 22px 20px; }

/* Right column (activity / clients list) */
.crm-activity { display: flex; flex-direction: column; gap: 12px; }

/* Note composer */
.note-composer {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.note-composer-body { padding: 16px 20px 0; }
.note-composer textarea {
  width: 100%; border: 0; padding: 0;
  font: inherit; font-size: 0.95rem; background: transparent; color: var(--text);
  resize: none; outline: none; min-height: 80px; line-height: 1.6; display: block;
}
.note-composer-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 20px; border-top: 1px solid var(--border); margin-top: 12px; background: var(--bg);
}
.note-subject-inp {
  border: 0; background: transparent; font: inherit; font-size: 0.88rem;
  color: var(--text); outline: none; flex: 1; min-width: 0; padding: 0;
}
.note-subject-inp::placeholder { color: var(--border); }
.btn-add-note {
  padding: 7px 16px; background: var(--grad); color: #fff; border: 0;
  border-radius: var(--radius-sm); font: inherit; font-size: 0.87rem; font-weight: 600;
  cursor: pointer; flex-shrink: 0; transition: filter 0.15s;
}
.btn-add-note:hover { filter: brightness(1.08); }

/* Timeline */
.timeline-empty {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 40px; text-align: center; color: var(--muted); font-size: 0.92rem;
}
.timeline-entry {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px;
}
.timeline-entry-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.timeline-entry-left { display: flex; align-items: center; gap: 11px; flex: 1; min-width: 0; }
.timeline-icon { width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.timeline-icon.t-note { background: var(--bs-primary-bg-subtle); color: var(--bs-primary-text-emphasis); }
.timeline-icon.t-form { background: var(--bs-success-bg-subtle); color: var(--bs-success-text-emphasis); }
.timeline-icon.t-fail { background: var(--bs-danger-bg-subtle); color: var(--bs-danger-text-emphasis); }
.timeline-subject { font-weight: 600; font-size: 0.92rem; }
.timeline-time { color: var(--muted); font-size: 0.8rem; white-space: nowrap; flex-shrink: 0; }
.timeline-body { color: var(--muted); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.6; margin-top: 10px; }
.timeline-del {
  background: none; border: 1px solid transparent; border-radius: 6px;
  cursor: pointer; color: transparent; padding: 3px 8px; font: inherit; font-size: 0.82rem;
  transition: all 0.12s; flex-shrink: 0;
}
.timeline-entry:hover .timeline-del { color: var(--muted); border-color: var(--border); }
.timeline-del:hover { border-color: var(--danger-bd) !important; color: var(--danger) !important; background: var(--danger-bg); }

/* Company clients right-column list */
.crm-clients-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.crm-clients-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  font-size: 0.76rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--muted); background: var(--bg);
}
.crm-client-row {
  display: flex; align-items: center; padding: 16px 20px;
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s;
  text-decoration: none;
}
.crm-client-row:last-child { border-bottom: 0; }
.crm-client-row:hover { background: var(--bs-tertiary-bg); text-decoration: none; }
.crm-client-row-name { font-weight: 600; font-size: 0.93rem; color: var(--text); flex: 1; }
.crm-client-row-meta { color: var(--muted); font-size: 0.85rem; }
.crm-clients-empty { padding: 36px 20px; text-align: center; color: var(--muted); font-size: 0.9rem; line-height: 1.6; }

/* --- Dashboard ------------------------------------------------------------ */
.dashboard-welcome { margin-bottom: 32px; }
.dashboard-welcome h1 { font-size: 2rem; font-weight: 800; margin-bottom: 6px; }
.dashboard-welcome p { color: var(--muted); font-size: 0.95rem; margin: 0; }

/* Two-column dashboard layout */
.dashboard-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  align-items: start;
}

/* Quick-nav card column */
.dashboard-quicknav { display: flex; flex-direction: column; gap: 10px; }
.dash-nav-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 14px;
  cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s;
  text-decoration: none; color: var(--text);
}
.dash-nav-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 20px rgba(var(--bs-primary-rgb),0.1);
  text-decoration: none; color: var(--text);
}
.dash-nav-card-icon {
  width: 40px; height: 40px; flex-shrink: 0;
  background: rgba(var(--bs-primary-rgb),0.08); border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.dash-nav-card > div:nth-child(2) { flex: 1; min-width: 0; }
.dash-nav-card-title { font-size: 0.95rem; font-weight: 600; line-height: 1.3; }
.dash-nav-card-sub { font-size: 0.8rem; color: var(--muted); margin-top: 1px; }
.dash-nav-card-arrow { color: var(--border); flex-shrink: 0; transition: color 0.15s; }
.dash-nav-card:hover .dash-nav-card-arrow { color: var(--accent); }

/* Notification panel */
.notif-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.notif-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.notif-panel-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.85rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted);
}
.notif-panel-viewall {
  font-size: 0.82rem; font-weight: 500; color: var(--accent);
}
.notif-panel-viewall:hover { text-decoration: underline; }

/* Feed items */
.notif-feed { display: flex; flex-direction: column; }
.notif-empty {
  padding: 48px 24px;
  text-align: center; color: var(--muted);
  display: flex; flex-direction: column; align-items: center;
}
.notif-empty p { margin: 0 0 4px; font-size: 0.92rem; }
.notif-empty .hint { font-size: 0.84rem; margin: 0; }

.notif-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.notif-item:last-child { border-bottom: 0; }
.notif-item:hover { background: var(--bs-tertiary-bg); }

.notif-icon {
  width: 32px; height: 32px; flex-shrink: 0;
  background: var(--bs-primary-bg-subtle); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--bs-primary-text-emphasis);
}
.notif-content { flex: 1; min-width: 0; }
.notif-top {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 3px; flex-wrap: wrap;
}
.notif-form-name { font-weight: 600; font-size: 0.92rem; }
.notif-new-pill {
  font-size: 0.68rem; font-weight: 700; padding: 1px 7px;
  border-radius: 999px; background: var(--bs-primary-bg-subtle); color: var(--bs-primary-text-emphasis);
  text-transform: uppercase; letter-spacing: 0.06em; flex-shrink: 0;
}
.notif-time { font-size: 0.8rem; color: var(--muted); margin-left: auto; white-space: nowrap; }
.notif-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.notif-client-link { font-size: 0.87rem; font-weight: 500; color: var(--accent); }
.notif-client-link:hover { text-decoration: underline; }
.notif-submitter { font-size: 0.87rem; color: var(--text); font-weight: 500; }
.notif-email { font-size: 0.87rem; color: var(--muted); }
.notif-anon { font-size: 0.87rem; color: var(--muted); font-style: italic; }
.notif-sep { color: var(--border); font-size: 0.9rem; }
.notif-open {
  flex-shrink: 0; width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px; color: var(--border);
  transition: background 0.12s, color 0.12s;
}
.notif-item:hover .notif-open { color: var(--muted); background: var(--bg-alt); }
.notif-open:hover { color: var(--accent) !important; background: var(--bs-primary-bg-subtle) !important; }

/* Failed payments panel - sits above the two-column layout, full width */
.failed-payments-panel { margin-bottom: 24px; }
.failed-payment-icon { background: var(--bs-danger-bg-subtle); color: var(--bs-danger-text-emphasis); }
.failed-pill-warn { background: var(--bs-warning-bg-subtle); color: var(--bs-warning-text-emphasis); }
.failed-pill { background: var(--bs-danger-bg-subtle); color: var(--bs-danger-text-emphasis); }
.failed-payment-item.threshold-reached { background: var(--bs-danger-bg-subtle); }
.failed-payment-item.threshold-reached:hover { background: var(--bs-danger-bg-subtle); }
.billing-off-pill { flex-shrink: 0; }

/* --- Reports --------------------------------------------------------------- */
.report-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 28px;
}
.report-tabs a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 11px 18px;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.12s;
  white-space: nowrap;
}
.report-tabs a:hover { color: var(--text); text-decoration: none; }
.report-tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* Revenue stat cards */
.report-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.report-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
}
.report-stat-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 8px;
}
.report-stat-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  margin-bottom: 6px;
}
.report-stat-sub { font-size: 0.82rem; color: var(--muted); }
.report-yoy { font-weight: 600; }
.report-yoy.up   { color: var(--bs-success-text-emphasis); }
.report-yoy.down { color: var(--danger); }

/* Report sections */
.report-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  overflow: hidden;
}
.report-section-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.report-section-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}
.report-section-sub { font-size: 0.82rem; color: var(--muted); }
.report-empty { padding: 32px 24px; text-align: center; color: var(--muted); font-size: 0.9rem; }

/* Bar chart */
.bar-chart { padding: 20px 24px; display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 120px; align-items: center; gap: 14px; }
.bar-label { font-size: 0.8rem; color: var(--muted); text-align: right; white-space: nowrap; }
.bar-track { background: var(--bg-alt); border-radius: 6px; height: 32px; overflow: hidden; }
.bar-fill { background: var(--grad); height: 100%; border-radius: 6px; min-width: 3px; transition: width 0.4s ease; }
.bar-meta { display: flex; flex-direction: column; gap: 1px; }
.bar-value { font-size: 0.88rem; font-weight: 700; }
.bar-count { font-size: 0.75rem; color: var(--muted); }

/* Export bar */
.report-export-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 16px;
  flex-wrap: wrap;
}

/* Report date-range filter bar */
.report-filter-bar {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 14px;
  padding: 16px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.report-filter-field { display: flex; flex-direction: column; gap: 6px; }
.report-filter-field label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-transform: uppercase;
}
.report-filter-field input[type="date"] {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.report-filter-field input[type="date"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb),0.12);
}
.report-filter-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.report-filter-actions .btn-cancel,
.report-filter-actions .btn-new { margin: 0; }

/* --- Company record tabs -------------------------------------------------- */
.crm-tabs-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.crm-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  padding: 0 20px;
  background: var(--bg);
}
.crm-tabs a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 13px 16px;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.12s;
  white-space: nowrap;
}
.crm-tabs a:hover { color: var(--text); text-decoration: none; }
.crm-tabs a.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.crm-tab-badge {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 7px;
  color: var(--muted);
}
.crm-tabs a.active .crm-tab-badge { background: rgba(var(--bs-primary-rgb),0.1); border-color: rgba(var(--bs-primary-rgb),0.2); color: var(--accent); }
.crm-tab-empty {
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.crm-tab-empty p { margin: 0 0 4px; font-size: 0.92rem; }
.crm-tab-empty .hint { font-size: 0.84rem; margin: 0; }

/* Assign-product bar (products tab) */
.crm-tab-assign-bar {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.crm-assign-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.crm-assign-select {
  flex: 1;
  min-width: 200px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.88rem;
  background: var(--surface);
  color: var(--text);
}
.crm-assign-select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb),0.1); }
.crm-assign-qty {
  width: 70px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.88rem;
  background: var(--surface);
  color: var(--text);
  text-align: center;
}
.crm-assign-qty:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb),0.1); }
.crm-assign-price {
  width: 150px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.88rem;
  background: var(--surface);
  color: var(--text);
}
.crm-assign-price:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb),0.1); }

/* Products table inside company record */
.crm-products-table { width: 100%; border-collapse: collapse; }
.crm-products-table th {
  text-align: left;
  padding: 10px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}
.crm-products-table td {
  padding: 13px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  vertical-align: middle;
}
.crm-products-table tbody tr:last-child td { border-bottom: 1px solid var(--border); }
.crm-products-total td {
  padding: 12px 20px;
  background: var(--bg);
  font-size: 0.92rem;
}

/* Invoice placeholder */
.crm-invoice-preview {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 24px;
  max-width: 380px;
}
.crm-invoice-preview-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.83rem;
  color: var(--muted);
}

/* --- Billing tab (company record) ----------------------------------------- */
.billing-pane { display: flex; flex-direction: column; }
.billing-banner {
  background: var(--bs-warning-bg-subtle);
  border: 1px solid var(--bs-warning-border-subtle);
  color: var(--bs-warning-text-emphasis);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.87rem;
  margin: 16px 20px 0;
  line-height: 1.5;
}
.billing-section {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.billing-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 12px;
}
.billing-card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.billing-card-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
}
.billing-card-info svg { color: var(--muted); }

/* --- Payment result card (checkout return) -------------------------------- */
.payment-result-card {
  max-width: 460px;
  margin: 40px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px 32px;
  text-align: center;
}
.payment-result-icon {
  width: 64px; height: 64px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
}
.payment-result-card.ok .payment-result-icon   { background: var(--bs-success-bg-subtle); color: var(--bs-success-text-emphasis); }
.payment-result-card.fail .payment-result-icon { background: var(--danger-bg); color: var(--danger); }
.payment-result-card h1 { font-size: 1.4rem; margin-bottom: 8px; }
.payment-result-card p { color: var(--muted); font-size: 0.95rem; margin: 0 0 24px; }
.payment-result-card .btn-primary { display: inline-flex; }

/* --- Responsive ----------------------------------------------------------- */

/* Horizontal-scroll wrapper for wide tables inside cards/tabs (the parent
   card has overflow:hidden, which would otherwise clip them). */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Mobile toggle that collapses the CRM details form (hidden on desktop) */
.crm-details-cb { position: absolute; opacity: 0; pointer-events: none; }
.crm-details-toggle { display: none; }

@media (max-width: 900px) {
  /* Layout adjustments */
  .crm-body { grid-template-columns: 1fr; }
  .crm-sidebar { position: static; }
  .crm-field-row { grid-template-columns: 1fr; }
  .crm-header { flex-direction: column; align-items: flex-start; }
  .crm-header-actions { width: 100%; justify-content: flex-end; }

  /* Collapse the details form behind a toggle so tabs/activity are reachable
     without scrolling past the whole form */
  .crm-details-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 22px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent);
    cursor: pointer;
  }
  .crm-details-toggle::after {
    content: "▾";
    color: var(--muted);
    transition: transform 0.15s;
  }
  .crm-details-cb:checked ~ .crm-details-toggle { border-bottom: 1px solid var(--border); }
  .crm-details-cb:checked ~ .crm-details-toggle::after { transform: rotate(180deg); }
  .crm-details-cb:not(:checked) ~ form { display: none; }
  .crm-contact-head { padding: 18px 20px 16px; }

  /* Tab strip scrolls instead of wrapping/overflowing */
  .crm-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .crm-tabs::-webkit-scrollbar { display: none; }

  /* Prevent iOS zoom-on-focus (fires when inputs are under 16px) */
  .field input, .field select, .field textarea,
  .crm-field input, .crm-field select, .crm-field textarea,
  .crm-assign-select, .crm-assign-qty, .crm-assign-price,
  .search-input, .note-composer textarea, .note-subject-inp {
    font-size: 16px;
  }

  /* Touch devices have no hover - keep row delete buttons visible */
  .timeline-del { color: var(--muted); border-color: var(--border); }

  /* Wide tables inside tabs scroll rather than squish */
  .table-scroll > table { min-width: 560px; }

  /* Settings tables scroll inside their card */
  table.data { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Timeline / people rows wrap instead of overflowing */
  .timeline-entry-top { flex-wrap: wrap; }
  .crm-client-row { flex-wrap: wrap; }

  /* Padding scale-down */
  .setup-wrap  { padding: 20px 16px 48px; }
  .data-page   { padding: 20px 16px 48px; }
  .crm-layout  { padding: 16px 16px 48px; }
  .dashboard-page { padding: 20px 16px 48px; }

  /* Dashboard */
  .dashboard-layout { grid-template-columns: 1fr; }

  /* Reports */
  .report-stats { grid-template-columns: 1fr 1fr; }
  .report-tabs  { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .report-tabs a { padding: 10px 14px; font-size: 0.84rem; }
  .bar-row { grid-template-columns: 70px 1fr 90px; gap: 8px; }

  /* Tables - horizontal scroll on small screens */
  .data-table-wrap { overflow-x: auto; }
  .report-section  { overflow-x: auto; }

  /* List toolbar stack */
  .data-toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .data-toolbar-left h1 { font-size: 1.5rem; }
  .data-toolbar-right { justify-content: space-between; }
  .search-input { flex: 1; width: auto; min-width: 0; }

  /* Page header */
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .page-header-actions { width: 100%; justify-content: flex-end; }

  /* Cards */
  .card { padding: 18px 18px; }

  /* Assign bar */
  .crm-assign-form { flex-direction: column; align-items: stretch; }
  .crm-assign-select, .crm-assign-qty, .crm-assign-price { width: 100%; }
}

/* List tables (opted in with .data-ent--cards) become stacked cards on
   phones: each row is one tappable card, cells get their column label. */
@media (max-width: 700px) {
  .data-table-wrap:has(.data-ent--cards) {
    background: transparent;
    border: 0;
    box-shadow: none;
    border-radius: 0;
    overflow: visible;
  }
  table.data-ent--cards,
  table.data-ent--cards tbody,
  table.data-ent--cards tr,
  table.data-ent--cards td { display: block; }
  table.data-ent--cards thead { display: none; }
  table.data-ent--cards tbody tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 10px;
    padding: 6px 0 12px;
  }
  table.data-ent--cards td {
    border-bottom: 0;
    padding: 4px 16px;
    font-size: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 14px;
  }
  table.data-ent--cards td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    flex-shrink: 0;
  }
  table.data-ent--cards td.td-name {
    display: block;
    font-size: 1.02rem;
    padding: 12px 16px 6px;
  }
  table.data-ent--cards td.td-name::before { content: none; }
}

@media (max-width: 540px) {
  .report-stats { grid-template-columns: 1fr; }
  .report-stat-value { font-size: 1.6rem; }
  .crm-tabs { padding: 0 12px; }
  .app-dialog-body, .app-dialog-head, .app-dialog-foot { padding-left: 16px; padding-right: 16px; }
  .auth-card { padding: 24px 20px; }
  .bar-row { grid-template-columns: 60px 1fr; }
  .bar-meta { display: none; }
  .dashboard-quicknav .dash-nav-card-sub { display: none; }
}
@media (max-width: 600px) {
  .data-toolbar { flex-direction: column; align-items: stretch; }
  .data-toolbar-right { justify-content: space-between; }
  .search-input { flex: 1; width: auto; }
  .data-toolbar-left h1 { font-size: 1.5rem; }
  .crm-header-title { font-size: 1.4rem; }
}

/* Toasts sit below the top bar, not on top of it. */
.toast-container { margin-top: calc(var(--topnav-height) + env(safe-area-inset-top)); }
