/**
 * AIBets v11 — Unified Design System
 * Shared between admin.php + index.php (public)
 *
 * Architecture:
 *   - CSS variables (tokens) — colors/spacing/radius/shadow
 *   - 4 themes (dark/blue/green/purple) via [data-theme] attr
 *   - Component classes prefixed `aib-`
 *   - Works alongside Tailwind utilities (no conflicts)
 *
 * Inspired by TI_claudebot palette + AIBets multi-theme + 2026 fintech aesthetic.
 */

/* ─────────────────────────────────────────
   DESIGN TOKENS
   ───────────────────────────────────────── */
:root {
    /* Spacing scale (4-based) */
    --aib-sp-1: 4px;   --aib-sp-2: 8px;
    --aib-sp-3: 12px;  --aib-sp-4: 16px;
    --aib-sp-5: 20px;  --aib-sp-6: 24px;
    --aib-sp-8: 32px;  --aib-sp-10: 40px;

    /* Radius */
    --aib-r-sm: 8px;
    --aib-r-md: 12px;
    --aib-r-lg: 16px;
    --aib-r-xl: 20px;
    --aib-r-pill: 999px;

    /* Shadows */
    --aib-shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --aib-shadow-md: 0 4px 12px rgba(0,0,0,0.20);
    --aib-shadow-lg: 0 12px 40px rgba(0,0,0,0.35);
    --aib-shadow-glow: 0 0 24px rgba(99, 102, 241, 0.25);

    /* Motion */
    --aib-easing: cubic-bezier(0.4, 0, 0.2, 1);
    --aib-easing-out: cubic-bezier(0.0, 0.0, 0.2, 1);
    --aib-dur-fast: 150ms;
    --aib-dur: 250ms;
    --aib-dur-slow: 400ms;

    /* Typography */
    --aib-font-mono: 'JetBrains Mono', ui-monospace, monospace;
    --aib-font-sans: 'Inter', -apple-system, system-ui, sans-serif;

    /* Semantic colors (theme-agnostic) */
    --aib-success: #10b981;
    --aib-success-soft: rgba(16, 185, 129, 0.12);
    --aib-danger: #ef4444;
    --aib-danger-soft: rgba(239, 68, 68, 0.12);
    --aib-warn: #f59e0b;
    --aib-warn-soft: rgba(245, 158, 11, 0.12);
    --aib-info: #3b82f6;
    --aib-info-soft: rgba(59, 130, 246, 0.12);
}

/* ─────────────────────────────────────────
   THEMES
   ───────────────────────────────────────── */

/* DARK (default) — neutral slate */
:root,
:root[data-theme="dark"] {
    --aib-bg: #0a0a0f;
    --aib-bg-2: #11121a;
    --aib-surface: #15171f;
    --aib-surface-2: #1d1f29;
    --aib-surface-hover: #232532;
    --aib-border: rgba(255, 255, 255, 0.06);
    --aib-border-strong: rgba(255, 255, 255, 0.12);
    --aib-text: #e5e7eb;
    --aib-text-muted: #9ca3af;
    --aib-text-subtle: #6b7280;
    --aib-primary: #6366f1;       /* indigo */
    --aib-primary-soft: rgba(99, 102, 241, 0.12);
    --aib-accent: #8b5cf6;        /* violet */
}

/* BLUE — fintech */
:root[data-theme="blue"] {
    --aib-bg: #050a1a;
    --aib-bg-2: #0a1228;
    --aib-surface: #0f1a36;
    --aib-surface-2: #15234a;
    --aib-surface-hover: #1c2c5e;
    --aib-border: rgba(96, 165, 250, 0.10);
    --aib-border-strong: rgba(96, 165, 250, 0.20);
    --aib-text: #dbeafe;
    --aib-text-muted: #93c5fd;
    --aib-text-subtle: #60a5fa;
    --aib-primary: #3b82f6;
    --aib-primary-soft: rgba(59, 130, 246, 0.15);
    --aib-accent: #06b6d4;
}

