/* Access CRM layout and components. Tokens live in theme.css. */

/* ---------- App shell ---------- */
.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 100;
  padding: 8px 14px;
  border-radius: var(--radius-control);
  background: var(--primary);
  color: #fff;
  font-weight: 500;
}
.skip-link:focus { top: 12px; color: #fff; }

.app-main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: margin-left .18s ease;
}

.app-content {
  flex-grow: 1;
  padding: var(--page-pad-y) var(--page-pad-x);
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}

html.no-transition .app-main,
html.no-transition .sidebar { transition: none !important; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: var(--sidebar-w);
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .18s ease, transform .2s ease;
}

.sidebar-header {
  height: 72px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  border-bottom: 1px solid var(--nav-line);
}

.brand-mark { flex-shrink: 0; display: block; }

.brand-text { flex-grow: 1; min-width: 0; }
.brand-name { font-size: 16px; font-weight: 600; color: #fff; line-height: 1.2; white-space: nowrap; }
.brand-tagline { font-size: 12px; color: var(--nav-text-dim); white-space: nowrap; }

.nav-icon-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: var(--radius-control);
  background: transparent;
  border: 1px solid var(--nav-button-line);
  color: var(--nav-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}
.nav-icon-btn:hover { background: var(--nav-hover-bg); color: #fff; }

.sidebar-close { display: none; }

.sidebar-nav {
  flex-grow: 1;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--nav-line) transparent;
}

.nav-group-label {
  padding: 16px 12px 6px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--nav-text-dim);
  font-weight: 500;
  white-space: nowrap;
}
.nav-group-line { display: none; height: 1px; background: var(--nav-line); margin: 12px 8px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 44px;
  flex-shrink: 0;
  border-radius: var(--radius-control);
  padding: 0 12px;
  color: var(--nav-text);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.nav-item svg { flex-shrink: 0; }
.nav-item:hover { background: var(--nav-hover-bg); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--nav-active-bg); color: #fff; font-weight: 600; }
.nav-item:focus-visible { outline-color: #8FB4FF; outline-offset: -2px; }

.sidebar-footer {
  flex-shrink: 0;
  border-top: 1px solid var(--nav-line);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.sidebar-user { min-width: 0; flex-grow: 1; }
.sidebar-user-name { font-size: 14px; font-weight: 500; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 12px; color: var(--nav-text-dim); white-space: nowrap; }
.sidebar-signout {
  display: none;
  background: none;
  border: 0;
  padding: 8px 4px;
  font: 500 13px var(--font);
  color: #8FB4FF;
  cursor: pointer;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  background: var(--primary-tint);
  color: var(--primary-ink);
}
.avatar-dark { background: var(--nav-avatar); color: #fff; }

/* Collapsed rail (desktop) */
.sidebar-header-collapsed { display: none; }

@media (min-width: 1200px) {
  html.sidebar-collapsed .sidebar-header { display: none; }
  html.sidebar-collapsed .sidebar-header-collapsed {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    flex-shrink: 0;
    border-bottom: 1px solid var(--nav-line);
  }
  html.sidebar-collapsed .nav-label,
  html.sidebar-collapsed .nav-group-label,
  html.sidebar-collapsed .sidebar-user { display: none; }
  html.sidebar-collapsed .nav-group-line { display: block; }
  html.sidebar-collapsed .nav-item { justify-content: center; padding: 0; }
  html.sidebar-collapsed .sidebar-footer { justify-content: center; padding: 14px 0; }
}

/* Drawer (tablet and phone) */
.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 35;
  background: rgba(14, 26, 47, .55);
}

@media (max-width: 1199.98px) {
  .sidebar {
    width: var(--drawer-w);
    max-width: 86vw;
    transform: translateX(-100%);
    box-shadow: none;
    visibility: hidden;
    transition: transform .2s ease, visibility 0s linear .2s;
  }
  html.drawer-open .sidebar {
    transform: none;
    visibility: visible;
    box-shadow: 8px 0 32px rgba(0, 0, 0, .3);
    transition: transform .2s ease;
  }
  html.drawer-open .drawer-backdrop { display: block; }
  html.drawer-open body { overflow: hidden; }
  .sidebar-toggle { display: none; }
  .sidebar-close {
    display: inline-flex;
    width: 44px;
    height: 44px;
    border: 0;
  }
  .nav-item { height: 48px; font-size: 15px; border-radius: 10px; padding: 0 14px; gap: 14px; }
  .sidebar-signout { display: inline-block; }
  .app-main { margin-left: 0; }
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 var(--page-pad-x);
}

.topbar .topbar-menu-btn,
.topbar .topbar-title,
.topbar .topbar-search-btn { display: none; }

.global-search {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 460px;
  max-width: 100%;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  background: var(--table-head);
  margin: 0;
}
.global-search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 95, 214, .15); }
.global-search svg { flex-shrink: 0; color: var(--text-muted); }
.global-search input {
  flex-grow: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: 400 14px var(--font);
  color: var(--text);
}
.global-search input::placeholder { color: var(--text-muted); }
.kbd {
  font-size: 12px;
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 1px 6px;
  background: var(--surface);
  line-height: 1.4;
}

.topbar-spacer { flex-grow: 1; }

.icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: var(--radius-control);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-label);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}
.icon-btn:hover { background: var(--table-head); }
.icon-btn.sm { width: 32px; height: 32px; }

