/* =============================================================================
   AIGate Theme — AItalon Design System (aitalon.ru style)
   Terminal-inspired, glassmorphism, green accent, dark-first
   ============================================================================= */

/* =============================================================================
   CSS Variables — Dark Theme (Default)
   ============================================================================= */
:root {
  /* Colors — close to DevScore's quiet gray panels, with AIGate green accents */
  --bg: #020617;
  --bg2: #0f172a;
  --surface: rgba(17, 24, 39, 0.9);
  --surface-solid: #111827;
  --surface-section: rgba(15, 23, 42, 0.82);
  --surface-elevated: rgba(31, 41, 55, 0.72);
  --border: #334155;
  --border-light: #475569;
  --table-header: rgba(15, 23, 42, 0.78);
  --row-hover: rgba(16, 185, 129, 0.07);

  /* Text */
  --text: #e5e7eb;
  --text-muted: #94a3b8;
  --text-dim: #94a3b8;

  /* Primary — Terminal Green */
  --primary: #10b981;
  --primary-hover: #34d399;
  --primary-glow: rgba(16, 185, 129, 0.25);
  --primary-dim: rgba(16, 185, 129, 0.08);

  /* Accent — Cyan/Blue */
  --accent-cyan: #2dd4bf;
  --accent-cyan-glow: rgba(45, 212, 191, 0.15);

  /* Status */
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.15);
  --warning: #f59e0b;
  --warning-glow: rgba(245, 158, 11, 0.15);
  /* Keep status text above WCAG AA contrast on translucent dark surfaces. */
  --danger: #fb7185;
  --danger-glow: rgba(239, 68, 68, 0.15);

  /* Typography */
  --font-sans: 'Inter', 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'Share Tech Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Buttons */
  --btn-height-md: 42px;
  --btn-height-sm: 34px;
  --btn-padding-x: 1rem;
  --btn-padding-x-sm: 0.8rem;
  --btn-font-size: 0.875rem;

  /* Spacing & Sizing */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 10px;
  --radius-xl: 14px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(2, 6, 23, 0.26);
  --shadow-md: 0 10px 28px rgba(2, 6, 23, 0.32);
  --shadow-lg: 0 18px 44px rgba(2, 6, 23, 0.38);
  --shadow-glow: 0 10px 24px rgba(16, 185, 129, 0.12);

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-slow: 0.4s ease;

  /* Layout */
  --sidebar-width: 260px;
  --mobile-topbar-height: 56px;
  color-scheme: dark;
}

/* =============================================================================
   Light Theme
   ============================================================================= */
[data-theme="light"] {
  --bg: #f4f7fb;
  --bg2: #ffffff;
  --surface: rgba(255, 255, 255, 0.96);
  --surface-solid: #ffffff;
  --surface-section: rgba(249, 250, 251, 0.96);
  --surface-elevated: rgba(249, 250, 251, 0.92);
  --border: #e5e7eb;
  --border-light: #d1d5db;
  --table-header: rgba(249, 250, 251, 0.92);
  --row-hover: rgba(16, 185, 129, 0.05);

  --text: #111827;
  --text-muted: #4b5563;
  --text-dim: #4b5563;

  --primary: #036b4f;
  --primary-hover: #065f46;
  --primary-glow: rgba(16, 185, 129, 0.15);
  --primary-dim: rgba(16, 185, 129, 0.05);

  --accent-cyan: #0f766e;
  --accent-cyan-glow: rgba(15, 118, 110, 0.1);

  /* Status foregrounds must remain readable on pale status surfaces. */
  --success: #036b4f;
  --warning: #92400e;
  --danger: #b91c1c;

  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 10px 26px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 18px 42px rgba(15, 23, 42, 0.12);
  --shadow-glow: 0 10px 24px rgba(16, 185, 129, 0.1);
  color-scheme: light;
}

/* =============================================================================
   Base Reset & Global
   ============================================================================= */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  scrollbar-gutter: stable both-edges;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Prevent text/icon flicker during runtime theme switch. */
html.theme-switching *,
html.theme-switching *::before,
html.theme-switching *::after,
body.theme-switching *,
body.theme-switching *::before,
body.theme-switching *::after {
  transition: none !important;
}

