/*
 * FILE: style.css
 * DESCRIPTION: Unified and refactored stylesheet for the KAiSA application.
 * Organized by component and view for better maintainability.
 */

/* --- 1. GLOBAL STYLES & ROOT VARIABLES --- */

:root {
    /* Theme Colors */
    --primary-color: #171636;
    --secondary-color: #16B8DF;
    --success-color: #1DB17D;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --info-color: #adb5bd;
    --violet-color: #9370DB;

    /* Grayscale & Text */
    --light-gray: #f8f9fa;
    --medium-gray: #e9ecef;
    --dark-gray: #343a40;
    --text-color: #212529;

    /* Typography */
    --font-family: 'Nunito Sans', Arial, sans-serif;
}

body {
    margin: 0;
    font-family: var(--font-family);
    display: flex;
    height: 100vh;
    background: #f5f5f5;
    color: var(--text-color);
}


/* --- 2. MAIN LAYOUT STRUCTURE --- */

/* Main application wrapper, controlled by auth.js */
#protectedContent {
    display: flex;
    flex-grow: 1;
    width: 100%;
    height: 100vh;
}

/* Sidebar container */
.sidebar {
    width: 240px;
    background: var(--primary-color);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 0;
    flex-shrink: 0;
    position: relative;
}

.sidebar img {
    width: 100%;
    height: auto;
    margin-bottom: 1rem;
    padding: 1rem 1rem 0 1rem;
    box-sizing: border-box;
}

/* Sidebar navigation links and buttons */
.sidebar a, .sidebar button {
    margin: 0 1rem 0.5rem 1rem;
    padding: 0.75rem 1rem;
    box-sizing: border-box;
    width: calc(100% - 2rem);
    color: #fff;
    text-decoration: none;
    border-radius: 8px;
    display: block;
    transition: background-color 0.3s;
    background: transparent;
    border: none;
    text-align: left;
    font-size: 1rem;
    font-family: var(--font-family);
    cursor: pointer;
}

.sidebar a:hover,
.sidebar button:hover,
.sidebar button.active {
    background: rgba(255, 255, 255, 0.2);
}

/* Main content area wrapper */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

/* Header bar at the top of the main content */
.header {
    background: #fff;
    padding: 1rem 2rem;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    gap: 20px;
}

.header-right-controls {
    display: flex;
    align-items: center;
    gap: 20px; /* This controls the space between the project selector and user icon */
    flex-shrink: 0; /* Prevents this group from shrinking */
}

/* Global Search Bar styles */
.global-search-container {
    flex-grow: 1; /* Allows the container to take up available space */
    display: flex;
    justify-content: center;
    margin: 0;
    padding: 0;
}

#globalSearchInput {
    width: 100%;
    max-width: 600px; /* Prevents the search bar from being too wide on large screens */
    padding: 10px 15px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1em;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#globalSearchInput:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 3px rgba(22, 184, 223, 0.2); /* Use secondary color with transparency for focus */
}

/* Content area below the header where tabs are displayed */
.content {
    padding: 2rem;
}


/* --- 3. COMMON REUSABLE COMPONENTS --- */

/* Buttons */
button.button-like, .button-like {
    background-color: var(--primary-color);
    color: white;
    padding: 10px 18px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 500;
    transition: background-color 0.3s ease;
}
button.button-like:hover, .button-like:hover {
    background-color: #157359;
}
button.button-like.secondary, .button-like.secondary {
    background-color: var(--medium-gray);
    color: var(--dark-gray);
}
button.button-like.secondary:hover, .button-like.secondary:hover {
    background-color: #ced4da;
}
.button-like.primary.large-button {
    padding: 12px 25px;
    font-size: 1.1em;
    font-weight: bold;
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}
.form-group {
    margin-bottom: 20px;
}
.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
}
.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="file"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1em;
    box-sizing: border-box;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--primary-color);
    outline: none;
}
.password-group {
    position: relative;
}
.toggle-password {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(5px);
    cursor: pointer;
    user-select: none;
}

/* Styles for editable display fields in modals */
.display-container {
    position: relative;
    cursor: pointer;
}

.form-control-display {
    width: 100%;
    min-height: 40px;
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: var(--light-gray);
    box-sizing: border-box;
    transition: border-color 0.2s ease, background-color 0.2s ease;
    white-space: pre-line;
    padding-right: 35px;
}

.display-container:hover .form-control-display {
    border-color: var(--primary-color);
    background-color: #fff;
}

.display-container:hover {
    color: var(--primary-color);
}

.form-control-display-as-textarea {
    resize: vertical;
    overflow-y: auto;
    min-height: 60px;
    line-height: 1.5;
}

.action-plan-header {
    display: flex;
    align-items: flex-end; /* Vertically aligns the text and the date input */
    gap: 10px; /* Adds some space between the label and the date input */
    margin-bottom: 8px; /* Adds space before the textarea */
}

