/* ============================================================================
 * KONEXIA · DESIGN SYSTEM v2
 * Tokens, base components, motion. Loaded after Tailwind CDN.
 * ========================================================================= */

:root {
  /* === Surface scale (dark navy) === */
  --bg-900: #070B14;
  --bg-800: #0A0F1C;
  --bg-700: #0F1626;
  --bg-600: #141C2F;
  --surface: #1A2238;
  --surface-elevated: #202B45;
  --surface-overlay: rgba(20, 28, 48, 0.85);

  /* === Brand cyan/teal === */
  --brand-300: #5EEAEA;
  --brand-400: #22D3D3;
  --brand-500: #14B8B8;
  --brand-600: #0E9494;
  --brand-700: #0A6F6F;
  --brand-glow: rgba(20, 184, 184, 0.35);
  --brand-glow-strong: rgba(20, 184, 184, 0.55);

  /* === Semantic === */
  --success-400: #34D399;
  --success-500: #10B981;
  --success-600: #059669;
  --success-bg: rgba(16, 185, 129, 0.10);
  --warning-400: #FBBF24;
  --warning-500: #F59E0B;
  --warning-600: #D97706;
  --warning-bg: rgba(245, 158, 11, 0.10);
  --danger-400: #F87171;
  --danger-500: #EF4444;
  --danger-600: #DC2626;
  --danger-bg: rgba(239, 68, 68, 0.10);
  --danger-glow: rgba(239, 68, 68, 0.40);
  --info-400: #60A5FA;
  --info-500: #3B82F6;
  --info-600: #2563EB;
  --info-bg: rgba(59, 130, 246, 0.10);

  /* === Text === */
  --text-primary: #F1F5F9;
  --text-secondary: #CBD5E1;
  --text-muted: #94A3B8;
  --text-disabled: #64748B;
  --text-on-brand: #002525;

  /* === Borders === */
  --border-subtle: rgba(255, 255, 255, 0.04);
  --border-default: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --border-brand: rgba(20, 184, 184, 0.35);

  /* === Radii === */
  --r-sm: 6px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-2xl: 20px;
  --r-3xl: 24px;
  --r-full: 9999px;

  /* === Spacing scale (4px base) === */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px;
  --s-12: 48px; --s-16: 64px;

  /* === Typography === */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
  --fs-xs: 11px;   --lh-xs: 16px;
  --fs-sm: 12px;   --lh-sm: 18px;
  --fs-base: 13px; --lh-base: 20px;
  --fs-md: 14px;   --lh-md: 22px;
  --fs-lg: 16px;   --lh-lg: 24px;
  --fs-xl: 18px;   --lh-xl: 28px;
  --fs-2xl: 20px;  --lh-2xl: 30px;
  --fs-3xl: 24px;  --lh-3xl: 32px;
  --fs-4xl: 30px;  --lh-4xl: 38px;
  --fs-5xl: 36px;  --lh-5xl: 44px;
  --fs-6xl: 48px;  --lh-6xl: 56px;

  /* === Shadows === */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.20);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.35);
  --shadow-xl: 0 24px 48px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 32px -4px var(--brand-glow);
  --shadow-glow-strong: 0 0 48px -4px var(--brand-glow-strong);
  --shadow-danger: 0 0 24px -4px var(--danger-glow);

  /* === Motion === */
  --dur-fast: 150ms;
  --dur-base: 220ms;
  --dur-slow: 360ms;
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out-quart: cubic-bezier(0.76, 0, 0.24, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ============================================================================
 * Base reset + typography
 * ========================================================================= */

html, body {
  font-family: var(--font-sans);
  background: var(--bg-800);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.font-mono, .num-mono {
  font-family: var(--font-mono);
  font-feature-settings: "tnum" 1, "lnum" 1;
}

/* ============================================================================
 * Surfaces
 * ========================================================================= */

.k-card {
  background: linear-gradient(135deg, rgba(255,255,255,0.03), rgba(255,255,255,0.005));
  border: 1px solid var(--border-default);
  border-radius: var(--r-2xl);
  transition: border-color var(--dur-base) var(--ease-out-expo),
              transform var(--dur-base) var(--ease-out-expo),
              box-shadow var(--dur-base) var(--ease-out-expo);
}
.k-card.k-interactive { cursor: pointer; }
.k-card.k-interactive:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.k-card-elevated {
  background: linear-gradient(135deg, var(--surface), var(--surface-elevated));
  border: 1px solid var(--border-strong);
  border-radius: var(--r-2xl);
  box-shadow: var(--shadow-md);
}

.k-glass {
  background: rgba(20, 28, 48, 0.55);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid var(--border-default);
}

/* Brand-bordered card (for AI insights, premium features) */
.k-card-brand {
  position: relative;
  background: linear-gradient(135deg, rgba(20,184,184,0.06), rgba(20,184,184,0.01));
  border: 1px solid var(--border-default);
  border-radius: var(--r-2xl);
  overflow: hidden;
}
.k-card-brand::before {
  content: '';
  position: absolute; inset: 0;
  padding: 1px;
  background: linear-gradient(135deg, rgba(20,184,184,0.6), rgba(20,184,184,0.1) 50%, rgba(20,184,184,0.4));
  border-radius: inherit;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
}

/* SuperAdmin / restricted zone card (amber-violet edge) */
.k-card-restricted {
  position: relative;
  background: linear-gradient(135deg, rgba(245,158,11,0.04), rgba(168,85,247,0.04));
  border: 1px solid var(--border-default);
  border-radius: var(--r-2xl);
  overflow: hidden;
}
.k-card-restricted::before {
  content: '';
  position: absolute; inset: 0;
  padding: 1px;
  background: linear-gradient(135deg, rgba(245,158,11,0.55), rgba(168,85,247,0.55));
  border-radius: inherit;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask-composite: exclude;
  pointer-events: none;
}

/* ============================================================================
 * Typography helpers
 * ========================================================================= */

.k-eyebrow {
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}
.k-h1 { font-size: var(--fs-4xl); line-height: var(--lh-4xl); font-weight: 700; letter-spacing: -0.02em; }
.k-h2 { font-size: var(--fs-3xl); line-height: var(--lh-3xl); font-weight: 700; letter-spacing: -0.015em; }
.k-h3 { font-size: var(--fs-2xl); line-height: var(--lh-2xl); font-weight: 600; letter-spacing: -0.01em; }
.k-h4 { font-size: var(--fs-xl); line-height: var(--lh-xl); font-weight: 600; }
.k-text-muted { color: var(--text-muted); }
.k-text-secondary { color: var(--text-secondary); }
.k-grad-text {
  background: linear-gradient(135deg, var(--brand-400), var(--brand-600));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Big metric number, tabular */
.k-metric {
  font-family: var(--font-mono);
  font-size: var(--fs-5xl);
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-feature-settings: "tnum" 1, "lnum" 1;
  color: var(--text-primary);
}
.k-metric-sm {
  font-family: var(--font-mono);
  font-size: var(--fs-2xl);
  font-weight: 600;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

/* ============================================================================
 * Status dots & badges
 * ========================================================================= */

.k-status-dot {
  width: 8px; height: 8px;
  border-radius: var(--r-full);
  display: inline-block;
  position: relative;
}
.k-status-dot.is-ok { background: var(--success-500); box-shadow: 0 0 0 0 var(--success-500); animation: k-pulse-ok 2.4s infinite; }
.k-status-dot.is-warn { background: var(--warning-500); }
.k-status-dot.is-bad { background: var(--danger-500); animation: k-pulse-bad 1.6s infinite; }
.k-status-dot.is-neutral { background: var(--text-muted); }

@keyframes k-pulse-ok {
  0%   { box-shadow: 0 0 0 0 rgba(16,185,129,0.55); }
  70%  { box-shadow: 0 0 0 10px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}
@keyframes k-pulse-bad {
  0%   { box-shadow: 0 0 0 0 rgba(239,68,68,0.65); }
  70%  { box-shadow: 0 0 0 10px rgba(239,68,68,0); }
  100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}

.k-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  line-height: 16px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid transparent;
  white-space: nowrap;
}
.k-badge.is-success { color: var(--success-400); background: var(--success-bg); border-color: rgba(16,185,129,0.25); }
.k-badge.is-warning { color: var(--warning-400); background: var(--warning-bg); border-color: rgba(245,158,11,0.25); }
.k-badge.is-danger  { color: var(--danger-400);  background: var(--danger-bg);  border-color: rgba(239,68,68,0.25); }
.k-badge.is-info    { color: var(--info-400);    background: var(--info-bg);    border-color: rgba(59,130,246,0.25); }
.k-badge.is-brand   { color: var(--brand-400);   background: rgba(20,184,184,0.10); border-color: rgba(20,184,184,0.30); }
.k-badge.is-neutral { color: var(--text-secondary); background: rgba(255,255,255,0.05); border-color: var(--border-default); }
.k-badge.is-beta    { color: #C4B5FD; background: rgba(167,139,250,0.10); border-color: rgba(167,139,250,0.30); }

.k-delta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 6px;
  border-radius: var(--r-md);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 600;
  font-feature-settings: "tnum" 1;
}
.k-delta.is-up   { color: var(--success-400); background: var(--success-bg); }
.k-delta.is-down { color: var(--danger-400);  background: var(--danger-bg); }
.k-delta.is-flat { color: var(--text-muted);  background: rgba(255,255,255,0.05); }

/* ============================================================================
 * Buttons
 * ========================================================================= */

.k-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--r-lg);
  font-size: var(--fs-md);
  font-weight: 500;
  line-height: 1;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out-expo);
  white-space: nowrap;
  user-select: none;
}
.k-btn:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
}
.k-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.k-btn.is-primary {
  background: linear-gradient(135deg, var(--brand-500), var(--brand-600));
  color: var(--text-on-brand);
  font-weight: 600;
  box-shadow: var(--shadow-sm), 0 0 16px -4px var(--brand-glow);
}
.k-btn.is-primary:hover:not(:disabled) {
  box-shadow: var(--shadow-md), 0 0 24px -2px var(--brand-glow-strong);
  transform: translateY(-1px);
}
.k-btn.is-secondary {
  background: var(--surface);
  color: var(--text-primary);
  border-color: var(--border-default);
}
.k-btn.is-secondary:hover:not(:disabled) { background: var(--surface-elevated); border-color: var(--border-strong); }
.k-btn.is-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.k-btn.is-ghost:hover:not(:disabled) { background: rgba(255,255,255,0.04); color: var(--text-primary); }
.k-btn.is-danger {
  background: linear-gradient(135deg, var(--danger-500), var(--danger-600));
  color: white;
}
.k-btn.is-ai {
  background: linear-gradient(135deg, #A78BFA, var(--brand-500));
  color: white;
  font-weight: 600;
  box-shadow: 0 0 24px -4px rgba(167,139,250,0.45);
}
.k-btn.is-sm { padding: 6px 10px; font-size: var(--fs-sm); border-radius: var(--r-md); }
.k-btn.is-lg { padding: 12px 20px; font-size: var(--fs-lg); border-radius: var(--r-xl); }
.k-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--r-md);
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out-expo);
}
.k-icon-btn:hover { background: rgba(255,255,255,0.06); color: var(--text-primary); border-color: var(--border-default); }
.k-icon-btn:focus-visible { outline: 2px solid var(--brand-500); outline-offset: 2px; }