img,
svg,
canvas,
video {
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
}

code,
pre,
kbd,
samp {
  font-family: var(--font-mono);
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: 0.75rem;
  z-index: 6000;
  padding: 0.65rem 0.9rem;
  border: 2px solid var(--primary);
  border-radius: var(--radius-md);
  background: var(--surface-solid);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
  text-decoration: none;
  box-shadow: var(--shadow-md);
  transform: translateY(calc(-100% - 1.5rem));
}

.skip-link:focus {
  transform: translateY(0);
}

/* Selection */
::selection {
  background: var(--primary);
  color: white;
}

/* =============================================================================
   Space Background Canvas
   ============================================================================= */
#space-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

[data-stop-motion="true"] #space-canvas {
  opacity: 1;
}

body[data-page-surface="configuration"] #space-canvas {
  display: none !important;
}

/* =============================================================================
   Layout
   ============================================================================= */
.mobile-topbar,
.sidebar-overlay {
  display: none;
}

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: color-mix(in srgb, var(--surface-solid) 88%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.mobile-nav-toggle {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-section);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.mobile-nav-toggle:hover {
  color: var(--primary);
  border-color: var(--primary);
}

.mobile-sidebar-close {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  min-width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-section);
  color: var(--text);
  cursor: pointer;
}

.mobile-sidebar-close svg {
  width: 1rem;
  height: 1rem;
}

.mobile-topbar-brand {
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  font-weight: 700;
}

.mobile-topbar-brand:hover {
  color: var(--primary);
}

.sidebar-header {
  padding: 1rem 1rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.55rem;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  min-height: 36px;
  min-width: 0;
  flex: 1;
}

.sidebar-logo .logo-icon {
  filter: drop-shadow(0 0 6px var(--primary-glow));
}

.sidebar-logo .logo-radar {
  opacity: 0.8;
}

.sidebar-logo .logo-radar > div {
  opacity: 0.6;
}

.sidebar-logo .logo-stack {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.1;
}

.sidebar-logo .logo-eyebrow {
  font-size: 0.52rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.sidebar-logo .logo-product {
  font-size: 1.02rem;
  letter-spacing: 0.08em;
  text-transform: none;
  font-weight: 650;
  color: var(--text);
  text-shadow: none;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0 0.85rem;
}

.nav-section {
  margin-bottom: 0.65rem;
}

.nav-section-title {
  padding: 0.35rem 1.1rem 0.25rem;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  text-transform: none;
  opacity: 1;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hint-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  opacity: 0.9;
  position: relative;
  user-select: none;
  transition: color var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

.hint-icon:hover {
  color: var(--primary);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.quiet-help-icon {
  width: 15px;
  height: 15px;
  margin-left: 0.35rem;
  vertical-align: middle;
  opacity: 0.62;
}

.quiet-help-icon:hover,
.quiet-help-icon:focus-visible,
.quiet-help-icon.tooltip-open {
  opacity: 1;
}

.aigate-quiet-help-source[hidden] {
  display: none !important;
}

.hint-icon::before,
.hint-icon::after {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  z-index: 1600;
}

.hint-icon::before {
  content: '';
  left: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%) translateX(-3px);
  border: 5px solid transparent;
  border-right-color: var(--border-light);
}

.hint-icon::after {
  content: attr(data-hint-text);
  left: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) translateX(-4px);
  min-width: 180px;
  max-width: 280px;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg2);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0.2px;
  text-transform: none;
  white-space: normal;
  box-shadow: var(--shadow-md);
}

.hint-icon:hover::before,
.hint-icon:hover::after,
.hint-icon:focus-visible::before,
.hint-icon:focus-visible::after,
.hint-icon.tooltip-open::before,
.hint-icon.tooltip-open::after {
  opacity: 1;
}

.hint-icon:hover::before,
.hint-icon:focus-visible::before,
.hint-icon.tooltip-open::before {
  transform: translateY(-50%) translateX(0);
}

.hint-icon:hover::after,
.hint-icon:focus-visible::after,
.hint-icon.tooltip-open::after {
  transform: translateY(-50%) translateX(0);
}

.hint-icon:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

body.hints-js-ready .hint-icon::before,
body.hints-js-ready .hint-icon::after {
  display: none;
}

