/**
 * RenderCAD Design System
 * Unified design tokens for authenticated pages (render studio)
 *
 * Philosophy:
 * - Clean, dark industrial aesthetic
 * - NO glass morphism (that's for public pages)
 * - Cyan accent for interactivity
 * - Consistent spacing/typography scales
 */

:root {
    /* ========================================
       COLORS
       ======================================== */

    /* Backgrounds - Premium Dark Mode */
    --bg-primary: #0a0a0f;
    --bg-solid: #0a0a0f;
    --bg-surface: rgba(255, 255, 255, 0.03);
    --bg-surface-hover: rgba(255, 255, 255, 0.05);
    --bg-overlay: rgba(0, 0, 0, 0.95);
    --bg-card: #12121a;

    /* Text */
    --text-primary: rgba(255, 255, 255, 0.95);
    --text-secondary: rgba(255, 255, 255, 0.8);
    --text-tertiary: rgba(255, 255, 255, 0.65);
    --text-muted: rgba(255, 255, 255, 0.7);

    /* Borders */
    --border-light: rgba(255, 255, 255, 0.1);
    --border-medium: rgba(255, 255, 255, 0.3);
    --border-heavy: rgba(255, 255, 255, 0.5);

    /* Accents */
    --accent-cyan: #00d4ff;
    --accent-cyan-hover: #00ffff;
    --accent-cyan-dim: rgba(0, 212, 255, 0.1);

    /* Status Colors */
    --success: #22c55e;
    --success-dark: #16a34a;
    --success-dim: rgba(16, 185, 129, 0.15);
    --warning: #f59e0b;
    --warning-dim: rgba(245, 158, 11, 0.15);
    --error: #ef4444;
    --error-dim: rgba(239, 68, 68, 0.15);
    --info: #3b82f6;
    --info-dim: rgba(59, 130, 246, 0.15);

    /* ========================================
       SPACING SCALE
       ======================================== */
    --space-xs: 0.25rem;   /* 4px */
    --space-sm: 0.5rem;    /* 8px */
    --space-md: 0.75rem;   /* 12px */
    --space-lg: 1rem;      /* 16px */
    --space-xl: 1.5rem;    /* 24px */
    --space-2xl: 2rem;     /* 32px */
    --space-3xl: 3rem;     /* 48px */
    --space-4xl: 4rem;     /* 64px */

    /* ========================================
       TYPOGRAPHY SCALE
       ======================================== */
    --text-xs: clamp(0.75rem, 1.5vw, 0.875rem);    /* 12-14px */
    --text-sm: clamp(0.875rem, 2vw, 1rem);         /* 14-16px */
    --text-base: clamp(1rem, 2.5vw, 1.125rem);     /* 16-18px */
    --text-lg: clamp(1.125rem, 3vw, 1.25rem);      /* 18-20px */
    --text-xl: clamp(1.25rem, 3.5vw, 1.5rem);      /* 20-24px */
    --text-2xl: clamp(1.5rem, 4vw, 2rem);          /* 24-32px */
    --text-3xl: clamp(2rem, 5vw, 2.5rem);          /* 32-40px */

    /* Font Weights */
    --font-light: 300;
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    /* Line Heights */
    --leading-tight: 1.2;
    --leading-normal: 1.5;
    --leading-relaxed: 1.6;

    /* ========================================
       BORDER RADIUS
       ======================================== */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* ========================================
       SHADOWS
       ======================================== */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 8px 16px rgba(0, 0, 0, 0.5);

    /* ========================================
       TRANSITIONS
       ======================================== */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.2s ease;
    --transition-slow: 0.3s ease;
    --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* ========================================
       BUTTON SIZING
       ======================================== */
    --btn-padding-sm: var(--space-sm) var(--space-lg);
    --btn-padding-md: var(--space-md) var(--space-xl);
    --btn-padding-lg: var(--space-lg) var(--space-2xl);

    /* ========================================
       Z-INDEX SCALE
       ======================================== */
    --z-base: 1;
    --z-dropdown: 10;
    --z-sticky: 100;
    --z-fixed: 1000;
    --z-modal-backdrop: 9998;
    --z-modal: 9999;
    --z-toast: 10000;
}

/* ========================================
   BASE STYLES
   ======================================== */

