/* ======================================== */
/* --- Base & Layout --- */
/* ======================================== */
/* --- Card List Layout (Using Flexbox) --- */
.controle-card-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: left; /* Align cards starting from the left */
    gap: 20px;
    padding: 15px;
    max-width: 1400px; /* Max width for the grid container */
    margin-left: auto;  /* Center the grid container */
    margin-right: auto; /* Center the grid container */
    box-sizing: border-box; /* Good practice */
}

/* --- Individual Card Styling --- */
.controle-card {
  border: 1px solid #ddd;
  border-radius: 8px;
  background-color: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 300px;
  flex: 1 0 260px;
  max-width: 300px;
}

.controle-card-header {
    padding: 10px 15px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.controle-card-header .info-item {
    font-size: 0.9em;
    color: #555;
}

.controle-card-header .info-item strong {
    color: #333;
}

.controle-card-body {
    padding: 15px;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Title positioned above image */
.card-visible-title {
  order: -1;
  margin-bottom: 10px;
  font-size: 1.1em;
  font-weight: bold;
  color: #737373;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  max-height: calc(1.4em * 2);
}

/* Image Preview Container */
.image-preview-container {
    border: none;
    /* min-height: 150px; */ /* Removed */
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #f0f0f0;
    overflow: hidden;
    width: 100%;
    aspect-ratio: 1 / 1.4142; /* A4 Portrait */
}

/* Styling the Image Rendered by Moodle */
.image-preview-container img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
}

.image-preview-container a {
   display: flex;
   justify-content: center;
   align-items: center;
   width: 100%;
   height: 100%;
   line-height: 0;
   box-shadow: 0px 0px 5px #bdbdbd;
}

.image-preview-container .fielduploadsubmission,
.image-preview-container .fileuploadsubmission {
   margin: 0;
   padding: 0;
   display: flex;
   justify-content: center;
   align-items: center;
   width: 100%;
   height: 100%;
}

/* Info Text Styling */
.controle-card-info {
    margin-top: auto; /* Push towards bottom */
}

.controle-card-info .chapitres {
    margin: 10px 0 0 0;
    font-size: 0.95em;
    color: #333;
    line-height: 1.4;
}

.controle-card-info .chapitres strong {
    font-weight: bold;
    display: block; /* Put "Chapitres:" on its own line */
    margin-bottom: 5px;
}

.controle-card-info .chapitres .pill.pill-chapitres {
    margin-right: 5px; /* Space between pills */
    margin-bottom: 5px; /* Space below pills if they wrap */
}

/* Footer Styling */
.controle-card-footer {
    padding: 10px 15px;
    background-color: #f8f9fa;
    border-top: 1px solid #ddd;
    font-size: 0.85em;
    color: #666;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    min-height: 40px;
}

.controle-card-footer .actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.controle-card-footer .actions a,
.controle-card-footer .actions span {
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.controle-card-footer .actions a img,
.controle-card-footer .actions span img {
    margin-right: 3px;
    height: 1em;
    width: 1em;
}

.controle-card-footer .entry-meta {
   text-align: right;
   flex-grow: 1;
}

/* ======================================== */
/* --- Pill Styling --- */
/* ======================================== */
.pill {
    display: inline-block;
    font-weight: bold;
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.85em;
    border: 1px solid;
    white-space: nowrap;
    margin-bottom: 3px;
    margin-right: 3px;
}
.pill-niveau { background-color: white; border-color: #f59c27; color: #f59c27; }
.pill-chapitres { background-color: white; border-color: #0e5c4b; color: #0e5c4b; }
.pill-date { background-color: white; border-color: #39b8b0; color: #39b8b0; }
.pill-corrige {
    background-color: #f1a137;
    color: white;
    border-color: #f1a137;
    font-size: 0.8em;
    padding: 3px 8px;
    vertical-align: middle;
}

/* ======================================== */
/* --- Filter Controls --- */
/* ======================================== */
#filter-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 15px 15px 0 15px;
    margin-bottom: 15px;
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
    box-sizing: border-box;
}
.filter-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.filter-group label {
    font-size: 0.9em;
    font-weight: bold;
    color: #555;
}
.filter-group select,
.filter-group input[type="text"] {
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.95em;
    min-width: 200px;
}
.custom-filter-controls {
    margin-bottom: 20px;
    padding: 15px;
    background-color: #f8f8f8;
    border: 1px solid #ddd;
    border-radius: 5px;
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
}
.filter-row {
    margin-bottom: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.filter-row:last-child {
    margin-bottom: 0;
}
.filter-row strong {
    margin-right: 10px;
    white-space: nowrap;
}
.filter-button {
    padding: 6px 12px;
    border: 1px solid #ccc;
    background-color: #fff;
    color: #0e5c4b;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    font-size: 0.9em;
    white-space: nowrap;
}
.filter-button:hover {
    background-color: #eee;
    border-color: #aaa;
}
.filter-button.active {
    background-color: #0e5c4b;
    color: #fff;
    border-color: #0e5c4b;
    font-weight: bold;
}
.chapter-buttons-container {
    min-height: 30px;
}
#cosmetic-search-button {
  background-color: #0e5c4b;
  font-weight: bolder;
  font-size: inherit;
  color: white;
  border: none;
  padding: 8px 15px;
  border-radius: 4px;
  cursor: pointer;
}
#cosmetic-reset-button {
  display: none;
}

/* ======================================== */
/* --- Moodle Specific Hiding & Adjustments --- */
/* ======================================== */
#data_adv_form {
    display: none !important;
    visibility: hidden !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    overflow: hidden !important;
}
#advancedcheckbox {
    display:none;
}
#page-mod-data-view .drawer-left:not(#theme_boost-drawers-primary) {
    display: none !important;
}
#page-mod-data-view #page {
    padding-left: 0 !important;
    margin-left: 0 !important;
}
label[for="pref_search"],
#pref_search,
#reg_search {
    display: none !important;
}

