/* Headings, chrome, and UI use --font-body from material-tokens (system UI stack). */
html {
  overflow-x: clip;
  max-width: 100%;
}

h1, .h1, h2, .h2, h3, .h3, h4, .h4, h5, .h5, h6, .h6,
.app-sidebar .app-brand-wordmark,
.md-page-header .h2,
.md-stat-card .h4,
.md-stat-card .fw-semibold,
.btn,
.form-control,
.form-select,
.input-group-text,
.table,
.dropdown-menu {
  font-family: var(--font-body);
}

.app-body {
  margin: 0;
  overflow-x: clip;
  max-width: 100%;
  background-color: var(--md-body-bg);
  background-image:
    radial-gradient(1200px 600px at 12% -10%, var(--md-body-mesh-a), transparent 55%),
    radial-gradient(900px 500px at 88% 0%, var(--md-body-mesh-b), transparent 50%);
  color: var(--bs-body-color);
  position: relative;
}

/* Subtle film grain (SVG noise), gated for motion preference */
@media (prefers-reduced-motion: no-preference) {
  .app-body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    opacity: 0.045;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-size: 180px 180px;
  }
}

.app-body > .d-flex {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}

.app-body > .d-flex > .d-flex.flex-column {
  min-width: 0;
  overflow-x: clip;
}

.app-sidebar {
  flex: 0 0 15rem;
  width: 15rem;
  min-width: 15rem;
  background: linear-gradient(165deg, var(--md-sidebar-gradient-start) 0%, var(--md-sidebar-gradient-end) 92%);
  border-right: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.04);
}

.app-sidebar-backdrop {
  display: none;
}

.app-sidebar-toggle,
.app-sidebar-close {
  line-height: 1;
}

.app-topbar-title {
  max-width: 10rem;
  font-weight: 600;
}

@media (min-width: 768px) {
  .app-topbar-title {
    max-width: none;
    font-weight: 400;
  }
}

@media (max-width: 991.98px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1050;
    flex: none;
    width: min(14rem, 78vw);
    min-width: 0;
    max-width: 14rem;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.28);
  }

  body.app-sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  .app-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1045;
    background: rgba(8, 15, 28, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  body.app-sidebar-open .app-sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  body.app-sidebar-open {
    overflow: hidden;
  }

  .app-topbar {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
    gap: 0.5rem !important;
  }

  .app-main {
    padding: 1rem !important;
    overflow-x: auto;
  }

  .app-main-reveal {
    overflow-x: visible;
  }

  .app-topbar-actions {
    gap: 0.35rem !important;
  }

  .app-topbar .md-theme-switcher .md-theme-opt {
    font-size: 0.62rem;
    padding: 0.15rem 0.35rem;
  }

  .app-topbar .md-login-username {
    max-width: 4.5rem;
  }
}

@media (min-width: 992px) {
  .app-sidebar-toggle,
  .app-sidebar-close,
  .app-sidebar-backdrop {
    display: none !important;
  }
}

.app-brand-wordmark {
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.app-nav-link {
  color: rgba(255, 255, 255, 0.82) !important;
  border-radius: 0.375rem;
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}

@media (prefers-reduced-motion: no-preference) {
  .app-nav-link:hover,
  .app-nav-link.active {
    transform: translateX(3px);
  }
}

.app-nav-link:hover,
.app-nav-link.active {
  color: #fff !important;
  background: rgba(255, 255, 255, 0.09);
}

.app-topbar {
  min-height: 3.25rem;
  background: var(--md-topbar-bg) !important;
  border-bottom-color: var(--md-topbar-border) !important;
  backdrop-filter: blur(12px);
  /* Stack above .app-main: main comes later in DOM and stat-card transforms paint over the header otherwise. */
  position: relative;
  z-index: 1040;
  overflow: visible;
}

.app-main {
  max-width: 100%;
  min-width: 0;
  overflow-x: clip;
  position: relative;
  z-index: 0;
}

.app-main-reveal {
  min-width: 0;
  max-width: 100%;
  overflow-x: clip;
}

[data-leads-index] {
  min-width: 0;
  max-width: 100%;
}

/* Notification bell: badge must not clip; dropdown must sit above page content */
.app-notifications-dropdown {
  position: relative;
  overflow: visible;
}

.app-notifications-dropdown-toggle {
  overflow: visible !important;
}

.app-notifications-bell-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  min-width: 1.5rem;
  min-height: 1.5rem;
}

