/**
 * Key Balancer - Modern SaaS Design System
 * Theme: Light Mode (Linear/Vercel Style)
 * Features: Rainbow gradients, glassmorphism, fluid typography
 */

:root {
    /* Brand & Accents */
    --color-primary: #6366f1; /* Indigo 500 */
    --color-primary-dark: #4f46e5;
    --color-accent: #8b5cf6; /* Violet 500 */
    
    /* Rainbow Gradients */
    --gradient-rainbow: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 50%, #ec4899 100%);
    --gradient-rainbow-text: linear-gradient(135deg, #2563eb 0%, #7c3aed 50%, #db2777 100%);
    --gradient-subtle: linear-gradient(180deg, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 100%);
    
    /* Semantic */
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-error: #ef4444;
    
    /* Backgrounds */
    --bg-base: #ffffff;
    --bg-sidebar: #fbfbfb; /* Very subtle gray */
    --bg-surface: #ffffff;
    --bg-hover: #f3f4f6;
    --bg-active: #eff6ff;
    
    /* Borders */
    --border-subtle: rgba(0, 0, 0, 0.06);
    --border-medium: rgba(0, 0, 0, 0.12);
    --border-focus: rgba(99, 102, 241, 0.4);
    
    /* Text */
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-tertiary: #9ca3af;
    --text-disabled: #d1d5db;
    
    /* Shadows (The key to "Texture") */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.02), 0 1px 0 rgba(0,0,0,0.02);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0,0,0,0.02);
    --shadow-float: 0 12px 24px -6px rgba(0, 0, 0, 0.08);
    
    /* Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    
    /* Animation */
    --ease-out: cubic-bezier(0.215, 0.61, 0.355, 1);
}

/* ==================== Reset & Base ==================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-base);
}

/* ==================== Typography & Effects ==================== */
h1, h2, h3, h4, h5 {
    color: var(--text-primary);
    font-weight: 600;
    letter-spacing: -0.025em; /* Tight tracking for modern feel */
}

.font-mono {
    font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
    letter-spacing: -0.01em;
}

.text-rainbow {
    background: var(--gradient-rainbow-text);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ==================== Components ==================== */

/* Buttons */
button {
    font-weight: 500;
    transition: all 0.2s var(--ease-out);
}

button:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--color-primary);
    color: white;
    box-shadow: 0 1px 2px rgba(99, 102, 241, 0.3), inset 0 1px 0 rgba(255,255,255,0.2);
}
.btn-primary:hover {
    background: var(--color-primary-dark);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

/* Cards */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s var(--ease-out), border-color 0.2s;
}

.card:hover {
    border-color: var(--border-medium);
    box-shadow: var(--shadow-md);
}

/* Sidebar */
aside {
    background-color: var(--bg-sidebar) !important;
    border-right: 1px solid var(--border-subtle) !important;
}

aside a {
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    transition: all 0.15s ease;
}

aside a:hover {
    background-color: rgba(0,0,0,0.04);
    color: var(--text-primary);
}

aside a.active {
    background-color: white;
    color: var(--color-primary);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

aside a.active i {
    color: var(--color-primary);
}

/* Table */
table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
}

th {
    background-color: var(--bg-sidebar);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border-subtle);
}

td {
    padding: 12px 24px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 13px;
    background: white;
    transition: background 0.1s;
}

tr:hover td {
    background-color: var(--bg-hover);
}

tr:last-child td {
    border-bottom: none;
}

/* Tokens Table Enhancements */
.tokens-table {
    min-width: 1100px;
}

.tokens-table th,
.tokens-table td {
    white-space: nowrap;
}

.tokens-table .tokens-limits-cell {
    white-space: normal;
}

.tokens-table .token-cell {
    min-width: 260px;
}

.token-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius-lg);
    background: linear-gradient(120deg, rgba(99, 102, 241, 0.08), rgba(79, 70, 229, 0.16));
    border: 1px solid rgba(99, 102, 241, 0.18);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
    font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
    font-size: 12px;
    letter-spacing: 0.04em;
    color: var(--text-primary);
}

.token-chip::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 999px;
    background: var(--color-primary);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.45);
}

/* Status Dots */
.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(255,255,255,0.5);
}