/* Override the global 'display: block' rule for this specific label */
.action-plan-header label {
    display: inline;      /* Allows the label to sit next to other elements */
    margin-bottom: 0;     /* Removes the default bottom margin for labels */
    flex-shrink: 0;       /* Prevents the label from wrapping if space is tight */
}

.action-plan-header input[type="date"] {
    padding: 5px 8px; /* Makes the date input a bit smaller to fit well */
}

/* Header User Profile Dropdown */
#user-profile-menu {
    position: relative;
    cursor: pointer;
}
#user-initials-bubble {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1.1em;
    text-transform: uppercase;
}
.dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background-color: white;
    min-width: 220px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
    z-index: 1001;
    border-radius: 5px;
    padding: 5px 0;
}
#user-profile-menu:hover .dropdown-content {
    display: block;
}
.dropdown-header {
    padding: 10px 15px;
    border-bottom: 1px solid var(--medium-gray);
    margin-bottom: 5px;
}
#dropdown-user-name {
    font-weight: bold;
    color: var(--dark-gray);
}
#dropdown-user-email {
    font-size: 0.9em;
    color: #6c757d;
}
.dropdown-content a {
    color: var(--dark-gray);
    padding: 10px 15px;
    text-decoration: none;
    display: block;
    font-size: 0.95em;
}
.dropdown-content a:hover {
    background-color: var(--light-gray);
}
#projectSelector {
    padding: 8px 12px;
    border-radius: 5px;
    border: 1px solid #ccc;
    background-color: #fff;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    min-width: 150px;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0; top: 0;
    width: 100%; height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.6);
    align-items: center;
    justify-content: center;
}
.modal-content {
    background-color: #fff;
    margin: auto;
    padding: 30px;
    border: 1px solid #888;
    width: 90%;
    max-width: 650px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    position: relative;
}
.modal-content h3 {
    margin-top: 0;
    margin-left: -30px; /* Counteract parent padding */
    margin-right: -30px; /* Counteract parent padding */
    margin-bottom: 25px;
    padding: 15px 30px;
    background-color: var(--primary-color);
    color: white;
    border-radius: 8px 8px 0 0; /* Rounded corners only on top */
}
.close-button {
    color: #aaa;
    font-size: 32px;
    font-weight: bold;
    position: absolute;
    top: 10px;
    right: 20px;
    cursor: pointer;
    z-index: 10;
}

/* This rule targets any close-button inside a modal-content that has a title (h3) */
.modal-content:has(h3) .close-button {
    color: white;
    top: 25px;
    right: 25px;
    opacity: 0.8;
    transition: opacity 0.2s ease;
}

.modal-content:has(h3) .close-button:hover {
    opacity: 1;
}


.auth-modal-content {
    max-width: 400px;
    text-align: center;
}
.confirm-modal-actions {
    margin-top: 25px;
    display: flex;
    justify-content: flex-end;
    gap: 15px;
}
#confirmModalMessage {
    white-space: pre-line;
}

/* Unified List Items (used for Norms, internal docs, etc.) */
.unified-list-item {
    background-color: #fff;
    border: 1px solid var(--medium-gray);
    border-left: 5px solid var(--secondary-color);
    margin-bottom: 12px;
    border-radius: 4px;
    list-style: none;
}
.list-item-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    padding: 12px 18px;
}
.list-item-info {
    flex-grow: 1;
}
.list-item-info strong {
    display: block;
    font-size: 1.1em;
    color: var(--primary-color);
}
.list-item-info p {
    font-size: 0.95em;
    color: #555;
    margin: 0;
}
.list-item-info strong.norm-title-link {
    cursor: pointer;
    transition: color 0.2s ease-in-out;
}
.list-item-info strong.norm-title-link:hover {
    color: var(--success-color);
}
.list-item-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.icon-loupe,.icon-delete,.icon-text,.tree-action-icon,.norm-source-link,.report-action-icon {
    cursor: pointer;
    font-size: 1.6em;
    color: var(--dark-gray);
    transition: transform 0.2s ease, color 0.2s ease;
}
.icon-loupe:hover,.icon-delete:hover,.icon-text:hover,.tree-action-icon:hover,.norm-source-link:hover,.report-action-icon:hover {
    transform: scale(1.2);
    color: var(--primary-color); /* change color in hover */
}
.icon-delete {
    color: var(--danger-color);
}

.icon-delete:hover {
    color: #a71d2a;
}

/* Loaders, Spinners & Toasts */
.loader-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}
.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1050;
}
.toast {
    position: relative;
    padding: 15px 40px 15px 20px;
    border-radius: 5px;
    color: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.5s;
    margin-bottom: 10px;
    white-space: pre-line;
}
.toast.show {
    opacity: 1;
    transform: translateX(0);
}
.toast.toast-success { background-color: var(--success-color); }
.toast.toast-error { background-color: var(--danger-color); }
.toast.toast-info { background-color: var(--info-color); }
.toast .toast-close-button {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: white;
    font-size: 24px;
    font-weight: bold;
    line-height: 1;
    cursor: pointer;
    opacity: 0.7;
    padding: 0;
    transition: opacity 0.2s ease;
}
.toast .toast-close-button:hover {
    opacity: 1;
}