/* ============================================================================= */
/* --- Custom Autocomplete Search --- */
/* ============================================================================= */
#custom-search-container,
#custom-search-container-single {
    max-width: 1400px;
    margin: 0 auto 20px auto;
    padding: 0 15px;
    box-sizing: border-box;
    position: relative;
}
#custom-search-container .autoComplete_wrapper,
#custom-search-container-single .autoComplete_wrapper {
    display: block !important;
    max-width: 700px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    position: relative;
}
#custom-search-input,
#custom-search-input-single {
    display: block;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 10px 15px 10px 40px;
    font-size: 1.1em;
    color: #333;
    border: 1px solid #ccc;
    border-radius: 25px;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23888' class='bi bi-search' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 15px center;
    background-size: 16px 16px;
    -webkit-appearance: none;
       -moz-appearance: none;
            appearance: none;
    box-sizing: border-box;
}
#custom-search-input:focus,
#custom-search-input-single:focus {
    outline: none;
    border-color: #0e5c4b;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.1), 0 0 0 2px rgba(14, 92, 75, 0.2);
}
#custom-search-input::placeholder,
#custom-search-input-single::placeholder {
  color: #0e5c4bb2 !important;
  opacity: 1;
  font-weight: bold;
}
#custom-search-input::-webkit-input-placeholder,
#custom-search-input-single::-webkit-input-placeholder {
    color: #0e5c4bb2 !important;
    opacity: 1;
    font-weight: bold;
}
#custom-search-input::-moz-placeholder,
#custom-search-input-single::-moz-placeholder {
    color: #0e5c4bb2 !important;
    opacity: 1;
    font-weight: bold;
}
#custom-search-input:-ms-input-placeholder,
#custom-search-input-single:-ms-input-placeholder {
    color: #0e5c4bb2 !important;
    font-weight: bold;
}
#custom-search-input::-ms-input-placeholder,
#custom-search-input-single::-ms-input-placeholder {
     color: #0e5c4bb2 !important;
    font-weight: bold;
}
#custom-search-container .autoComplete_wrapper > ul,
#custom-search-container-single .autoComplete_wrapper > ul {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    margin-top: 5px;
    list-style: none;
    margin: 0;
    padding: 0;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    max-height: 300px;
    overflow-y: auto;
    box-sizing: border-box;
}
#custom-search-container .autoComplete_wrapper > ul > li,
#custom-search-container-single .autoComplete_wrapper > ul > li {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    font-size: 0.95em;
    color: #333333;
}
#custom-search-container .autoComplete_wrapper > ul > li:last-child,
#custom-search-container-single .autoComplete_wrapper > ul > li:last-child {
    border-bottom: none;
}
#custom-search-container .autoComplete_wrapper > ul > li:hover,
#custom-search-container-single .autoComplete_wrapper > ul > li:hover,
#custom-search-container .autoComplete_wrapper > ul > li.autoComplete_selected,
#custom-search-container-single .autoComplete_wrapper > ul > li.autoComplete_selected {
    background-color: #f0f0f0;
    color: #0e5c4b;
}
#custom-search-container .autoComplete_wrapper > ul > li mark,
#custom-search-container-single .autoComplete_wrapper > ul > li mark {
    background-color: transparent;
    color: #f59c27;
    font-weight: bold;
    padding: 0;
}

