/* ==========================================================================
   EdgeSync shared base theme
   One source of truth for colour, type, radius, shadow and focus across:
   Portal, RMS, Batch Processing, Bulk Mailer, Payment Plans (PPP).

   Load it AFTER Bootstrap (where Bootstrap is used) and BEFORE each page's
   own <style> block, so page styles can still override when needed.

   To re-brand every app at once, change the values in the SEMANTIC section.
   ========================================================================== */

:root {
  /* ---------- Primitives (raw palette — don't use directly in pages) ---------- */
  --es-navy-950: #020617;
  --es-navy-900: #0f172a;
  --es-navy-800: #1e293b;
  --es-navy-700: #334155;
  --es-slate-600: #475569;
  --es-slate-500: #64748b;
  --es-slate-400: #94a3b8;
  --es-slate-300: #cbd5e1;
  --es-slate-200: #e2e8f0;
  --es-slate-100: #f1f5f9;
  --es-slate-50:  #f8fafc;

  --es-blue-700: #1d4ed8;
  --es-blue-600: #2563eb;
  --es-blue-200: #bfdbfe;
  --es-blue-50:  #eff6ff;

  --es-green-800: #166534;
  --es-green-700: #15803d;
  --es-green-600: #16a34a;
  --es-green-100: #dcfce7;
  --es-green-50:  #f0fdf4;

  --es-red-800: #991b1b;
  --es-red-700: #b91c1c;
  --es-red-600: #dc2626;
  --es-red-100: #fee2e2;
  --es-red-50:  #fef2f2;

  --es-amber-800: #92400e;
  --es-amber-600: #d97706;
  --es-amber-100: #fef3c7;
  --es-amber-50:  #fffbeb;

  --es-sky-800: #075985;
  --es-sky-600: #0284c7;
  --es-sky-100: #e0f2fe;

  /* ---------- Semantic tokens (use these in pages) ---------- */
  /* App chrome: header bar, sidebar */
  --es-chrome:        var(--es-navy-900);
  --es-chrome-2:      var(--es-navy-800);
  --es-chrome-fg:     #ffffff;
  --es-chrome-muted:  var(--es-slate-300);
  --es-chrome-line:   rgba(255, 255, 255, 0.12);
  --es-chrome-hover:  rgba(255, 255, 255, 0.08);

  /* Actions */
  --es-primary:       var(--es-blue-600);
  --es-primary-hover: var(--es-blue-700);
  --es-primary-soft:  var(--es-blue-50);
  --es-primary-line:  var(--es-blue-200);
  --es-on-primary:    #ffffff;

  /* Status */
  --es-success:       var(--es-green-600);
  --es-success-hover: var(--es-green-700);
  --es-success-soft:  var(--es-green-100);
  --es-success-ink:   var(--es-green-800);
  --es-danger:        var(--es-red-600);
  --es-danger-hover:  var(--es-red-700);
  --es-danger-soft:   var(--es-red-100);
  --es-danger-ink:    var(--es-red-800);
  --es-warning:       var(--es-amber-600);
  --es-warning-soft:  var(--es-amber-100);
  --es-warning-ink:   var(--es-amber-800);
  --es-info:          var(--es-sky-600);
  --es-info-soft:     var(--es-sky-100);
  --es-info-ink:      var(--es-sky-800);

  /* Surfaces & text */
  --es-bg:            var(--es-slate-100);
  --es-surface:       #ffffff;
  --es-surface-2:     var(--es-slate-50);
  --es-ink:           var(--es-navy-900);
  --es-ink-2:         var(--es-navy-700);
  --es-muted:         var(--es-slate-500);   /* 4.76:1 on white — passes AA */
  --es-border:        var(--es-slate-200);
  --es-border-strong: var(--es-slate-300);

  /* Tables */
  --es-table-head-bg: var(--es-slate-100);
  --es-table-head-fg: var(--es-navy-800);
  --es-table-stripe:  var(--es-slate-50);
  --es-table-hover:   var(--es-blue-50);

  /* Shape, depth, motion */
  --es-radius-sm: 6px;
  --es-radius:    8px;
  --es-radius-lg: 12px;
  --es-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --es-shadow:    0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --es-shadow-lg: 0 10px 25px rgba(15, 23, 42, 0.10);
  --es-ring:      0 0 0 3px rgba(37, 99, 235, 0.35);
  --es-dur:       150ms;
  --es-ease:      cubic-bezier(0.2, 0, 0, 1);

  /* Type */
  --es-font: 'Fira Sans', 'Segoe UI', system-ui, -apple-system, Roboto, 'Helvetica Neue', Arial, sans-serif;
  --es-font-mono: 'Fira Code', ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', monospace;

  /* Layout */
  --es-appbar-h: 64px;

  /* ---------- Bootstrap 5.3 remap (RMS + Portal pages) ---------- */
  --bs-primary: #2563eb;
  --bs-primary-rgb: 37, 99, 235;
  --bs-primary-text-emphasis: #1e40af;
  --bs-primary-bg-subtle: #eff6ff;
  --bs-primary-border-subtle: #bfdbfe;
  --bs-success: #16a34a;
  --bs-success-rgb: 22, 163, 74;
  --bs-danger: #dc2626;
  --bs-danger-rgb: 220, 38, 38;
  --bs-warning: #d97706;
  --bs-warning-rgb: 217, 119, 6;
  --bs-info: #0284c7;
  --bs-info-rgb: 2, 132, 199;
  --bs-secondary: #64748b;
  --bs-secondary-rgb: 100, 116, 139;
  --bs-dark: #0f172a;
  --bs-dark-rgb: 15, 23, 42;
  --bs-light: #f8fafc;
  --bs-light-rgb: 248, 250, 252;
  --bs-body-font-family: var(--es-font);
  --bs-body-color: #0f172a;
  --bs-body-color-rgb: 15, 23, 42;
  --bs-body-bg: #f1f5f9;
  --bs-body-bg-rgb: 241, 245, 249;
  --bs-secondary-color: rgba(15, 23, 42, 0.72);
  --bs-border-color: #e2e8f0;
  --bs-border-radius: 8px;
  --bs-border-radius-lg: 12px;
  --bs-link-color: #2563eb;
  --bs-link-color-rgb: 37, 99, 235;
  --bs-link-hover-color: #1d4ed8;
  --bs-link-hover-color-rgb: 29, 78, 216;
  --bs-focus-ring-color: rgba(37, 99, 235, 0.35);
}