/* Misc Components */
.section-separator {
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid var(--medium-gray);
}
.error-message {
    color: var(--danger-color);
    margin-top: 10px;
    min-height: 1em;
}
.file-actions-container {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-top: 5px;
}


/* --- 4. TAB/PAGE SPECIFIC STYLES --- */

/* 4.1. General Tab Styles */
.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
}
.tab-header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}
.tab-header-actions h2 {
    margin-bottom: 0;
    flex-grow: 1;
}
.content h2 {
    margin-bottom: 1rem;
    color: var(--primary-color);
    border-bottom: 2px solid var(--secondary-color);
    padding-bottom: 10px;
    font-size: 1.6em;
}
.content h3 {
    color: var(--secondary-color);
    margin-top: 30px;
    margin-bottom: 15px;
    font-size: 1.3em;
}

/* 4.2. Entreprise Tab */
.inner-tabs {
    display: flex;
    border-bottom: 2px solid var(--medium-gray);
    margin-bottom: 0px;
}
.inner-tab-button {
    padding: 10px 20px;
    cursor: pointer;
    border: none;
    background-color: transparent;
    font-size: 1rem;
    font-weight: 500;
    color: var(--dark-gray);
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
}
.inner-tab-button:hover {
    color: var(--primary-color);
}
.inner-tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    font-weight: bold;
}
.inner-tab-content {
    display: none;
    padding-top: 10px;
}
.inner-tab-content.active {
    display: block;
}
#entrepriseForm button[type="submit"] {
    display: block;
    margin-left: auto;
    margin-right: auto;
    margin-top: 20px;
}
.action-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--medium-gray);
}
.action-footer .form-group {
    margin-top: 0;
    text-align: center;
}