.app-notifications-badge {
  position: absolute;
  top: -0.4rem;
  right: -0.55rem;
  min-width: 1.15rem;
  padding: 0.2em 0.38em;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1.1;
  z-index: 2;
  box-shadow: 0 0 0 2px var(--md-topbar-bg, #fff);
}

.app-notifications-dropdown-menu {
  z-index: 1055 !important;
}

/* Modals must not participate in .app-main-reveal stagger (opacity/transform) or they sit under the backdrop. */
@media (prefers-reduced-motion: no-preference) {
  .app-main-reveal > .modal {
    opacity: 1 !important;
    animation: none !important;
    transform: none !important;
  }
}

/* Material dashboard sets modal and backdrop both at 1040–1050; raise so dialogs stay above shell chrome. */
.modal {
  z-index: 1090 !important;
}

.modal-backdrop {
  z-index: 1080 !important;
}

/* Staggered reveal: one orchestrated entrance (figma-ui); no JS required */
@media (prefers-reduced-motion: no-preference) {
  .app-main-reveal > * {
    opacity: 0;
    animation: md-main-rise 0.68s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  }

  .app-main-reveal > *:nth-child(1) { animation-delay: 0.05s; }
  .app-main-reveal > *:nth-child(2) { animation-delay: 0.11s; }
  .app-main-reveal > *:nth-child(3) { animation-delay: 0.17s; }
  .app-main-reveal > *:nth-child(4) { animation-delay: 0.23s; }
  .app-main-reveal > *:nth-child(5) { animation-delay: 0.29s; }
  .app-main-reveal > *:nth-child(6) { animation-delay: 0.35s; }
  .app-main-reveal > *:nth-child(7) { animation-delay: 0.41s; }
  .app-main-reveal > *:nth-child(8) { animation-delay: 0.47s; }
  .app-main-reveal > *:nth-child(n + 9) { animation-delay: 0.53s; }
}

@media (prefers-reduced-motion: reduce) {
  .app-main-reveal > * {
    opacity: 1;
    transform: none;
    animation: none;
  }
}

@keyframes md-main-rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.admin-nav-toggler {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.88);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.35rem 0.5rem;
  border-radius: 0.375rem;
  letter-spacing: -0.01em;
  transition: background 0.2s ease, color 0.2s ease;
}

.admin-nav-toggler:hover,
.admin-nav-toggler.active {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

a.admin-nav-toggler,
a.admin-nav-toggler:visited {
  text-decoration: none;
  color: rgba(255, 255, 255, 0.88);
}

a.admin-nav-toggler:hover {
  color: #fff;
}

.app-nav-sublink {
  display: block;
  padding: 0.2rem 0.5rem 0.2rem 1rem;
  color: rgba(255, 255, 255, 0.66) !important;
  text-decoration: none;
  font-size: 0.88rem;
  border-radius: 0.25rem;
  transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease;
}

@media (prefers-reduced-motion: no-preference) {
  .app-nav-sublink:hover {
    transform: translateX(2px);
  }
}

.app-nav-sublink:hover {
  color: #fff !important;
  background: rgba(255, 255, 255, 0.07);
}

.md-page-header .h2 {
  font-weight: 600;
  letter-spacing: -0.035em;
}

.md-stat-card {
  position: relative;
  background: var(--md-stat-accent);
  border-radius: 0.65rem;
  overflow: hidden;
  transition: box-shadow 0.25s ease, transform 0.25s ease;
}

.md-stat-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--md-stat-accent-b);
  pointer-events: none;
}

.md-stat-card .card-body {
  position: relative;
  z-index: 1;
}

@media (prefers-reduced-motion: no-preference) {
  .md-stat-row > div:nth-child(3n + 1) .md-stat-card { transform: rotate(-0.65deg); }
  .md-stat-row > div:nth-child(3n + 2) .md-stat-card { transform: rotate(0.35deg); }
  .md-stat-row > div:nth-child(3n + 3) .md-stat-card { transform: rotate(-0.25deg); }

  .md-stat-row .md-stat-card:hover {
    transform: translateY(-4px) scale(1.01) rotate(0deg);
    box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.25);
  }
}

.md-content-card {
  background: var(--md-card-bg);
  box-shadow: var(--md-card-shadow);
  border-radius: 0.65rem;
  overflow: hidden;
  backdrop-filter: blur(8px);
  transition: box-shadow 0.25s ease, transform 0.25s ease;
}

@media (prefers-reduced-motion: no-preference) {
  .md-content-card:hover {
    box-shadow: var(--md-card-shadow), 0 0 0 1px rgba(var(--md-primary-rgb), 0.12);
  }
}

.md-content-card-header {
  background: linear-gradient(100deg, rgba(var(--md-primary-rgb), 0.14) 0%, transparent 62%);
  color: var(--bs-body-color);
  font-family: var(--font-body);
  letter-spacing: -0.02em;
}