/* ======================================== */
/* --- Single View Specific --- */
/* ======================================== */
.database-backlink,
.fiche-title-area,
.fiche-controle-container,
.mod_data_fastcomments_wrapper,
.custom-search-container-singleview {
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
}
.database-backlink,
.fiche-title-area,
.mod_data_fastcomments_wrapper,
.custom-search-container-singleview {
    padding-left: 15px;
    padding-right: 15px;
}
.database-backlink { margin-bottom: 20px; padding-top: 10px; }
.fiche-title-area { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; padding-bottom: 10px; position: relative; }
.fiche-title-wrapper { display: flex; align-items: center; gap: 10px; flex-grow: 1; margin-right: 15px; flex-wrap: wrap; }
.fiche-title { font-size: 1.8em; color: #333; margin: 0; display: inline; }
.fiche-actions-haut { font-size: 0.9em; flex-shrink: 0; }
.fiche-controle-container { padding: 15px; border: 1px solid #dee2e6; border-radius: 5px; margin-bottom: 30px; background-color: white; }
.fiche-metadata-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.fiche-description { margin-bottom: 25px; padding: 15px; background-color: #fdfdfd; border: 1px solid #eee; border-radius: 4px; line-height: 1.6; color: #555; display: flow-root; }
.fiche-description p { margin-bottom: 10px; }
.fiche-description p:last-child { margin-bottom: 0; }
.pdf-thumbnail-float { float: right; width: 35%; margin-left: 20px; margin-bottom: 10px; margin-top: -60px; position: relative; z-index: 10; background-color: #fff; border: 1px solid #ccc; box-shadow: 0px 3px 8px rgba(0, 0, 0, 0.2); border-radius: 4px; overflow: hidden; line-height: 0; }
.pdf-thumbnail-float:empty { display: none; }
.pdf-thumbnail-float img { display: block; width: 100%; height: auto; border-radius: 4px; }
.pdf-thumbnail-float a { display: block; line-height: 0; }
.tabs-and-actions-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0; padding-bottom: 10px; border-bottom: 1px solid #eee; flex-wrap: wrap; }
.desktop-tabs { margin-bottom: -11px; margin-right: 15px; }
.desktop-tabs .tab { background-color: transparent; border: none; border-bottom: 2px solid transparent; padding: 10px 15px; cursor: pointer; font-size: 1em; color: #f59c27; transition: all 0.2s ease-in-out; font-weight: bold; position: relative; }
.desktop-tabs .tab:hover { background-color: #f8f9fa; border-bottom-color: #ccc; color: #cf821f; }
.desktop-tabs .tab.active { font-weight: bold; color: #0e5c4b; border-bottom: 2px solid #0e5c4b; background-color: white; z-index: 1; }
.active-download-button-area { flex-shrink: 0; white-space: nowrap; display: flex; align-items: center; gap: 10px; }
#active-pdf-download-button.whitebutton { display: inline-block; padding: 6px 12px; background-color: #f59c27; color: white; text-decoration: none; border-radius: 4px; font-weight: bold; font-size: 0.9em; border: 1px solid #f59c27; transition: background-color 0.2s ease, border-color 0.2s ease; }
#active-pdf-download-button.whitebutton:hover { background-color: #ec971f; border-color: #e08e0b; }
#active-pdf-error { color: #dc3545; font-size: 0.9em; }
.fiche-controle-contenu { margin-top: 20px; }
.fiche-controle-colonne.onglet { flex-direction: column; padding: 15px; border: 1px solid #eee; border-radius: 4px; background-color: #fff; width: 100%; box-sizing: border-box; }
.adobe-viewer-container { width: 100%; aspect-ratio: 1 / 1.414; border: 1px solid #ccc; margin-bottom: 15px; display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; }
.adobe-viewer-message { color: #666; font-style: italic; padding: 20px; text-align: center; }
.fiche-controle-footer { margin-top: 25px; padding-top: 15px; border-top: 1px solid #eee; font-size: 0.8em; color: #6c757d; text-align: center; }
.mod_data_fastcomments_wrapper { margin-top: 30px; margin-bottom: 30px; }


/* ======================================== */
/* --- Responsive Adjustments --- */
/* ======================================== */
@media(max-width:768px){
    .desktop-tabs{ display:none; }
    .fiche-controle-colonne.onglet{ display:flex !important; width: 100%; flex-direction: column; margin-bottom: 15px; }
    .fiche-controle-colonne.onglet:last-child { margin-bottom: 0; }
    .tabs-and-actions-header { flex-direction: column; align-items: flex-start; border-bottom: none; padding-bottom: 0; margin-bottom: 15px; }
    .active-download-button-area { margin-top: 10px; }
    .controle-card-list, #filter-controls, .custom-filter-controls, #custom-search-container, #custom-search-container-single { max-width: 100%; padding-left: 10px; padding-right: 10px; }
    .database-backlink, .fiche-title-area, .fiche-controle-container, .mod_data_fastcomments_wrapper, .custom-search-container-singleview { max-width: 100%; padding-left: 10px; padding-right: 10px; }
    .pdf-thumbnail-float { float: none; width: auto; max-width: 60%; display: block; margin: 15px auto; position: static; z-index: auto; }
    .fiche-description { display: block; }
    #page-mod-data-view #page { padding-left: 0 !important; margin-left: 0 !important; }
}

@media (max-width: 680px) {
    .controle-card {
        width: calc(100% - 10px); /* Single column on small mobile */
    }
    .controle-card-list {
        justify-content: center;
        padding-left: 5px;
        padding-right: 5px;
        gap: 10px;
    }
    .pdf-thumbnail-float { max-width: 70%; }
    #custom-search-container .autoComplete_wrapper, #custom-search-container-single .autoComplete_wrapper { max-width: none; }
}

@media (max-width: 480px) {
    .fiche-title { font-size: 1.5em; }
    .fiche-title-area { flex-direction: column; align-items: flex-start; }
    .fiche-title-wrapper { margin-right: 0; margin-bottom: 10px; gap: 5px; }
    #filter-controls { gap: 10px; }
    .filter-group select, .filter-group input[type="text"] { min-width: 0; width: 100%; }
    .filter-group { width: 100%; }
    .pill { font-size: 0.8em; padding: 4px 8px; }
    .pill-corrige { font-size: 0.75em; padding: 2px 6px; }
    .custom-filter-controls { padding: 10px; }
    .filter-button { padding: 5px 10px; font-size: 0.85em; }
    .mod_data_fastcomments_wrapper { margin-top: 20px; margin-bottom: 20px; padding-left: 5px; padding-right: 5px; }
    .pdf-thumbnail-float { max-width: 85%; margin-left: auto; margin-right: auto; }
    #custom-search-input, #custom-search-input-single { padding: 8px 12px 8px 35px; font-size: 1em; background-position: 12px center; }
    #custom-search-container .autoComplete_wrapper > ul, #custom-search-container-single .autoComplete_wrapper > ul { left: 0px; right: 0px; }
}