/* 4.3. Normes Tab */
#normes-header {
    gap: 15px;
}
.normes-header-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-left: auto;
}
.normes-header-controls select {
    padding: 6px 10px;
    font-size: 0.9em;
}
.normes-header-controls .sort-order-btn {
    font-size: 1.4em;
    padding: 4px 8px;
    cursor: pointer;
    background: transparent;
    border: 1px solid #ccc;
    border-radius: 4px;
}
.back-button {
    background: none;
    border: none;
    font-size: 1.1em;
    cursor: pointer;
    color: var(--primary-color);
    font-weight: bold;
}
.back-button:hover {
    text-decoration: underline;
}
.normes-grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 20px;
}
.normes-tile {
    background-color: #fff;
    border: 1px solid var(--medium-gray);
    border-radius: 8px;
    padding: 20px;
    cursor: pointer;
    transition: box-shadow 0.2s ease-in-out, transform 0.2s ease-in-out;
    display: flex;
    flex-direction: column;
}
.normes-tile:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    transform: translateY(-3px);
}
.normes-tile .tile-header {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 15px;
    flex-shrink: 0;
}
.normes-tile .tile-body {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-grow: 1;
}
.normes-tile .tile-chart-container {
    position: relative;
    width: 150px;
    height: 150px;
    flex-shrink: 0;
}
.normes-tile .tile-chart {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    position: relative;
}
.normes-tile .tile-chart::before {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 80%; height: 80%;
    background: #fff;
    border-radius: 50%;
    z-index: 1;
}
.normes-tile .tile-chart-center-text {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    text-align: center;
    font-size: 1em;
    font-weight: bold;
    color: var(--success-color);
}
.normes-tile .tile-chart-center-text span {
    display: block;
    font-size: 0.7em;
    font-weight: normal;
    color: var(--dark-gray);
}
.normes-tile .tile-stats {
    font-size: 0.9em;
    color: var(--dark-gray);
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex-grow: 1;
}
.tile-stats-compliance, .tile-stats-norms {
    padding: 5px 0;
}
.tile-stats-separator {
    height: 1px;
    background-color: var(--medium-gray);
    margin: 8px 0;
    width: 80%;
}
.normes-tile .tile-footer {
    /* Reserve a minimum height to ensure consistent spacing even when empty */
    min-height: 36px;
    text-align: center;
    /* Use flexbox to vertically center the link when it appears */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Apply visual styles (border, margins) ONLY when the footer has content */
.normes-tile .tile-footer:not(:empty) {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid var(--medium-gray);
}

.critical-points-link {
    color: var(--danger-color);
    font-weight: bold;
    text-decoration: none;
    font-size: 0.95em;
    transition: color 0.2s ease-in-out;
}
.critical-points-link:hover {
    color: var(--success-color);
    text-decoration: underline;
}
.norm-list-tabs {
    display: flex;
    border-bottom: 2px solid var(--medium-gray);
    margin-bottom: 20px;
}
.norm-list-tab-button {
    padding: 10px 20px;
    cursor: pointer;
    border: none;
    background-color: transparent;
    font-size: 1.1em;
    font-weight: 500;
    color: var(--dark-gray);
    border-bottom: 3px solid transparent;
    transition: all 0.2s ease;
}
.norm-list-tab-button:hover {
    color: var(--primary-color);
}
.norm-list-tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    font-weight: bold;
}
.norm-list-tab-content {
    display: none;
}
.norm-list-tab-content.active {
    display: block;
}
.norm-status-filter-container {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    padding: 10px;
    background-color: var(--light-gray);
    border-radius: 4px;
    align-items: center;
}
.norm-status-filter-container strong {
    font-size: 0.95em;
    color: var(--dark-gray);
}
.norm-status-filter-container label {
    cursor: pointer;
    font-size: 0.9em;
}
.norm-status-filter-container input[type="radio"] {
    margin-right: 5px;
    appearance: none;
    background-color: #fff;
    width: 1.15em;
    height: 1.15em;
    border: 1px solid #ccc;
    border-radius: 50%;
    display: inline-grid;
    place-content: center;
    vertical-align: middle;
}
.norm-status-filter-container input[type="radio"]::before {
    content: "";
    width: 0.65em;
    height: 0.65em;
    border-radius: 50%;
    transform: scale(0);
    transition: 120ms transform ease-in-out;
    box-shadow: inset 1em 1em var(--primary-color);
}
.norm-status-filter-container input[type="radio"]:checked::before {
    transform: scale(1);
}
.icon-info-norm {
    font-size: 1.2em;
    color: var(--info-color);
    margin-right: 10px;
    cursor: default;
}
.normes-tree-container ul {
    list-style: none;
    padding-left: 0;
}
.normes-tree-container .tree-node-norme-main {
    font-weight: bold;
    cursor: pointer;
    padding: 8px 12px;
    background-color: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 5px;
}
.normes-tree-container .toggler {
    display: inline-block;
    width: 18px;
    margin-right: 8px;
}
.normes-tree-container .toggler::before {
    content: '+';
}
.normes-tree-container li.expanded > .tree-node-norme-main > .toggler::before {
    content: '−';
}
.normes-tree-container .norm-item-wrapper {
    padding-left: 25px;
    display: none;
}
.normes-tree-container li.expanded > .norm-item-wrapper {
    display: block;
}
/* Styles for the compliance legend on the Normes page */
.compliance-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px 20px; /* Space between items */
    margin-bottom: 25px; /* Space below the legend */
    padding: 10px;
    background-color: var(--light-gray);
    border-radius: 4px;
}
.legend-item {
    display: flex;
    align-items: center;
    font-size: 0.9em;
}
.legend-color-box {
    display: inline-block;
    width: 15px;
    height: 15px;
    margin-right: 8px;
    border-radius: 3px;
}