.aigate-hint-tooltip {
  position: fixed;
  left: 0;
  top: 0;
  max-width: min(320px, calc(100vw - 24px));
  min-width: 180px;
  padding: 0.55rem 0.7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg2);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.35;
  box-shadow: var(--shadow-md);
  z-index: 5000;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transform: translateY(2px);
  transition: opacity var(--transition-fast), transform var(--transition-fast), visibility var(--transition-fast);
}

.aigate-hint-tooltip::after {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border: 6px solid transparent;
}

.aigate-hint-tooltip[data-placement="right"]::after {
  left: -11px;
  top: calc(50% - 6px);
  border-right-color: var(--border-light);
}

.aigate-hint-tooltip[data-placement="left"]::after {
  right: -11px;
  top: calc(50% - 6px);
  border-left-color: var(--border-light);
}

.aigate-hint-tooltip[data-placement="top"]::after {
  left: calc(50% - 6px);
  bottom: -11px;
  border-top-color: var(--border-light);
}

.aigate-hint-tooltip[data-placement="bottom"]::after {
  left: calc(50% - 6px);
  top: -11px;
  border-bottom-color: var(--border-light);
}

.aigate-hint-tooltip.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

@media (max-width: 1024px) {
  .hint-icon::before {
    left: 50%;
    top: calc(100% + 6px);
    transform: translateX(-50%) rotate(90deg);
    border-right-color: var(--border-light);
  }

  .hint-icon::after {
    left: 50%;
    top: calc(100% + 10px);
    transform: translateX(-50%) translateY(-3px);
    width: min(280px, calc(100vw - 2.5rem));
    min-width: 180px;
  }

  .hint-icon:hover::after,
  .hint-icon:focus-visible::after,
  .hint-icon.tooltip-open::after {
    transform: translateX(-50%) translateY(0);
  }
}

.table .hint-icon,
.form-label .hint-icon {
  margin-left: 6px;
  vertical-align: middle;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0.55rem;
  padding: 0.58rem 0.72rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 550;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  letter-spacing: 0.01em;
  line-height: 1.35;
}

.nav-link:hover {
  background: var(--surface-section);
  color: var(--text);
  border-color: color-mix(in srgb, var(--border) 72%, var(--primary) 28%);
}

html[data-theme="light"] .nav-link:hover {
  background: rgba(249, 250, 251, 0.92);
}

.nav-link.active {
  background: var(--primary-dim);
  color: var(--text);
  border-color: rgba(16, 185, 129, 0.42);
  text-shadow: none;
  box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.1);
}

.nav-link svg,
.nav-link i {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.9;
}

/* Keep sidebar/menu rendering static on page transitions (no jump/flicker effects). */
.sidebar .logo-radar > div,
.sidebar .logo-radar svg,
.sidebar .nav-link,
.sidebar .nav-link *,
.sidebar .theme-btn,
.sidebar .hint-icon,
.mobile-topbar .mobile-nav-toggle {
  animation: none !important;
  transition: none !important;
}

.sidebar-footer {
  padding: 0.85rem 1.1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-menu {
  position: relative;
}

.user-menu-toggle {
  width: 100%;
  padding: 0.72rem 0.8rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.user-menu-toggle:hover {
  border-color: var(--border);
  background: var(--surface-section);
}

html[data-theme="light"] .user-menu-toggle:hover {
  background: rgba(17, 24, 39, 0.03);
}

.user-menu[data-open="true"] .user-menu-toggle {
  border-color: rgba(16, 185, 129, 0.22);
  background: rgba(16, 185, 129, 0.05);
}

.user-menu-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 10px);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--surface-solid) 94%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-md);
  z-index: 140;
}

.user-menu-panel[hidden] {
  display: none;
}

.user-menu-section {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.user-menu-label {
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: none;
  color: var(--text-dim);
}

.user-menu-caret {
  width: 0.55rem;
  height: 0.55rem;
  margin-left: auto;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  flex-shrink: 0;
}

.user-menu[data-open="true"] .user-menu-caret {
  transform: rotate(-135deg);
}

.user-menu-logout-form,
.user-menu-action {
  width: 100%;
}

.user-menu-action {
  justify-content: center;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-dim);
  border: 1px solid var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
}

