/* ===========================================================================
   LeadPulse — component library (docs/DESIGN_SYSTEM.md)
   Buttons · cards · stat cards · badges · tables · forms · modals · drawers
   toasts · tabs · dropdowns · pagination · empty states · skeletons
   gps-badge · timeline · kanban · map · charts
   =========================================================================== */

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  --btn-h: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--btn-h);
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast),
              color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
  text-decoration: none;
  user-select: none;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled,
.btn.is-disabled {
  opacity: .55;
  cursor: not-allowed;
  pointer-events: none;
}
.btn i { font-size: .92em; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }

.btn-secondary {
  background: var(--tf-navy);
  border-color: var(--tf-navy);
  color: #fff;
}
.btn-secondary:hover { background: var(--tf-navy-700); color: #fff; }

.btn-outline {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--tf-teal-100); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b62626; border-color: #b62626; color: #fff; }

.btn-danger-outline { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger-outline:hover { background: var(--tf-red-100); }

.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #256a29; color: #fff; }

.btn-sm { --btn-h: 30px; padding: 0 10px; font-size: var(--fs-sm); }
.btn-lg { --btn-h: 46px; padding: 0 24px; font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn-icon { padding: 0; width: var(--btn-h); }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

.btn .spinner {
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: lp-spin .7s linear infinite;
}
@keyframes lp-spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card + .card { margin-top: 16px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.card-header h2,
.card-header h3 { margin: 0; font-size: var(--fs-md); font-weight: 600; }
.card-header .card-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-subtitle { color: var(--text-muted); font-size: var(--fs-xs); margin: 2px 0 0; }

.card-body { padding: 16px; }
.card-body.is-flush { padding: 0; }
.card-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   Stat cards
   -------------------------------------------------------------------------- */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--t-fast), transform var(--t-fast);
}
a.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); text-decoration: none; }

.stat-icon {
  width: 42px; height: 42px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
  background: var(--tf-teal-100);
  color: var(--tf-teal);
  flex-shrink: 0;
}
.stat-icon.is-cyan   { background: var(--tf-cyan-100);   color: var(--tf-cyan); }
.stat-icon.is-green  { background: var(--tf-green-100);  color: var(--tf-green); }
.stat-icon.is-amber  { background: var(--tf-amber-100);  color: #b57d00; }
.stat-icon.is-red    { background: var(--tf-red-100);    color: var(--tf-red); }
.stat-icon.is-purple { background: var(--tf-purple-100); color: var(--tf-purple); }
.stat-icon.is-navy   { background: rgba(13, 43, 69, .09); color: var(--tf-navy); }

.stat-meta { min-width: 0; flex: 1; }
.stat-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
  margin: 0 0 2px;
}
.stat-value {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: var(--fs-stat);
  line-height: 1.1;
  color: var(--tf-navy);
}
:root[data-theme="dark"] .stat-value { color: var(--text); }
.stat-sub { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 3px; }
.stat-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--fs-xs);
  font-weight: 600;
  margin-top: 4px;
}
.stat-delta.is-up { color: var(--success); }
.stat-delta.is-down { color: var(--danger); }
.stat-delta.is-flat { color: var(--text-muted); }

/* --------------------------------------------------------------------------
   Badges, chips, pills
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.5;
  background: var(--surface-2);
  color: var(--text-muted);
  white-space: nowrap;
}
.badge-primary { background: var(--tf-teal-100); color: var(--tf-teal-700); }
.badge-info    { background: var(--tf-cyan-100); color: #00727f; }
.badge-success { background: var(--tf-green-100); color: var(--tf-green); }
.badge-warning { background: var(--tf-amber-100); color: #a67500; }
.badge-danger  { background: var(--tf-red-100); color: var(--tf-red); }
.badge-purple  { background: var(--tf-purple-100); color: var(--tf-purple); }
.badge-solid   { background: var(--primary); color: #fff; }
.badge-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* Stage badge takes its colour from a --stage-color custom property. */
.stage-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  background: color-mix(in srgb, var(--stage-color, var(--tf-teal)) 14%, transparent);
  color: var(--stage-color, var(--tf-teal));
  border: 1px solid color-mix(in srgb, var(--stage-color, var(--tf-teal)) 30%, transparent);
  white-space: nowrap;
}
@supports not (background: color-mix(in srgb, red 10%, transparent)) {
  .stage-badge { background: var(--surface-2); }
}
.stage-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--stage-color, var(--tf-teal));
  display: inline-block;
  flex-shrink: 0;
}