/* 4.4. Exigences Tab */
.exigences-layout {
    display: flex;
    gap: 20px;
}
.exigences-content {
    flex-grow: 1;
}
.exigences-tree {
    flex: 0 0 250px;
    background-color: var(--light-gray);
    padding: 15px;
    border-radius: 4px;
    height: fit-content;
}
.exigences-tree ul {
    list-style: none;
    padding-left: 0;
}
.exigences-tree .tree-node {
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 3px;
    transition: background-color 0.2s;
    display: block;
    text-decoration: none;
    color: var(--text-color);
}
.exigences-tree .tree-node:hover {
    background-color: #e9e9e9;
}
.exigences-tree .tree-node.active-node {
    background-color: var(--secondary-color);
    color: white;
}
.exigences-tree .tree-node-level-1 {
    font-weight: bold;
}
.exigences-tree .toggler {
    display: inline-block;
    width: 18px;
    margin-right: 8px;
}
.exigences-tree .toggler::before {
    content: '+';
}
.exigences-tree li.expanded > .tree-node-level-1 > .toggler::before {
    content: '−';
}
.exigences-tree ul ul {
    padding-left: 25px;
    display: none;
}
.exigences-tree li.expanded > ul {
    display: block;
}
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    padding: 10px;
    background-color: var(--medium-gray);
    border-radius: 4px;
}
.filter-bar input, .filter-bar select {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    flex: 1 1 130px;
}
table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
th, td {
    border: 1px solid var(--medium-gray);
    padding: 10px 12px;
    text-align: left;
    vertical-align: middle;
}
th {
    background-color: var(--primary-color);
    color: white;
}
th[data-sort-by] {
    cursor: pointer;
    white-space: nowrap;
}
th[data-sort-by].sort-asc::after { content: ' ▲'; }
th[data-sort-by].sort-desc::after { content: ' ▼'; }
td.actions-cell {
    vertical-align: middle;
}
.actions-wrapper {
    display: grid;
    grid-template-columns: 1fr 1fr;
    place-items: center;
    gap: 5px;
    width: 100%;
}
.priority-dot {
    display: inline-block;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
}
.priority-dot.status-red { background-color: var(--danger-color); }
.priority-dot.status-yellow { background-color: var(--warning-color); }
.priority-dot.status-green { background-color: var(--success-color); }
.priority-dot.status-grey { background-color: var(--info-color); }
.priority-menu {
    position: absolute;
    z-index: 1050;
    background-color: #fff;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border: 1px solid var(--medium-gray);
    padding: 5px;
    min-width: 180px;
}
.priority-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.95em;
    transition: background-color 0.2s ease;
}
.priority-option:hover {
    background-color: var(--light-gray);
}
.priority-option .priority-dot {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}
.state-icons-container {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
}
.state-icon {
    font-size: 1.5em;
    cursor: pointer;
}
.state-icon:not(.active) { color: #b0b0b0; }
.state-icon.active.state-conforme { color: var(--success-color); }
.state-icon.active.state-non_conforme { color: var(--danger-color); }
.state-icon.active.state-a_evaluer { color: var(--primary-color); }
.state-icon.active.state-non_applicable { color: var(--violet-color); }
.pagination-container {
    text-align: center;
    padding: 15px 0;
}
.pagination-button {
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 8px 12px;
    margin: 0 4px;
    cursor: pointer;
}
.pagination-button.active {
    background-color: var(--primary-color);
    color: white;
}

/* Styles for Action Plan page */
.action-plan-required {
    color: var(--danger-color);
    font-style: italic;
}

.compliance-cell-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.compliance-checkbox {
    transform: scale(1.5);
    cursor: pointer;
}

.action-plan-alert {
    font-size: 1.5em;
    cursor: pointer;
}

/* Column width styles for Exigences & Plan d'Actions tables */
.audit-point-cell, .action-plan-cell {
    width: auto; /* This column takes up the remaining space */
}

.assignee-cell, .state-cell {
    width: 150px; /* Fixed width for these columns */
    min-width: 150px;
    text-align: center;
}

.actions-cell {
    width: 90px; /* Fixed width for the 2x2 icon grid */
    min-width: 90px;
}

/* This rule makes any state icon that is NOT active appear grey.
   This will apply to the Plan d'Action icon by default. */
.state-icon:not(.active) {
    color: #b0b0b0; /* A neutral grey */
}

/* This rule styles the single clickable icon on the Plan d'Action page */
.state-icon.conforme-toggle {
    font-size: 1.8em;
    transition: transform 0.2s ease, color 0.2s ease;
    /* It will inherit the grey color from the rule above because it has no 'active' class */
}

/* This rule makes the icon turn green ONLY on hover, indicating the action */
.state-icon.conforme-toggle:hover {
    transform: scale(1.2);
    color: var(--success-color);
}

.deadline-text {
    display: block; /* Ensures the date appears on a new line */
    font-size: 0.85em;
    font-style: italic;
    color: #6c757d; /* A standard bootstrap secondary text color */
    margin-top: 4px;
}
.exigences-tree-header {
    display: flex;
    justify-content: flex-start;
    gap: 12px;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--medium-gray);
    align-items: center;
}

.exigences-bulk-actions {
    display: flex;
    gap: 12px;
}


.tree-action-icon.active.state-conforme {
    color: var(--success-color);
}

.tree-action-icon.active.state-a_evaluer {
    color: var(--primary-color);
}

.tree-action-icon.active.state-non_applicable {
    color: var(--violet-color);
}

/* 4.5. Rapport Tab */
.report-actions-footer {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--medium-gray);
    display: flex;
    justify-content: center;
}

#report-options-container {
    background-color: #fff;
    border: 1px solid var(--medium-gray);
    border-radius: 8px;
    padding: 25px;
    margin-bottom: 25px;
    width: 100%;
    max-width: 700px;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

#report-options-container h3 {
    margin-top: 0;
    margin-bottom: 0;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--medium-gray);
    text-align: center;
    width: 100%;
}

.report-domain-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
    margin-bottom: 0;
}

.domain-checkbox-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: var(--light-gray);
    padding: 8px 12px;
    border-radius: 4px;
}

.domain-checkbox-item label {
    font-weight: normal;
    margin-bottom: 0;
}

.report-name-container {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 500px;
    align-self: center;
}

.report-name-container label {
    font-weight: bold;
    flex-shrink: 0;
}

.report-name-container input {
    flex-grow: 1;
}

#report-options-container #generateReportButton {
    margin-top: 10px;
    align-self: center;
}