.user-details {
  flex: 1;
}

.user-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.user-role {
  font-size: 0.68rem;
  color: var(--text-dim);
  letter-spacing: 0.04em;
  text-transform: none;
}

.sidebar-theme-toggle {
  flex-shrink: 0;
  padding: 1px;
  gap: 1px;
  background: transparent;
  border-color: transparent;
  opacity: 0.68;
}

.sidebar-theme-toggle:hover {
  opacity: 1;
  border-color: rgba(255, 255, 255, 0.08);
}

html[data-theme="light"] .sidebar-theme-toggle:hover {
  border-color: rgba(17, 24, 39, 0.08);
}

.sidebar-theme-toggle .theme-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  color: var(--text-dim);
}

.sidebar-theme-toggle .theme-btn:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.sidebar-theme-toggle .theme-btn.active {
  background: rgba(16, 185, 129, 0.12);
  color: var(--text);
  box-shadow: none;
}

.user-lang-toggle {
  align-self: flex-start;
}

.main {
  margin-left: var(--sidebar-width);
  padding: 1.5rem;
  min-height: 100vh;
  width: calc(100% - var(--sidebar-width));
  max-width: calc(100vw - var(--sidebar-width));
  min-width: 0;
}

.main-content-wrap {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  min-width: 0;
}

.main-content-wrap>* {
  min-width: 0;
}

/* =============================================================================
   Theme Toggle
   ============================================================================= */
.theme-toggle {
  display: flex;
  gap: 2px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.theme-btn {
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: var(--font-sans);
  background: transparent;
  border: none;
  color: var(--text-muted);
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 1px;
}

.theme-btn .theme-icon {
  width: 14px;
  height: 14px;
  display: block;
}

.theme-btn:hover {
  color: var(--primary);
  background: var(--primary-dim);
}

.theme-btn.active {
  background: var(--primary);
  color: #000;
  box-shadow: 0 0 10px var(--primary-glow);
}

.motion-btn {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}

.motion-btn.active {
  background: var(--primary-dim);
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
}

.rocket-btn .rocket-icon {
  transition: transform 0.3s ease, color 0.3s ease;
  color: currentColor;
}

.rocket-btn.animating .rocket-icon {
  animation: rocket-pulse 1.5s ease-in-out infinite;
  color: var(--primary);
}

@keyframes rocket-pulse {

  0%,
  100% {
    transform: translateY(0) rotate(-45deg);
  }

  50% {
    transform: translateY(-3px) rotate(-45deg);
  }
}

/* =============================================================================
   Page Header
   ============================================================================= */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-header > * {
  min-width: 0;
}

.page-title {
  font-size: 1.38rem;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 0.25rem 0;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  text-shadow: none;
  line-height: 1.15;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.page-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
  letter-spacing: 0.5px;
  display: inline;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.page-subtitle-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  max-width: 100%;
}

.page-subtitle+.hint-icon,
.page-subtitle-row .hint-icon {
  margin-top: 0;
  margin-left: 6px;
  vertical-align: middle;
  position: relative;
  top: -1px;
  flex: 0 0 auto;
}

.page-subtitle-row .hint-icon {
  margin-left: 0;
}

/* =============================================================================
   Cards — Glassmorphism Style
   ============================================================================= */
.card {
  background: var(--surface);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-normal);
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.card:hover {
  border-color: color-mix(in srgb, var(--border-light) 72%, var(--primary) 28%);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  min-width: 0;
  margin-bottom: 1rem;
}

.card-header > * {
  min-width: 0;
}

.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  line-height: 1.35;
  max-width: 100%;
  overflow-wrap: anywhere;
}

/* =============================================================================
   Stats Grid
   ============================================================================= */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.stat-card {
  background: var(--surface);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
  transition: all var(--transition-normal);
  min-width: 0;
  overflow-wrap: anywhere;
}

.stat-card:hover {
  border-color: color-mix(in srgb, var(--border-light) 72%, var(--primary) 28%);
  box-shadow: var(--shadow-sm);
}

.stat-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  opacity: 0.8;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
  font-feature-settings: 'tnum';
  color: var(--text);
  max-width: 100%;
  overflow-wrap: anywhere;
}

