/* ==========================================================================
   ADMIN COMMAND CENTER DESIGN SYSTEM v7.0
   35 Structural Dashboard Layouts + Calm Luxury Motion + All 10 Sidebar Tabs
   ========================================================================== */

:root {
  --kd-bg: #050811;
  --kd-sidebar: rgba(9, 14, 28, 0.94);
  --kd-card: rgba(15, 23, 42, 0.80);
  --kd-border: rgba(255, 255, 255, 0.08);
  --kd-cyan: #38bdf8;
  --kd-emerald: #10b981;
  --kd-amber: #f59e0b;
  --kd-rose: #ef4444;
  --kd-orange: #f97316;
  --kd-radius: 16px;
  --kd-spring: cubic-bezier(0.16, 1, 0.3, 1);
  --kd-mono: 'Fira Code', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

body {
  background-color: var(--kd-bg) !important;
  background-image:
    radial-gradient(ellipse 75% 42% at 55% -10%, rgba(249, 115, 22, 0.13), transparent 65%),
    radial-gradient(ellipse 55% 40% at 15% 15%, rgba(56, 189, 248, 0.10), transparent 62%),
    linear-gradient(to right, rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.02) 1px, transparent 1px) !important;
  background-size: 100% 100%, 100% 100%, 48px 48px, 48px 48px !important;
  background-attachment: fixed !important;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 8px; height: 6px; }
::-webkit-scrollbar-track { background: #050811; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.25); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--kd-orange); }

/* Sidebar & Mobile Drawer */
.admin-sidebar {
  background: var(--kd-sidebar) !important;
  backdrop-filter: blur(22px) saturate(160%) !important;
  -webkit-backdrop-filter: blur(22px) saturate(160%) !important;
  border-right: 1px solid var(--kd-border) !important;
  z-index: 250 !important;
}
.sidebar-logo {
  flex-shrink: 0 !important;
  min-width: 38px !important;
  width: 38px !important;
  height: 38px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: linear-gradient(135deg, var(--kd-orange) 0%, var(--kd-cyan) 100%) !important;
  box-shadow: 0 6px 20px rgba(249, 115, 22, 0.38) !important;
  color: #ffffff !important;
}
.nav-item {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  cursor: pointer !important;
  border-radius: 10px !important;
  transition: transform 0.22s var(--kd-spring), background 0.22s ease, color 0.22s ease !important;
}
.nav-item svg.kd-nav-ico { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.72; }
.nav-item:hover { transform: translateX(3px); background: rgba(255, 255, 255, 0.06) !important; }
.nav-item:hover svg.kd-nav-ico, .nav-item.active svg.kd-nav-ico { opacity: 1; }
.nav-item.active {
  background: linear-gradient(90deg, rgba(249, 115, 22, 0.20) 0%, rgba(249, 115, 22, 0.03) 100%) !important;
  color: var(--kd-orange) !important;
  box-shadow: inset 3px 0 0 var(--kd-orange) !important;
}

.kd-mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--kd-border);
  color: #f8fafc;
  cursor: pointer;
  margin-right: 10px;
}
.kd-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 17, 0.72);
  backdrop-filter: blur(4px);
  z-index: 240;
}
.kd-sidebar-backdrop.open { display: block; }

.admin-topbar {
  z-index: 40 !important;
  background: rgba(5, 8, 17, 0.82) !important;
  backdrop-filter: blur(18px) saturate(160%) !important;
  -webkit-backdrop-filter: blur(18px) saturate(160%) !important;
  border-bottom: 1px solid var(--kd-border) !important;
}

/* Structural KPI Layouts Controlled by 35 Dashboard Templates */
.stats-grid {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 16px !important;
  width: 100% !important;
  max-width: none !important;
  margin-bottom: 20px !important;
}
body[data-db-kpi="2x2"] .stats-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}
body[data-db-kpi="hero-left"] .stats-grid {
  grid-template-columns: 1.45fr 1fr 1fr 1fr !important;
}