.priority-low     { background: var(--surface-2); color: var(--text-muted); }
.priority-normal  { background: var(--tf-cyan-100); color: #00727f; }
.priority-high    { background: var(--tf-amber-100); color: #a67500; }
.priority-urgent  { background: var(--tf-red-100); color: var(--tf-red); }

.role-badge { font-size: 11px; }
.role-super_admin   { background: var(--tf-purple-100); color: var(--tf-purple); }
.role-tenant_admin  { background: var(--tf-teal-100); color: var(--tf-teal-700); }
.role-sales_manager { background: var(--tf-cyan-100); color: #00727f; }
.role-field_agent   { background: var(--tf-green-100); color: var(--tf-green); }
.role-auditor       { background: var(--surface-2); color: var(--text-muted); }

.status-active    { background: var(--tf-green-100); color: var(--tf-green); }
.status-invited   { background: var(--tf-amber-100); color: #a67500; }
.status-suspended { background: var(--tf-red-100); color: var(--tf-red); }
.status-disabled  { background: var(--surface-2); color: var(--text-muted); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: var(--fs-xs);
  color: var(--text);
}
.chip .chip-remove {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  padding: 0 2px;
  line-height: 1;
}
.chip .chip-remove:hover { color: var(--danger); }
.chip-list { display: flex; flex-wrap: wrap; gap: 6px; }

/* --------------------------------------------------------------------------
   GPS badge
   -------------------------------------------------------------------------- */
.gps-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.gps-badge i { font-size: 11px; }
.gps-badge.is-good { background: var(--tf-green-100); color: var(--gps-good); border-color: transparent; }
.gps-badge.is-ok   { background: var(--tf-amber-100); color: #a67500; border-color: transparent; }
.gps-badge.is-poor { background: var(--tf-red-100); color: var(--gps-poor); border-color: transparent; }
.gps-badge.is-none { background: var(--surface-2); color: var(--text-muted); }
.gps-badge.is-searching i { animation: lp-pulse 1.3s ease-in-out infinite; }
@keyframes lp-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* --------------------------------------------------------------------------
   Tables — responsive, stacked below 640px
   -------------------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
.table th,
.table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table thead th {
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .5px;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}
.table tbody tr { transition: background var(--t-fast); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.is-numeric,
.table th.is-numeric { text-align: right; font-variant-numeric: tabular-nums; }
.table td.is-actions { text-align: right; white-space: nowrap; width: 1%; }
.table .col-check { width: 36px; }

.table thead th a.sortable {
  color: inherit;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.table thead th a.sortable:hover { color: var(--primary); text-decoration: none; }
.table thead th .sort-icon { opacity: .4; font-size: 10px; }
.table thead th a.sortable.is-sorted .sort-icon { opacity: 1; color: var(--primary); }

.table-striped tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.table-compact th, .table-compact td { padding: 7px 10px; }

@media (max-width: 639.98px) {
  .table.is-stacked thead { display: none; }
  .table.is-stacked,
  .table.is-stacked tbody,
  .table.is-stacked tr,
  .table.is-stacked td { display: block; width: 100%; }
  .table.is-stacked tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 6px 10px;
    background: var(--surface);
  }
  .table.is-stacked td {
    border: 0;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    text-align: right;
  }
  .table.is-stacked td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: .4px;
    text-align: left;
    flex-shrink: 0;
  }
  .table.is-stacked td.is-actions { justify-content: flex-end; }
  .table.is-stacked td.is-actions::before { display: none; }
}

.bulk-bar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--tf-teal-100);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
  font-weight: 600;
  flex-wrap: wrap;
}
.bulk-bar.is-visible { display: flex; }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

.label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.label .required { color: var(--danger); margin-left: 2px; }
.label .optional { color: var(--text-faint); font-weight: 400; font-size: var(--fs-xs); margin-left: 4px; }

.input,
.select,
.textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.4;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  appearance: none;
}
.input::placeholder,
.textarea::placeholder { color: var(--text-faint); }
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--tf-cyan);
  box-shadow: var(--ring);
}
.input:disabled,
.select:disabled,
.textarea:disabled {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: not-allowed;
}
.input.is-invalid,
.select.is-invalid,
.textarea.is-invalid { border-color: var(--danger); }
.input.is-invalid:focus { box-shadow: 0 0 0 3px rgba(211, 47, 47, .22); }
.textarea { min-height: 96px; resize: vertical; }

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23607d8b' d='M6 8 0 1.4 1.4 0 6 4.6 10.6 0 12 1.4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .btn { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; --btn-h: 40px; }
.input-affix {
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.input-group .input-affix:first-child { border-right: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.input-group .input-affix:first-child + .input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }

.help { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 5px; }
.error {
  font-size: var(--fs-xs);
  color: var(--danger);
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.checkbox,
.radio {
  display: inline-flex;
  align-items: flex-start;
  gap: 9px;
  cursor: pointer;
  font-size: var(--fs-base);
  line-height: 1.4;
}
.checkbox input[type="checkbox"],
.radio input[type="radio"] {
  width: 17px; height: 17px;
  margin: 1px 0 0;
  accent-color: var(--primary);
  flex-shrink: 0;
  cursor: pointer;
}
.checkbox-list { display: flex; flex-direction: column; gap: 10px; }
.checkbox-inline { display: flex; flex-wrap: wrap; gap: 16px; }

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 38px; height: 21px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  transition: background var(--t-fast);
  flex-shrink: 0;
  position: relative;
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 17px; height: 17px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--t-fast);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(17px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--ring); }
.switch input:disabled + .switch-track { opacity: .5; cursor: not-allowed; }

