/* Government Document Management System Styles */
/* Professional, formal styling suitable for Malaysian government agencies */

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: #333;
    background-color: #f8f9fa;
}

/* Government Color Scheme */
:root {
    --primary-color: #1e3a8a; /* Dark blue for government */
    --secondary-color: #3b82f6; /* Medium blue */
    --accent-color: #dc2626; /* Red for important items */
    --success-color: #16a34a; /* Green for success states */
    --warning-color: #ca8a04; /* Yellow for warnings */
    --light-bg: #f8fafc;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Header Styles */
.government-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 1rem 0;
    box-shadow: var(--shadow-lg);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.gov-logo {
    width: 60px;
    height: 60px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 8px;
}

.header-text h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.ministry-name {
    font-size: 0.875rem;
    opacity: 0.9;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.875rem;
}

.user-name, .user-department {
    padding: 0.5rem 1rem;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
}

.logout-btn {
    background-color: rgba(255, 255, 255, 0.2);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.logout-btn:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

/* Navigation Styles */
.main-navigation {
    background-color: white;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: 0;
}

.nav-item {
    position: relative;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-bottom: 3px solid transparent;
    transition: all 0.3s ease;
    font-weight: 500;
}

.nav-link:hover {
    color: var(--primary-color);
    background-color: var(--light-bg);
}

.nav-link.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background-color: var(--light-bg);
}

.nav-link i {
    font-size: 1.125rem;
}

/* Main Content */
.main-content {
    position: relative;
    min-height: calc(100vh - 200px);
    padding: 2rem 0;
    overflow: hidden; /* Prevent content from showing behind loading overlay */
}

.content-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Page Management */
.page {
    display: none;
}

.page.active {
    display: block;
}

/* Ensure page content is visible when loaded via AJAX */
#page-content .page {
    display: block !important;
}

#page-content .page.active {
    display: block !important;
}

/* Page Headers */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.page-header h2 {
    color: var(--text-primary);
    font-size: 1.875rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 1rem;
}

/* Button Styles */
.btn-primary, .btn-secondary, .btn-filter {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    font-size: 0.875rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: #1e40af;
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background-color: white;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--light-bg);
    border-color: var(--primary-color);
}

.btn-filter {
    background-color: var(--secondary-color);
    color: white;
}

.btn-filter:hover {
    background-color: #2563eb;
}

/* Dashboard Stats */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.stat-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: white;
}

.incoming-icon {
    background-color: var(--success-color);
}

.outgoing-icon {
    background-color: var(--secondary-color);
}

.pending-icon {
    background-color: var(--warning-color);
}

.total-icon {
    background-color: var(--primary-color);
}

.stat-content h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Recent Activity */
.recent-activity {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.recent-activity h3 {
    margin-bottom: 1rem;
    color: var(--text-primary);
    font-size: 1.25rem;
}

.activity-list {
    max-height: 400px;
    overflow-y: auto;
}

.activity-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.3s ease;
}

.activity-item:hover {
    background-color: var(--light-bg);
}

.activity-item:last-child {
    border-bottom: none;
}

.activity-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.activity-type {
    font-weight: 600;
    color: var(--primary-color);
    font-size: 0.875rem;
}

.activity-ref {
    color: var(--text-primary);
    font-weight: 500;
}

