@import url('https://fonts.googleapis.com/css2?family=Google+Sans+Flex:opsz,wght@9..144,300..800&family=Google+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400;1,500;1,700&family=Google+Sans+Code:ital,wght@0,400..700;1,400..700&display=swap');

/**
 * ====================================================================
 * GOOGLE ANTIGRAVITY & FUTURISTIC HUD DESIGN SYSTEM
 * Architecture: CSS Cascade Layers + 4px/8px Modular Scale + Dual Theme
 * Compatible with HTMX SPAs, Bootstrap 5 & Shadcn Token Bridge
 * ====================================================================
 */

@layer tokens, reset, base, layout, components, hud, utilities;

@layer tokens {
  :root,
  [data-theme="light"] {
    /* Base Surfaces & Canvas */
    --bg-canvas: #f8fafc;
    --bg-canvas-mesh: radial-gradient(circle at 15% 0%, rgba(37, 99, 235, 0.04) 0%, transparent 45%),
                      radial-gradient(circle at 85% 10%, rgba(14, 165, 233, 0.04) 0%, transparent 45%),
                      #f8fafc;
    --bg-surface-raw: 255 255 255;
    --bg-surface: #ffffff;
    --bg-surface-glass: rgba(255, 255, 255, 0.88);
    --bg-elevated: #f1f5f9;
    --bg-subdued: #f8fafc;
    --bg-hover: #e2e8f0;
    --bg-active: #cbd5e1;

    /* Text & Foregrounds */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;

    /* Borders & Highlighting */
    --border-subtle: #f1f5f9;
    --border-default: #e2e8f0;
    --border-strong: #cbd5e1;
    --border-focus: #2563eb;
    --border-glass: rgba(226, 232, 240, 0.8);
    --specular-highlight: inset 0 1px 0 0 rgba(255, 255, 255, 0.95);

    /* Google Blue Accents & Interactive States */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-active: #1e40af;
    --primary-subdued: rgba(37, 99, 235, 0.08);
    --primary-border: rgba(37, 99, 235, 0.25);
    --primary-glow: rgba(37, 99, 235, 0.35);
    --primary-fg: #ffffff;

    /* Semantic Status & Telemetry */
    --info: #0284c7;
    --info-subdued: rgba(2, 132, 199, 0.08);
    --info-border: rgba(2, 132, 199, 0.3);

    --success: #059669;
    --success-subdued: rgba(5, 150, 105, 0.08);
    --success-border: rgba(5, 150, 105, 0.3);

    --warning: #d97706;
    --warning-subdued: rgba(217, 119, 6, 0.08);
    --warning-border: rgba(217, 119, 6, 0.3);

    --danger: #dc2626;
    --danger-subdued: rgba(220, 38, 38, 0.08);
    --danger-border: rgba(220, 38, 38, 0.3);

    /* Shadows & Elevation */
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.08), 0 1px 2px -1px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.08);
    --shadow-focus: 0 0 0 3px rgba(37, 99, 235, 0.18);

    /* Fixed Dark Terminal Code Surface */
    --code-bg: #0d1117;
    --code-fg: #e6edf3;
    --code-border: #30363d;
    --code-header-bg: #161b22;
  }

  [data-theme="dark"],
  :root.dark {
    /* Base Surfaces & Canvas */
    --bg-canvas: #0b0f19;
    --bg-canvas-mesh: radial-gradient(circle at 15% 0%, rgba(59, 130, 246, 0.09) 0%, transparent 50%),
                      radial-gradient(circle at 85% 10%, rgba(99, 102, 241, 0.06) 0%, transparent 45%),
                      #0b0f19;
    --bg-surface-raw: 17 24 39;
    --bg-surface: #111827;
    --bg-surface-glass: rgba(17, 24, 39, 0.82);
    --bg-elevated: #1f2937;
    --bg-subdued: #151d30;
    --bg-hover: #1f2937;
    --bg-active: #374151;

    /* Text & Foregrounds */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-inverse: #0f172a;

    /* Borders & Highlighting */
    --border-subtle: #1e293b;
    --border-default: #2d3748;
    --border-strong: #4b5563;
    --border-focus: #3b82f6;
    --border-glass: rgba(255, 255, 255, 0.08);
    --specular-highlight: inset 0 1px 0 0 rgba(255, 255, 255, 0.12);

    /* Google Blue Accents & Interactive States */
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-active: #2563eb;
    --primary-subdued: rgba(59, 130, 246, 0.15);
    --primary-border: rgba(59, 130, 246, 0.35);
    --primary-glow: rgba(59, 130, 246, 0.45);
    --primary-fg: #ffffff;

    /* Semantic Status & Telemetry */
    --info: #38bdf8;
    --info-subdued: rgba(56, 189, 248, 0.12);
    --info-border: rgba(56, 189, 248, 0.3);

    --success: #10b981;
    --success-subdued: rgba(16, 185, 129, 0.12);
    --success-border: rgba(16, 185, 129, 0.3);

    --warning: #f59e0b;
    --warning-subdued: rgba(245, 158, 11, 0.12);
    --warning-border: rgba(245, 158, 11, 0.3);

    --danger: #ef4444;
    --danger-subdued: rgba(239, 68, 68, 0.12);
    --danger-border: rgba(239, 68, 68, 0.3);

    /* Shadows & Elevation */
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4), 0 1px 2px -1px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -4px rgba(0, 0, 0, 0.6);
    --shadow-focus: 0 0 0 3px rgba(59, 130, 246, 0.25);

    /* Dark Code Terminal Surface */
    --code-bg: #090d16;
    --code-fg: #e6edf3;
    --code-border: #1e293b;
    --code-header-bg: #0f172a;
  }

  :root {
    /* 4px / 8px Strict Modular Spacing System */
    --space-1: 4px;
    --space-1-5: 6px;
    --space-2: 8px;
    --space-2-5: 10px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;

    /* Typography */
    --font-sans: 'Google Sans Flex', 'Google Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-mono: 'Google Sans Code', 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    --font-code: "Google Sans Code", "JetBrains Mono", "Fira Code", monospace;

    /* Typographic Scales */
    --text-xs: 0.75rem;     /* 12px */
    --text-sm: 0.875rem;    /* 14px */
    --text-base: 1rem;      /* 16px */
    --text-lg: 1.125rem;    /* 18px */
    --text-xl: 1.25rem;     /* 20px */
    --text-2xl: 1.5rem;     /* 24px */
    --text-3xl: 1.875rem;   /* 30px */

    /* Leading */
    --leading-tight: 1.25;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;

    /* Radii */
    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    /* Layout Metrics */
    --header-height: 56px;
    --sidebar-width: 250px;
    --blur-glass: 16px;
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-snappy: 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  }
}