/* Body & Global Styles - Premium Dark with Texture */
body {
    background: var(--bg-solid);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    min-height: 100vh;
    overflow-y: auto;
    line-height: var(--leading-normal);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    margin: 0;
    padding: 0;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Hide scrollbars globally but keep scrolling functionality */
body, #main-content {
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

body::-webkit-scrollbar,
#main-content::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

/* Prevent dragging on interactive elements globally */
a, button {
    cursor: pointer;
    -webkit-user-drag: none;
    user-drag: none;
    /* Removed user-select: none - was blocking modal button clicks */
}

/* Site Container - MERGED (removed duplicate rules) */
#site-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    flex: 1;
    /* REMOVED position: relative + z-index - was creating stacking context that trapped modals */
    /* REMOVED overflow-y: auto - was breaking Bootstrap modals */
    /* Modals inside this container need body-level overflow, not container overflow */
}

/* Main Content - MERGED (removed duplicate rules) */
#main-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-2xl) 0;
    position: relative;
    z-index: 2;
}

/* Subtle Noise Texture Overlay for Premium Feel */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.03;
    z-index: 0;
    pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='4' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-2xl);
}

/* Layout Components */
.container {
    max-width: 1200px;
}

/* Navbar - Clean Dark Styling */
.navbar {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-light);
    padding: var(--space-lg) 0;
    position: relative;
    z-index: 10;
}

.navbar-dark {
    background: var(--bg-surface);
}

.navbar-brand {
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.navbar-brand:hover {
    color: var(--accent-cyan);
}

/* Navbar button container - consistent spacing */
.navbar-nav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

/* Navbar alignment fix - work with Bootstrap's flexbox */
@media (min-width: 992px) {
    /* On desktop, make collapse flex and push content right */
    .navbar-expand-lg .navbar-collapse.justify-content-end {
        display: flex !important;
        justify-content: flex-end !important;
    }

    /* Navbar-nav should NOT have margin that centers it */
    .navbar-expand-lg .navbar-collapse.justify-content-end .navbar-nav {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
}

/* Nav button overrides for studio buttons */
.navbar-nav .studio-btn-nav {
    border-radius: 10px;
}

.nav-link {
    color: var(--text-secondary);
    transition: color var(--transition-normal);
    padding: var(--space-sm) var(--space-lg);
}

.nav-link:hover {
    color: var(--text-primary);
}

.nav-link.active {
    color: var(--accent-cyan);
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

/* Typography */
h1 { font-size: var(--text-3xl); line-height: var(--leading-tight); font-weight: var(--font-bold); }
h2 { font-size: var(--text-2xl); line-height: var(--leading-tight); font-weight: var(--font-semibold); }
h3 { font-size: var(--text-xl); line-height: var(--leading-normal); font-weight: var(--font-semibold); }
h4 { font-size: var(--text-lg); line-height: var(--leading-normal); font-weight: var(--font-medium); }
h5 { font-size: var(--text-base); line-height: var(--leading-normal); font-weight: var(--font-medium); }

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-muted { color: var(--text-muted); }

/* Override Bootstrap's low-contrast .text-muted */
/* Bootstrap uses !important, so we override the variable AND use !important */
:root {
    --bs-secondary-color: rgba(255, 255, 255, 0.75);
}

body .text-muted,
small.text-muted {
    color: rgba(255, 255, 255, 0.75) !important;
}

/* Spacing */
.p-xs { padding: var(--space-xs); }
.p-sm { padding: var(--space-sm); }
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }
.p-xl { padding: var(--space-xl); }
.p-2xl { padding: var(--space-2xl); }

.m-xs { margin: var(--space-xs); }
.m-sm { margin: var(--space-sm); }
.m-md { margin: var(--space-md); }
.m-lg { margin: var(--space-lg); }
.m-xl { margin: var(--space-xl); }
.m-2xl { margin: var(--space-2xl); }

.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }

/* ========================================
   BOOTSTRAP DARK OVERRIDES
   Premium dark mode for all Bootstrap components
   ======================================== */

/* Cards - Premium Dark Styling */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
}

.card-header {
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
}

.card-body {
    background: transparent;
    color: var(--text-secondary);
}

.card-footer {
    background: rgba(255, 255, 255, 0.02);
    border-top: 1px solid var(--border-light);
}

/* Token/List Items - Clean separation with subtle dividers */
.token-item {
    padding: var(--space-lg) 0;
    border-bottom: 1px solid var(--border-light);
    transition: all var(--transition-normal);
}