.stat-change {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  margin-top: 0.5rem;
}

.stat-change.positive {
  color: var(--success);
}

.stat-change.negative {
  color: var(--danger);
}

/* =============================================================================
   Buttons — Skewed AItalon Style
   ============================================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--btn-height-md);
  padding: 0 var(--btn-padding-x);
  font-size: var(--btn-font-size);
  font-weight: 600;
  line-height: 1.2;
  font-family: var(--font-sans);
  letter-spacing: 0.01em;
  text-transform: none;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: normal;
  text-align: center;
  max-width: 100%;
  min-width: 0;
  flex: 0 1 auto;
  overflow-wrap: anywhere;
  position: relative;
}

.btn > span,
.btn > strong {
  min-width: 0;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.btn:disabled,
.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.58;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #02150f;
  box-shadow: 0 6px 14px rgba(16, 185, 129, 0.16);
}

[data-theme="light"] .btn-primary {
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 8px 18px var(--primary-glow);
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border-light);
  box-shadow: none;
}

.btn-secondary:hover {
  background: var(--primary-dim);
  border-color: rgba(16, 185, 129, 0.42);
  color: var(--primary);
  transform: translateY(-1px);
  box-shadow: none;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: white;
  box-shadow: 0 8px 18px rgba(239, 68, 68, 0.16);
}

.btn-danger:hover {
  background: #f87171;
  border-color: #f87171;
  transform: translateY(-1px);
  box-shadow: 0 10px 22px var(--danger-glow);
}

.btn-sm {
  min-height: var(--btn-height-sm);
  padding: 0 var(--btn-padding-x-sm);
  font-size: 0.8rem;
}

.btn-icon {
  width: var(--btn-height-md);
  min-width: var(--btn-height-md);
  height: var(--btn-height-md);
  padding: 0;
}

.btn svg,
.btn i {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

/* =============================================================================
   Tables
   ============================================================================= */
.table-container {
  overflow-x: auto;
  min-width: 0;
  max-width: 100%;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table thead th {
  padding: 0.76rem 0.9rem;
  text-align: left;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--table-header);
  border-bottom: 1px solid var(--border);
  opacity: 1;
}

.table tbody td {
  padding: 0.78rem 0.9rem;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  vertical-align: middle;
  font-size: 0.85rem;
}

[data-theme="light"] .table tbody td {
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.table tbody tr {
  transition: all var(--transition-fast);
}

.table tbody tr:hover {
  background: var(--row-hover);
}

/* =============================================================================
   Badges
   ============================================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  font-size: 0.65rem;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.5px;
  border-radius: 100px;
  text-transform: uppercase;
  max-width: 100%;
  white-space: normal;
  text-align: center;
  overflow-wrap: anywhere;
}

.badge-primary {
  background: var(--primary-dim);
  color: var(--primary);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-success {
  background: var(--success-glow);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-warning {
  background: var(--warning-glow);
  color: var(--warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-danger {
  background: var(--danger-glow);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-muted {
  background: rgba(107, 114, 128, 0.1);
  color: var(--text-muted);
  border: 1px solid rgba(107, 114, 128, 0.2);
}

/* =============================================================================
   Score Bar
   ============================================================================= */
.score {
  display: flex;
  align-items: center;
  gap: 8px;
}

.score-bar {
  width: 60px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.score-fill {
  height: 100%;
  border-radius: 2px;
  transition: width var(--transition-normal);
}

.score-low .score-fill {
  background: var(--success);
  box-shadow: 0 0 8px var(--success-glow);
}

.score-medium .score-fill {
  background: var(--warning);
  box-shadow: 0 0 8px var(--warning-glow);
}

.score-high .score-fill {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger-glow);
}

/* =============================================================================
   Forms
   ============================================================================= */
.form-group {
  margin-bottom: 1rem;
  min-width: 0;
}

.form-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--primary);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.8;
}

.form-input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 0.85rem;
  font-family: var(--font-sans);
  background: var(--surface-section);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  letter-spacing: 0.01em;
}

