/* ==========================================================================
   Algomi Theme - Centralized Styles
   ========================================================================== */

/* CSS Custom Properties - Theme Colors */
:root {
    /* Primary Colors */
    --color-primary: #3b82f6;
    --color-primary-light: #60a5fa;
    --color-primary-dark: #2563eb;
    
    /* Secondary Colors */
    --color-secondary: #8b5cf6;
    --color-accent: #22d3ee;
    
    /* Status Colors */
    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --color-error: #ef4444;
    --color-info: #3b82f6;
    
    /* Neutral Colors - Light Theme */
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #f8fafc;
    --color-bg-tertiary: #f1f5f9;
    --color-border: #e2e8f0;
    --color-border-light: #f1f5f9;
    
    /* Text Colors */
    --color-text-primary: #1e293b;
    --color-text-secondary: #64748b;
    --color-text-muted: #94a3b8;
    
    /* Gradient */
    --gradient-primary: linear-gradient(135deg, #22d3ee 0%, #3b82f6 50%, #8b5cf6 100%);
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    
    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;
    
    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
}

/* ==========================================================================
   Base Styles
   ========================================================================== */

body {
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ==========================================================================
   Gradient Classes
   ========================================================================== */

.gradient-text {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.gradient-bg {
    background: var(--gradient-primary);
}

/* ==========================================================================
   Card Styles
   ========================================================================== */

.card {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    transition: all 0.3s ease;
}

.card:hover {
    box-shadow: var(--shadow-lg);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

/* ==========================================================================
   Form Styles
   ========================================================================== */

.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: var(--space-2);
}

.form-input,
.form-select {
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg-primary);
    color: var(--color-text-primary);
    transition: all 0.2s;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ==========================================================================
   Button Styles
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
}

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-border);
}

.btn-success {
    background: var(--color-success);
    color: white;
}

.btn-success:hover {
    background: #16a34a;
}

.btn-danger {
    background: var(--color-error);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

/* ==========================================================================
   Global Loading Overlay
   ========================================================================== */

.page-loader {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(2px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.page-loader.active {
    opacity: 1;
    visibility: visible;
}

.page-loader .spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(59, 130, 246, 0.2);
    border-top-color: #22d3ee;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.page-loader p {
    margin-top: 1rem;
    color: var(--color-text-secondary);
    font-size: 0.875rem;
}

/* Inline Loading Spinner */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.loading-spinner .spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(59, 130, 246, 0.2);
    border-top-color: #22d3ee;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-spinner p {
    margin-top: 1rem;
    color: var(--color-text-muted);
}

/* Small Spinner for buttons */
.spinner-sm {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   Sidebar Expand Button - Centered on Screen
   ========================================================================== */

.expand-btn {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    background: var(--gradient-primary);
    border: none;
    color: white;
    width: 24px;
    height: 48px;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    box-shadow: 2px 0 10px rgba(59, 130, 246, 0.3);
    transition: width 0.2s;
}

.expand-btn:hover {
    width: 28px;
}

.expand-btn i {
    font-size: 0.75rem;
}

/* ==========================================================================
   Page Layout
   ========================================================================== */

.page-layout {
    display: flex;
    min-height: calc(100vh - 72px);
    position: relative;
}

/* Sidebar Styles */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: linear-gradient(180deg, var(--color-bg-secondary) 0%, var(--color-bg-tertiary) 100%);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.sidebar.collapsed {
    width: 0;
    min-width: 0;
    overflow: hidden;
}

.sidebar-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(59, 130, 246, 0.05);
}

.sidebar-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--color-text-primary);
    font-size: 0.9375rem;
}

.sidebar-title i {
    color: var(--color-primary);
}

.sidebar-toggle {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
    color: var(--color-primary);
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    background: rgba(59, 130, 246, 0.2);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
}

/* Main Panel */
.main-panel {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-6);
    position: relative;
    background: var(--color-bg-secondary);
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
}

.sidebar-overlay.active {
    display: block;
}

/* ==========================================================================
   Content Panel
   ========================================================================== */

.content-panel {
    background: var(--color-bg-primary);
    border-radius: var(--radius-xl);
    border: 1px solid var(--color-border);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.content-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
}

/* ==========================================================================
   Page Header
   ========================================================================== */

.page-header {
    margin-bottom: var(--space-8);
}

.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text-primary);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.page-subtitle {
    color: var(--color-text-secondary);
    font-size: 1rem;
}

/* ==========================================================================
   Info Box
   ========================================================================== */

.info-box {
    background: rgba(59, 130, 246, 0.05);
    border: 1px solid rgba(59, 130, 246, 0.2);
    border-radius: var(--radius-lg);
    padding: var(--space-4) var(--space-6);
    margin-bottom: var(--space-6);
    display: flex;
    align-items: flex-start;
    gap: var(--space-4);
}

.info-box i {
    color: var(--color-primary);
    font-size: 1.25rem;
    margin-top: 0.125rem;
}

.info-box p {
    color: var(--color-text-secondary);
    font-size: 0.9375rem;
    line-height: 1.6;
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */

.toast {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-lg);
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
    z-index: 9999;
    animation: slideIn 0.3s ease;
}

.toast-success { background: var(--color-success); }
.toast-error { background: var(--color-error); }
.toast-info { background: var(--color-info); }
.toast-warning { background: var(--color-warning); }

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

/* Current page indicator in navigation */
.current-page {    
    color: #3b82f6 !important;
    pointer-events: none;
    cursor: default;
}

@media (max-width: 768px) {
    /* Fixed viewport layout - prevent body scroll ONLY on pages with page-layout (sidebar pages) */
    /* Note: pages without .page-layout will scroll normally */
    
    body:has(.page-layout) {
        overflow: hidden;
        height: 100%;
    }

    .page-layout {
        height: calc(100vh - 72px);
        overflow: hidden;
    }

    .sidebar {
        position: fixed;
        top: 72px;
        left: 0;
        height: calc(100vh - 72px);
        z-index: 999;
        transform: translateX(0);
    }

    .sidebar.collapsed {
        transform: translateX(-100%);
        width: 280px;
        min-width: 280px;
    }

    .main-panel {
        padding: var(--space-4);
        height: calc(100vh - 72px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Keep expand button fixed at center of viewport */
    .expand-btn {
        display: flex;
        position: fixed;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        z-index: 1001;
    }

    /* Hide expand button when sidebar is open - various HTML structures */
    .sidebar:not(.collapsed) ~ .expand-btn,
    .sidebar:not(.collapsed) + .sidebar-overlay + .expand-btn,
    .sidebar:not(.collapsed) ~ .main-panel .expand-btn {
        display: none !important;
    }

    /* Sidebar overlay */
    .sidebar-overlay {
        top: 72px;
    }
}