/* EMERALD — profit */
:root[data-theme="green"] {
    --aib-bg: #050f0a;
    --aib-bg-2: #061a14;
    --aib-surface: #0a2620;
    --aib-surface-2: #0e352c;
    --aib-surface-hover: #144238;
    --aib-border: rgba(110, 231, 183, 0.10);
    --aib-border-strong: rgba(110, 231, 183, 0.20);
    --aib-text: #d1fae5;
    --aib-text-muted: #6ee7b7;
    --aib-text-subtle: #10b981;
    --aib-primary: #10b981;
    --aib-primary-soft: rgba(16, 185, 129, 0.15);
    --aib-accent: #14b8a6;
}

/* VIOLET — premium */
:root[data-theme="purple"] {
    --aib-bg: #0a061a;
    --aib-bg-2: #150a2a;
    --aib-surface: #1d1140;
    --aib-surface-2: #271a55;
    --aib-surface-hover: #34256d;
    --aib-border: rgba(167, 139, 250, 0.10);
    --aib-border-strong: rgba(167, 139, 250, 0.20);
    --aib-text: #ede9fe;
    --aib-text-muted: #c4b5fd;
    --aib-text-subtle: #a78bfa;
    --aib-primary: #8b5cf6;
    --aib-primary-soft: rgba(139, 92, 246, 0.15);
    --aib-accent: #ec4899;
}

/* ─────────────────────────────────────────
   BASE
   ───────────────────────────────────────── */
.aib-app {
    background: var(--aib-bg);
    color: var(--aib-text);
    font-family: var(--aib-font-sans);
    -webkit-font-smoothing: antialiased;
}

.aib-app * { transition-property: background-color, border-color, color, transform, opacity; transition-duration: var(--aib-dur-fast); transition-timing-function: var(--aib-easing); }

/* ─────────────────────────────────────────
   COMPONENTS
   ───────────────────────────────────────── */

/* CARD */
.aib-card {
    background: var(--aib-surface);
    border: 1px solid var(--aib-border);
    border-radius: var(--aib-r-lg);
    padding: var(--aib-sp-5);
}
.aib-card-elevated {
    background: linear-gradient(135deg, var(--aib-surface) 0%, var(--aib-surface-2) 100%);
    box-shadow: var(--aib-shadow-md);
}
.aib-card-glass {
    background: rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--aib-border);
}
.aib-card-glow {
    border: 1px solid var(--aib-primary-soft);
    box-shadow: var(--aib-shadow-glow);
}

/* HEADING */
.aib-h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.aib-h2 { font-size: 20px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; }
.aib-h3 { font-size: 16px; font-weight: 600; line-height: 1.4; }
.aib-text-xs { font-size: 12px; color: var(--aib-text-muted); }
.aib-text-num { font-family: var(--aib-font-mono); font-variant-numeric: tabular-nums; }

/* GRADIENT TEXT */
.aib-text-gradient {
    background: linear-gradient(135deg, var(--aib-primary) 0%, var(--aib-accent) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

/* BUTTON */
.aib-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--aib-sp-2);
    padding: var(--aib-sp-2) var(--aib-sp-4);
    border-radius: var(--aib-r-md);
    font-size: 14px;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--aib-dur-fast) var(--aib-easing);
    user-select: none;
    background: var(--aib-surface-2);
    color: var(--aib-text);
}
.aib-btn:hover { background: var(--aib-surface-hover); transform: translateY(-1px); }
.aib-btn:active { transform: translateY(0); }
.aib-btn-primary {
    background: var(--aib-primary);
    color: white;
}
.aib-btn-primary:hover { background: var(--aib-accent); }
.aib-btn-ghost { background: transparent; border: 1px solid var(--aib-border); }
.aib-btn-ghost:hover { background: var(--aib-surface-2); }
.aib-btn-success { background: var(--aib-success); color: white; }
.aib-btn-danger { background: var(--aib-danger); color: white; }