/* Bootstrap component colours (5.3 sets these per class, so remap here) */
.btn-primary {
  --bs-btn-bg: var(--es-primary);            --bs-btn-border-color: var(--es-primary);
  --bs-btn-hover-bg: var(--es-primary-hover); --bs-btn-hover-border-color: var(--es-primary-hover);
  --bs-btn-active-bg: var(--es-primary-hover);--bs-btn-active-border-color: var(--es-primary-hover);
  --bs-btn-disabled-bg: var(--es-primary);   --bs-btn-disabled-border-color: var(--es-primary);
  --bs-btn-focus-shadow-rgb: 37, 99, 235;
}
.btn-outline-primary {
  --bs-btn-color: var(--es-primary);          --bs-btn-border-color: var(--es-primary);
  --bs-btn-hover-bg: var(--es-primary);       --bs-btn-hover-border-color: var(--es-primary);
  --bs-btn-active-bg: var(--es-primary-hover);--bs-btn-active-border-color: var(--es-primary-hover);
  --bs-btn-focus-shadow-rgb: 37, 99, 235;
}
.btn-success {
  --bs-btn-bg: var(--es-success);             --bs-btn-border-color: var(--es-success);
  --bs-btn-hover-bg: var(--es-success-hover); --bs-btn-hover-border-color: var(--es-success-hover);
  --bs-btn-active-bg: var(--es-success-hover);--bs-btn-active-border-color: var(--es-success-hover);
  --bs-btn-disabled-bg: var(--es-success);    --bs-btn-disabled-border-color: var(--es-success);
}
.btn-outline-success {
  --bs-btn-color: var(--es-success);          --bs-btn-border-color: var(--es-success);
  --bs-btn-hover-bg: var(--es-success);       --bs-btn-hover-border-color: var(--es-success);
  --bs-btn-active-bg: var(--es-success-hover);
}
.btn-danger {
  --bs-btn-bg: var(--es-danger);              --bs-btn-border-color: var(--es-danger);
  --bs-btn-hover-bg: var(--es-danger-hover);  --bs-btn-hover-border-color: var(--es-danger-hover);
  --bs-btn-active-bg: var(--es-danger-hover); --bs-btn-active-border-color: var(--es-danger-hover);
  --bs-btn-disabled-bg: var(--es-danger);     --bs-btn-disabled-border-color: var(--es-danger);
}
.btn-outline-danger {
  --bs-btn-color: var(--es-danger);           --bs-btn-border-color: var(--es-danger);
  --bs-btn-hover-bg: var(--es-danger);        --bs-btn-hover-border-color: var(--es-danger);
  --bs-btn-active-bg: var(--es-danger-hover);
}
.btn-secondary {
  --bs-btn-bg: var(--es-slate-600);           --bs-btn-border-color: var(--es-slate-600);
  --bs-btn-hover-bg: var(--es-navy-700);      --bs-btn-hover-border-color: var(--es-navy-700);
  --bs-btn-active-bg: var(--es-navy-700);
}
.btn-dark {
  --bs-btn-bg: var(--es-navy-900);            --bs-btn-border-color: var(--es-navy-900);
  --bs-btn-hover-bg: var(--es-navy-800);      --bs-btn-hover-border-color: var(--es-navy-800);
}
.form-control:focus,
.form-select:focus {
  border-color: var(--es-primary);
  box-shadow: var(--es-ring);
}
.form-check-input:checked {
  background-color: var(--es-primary);
  border-color: var(--es-primary);
}
.page-link { --bs-pagination-color: var(--es-primary); }
.pagination {
  --bs-pagination-active-bg: var(--es-primary);
  --bs-pagination-active-border-color: var(--es-primary);
  --bs-pagination-focus-box-shadow: var(--es-ring);
}
.nav-pills { --bs-nav-pills-link-active-bg: var(--es-primary); }
.card { --bs-card-border-color: var(--es-border); --bs-card-border-radius: var(--es-radius-lg); }