.stat-card {
  position: relative;
  display: flex !important;
  flex-direction: column !important;
  justify-content: space-between !important;
  min-height: 138px !important;
  padding: 20px !important;
  background: var(--kd-card) !important;
  backdrop-filter: blur(16px) !important;
  -webkit-backdrop-filter: blur(16px) !important;
  border: 1px solid var(--kd-border) !important;
  border-radius: var(--kd-radius) !important;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.06) !important;
  transition: transform 0.26s var(--kd-spring), border-color 0.26s ease, box-shadow 0.26s var(--kd-spring) !important;
  overflow: hidden;
}
.stat-card::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(280px circle at var(--mx, 50%) var(--my, 50%), rgba(56, 189, 248, 0.14), transparent 65%);
  transition: opacity 0.25s ease;
}
.stat-card:hover::after { opacity: 1; }
.stat-card:hover {
  transform: translateY(-3px) !important;
  border-color: rgba(56, 189, 248, 0.42) !important;
}
.stat-card:nth-child(1) { border-top: 2px solid rgba(16, 185, 129, 0.72) !important; }
.stat-card:nth-child(2) { border-top: 2px solid rgba(56, 189, 248, 0.72) !important; }
.stat-card:nth-child(3) { border-top: 2px solid rgba(129, 140, 248, 0.72) !important; }
.stat-card:nth-child(4) { border-top: 2px solid rgba(245, 158, 11, 0.72) !important; }