.activity-time {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* Form Styles */
.filters-section, .audit-filters {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    min-width: 200px;
}

.filter-group label {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.form-input, .form-select, .form-textarea {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.875rem;
    transition: border-color 0.3s ease;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.1);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
}

/* Search Section */
.search-section {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
}

.search-form {
    margin-bottom: 2rem;
}

.search-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.search-group {
    flex: 1;
    min-width: 200px;
}

.search-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

/* Table Styles */
.documents-table, .results-table, .audit-table {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background-color: var(--light-bg);
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

td {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

tbody tr:hover {
    background-color: var(--light-bg);
}

tbody tr:last-child td {
    border-bottom: none;
}

/* Status Badges */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
}

.status-received {
    background-color: rgba(22, 163, 74, 0.1);
    color: var(--success-color);
}

.status-processing {
    background-color: rgba(202, 138, 4, 0.1);
    color: var(--warning-color);
}

.status-completed {
    background-color: rgba(30, 58, 138, 0.1);
    color: var(--primary-color);
}

.status-draft {
    background-color: rgba(100, 116, 139, 0.1);
    color: var(--text-secondary);
}

.status-sent {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--secondary-color);
}

.status-delivered {
    background-color: rgba(22, 163, 74, 0.1);
    color: var(--success-color);
}

/* Action Buttons */
.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

.action-btn.view {
    background-color: rgba(59, 130, 246, 0.1);
    color: var(--secondary-color);
}

.action-btn.edit {
    background-color: rgba(202, 138, 4, 0.1);
    color: var(--warning-color);
}

.action-btn.delete {
    background-color: rgba(220, 38, 38, 0.1);
    color: var(--accent-color);
}

.action-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 0;
    border-radius: 12px;
    width: 90%;
    max-width: 600px;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.modal-close:hover {
    color: var(--accent-color);
}

.modal-body {
    padding: 1.5rem;
    max-height: 60vh;
    overflow-y: auto;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* Footer */
.government-footer {
    background-color: var(--text-primary);
    color: white;
    padding: 2rem 0;
    margin-top: 4rem;
}

.footer-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer-info p {
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
}

.footer-links a {
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    font-size: 0.875rem;
    margin: 0 0.5rem;
    transition: color 0.3s ease;
}

.footer-links a:hover {
    color: white;
}

/* Responsive Design */
@media (max-width: 768px) {
    .header-container {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .nav-menu {
        flex-wrap: wrap;
    }

    .nav-link {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }

    .page-header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .dashboard-stats {
        grid-template-columns: 1fr;
    }

    .filters-section, .audit-filters {
        flex-direction: column;
    }

    .search-row {
        flex-direction: column;
    }

    .footer-container {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .modal-content {
        margin: 10% auto;
        width: 95%;
    }

    table {
        font-size: 0.75rem;
    }

    th, td {
        padding: 0.5rem;
    }
}

/* Print Styles */
@media print {
    .main-navigation,
    .header-actions,
    .modal,
    .btn-primary,
    .btn-secondary {
        display: none !important;
    }

    .government-header {
        background: white !important;
        color: black !important;
        box-shadow: none !important;
    }

    body {
        background: white !important;
    }
}

/* Page Loading Indicator */
.main-content {
    position: relative; /* Establish positioning context for loading overlay */
}

.page-loading {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
    border-radius: 12px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.1);
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(59, 130, 246, 0.2);
    border-top: 5px solid #3b82f6;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.1);
}

.page-loading p {
    margin-top: 1.5rem;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: 0.025em;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Loading States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus states for accessibility */
.nav-link:focus,
.form-input:focus,
.form-select:focus,
.btn-primary:focus,
.btn-secondary:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Admin Styles */
.admin-tabs {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.tab-buttons {
    display: flex;
    background-color: var(--light-bg);
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    flex: 1;
    padding: 1rem;
    background: none;
    border: none;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    border-bottom: 3px solid transparent;
}

.tab-btn.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background-color: white;
}

.tab-btn:hover:not(.active) {
    color: var(--primary-color);
    background-color: rgba(30, 58, 138, 0.05);
}

.tab-content {
    padding: 0;
}

.tab-pane {
    display: none;
    padding: 2rem;
}

.tab-pane.active {
    display: block;
}

.tab-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.tab-header h3 {
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 600;
}

/* Departments */
.departments-list {
    display: grid;
    gap: 1rem;
}

.department-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    background: var(--light-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.department-info h4 {
    color: var(--text-primary);
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.department-info p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0.25rem 0;
}

.department-actions {
    display: flex;
    gap: 0.5rem;
}

/* Settings */
.settings-section {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: var(--light-bg);
    border-radius: 8px;
}

.settings-section h4 {
    color: var(--text-primary);
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.setting-group {
    margin-bottom: 1.5rem;
}

.setting-group label {
    display: block;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.settings-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Reports */
.reports-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
}

.report-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.3s ease;
}

.report-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.report-icon {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    background-color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
}

.report-content h3 {
    color: var(--text-primary);
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.report-content p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.report-filters {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.report-filters h3 {
    color: var(--text-primary);
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
}

.filter-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.custom-period {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--light-bg);
    border-radius: 8px;
}

/* Status badges for users */
.status-active {
    background-color: rgba(22, 163, 74, 0.1);
    color: var(--success-color);
}

.status-inactive {
    background-color: rgba(100, 116, 139, 0.1);
    color: var(--text-secondary);
}

/* Login page specific styles */
.success-message {
    background-color: #d1fae5 !important;
    border-color: #10b981 !important;
    color: #059669 !important;
}

/* Form validation states */
.form-input.invalid {
    border-color: #ef4444;
    background-color: #fef2f2;
}

.form-input.valid {
    border-color: #10b981;
    background-color: #f0fdf4;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .stat-card,
    .documents-table,
    .search-section,
    .department-card,
    .report-card {
        border: 2px solid var(--text-primary);
    }

    .login-card {
        border: 2px solid white;
    }
}