/*
 * Kilimo Makueni — Backoffice Enhancement Stylesheet
 * Overlays DashLite with the agricultural palette used by the landing site
 * and a uniform typography scale. Loads AFTER dashlite.css + theme.css so
 * rules here win on conflict.
 */

:root {
  --km-primary: #14532d;
  --km-primary-600: #166534;
  --km-primary-700: #14532d;
  --km-leaf: #22c55e;
  --km-leaf-600: #16a34a;
  --km-harvest: #f59e0b;
  --km-harvest-600: #d97706;
  --km-cream: #fdfbf5;
  --km-ink: #1f2937;
  --km-muted: #64748b;
  --km-border: #e5e7eb;
  --km-surface: #ffffff;
  --km-surface-soft: #f6faf4;
  --km-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
  --km-shadow-lg: 0 14px 40px rgba(15, 23, 42, 0.08);
  --km-radius: 10px;
  --km-radius-lg: 14px;
  --km-ease: cubic-bezier(0.2, 0.7, 0.2, 1);

  --km-font: "Inter", "Roboto", "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --km-font-display: "Poppins", "Inter", "Helvetica Neue", Arial, sans-serif;
  --km-font-read: "Open Sans", "Inter", "Roboto", "Helvetica Neue", Arial, sans-serif;
  --km-font-mono: ui-monospace, SFMono-Regular, Menlo, monospace;

  --bs-primary: var(--km-primary);
  --bs-primary-rgb: 20, 83, 45;
  --bs-success: var(--km-leaf-600);
  --bs-success-rgb: 22, 163, 74;
  --bs-warning: var(--km-harvest);
  --bs-warning-rgb: 245, 158, 11;
  --bs-body-font-family: var(--km-font);
}

/* Back-compat: pages that hardcode .jost get the new body family */
.jost {
  font-family: var(--km-font) !important;
  font-feature-settings: "ss01", "cv02", "cv11";
}
/* Headings with .jost take the display family (Poppins) — matches landing */
h1.jost, h2.jost, h3.jost, h4.jost,
.display-1.jost, .display-2.jost, .display-3.jost,
.display-4.jost, .display-5.jost, .display-6.jost {
  font-family: var(--km-font-display) !important;
}

/* Typography utility roles */
.font-display { font-family: var(--km-font-display) !important; letter-spacing: -0.01em; }
.font-read    { font-family: var(--km-font-read) !important; line-height: 1.7; }
.font-body    { font-family: var(--km-font) !important; }

/* ---------- Base ---------- */
body.nk-body,
body {
  background-color: #f5f7f3 !important;
  color: var(--km-ink);
  font-family: var(--km-font) !important;
  font-size: 16px !important;
  line-height: 1.6 !important;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern", "liga", "cv11";
}

/* Force the body family on text elements. Never target pseudo-elements or
   icon classes here — DashLite's Nioicon (`.ni`) and other icon fonts rely
   on font-family declarations on `.ni`, `.fa`, `[class^="bi-"]`, etc. */
.nk-header,
.nk-sidebar,
.nk-content,
.nk-footer,
.nk-menu,
.nk-menu-link,
.nk-menu-text,
.nk-tb-list,
.nk-block-title,
.card,
.card-title,
.card-amount,
.btn,
.form-control,
.form-select,
input,
select,
textarea,
button,
table,
.table,
.dropdown-menu,
.dropdown-item,
.breadcrumb,
.badge,
.alert,
.title,
.subtitle,
.overline-title,
.amount,
.lead-text,
.sub-text,
.user-name,
.user-status,
p, span, a, label, li, td, th, div {
  font-family: var(--km-font);
}

/* Preserve icon fonts — these must always win over the overrides above */
.icon,
.ni,
em.icon,
[class^="ni-"],
[class*=" ni-"],
.fa,
.fab,
.fas,
.far,
.fal,
.fad,
[class^="fa-"],
[class*=" fa-"],
[class^="bi-"],
[class*=" bi-"] {
  font-family: inherit;
}
.ni,
em.icon.ni,
[class^="ni-"],
[class*=" ni-"] {
  font-family: "Nioicon" !important;
}
.fa, .fab, .fas, .far, .fal, .fad,
[class^="fa-"], [class*=" fa-"] {
  font-family: "Font Awesome 5 Free", "FontAwesome" !important;
}
[class^="bi-"],
[class*=" bi-"] {
  font-family: "bootstrap-icons" !important;
}

