/* KMC HUB Design System v2 — professional redesign pass. Tokens grounded in 2026 admin-
   dashboard conventions: strategic minimalism (fewer, bigger, breathing-room elements),
   larger card radii, clear visual hierarchy (biggest number = most important KPI), and
   role-grouped navigation. Loaded once via includes/header.php — every authenticated page
   inherits it automatically, no per-page CSS needed. */

:root {
  /* Brand — deep environment green, kept for identity continuity, paired with a teal
     accent so charts/badges have a second hue instead of leaning on green for everything */
  --kmc-primary: #0f5132;
  --kmc-primary-hover: #0b3d26;
  --kmc-primary-light: #e6f4ec;
  --kmc-accent: #0891b2;
  --kmc-accent-light: #e0f7fa;

  /* Sidebar gradient stops */
  --kmc-sidebar-from: #0b3625;
  --kmc-sidebar-to: #08251a;

  /* Ink */
  --kmc-ink: #0f172a;
  --kmc-ink-muted: #475569;
  --kmc-ink-faint: #94a3b8;

  /* Surface */
  --kmc-surface: #ffffff;
  --kmc-surface-sunken: #f6f8f7;
  --kmc-border: #e5e9e8;

  /* Status — reserved, never reused for series/identity (WCAG AA verified against white) */
  --kmc-good: #047857;
  --kmc-good-bg: #d1fae5;
  --kmc-warn: #b45309;
  --kmc-warn-bg: #fef3c7;
  --kmc-critical: #be123c;
  --kmc-critical-bg: #ffe4e6;
  --kmc-info: #1d4ed8;
  --kmc-info-bg: #dbeafe;

  /* Spacing scale (4px base) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;

  /* Radius — larger than v1, "breathing room" over dense edges */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 22px;

  /* Shadow */
  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 2px 12px rgba(15, 23, 42, 0.05);
  --shadow-raised: 0 8px 28px rgba(15, 23, 42, 0.12);

  /* v3 depth — layered elevation (near + far shadow = perceived 3D lift, not just a
     bigger blur) and a tinted ambient glow used sparingly on primary hover states. */
  --shadow-1: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-2: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 10px rgba(15, 23, 42, 0.06);
  --shadow-3: 0 2px 4px rgba(15, 23, 42, 0.05), 0 12px 28px rgba(15, 23, 42, 0.10);
  --shadow-4: 0 4px 8px rgba(15, 23, 42, 0.06), 0 20px 44px rgba(15, 23, 42, 0.14);
  --shadow-glow-primary: 0 8px 24px rgba(15, 81, 50, 0.28);
  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.5);
  --ease-depth: cubic-bezier(0.22, 1, 0.36, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --kmc-primary: #34d399;
    --kmc-primary-hover: #6ee7b7;
    --kmc-primary-light: #064e3b;
    --kmc-accent: #22d3ee;
    --kmc-accent-light: #083344;
    --kmc-ink: #f1f5f9;
    --kmc-ink-muted: #cbd5e1;
    --kmc-ink-faint: #64748b;
    --kmc-surface: #131c18;
    --kmc-surface-sunken: #0b1310;
    --kmc-border: #263230;
    --glass-bg: rgba(19, 28, 24, 0.72);
    --glass-border: rgba(255, 255, 255, 0.08);
    --shadow-glow-primary: 0 8px 24px rgba(52, 211, 153, 0.22);
  }
}

* { font-family: 'Inter', 'Noto Sans Devanagari', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }

body {
  background:
    radial-gradient(900px 500px at 100% -10%, rgba(8, 145, 178, 0.06), transparent 60%),
    radial-gradient(700px 500px at -10% 20%, rgba(15, 81, 50, 0.05), transparent 55%),
    var(--kmc-surface-sunken);
  color: var(--kmc-ink);
}
@media (prefers-color-scheme: dark) {
  body {
    background:
      radial-gradient(900px 500px at 100% -10%, rgba(34, 211, 238, 0.06), transparent 60%),
      radial-gradient(700px 500px at -10% 20%, rgba(52, 211, 153, 0.05), transparent 55%),
      var(--kmc-surface-sunken);
  }
}

/* Skip-to-content link — WCAG 2.4.1, hidden until keyboard-focused */
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--kmc-primary); color: #fff;
  padding: var(--sp-2) var(--sp-4); border-radius: var(--radius-sm);
}
.skip-link:focus { left: var(--sp-3); top: var(--sp-3); }