.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 640px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid .field-full { grid-column: 1 / -1; }
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.filter-bar .field { margin: 0; min-width: 150px; flex: 1 1 150px; }
.filter-bar .field .label { font-size: var(--fs-xs); margin-bottom: 4px; }
.filter-bar .input,
.filter-bar .select { min-height: 36px; padding: 6px 10px; font-size: var(--fs-sm); }
.filter-bar .filter-actions { display: flex; gap: 8px; flex: 0 0 auto; }

/* --------------------------------------------------------------------------
   Tabs
   -------------------------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 16px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  background: transparent;
  border-top: 0; border-left: 0; border-right: 0;
  cursor: pointer;
  font-family: var(--font-body);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; padding-top: 16px; }
.tab-panel.is-active { display: block; }

.pill-tabs { display: inline-flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: var(--radius-pill); }
.pill-tabs .tab {
  border: 0;
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font-size: var(--fs-sm);
}
.pill-tabs .tab.is-active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }

/* --------------------------------------------------------------------------
   Dropdowns
   -------------------------------------------------------------------------- */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: var(--z-modal);
  display: none;
  max-height: 70vh;
  overflow-y: auto;
}
.dropdown-menu.is-open { display: block; animation: lp-fade-in var(--t-fast); }
.dropdown-menu.align-left { right: auto; left: 0; }
@keyframes lp-fade-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--fs-sm);
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
  font-family: var(--font-body);
}
.dropdown-item:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.dropdown-item i { width: 16px; text-align: center; color: var(--text-muted); font-size: 13px; }
.dropdown-item.is-danger { color: var(--danger); }
.dropdown-item.is-danger i { color: var(--danger); }
.dropdown-divider { height: 1px; background: var(--border); margin: 5px 2px; }
.dropdown-header {
  padding: 8px 10px 4px;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.dropdown-menu form { margin: 0; }

/* --------------------------------------------------------------------------
   Modals & drawers
   -------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
.modal-backdrop.is-open { opacity: 1; pointer-events: auto; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  transform: translateY(24px);
  transition: transform var(--t-base);
}
.modal-backdrop.is-open .modal { transform: none; }
.modal-sm { max-width: 400px; }
.modal-lg { max-width: 860px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { margin: 0; font-size: var(--fs-md); }
.modal-body { padding: 16px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-shrink: 0;
}
.modal-close {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 17px;
  cursor: pointer;
  width: 32px; height: 32px;
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { border-radius: var(--radius-lg); }
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: var(--z-drawer);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
.drawer-backdrop.is-open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(480px, 100%);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  z-index: calc(var(--z-drawer) + 1);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--t-base);
}
.drawer.is-open { transform: none; }
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-header h3 { margin: 0; font-size: var(--fs-md); }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; }
.drawer-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.drawer-footer .btn { flex: 1; }

/* --------------------------------------------------------------------------
   Toasts
   -------------------------------------------------------------------------- */
.toast-stack {
  position: fixed;
  left: 12px; right: 12px;
  bottom: calc(var(--bottombar-h) + 12px);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
@media (min-width: 768px) {
  .toast-stack { left: auto; right: 20px; bottom: 20px; width: 360px; }
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: var(--fs-sm);
  pointer-events: auto;
  animation: lp-toast-in var(--t-base);
}
.toast.is-leaving { animation: lp-toast-out var(--t-base) forwards; }
@keyframes lp-toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes lp-toast-out { to { opacity: 0; transform: translateX(16px); } }

.toast-icon { font-size: 15px; margin-top: 1px; flex-shrink: 0; color: var(--primary); }
.toast-message { flex: 1; min-width: 0; }
.toast-close {
  background: transparent;
  border: 0;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
}
.toast-close:hover { color: var(--text); }
.toast.is-success { border-left-color: var(--success); }
.toast.is-success .toast-icon { color: var(--success); }
.toast.is-error { border-left-color: var(--danger); }
.toast.is-error .toast-icon { color: var(--danger); }
.toast.is-warning { border-left-color: var(--warning); }
.toast.is-warning .toast-icon { color: #a67500; }
.toast.is-info { border-left-color: var(--tf-cyan); }
.toast.is-info .toast-icon { color: var(--tf-cyan); }

/* Inline alerts ----------------------------------------------------------- */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  margin-bottom: 16px;
}
.alert i { margin-top: 2px; }
.alert-success { background: var(--tf-green-100); border-color: transparent; color: #1b5e20; }
.alert-warning { background: var(--tf-amber-100); border-color: transparent; color: #7a5600; }
.alert-danger  { background: var(--tf-red-100); border-color: transparent; color: #8e1b1b; }
.alert-info    { background: var(--tf-cyan-100); border-color: transparent; color: #006064; }
:root[data-theme="dark"] .alert-success,
:root[data-theme="dark"] .alert-warning,
:root[data-theme="dark"] .alert-danger,
:root[data-theme="dark"] .alert-info { color: var(--text); }

/* --------------------------------------------------------------------------
   Pagination
   -------------------------------------------------------------------------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: var(--fs-sm);
}
.pagination-summary { color: var(--text-muted); font-size: var(--fs-xs); }
.pagination-list {
  display: flex;
  list-style: none;
  margin: 0; padding: 0;
  gap: 4px;
  flex-wrap: wrap;
}
.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 500;
  background: var(--surface);
}
.page-link:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.page-link.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}
.page-link.is-disabled { opacity: .4; pointer-events: none; }
.page-ellipsis {
  display: inline-flex;
  align-items: center;
  padding: 0 4px;
  color: var(--text-faint);
  height: 34px;
}

/* --------------------------------------------------------------------------
   Empty states & skeletons
   -------------------------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .empty-icon {
  width: 72px; height: 72px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
}
.empty-state h3 { color: var(--text); margin-bottom: 6px; font-size: var(--fs-md); }
.empty-state p { max-width: 420px; margin: 0 auto 18px; font-size: var(--fs-sm); }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: lp-shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
}
@keyframes lp-shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skeleton-text { height: 12px; margin-bottom: 8px; }
.skeleton-title { height: 20px; width: 45%; margin-bottom: 14px; }
.skeleton-row { height: 44px; margin-bottom: 8px; }
.skeleton-card { height: 92px; }
.skeleton-circle { border-radius: 50%; width: 40px; height: 40px; }

/* --------------------------------------------------------------------------
   Timeline
   -------------------------------------------------------------------------- */
.timeline { position: relative; padding-left: 30px; }
.timeline::before {
  content: '';
  position: absolute;
  left: 13px; top: 6px; bottom: 6px;
  width: 2px;
  background: var(--border);
}
.timeline-item { position: relative; padding-bottom: 20px; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-marker {
  position: absolute;
  left: -30px; top: 0;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-muted);
  z-index: 1;
}
.timeline-marker.is-call    { border-color: var(--tf-cyan);  color: var(--tf-cyan); }
.timeline-marker.is-visit   { border-color: var(--tf-green); color: var(--tf-green); }
.timeline-marker.is-note    { border-color: var(--border-strong); }
.timeline-marker.is-stage   { border-color: var(--tf-teal);  color: var(--tf-teal); }
.timeline-marker.is-message { border-color: var(--tf-lime);  color: #6d8f1f; }
.timeline-marker.is-system  { border-color: var(--text-faint); }
.timeline-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
}
.timeline-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 6px;
}
.timeline-meta a { color: var(--text-muted); }
.timeline-title { font-weight: 600; font-size: var(--fs-sm); }

/* --------------------------------------------------------------------------
   Kanban (SortableJS)
   -------------------------------------------------------------------------- */
.kanban {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 12px;
  -webkit-overflow-scrolling: touch;
  align-items: flex-start;
}
.kanban-column {
  flex: 0 0 272px;
  background: var(--surface-2);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 240px);
}
.kanban-column-header {
  padding: 11px 13px;
  border-bottom: 2px solid var(--stage-color, var(--tf-teal));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 600;
  font-size: var(--fs-sm);
  position: sticky;
  top: 0;
  background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0;
  z-index: 1;
}
.kanban-count {
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 1px 8px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
}
.kanban-items {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 60px;
}
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  box-shadow: var(--shadow-sm);
  cursor: grab;
  font-size: var(--fs-sm);
}
.kanban-card:active { cursor: grabbing; }
.kanban-card.sortable-ghost { opacity: .35; }
.kanban-card.sortable-chosen { box-shadow: var(--shadow-lg); }
.kanban-card-title { font-weight: 600; margin-bottom: 4px; }
.kanban-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 6px;
}

/* --------------------------------------------------------------------------
   Map & charts
   -------------------------------------------------------------------------- */
.map-container {
  width: 100%;
  height: 420px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
  position: relative;
  z-index: 0;
}
.map-container.is-tall { height: calc(100vh - 220px); min-height: 380px; }
.map-container.is-short { height: 220px; }
.leaflet-container { font-family: var(--font-body); font-size: var(--fs-sm); background: var(--surface-2); }
.lp-marker {
  background: var(--tf-teal);
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  width: 22px; height: 22px;
  box-shadow: var(--shadow);
}
.map-legend {
  position: absolute;
  right: 10px; bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: var(--fs-xs);
  box-shadow: var(--shadow);
  z-index: 500;
}
.map-legend-item { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.map-legend-item:last-child { margin-bottom: 0; }

.chart-card .chart-canvas-wrap { position: relative; height: 280px; }
.chart-card .chart-canvas-wrap.is-short { height: 200px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: var(--fs-xs); }
.chart-legend-item { display: flex; align-items: center; gap: 6px; color: var(--text-muted); }
.chart-legend-swatch { width: 10px; height: 10px; border-radius: 3px; }

/* --------------------------------------------------------------------------
   Misc
   -------------------------------------------------------------------------- */
.divider-label {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-faint);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin: 20px 0;
}
.divider-label::before,
.divider-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.kv-list { display: grid; grid-template-columns: 1fr; gap: 0; }
.kv-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
}
.kv-row:last-child { border-bottom: 0; }
.kv-key { color: var(--text-muted); flex-shrink: 0; }
.kv-value { text-align: right; font-weight: 500; min-width: 0; word-break: break-word; }

.code-block {
  background: var(--tf-navy);
  color: #d7e6f2;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.copy-field {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  word-break: break-all;
}
.copy-field .btn { flex-shrink: 0; }

.progress {
  height: 7px;
  background: var(--surface-3);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--grad-brand);
  border-radius: var(--radius-pill);
  transition: width var(--t-slow);
}