/* --- Consolidated Report List Styles --- */
.report-list {
    list-style-type: none;
    padding-left: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.report-list-item {
    background-color: #f9f9f9;
    padding: 12px 18px;
    border-radius: 6px;
    border: 1px solid var(--medium-gray);
    display: flex;
    justify-content: space-between; /* Pushes info to the left and actions to the right */
    align-items: center;
    gap: 20px;
}

/* Make the info container a flexbox to align name and date */
.report-info {
    display: flex;
    align-items: baseline; /* Aligns the text at the bottom, looks clean */
    gap: 15px; /* Space between name and date */
    flex-wrap: wrap; /* Allows date to wrap on very small screens */
}

.report-info a.report-name-link {
    font-weight: bold;
    font-size: 1.1em;
    color: var(--primary-color);
    text-decoration: none;
    white-space: nowrap; /* Prevent name from wrapping */
}
.report-info a.report-name-link:hover {
    text-decoration: underline;
}

.report-date {
    font-size: 0.9em;
    color: #555;
    white-space: nowrap;
    font-style: italic; /* The requested italic style */
}

.report-actions {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-shrink: 0; /* Prevent the actions group from shrinking */
}



/* Styles for the inline rename editor */
.rename-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.rename-container input {
    padding: 6px 10px;
    border: 1px solid var(--primary-color);
    border-radius: 4px;
    font-size: 0.95em;
}

.rename-container .button-like {
    padding: 6px 12px;
    font-size: 0.9em;
}

/* 4.6. Discussion Tab (Chatbot) */

/*
   Main Chat Interface Container
   Structure: Flex Column.
   Height: Fixed calculation to fill the screen minus headers/tabs.
*/
.chatbot-interface {
    /* Visual Styles */
    border: 1px solid var(--medium-gray);
    border-radius: 8px;
    background-color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-top: 20px;

    /* Layout Styles - The "Google AI Studio" effect */
    display: flex;
    flex-direction: column;

    /*
       IMPORTANT: We set a fixed height calculation.
       100vh (screen) - approx 260px (headers + tabs + margins).
       This forces the container to be tall, pushing the input to the bottom.
    */
    height: calc(100vh - 350px);

    /* Remove padding here, we will add it to children to handle scrollbars correctly */
    padding: 0;

    /* Ensure content doesn't spill out of rounded corners */
    overflow: hidden;
}

/* Bubble Styles */
.chatbot-question, .chatbot-answer {
    padding: 12px 15px;
    margin-bottom: 12px;
    border-radius: 8px;
    line-height: 1.5;
    flex-shrink: 0; /* Prevent bubbles from being crushed */
    max-width: 85%; /* Aesthetic: don't let bubbles span full width */
}

.chatbot-question {
    background-color: var(--light-gray);
    border-left: 4px solid var(--primary-color);
    font-weight: bold;
    color: var(--dark-gray);
    align-self: flex-end; /* User messages on the right (optional, remove if unwanted) */
    margin-left: auto;
}

.chatbot-answer {
    background-color: var(--secondary-color);
    color: white;
    white-space: pre-line;
    border-left: 4px solid var(--primary-color);
    align-self: flex-start;
}

/*
   Chat History Area This is the ONLY part that scrolls.
*/
#discussionChatHistory {
    flex-grow: 1;            /* Takes all available empty space */
    overflow-y: auto;        /* Scrollbar appears here */
    padding: 20px;           /* Internal padding for text */
    scroll-behavior: smooth;

    /* CRITICAL for Flexbox scrolling to work properly */
    min-height: 0;

    display: flex;
    flex-direction: column; /* Stacks messages */
}

/* Loading spinner styling */
#discussionLoading {
    text-align: center;
    padding: 10px;
    font-style: italic;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-shrink: 0;
    background: #f9f9f9; /* Slight background to distinguish */
}

#discussionLoading .spinner {
    width: 20px;
    height: 20px;
    border-width: 3px;
}

/*
   Input Area Container
   Pinned to the bottom.
*/
.chatbot-response-area {
    display: flex;
    align-items: flex-start;
    flex-shrink: 0; /* NEVER shrink this area */
    background: #fff;
    border-top: 1px solid var(--medium-gray);

    /* Spacing: Padding inside the box */
    padding: 15px 20px;

    /* Extra padding at the bottom to lift the input up */
    padding-bottom: 25px;
}

.chatbot-response-area textarea {
    flex-grow: 1;
    resize: none; /* Prevent user from breaking layout */
    min-height: 50px; /* Comfortable typing height */
    border-radius: 20px; /* Modern rounded input */
    padding: 10px 15px;
}

.chatbot-response-area .button-like.icon-send {
    padding: 10px 15px;
    font-size: 1.5em;
    line-height: 1;
    margin-left: 10px;
    align-self: center; /* Center button vertically with textarea */
    border-radius: 50%; /* Round button */
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- RAG CHATBOT HEADER STYLES --- */

.discussion-header-container {
    background: #fff;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--medium-gray);
    margin-bottom: 15px; /* Reduced margin to pull chat up */
    display: flex;
    align-items: flex-end;
    gap: 20px;
}

.discussion-filters {
    display: flex;
    gap: 20px;
    flex-grow: 1;
}

.discussion-filters .form-group {
    margin-bottom: 0;
    flex: 1;
}

/* --- 4.7. Accueil Tab --- */

.accueil-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 25px;
    margin-bottom: 25px;
}