.count-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--danger-dot);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--surface);
}

.user-btn {
  border: 0;
  background: none;
  padding: 0 0 0 8px;
  cursor: pointer;
  border-radius: 50%;
}

/* Dropdown panels */
.dropdown-menu {
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-float);
  padding: 6px;
  font-size: 14px;
  min-width: 220px;
}
.dropdown-item {
  border-radius: 6px;
  padding: 9px 12px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}
.dropdown-item:hover, .dropdown-item:focus { background: var(--table-head); color: var(--text); text-decoration: none; }
.dropdown-item svg { color: var(--text-muted); flex-shrink: 0; }
.dropdown-header-user { padding: 10px 12px 8px; }
.dropdown-header-user .name { font-weight: 600; }
.dropdown-header-user .meta { font-size: 13px; color: var(--text-muted); }
.dropdown-divider { border-top-color: var(--row-line); margin: 4px 0; }

.notif-panel { width: 392px; max-width: calc(100vw - 24px); padding: 0; overflow: hidden; }
.notif-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--row-line);
}
.notif-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.notif-empty { padding: 28px 16px; text-align: center; color: var(--text-muted); font-size: 14px; }
.notif-foot { padding: 12px 16px; text-align: center; border-top: 1px solid var(--row-line); font-size: 13px; font-weight: 500; }

/* Phone top bar */
.mobile-search-row { display: none; }

@media (max-width: 1199.98px) {
  .topbar .topbar-menu-btn { display: inline-flex; }
}