/* ============================================================================
 * Inputs
 * ========================================================================= */

.k-input, .k-select, .k-textarea {
  width: 100%;
  background: var(--bg-700);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  padding: 8px 12px;
  color: var(--text-primary);
  font-size: var(--fs-md);
  font-family: inherit;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.k-input::placeholder, .k-textarea::placeholder { color: var(--text-disabled); }
.k-input:focus, .k-select:focus, .k-textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(20,184,184,0.15);
}

/* ============================================================================
 * Skeleton loaders
 * ========================================================================= */

.k-skeleton {
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 0%, rgba(255,255,255,0.10) 50%, rgba(255,255,255,0.04) 100%);
  background-size: 200% 100%;
  animation: k-shimmer 1.6s infinite;
  border-radius: var(--r-md);
}
@keyframes k-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ============================================================================
 * Animations
 * ========================================================================= */

.k-fade-in { animation: k-fade-in var(--dur-base) var(--ease-out-expo); }
@keyframes k-fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.k-stagger > * {
  opacity: 0;
  animation: k-stagger-in var(--dur-slow) var(--ease-out-expo) forwards;
}
.k-stagger > *:nth-child(1) { animation-delay: 0ms; }
.k-stagger > *:nth-child(2) { animation-delay: 40ms; }
.k-stagger > *:nth-child(3) { animation-delay: 80ms; }
.k-stagger > *:nth-child(4) { animation-delay: 120ms; }
.k-stagger > *:nth-child(5) { animation-delay: 160ms; }
.k-stagger > *:nth-child(6) { animation-delay: 200ms; }
.k-stagger > *:nth-child(7) { animation-delay: 240ms; }
.k-stagger > *:nth-child(8) { animation-delay: 280ms; }
@keyframes k-stagger-in { to { opacity: 1; transform: none; } from { opacity: 0; transform: translateY(12px); } }