[data-theme="light"] .form-input {
  background: rgba(255, 255, 255, 0.8);
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-input::placeholder {
  color: var(--text-dim);
}

.form-input:user-invalid {
  border-color: color-mix(in srgb, var(--danger) 72%, var(--border));
}

.form-input:user-invalid:focus {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--danger) 22%, transparent);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
}

.form-hint.aigate-quiet-help-source,
.help-text.aigate-quiet-help-source,
.section-description.aigate-quiet-help-source {
  margin: 0 !important;
}

/* =============================================================================
   Alerts / Messages
   ============================================================================= */
.alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  font-size: 0.85rem;
  backdrop-filter: blur(8px);
  min-width: 0;
  max-width: 100%;
}

.alert > * {
  min-width: 0;
}

.alert-success {
  background: var(--success-glow);
  border: 1px solid var(--success);
  color: var(--success);
}

.alert-warning {
  background: var(--warning-glow);
  border: 1px solid var(--warning);
  color: var(--warning);
}

.alert-error {
  background: var(--danger-glow);
  border: 1px solid var(--danger);
  color: var(--danger);
}

.alert-close {
  background: none;
  border: none;
  color: inherit;
  font-size: 1.25rem;
  cursor: pointer;
  opacity: 0.7;
}

.alert-close:hover {
  opacity: 1;
}

/* =============================================================================
   Utility Classes
   ============================================================================= */
.mono {
  font-family: var(--font-mono);
  font-size: 0.85em;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.techno-label {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--primary);
  opacity: 0.7;
}

.fade-in {
  animation: fadeIn var(--transition-normal);
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Glow effect for special cards */
.glow-green {
  box-shadow: var(--shadow-glow);
  border-color: rgba(16, 185, 129, 0.42) !important;
}

.glow-blue {
  box-shadow: 0 10px 24px rgba(45, 212, 191, 0.12);
  border-color: rgba(45, 212, 191, 0.42) !important;
}

/* Terminal cursor blink */
@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

.cursor-blink::after {
  content: '▌';
  animation: blink 1s step-end infinite;
  color: var(--primary);
}

/* =============================================================================
   Scrollbar
   ============================================================================= */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* =============================================================================
   Animations
   ============================================================================= */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {

  0%,
  100% {
    opacity: 0.6;
    transform: scale(1);
  }

  50% {
    opacity: 1;
    transform: scale(1.15);
  }
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes rocket-pulse {

  0%,
  100% {
    transform: translateY(0) rotate(-45deg);
  }

  50% {
    transform: translateY(-3px) rotate(-45deg);
  }
}

.fade-in {
  animation: fadeIn 0.25s ease;
}

.cursor-blink::after {
  content: '▌';
  animation: blink 1s step-end infinite;
  color: var(--primary);
}

/* Glow effects */
.glow-green {
  box-shadow: var(--shadow-glow);
  border-color: rgba(16, 185, 129, 0.42) !important;
}

.glow-blue {
  box-shadow: 0 10px 24px rgba(45, 212, 191, 0.12);
  border-color: rgba(45, 212, 191, 0.42) !important;
}

/* =============================================================================
   Django Admin Override
   ============================================================================= */
body.django-admin #container {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
}

body.django-admin #header {
  background: var(--surface) !important;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

body.django-admin #header a:link,
body.django-admin #header a:visited {
  color: var(--primary) !important;
}

body.django-admin #branding h1 {
  color: var(--primary) !important;
  font-family: var(--font-mono);
  letter-spacing: 2px;
  text-transform: uppercase;
  text-shadow: none;
}

body.django-admin #user-tools {
  color: var(--text-muted);
}

body.django-admin #user-tools a {
  color: var(--primary) !important;
}

body.django-admin .module h2,
body.django-admin .module caption {
  background: rgba(16, 185, 129, 0.1) !important;
  color: var(--primary) !important;
  font-family: var(--font-mono);
  letter-spacing: 1px;
  border: none;
}

body.django-admin .module {
  background: var(--surface);
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-md);
}

body.django-admin div.breadcrumbs {
  background: var(--surface) !important;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}

body.django-admin div.breadcrumbs a {
  color: var(--primary) !important;
}