a { color: var(--km-primary); }
a:hover { color: var(--km-primary-600); text-decoration: none; }

::selection { background: rgba(20, 83, 45, 0.18); color: var(--km-primary); }

/* Skip link — mirrors the landing version */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--km-primary);
  color: #fff;
  padding: 10px 16px;
  z-index: 10000;
  border-radius: 0 0 8px 0;
  text-decoration: none;
  font-weight: 600;
}
.skip-link:focus {
  left: 0;
  color: #fff;
}

/* Keyboard focus rings — DashLite strips outline globally; restore for keyboard users */
:focus-visible {
  outline: 2px solid var(--km-leaf-600) !important;
  outline-offset: 2px;
  border-radius: 4px;
}
.btn:focus-visible,
.nk-menu-link:focus-visible,
.dropdown-item:focus-visible {
  outline-offset: 3px !important;
}
.form-control:focus-visible,
.form-select:focus-visible {
  outline: none !important;
}

/* ---------- Typography scale (mirrors landing-enhance.css) ----------
   h1–h4 and page-titles take Poppins for confident section headings.
   h5–h6 stay on Inter for UI density (form labels, card subtitles, etc.). */
h1, h2, h3, h4,
.h1, .h2, .h3, .h4,
.nk-block-title,
.title {
  font-family: var(--km-font-display) !important;
  color: var(--km-ink);
}
h5, h6, .h5, .h6 {
  font-family: var(--km-font) !important;
  color: var(--km-ink);
}
h1, .h1 {
  font-size: clamp(1.9rem, 1.4rem + 1.4vw, 2.4rem);
  font-weight: 700;
  line-height: 1.18;
  letter-spacing: -0.02em;
}
h2, .h2 {
  font-size: clamp(1.5rem, 1.2rem + 0.9vw, 1.95rem);
  font-weight: 700;
  line-height: 1.22;
  letter-spacing: -0.015em;
}
h3, .h3 {
  font-size: clamp(1.25rem, 1.05rem + 0.6vw, 1.5rem);
  font-weight: 600;
  line-height: 1.28;
  letter-spacing: -0.01em;
}
h4, .h4 {
  font-size: clamp(1.1rem, 1rem + 0.3vw, 1.28rem);
  font-weight: 600;
  line-height: 1.32;
  letter-spacing: -0.005em;
}
h5, .h5 {
  font-size: clamp(1rem, 0.95rem + 0.2vw, 1.12rem);
  font-weight: 600;
  line-height: 1.4;
}
h6, .h6 {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: 0.02em;
}

/* Stat-card amounts feel more confident in Poppins */
.quickstats .card-amount .amount,
.card-amount .amount {
  font-family: var(--km-font-display) !important;
}

/* Numeric UI — tabular figures stabilise stats + table columns */
.amount,
.counter,
.nk-tb-col.text-right,
.nk-tb-col.text-end,
.fs-1,
.fs-2,
table td, table th {
  font-variant-numeric: tabular-nums;
}

/* DashLite-specific header/title tokens — align to the scale */
.nk-block-title.page-title,
.page-title {
  font-size: clamp(1.25rem, 1.05rem + 0.6vw, 1.55rem) !important;
  font-weight: 700;
}
.lead-text { font-size: 0.95rem; font-weight: 600; }
.sub-text { font-size: 0.85rem; color: var(--km-muted); }
.subtitle {
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.2px;
  text-transform: none;
  color: var(--km-muted);
}
.overline-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--km-muted) !important;
  text-transform: uppercase;
}