.k-breathe {
  animation: k-breathe 3s ease-in-out infinite;
}
@keyframes k-breathe {
  0%, 100% { box-shadow: 0 0 24px -4px var(--brand-glow); }
  50%      { box-shadow: 0 0 32px -2px var(--brand-glow-strong); }
}

/* ============================================================================
 * Sparkline / mini chart container
 * ========================================================================= */

.k-sparkline { display: block; width: 100%; height: 32px; }
.k-sparkline-tall { height: 56px; }

/* ============================================================================
 * Cmd palette
 * ========================================================================= */

.k-cmdk-overlay {
  position: fixed; inset: 0;
  background: rgba(7, 11, 20, 0.65);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  justify-content: center;
  padding-top: 12vh;
  animation: k-fade-in 180ms var(--ease-out-expo);
}
.k-cmdk-panel {
  width: min(640px, 92vw);
  max-height: 70vh;
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-2xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.k-cmdk-input {
  border: 0;
  border-bottom: 1px solid var(--border-default);
  background: transparent;
  padding: 16px 20px;
  font-size: var(--fs-lg);
  color: var(--text-primary);
}
.k-cmdk-input:focus { outline: none; }
.k-cmdk-list { overflow-y: auto; padding: 8px; }
.k-cmdk-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-md);
  cursor: pointer;
  font-size: var(--fs-md);
  color: var(--text-secondary);
  transition: background var(--dur-fast);
}
.k-cmdk-item.is-active, .k-cmdk-item:hover {
  background: rgba(20,184,184,0.08);
  color: var(--text-primary);
}
.k-cmdk-item .k-cmdk-shortcut {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--text-muted);
  padding: 2px 6px;
  background: var(--bg-700);
  border-radius: var(--r-sm);
  border: 1px solid var(--border-default);
}
.k-cmdk-group-label {
  padding: 12px 12px 4px;
  font-size: var(--fs-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* ============================================================================
 * Sidebar groups
 * ========================================================================= */

.k-side-group-label {
  padding: 16px 12px 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--text-disabled);
}
.k-side-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--r-lg);
  font-size: var(--fs-md);
  color: var(--text-secondary);
  transition: background var(--dur-fast), color var(--dur-fast);
  position: relative;
  width: 100%;
  text-align: left;
}
.k-side-item:hover { background: rgba(255,255,255,0.04); color: var(--text-primary); }
.k-side-item.is-active {
  background: linear-gradient(135deg, rgba(20,184,184,0.18), rgba(20,184,184,0.06));
  color: var(--brand-300);
  font-weight: 500;
}
.k-side-item.is-active::before {
  content: '';
  position: absolute;
  left: 0; top: 25%; bottom: 25%;
  width: 3px;
  background: var(--brand-400);
  border-radius: 0 2px 2px 0;
  box-shadow: 0 0 8px var(--brand-glow-strong);
}
.k-side-badge {
  margin-left: auto;
  padding: 1px 7px;
  border-radius: var(--r-full);
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  background: var(--danger-bg);
  color: var(--danger-400);
  border: 1px solid rgba(239,68,68,0.25);
}
.k-side-badge.is-warn { background: var(--warning-bg); color: var(--warning-400); border-color: rgba(245,158,11,0.25); }
.k-side-badge.is-info { background: var(--info-bg); color: var(--info-400); border-color: rgba(59,130,246,0.25); }