@media (max-width: 767.98px) {
  .topbar {
    background: var(--nav-bg);
    border-bottom: 0;
    color: #fff;
    gap: 4px;
    padding: 0 8px;
  }
  .topbar .global-search,
  .topbar .quick-add-btn,
  .topbar .user-menu { display: none; }
  .topbar .topbar-title { display: block; flex-grow: 1; font-size: 17px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar-spacer { display: none; }
  .topbar .topbar-search-btn { display: inline-flex; }
  .topbar .icon-btn {
    width: 44px;
    height: 44px;
    border: 0;
    background: transparent;
    color: #fff;
  }
  .topbar .count-badge { top: 5px; right: 4px; min-width: 18px; height: 18px; border: 0; background: #E5484D; }
  .mobile-search-row.open {
    display: block;
    position: sticky;
    top: var(--topbar-h);
    z-index: 29;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
  .mobile-search-row .global-search { width: 100%; height: 48px; }
  .mobile-search-row .global-search input { font-size: 16px; }
}

/* ---------- Bottom navigation (phone) ---------- */
.bottom-nav { display: none; }

@media (max-width: 767.98px) {
  .bottom-nav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 30;
    height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
  }
  .bottom-nav a, .bottom-nav button.bn-item {
    flex: 1;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    background: none;
    border: 0;
    padding: 0;
  }
  .bottom-nav a.active { color: var(--primary-ink); font-weight: 600; }
  .bn-add-wrap { flex: 1; height: 100%; display: flex; }
  .bn-add {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: -18px;
    box-shadow: 0 6px 16px rgba(31, 95, 214, .4);
  }
  .app-content { padding-bottom: calc(var(--bottomnav-h) + 24px + env(safe-area-inset-bottom, 0px)); }
}

/* ---------- Page header ---------- */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.page-header-text { min-width: 0; }
.breadcrumb-c {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  margin: 0 0 6px;
  padding: 0;
  font-size: 13px;
  color: var(--text-muted);
}
.breadcrumb-c li + li::before { content: "/"; margin-right: 6px; color: var(--border-strong); }
.breadcrumb-c a { color: var(--text-muted); }
.breadcrumb-c a:hover { color: var(--primary-ink); }
.page-title { margin: 0; font-size: 28px; font-weight: 600; line-height: 1.2; }
.page-subtitle { margin: 6px 0 0; font-size: 14px; color: var(--text-muted); }
.page-actions { display: flex; gap: 12px; flex-wrap: wrap; }

@media (max-width: 767.98px) {
  .page-title { font-size: 22px; }
  .page-subtitle { font-size: 13px; margin-top: 4px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
}

/* ---------- Cards ---------- */
.card-c {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  min-width: 0;
}
.card-pad { padding: 20px; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  padding: 0 20px;
}
.card-title { margin: 0; font-size: 16px; font-weight: 600; }

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi-label { font-size: 13px; color: var(--text-muted); }
.kpi-value { font-size: 34px; font-weight: 600; margin-top: 6px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-help { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

@media (max-width: 1199.98px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 767.98px) {
  .kpi-grid { gap: 12px; }
  .kpi-grid .card-pad { padding: 14px; }
  .kpi-label { font-size: 12px; }
  .kpi-value { font-size: 28px; margin-top: 2px; }
  .kpi-help { font-size: 12px; }
}

.split-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.home-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; margin-top: 24px; }
@media (max-width: 991.98px) { .home-pair { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 1199.98px) { .split-grid { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Empty state ---------- */
.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  border-top: 1px solid var(--row-line);
}
.empty-state p { margin: 0; font-size: 14px; }
.empty-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary-tint);
  color: var(--primary-ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-control);
  font: 500 14px var(--font);
  white-space: nowrap;
  border-width: 1px;
}
.btn:focus { box-shadow: none; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; box-shadow: none; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: var(--radius-control); }
.btn-lg { height: 46px; font-size: 15px; font-weight: 600; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover, .btn-primary:active, .btn-primary:focus { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover, .btn-secondary:active, .btn-secondary:focus { background: var(--table-head); border-color: var(--border-strong); color: var(--text); }
.btn-danger-outline { background: var(--surface); border-color: var(--danger-line); color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger-tint); border-color: var(--danger-line); color: var(--danger); }
.btn-success-outline { background: var(--surface); border-color: #B9E2CE; color: var(--success); }
.btn-success-outline:hover { background: var(--success-tint); color: var(--success); }
.btn-block { width: 100%; }

@media (max-width: 767.98px) {
  .btn { height: 44px; }
  .btn-sm { height: 36px; }
}

/* ---------- Badges ---------- */
.badge-c {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  border-radius: 12px;
  font: 500 12px var(--font);
  white-space: nowrap;
}
.badge-blue { background: var(--primary-tint); color: var(--primary-ink); }
.badge-amber { background: var(--warning-tint); color: var(--warning); }
.badge-green { background: var(--success-tint); color: var(--success); }
.badge-red { background: var(--danger-tint); color: var(--danger); }
.badge-gray { background: var(--neutral-tint); color: var(--neutral); }
.badge-purple { background: var(--purple-tint); color: var(--purple); }

/* ---------- Alerts ---------- */
.alert-c {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-card);
  font-size: 14px;
  border: 1px solid transparent;
}
.alert-c svg { flex-shrink: 0; margin-top: 1px; }
.alert-c .alert-body { flex-grow: 1; min-width: 0; }
.alert-danger-c { background: var(--danger-tint); border-color: var(--danger-line); color: #7A1F19; }
.alert-warning-c { background: var(--warning-tint); border-color: #F3D9A4; color: #6B3A00; }
.alert-success-c { background: var(--success-tint); border-color: #B9E2CE; color: #0A4F37; }
.alert-info-c { background: var(--primary-tint); border-color: #C7D8F8; color: var(--primary-ink); }

/* ---------- Forms ---------- */
.form-label, .form-label-c {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-label);
}
.req { color: var(--danger); margin-left: 2px; }
.form-control, .form-select {
  height: 40px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-control);
  padding: 0 12px;
  font: 400 14px var(--font);
  color: var(--text);
  background-color: var(--surface);
}
.form-select { padding-right: 36px; }
textarea.form-control { height: auto; min-height: 96px; padding: 10px 12px; }
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 95, 214, .15);
}
.form-control::placeholder { color: #8792A2; }
.form-control.input-validation-error, .form-select.input-validation-error { border-color: var(--danger); }
.field-validation-error, .text-danger { color: var(--danger) !important; font-size: 13px; display: block; margin-top: 4px; }
.validation-summary-errors ul { margin: 0; padding-left: 18px; }
.form-help { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.form-check-input { width: 16px; height: 16px; margin-top: 0; border-color: var(--border-strong); }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }
.form-check { display: flex; align-items: center; gap: 8px; padding-left: 0; margin: 0; }
.form-check .form-check-input { float: none; margin-left: 0; }
.form-check-label { color: var(--text-label); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.form-grid .span-2 { grid-column: span 2; }
.form-stack { display: flex; flex-direction: column; gap: 20px; }
.form-actions { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; }
.form-section-title { margin: 0 0 4px; font-size: 16px; font-weight: 600; }

@media (max-width: 767.98px) {
  .form-control, .form-select { height: 48px; font-size: 16px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .form-actions .btn { flex: 1; }
}

/* ---------- Filter bar ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  padding: 16px 20px;
  border-bottom: 1px solid var(--row-line);
}
.filter-bar .filter-field { display: flex; flex-direction: column; min-width: 160px; }
.filter-bar .filter-field.grow { flex: 1 1 240px; }
@media (max-width: 767.98px) {
  .filter-bar { padding: 14px 16px; }
  .filter-bar .filter-field { flex: 1 1 100%; }
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table-c {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}
.table-c thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: 44px;
  padding: 0 16px;
  background: var(--table-head);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-align: left;
  white-space: nowrap;
}
.table-c thead th a { color: var(--text-muted); display: inline-flex; align-items: center; gap: 4px; }
.table-c thead th a:hover { color: var(--text); text-decoration: none; }
.table-c thead th a.sorted { color: var(--text); }
.table-c tbody td {
  height: 62px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--row-line);
  vertical-align: middle;
}
.table-c tbody tr:last-child td { border-bottom: 0; }
.table-c tbody tr:hover td { background: #FAFBFD; }
.table-c .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-c .actions { text-align: right; white-space: nowrap; }
.cell-strong { font-weight: 600; }
.cell-sub { font-size: 13px; color: var(--text-muted); }

/* Tables become cards on phones */
@media (max-width: 767.98px) {
  .table-c.stack-sm thead { display: none; }
  .table-c.stack-sm, .table-c.stack-sm tbody, .table-c.stack-sm tr, .table-c.stack-sm td { display: block; width: 100%; }
  .table-c.stack-sm tr { padding: 14px 16px; border-bottom: 1px solid var(--row-line); }
  .table-c.stack-sm tbody tr:last-child { border-bottom: 0; }
  .table-c.stack-sm td { height: auto; padding: 2px 0; border: 0; text-align: left; }
  .table-c.stack-sm td[data-label]::before {
    content: attr(data-label) ": ";
    color: var(--text-muted);
    font-size: 13px;
  }
  .table-c.stack-sm td.actions { text-align: left; padding-top: 10px; }
  .table-c.stack-sm tbody tr:hover td { background: transparent; }
}

/* ---------- Pagination ---------- */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 8px 20px;
  border-top: 1px solid var(--row-line);
  font-size: 13px;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.pager-links { display: flex; gap: 6px; }
.pager-links a, .pager-links span {
  min-width: 32px;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  background: var(--surface);
}
.pager-links a:hover { background: var(--table-head); text-decoration: none; }
.pager-links .current { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager-links .disabled { color: #A0A9B6; }

/* ---------- Toasts ---------- */
.toast-stack {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 400px;
  max-width: calc(100vw - 32px);
}
.toast-c {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-float);
  font-size: 14px;
}
.toast-c .toast-icon { flex-shrink: 0; color: var(--success); margin-top: 1px; }
.toast-c.error .toast-icon { color: var(--danger); }
.toast-c .toast-text { flex-grow: 1; min-width: 0; }
.toast-c .toast-close { background: none; border: 0; color: var(--text-muted); padding: 0 2px; cursor: pointer; line-height: 1; }
@media (max-width: 767.98px) {
  .toast-stack { right: 16px; left: 16px; width: auto; bottom: calc(var(--bottomnav-h) + 16px); }
}

/* ---------- Auth pages ---------- */
.auth-shell { min-height: 100vh; display: flex; background: var(--bg); }
.auth-aside {
  width: 640px;
  flex-shrink: 0;
  padding: 64px;
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  flex-direction: column;
}
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-brand-name { font-size: 20px; font-weight: 600; color: #fff; }
.auth-pitch { flex-grow: 1; display: flex; flex-direction: column; justify-content: center; gap: 24px; padding: 40px 0; }
.auth-pitch h1 { margin: 0; font-size: 42px; line-height: 1.15; font-weight: 600; color: #fff; max-width: 460px; }
.auth-pitch p { margin: 0; font-size: 16px; line-height: 1.6; max-width: 440px; }
.auth-points { display: flex; flex-direction: column; gap: 14px; margin: 8px 0 0; padding: 0; list-style: none; font-size: 15px; color: #E6ECF5; }
.auth-points li { display: flex; align-items: center; gap: 12px; }
.auth-points svg { flex-shrink: 0; color: #6FA0FF; }
.auth-note { font-size: 13px; color: var(--nav-text-dim); }
.auth-main { flex-grow: 1; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  width: 420px;
  max-width: 100%;
  padding: 40px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.auth-card h2 { margin: 0; font-size: 26px; font-weight: 600; }
.auth-card .lead-c { margin: 6px 0 0; font-size: 14px; color: var(--text-muted); }
.auth-card .form-control { height: 44px; font-size: 15px; padding: 0 14px; }
.auth-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; flex-wrap: wrap; }
.auth-foot { margin: 0; font-size: 13px; color: var(--text-muted); text-align: center; }
.auth-mobile-brand { display: none; }

@media (max-width: 1199.98px) {
  .auth-aside { width: 460px; padding: 48px; }
  .auth-pitch h1 { font-size: 34px; }
}
@media (max-width: 899.98px) {
  .auth-shell { flex-direction: column; }
  .auth-aside { display: none; }
  .auth-mobile-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: 64px;
    background: var(--nav-bg);
  }
  .auth-main { align-items: flex-start; padding: 24px 16px; }
}
@media (max-width: 767.98px) {
  .auth-card { padding: 24px 20px; }
  .auth-card .form-control { height: 48px; font-size: 16px; }
}

/* ---------- Error / placeholder pages ---------- */
.notice-card { max-width: 640px; }

.validation-summary-valid { display: none !important; }
.alert-c.validation-summary-errors { display: block; }
.alert-c.validation-summary-errors ul { list-style: none; padding: 0; margin: 0; }

/* ---------- Pop-ups whose content is a form (Quick Add, Log Call) ----------
   Bootstrap's scrollable dialog expects header, body and footer directly inside .modal-content.
   When a <form> wraps them, the form must pass the height limit on, or the body cannot scroll
   and everything below the visible area (including the Save buttons) is cut off. */
.modal-content > form { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.modal-content > form > .modal-body { overflow-y: auto; }

/* ---------- To-do list ---------- */
.todo-add { display: grid; grid-template-columns: minmax(0, 1fr) 190px auto; gap: 16px; align-items: end; }
.todo-list { list-style: none; margin: 0; padding: 0; }
.todo-row { display: flex; align-items: center; gap: 14px; padding: 12px 20px; border-top: 1px solid var(--row-line); }
.todo-row form { margin: 0; }
.todo-text { flex-grow: 1; min-width: 0; }
.todo-title { font-weight: 500; overflow-wrap: anywhere; }
.todo-due { font-size: 13px; color: var(--text-muted); }
.todo-due.late { color: var(--danger); font-weight: 500; }
.todo-check {
  width: 28px; height: 28px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--border-strong); border-radius: 8px; background: var(--surface); color: transparent; cursor: pointer; padding: 0;
}
.todo-check:hover { border-color: var(--primary); color: var(--primary); }
.todo-check.on { background: var(--success); border-color: var(--success); color: #fff; }
.todo-row.done .todo-title { color: var(--text-muted); text-decoration: line-through; }
@media (max-width: 767.98px) {
  .todo-add { grid-template-columns: minmax(0, 1fr); }
  .todo-row { padding: 12px 16px; }
}

/* ---------- Users: password shown to the administrator ---------- */
.password-text { margin-left: 8px; font-weight: 500; overflow-wrap: anywhere; }

/* ---------- Facebook leads ---------- */
.lead-list { display: flex; flex-direction: column; gap: 16px; margin-top: 20px; }
.lead-card { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; padding: 20px; align-items: start; }
.lead-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.lead-name { font-size: 17px; font-weight: 600; margin: 0; overflow-wrap: anywhere; }
.lead-when { margin-left: auto; font-size: 13px; color: var(--text-muted); }
.lead-contact { display: flex; gap: 6px 16px; flex-wrap: wrap; margin-bottom: 4px; overflow-wrap: anywhere; }
.lead-phone { font-weight: 600; }
.lead-answers { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px 20px; margin: 12px 0 0; }
.lead-answers dt { font-size: 12px; font-weight: 400; color: var(--text-muted); }
.lead-answers dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.lead-dup { margin-top: 12px; }
.lead-actions { border-left: 1px solid var(--row-line); padding-left: 24px; }
.lead-dismiss { margin-top: 14px; font-size: 13px; }
.lead-dismiss summary { cursor: pointer; color: var(--text-muted); }
@media (max-width: 991.98px) {
  .lead-card { grid-template-columns: minmax(0, 1fr); gap: 16px; padding: 16px; }
  .lead-actions { border-left: 0; padding-left: 0; border-top: 1px solid var(--row-line); padding-top: 16px; }
  .lead-when { margin-left: 0; width: 100%; }
}

/* ---------- Messenger inbox ---------- */
.inbox-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.inbox-search { display: flex; gap: 8px; flex: 1 1 280px; max-width: 460px; }
.conv-list { list-style: none; margin: 0; padding: 0; }
.conv-list li + li { border-top: 1px solid var(--row-line); }
.conv-row { display: flex; align-items: center; gap: 14px; padding: 14px 20px; color: var(--text); text-decoration: none; }
.conv-row:hover { background: var(--table-head); color: var(--text); text-decoration: none; }
.conv-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.conv-name { font-weight: 500; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.conv-preview { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.conv-time { font-size: 12px; color: var(--text-muted); }
.conv-row.unread .conv-name { font-weight: 700; }
.conv-row.unread .conv-preview { color: var(--text); font-weight: 500; }

.thread-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.thread-card { display: flex; flex-direction: column; }
.thread-messages { display: flex; flex-direction: column; gap: 10px; padding: 20px; height: min(62vh, 640px); overflow-y: auto; }
.msg { display: flex; flex-direction: column; max-width: 76%; }
.msg.in { align-self: flex-start; align-items: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg-bubble { padding: 9px 13px; border-radius: 14px; background: var(--table-head); border: 1px solid var(--border); overflow-wrap: anywhere; }
.msg.out .msg-bubble { background: var(--primary); border-color: var(--primary); color: #fff; }
.msg-text { white-space: pre-wrap; }
.msg-attachment { display: inline-block; margin-top: 2px; font-weight: 500; text-decoration: underline; }
.msg.out .msg-attachment { color: #fff; }
.msg-meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.thread-reply { border-top: 1px solid var(--row-line); padding: 16px 20px; display: flex; flex-direction: column; gap: 8px; }
.reply-form { display: flex; gap: 10px; align-items: flex-end; }
.reply-form textarea { flex: 1 1 auto; resize: vertical; }
.link-list { list-style: none; margin: 14px 0 0; padding: 0; }
.link-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--row-line); }
.link-list form { margin: 0; flex-shrink: 0; }
@media (max-width: 991.98px) {
  .thread-grid { grid-template-columns: minmax(0, 1fr); }
  .thread-messages { height: 56vh; padding: 16px; }
  .msg { max-width: 88%; }
  .conv-row { padding: 12px 16px; }
  .thread-reply { padding: 12px 16px; }
}
