/* ==========================================================================
   Components CSS - Cards, Tables, Forms, Modals & UI Components
   ========================================================================== */

/* 1. Cards & Containers
   ========================================================================== */

/* Card Layouts */
.card {
    background-color: var(--light-bg);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    margin-bottom: 1.5rem;
}

.card-header {
    padding: 1rem 1.25rem;
    background-color: var(--light-bg);
    border-bottom: 1px solid var(--light-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-body {
    padding: 1.25rem;
}

.card-footer {
    padding: 1rem 1.25rem;
    background-color: var(--light-bg);
    border-top: 1px solid var(--light-border);
}

/* Asset Containers */
.asset-container {
    border: 1px solid var(--light-border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.image-preview-container {
    position: relative;
    display: inline-block;
    margin: 5px;
}

.image-preview-container img {
    max-height: 100px;
    width: auto;
    border-radius: 4px;
}

.image-preview-container .delete-asset {
    position: absolute;
    top: 5px;
    right: 5px;
    padding: 2px 6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.image-preview-container:hover .delete-asset {
    opacity: 1;
}

.existing-assets {
    min-height: 100px;
    border: 1px dashed var(--border-color);
    padding: 10px;
    border-radius: 4px;
    background-color: var(--light-bg);
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.existing-assets:empty {
    display: flex;
    align-items: center;
    justify-content: center;
}

.existing-assets:empty::after {
    content: 'No assets uploaded yet';
    color: var(--light-text);
    font-style: italic;
}

/* Content Area */
.content-area {
    flex: 1;
    padding: 1.5rem;
    background-color: var(--light-bg);
    min-height: calc(100vh - var(--navbar-height));
}

/* Grid Layouts */
.grid-container {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

/* Dashboard Layout */
.dashboard-container {
    padding: 1.5rem;
    max-width: 1400px;
    margin: 0 auto;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.dashboard-card {
    background: var(--surface-color);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

/* Chart Layouts */
.chart-container {
    position: relative;
    background: var(--surface-color);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.chart-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-color);
}

/* Table Container */
.table-container {
    background-color: var(--light-bg);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

/* Form Layouts */
.form-container {
    max-width: 800px;
    margin: 0 auto;
    background: var(--surface-color);
    border-radius: 8px;
    padding: 2rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.form-section {
    margin-bottom: 2rem;
}

.form-section:last-child {
    margin-bottom: 0;
}

/* 2. Tables
   ========================================================================== */
.table {
    width: 100%;
    margin-bottom: 1rem;
    background-color: transparent;
    border-collapse: collapse;
    color: var(--text-color);
}

.table th,
.table td {
    padding: 0.75rem;
    vertical-align: middle;
    border-top: 1px solid var(--border-color);
}

.table thead th {
    vertical-align: bottom;
    border-bottom: 2px solid var(--border-color);
    background-color: var(--theme-bg);
    font-weight: 500;
}

.table tbody tr:hover {
    background-color: var(--theme-hover);
}

.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* 3. Forms & Inputs
   ========================================================================== */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-control {
    display: block;
    width: 100%;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--light-text);
    background-color: var(--light-bg);
    border: 1px solid var(--light-border);
    border-radius: 4px;
    transition: border-color 0.15s ease-in-out;
}

.form-control:focus {
    border-color: var(--primary-color);
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(var(--primary-text-rgb), 0.25);
}

/* Button Styles */
.btn {
    display: inline-block;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    border-radius: 4px;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.15s ease-in-out;
}

.btn-primary {
    background-color: var(--btn-primary-bg);
    border-color: var(--btn-primary-border);
    color: var(--btn-primary-color);
}

.btn-primary:hover {
    background-color: rgba(var(--primary-color), 0.8);
    border-color: rgba(var(--primary-color), 0.8);
}

.btn-secondary {
    background-color: #6c757d;
    border-color: #6c757d;
    color: #ffffff;
}

.btn-secondary:hover {
    background-color: #5a6268;
    border-color: #545b62;
}

.btn-link {
    background: transparent;
    border: none;
    color: var(--primary-color);
    text-decoration: none;
    padding: 0;
}

.btn-link:hover {
    color: rgba(var(--primary-color), 0.8);
    text-decoration: underline;
}

/* 4. Modals & Overlays
   ========================================================================== */

/* Override Bootstrap's modal backdrop */
.modal-backdrop {
    display: none !important;  /* Completely disable Bootstrap's backdrop */
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: var(--z-modal);
    display: none;
    background: rgba(0, 0, 0, 0.5);  /* Add semi-transparent background for modal backdrop */
    align-items: center;
    justify-content: center;
    pointer-events: none;  /* Disable pointer events when hidden */
}

/* Only enable pointer events when modal is shown */
.modal.show {
    display: flex !important;
    pointer-events: auto;
}

.modal-dialog {
    max-width: 500px;
    width: 90%;
    margin: auto;
    z-index: calc(var(--z-modal) + 1);
    pointer-events: auto;  /* Re-enable pointer events for the dialog */
}

.modal-content {
    position: relative;
    background-color: var(--light-bg);
    border: 1px solid var(--light-border);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    width: 100%;
}

/* Make sure form elements within modal are interactive */
.modal-content input,
.modal-content button,
.modal-content select,
.modal-content textarea {
    pointer-events: all;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--light-border);
    background-color: var(--light-bg);
    border-radius: 8px 8px 0 0;
}

.modal-body {
    position: relative;
    padding: 1rem;
    max-height: calc(90vh - 130px);
    overflow-y: auto;
    background-color: var(--light-bg);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-color);
    opacity: 0.7;
}

.modal-close:hover {
    opacity: 1;
}

/* 5. Dropdowns
   ========================================================================== */
.dropdown-menu {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: var(--shadow-sm);
    min-width: 200px;
}

.dropdown-item {
    display: block;
    width: 100%;
    padding: 0.5rem 1rem;
    color: var(--text-color);
    text-decoration: none;
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s ease-in-out;
}

.dropdown-item:hover {
    background-color: var(--hover-color);
    color: var(--text-color);
}

.dropdown-item.active {
    background-color: var(--primary-color);
    color: var(--primary-text);
}

/* Ensure dropdowns show properly */
.dropdown-menu.show {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
    z-index: var(--z-dropdown) !important;
}

/* Hide dropdowns properly when not shown */
.dropdown-menu:not(.show) {
    display: none !important;
    pointer-events: none !important;
}

/* 6. Alerts & Messages
   ========================================================================== */
.alert {
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid transparent;
    border-radius: 4px;
}

.alert-success {
    background-color: #d4edda;
    border-color: #c3e6cb;
    color: #155724;
}

.alert-danger {
    background-color: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

.alert-warning {
    background-color: #fff3cd;
    border-color: #ffeaa7;
    color: #856404;
}

.alert-info {
    background-color: #d1ecf1;
    border-color: #bee5eb;
    color: #0c5460;
}

/* 7. Dark Theme Component Adjustments
   ========================================================================== */

/* Cards */
body.dark-theme .card {
    background-color: var(--dark-bg);
    border-color: var(--dark-border);
}

body.dark-theme .card-header,
body.dark-theme .card-footer {
    background-color: var(--dark-bg);
    border-color: var(--dark-border);
}

/* Asset Containers */
body.dark-theme .asset-container {
    border-color: var(--dark-border);
}

body.dark-theme .existing-assets {
    border-color: var(--dark-border);
    background-color: var(--dark-input-bg);
}

body.dark-theme .existing-assets:empty::after {
    color: var(--dark-text);
}

/* Content Areas */
body.dark-theme .content-area {
    background-color: var(--dark-bg);
}

body.dark-theme .dashboard-card,
body.dark-theme .chart-container,
body.dark-theme .table-container,
body.dark-theme .form-container {
    background-color: var(--dark-bg);
    border-color: var(--dark-border);
}

/* Tables */
body.dark-theme .table th,
body.dark-theme .table td {
    border-color: var(--dark-border);
}

body.dark-theme .table thead th {
    background-color: var(--dark-card-bg);
    border-color: var(--dark-border);
}

body.dark-theme .table tbody tr:hover {
    background-color: var(--dark-card-bg);
}

/* Forms */
body.dark-theme .form-control {
    color: var(--dark-text);
    background-color: var(--dark-input-bg);
    border-color: var(--dark-border);
}

body.dark-theme .form-label {
    color: var(--dark-text);
}

/* Buttons */
body.dark-theme .btn-secondary {
    background-color: #495057;
    border-color: #495057;
}

body.dark-theme .btn-secondary:hover {
    background-color: #3d4449;
    border-color: #373b3e;
}

body.dark-theme .btn-link {
    color: var(--primary-text);
}

/* Modals */
body.dark-theme .modal-content {
    background-color: var(--dark-bg);
    border-color: var(--dark-border);
}

body.dark-theme .modal-header,
body.dark-theme .modal-body,
body.dark-theme .modal-footer {
    background-color: var(--dark-bg);
    border-color: var(--dark-border);
}

body.dark-theme .modal-title,
body.dark-theme .modal-close {
    color: var(--dark-text);
}

/* Dropdowns */
body.dark-theme .dropdown-menu {
    background-color: var(--dark-bg);
    border-color: var(--dark-border);
}

body.dark-theme .dropdown-item {
    color: var(--dark-text);
}

body.dark-theme .dropdown-item:hover {
    background-color: var(--dark-card-bg);
    color: var(--dark-text);
}

body.dark-theme .dropdown-item.active {
    background-color: rgba(255, 255, 255, 0.2);
    color: var(--primary-text);
}

/* Alerts */
body.dark-theme .alert-success {
    background-color: #1e3a2e;
    border-color: #2d5a3d;
    color: #a3d9a5;
}

body.dark-theme .alert-danger {
    background-color: #3a1e1e;
    border-color: #5a2d2d;
    color: #d9a3a3;
}

body.dark-theme .alert-warning {
    background-color: #3a3a1e;
    border-color: #5a5a2d;
    color: #d9d9a3;
}

body.dark-theme .alert-info {
    background-color: #1e2a3a;
    border-color: #2d3d5a;
    color: #a3b9d9;
}

/* 8. Authentication Pages
   ========================================================================== */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background-color: var(--light-bg);
}

body.dark-theme .auth-wrapper {
    background-color: #000000 !important;
}

.auth-container {
    width: 100%;
    max-width: 480px;
    background: var(--surface-color);
    border-radius: 12px;
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
    margin-top: -10vh;
    border: 1px solid var(--border-color);
}

body.dark-theme .auth-container {
    background: #333333;
    border-color: var(--dark-border);
}

.auth-logo-container {
    text-align: center;
    margin-bottom: 2rem;
    display: flex;
    justify-content: center;
}

.auth-logo {
    max-width: 180px;
    height: auto;
    margin: 0 auto;
}

/* Show/hide logos based on theme */
.light-theme-logo {
    display: block;
}

.dark-theme-logo {
    display: none;
}

body.dark-theme .light-theme-logo {
    display: none;
}

body.dark-theme .dark-theme-logo {
    display: block;
}

.auth-form {
    width: 100%;
}

.auth-input-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.auth-input-container {
    margin-bottom: 1.5rem;
    width: 100%;
}

.auth-input-container.half-width {
    width: calc(50% - 0.5rem);
}

.auth-input-label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.auth-input-field input,
.auth-input-field .form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--input-bg);
    color: var(--text-color);
    font-size: 1rem;
    transition: border-color 0.15s ease-in-out;
}

.auth-input-field input:focus,
.auth-input-field .form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.1);
}

body.dark-theme .auth-input-field input:focus,
body.dark-theme .auth-input-field .form-control:focus {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1);
}

.auth-buttons-container {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

.auth-button {
    flex: 1;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: all 0.2s ease;
    display: inline-block;
}

.auth-button.primary {
    background-color: var(--primary-color);
    color: var(--primary-text);
    border: 1px solid var(--primary-color);
}

.auth-button.secondary {
    background-color: transparent;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
}

.auth-button:hover {
    opacity: 0.9;
    text-decoration: none;
}

.auth-button.secondary:hover {
    background-color: var(--primary-color);
    color: var(--primary-text);
}

.auth-links-container {
    margin-top: 1.5rem;
    text-align: center;
}

.auth-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: opacity 0.2s ease;
}

.auth-link:hover {
    opacity: 0.8;
    text-decoration: underline;
    color: var(--primary-color);
}

.auth-message {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-message h2 {
    color: var(--text-color);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.auth-message p {
    color: var(--text-muted);
    margin: 0;
}

body.dark-theme .auth-message h2 {
    color: var(--dark-text);
}

body.dark-theme .auth-message p {
    color: var(--text-muted);
}

/* Dark theme adjustments for auth elements */
body.dark-theme .auth-input-label {
    color: var(--dark-text);
}

body.dark-theme .auth-input-field input,
body.dark-theme .auth-input-field .form-control {
    background-color: var(--dark-input-bg);
    border-color: var(--dark-border);
    color: var(--dark-text);
}

body.dark-theme .auth-input-field input::placeholder,
body.dark-theme .auth-input-field .form-control::placeholder {
    color: #999999;
}

/* Error messages styling */
.errorlist {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem 0;
    color: var(--danger-color);
    font-size: 0.875rem;
}

.errorlist li {
    margin-bottom: 0.25rem;
}

body.dark-theme .errorlist {
    color: #ff6b6b;
}

/* Mobile auth adjustments */
@media (max-width: 767px) {
    .auth-wrapper {
        padding: 1rem;
    }
    
    .auth-container {
        padding: 2rem;
        margin-top: 0;
    }
    
    .auth-input-row {
        flex-direction: column;
        gap: 0;
    }
    
    .auth-input-container.half-width {
        width: 100%;
    }
    
    .auth-buttons-container {
        flex-direction: column;
    }
}

/* 9. Responsive Component Adjustments
   ========================================================================== */

/* Mobile Adjustments */
@media (max-width: 767px) {
    .content-area {
        padding: 1rem;
    }
    
    .dashboard-container {
        padding: 1rem;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .form-container {
        padding: 1rem;
        margin: 0 1rem;
    }
    
    .modal-dialog {
        width: 95%;
        margin: 1rem;
    }
    
    .table-responsive {
        font-size: 0.875rem;
    }
    
    .card {
        margin-bottom: 1rem;
    }
    
    .card-header,
    .card-body,
    .card-footer {
        padding: 1rem;
    }
}

/* Tablet Adjustments */
@media (max-width: 991px) {
    .dashboard-grid {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
    
    .form-container {
        max-width: 600px;
    }
}