/* Bootstrap display + fs-* utilities — match landing */
.display-1 { font-size: clamp(2.1rem, 1.4rem + 2.4vw, 3.2rem); font-weight: 700; line-height: 1.1; }
.display-2 { font-size: clamp(2rem, 1.4rem + 2vw, 2.9rem); font-weight: 700; line-height: 1.1; }
.display-3 { font-size: clamp(1.9rem, 1.35rem + 1.8vw, 2.7rem); font-weight: 700; line-height: 1.12; }
.display-4 { font-size: clamp(1.8rem, 1.3rem + 1.5vw, 2.4rem); font-weight: 700; line-height: 1.14; }
.display-5 { font-size: clamp(1.7rem, 1.3rem + 1.2vw, 2.2rem); font-weight: 700; line-height: 1.16; }
.display-6 { font-size: clamp(1.5rem, 1.2rem + 0.9vw, 1.95rem); font-weight: 700; line-height: 1.18; }

.fs-1 { font-size: clamp(1.65rem, 1.25rem + 1.2vw, 2.1rem) !important; }
.fs-2 { font-size: clamp(1.4rem, 1.1rem + 0.9vw, 1.75rem) !important; }
.fs-3 { font-size: clamp(1.2rem, 1rem + 0.6vw, 1.5rem) !important; }
.fs-4 { font-size: clamp(1.05rem, 0.95rem + 0.4vw, 1.25rem) !important; }
.fs-5 { font-size: 1rem !important; }
.fs-6 { font-size: 0.9rem !important; }

/* ---------- Sidebar ---------- */
.nk-sidebar {
  background: #ffffff !important;
  border-right: 1px solid var(--km-border);
  box-shadow: 0 0 0 1px transparent;
}
.nk-sidebar-head {
  border-bottom: 1px solid var(--km-border);
}
.nk-menu .nk-menu-link {
  color: #334155;
  font-size: 0.92rem;
  font-weight: 500;
  border-radius: 8px;
  margin: 2px 8px;
  padding: 9px 14px;
  transition: background 0.2s var(--km-ease), color 0.2s var(--km-ease);
}
.nk-menu-text { font-size: 0.92rem; }
.nk-menu .nk-menu-link:hover {
  background: rgba(22, 163, 74, 0.08);
  color: var(--km-primary);
}
.nk-menu .nk-menu-icon .icon {
  color: #64748b;
  transition: color 0.2s var(--km-ease);
}
.nk-menu .nk-menu-link:hover .nk-menu-icon .icon,
.nk-menu .nk-menu-item.active > .nk-menu-link .nk-menu-icon .icon,
.nk-menu .nk-menu-item.current-menu > .nk-menu-link .nk-menu-icon .icon {
  color: var(--km-primary);
}
.nk-menu .nk-menu-item.active > .nk-menu-link,
.nk-menu .nk-menu-item.current-menu > .nk-menu-link {
  background: linear-gradient(90deg, rgba(22, 163, 74, 0.1), transparent 80%);
  color: var(--km-primary);
  font-weight: 600;
  position: relative;
}
.nk-menu .nk-menu-item.active > .nk-menu-link::before,
.nk-menu .nk-menu-item.current-menu > .nk-menu-link::before {
  content: "";
  position: absolute;
  left: -8px;
  top: 10%;
  bottom: 10%;
  width: 3px;
  background: var(--km-primary);
  border-radius: 3px;
}
.nk-menu-sub .nk-menu-link {
  font-size: 0.85rem;
  padding: 7px 12px 7px 42px;
  margin: 1px 8px;
  font-weight: 400;
}
.nk-menu-heading .overline-title {
  padding: 8px 16px;
  color: var(--km-muted) !important;
}

/* ---------- Header ---------- */
.nk-header.nk-header-fixed {
  background: rgba(255, 255, 255, 0.92) !important;
  backdrop-filter: saturate(1.2) blur(6px);
  border-bottom: 1px solid var(--km-border);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
}

/* DashLite clears the fixed header via `.nk-header-fixed + .nk-content { margin-top: 65px }`
   — an adjacent-sibling selector. Our skip-link anchor sits between those two elements,
   breaking that selector. Use the general-sibling selector so clearance always applies,
   and make the anchor layout-neutral. */