/* ==========================================================================
   Safe global base (applies to every app, incl. non-Bootstrap pages)
   ========================================================================== */
body {
  font-family: var(--es-font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Numbers line up in columns */
table { font-variant-numeric: tabular-nums; }

/* Visible keyboard focus everywhere (mouse clicks don't show the ring) */
:where(a, button, input, select, textarea, [tabindex], summary):focus-visible {
  outline: 2px solid var(--es-primary);
  outline-offset: 2px;
}

/* Anything clickable gets the pointer */
:where(button, [role="button"], summary, label[for], select):not(:disabled) { cursor: pointer; }
:where(button, input, select, textarea):disabled { cursor: not-allowed; }

/* Skip link — hidden until a keyboard user tabs to it */
.es-skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  z-index: 2000;
  padding: 10px 16px;
  border-radius: var(--es-radius);
  background: var(--es-surface);
  color: var(--es-ink);
  font-weight: 600;
  text-decoration: none;
  box-shadow: var(--es-shadow-lg);
  transition: top var(--es-dur) var(--es-ease);
}
.es-skip-link:focus { top: 12px; }

/* ==========================================================================
   Shared app header — same bar in every app
   Usage: <header class="es-appbar"> ... </header>
   (On Bootstrap pages add it to the existing <nav class="navbar">.)
   ========================================================================== */
.es-appbar {
  background: var(--es-chrome) !important;
  color: var(--es-chrome-fg);
  min-height: var(--es-appbar-h);
  border-bottom: 1px solid var(--es-chrome-line);
  box-shadow: 0 1px 0 rgba(2, 6, 23, 0.4), 0 4px 14px rgba(2, 6, 23, 0.12);
}
.es-appbar .es-brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--es-chrome-fg);
  text-decoration: none;
}
.es-appbar .es-brand img { height: 40px; width: auto; display: block; }
.es-appbar .es-app-name {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.1px;
  color: var(--es-chrome-fg);
  padding-left: 12px;
  border-left: 1px solid var(--es-chrome-line);
  white-space: nowrap;
}

/* "All apps" link back to the Portal — same spot in every app */
.es-apps-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--es-radius);
  border: 1px solid var(--es-chrome-line);
  background: transparent;
  color: var(--es-chrome-fg) !important;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color var(--es-dur) var(--es-ease), border-color var(--es-dur) var(--es-ease);
}
.es-apps-link:hover { background: var(--es-chrome-hover); border-color: rgba(255, 255, 255, 0.24); }
.es-apps-link i { margin-right: 0 !important; }

/* Bootstrap navbar links inside the app bar */
.es-appbar .navbar-nav .nav-link {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 14px !important;
  border-radius: var(--es-radius);
  color: var(--es-chrome-muted);
  font-weight: 500;
  transition: background-color var(--es-dur) var(--es-ease), color var(--es-dur) var(--es-ease);
}
.es-appbar .navbar-nav .nav-link:hover { color: var(--es-chrome-fg); background: var(--es-chrome-hover); }
.es-appbar .navbar-nav .nav-link.active {
  color: var(--es-chrome-fg);
  background: var(--es-primary);
}
.es-appbar .navbar-nav { gap: 4px; }

/* ==========================================================================
   Reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   "Made with love by LedgerPoint" credit
   Use --on-light on light backgrounds, --on-dark on navy footers/sidebars.
   ========================================================================== */
.es-sr {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}
.es-madeby {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 2px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1;
  text-decoration: none !important;
  opacity: 0.85;
  transition: opacity var(--es-dur) var(--es-ease);
}
.es-madeby:hover { opacity: 1; }
.es-madeby img {
  display: block;
  height: 14px;
  width: auto;
  flex-shrink: 0;
}
.es-madeby .es-heart {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  fill: currentColor;
  stroke: none;
}
.es-madeby--on-light { color: var(--es-muted) !important; }
.es-madeby--on-light .es-heart { color: #e11d48; }
.es-madeby--on-dark  { color: var(--es-slate-400) !important; }
.es-madeby--on-dark  .es-heart { color: #fb7185; }