/* BADGE / PILL */
.aib-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--aib-sp-1);
    padding: 2px var(--aib-sp-2);
    border-radius: var(--aib-r-pill);
    font-size: 11px;
    font-weight: 500;
    background: var(--aib-surface-2);
    color: var(--aib-text-muted);
}
.aib-pill-success { background: var(--aib-success-soft); color: var(--aib-success); }
.aib-pill-danger { background: var(--aib-danger-soft); color: var(--aib-danger); }
.aib-pill-warn { background: var(--aib-warn-soft); color: var(--aib-warn); }
.aib-pill-info { background: var(--aib-info-soft); color: var(--aib-info); }

/* DOT INDICATOR */
.aib-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.aib-dot-success { background: var(--aib-success); box-shadow: 0 0 8px var(--aib-success); }
.aib-dot-danger { background: var(--aib-danger); box-shadow: 0 0 8px var(--aib-danger); }
.aib-dot-warn { background: var(--aib-warn); box-shadow: 0 0 8px var(--aib-warn); }
.aib-dot-pulse { animation: aib-pulse 2s ease infinite; }
@keyframes aib-pulse {
    0%,100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.15); }
}

/* STAT CARD */
.aib-stat {
    background: var(--aib-surface);
    border: 1px solid var(--aib-border);
    border-radius: var(--aib-r-lg);
    padding: var(--aib-sp-4);
    position: relative;
    overflow: hidden;
}
.aib-stat::after {
    content: '';
    position: absolute;
    top: 0; right: 0;
    width: 80px; height: 80px;
    background: radial-gradient(circle, var(--aib-primary-soft) 0%, transparent 70%);
    pointer-events: none;
}
.aib-stat-label { font-size: 11px; color: var(--aib-text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.aib-stat-value { font-size: 28px; font-weight: 700; font-family: var(--aib-font-mono); margin-top: var(--aib-sp-2); letter-spacing: -0.02em; }
.aib-stat-delta { font-size: 12px; font-weight: 500; margin-top: var(--aib-sp-1); }
.aib-stat-delta.up { color: var(--aib-success); }
.aib-stat-delta.down { color: var(--aib-danger); }

/* INPUT */
.aib-input, .aib-select, .aib-textarea {
    background: var(--aib-bg-2);
    border: 1px solid var(--aib-border);
    border-radius: var(--aib-r-md);
    padding: var(--aib-sp-2) var(--aib-sp-3);
    color: var(--aib-text);
    font-size: 14px;
    font-family: var(--aib-font-sans);
    width: 100%;
    transition: border-color var(--aib-dur-fast) var(--aib-easing);
}
.aib-input:focus, .aib-select:focus, .aib-textarea:focus {
    outline: none;
    border-color: var(--aib-primary);
    box-shadow: 0 0 0 3px var(--aib-primary-soft);
}
.aib-textarea { font-family: var(--aib-font-mono); resize: vertical; }

/* TABLE */
.aib-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.aib-table th { text-align: left; padding: var(--aib-sp-3); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--aib-text-muted); border-bottom: 1px solid var(--aib-border); }
.aib-table td { padding: var(--aib-sp-3); border-bottom: 1px solid var(--aib-border); }
.aib-table tbody tr:hover { background: var(--aib-surface-2); }

/* PROGRESS BAR */
.aib-progress {
    height: 6px;
    background: var(--aib-bg-2);
    border-radius: var(--aib-r-pill);
    overflow: hidden;
}
.aib-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--aib-primary) 0%, var(--aib-accent) 100%);
    border-radius: var(--aib-r-pill);
    transition: width var(--aib-dur) var(--aib-easing);
}

/* TOGGLE SWITCH */
.aib-toggle { position: relative; display: inline-block; width: 38px; height: 22px; }
.aib-toggle input { opacity: 0; width: 0; height: 0; }
.aib-toggle-slider { position: absolute; cursor: pointer; inset: 0; background: var(--aib-surface-2); border-radius: var(--aib-r-pill); transition: var(--aib-dur-fast); }
.aib-toggle-slider::before { content: ''; position: absolute; height: 16px; width: 16px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: var(--aib-dur-fast); }
.aib-toggle input:checked + .aib-toggle-slider { background: var(--aib-primary); }
.aib-toggle input:checked + .aib-toggle-slider::before { transform: translateX(16px); }