/* Header theme pills: smaller, each hue matches the shell it selects */
.md-theme-switcher .md-theme-opt {
  font-family: var(--font-body);
  letter-spacing: 0.01em;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.2;
  padding: 0.2rem 0.45rem;
  border-radius: 0.3rem;
  border-width: 1.5px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.md-theme-switcher .md-theme-opt-studio {
  border-color: rgba(217, 72, 38, 0.55);
  color: #a63a1f;
  background: rgba(217, 72, 38, 0.1);
}

.md-theme-switcher .md-theme-opt-night {
  border-color: rgba(90, 104, 140, 0.65);
  color: #4a5572;
  background: rgba(90, 104, 140, 0.12);
}

.md-theme-switcher .md-theme-opt-signature {
  border-color: rgba(15, 118, 110, 0.55);
  color: #0d5c56;
  background: rgba(15, 118, 110, 0.1);
}

[data-bs-theme="dark"] .md-theme-switcher .md-theme-opt-studio {
  color: #ffb39a;
  border-color: rgba(255, 138, 101, 0.45);
  background: rgba(255, 138, 101, 0.1);
}

[data-bs-theme="dark"] .md-theme-switcher .md-theme-opt-night {
  color: #c5cee0;
  border-color: rgba(154, 164, 178, 0.45);
  background: rgba(120, 135, 165, 0.15);
}

[data-bs-theme="dark"] .md-theme-switcher .md-theme-opt-signature {
  color: #7dd3c0;
  border-color: rgba(45, 212, 191, 0.35);
  background: rgba(13, 148, 136, 0.18);
}

.md-theme-switcher .md-theme-opt-active.md-theme-opt-studio {
  background: #d94826;
  border-color: #c23d18;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.md-theme-switcher .md-theme-opt-active.md-theme-opt-night {
  background: #4a5578;
  border-color: #3d4660;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.md-theme-switcher .md-theme-opt-active.md-theme-opt-signature {
  background: #0f766e;
  border-color: #0d5c56;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.md-header-signout {
  min-width: 2rem;
}

html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem rgba(var(--md-primary-rgb), 0.35);
}

.btn-primary {
  background-color: var(--md-primary);
  border-color: var(--md-primary);
}

.btn-primary:hover, .btn-primary:focus {
  background-color: var(--md-primary);
  border-color: var(--md-primary);
  filter: brightness(0.94);
}

html {
  position: relative;
  min-height: 100%;
}

body.app-body {
  margin-bottom: 0;
  font-family: var(--font-body);
}

/*
  Material Dashboard uses no horizontal padding on default .form-control, padding-left: 0 on .form-select,
  and border-color: transparent on :focus. Restore visible borders and comfortable text insets app-wide.
*/
.app-body .form-control:not(.form-control-plaintext),
.app-body textarea.form-control {
  border: 1px solid var(--bs-border-color);
  background-color: var(--bs-body-bg);
}

.app-body .form-control:not(.form-control-plaintext):not(.form-control-sm):not(.form-control-lg),
.app-body textarea.form-control:not(.form-control-sm):not(.form-control-lg) {
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

.app-body .form-control:not(.form-control-plaintext):focus,
.app-body textarea.form-control:focus {
  border-color: rgba(var(--md-primary-rgb), 0.55);
  box-shadow: 0 0 0 0.1rem var(--bs-body-bg), 0 0 0 0.25rem rgba(var(--md-primary-rgb), 0.28);
  outline: 0;
}

.app-body .form-control:not(.form-control-plaintext):disabled,
.app-body textarea.form-control:disabled {
  border-color: var(--bs-border-color);
}

.app-body .form-select {
  padding-left: 0.75rem;
  padding-right: 2.25rem;
  border: 1px solid var(--bs-border-color);
  background-color: var(--bs-body-bg);
  background-position: right 0.65rem center;
}

.app-body .form-select:focus {
  border-color: rgba(var(--md-primary-rgb), 0.55);
  box-shadow: 0 0 0 0.1rem var(--bs-body-bg), 0 0 0 0.25rem rgba(var(--md-primary-rgb), 0.28);
  outline: 0;
}

.app-body .form-select[multiple],
.app-body .form-select[size]:not([size="1"]) {
  padding-right: 0.75rem;
}

.app-body .form-select-sm {
  padding-left: 0.75rem;
  padding-right: 2rem;
  background-position: right 0.5rem center;
}

.app-body .form-select-lg {
  padding-left: 0.875rem;
  padding-right: 2.5rem;
  background-position: right 0.75rem center;
}

.app-body .dataTable-selector {
  padding-left: 0.75rem;
  padding-right: 0.75rem;
  border: 1px solid var(--bs-border-color);
  border-radius: 0.375rem;
  background-color: var(--bs-body-bg);
}

.app-body .dataTable-input {
  border: 1px solid var(--bs-border-color);
  background-color: var(--bs-body-bg);
}

.form-floating > .form-control-plaintext::placeholder, .form-floating > .form-control::placeholder {
  color: var(--bs-secondary-color);
  text-align: end;
}

.form-floating > .form-control-plaintext:focus::placeholder, .form-floating > .form-control:focus::placeholder {
  text-align: start;
}

/* In-app notification HTML bodies (trusted admin content) */
.app-body .notification-html img,
.app-body .notification-html video {
  max-width: 100%;
  height: auto;
}

.app-body .notification-html p:last-child {
  margin-bottom: 0;
}