.accueil-widget {
    background-color: #fff;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    border: 1px solid var(--medium-gray);
}

#accueil-stats-container {
    display: flex;
    align-items: center;
    gap: 30px;
}

.donut-chart-wrapper {
    text-align: center;
}

.donut-chart {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    position: relative;
    margin: 0 auto 15px auto;
}

.donut-chart-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 75%;
    height: 75%;
    background: #fff;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.donut-chart-percentage {
    font-size: 2.2em;
    font-weight: bold;
    color: var(--primary-color);
}

.donut-chart-label {
    font-size: 1em;
    color: var(--dark-gray);
}

.donut-chart-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px 15px;
}

.global-stats-text {
    font-size: 1.1em;
    flex-grow: 1;
}

.stats-line {
    margin-bottom: 8px;
}

.stats-line.critical a {
    color: var(--danger-color); /* Red text */
    text-decoration: none;      /* No underline by default */
    font-weight: bold;
}
.stats-line.critical a:hover {
    text-decoration: underline; /* Underline only on hover */
}

.stats-line.late a {
    text-decoration: none;
    font-weight: bold;
}
.stats-line.late a:hover {
    text-decoration: underline;
}

/* Style for when there are 0 overdue items */
.stats-line.late a.late-ok {
    color: var(--secondary-color); /* Light blue color */
}

/* Style for when there are > 0 overdue items */
.stats-line.late a.late-overdue {
    color: var(--danger-color); /* Red color */
}

.stats-separator {
    border: none;
    height: 1px;
    background-color: var(--medium-gray);
    margin: 15px 0;
}

#accueil-summary-table-container th,
#accueil-summary-table-container td {
    text-align: center;
}
#accueil-summary-table-container td:first-child {
    text-align: left;
    font-weight: bold;
}

.bar-chart-vertical-container {
    flex-grow: 1;
    display: flex;
    justify-content: space-around;
    align-items: flex-end;
    height: 100%;
    padding: 0 10px;
    background-color: var(--light-gray);
    border-radius: 4px;
    border-left: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
}

.bar-chart-vertical-container .bar-item {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    flex: 1;
    max-width: 50px;
}

.bar-chart-vertical-container .bar {
    width: 70%;
    background-color: var(--success-color);
    border-radius: 4px 4px 0 0;
    transition: height 0.5s ease-out;
}

.bar-chart-vertical-container .bar-label {
    margin-top: 8px;
    font-size: 0.8em;
    white-space: nowrap;
}
.clickable {
    cursor: pointer;
    transition: transform 0.2s ease-in-out;
}

.clickable:hover {
    transform: scale(1.03);
}
.chart-with-axis-wrapper {
    display: flex;
    height: 250px;
    margin-top: 10px;
}

/* Style for the Y-axis title container */
.y-axis-title-container {
    flex: 0 0 30px; /* Fixed width for the title */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Style for the vertical title */
.y-axis-title {
    writing-mode: vertical-rl; /* Makes the text vertical */
    transform: rotate(180deg); /* Rotates it to be read from bottom to top */
    white-space: nowrap;
    font-size: 0.9em;
    color: #6c757d;
    font-weight: bold;
}

/* Style for the overdue items link */
.stats-line.late a {
    color: var(--warning-color); /* Or another color, like --danger-color */
    text-decoration: none;
    font-weight: bold;
}
.stats-line.late a:hover {
    text-decoration: underline;
    color: #e5a000; /* A darker version of the warning color */
}

.y-axis {
    flex: 0 0 50px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: right;
    padding-right: 10px;
    font-size: 0.8em;
    color: #6c757d;
}

.y-axis-label {
    position: relative;
    top: -0.5em;
}

/* 4.8. Global Search Results Panel */
#globalSearchResultsPanel {
    position: fixed; /* Sits on top of other content */
    top: 75px; /* Height of the header */
    right: 0;
    width: 450px; /* Wide as requested */
    height: calc(100vh - 75px); /* Full height minus header */
    background-color: #fff;
    box-shadow: -5px 0 15px rgba(0,0,0,0.15);
    z-index: 1002; /* Above content, below modals */
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
}

#globalSearchResultsPanel:not(.hidden) {
    transform: translateX(0);
}

.search-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid var(--medium-gray);
    flex-shrink: 0;
}

.search-panel-header h3 {
    margin: 0;
    font-size: 1.1em;
    color: var(--primary-color);
}

.search-panel-close-btn {
    font-size: 1.8em;
    cursor: pointer;
    color: var(--dark-gray);
    background: none;
    border: none;
    padding: 0 5px;
}
.search-panel-close-btn:hover {
    color: var(--danger-color);
}