/* MODAL */
.aib-modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.65); backdrop-filter: blur(4px); z-index: 1000; display: flex; align-items: center; justify-content: center; }
.aib-modal { background: var(--aib-surface); border: 1px solid var(--aib-border); border-radius: var(--aib-r-xl); padding: var(--aib-sp-6); max-width: 560px; width: 90%; max-height: 90vh; overflow-y: auto; box-shadow: var(--aib-shadow-lg); }

/* SIDEBAR ITEM */
.aib-nav-item {
    display: flex;
    align-items: center;
    gap: var(--aib-sp-3);
    padding: var(--aib-sp-3) var(--aib-sp-4);
    border-radius: var(--aib-r-md);
    color: var(--aib-text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--aib-dur-fast) var(--aib-easing);
}
.aib-nav-item:hover { background: var(--aib-surface-2); color: var(--aib-text); }
.aib-nav-item.active { background: var(--aib-primary-soft); color: var(--aib-primary); }
.aib-nav-item.active::before { content: ''; position: absolute; left: 0; width: 3px; height: 60%; background: var(--aib-primary); border-radius: 0 4px 4px 0; }

/* HEALTH INDICATOR (traffic light card) */
.aib-health {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: var(--aib-sp-3);
    background: var(--aib-surface);
    border: 1px solid var(--aib-border);
    border-radius: var(--aib-r-md);
    min-width: 120px;
}
.aib-health.ok { border-color: var(--aib-success-soft); }
.aib-health.warn { border-color: var(--aib-warn-soft); }
.aib-health.err { border-color: var(--aib-danger-soft); }
.aib-health-label { font-size: 11px; color: var(--aib-text-muted); display: flex; justify-content: space-between; align-items: center; }
.aib-health-value { font-size: 13px; font-weight: 500; color: var(--aib-text); }

/* SCROLLBAR */
.aib-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.aib-scroll::-webkit-scrollbar-track { background: transparent; }
.aib-scroll::-webkit-scrollbar-thumb { background: var(--aib-border-strong); border-radius: 3px; }
.aib-scroll::-webkit-scrollbar-thumb:hover { background: var(--aib-text-subtle); }

/* ANIMATIONS */
@keyframes aib-fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes aib-slide-in { from { opacity: 0; transform: translateX(-12px); } to { opacity: 1; transform: translateX(0); } }
.aib-fade-in { animation: aib-fade-in var(--aib-dur) var(--aib-easing-out); }
.aib-slide-in { animation: aib-slide-in var(--aib-dur) var(--aib-easing-out); }

/* RESPONSIVE */
@media (max-width: 768px) {
    .aib-h1 { font-size: 22px; }
    .aib-h2 { font-size: 18px; }
    .aib-stat-value { font-size: 22px; }
    .aib-card { padding: var(--aib-sp-4); }
}

/* ─────────────────────────────────────────
   UTILITIES
   ───────────────────────────────────────── */
.aib-divider { height: 1px; background: var(--aib-border); margin: var(--aib-sp-4) 0; }
.aib-grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--aib-sp-4); }
.aib-flex-between { display: flex; align-items: center; justify-content: space-between; }
.aib-flex-gap { display: flex; align-items: center; gap: var(--aib-sp-3); }
.aib-mono { font-family: var(--aib-font-mono); font-variant-numeric: tabular-nums; }

/* DASHBOARD HERO */
.aib-hero {
    background: linear-gradient(135deg, var(--aib-bg-2) 0%, var(--aib-surface) 100%);
    border-radius: var(--aib-r-xl);
    padding: var(--aib-sp-6);
    border: 1px solid var(--aib-border);
    position: relative;
    overflow: hidden;
}
.aib-hero::before {
    content: '';
    position: absolute;
    top: -50%; right: -30%;
    width: 60%; aspect-ratio: 1;
    background: radial-gradient(circle, var(--aib-primary-soft) 0%, transparent 70%);
    pointer-events: none;
}