@layer base {
  /* Native View Transition API */
  @view-transition {
    navigation: auto;
  }
  ::view-transition-old(root),
  ::view-transition-new(root) {
    animation-duration: 0.18s;
    animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  }
}

@layer components {
  /* --- Holographic Glass Panels --- */
  .ag-glass-panel,
  .hud-panel {
    background: var(--bg-surface-glass);
    backdrop-filter: blur(var(--blur-glass));
    -webkit-backdrop-filter: blur(var(--blur-glass));
    border: 1px solid var(--border-glass);
    box-shadow: var(--specular-highlight), var(--shadow-sm);
    border-radius: var(--radius-md);
    position: relative;
    overflow: hidden;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  }

  .ag-glass-panel::after,
  .hud-panel::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    opacity: 0;
    transition: opacity var(--transition-snappy);
    pointer-events: none;
  }

  .ag-glass-panel:hover::after,
  .hud-panel:hover::after {
    opacity: 0.8;
  }

  /* --- Calibrated Dense Form Controls (36px Height Standard) --- */
  .ag-form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-1-5);
    margin-bottom: var(--space-4);
  }

  .ag-form-label {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
  }

  .ag-form-input,
  .ag-form-select,
  .ag-form-textarea {
    width: 100%;
    height: 36px;
    padding: 0 var(--space-3);
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: var(--text-sm);
    box-shadow: var(--shadow-xs);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  }

  .ag-form-textarea {
    height: auto;
    padding: var(--space-2) var(--space-3);
    min-height: 84px;
  }

  .ag-form-input:focus,
  .ag-form-select:focus,
  .ag-form-textarea:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: var(--shadow-focus);
  }

  .ag-form-input::placeholder {
    color: var(--text-muted);
  }

  .ag-form-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
  }

  /* --- Standardized Callouts & Note Boxes --- */
  .ag-callout {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    margin: var(--space-4) 0;
    border-left: 4px solid var(--primary);
    background-color: var(--primary-subdued);
    display: flex;
    gap: var(--space-3);
    align-items: flex-start;
  }

  .ag-callout-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin-top: 2px;
  }

  .ag-callout-content {
    flex: 1;
    font-size: var(--text-sm);
  }

  .ag-callout-title {
    font-weight: 600;
    margin-bottom: var(--space-1);
  }

  .ag-callout p:last-child {
    margin-bottom: 0;
  }

  .ag-callout-info {
    border-left-color: var(--info);
    background-color: var(--info-subdued);
  }
  .ag-callout-info .ag-callout-title { color: var(--info); }

  .ag-callout-tip {
    border-left-color: var(--success);
    background-color: var(--success-subdued);
  }
  .ag-callout-tip .ag-callout-title { color: var(--success); }

  .ag-callout-warning {
    border-left-color: var(--warning);
    background-color: var(--warning-subdued);
  }
  .ag-callout-warning .ag-callout-title { color: var(--warning); }

  .ag-callout-danger {
    border-left-color: var(--danger);
    background-color: var(--danger-subdued);
  }
  .ag-callout-danger .ag-callout-title { color: var(--danger); }

  /* --- Fixed Dark Code Blocks with Syntax Copy Button --- */
  .ag-code-block {
    background-color: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: var(--radius-md);
    margin: var(--space-4) 0;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
  }

  .ag-code-header {
    background-color: var(--code-header-bg);
    border-bottom: 1px solid var(--code-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-1-5) var(--space-3);
  }

  .ag-code-lang {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    color: #8b949e;
    font-weight: 500;
  }

  .ag-code-copy-btn {
    background: transparent;
    border: none;
    color: #8b949e;
    cursor: pointer;
    padding: 3px 8px;
    border-radius: var(--radius-xs);
    font-size: var(--text-xs);
    font-family: var(--font-sans);
    display: flex;
    align-items: center;
    gap: 4px;
    transition: all var(--transition-fast);
  }

  .ag-code-copy-btn:hover {
    background-color: rgba(255, 255, 255, 0.12);
    color: #f0f6fc;
  }

  .ag-code-pre {
    padding: var(--space-3) var(--space-4);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--code-fg);
    margin: 0;
  }

  .ag-code-inline {
    font-family: var(--font-mono);
    font-size: 0.88em;
    padding: 0.15em 0.35em;
    background-color: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xs);
    color: var(--primary);
  }

  /* --- Pulsing Radar Telemetry Beacons --- */
  .ag-beacon {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .ag-beacon-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    position: relative;
  }

  .ag-beacon-dot.live {
    background-color: var(--success);
    box-shadow: 0 0 8px var(--success);
  }

  .ag-beacon-dot.live::after {
    content: "";
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 1px solid var(--success);
    animation: agBeaconPulse 2s infinite cubic-bezier(0, 0, 0.2, 1);
  }

  .ag-beacon-dot.warning {
    background-color: var(--warning);
    box-shadow: 0 0 8px var(--warning);
  }

  .ag-beacon-dot.danger {
    background-color: var(--danger);
    box-shadow: 0 0 8px var(--danger);
  }

  @keyframes agBeaconPulse {
    0% { transform: scale(0.8); opacity: 1; }
    100% { transform: scale(2.4); opacity: 0; }
  }

  /* --- Badges & Status Pills --- */
  .ag-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.4;
  }

  .ag-badge-blue { background: var(--primary-subdued); color: var(--primary); }
  .ag-badge-green { background: var(--success-subdued); color: var(--success); }
  .ag-badge-amber { background: var(--warning-subdued); color: var(--warning); }
  .ag-badge-red { background: var(--danger-subdued); color: var(--danger); }

  /* ─── Global Bootstrap .badge Glass Override ─── */
  /* Replaces Bootstrap's solid opaque badges with theme-aware glass pills      */
  /* Works with all existing .badge usage: rounded-pill, px-*, fw-*, font-mono  */
  .badge {
    font-family: var(--font-sans) !important;
    font-size: 0.72rem !important;
    font-weight: 600 !important;
    letter-spacing: 0.01em !important;
    line-height: 1.4 !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 3px !important;
    backdrop-filter: blur(8px) saturate(160%) !important;
    -webkit-backdrop-filter: blur(8px) saturate(160%) !important;
    border: 1px solid transparent !important;
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease !important;
    vertical-align: middle !important;
  }

  /* font-monospace override within badges (metric values, counts, IDs) */
  .badge.font-monospace,
  .badge .font-monospace {
    font-family: var(--font-mono) !important;
  }

  /* Semantic Glass Variants — bg-* maps to token-subdued + token-border */
  .badge.bg-primary {
    background: var(--primary-subdued) !important;
    color: var(--primary) !important;
    border-color: var(--primary-border) !important;
  }
  .badge.bg-success {
    background: var(--success-subdued) !important;
    color: var(--success) !important;
    border-color: var(--success-border) !important;
  }
  .badge.bg-danger {
    background: var(--danger-subdued) !important;
    color: var(--danger) !important;
    border-color: var(--danger-border) !important;
  }
  .badge.bg-warning {
    background: var(--warning-subdued) !important;
    color: var(--warning) !important;
    border-color: var(--warning-border) !important;
  }
  .badge.bg-info {
    background: var(--info-subdued) !important;
    color: var(--info) !important;
    border-color: var(--info-border) !important;
  }
  .badge.bg-secondary {
    background: rgba(100, 116, 139, 0.12) !important;
    color: var(--text-secondary) !important;
    border-color: rgba(100, 116, 139, 0.25) !important;
  }
  .badge.bg-dark {
    background: rgba(15, 23, 42, 0.5) !important;
    color: var(--text-primary) !important;
    border-color: var(--border-default) !important;
  }
  .badge.bg-light {
    background: rgba(248, 250, 252, 0.75) !important;
    color: var(--text-secondary) !important;
    border-color: var(--border-default) !important;
  }

  /* bg-opacity-* glass shim — strip Bootstrap's opacity modifier interference */
  /* These are the most common combos used in templates: bg-*  bg-opacity-25/20 */
  .badge.bg-primary.bg-opacity-25,
  .badge.bg-primary.bg-opacity-20 {
    background: var(--primary-subdued) !important;
    color: var(--primary) !important;
    border-color: var(--primary-border) !important;
  }
  .badge.bg-success.bg-opacity-25,
  .badge.bg-success.bg-opacity-20 {
    background: var(--success-subdued) !important;
    color: var(--success) !important;
    border-color: var(--success-border) !important;
  }
  .badge.bg-danger.bg-opacity-25,
  .badge.bg-danger.bg-opacity-20 {
    background: var(--danger-subdued) !important;
    color: var(--danger) !important;
    border-color: var(--danger-border) !important;
  }
  .badge.bg-warning.bg-opacity-25,
  .badge.bg-warning.bg-opacity-20 {
    background: var(--warning-subdued) !important;
    color: var(--warning) !important;
    border-color: var(--warning-border) !important;
  }
  .badge.bg-info.bg-opacity-25,
  .badge.bg-info.bg-opacity-20 {
    background: var(--info-subdued) !important;
    color: var(--info) !important;
    border-color: var(--info-border) !important;
  }
  .badge.bg-secondary.bg-opacity-25,
  .badge.bg-secondary.bg-opacity-20 {
    background: rgba(100, 116, 139, 0.12) !important;
    color: var(--text-secondary) !important;
    border-color: rgba(100, 116, 139, 0.25) !important;
  }

  /* Explicit text-* color overrides — High Contrast Semantic Tokens */
  .badge.text-primary,
  :root.dark .badge.text-primary,
  [data-theme="dark"] .badge.text-primary { color: #38bdf8 !important; }
  .badge.text-success,
  :root.dark .badge.text-success,
  [data-theme="dark"] .badge.text-success { color: #4ade80 !important; }
  .badge.text-danger,
  :root.dark .badge.text-danger,
  [data-theme="dark"] .badge.text-danger  { color: #f87171 !important; }
  .badge.text-warning,
  :root.dark .badge.text-warning,
  [data-theme="dark"] .badge.text-warning { color: #fde047 !important; }
  .badge.text-info,
  :root.dark .badge.text-info,
  [data-theme="dark"] .badge.text-info    { color: #38bdf8 !important; }
  .badge.text-light,
  :root.dark .badge.text-light,
  [data-theme="dark"] .badge.text-light   { color: #fafafa !important; }
  .badge.text-muted,
  :root.dark .badge.text-muted,
  [data-theme="dark"] .badge.text-muted   { color: #a1a1aa !important; }

  [data-theme="light"] .badge.text-primary { color: #0284c7 !important; }
  [data-theme="light"] .badge.text-success { color: #16a34a !important; }
  [data-theme="light"] .badge.text-danger  { color: #dc2626 !important; }
  [data-theme="light"] .badge.text-warning { color: #b45309 !important; }
  [data-theme="light"] .badge.text-info    { color: #0284c7 !important; }
  [data-theme="light"] .badge.text-light   { color: #18181b !important; }
  [data-theme="light"] .badge.text-muted   { color: #71717a !important; }

  /* --- HTMX Top Progress Indicator Bar --- */
  .htmx-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 2.5px;
    width: 0%;
    background: linear-gradient(90deg, #2563eb, #38bdf8);
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: width 0.3s ease, opacity 0.2s ease;
    box-shadow: 0 0 10px rgba(37, 99, 235, 0.6);
  }

  .htmx-request.htmx-progress-bar,
  body.htmx-request .htmx-progress-bar {
    opacity: 1;
    width: 80%;
  }
}

@layer hud {
  /* --- Spotlight Command Palette HUD (Cmd+K) --- */
  .ag-cmd-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10500;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 14vh;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease-out;
  }

  .ag-cmd-backdrop.active {
    opacity: 1;
    pointer-events: auto;
  }

  .ag-cmd-box {
    width: 100%;
    max-width: 620px;
    background: var(--bg-surface-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-glass);
    box-shadow: var(--specular-highlight), 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    border-radius: 12px;
    overflow: hidden;
    transform: scale(0.96) translateY(-8px);
    transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .ag-cmd-backdrop.active .ag-cmd-box {
    transform: scale(1) translateY(0);
  }

  .ag-cmd-input-wrapper {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-default);
    gap: 10px;
  }

  .ag-cmd-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    font-family: var(--font-sans);
  }

  .ag-cmd-input::placeholder {
    color: var(--text-muted);
  }

  .ag-cmd-results {
    max-height: 360px;
    overflow-y: auto;
    padding: 8px;
  }

  .ag-cmd-group-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    padding: 6px 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .ag-cmd-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 12px;
    border-radius: 6px;
    color: var(--text-primary);
    text-decoration: none !important;
    font-size: 13.5px;
    font-weight: 500;
    transition: background-color var(--transition-fast);
    cursor: pointer;
  }

  .ag-cmd-item:hover,
  .ag-cmd-item:focus {
    background-color: var(--primary-subdued);
    color: var(--primary);
  }

  /* --- Antigravity Institutional Table & Drawer Specifications --- */
  .custom-glass-table,
  table.custom-glass-table {
    font-family: var(--font-sans);
    color: var(--text-primary);
    border-collapse: separate;
    border-spacing: 0;
  }

  .custom-glass-table thead th {
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text-muted) !important;
    vertical-align: middle;
  }

  .custom-glass-table tbody tr {
    transition: background-color var(--transition-fast);
  }

  .custom-glass-table tbody tr:hover td {
    background-color: var(--bg-hover) !important;
  }

  .custom-glass-table td {
    font-family: var(--font-sans);
    vertical-align: middle;
  }

  .trade-row-drawer {
    font-family: var(--font-sans);
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    box-shadow: var(--shadow-lg);
  }

  .trade-drawer-narrative {
    font-family: var(--font-sans) !important;
    font-size: 0.75rem;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  /* --- Global Antigravity HUD Switch Toggle Engine --- */
  .form-check.form-switch,
  .form-switch {
    padding-left: 0 !important;
    margin-bottom: 0 !important;
    display: inline-flex;
    align-items: center;
  }

  .form-switch .form-check-input,
  .form-check.form-switch .form-check-input,
  input[type="checkbox"][role="switch"],
  input[type="checkbox"].form-switch-input,
  input[type="checkbox"].edit-rule-toggle {
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    width: 2.6rem !important;
    height: 1.35rem !important;
    min-width: 2.6rem !important;
    min-height: 1.35rem !important;
    background-color: var(--bg-elevated) !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23ffffff'/%3e%3c/svg%3e") !important;
    background-position: left 2px center !important;
    background-repeat: no-repeat !important;
    background-size: 1.1rem 1.1rem !important;
    border: 1.5px solid var(--border-default) !important;
    border-radius: 9999px !important;
    cursor: pointer !important;
    transition: background-position 0.2s cubic-bezier(0.16, 1, 0.3, 1), background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease !important;
    display: inline-block !important;
    vertical-align: middle !important;
    float: none !important;
    margin: 0 !important;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.2) !important;
    --bs-form-check-bg-image: none !important;
    --bs-form-switch-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23ffffff'/%3e%3c/svg%3e") !important;
  }

  /* Checked Active State (Pure Solid Knob on Right with Vibrant Track) */
  .form-switch .form-check-input:checked,
  .form-check.form-switch .form-check-input:checked,
  input[type="checkbox"][role="switch"]:checked,
  input[type="checkbox"].form-switch-input:checked,
  input[type="checkbox"].edit-rule-toggle:checked {
    background-color: #10b981 !important;
    border-color: #059669 !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23ffffff'/%3e%3c/svg%3e") !important;
    background-position: right 2px center !important;
    background-repeat: no-repeat !important;
    background-size: 1.1rem 1.1rem !important;
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.45), inset 0 1px 2px rgba(0, 0, 0, 0.15) !important;
    --bs-form-check-bg-image: none !important;
  }

  .form-switch .form-check-input:focus,
  .form-check.form-switch .form-check-input:focus,
  input[type="checkbox"][role="switch"]:focus,
  input[type="checkbox"].form-switch-input:focus,
  input[type="checkbox"].edit-rule-toggle:focus {
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.25) !important;
  }

  /* Suppress ANY pseudo-element checkmark on switch controls */
  .form-switch .form-check-input::before,
  .form-switch .form-check-input::after,
  .form-check.form-switch .form-check-input::before,
  .form-check.form-switch .form-check-input::after,
  input[type="checkbox"][role="switch"]::before,
  input[type="checkbox"][role="switch"]::after,
  input[type="checkbox"].form-switch-input::before,
  input[type="checkbox"].form-switch-input::after,
  input[type="checkbox"].edit-rule-toggle::before,
  input[type="checkbox"].edit-rule-toggle::after {
    content: none !important;
    display: none !important;
  }

  /* Light Theme Specific Contrast Calibration for Switches */
  :root[data-theme="light"] .form-switch .form-check-input:not(:checked),
  :root[data-theme="light"] .form-check.form-switch .form-check-input:not(:checked),
  :root[data-theme="light"] input[type="checkbox"][role="switch"]:not(:checked),
  :root[data-theme="light"] input[type="checkbox"].edit-rule-toggle:not(:checked) {
    background-color: #e2e8f0 !important;
    border-color: #cbd5e1 !important;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%2364748b'/%3e%3c/svg%3e") !important;
  }
}

@layer layout {
  /* ═══════════════════════════════════════════════════════════════════════
     Universal Responsive Layout & Portrait Mode Auto-Hide Engine
     ═══════════════════════════════════════════════════════════════════════ */

  /* Force auto-hide sidebar and expand main content in all portrait modes and small screens */
  @media (max-width: 991.98px), (orientation: portrait) {
    :root {
      --sidebar-width: 280px;
    }

    .sidebar,
    aside.sidebar,
    #mainSidebar,
    .sidebar-wrapper {
      position: fixed !important;
      top: 0 !important;
      left: 0 !important;
      height: 100vh !important;
      height: 100dvh !important;
      width: var(--sidebar-width) !important;
      max-width: 85vw !important;
      z-index: 1060 !important;
      transform: translateX(-100%) !important;
      box-shadow: none !important;
      transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s ease !important;
    }

    .sidebar.show,
    .sidebar-wrapper.show,
    body.sidebar-mobile-open .sidebar,
    body.sidebar-mobile-open aside.sidebar,
    body.sidebar-mobile-open #mainSidebar,
    body.sidebar-mobile-open .sidebar-wrapper {
      transform: translateX(0) !important;
      box-shadow: 0 0 50px rgba(0, 0, 0, 0.75), 4px 0 25px rgba(0, 0, 0, 0.5) !important;
    }

    .sidebar-overlay,
    #sidebarOverlay {
      display: none;
      position: fixed !important;
      top: 0 !important;
      left: 0 !important;
      width: 100vw !important;
      height: 100vh !important;
      height: 100dvh !important;
      background: rgba(3, 7, 18, 0.6) !important;
      backdrop-filter: none !important;
      -webkit-backdrop-filter: none !important;
      z-index: 1050 !important;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
    }

    .sidebar-overlay.show,
    body.sidebar-mobile-open .sidebar-overlay,
    body.sidebar-mobile-open #sidebarOverlay {
      display: block !important;
      opacity: 1 !important;
      pointer-events: auto !important;
    }

    .main-with-sidebar,
    .main-wrapper,
    #mainContentBody {
      margin-left: 0 !important;
      width: 100% !important;
      max-width: 100vw !important;
      padding: 0.75rem 0.85rem !important;
      box-sizing: border-box !important;
      transition: margin-left 0.3s cubic-bezier(0.16, 1, 0.3, 1), width 0.3s cubic-bezier(0.16, 1, 0.3, 1) !important;
    }

    #app-main-container {
      padding: 0 !important;
    }

    body.sidebar-mobile-open {
      overflow: hidden !important;
    }
  }

  /* Portrait Mode, Vertical Displays (1080x1920, 1440x2560) & Ultra-Tall Monitors */
  @media (orientation: portrait) {
    .sticky-top-navbar {
      padding-top: 0.35rem !important;
      padding-bottom: 0.35rem !important;
    }

    /* Container Uniformity: Enforce full-width col-12 flow across all pages */
    .container:not(.auth-container):not(.modal-dialog .container) {
      max-width: 100% !important;
      width: 100% !important;
      padding-left: 0.75rem !important;
      padding-right: 0.75rem !important;
    }

    .table-responsive {
      border-radius: var(--radius-md);
      overflow-x: auto !important;
      -webkit-overflow-scrolling: touch;
      width: 100% !important;
    }

    .glass-card {
      border-radius: 14px !important;
      padding: 1rem !important;
    }

    /* Stat card grid spacing for vertical monitors */
    .row.g-3 > [class*="col-"] {
      margin-bottom: 0.25rem;
    }

    /* Terminal & Trading View height optimization in vertical portrait */
    .chart-container-vertical,
    #tradingview_chart_wrapper,
    .tv-chart-container {
      min-height: 480px !important;
      max-height: 60vh !important;
    }
  }

  /* Ultra-wide & High-Resolution WQHD Displays (2560x1440+) */
  @media (min-width: 2560px) {
    :root {
      --sidebar-width: 280px;
    }

    .main-with-sidebar {
      padding: 1.5rem 2rem 3rem 2rem !important;
    }

    .glass-card {
      padding: 1.5rem !important;
    }

    h1, .h1 { font-size: 1.6rem !important; }
    h2, .h2 { font-size: 1.4rem !important; }
    h3, .h3 { font-size: 1.25rem !important; }
  }

  /* Standardized Global Button Design System (Pill Standard: 38px Height, 50px Radius) */
  .btn,
  .btn-primary,
  .btn-secondary,
  .btn-outline-primary,
  .btn-outline-secondary,
  .btn-outline-success,
  .btn-outline-danger,
  .btn-outline-warning,
  .btn-outline-info,
  .theme-pill-btn {
    height: 38px !important;
    padding: 0 16px !important;
    font-size: 0.82rem !important;
    font-weight: 500 !important;
    border-radius: 50px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    line-height: 1 !important;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
  }

  /* Global Icon-Only Circle Buttons (Strict 1:1 Aspect Ratio, Zero Pill Padding) */
  .glass-icon-btn,
  .btn-icon,
  a.glass-icon-btn,
  button.glass-icon-btn,
  .btn.glass-icon-btn,
  .btn.btn-sm.glass-icon-btn,
  button.btn.glass-icon-btn,
  a.btn.glass-icon-btn {
    width: 26px !important;
    height: 26px !important;
    min-width: 26px !important;
    min-height: 26px !important;
    max-width: 26px !important;
    max-height: 26px !important;
    aspect-ratio: 1 / 1 !important;
    border-radius: 50% !important;
    padding: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-sizing: border-box !important;
  }

  .glass-icon-btn .material-icons,
  .glass-icon-btn .material-symbols-outlined,
  .glass-icon-btn i,
  .glass-icon-btn .bi,
  .btn-icon .material-icons,
  .btn-icon .material-symbols-outlined,
  .btn-icon i,
  .btn-icon .bi {
    line-height: 1 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: auto !important;
    height: auto !important;
    max-width: none !important;
    overflow: visible !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* Global Glassmorphic Input Consistency */
  .form-control,
  .form-select,
  select,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  textarea {
    background-color: rgba(255, 255, 255, 0.04) !important;
    border: 1px solid var(--border-color, rgba(0, 242, 254, 0.14)) !important;
    color: var(--text-main, #F8FAFC) !important;
    border-radius: 8px !important;
    padding: 6px 12px !important;
    font-size: 0.8125rem !important;
    min-height: 34px !important;
    transition: border-color 0.2s ease, box-shadow 0.2s ease !important;
  }

  /* Global Section-Wise Scroll Snapping & Adaptive Momentum */
  html, body {
    scroll-behavior: smooth !important;
    scroll-padding-top: calc(var(--header-height, 56px) + 20px) !important;
  }

  .ag-scroll-snap-container,
  .form-scroll-snap,
  #app-main-container {
    scroll-snap-type: y proximity;
  }

  /* Section Targets & Form Cards Snap Alignment */
  .form-section,
  .hud-section,
  .section-snap,
  .glass-card,
  .hud-panel,
  .card,
  form > div[class*="border-bottom"],
  form > div[id*="section"] {
    scroll-snap-align: start;
    scroll-margin-top: calc(var(--header-height, 56px) + 20px) !important;
  }

  /* Exclude Snapping on Nested Interactive Scrollports */
  .table-responsive,
  .modal-body,
  .dropdown-menu,
  textarea,
  pre,
  .ag-code-block,
  .custom-scrollable-rules {
    scroll-snap-align: none !important;
    scroll-snap-type: none !important;
    overscroll-behavior: contain !important;
  }
}