.search-panel-content {
    overflow-y: auto;
    padding: 15px;
    flex-grow: 1;
}

.search-result-group h4 {
    font-size: 1em;
    color: var(--secondary-color);
    margin-top: 10px;
    margin-bottom: 8px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--medium-gray);
}
.search-result-group:first-child h4 {
    margin-top: 0;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 4px;
    margin-bottom: 5px;
}

.search-result-item.clickable {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.search-result-item.clickable:hover {
    background-color: var(--light-gray);
}

.search-result-title {
    flex-grow: 1;
    font-size: 0.85em; /* Smaller text as requested */
    line-height: 1.3;
    color: var(--dark-gray);
}

.search-result-item .icon {
    font-size: 1.4em;
    flex-shrink: 0;
}

.search-result-item .icon-info {
    color: var(--info-color);
    cursor: default;
}

.search-result-item .icon-source {
    color: var(--dark-gray);
    cursor: pointer;
    transition: color 0.2s ease;
}
.search-result-item .icon-source:hover {
    color: var(--primary-color);
}

/* --- 5. THIRD-PARTY LIBRARY OVERRIDES --- */

/* Awesomplete (autocomplete library) */
.filter-bar .awesomplete {
    flex: 1 1 320px;
    min-width: 240px;
    display: block;
}
.filter-bar .norm-filter-wrapper {
    position: relative;
    flex-basis: 100%;
}
.filter-bar .norm-filter-wrapper::after {
    content: '▼';
    position: absolute;
    top: 50%;
    right: 12px;
    transform: translateY(-50%);
    font-size: 0.8em;
    color: #555;
    cursor: pointer;
    z-index: 2;
}
.filter-bar .norm-filter-wrapper input {
    width: 100%;
    box-sizing: border-box;
    padding-right: 30px !important;
}
div.awesomplete > ul {
  min-width: 350px;
  border-radius: 4px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
  border: 1px solid #ccc;
  max-height: 300px;
  overflow-y: auto;
  z-index: 1010;
  background: #fff;
}
div.awesomplete > ul > li {
  padding: 10px;
  font-size: 0.9em;
}
div.awesomplete > ul > li[aria-selected="true"] {
  background: var(--light-gray);
  color: var(--text-color);
}

.awesomplete > input {
    width: 100%;
    box-sizing: border-box;
}

/* --- 6. UTILITY CLASSES --- */

.hidden {
    display: none !important;
}

/* --- Styles for Advanced Confirmation Modal --- */
.advanced-confirm-container {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--medium-gray);
}

.confirmation-instruction {
    font-size: 0.9em;
    color: var(--dark-gray);
    margin-bottom: 5px;
}

.confirmation-text-to-type {
    font-weight: bold;
    color: var(--danger-color);
    background-color: var(--light-gray);
    padding: 8px;
    border-radius: 4px;
    text-align: center;
    margin-bottom: 15px;
    user-select: none; /* Prevents accidental text selection */
}

.confirmation-input {
    width: 100%;
}

/* --- Sidebar Toggle and Minimization Styles --- */

/* Add smooth transitions to sidebar and main content area */
.sidebar, .main {
    transition: all 0.3s ease-in-out;
}

/* Base styling for the toggle button */
.sidebar-toggle {
    margin-top: auto; /* Pushes the button to the bottom */
    margin-bottom: 1rem !important;
    width: 40px !important;
    height: 40px;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
    font-size: 1.2em !important;
    transition: all 0.3s ease-in-out; /* Animate its properties */
}

/* --- Expanded State (Default) --- */

/* When expanded, align the button to the right */
.sidebar-toggle {
    align-self: flex-end; /* THIS IS THE KEY: push to the right */
    margin-right: 1rem; /* Add some space from the edge */
}

/* The arrow icon when expanded */
.sidebar-toggle::before {
    content: '<';
    transition: transform 0.3s ease-in-out;
}


/* --- Minimized State --- */

/* When the body has the 'sidebar-minimized' class, apply these styles */

/* 1. Shrink the sidebar */
body.sidebar-minimized .sidebar {
    width: 80px;
}

/* 2. Hide the text inside the navigation buttons */
body.sidebar-minimized .button-text {
    display: none;
}

/* 3. Center the icon and adjust padding for the new size */
body.sidebar-minimized .sidebar-button {
    padding: 0.75rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 4. Hide the logo image */
body.sidebar-minimized .sidebar img {
    display: none;
}

/* 5. Re-center the toggle button in the minimized sidebar */
body.sidebar-minimized .sidebar-toggle {
    align-self: center; /* THIS IS THE KEY: re-center the button */
    margin-right: 0; /* Remove the right margin */
}

/* 6. Invert the arrow icon */
body.sidebar-minimized .sidebar-toggle::before {
    transform: rotate(180deg);
}