.live-feed { max-height: 340px; overflow-y: auto; }
.live-feed-item {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm);
  animation: lp-fade-in var(--t-base);
}
.live-feed-item:last-child { border-bottom: 0; }
.live-feed-icon {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--tf-cyan-100);
  color: var(--tf-cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
}
.live-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--success);
  margin-right: 6px;
  animation: lp-pulse 1.8s ease-in-out infinite;
}
.live-dot.is-offline { background: var(--text-faint); animation: none; }

.notification-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background var(--t-fast);
}
.notification-item:hover { background: var(--surface-2); }
.notification-item.is-unread { background: var(--tf-cyan-100); }
:root[data-theme="dark"] .notification-item.is-unread { background: var(--surface-2); }
.notification-item:last-child { border-bottom: 0; }
.notification-icon {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--tf-teal);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.section-title {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--text-muted);
  margin: 0 0 10px;
}

.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--fs-xs);
  color: var(--text-muted);
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
}
.sync-status.is-syncing i { animation: lp-spin 1s linear infinite; }
.sync-status.is-offline { background: var(--tf-amber-100); color: #a67500; }
.sync-status.is-error { background: var(--tf-red-100); color: var(--danger); }

/* ---- Settings pages (general, assignment, tags, audit) ---- */
.settings-nav{display:flex;gap:6px;overflow-x:auto;padding:4px 0 10px;margin-bottom:18px;border-bottom:1px solid var(--border);-webkit-overflow-scrolling:touch}
.settings-nav-item{display:inline-flex;align-items:center;gap:7px;padding:8px 14px;border-radius:999px;white-space:nowrap;font-size:14px;font-weight:500;color:var(--text-muted);text-decoration:none;background:var(--surface-2);border:1px solid transparent}
.settings-nav-item:hover{color:var(--tf-teal-700);background:var(--surface)}
.settings-nav-item.is-active{background:var(--tf-teal);border-color:var(--tf-teal);color:#fff}
.settings-grid{display:grid;grid-template-columns:minmax(0,2fr) minmax(0,1fr);gap:20px;align-items:start}
.settings-aside{position:sticky;top:calc(var(--topbar-h) + 16px)}
.field-row{display:grid;grid-template-columns:1fr 1fr;gap:16px}
.input-color{padding:2px;height:40px;min-width:60px;cursor:pointer}
.input-sm{height:32px;font-size:13px;padding:4px 8px}
.checkbox-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(210px,1fr));gap:8px}
.inline-form{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin:0}
.tag-dot{width:12px;height:12px;border-radius:50%;display:inline-block;flex:0 0 auto}
.kv{display:grid;grid-template-columns:auto 1fr;gap:8px 16px;margin:0}
.kv dt{color:var(--text-muted);font-size:13.5px}
.kv dd{margin:0;font-weight:600;text-align:right}
.filter-bar{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:14px;padding:16px;margin-bottom:18px}
.filter-bar .field{margin:0}
.field-actions{display:flex;align-items:flex-end;gap:8px}
.nowrap{white-space:nowrap}
.small{font-size:12.5px}
@media (max-width:900px){
  .settings-grid{grid-template-columns:1fr}
  .settings-aside{position:static}
  .field-row{grid-template-columns:1fr}
}

/* MFA enrolment: clock comparison notice */
.mfa-clock{display:flex;gap:7px;align-items:flex-start;margin:10px 0 14px;line-height:1.5}
.mfa-clock.is-warning{color:var(--tf-amber);background:rgba(249,168,37,.10);border:1px solid rgba(249,168,37,.35);border-radius:var(--radius-sm,6px);padding:9px 11px}
.mfa-clock.is-warning strong{color:var(--text)}