.nk-header-fixed ~ .nk-content {
  margin-top: 65px;
  position: relative;
}
#main-content {
  display: block;
  height: 0;
  width: 0;
  overflow: hidden;
}
.nk-header .user-name { color: var(--km-ink); font-weight: 600; font-size: 0.9rem; }
.nk-header .user-status { color: var(--km-muted); font-size: 0.72rem; letter-spacing: 0.3px; font-weight: 500; }
.nk-header .user-avatar {
  background: linear-gradient(135deg, var(--km-primary), var(--km-leaf-600));
  color: #fff;
}
.nk-header .user-avatar .icon { color: #fff; }

/* ---------- Cards ---------- */
.card,
.card-bordered {
  border: 1px solid var(--km-border) !important;
  border-radius: var(--km-radius) !important;
  box-shadow: var(--km-shadow);
  transition: transform 0.25s var(--km-ease), box-shadow 0.25s var(--km-ease);
}
.card.card-bordered:hover,
.quickstats .card:hover {
  transform: translateY(-2px);
  box-shadow: var(--km-shadow-lg);
}
.card-inner { padding: 1.1rem 1.25rem; }
.card-title .title,
.card-title h6 { color: var(--km-ink); }

/* Stat cards (dashboard) */
.quickstats .card { background: #fff; }
.quickstats .card-amount .amount {
  font-size: clamp(1.4rem, 1.1rem + 0.9vw, 1.9rem);
  font-weight: 700;
  color: var(--km-primary) !important;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.quickstats .subtitle {
  font-size: 0.78rem;
  color: var(--km-muted);
  font-weight: 500;
}

/* ---------- Buttons ---------- */
.btn {
  border-radius: 8px;
  font-weight: 500;
  letter-spacing: 0.2px;
  transition: background 0.2s var(--km-ease), color 0.2s var(--km-ease),
    box-shadow 0.2s var(--km-ease), transform 0.2s var(--km-ease);
}
.btn:hover { transform: translateY(-1px); }

.btn-primary {
  background: var(--km-primary) !important;
  border-color: var(--km-primary) !important;
  color: #fff !important;
}
.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
  background: var(--km-leaf-600) !important;
  border-color: var(--km-leaf-600) !important;
  color: #fff !important;
  box-shadow: 0 8px 18px rgba(22, 163, 74, 0.28) !important;
}

.btn-success {
  background: var(--km-leaf-600) !important;
  border-color: var(--km-leaf-600) !important;
  color: #fff !important;
}
.btn-success:hover,
.btn-success:focus,
.btn-success:active {
  background: var(--km-primary) !important;
  border-color: var(--km-primary) !important;
  color: #fff !important;
  box-shadow: 0 8px 18px rgba(20, 83, 45, 0.25) !important;
}

.btn-warning {
  background: var(--km-harvest) !important;
  border-color: var(--km-harvest) !important;
  color: #3a2500 !important;
}
.btn-warning:hover,
.btn-warning:focus,
.btn-warning:active {
  background: var(--km-harvest-600) !important;
  border-color: var(--km-harvest-600) !important;
  color: #fff !important;
  box-shadow: 0 8px 18px rgba(217, 119, 6, 0.28) !important;
}

.btn-dim.btn-primary {
  background: rgba(20, 83, 45, 0.08) !important;
  color: var(--km-primary) !important;
  border: 1px solid transparent !important;
}
.btn-dim.btn-primary:hover {
  background: var(--km-leaf-600) !important;
  color: #fff !important;
  border-color: var(--km-leaf-600) !important;
}

.btn-outline-primary,
.btn-outline-light {
  border-color: var(--km-border) !important;
  color: var(--km-primary) !important;
  background: transparent !important;
}
.btn-outline-primary:hover,
.btn-outline-primary:focus {
  background: var(--km-leaf-600) !important;
  border-color: var(--km-leaf-600) !important;
  color: #fff !important;
}

/* Primary utility classes */
.bg-primary { background-color: var(--km-primary) !important; }
.bg-primary-dim { background-color: rgba(20, 83, 45, 0.08) !important; }
.text-primary { color: var(--km-primary) !important; }
.text-success { color: var(--km-leaf-600) !important; }
.border-primary { border-color: var(--km-primary) !important; }

/* Links in links, legacy blue color from dashlite */
.link-primary { color: var(--km-primary) !important; }
.link-primary:hover { color: var(--km-primary-600) !important; }

/* ---------- Forms ---------- */
.form-control,
.form-select,
.custom-select {
  border-radius: 8px;
  border-color: var(--km-border);
  transition: border-color 0.2s var(--km-ease), box-shadow 0.2s var(--km-ease);
}
.form-control:focus,
.form-select:focus {
  border-color: var(--km-leaf-600) !important;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15) !important;
}
.form-label { font-weight: 600; color: var(--km-ink); font-size: 0.85rem; }

/* ---------- Tables ---------- */
.table {
  color: var(--km-ink);
  font-size: 0.9rem;
}
.table thead th,
.nk-tb-head .nk-tb-col {
  color: var(--km-muted);
  font-weight: 600;
  font-size: 0.72rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--km-border);
  background: #f8faf6;
}
.table tbody tr,
.nk-tb-list .nk-tb-item {
  transition: background 0.15s var(--km-ease);
}
.table tbody tr:hover,
.nk-tb-list .nk-tb-item:hover {
  background: rgba(22, 163, 74, 0.04);
}
.nk-tb-list .nk-tb-col { font-size: 0.88rem; }