/* Visible focus ring everywhere — WCAG 2.4.7 */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--kmc-primary);
  outline-offset: 2px;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.kmc-sidebar {
  background: linear-gradient(180deg, var(--kmc-sidebar-from), var(--kmc-sidebar-to));
  box-shadow: inset -1px 0 0 rgba(255,255,255,0.04), 4px 0 24px rgba(0,0,0,0.10);
  position: sticky; top: 0; z-index: 20;
}
.kmc-sidebar .brand-mark {
  width: 34px; height: 34px; border-radius: var(--radius-md);
  background: rgba(255,255,255,0.12); display: flex; align-items: center; justify-content: center;
}
.kmc-sidebar .nav-link {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 6px var(--sp-4); border-radius: var(--radius-md);
  color: #cfe0d7; font-size: 13px; font-weight: 500;
  transition: background 0.14s ease, color 0.14s ease, transform 0.1s ease;
  min-height: 34px; position: relative;
}
.kmc-sidebar .nav-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.kmc-sidebar .nav-link:hover { transform: translateX(2px); }
.kmc-sidebar .nav-link.active {
  background: rgba(255,255,255,0.14); color: #fff; font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 4px 14px rgba(0,0,0,0.18);
}
.kmc-sidebar .nav-link.active::before {
  content: ''; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 3px; background: #6ee7b7;
  box-shadow: 0 0 10px rgba(110, 231, 183, 0.7);
}
.kmc-sidebar .nav-link .nav-icon-chip {
  width: 22px; height: 22px; border-radius: var(--radius-sm); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.06);
}
.kmc-sidebar .nav-link.active .nav-icon-chip { background: rgba(255,255,255,0.18); }
.kmc-sidebar .nav-icon { width: 14px; height: 14px; flex-shrink: 0; }
.kmc-sidebar .nav-section-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: #5f8a72; padding: var(--sp-3) var(--sp-4) 2px;
}

/* Mobile sidebar — the fixed 256px sidebar had no way to hide, so a narrow viewport just
   scrolled the whole page horizontally instead of the sidebar getting out of the way. */
.kmc-mobile-menu-btn {
  display: none; background: none; border: none; font-size: 22px; line-height: 1;
  color: var(--kmc-ink); padding: 4px 8px; border-radius: var(--radius-sm); cursor: pointer;
}
.kmc-sidebar-backdrop { display: none; }
@media (max-width: 768px) {
  .kmc-mobile-menu-btn { display: inline-flex; }
  /* #id selector, not .kmc-sidebar — the <aside> also carries Tailwind's `sticky` utility
     class (same specificity as a plain class selector, and CDN Tailwind injects its own
     <style> tag at a point in <head> parsing this can't rely on winning by source order
     alone), so position:fixed here must out-specificity it to be guaranteed to apply. */
  #kmc-sidebar-el {
    position: fixed; left: 0; top: 0; height: 100vh; z-index: 210;
    transform: translateX(-100%); transition: transform 0.2s ease;
  }
  #kmc-sidebar-el.open { transform: translateX(0); }
  .kmc-sidebar-backdrop.open {
    display: block; position: fixed; inset: 0; z-index: 205; background: rgba(15,23,42,0.5);
  }
}

/* ── Topbar — sticky glass surface, blurs page content scrolling underneath it ── */
.kmc-topbar {
  background: var(--glass-bg); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--kmc-border);
  padding: var(--sp-4) var(--sp-8); display: flex; align-items: center; gap: var(--sp-5);
  position: sticky; top: 0; z-index: 10;
}
@supports not (backdrop-filter: blur(1px)) {
  .kmc-topbar { background: var(--kmc-surface); }
}
.kmc-topbar h1 { font-size: 20px; font-weight: 700; color: var(--kmc-ink); letter-spacing: -0.01em; }
.kmc-search {
  flex: 1; max-width: 380px; position: relative;
}
.kmc-search input {
  width: 100%; background: var(--kmc-surface-sunken); border: 1px solid var(--kmc-border);
  border-radius: var(--radius-md); padding: 9px 14px 9px 38px; font-size: 13.5px;
  color: var(--kmc-ink); transition: border-color 0.12s ease, background 0.12s ease;
}
.kmc-search input:focus { border-color: var(--kmc-primary); background: var(--kmc-surface); }
.kmc-search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--kmc-ink-faint); pointer-events: none; }
.kmc-bell-wrap { position: relative; }
.kmc-bell-dot {
  position: absolute; top: -2px; right: -2px; min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 999px; background: var(--kmc-critical); color: #fff;
  font-size: 10px; font-weight: 700; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--kmc-surface);
}

/* ── Cards — layered elevation + gentle lift on hover reads as depth without a
   literal 3D transform (which fights with table/form content inside cards). ── */
.kmc-card {
  background: var(--kmc-surface); border: 1px solid var(--kmc-border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-2);
  transition: box-shadow 0.25s var(--ease-depth), transform 0.25s var(--ease-depth), border-color 0.25s ease;
  position: relative;
}
.kmc-card:hover { box-shadow: var(--shadow-3); transform: translateY(-2px); border-color: rgba(15, 81, 50, 0.14); }

