/* General Styles & Variables */
:root {
    --primary-color: #005a9c;
    --primary-hover-color: #004a80;
    --secondary-color: #6c757d;
    --success-color: #198754;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #0d6efd;
    --orange-color: #fd7e14;
    --ai-color: #563d7c;
    --light-gray: #f8f9fa;
    --border-color: #dee2e6;
    --text-color: #212529;
    --text-muted: #6c757d;
    --body-bg: #f0f2f5;
    --card-bg: #ffffff;
    --border-radius: 8px;
    --box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --box-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
}

/* Default body style for ALL pages (no background image) */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--body-bg);
    margin: 0;
    padding: 20px;
    color: var(--text-color);
    line-height: 1.6;
}

/* ===== START: STYLES ONLY FOR AUTH/LOGIN PAGES ===== */

/* This targets ONLY pages with the 'auth-page-body' class, like login.html */
.auth-page-body {
    /* 1. Set the background image */
    background-image: url('bg.jpg');
    
    /* 2. CRITICAL FIX: Use 'cover' to fill the entire screen without distortion. */
    /* This will ensure there are no black bars. Cropping on the far left/right is normal. */
    background-size: cover;
    
    /* 3. Center the image, so the most important part is always visible */
    background-position: center center;
    
    background-repeat: no-repeat;
    
    /* 4. Set a black background color for loading and fallback */
    background-color: #000000;
    
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    padding: 0; /* Override default body padding for this page */
}

/* 5. Style the logo so it ONLY appears on auth pages */
.auth-page-body .site-logo-link {
    position: fixed;
    top: 20px;
    left: 25px;
    z-index: 1001;
    display: block;
}

.auth-page-body .site-logo {
    height: 50px; /* You can adjust this value */
    width: auto;
    display: block;
    transition: transform 0.2s ease-in-out;
}

.auth-page-body .site-logo:hover {
    transform: scale(1.05);
}

/* ===== END: STYLES ONLY FOR AUTH/LOGIN PAGES ===== */