.kd-stat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; position: relative; z-index: 2; }
.kd-stat-ico { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-card-value {
  position: relative; z-index: 2;
  font-family: 'Plus Jakarta Sans', sans-serif !important;
  font-size: clamp(1.45rem, 2vw, 1.88rem) !important;
  font-weight: 800 !important;
  font-variant-numeric: tabular-nums !important;
  letter-spacing: -0.025em;
  color: #ffffff !important;
  margin-top: 10px !important;
}
.kd-stat-sub { position: relative; z-index: 2; margin-top: 8px; font-size: 11.5px; color: #94a3b8; display: flex; align-items: center; gap: 6px; }
.kd-pill-live { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 10px; font-weight: 700; background: rgba(16, 185, 129, 0.14); color: #34d399; }
.kd-spark { position: absolute; right: 0; bottom: 0; width: 58%; height: 54px; opacity: 0.26; pointer-events: none; z-index: 1; }

/* Structural Analytics Row Layouts */
.kd-analytics-row {
  display: grid;
  grid-template-columns: 1.7fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
body[data-db-analytics="donut-left"] .kd-analytics-row {
  grid-template-columns: 1fr 1.7fr;
}
body[data-db-analytics="donut-left"] .kd-panel-chart { order: 2; }
body[data-db-analytics="donut-left"] .kd-panel-telemetry { order: 1; }
body[data-db-analytics="stacked"] .kd-analytics-row {
  grid-template-columns: 1fr;
}

.kd-panel {
  background: var(--kd-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--kd-border);
  border-radius: var(--kd-radius);
  padding: 20px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.kd-panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 8px; }
.kd-panel-title { font-family: 'Plus Jakarta Sans', sans-serif; font-size: 14.5px; font-weight: 700; color: #f8fafc; }
.kd-panel-badge { font-size: 11px; font-weight: 600; color: var(--kd-cyan); background: rgba(56, 189, 248, 0.12); border: 1px solid rgba(56, 189, 248, 0.25); padding: 3px 9px; border-radius: 999px; }
.kd-chart-box { width: 100%; height: 165px; position: relative; }

.kd-telemetry-body { display: flex; align-items: center; gap: 16px; }
.kd-donut-wrap { position: relative; width: 92px; height: 92px; flex-shrink: 0; }
.kd-donut-text {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 800; font-size: 16px; color: #ffffff;
}
.kd-donut-text span { font-size: 9.5px; font-weight: 600; color: #94a3b8; text-transform: uppercase; }
.kd-health-list { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.kd-health-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 11px; border-radius: 11px;
  background: rgba(9, 14, 28, 0.68);
  border: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 12px;
}
.kd-health-label { color: #cbd5e1; font-weight: 500; }
.kd-health-ok { display: inline-flex; align-items: center; gap: 6px; color: #34d399; font-weight: 700; font-size: 11px; }
.kd-dot-green { width: 7px; height: 7px; border-radius: 50%; background: #10b981; box-shadow: 0 0 8px #10b981; }

/* Cards, Tables, Toggle Items & Modals */
.admin-card {
  background: var(--kd-card) !important;
  backdrop-filter: blur(16px) !important;
  -webkit-backdrop-filter: blur(16px) !important;
  border: 1px solid var(--kd-border) !important;
  border-radius: var(--kd-radius) !important;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.05) !important;
}
.admin-card-header {
  display: flex !important; flex-wrap: wrap !important; align-items: center !important; justify-content: space-between !important;
  gap: 12px !important; padding-bottom: 14px !important; margin-bottom: 16px !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07) !important;
}
.admin-card-title { font-family: 'Plus Jakarta Sans', sans-serif !important; font-weight: 800 !important; color: #ffffff !important; }
.toggle-item {
  background: rgba(9, 14, 28, 0.72) !important;
  border: 1px solid rgba(255, 255, 255, 0.08) !important;
  border-radius: 14px !important;
  padding: 16px 18px !important;
  transition: transform 0.22s var(--kd-spring), border-color 0.22s ease !important;
}
.toggle-item:hover { transform: translateY(-2px); border-color: var(--kd-orange) !important; }
.switch input:checked + .slider { background: linear-gradient(135deg, #10b981, #059669) !important; }

.kd-table-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.kd-filter-pills { display: inline-flex; gap: 4px; background: rgba(9, 14, 28, 0.85); padding: 3px; border-radius: 9px; border: 1px solid var(--kd-border); }
.kd-fpill {
  background: transparent; border: none; color: #94a3b8; font-size: 11.5px; font-weight: 600;
  padding: 5px 10px; border-radius: 7px; cursor: pointer;
}
.kd-fpill.active { background: var(--kd-orange); color: #ffffff; }
.kd-filter-input {
  background: rgba(9, 14, 28, 0.85); border: 1px solid var(--kd-border); color: #f8fafc;
  padding: 7px 12px; border-radius: 9px; font-size: 12.5px; outline: none; min-width: 185px;
}
.kd-btn-export {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 9px;
  background: rgba(56, 189, 248, 0.12); border: 1px solid rgba(56, 189, 248, 0.30);
  color: var(--kd-cyan); font-size: 12px; font-weight: 700; cursor: pointer;
}
.admin-table thead th {
  background: rgba(9, 14, 28, 0.92) !important; color: #94a3b8 !important;
  font-size: 11px !important; text-transform: uppercase; letter-spacing: 0.06em;
  border-bottom: 1px solid var(--kd-border) !important;
}
body[data-db-table="zebra"] .admin-table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.025) !important;
}
.admin-table tbody tr:hover { background: rgba(56, 189, 248, 0.06) !important; }
.kd-inv-id { font-family: var(--kd-mono); font-size: 12px; color: #e2e8f0; cursor: pointer; }
.kd-inv-id:hover { color: var(--kd-cyan); text-decoration: underline; }
.kd-status-pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.kd-st-ok { background: rgba(16, 185, 129, 0.14); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.30); }
.kd-st-warn { background: rgba(245, 158, 11, 0.14); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.30); }
.kd-st-bad { background: rgba(239, 68, 68, 0.12); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.25); }

.kd-copy-toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 9999;
  background: rgba(15, 23, 42, 0.96); border: 1px solid rgba(56, 189, 248, 0.45);
  color: #f8fafc; padding: 10px 16px; border-radius: 10px; font-size: 12.5px; font-weight: 600;
  box-shadow: 0 12px 30px rgba(0,0,0,0.5);
  opacity: 0; transform: translateY(10px); transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.kd-copy-toast.show { opacity: 1; transform: translateY(0); }

/* Responsive (Tablet, Android & iOS) */
@media (max-width: 1120px) {
  .stats-grid, body[data-db-kpi="hero-left"] .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .kd-analytics-row, body[data-db-analytics="donut-left"] .kd-analytics-row { grid-template-columns: 1fr !important; }
}
@media (max-width: 768px) {
  body { min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom, 0px); }
  .kd-mobile-menu-btn { display: inline-flex; }
  .admin-sidebar {
    position: fixed !important; left: 0; top: 0; bottom: 0;
    transform: translateX(-105%);
    transition: transform 0.28s var(--kd-spring) !important;
  }
  .admin-sidebar.kd-open { transform: translateX(0) !important; display: flex !important; visibility: visible !important; }
  .admin-main { margin-left: 0 !important; width: 100% !important; }
  input, select, textarea, .form-control, .kd-filter-input { font-size: 16px !important; min-height: 44px !important; }
  .btn, .btn-brand, .btn-primary, .btn-secondary, .btn-danger, .btn-full, .nav-item { min-height: 42px !important; }
  .kd-telemetry-body { flex-direction: column; align-items: stretch; }
  .kd-donut-wrap { margin: 0 auto; }
}
@media (max-width: 520px) {
  .stats-grid, body[data-db-kpi="2x2"] .stats-grid, body[data-db-kpi="hero-left"] .stats-grid { grid-template-columns: 1fr !important; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Compact sidebar variant */
@media (min-width: 769px) {
  body[data-db-sidebar="compact"] .admin-sidebar { width: 84px !important; }
  body[data-db-sidebar="compact"] .admin-main { margin-left: 84px !important; }
  body[data-db-sidebar="compact"] .sidebar-title,
  body[data-db-sidebar="compact"] .kd-sidebar-status { display: none !important; }
  body[data-db-sidebar="compact"] .sidebar-header { justify-content: center !important; }
  body[data-db-sidebar="compact"] .nav-item { font-size: 0 !important; justify-content: center !important; padding: 12px 0 !important; }
  body[data-db-sidebar="compact"] .nav-item svg.kd-nav-ico { width: 19px; height: 19px; opacity: 0.9; }
  body[data-db-sidebar="compact"] .admin-sidebar .btn { font-size: 11px !important; padding: 8px 4px !important; }
}


/* === v9.1 Tab Hero, Interactive Chart Modes & Template Studio Cards === */
.kd-tab-hero {
  position: relative;
  overflow: hidden;
  border-radius: var(--kd-radius, 16px);
  padding: 20px 22px;
  margin-bottom: 18px;
  background:
    radial-gradient(ellipse 70% 80% at 90% 15%, rgba(249, 115, 22, 0.13), transparent 60%),
    radial-gradient(ellipse 60% 70% at 10% 90%, rgba(56, 189, 248, 0.12), transparent 60%),
    var(--kd-card, rgba(15, 23, 42, 0.82));
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.36);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.kd-tab-hero-left {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  max-width: 720px;
}
.kd-tab-hero-orb {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.18), rgba(37, 99, 235, 0.18));
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #38bdf8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 8px 22px rgba(56, 189, 248, 0.18);
}
.kd-tab-hero-badge {
  display: inline-flex !important;
  align-items: center !important;
  gap: 7px !important;
  width: fit-content !important;
  padding: 4px 11px !important;
  border-radius: 999px !important;
  background: rgba(56, 189, 248, 0.12) !important;
  border: 1px solid rgba(56, 189, 248, 0.28) !important;
  color: #38bdf8 !important;
  font-size: 10.5px !important;
  font-weight: 800 !important;
  letter-spacing: 0.06em !important;
  margin-bottom: 6px !important;
}
.kd-tab-hero-title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 17px;
  font-weight: 800;
  color: #ffffff;
  margin-bottom: 4px;
}
.kd-tab-hero-sub {
  font-size: 12.5px;
  color: #94a3b8;
  line-height: 1.5;
  margin-bottom: 10px;
}
.kd-tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
  padding: 4px;
}
.kd-tpl-card {
  text-align: left;
  padding: 10px 12px;
  border-radius: 11px;
  background: rgba(9, 14, 28, 0.82);
  border: 1px solid rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
  cursor: pointer;
  transition: all 0.18s ease;
}
.kd-tpl-card:hover {
  border-color: rgba(56, 189, 248, 0.45);
  color: #ffffff;
}
.kd-tpl-card.active {
  background: linear-gradient(135deg, rgba(249, 115, 22, 0.22), rgba(56, 189, 248, 0.22));
  border-color: var(--kd-cyan, #38bdf8);
  color: #ffffff;
  box-shadow: 0 6px 18px rgba(56, 189, 248, 0.18);
}
.kd-tpl-num {
  font-size: 10.5px;
  font-weight: 800;
  color: var(--kd-cyan, #38bdf8);
}
.kd-tpl-name {
  font-size: 12px;
  font-weight: 700;
  color: #ffffff;
  margin-top: 2px;
}