/* ── KPI tile — icon chip + trend, largest number wins visual weight ───────── */
.kmc-kpi { padding: var(--sp-5) var(--sp-5) var(--sp-6); }
.kmc-kpi-icon-chip {
  width: 40px; height: 40px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  background: var(--kmc-primary-light); color: var(--kmc-primary); flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.5), inset 0 -6px 10px rgba(15,23,42,0.05);
  transition: transform 0.3s var(--ease-depth);
}
.kmc-card:hover .kmc-kpi-icon-chip { transform: scale(1.08) rotate(-4deg); }
.kmc-kpi-icon-chip svg { width: 20px; height: 20px; }
.kmc-kpi-icon-chip.warn { background: var(--kmc-warn-bg); color: var(--kmc-warn); }
.kmc-kpi-icon-chip.critical { background: var(--kmc-critical-bg); color: var(--kmc-critical); }
.kmc-kpi-icon-chip.info { background: var(--kmc-info-bg); color: var(--kmc-info); }
.kmc-kpi-icon-chip.accent { background: var(--kmc-accent-light); color: var(--kmc-accent); }
.kmc-kpi-label { font-size: 12px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; color: var(--kmc-ink-faint); }
.kmc-kpi-value { font-size: 34px; font-weight: 800; line-height: 1.1; margin-top: 2px; letter-spacing: -0.02em; }
.kmc-kpi-trend { font-size: 12.5px; font-weight: 500; color: var(--kmc-ink-muted); margin-top: var(--sp-2); }

/* ── Badges — status color + never color-alone (label text always present) ─── */
.kmc-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 11px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.kmc-badge-good { background: var(--kmc-good-bg); color: var(--kmc-good); }
.kmc-badge-warn { background: var(--kmc-warn-bg); color: var(--kmc-warn); }
.kmc-badge-critical { background: var(--kmc-critical-bg); color: var(--kmc-critical); }
.kmc-badge-info { background: var(--kmc-info-bg); color: var(--kmc-info); }
.kmc-badge-neutral { background: var(--kmc-surface-sunken); color: var(--kmc-ink-muted); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.kmc-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-5); border-radius: var(--radius-md);
  font-size: 14px; font-weight: 600; min-height: 40px;
  transition: background 0.12s ease, box-shadow 0.12s ease, transform 0.08s ease;
  cursor: pointer; border: 1px solid transparent;
}
.kmc-btn:active { transform: scale(0.97) translateY(1px); }
.kmc-btn-primary { background: var(--kmc-primary); color: #fff; box-shadow: var(--shadow-1); }
.kmc-btn-primary:hover { background: var(--kmc-primary-hover); box-shadow: var(--shadow-glow-primary); transform: translateY(-1px); }
.kmc-btn-secondary { background: var(--kmc-surface); color: var(--kmc-ink); border-color: var(--kmc-border); }
.kmc-btn-secondary:hover { background: var(--kmc-surface-sunken); box-shadow: var(--shadow-2); transform: translateY(-1px); }

/* ── Inputs ──────────────────────────────────────────────────────────────── */
.kmc-input {
  width: 100%; border: 1px solid var(--kmc-border); border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3); font-size: 14px; min-height: 40px;
  background: var(--kmc-surface); color: var(--kmc-ink);
  transition: border-color 0.12s ease;
}
.kmc-input:focus { border-color: var(--kmc-primary); }

/* ── Table ───────────────────────────────────────────────────────────────── */
/* No overflow wrapper existed anywhere — a wide table dragged the whole PAGE wider on
   mobile instead of scrolling in its own box. Every existing page already puts its table
   inside .kmc-card with no extra markup change needed — giving the card horizontal scroll
   when it holds a table is a safe drop-in fix (a plain table keeps normal thead/tbody
   alignment, unlike a display:block/table hack, which needs matching fixed column widths
   nothing here defines). */