/* ============================================================================
 * Gauge (circular progress)
 * ========================================================================= */

.k-gauge {
  --pct: 0;
  --gauge-color: var(--brand-500);
  --size: 64px;
  width: var(--size);
  height: var(--size);
  border-radius: var(--r-full);
  background: conic-gradient(var(--gauge-color) calc(var(--pct) * 3.6deg), rgba(255,255,255,0.05) 0);
  display: grid;
  place-items: center;
  position: relative;
  transition: background var(--dur-slow) var(--ease-out-expo);
}
.k-gauge::before {
  content: '';
  position: absolute; inset: 6px;
  border-radius: var(--r-full);
  background: var(--surface);
}
.k-gauge .k-gauge-label {
  position: relative;
  z-index: 1;
  font-family: var(--font-mono);
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--text-primary);
}

/* ============================================================================
 * Heatmap zone tile
 * ========================================================================= */

.k-zone-tile {
  background: var(--surface);
  border: 1px solid var(--border-default);
  border-radius: var(--r-xl);
  padding: 14px;
  cursor: pointer;
  transition: all var(--dur-base) var(--ease-out-expo);
  position: relative;
  overflow: hidden;
}
.k-zone-tile:hover { transform: translateY(-2px); border-color: var(--brand-400); }
.k-zone-tile::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--zone-color, transparent) 0%, transparent 60%);
  opacity: 0.18;
  pointer-events: none;
}

/* ============================================================================
 * Toast (enhanced)
 * ========================================================================= */

.k-toast {
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  padding: 12px 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  font-size: var(--fs-md);
  animation: k-toast-in var(--dur-base) var(--ease-spring);
}
.k-toast.is-success { border-left: 3px solid var(--success-500); }
.k-toast.is-error   { border-left: 3px solid var(--danger-500); }
.k-toast.is-info    { border-left: 3px solid var(--info-500); }
.k-toast.is-warn    { border-left: 3px solid var(--warning-500); }
@keyframes k-toast-in { from { opacity: 0; transform: translateY(-12px) scale(0.96); } to { opacity: 1; transform: none; } }

/* ============================================================================
 * Focus rings (accessibility)
 * ========================================================================= */

.k-focusable:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: var(--r-md);
}

/* ============================================================================
 * Scrollbar
 * ========================================================================= */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.18); }