body.django-admin .button,
body.django-admin input[type=submit],
body.django-admin .submit-row input {
  background: var(--primary) !important;
  color: #02150f !important;
  font-family: var(--font-sans);
  letter-spacing: 0.01em;
  border: 1px solid var(--primary) !important;
  border-radius: var(--radius-md);
  min-height: 40px;
  padding: 0 16px;
  text-transform: none;
}

body.django-admin .button:hover,
body.django-admin input[type=submit]:hover {
  background: var(--primary-hover) !important;
}

body.django-admin .button.default {
  background: var(--primary) !important;
}

body.django-admin .deletelink {
  color: var(--danger) !important;
}

body.django-admin #changelist-filter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

body.django-admin #changelist-filter h2 {
  color: var(--primary);
}

body.django-admin #changelist-filter li.selected a {
  color: var(--primary) !important;
  font-weight: 700;
}

body.django-admin #changelist table thead th {
  background: rgba(16, 185, 129, 0.05);
  border-bottom: 1px solid var(--border);
}

body.django-admin #changelist table thead th a:link {
  color: var(--primary) !important;
}

body.django-admin a:link,
body.django-admin a:visited {
  color: var(--primary);
}

body.django-admin #content {
  background: transparent;
}

/* =============================================================================
   UX Quiet Pass
   ============================================================================= */
#space-canvas {
  opacity: 0.14;
}

html[data-theme="light"] #space-canvas {
  opacity: 0.06;
}

.sidebar {
  background: color-mix(in srgb, var(--surface-solid) 94%, transparent);
}

.sidebar-logo .logo-radar {
  opacity: 0.56;
}

.sidebar-logo .logo-radar > div {
  opacity: 0.24;
}

.nav-section-title,
.user-menu-label,
.user-role,
.techno-label,
.stat-label,
.table thead th,
.form-label,
.badge {
  letter-spacing: 0;
  text-transform: none;
}

.techno-label,
.form-label,
.card-title {
  color: var(--text-muted);
}

.techno-label {
  font-size: 0.68rem;
  opacity: 1;
}

.page-title {
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  font-size: 1.28rem;
  font-weight: 700;
}

.page-subtitle {
  letter-spacing: 0;
}

.card,
.stat-card,
.user-menu-panel,
.alert {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.card:hover,
.stat-card:hover {
  border-color: var(--border-light);
  box-shadow: var(--shadow-sm);
}

.nav-link:hover {
  background: var(--surface-section);
  border-color: var(--border);
}

.nav-link.active {
  border-color: rgba(16, 185, 129, 0.32);
  background: color-mix(in srgb, var(--primary) 9%, var(--surface-section));
  box-shadow: none;
}

.btn-primary,
.btn-danger {
  box-shadow: none;
}

.btn-primary:hover,
.btn-secondary:hover,
.btn-danger:hover {
  transform: none;
}

.btn-primary:hover {
  box-shadow: none;
}

.btn-secondary:hover {
  background: var(--surface-section);
  border-color: var(--border-light);
  color: var(--text);
}

.theme-btn.active,
.motion-btn.active,
.glow-green,
.glow-blue,
.score-low .score-fill,
.score-medium .score-fill,
.score-high .score-fill {
  box-shadow: none;
}

.theme-btn.active {
  color: #02150f;
}

.form-label {
  font-size: 0.74rem;
  font-weight: 600;
  opacity: 1;
}

.form-input:focus,
.btn:focus-visible {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 22%, transparent);
}

.badge {
  font-family: var(--font-sans);
  font-size: 0.72rem;
  line-height: 1.2;
}

/* =============================================================================
   Scrollbar
   ============================================================================= */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-light);
}

/* =============================================================================
   Responsive
   ============================================================================= */