.token-item:last-child {
    border-bottom: none;
}

.token-item:first-child {
    padding-top: 0;
}

.token-item:hover {
    background: rgba(255, 255, 255, 0.02);
    margin: 0 calc(-1 * var(--space-md));
    padding-left: var(--space-md);
    padding-right: var(--space-md);
    border-radius: var(--radius-sm);
}

/* Usage Bar & Statistics */
.usage-bar-container {
    margin-bottom: var(--space-xl);
}

.usage-bar {
    height: 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-full);
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-light);
}

.usage-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-cyan), var(--accent-cyan-hover));
    border-radius: var(--radius-full);
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.4);
}

.usage-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0) 100%);
}

/* Over-limit state */
.usage-fill[style*="100%"] {
    background: linear-gradient(90deg, #ef4444, #dc2626);
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.5);
}

.usage-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-lg);
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border-light);
}

.usage-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: var(--space-md);
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    transition: all var(--transition-normal);
}

.usage-stat:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--border-medium);
    transform: translateY(-2px);
}

.usage-stat-value {
    font-size: var(--text-2xl);
    font-weight: var(--font-bold);
    color: var(--accent-cyan);
    line-height: 1.2;
    margin-bottom: var(--space-xs);
}

.usage-stat-label {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: var(--font-medium);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .usage-stats {
        grid-template-columns: 1fr;
        gap: var(--space-md);
    }
}

/* Form Controls - Refined Dark Inputs */
/* Higher specificity to override Bootstrap defaults */
body .form-control,
body .form-select,
.dark-theme .form-control,
.dark-theme .form-select {
    background: var(--bg-card);
    border: 1px solid var(--border-medium);
    color: var(--text-primary);
}

body .form-control:focus,
body .form-select:focus,
.dark-theme .form-control:focus,
.dark-theme .form-select:focus {
    background: var(--bg-surface-hover);
    border-color: var(--accent-cyan);
    color: var(--text-primary);
    box-shadow: 0 0 0 0.2rem rgba(0, 212, 255, 0.15);
}

body .form-control::placeholder,
.dark-theme .form-control::placeholder {
    color: var(--text-muted);
}

body .form-label,
.dark-theme .form-label {
    color: var(--text-primary);
    font-weight: var(--font-medium);
}

/* Select dropdown options - Fix white text on white background */
body .form-select option,
body select option,
.dark-theme .form-select option,
.dark-theme select option {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* Textareas */
body textarea.form-control,
.dark-theme textarea.form-control {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* Tables - Clean Dark Styling */
.table {
    color: var(--text-secondary);
}

.table thead {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.table tbody tr {
    border-bottom: 1px solid var(--border-light);
}

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

/* Modals - Elegant Dark Overlays */
.modal-content {
    background: var(--bg-overlay);
    border: 1px solid var(--border-medium);
    color: var(--text-primary);
}

.modal-header {
    border-bottom: 1px solid var(--border-light);
}

.modal-footer {
    border-top: 1px solid var(--border-light);
}

.modal-title {
    color: var(--text-primary);
}

/* Alerts - Status Colors with Dark Background */
.alert {
    border: 1px solid;
}

.alert-success {
    background: rgba(34, 197, 94, 0.1);
    border-color: var(--success);
    color: var(--text-primary);
}

.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    border-color: var(--warning);
    color: var(--text-primary);
}

.alert-danger {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--error);
    color: var(--text-primary);
}

.alert-info {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--info);
    color: var(--text-primary);
}

/* Badges - Refined Typography */
.badge {
    font-weight: var(--font-semibold);
}

/* List Groups - Dark Styling */
.list-group-item {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
}

.list-group-item:hover {
    background: var(--bg-surface-hover);
}

/* Dropdowns - Elegant Dark Menus */
.dropdown-menu {
    background: var(--bg-overlay);
    border: 1px solid var(--border-medium);
}

.dropdown-item {
    color: var(--text-secondary);
}

.dropdown-item:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

/* Nav Tabs - Clean Tab Styling */
.nav-tabs {
    border-bottom: 1px solid var(--border-light);
}

.nav-tabs .nav-link {
    color: var(--text-secondary);
    border: none;
}

.nav-tabs .nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-surface);
}

.nav-tabs .nav-link.active {
    color: var(--accent-cyan);
    background: transparent;
    border-bottom: 2px solid var(--accent-cyan);
}