/* Inputs */
input, select, textarea {
    background: white !important;
    border: 1px solid var(--border-medium) !important;
    color: var(--text-primary) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-xs) !important;
    transition: all 0.2s;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--color-primary) !important;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1) !important;
    outline: none;
}

/* Badges */
.badge {
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid transparent;
}
.badge-success { background: #ecfdf5; color: #059669; border-color: #d1fae5; }
.badge-warning { background: #fffbeb; color: #d97706; border-color: #fde68a; }
.badge-error { background: #fef2f2; color: #dc2626; border-color: #fee2e2; }
.badge-neutral { background: #f3f4f6; color: #4b5563; border-color: #e5e7eb; }
.badge-purple { background: #f5f3ff; color: #7c3aed; border-color: #ddd6fe; }

/* Animations */
@keyframes slideUpFade {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.animate-enter {
    animation: slideUpFade 0.4s var(--ease-out) forwards;
}

@keyframes numberScroll {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}
.stat-value {
    animation: numberScroll 0.5s ease-out;
}

/* Charts */
.chart-container {
    background: white;
    border-radius: var(--radius-lg);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }
::-webkit-scrollbar-track { background: transparent; }

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.toast {
    min-width: 280px;
    max-width: 420px;
    padding: 14px 18px;
    --toast-tint: rgba(59, 130, 246, 0.22);
    --toast-border: rgba(255, 255, 255, 0.18);
    --toast-shadow: 0 18px 60px -18px rgba(0, 0, 0, 0.55), 0 8px 22px rgba(0, 0, 0, 0.22);
    background:
        linear-gradient(135deg, rgba(11, 18, 32, 0.72) 0%, rgba(11, 18, 32, 0.62) 55%, rgba(11, 18, 32, 0.72) 100%),
        radial-gradient(900px circle at 15% 0%, var(--toast-tint) 0%, rgba(0,0,0,0) 55%);
    backdrop-filter: blur(16px) saturate(140%);
    -webkit-backdrop-filter: blur(16px) saturate(140%);
    border-radius: var(--radius-lg);
    box-shadow: var(--toast-shadow);
    border: 1px solid var(--toast-border);
    display: flex;
    align-items: center;
    gap: 12px;
    pointer-events: auto;
    animation: toastIn 0.38s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.toast::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(1000px circle at 10% -20%, rgba(255,255,255,0.10) 0%, rgba(255,255,255,0.03) 28%, rgba(255,255,255,0) 60%);
    pointer-events: none;
    opacity: 0.55;
}

.toast {
    position: relative;
}

.toast.toast-success { --toast-tint: rgba(34, 197, 94, 0.26); }
.toast.toast-error { --toast-tint: rgba(239, 68, 68, 0.26); }
.toast.toast-warning { --toast-tint: rgba(245, 158, 11, 0.28); }
.toast.toast-info { --toast-tint: rgba(59, 130, 246, 0.24); }

@keyframes toastIn {
    0% { opacity: 0; transform: translateX(28px) translateY(-6px) scale(0.985); }
    60% { opacity: 1; transform: translateX(0) translateY(0) scale(1.0); }
    100% { opacity: 1; transform: translateX(0) translateY(0) scale(1.0); }
}

@keyframes toastOut {
    0% { opacity: 1; transform: translateX(0) translateY(0) scale(1); }
    100% { opacity: 0; transform: translateX(22px) translateY(-4px) scale(0.99); }
}

.toast.toast-leave {
    animation: toastOut 0.32s cubic-bezier(0.2, 0, 0, 1) both;
}

 .modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.45);
    backdrop-filter: blur(6px);
 }

 .modal-container {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 50;
 }

 .modal-content {
    width: 100%;
    max-width: 720px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-float);
    overflow: hidden;
 }

 @keyframes scaleIn {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
 }

 .animate-scale-in {
    animation: scaleIn 0.16s var(--ease-out) both;
 }

/* Utility Overrides for Tailwind */
.bg-dark-900, .bg-dark-950 { background-color: transparent !important; }
.text-white { color: #ffffff !important; }
.text-gray-400 { color: var(--text-tertiary) !important; }
.border-gray-800 { border-color: var(--border-subtle) !important; }