/* Utility Classes */
.d-inline { display: inline; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.w-100 { width: 100%; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

/* General Components */
.main-content { max-width: 1200px; margin: auto; }
.container { border: 1px solid var(--border-color); padding: 1.5rem 2rem; margin-bottom: 1.5rem; border-radius: var(--border-radius); background: var(--card-bg); box-shadow: var(--box-shadow); width: 100%; box-sizing: border-box; }
details { width: 100%; }
details summary { cursor: pointer; user-select: none; }
details summary h2 { display: inline; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 1rem; border-bottom: 1px solid var(--border-color); text-align: left; vertical-align: middle; }
th { background-color: var(--light-gray); font-weight: 500; color: var(--text-muted); text-transform: uppercase; font-size: 12px; letter-spacing: 0.5px; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="date"], select, textarea {
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-right: 0.5rem;
    font-size: 1rem;
    box-sizing: border-box;
}
textarea { width: 98%; }
button, .button { display: inline-block; padding: 0.6rem 1.2rem; border: none; border-radius: var(--border-radius); cursor: pointer; color: white; font-weight: 500; font-size: 14px; text-decoration: none; text-align: center; transition: transform 0.1s ease-in-out, box-shadow 0.2s; }
button:hover, .button:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.button-primary { background-color: var(--primary-color); }
.button-secondary { background-color: var(--secondary-color); }
.button-success { background-color: var(--success-color); }
.button-danger { background-color: var(--danger-color); }
.button-info { background-color: var(--info-color); }
.button-warning { background-color: var(--warning-color); color: var(--text-color); }
.button-orange { background-color: var(--orange-color); }
.button-sm { font-size: 13px; padding: 5px 10px; }
.flash { padding: 1rem; margin-bottom: 1.5rem; border-radius: var(--border-radius); text-align: center; font-weight: 500; border: 1px solid transparent; }
.flash.success { color: #0f5132; background-color: #d1e7dd; border-color: #badbcc; }
.flash.danger { color: #842029; background-color: #f8d7da; border-color: #f5c2c7; }
.flash.warning { color: #664d03; background-color: #fff3cd; }
.flash.info { color: #055160; background-color: #cff4fc; border-color: #b6effb; }

/* Login box now sits on top of the background image */
.login-box { max-width: 400px; width: 100%; padding: 2.5rem; background: var(--card-bg); box-shadow: var(--box-shadow-lg); border-radius: var(--border-radius); }
.login-box h1 { text-align: center; color: var(--text-color); margin-top: 0; margin-bottom: 2rem; font-size: 2rem; font-weight: 600; }
.login-box p { text-align: center; color: var(--text-muted); margin-bottom: 25px; font-size: 15px; }
.login-box input[type="text"], .login-box input[type="password"], .login-box input[type="email"] { display: block; width: 100%; margin-bottom: 1rem; font-size: 16px; }
.login-box input[type="text"]:focus, .login-box input[type="password"]:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(0, 90, 156, 0.2); }
.login-box button { width: 100%; background-color: var(--primary-color); }
.login-box .extra-links { text-align: right; margin-top: 1rem; font-size: 14px; }
.login-box .extra-links a { color: var(--primary-color); text-decoration: none; }
.login-box .extra-links a:hover { text-decoration: underline; }
.verify-mfa input[type="text"] { text-align: center; letter-spacing: 0.5em; }

/* All other page styles remain the same */
/* --- Admin Panel & User Management --- */
.admin-panel-body .main-content { max-width: 1100px; }
.top-nav { margin-bottom: 2rem; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.top-nav div { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.actions-cell { display: flex; justify-content: flex-end; gap: 0.5rem; }
.inactive { opacity: 0.6; color: var(--text-muted); }
.status-dot { height: 12px; width: 12px; border-radius: 50%; display: inline-block; margin-right: 0.5rem; }
.status-dot.active { background-color: var(--success-color); }
.status-dot.deactivated { background-color: var(--secondary-color); }
.add-department-form { display:flex; gap: 10px; align-items:flex-end; }
.edit-department-form { display:flex; gap: 5px; }
.status-locked { color: var(--danger-color); font-weight: bold; }
.assignment-checkbox-container { max-height: 120px; overflow-y: auto; border: 1px solid var(--border-color); padding: 10px; border-radius: 5px; background-color: var(--card-bg); }
.assignment-checkbox-container label { display: block; margin-bottom: 5px; font-weight: normal; cursor: pointer; }
.assignment-checkbox-container input[type="checkbox"] { margin-right: 8px; vertical-align: middle; }
.add-user-form { display:flex; flex-wrap:wrap; gap:15px; align-items:flex-end; }
.edit-user-actions { display:flex; gap: 5px; align-items: center; }
.edit-user-actions input { width: 150px; }

/* --- Department Dashboard & Menu Content --- */
.flex-container { display: flex; min-height: 100vh; }
.sidebar { width: 280px; flex-shrink: 0; border-right: 1px solid var(--border-color); padding: 1.5rem; height: 100vh; position: sticky; top: 0; background-color: var(--card-bg); display:flex; flex-direction: column; }
.sidebar-nav { flex-grow: 1; overflow-y: auto;}
.department-dashboard .main-content { flex-grow: 1; padding: 2rem 2.5rem; }
.nav-header { text-transform: uppercase; font-size: 12px; font-weight: bold; color: var(--text-muted); margin: 25px 0 10px; padding-bottom: 5px; border-bottom: 1px solid var(--border-color);}
.sidebar-link { text-decoration: none; color: var(--text-color); display: block; padding: 0.75rem 1rem; border-radius: 6px; margin-top: 5px; font-weight: 500; }
.sidebar-link:hover { background-color: var(--light-gray); }
.sidebar-link.active { background-color: var(--primary-color); color: white;}
.sidebar-search-form { display: flex; }
.sidebar-search-form input { flex-grow:1; }
.sidebar-search-form button { background-color: var(--primary-color); }
.ai-qa-link { background-color: var(--ai-color); color: white; margin-top: 0.5rem; }
.global-admin-link { background-color: var(--danger-color); color: white; }
.delegate-approvals-link { background-color: var(--warning-color); color: var(--text-color); }
.logout-form { margin: 0; }
.logout-button { width: 100%; background-color: var(--secondary-color); color: white; text-align:center; margin-top: 10px; }
.department-title-span { color: var(--text-muted); font-weight: 400; }
.add-menu-form { display: flex; gap: 0.5rem; align-items: center; }
.menu-item { background: var(--light-gray); padding: 1rem; border-left: 4px solid transparent; margin-top: 0.5rem; border-radius: 6px; }
.menu-item .menu-item { background: #fdfdff; margin-left: 1rem; }
.menu-item > div { display: flex; justify-content: space-between; align-items: center; }
.menu-item > div > span > a { font-weight: 500; text-decoration: none; color: var(--primary-color); font-size: 1.1rem; }
.toggle-menu-button { background-color: var(--secondary-color); font-size: 12px; }
.menu-content-page h1 { margin-bottom: 0.5rem; }
.menu-content-page .back-link { text-decoration: none; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 768px) { .form-grid { grid-template-columns: 1fr 1fr; } }
.metadata-field-group { margin-bottom: 10px; }
.metadata-field-group label { display: block; margin-bottom: 5px; font-weight: bold; }
.tag-selection-box { max-height: 120px; overflow-y: auto; border: 1px solid var(--border-color); padding: 10px; border-radius: 5px; background-color: #fff; }
.tag-selection-box label { display: block; margin-bottom: 5px; }
.post-item { list-style: none; margin-bottom: 20px; padding: 20px; background: var(--light-gray); border-radius: 5px; position: relative; }
.post-title { margin-top: 0; margin-bottom: 10px; }
.post-header { display:flex; flex-direction: column; gap: 6px; }
.post-meta { color: var(--text-muted); font-size: 14px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; margin-left: 6px; background: #eef2ff; color: #3730a3; border: 1px solid #c7d2fe; }
.badge-company { background: #e6fffa; color: #065f46; border-color: #99f6e4; }
.badge-all { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.post-metadata { margin-top: 15px; padding-top: 15px; font-size: 14px; border-top: 1px solid #e9ecef;}
.post-metadata-item { margin-bottom: 5px;}
.post-metadata-item strong { color: #495057; display: inline-block; width: 120px; }
.post-content { margin-top: 15px; padding-top: 15px; border-top: 1px solid #e9ecef;}
.post-attachments ul { list-style-type: none; padding-left: 0; margin-top: 5px; }
.post-attachments li { background: #e9ecef; padding: 8px 12px; border-radius: 4px; margin-bottom: 8px;}
.file-main-line { display: flex; justify-content: space-between; align-items: center; font-weight: 500;}
.file-main-line a { margin-left: 10px; }
.version-history { font-size: 14px; margin-top: 8px; padding-left: 15px;}
.version-history a { color: #0056b3; }
.post-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; position: absolute; top: 20px; right: 20px;}
.post-status-badge { display:inline-block; padding: 4px 8px; font-size: 12px; font-weight: bold; border-radius: 12px; color: white; text-transform: capitalize; margin-left: 10px;}
.status-draft { background-color: #6c757d; }
.status-published { background-color: #28a745; }
.status-archived { background-color: #ffc107; color: #212529; }
.post-tags { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #ccc; }
.tag-badge { display: inline-block; background-color: var(--primary-color); color: white; padding: 4px 10px; margin-right: 5px; margin-bottom: 5px; border-radius: 12px; font-size: 13px; font-weight: 500; }

/* --- Compact Post List Styles --- */
.post-item-compact { 
    list-style: none; 
    margin-bottom: 15px; 
    padding: 15px 20px; 
    background: var(--light-gray); 
    border-radius: 5px; 
}

.post-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.post-left {
    flex: 1;
}

.post-title-inline {
    margin: 0;
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.post-actions-inline {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.post-meta-compact {
    color: var(--text-muted);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.post-tags-inline {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    margin-left: 8px;
}

.post-tags-inline .tag-badge {
    margin: 0;
    background-color: #d1fae5;
    color: #065f46;
    font-size: 12px;
    padding: 3px 10px;
}

/* --- Modern Post Item Styles --- */
.post-item-modern {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 1rem;
    transition: box-shadow 0.2s, transform 0.2s;
}

.post-item-modern:hover {
    box-shadow: var(--box-shadow);
    transform: translateY(-2px);
}

.post-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    gap: 1rem;
}

.post-title-section {
    flex: 1;
}

.post-title-modern {
    margin: 0 0 0.5rem 0;
    font-size: 1.25rem;
    color: var(--text-color);
    font-weight: 600;
}

.post-badges {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.post-actions-modern {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.post-meta-modern {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.post-tags-modern {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    width: 100%;
    margin-top: 0.5rem;
}

.tag-badge-modern {
    background-color: #e0f2fe;
    color: #075985;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 500;
}

.post-content-preview {
    margin-top: 1rem;
    padding-top: 1rem;
    color: var(--text-color);
    line-height: 1.6;
}

/* --- Form Enhancement Styles --- */
.checkbox-scroll-container {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.75rem;
    background-color: var(--card-bg);
}

.checkbox-label {
    display: block;
    padding: 0.5rem;
    margin-bottom: 0.25rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.checkbox-label:hover {
    background-color: var(--light-gray);
}

.checkbox-label input[type="checkbox"] {
    margin-right: 0.5rem;
    cursor: pointer;
}

.tag-select-label {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background-color: var(--light-gray);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.tag-select-label:hover {
    background-color: #e0f2fe;
    border-color: var(--primary-color);
}

.tag-select-label input[type="checkbox"] {
    margin-right: 0.5rem;
    cursor: pointer;
}

/* --- Button Enhancement --- */
#toggleFormBtn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#toggleIcon {
    font-size: 1.25rem;
    font-weight: bold;
}

.ai-feature-area { margin-bottom: 15px; padding: 10px; background-color: #eef7ff; border-radius: 5px; }
.summary-result { margin-top: 10px; white-space: pre-wrap; line-height: 1.6; color: #333; }

/* --- AI Search Page --- */
.ai-search-page .main-content { max-width: 900px; }
.ai-search-page .container { border: 1px solid #dee2e6; padding: 20px; margin-bottom: 25px; border-radius: 8px; }
.ai-search-page #ai-answer { margin-top: 20px; padding: 15px; background-color: #f8f9fa; border-radius: 5px; line-height: 1.7; white-space: pre-wrap; }
.ai-search-page #ai-answer h3 { margin-top: 0; }
.ai-search-page #ai-answer ul, .ai-search-page #ai-answer ol { padding-left: 25px; }
.ai-search-page .thinking { color: #6c757d; font-style: italic; }
.ai-search-page .back-link { margin-bottom: 20px; display: inline-block; }
.ai-search-page .filters { display: flex; gap: 30px; margin-top: 15px; padding-top: 15px; border-top: 1px solid #e9ecef;}
.ai-search-page .filter-group fieldset { border: 1px solid #dee2e6; border-radius: 5px; padding: 10px; }
.ai-search-page .filter-group legend { font-weight: bold; padding: 0 5px; }
.ai-search-page .filter-group label { display: block; margin-bottom: 5px; cursor: pointer; }
.ai-search-page #answer-container { display: none; }

/* --- Preview Page --- */
.preview-body { background-color: #525659; }
.preview-container { width: 100%; height: 100vh; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.preview-container img, .preview-container embed, .preview-container iframe { max-width: 100%; max-height: 100%; border: none; }
.preview-fallback { text-align: center; padding: 40px; color: white; }
.preview-fallback a { padding:10px 15px; background-color:var(--primary-color); color:white; text-decoration:none; border-radius:5px; }

/* --- Search Results Page --- */
.search-page-body .main-container { display: flex; }
.search-page-body .sidebar { width: 280px; padding: 20px; background-color: #fff; border-right: 1px solid #dee2e6; height: 100vh; position: sticky; top: 0;}
.search-page-body .main-content { flex-grow: 1; padding: 30px; }
.search-form .form-group { margin-bottom: 20px; }
.search-form label { display: block; font-weight: bold; margin-bottom: 5px; }
.search-form input, .search-form select { width: 100%; }
.result-item { background: #fff; border: 1px solid #dee2e6; padding: 15px; border-radius: 8px; margin-bottom: 15px; }
.result-item h3 { margin: 0 0 10px 0; }
.result-item a { text-decoration: none; color: #0056b3; }
.result-meta { font-size: 14px; color: #6c757d; }
.result-meta span:last-child { float: right; }

/* --- Reports Page --- */
.reports-page .main-content { max-width: 900px; }
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; }
.stat-card { background: #f8f9fa; padding: 20px; border-radius: 8px; text-align: center; }
.stat-card h3 { margin: 0 0 10px 0; color: #495057; }
.stat-card p { font-size: 2.5rem; font-weight: bold; color: var(--primary-color); margin: 0; }

/* --- Logs Page --- */
.logs-page .main-content { max-width: 1200px; }
.pagination { margin-top: 20px; text-align: center; }
.pagination a { color: var(--primary-color); text-decoration: none; padding: 8px 16px; margin: 0 4px; border: 1px solid var(--border-color); border-radius: 5px; }
.pagination a:hover { background-color: #e9ecef; }
.pagination .active { font-weight: bold; background-color: var(--primary-color); color: white; border-color: var(--primary-color); }
.pagination .disabled { color: var(--text-muted); pointer-events: none; }

/* --- Setup Page --- */
.setup-page .main-content { max-width: 600px; margin: 50px auto; }
.setup-page input[type="text"] { display: block; width: 95%; }

/* --- Delegation Page --- */
.delegation-page .main-content { max-width: 900px; }
.inactive-row { color: var(--text-muted); text-decoration: line-through; }

/* --- Change Request Page --- */
.change-request-actions { display:flex; gap: 5px; }

/* --- Base Template --- */
.base-template-body .main-container { display: flex; }
.base-template-body .sidebar { width: 280px; }
.base-template-body .content-area { flex-grow: 1; }

/* --- Permissions Page --- */
.permissions-page .main-content { max-width: 900px; }
.permissions-page .top-nav { margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; }
.permissions-page td { vertical-align: middle; }
.permissions-checkbox-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.permissions-checkbox-grid label { display: block; }

/* --- FIX: Constrain images within the post content area --- */
.post-content img {
    max-width: 100%;
    height: auto;
    display: block;
    margin-top: 1rem;
    margin-bottom: 1rem;
}

/* --- NEW STYLES for Login Box Branding --- */

.login-logo {
    display: block;
    margin: 0 auto 20px auto; /* Center the logo and add space below it */
    max-width: 160px;       /* Adjust size as needed */
    height: auto;
}

.login-box {
    /* This makes the description box positioning work perfectly */
    overflow: hidden; 
}

.login-description-box {
    /* Use negative margins to break out of the parent's padding */
    margin: 2rem -2.5rem -2.5rem -2.5rem;
    padding: 1.5rem 2.5rem;
    background-color: var(--light-gray); /* A light gray background like in the image */
    border-top: 1px solid var(--border-color);
}


.login-description-box p {
    margin: 0;
    font-size: 14px;
    text-align: center;
    color: var(--text-muted);
}


/* --- Two-column layout for post creation and list --- */
.post-content-layout {
    display: grid;
    grid-template-columns: 450px 1fr;
    gap: 1.5rem;
    align-items: start;
}

.post-creation-side {
    /* Sticky positioning so it stays in view when scrolling */
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

.post-list-side {
    /* This ensures the content list maintains its width */
    min-width: 0; /* Prevents grid blowout */
}

/* When screen is too narrow, stack vertically */
@media (max-width: 1024px) {
    .post-content-layout {
        grid-template-columns: 1fr;
    }
    
    .post-creation-side {
        position: static;
        max-height: none;
    }
}

@media (min-width: 768px) {
    .post-creation-layout {
        display: grid;
        grid-template-columns: 400px 1fr;
        gap: 2rem;
        align-items: start;
    }
    
    .post-creation-form {
        position: sticky;
        top: 20px;
        max-height: calc(100vh - 40px);
        overflow-y: auto;
    }
}

@media (max-width: 767px) {
    .post-creation-layout {
        display: block;
    }
    
    .post-creation-form {
        margin-bottom: 2rem;
    }
}