.kmc-card:has(> .kmc-table), .kmc-card:has(table.kmc-table) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.kmc-table { width: 100%; font-size: 14px; border-collapse: collapse; }
.kmc-table thead th {
  text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--kmc-ink-faint); padding: var(--sp-3) var(--sp-5);
  background: var(--kmc-surface-sunken);
}
.kmc-table tbody tr { border-top: 1px solid var(--kmc-border); transition: background 0.15s ease; }
.kmc-table tbody tr:hover { background: var(--kmc-surface-sunken); position: relative; box-shadow: inset 3px 0 0 var(--kmc-primary); }
.kmc-table tbody td { padding: var(--sp-3) var(--sp-5); }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.kmc-pagination { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.kmc-page-link {
  display: inline-flex; align-items: center; justify-content: center; min-width: 28px; height: 28px;
  padding: 0 6px; border-radius: 6px; font-size: 13px; color: var(--kmc-ink-muted);
  text-decoration: none; border: 1px solid transparent;
}
.kmc-page-link:hover { background: var(--kmc-surface-sunken); }
.kmc-page-link.active { background: var(--kmc-primary); color: #fff; font-weight: 600; }
.kmc-page-link.disabled { opacity: 0.35; pointer-events: none; }
.kmc-page-ellipsis { padding: 0 4px; color: var(--kmc-ink-faint); font-size: 13px; }
.kmc-list-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.kmc-list-toolbar .kmc-input { max-width: 220px; }
.kmc-list-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px var(--sp-5); flex-wrap: wrap; }
.kmc-list-footer .kmc-list-count { font-size: 12px; color: var(--kmc-ink-faint); }

/* ── Compact inline controls — filter bars, table-row edits that intentionally stay
   smaller than kmc-input/kmc-btn. Unifies color/radius without touching their sizing. ── */
input[class*="border-slate-300"], select[class*="border-slate-300"], textarea[class*="border-slate-300"] {
  border-color: var(--kmc-border); transition: border-color 0.12s ease;
}
input[class*="border-slate-300"]:focus, select[class*="border-slate-300"]:focus, textarea[class*="border-slate-300"]:focus {
  border-color: var(--kmc-primary);
}
button[class*="bg-slate-900"] {
  background: var(--kmc-primary) !important; transition: background 0.12s ease;
}
button[class*="bg-slate-900"]:hover { background: var(--kmc-primary-hover) !important; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.kmc-empty { padding: var(--sp-8); text-align: center; color: var(--kmc-ink-faint); font-size: 14px; }
.kmc-empty svg { width: 32px; height: 32px; margin: 0 auto var(--sp-3); opacity: 0.5; }

/* ── Quick-action tile (dashboard shortcuts row) ────────────────────────────── */
.kmc-quick-tile {
  display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-4);
  border-radius: var(--radius-md); border: 1px solid var(--kmc-border);
  background: var(--kmc-surface); transition: box-shadow 0.25s var(--ease-depth), transform 0.25s var(--ease-depth);
}
.kmc-quick-tile:hover { box-shadow: var(--shadow-4); transform: translateY(-3px) scale(1.015); }
.kmc-quick-tile .icon-chip {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: var(--kmc-primary-light); color: var(--kmc-primary);
  transition: transform 0.3s var(--ease-depth);
}
.kmc-quick-tile:hover .icon-chip { transform: scale(1.12) rotate(-6deg); }
.kmc-quick-tile .icon-chip svg { width: 18px; height: 18px; }

/* ── v3 depth — entrance choreography ───────────────────────────────────────
   Cards/KPIs/tiles rise + fade in on page load with a short stagger, giving the
   whole shell a sense of layered depth instead of popping in flat. Purely CSS
   (animation-delay via nth-child), so it works with zero JS on every page that
   already uses these classes. Respects prefers-reduced-motion below. ── */
@keyframes kmc-rise-in {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.kmc-card, .kmc-kpi, .kmc-quick-tile {
  animation: kmc-rise-in 0.5s var(--ease-depth) both;
}
.kmc-card:nth-of-type(2), .kmc-quick-tile:nth-of-type(2) { animation-delay: 0.04s; }
.kmc-card:nth-of-type(3), .kmc-quick-tile:nth-of-type(3) { animation-delay: 0.08s; }
.kmc-card:nth-of-type(4), .kmc-quick-tile:nth-of-type(4) { animation-delay: 0.12s; }
.kmc-card:nth-of-type(5), .kmc-quick-tile:nth-of-type(5) { animation-delay: 0.16s; }
.kmc-card:nth-of-type(n+6), .kmc-quick-tile:nth-of-type(n+6) { animation-delay: 0.2s; }

/* Optional opt-in scroll-reveal (paired with public/assets/js/depth-fx.js) and
   pointer-tilt for hero surfaces — inert until JS adds .is-visible / runs. */
.kmc-reveal { opacity: 0; transform: translateY(16px); transition: opacity 0.5s var(--ease-depth), transform 0.5s var(--ease-depth); }
.kmc-reveal.is-visible { opacity: 1; transform: translateY(0); }
.kmc-tilt { transform-style: preserve-3d; will-change: transform; transition: transform 0.15s ease-out; }

/* Thin, tinted scrollbar — small polish detail consistent with the depth theme */
* { scrollbar-width: thin; scrollbar-color: var(--kmc-ink-faint) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--kmc-ink-faint); border-radius: 999px; }
*::-webkit-scrollbar-track { background: transparent; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important; scroll-behavior: auto !important;
  }
  .kmc-card:hover, .kmc-quick-tile:hover, .kmc-btn-primary:hover, .kmc-btn-secondary:hover { transform: none; }
  .kmc-reveal { opacity: 1; transform: none; }
}