/* ---------- Badges ---------- */
.badge {
  font-weight: 600;
  letter-spacing: 0.3px;
  padding: 0.38em 0.7em;
  border-radius: 999px;
  transition: background 0.2s var(--km-ease), color 0.2s var(--km-ease),
    border-color 0.2s var(--km-ease);
}
.badge.bg-primary,
.badge-primary { background: var(--km-primary) !important; color: #fff !important; }
.badge.bg-success,
.badge-success { background: var(--km-leaf-600) !important; color: #fff !important; }
.badge.bg-warning,
.badge-warning { background: var(--km-harvest) !important; color: #3a2500 !important; }

/* Destructive outline badges — give them an unmistakable hover fill */
a.badge-outline-danger,
.badge-outline-danger {
  color: #b91c1c !important;
  border-color: rgba(185, 28, 28, 0.5) !important;
  background: transparent !important;
}
a.badge-outline-danger:hover,
a.badge-outline-danger:focus,
.badge-outline-danger:hover {
  background: #dc2626 !important;
  border-color: #dc2626 !important;
  color: #fff !important;
  text-decoration: none !important;
}

/* ---------- Alerts ---------- */
.alert {
  border-radius: var(--km-radius);
  border-width: 1px;
}

/* ---------- Pagination ---------- */
.pagination .page-link { color: var(--km-primary); border-color: var(--km-border); }
.pagination .page-item.active .page-link {
  background: var(--km-primary);
  border-color: var(--km-primary);
  color: #fff;
}

/* ---------- Dropdowns ---------- */
.dropdown-menu {
  border: 1px solid var(--km-border);
  border-radius: var(--km-radius);
  box-shadow: var(--km-shadow-lg);
  padding: 8px;
}
.dropdown-item {
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 0.82rem;
}
.dropdown-item:hover {
  background: rgba(22, 163, 74, 0.08);
  color: var(--km-primary);
}
.dropdown-item.active,
.dropdown-item:active {
  background: var(--km-primary);
  color: #fff;
}

/* ---------- Footer ---------- */
.nk-footer {
  border-top: 1px solid var(--km-border);
  background: #fff;
}
.nk-footer-copyright { color: var(--km-muted); font-size: 0.82rem; }

/* ---------- Misc polish ---------- */
.nk-block-head .nk-block-des p { color: var(--km-muted); }

.tooltip-inner { background: var(--km-primary); border-radius: 6px; }
.tooltip .tooltip-arrow::before { border-top-color: var(--km-primary) !important; }

/* SweetAlert2 tune */
.swal2-popup { border-radius: var(--km-radius-lg) !important; }
.swal2-styled.swal2-confirm {
  background: var(--km-primary) !important;
  border-radius: 8px !important;
}
.swal2-styled.swal2-confirm:focus { box-shadow: 0 0 0 3px rgba(20, 83, 45, 0.25) !important; }

/* Leaflet map container subtle rounding when present */
.leaflet-container { border-radius: var(--km-radius); }

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