@media (max-width: 1024px) {
  :root {
    --mobile-topbar-height: calc(56px + env(safe-area-inset-top));
  }

  body.mobile-nav-open {
    overflow: hidden;
  }

  .mobile-topbar {
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    min-height: var(--mobile-topbar-height);
    padding: calc(0.5rem + env(safe-area-inset-top)) calc(0.85rem + env(safe-area-inset-right)) 0.5rem calc(0.85rem + env(safe-area-inset-left));
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    z-index: 2400;
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    opacity: 0;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.56);
    transition: opacity var(--transition-normal);
    z-index: 2200;
  }

  body.mobile-nav-open .sidebar-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    width: min(320px, 88vw);
    height: 100dvh;
    padding-left: env(safe-area-inset-left);
    transform: translateX(calc(-100% - 16px));
    transition: transform var(--transition-normal), box-shadow var(--transition-normal);
    z-index: 2300;
    box-shadow: 12px 0 24px rgba(0, 0, 0, 0.45);
  }

  body.mobile-nav-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-header {
    padding: 1rem 1rem 0.85rem;
  }

  .sidebar-header-bar {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.65rem;
  }

  .mobile-sidebar-close {
    display: inline-flex;
  }

  .nav-section-title {
    padding: 0.45rem 1rem;
  }

  .nav-link {
    padding: 0.72rem 1rem;
  }

  .sidebar-footer {
    padding: 0.9rem 1rem calc(0.9rem + env(safe-area-inset-bottom));
  }

  .user-menu-panel {
    position: static;
    left: auto;
    right: auto;
    bottom: auto;
    margin-top: 0.55rem;
    box-shadow: none;
  }

  .main {
    margin-left: 0;
    padding: calc(var(--mobile-topbar-height) + 1rem) calc(1rem + env(safe-area-inset-right)) calc(1rem + env(safe-area-inset-bottom)) calc(1rem + env(safe-area-inset-left));
    width: 100%;
    max-width: 100%;
  }

  .page-header {
    position: sticky;
    top: calc(var(--mobile-topbar-height) + 0.2rem);
    z-index: 1200;
    margin: 0 -0.2rem 1rem;
    padding: 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
  }

  .main-content-wrap {
    max-width: 100%;
  }

  .table-container {
    margin: 0 -0.2rem;
    padding-bottom: 0.25rem;
  }

  .table:not(.ui-table-responsive) {
    min-width: 720px;
  }

  .table.ui-table-responsive {
    min-width: 0;
  }
}

@media (max-width: 768px) {
  .sidebar-theme-toggle .theme-btn {
    width: 28px;
    height: 28px;
  }

  .main {
    padding: calc(var(--mobile-topbar-height) + 0.85rem) calc(0.75rem + env(safe-area-inset-right)) calc(0.9rem + env(safe-area-inset-bottom)) calc(0.75rem + env(safe-area-inset-left));
  }

  .page-header {
    position: static;
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
    top: calc(var(--mobile-topbar-height) + 0.1rem);
    padding: 0.62rem;
  }

  .sidebar {
    width: min(300px, 90vw);
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .page-title {
    font-size: 1.2rem;
    letter-spacing: 1px;
  }

  .card {
    padding: 1rem;
  }

  .card-header {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.65rem;
  }

  .btn {
    min-height: 44px;
    padding: 0 0.9rem;
  }

  .btn-icon {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }

  .mobile-nav-toggle,
  .mobile-sidebar-close {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }

  .hint-icon {
    min-width: 1.75rem;
    min-height: 1.75rem;
  }

  .form-input {
    font-size: 16px;
  }

  .alert {
    gap: 0.45rem;
    flex-wrap: wrap;
  }
}

@media (max-width: 480px) {
  .sidebar-header-bar {
    gap: 0.5rem;
  }

  .sidebar-logo {
    flex-basis: auto;
  }

  .user-menu-toggle {
    padding: 0.68rem 0.74rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }
}

/* Keyboard and assistive-technology baseline shared by every product screen. */
.btn:focus-visible,
.nav-link:focus-visible,
.theme-btn:focus-visible,
.gate-ctx-btn:focus-visible,
.mobile-nav-toggle:focus-visible,
.mobile-sidebar-close:focus-visible,
.user-menu-toggle:focus-visible,
.alert-close:focus-visible,
a:focus-visible,
summary:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible {
  outline: 2px solid color-mix(in srgb, var(--primary) 78%, white 22%);
  outline-offset: 2px;
}

.form-input:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 24%, transparent);
}

.nav-link[aria-current="page"] {
  color: var(--text);
}

.btn[aria-busy="true"] {
  cursor: progress;
  opacity: 0.72;
}

:target {
  scroll-margin-top: calc(var(--mobile-topbar-height) + 1rem);
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  #space-canvas {
    display: none;
  }
}
