/* Custom styles for PostgreSQL API Admin — charte Ageneau Group */
:root {
    --brand-navy: #2c347e;      /* bleu du logo */
    --brand-navy-dark: #1d2357; /* blocs de code */
    --brand-grey: #d0d0d0;      /* gris de l'ellipse du logo */
}

html {
    /* Ancres (#...) visibles sous la barre de navigation fixée en haut */
    scroll-padding-top: 5rem;
}

body {
    padding-bottom: 20px;
    background-color: #f4f5f8; /* remplacé par /theme.css (Paramètres > Apparence) */
}

h1, .h1, h2, .h2 {
    color: var(--bs-primary);   /* couleur principale (Paramètres > Apparence) */
    font-weight: 700;
}

.navbar {
    margin-bottom: 20px;
}

/* Barre de navigation : liseré gris rappelant l'ellipse du logo */
.app-navbar {
    border-bottom: 3px solid var(--brand-grey);
    padding-top: 0.4rem;
    padding-bottom: 0.4rem;
}

.app-navbar .nav-link {
    font-weight: 600;
}

.app-navbar .nav-link.active {
    box-shadow: inset 0 -3px 0 currentColor;
}

/* Sous-menus (Accès, Données, Administration) : couleurs de la barre, voir /theme.css.
   L'entrée de la page courante est marquée comme le menu actif : trait vertical au lieu du soulignement. */
.app-navbar .dropdown-menu {
    border-top: 3px solid var(--app-navbar-text, currentColor);
    margin-top: 0.4rem;
    min-width: 13rem;
}

.app-navbar .dropdown-item {
    font-weight: 600;
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
}

.app-navbar .dropdown-item.active {
    box-shadow: inset 3px 0 0 currentColor;
}

/* Menu replié (petits écrans) : sous-menus en retrait, sans ombre */
@media (max-width: 991.98px) {
    .app-navbar .dropdown-menu {
        border-top-width: 0;
        border-left: 3px solid var(--app-navbar-text, currentColor);
        box-shadow: none !important;
        margin: 0 0 0.5rem 0.5rem;
    }
}

/* Logo : TOUJOURS sur fond blanc, même si la barre change de couleur */
.brand-logo {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    background-color: #fff;
    border-radius: 0.375rem;
    padding: 0.2rem 0.45rem;
    margin-right: 0.75rem;
}

.brand-logo img {
    display: block;
    height: 40px;
    width: auto;
}

.brand-title {
    padding-left: 0.75rem;
    border-left: 2px solid var(--brand-grey);
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.02em;
}

/* Petits écrans : logo seul, pour garder le bouton de menu sur la même ligne */
@media (max-width: 575.98px) {
    .brand-title {
        display: none;
    }
}

.login-logo img {
    background-color: #fff;     /* logo toujours sur fond blanc */
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
}

.card {
    margin-bottom: 20px;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

.table-responsive {
    overflow-x: auto;
}

.badge {
    font-size: 0.85em;
}

.btn-group .btn {
    margin-right: 5px;
}

footer {
    margin-top: 50px;
    padding: 20px 0;
    background-color: #fff;
    border-top: 3px solid var(--brand-grey);
}

.card-header {
    font-weight: 600;
}

/* En-têtes de cartes dans la charte (sauf en-têtes colorés, ex. page de connexion) */
.card-header:not([class*="bg-"]) {
    background-color: #fff;
    border-bottom: 2px solid var(--brand-grey);
    color: var(--bs-primary);
}

/* Tableau de bord : chiffres clés */
.stat-card {
    border: 0;
    border-left: 5px solid var(--bs-primary);
}

.stat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    flex-shrink: 0;
    border-radius: 50%;
    background-color: rgba(var(--bs-primary-rgb), 0.1);
    color: var(--bs-primary);
    font-size: 1.4rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.1;
    color: var(--bs-primary);
}

.stat-label {
    color: var(--bs-secondary-color);
}

.form-check-input {
    margin-right: 5px;
}

/* ---------- Documentation ---------- */
.doc-sidebar {
    position: sticky;
    top: 5rem; /* sous la barre de navigation fixée */
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
}

/* Sommaire : liste des tables repliable (<details>) */
.doc-toc-tables > summary {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: var(--bs-list-group-item-padding-y, 0.5rem) var(--bs-list-group-item-padding-x, 1rem);
    cursor: pointer;
    list-style: none;            /* masque le triangle natif */
    user-select: none;
}

.doc-toc-tables > summary::-webkit-details-marker {
    display: none;
}

.doc-toc-tables > summary:hover {
    background-color: var(--bs-tertiary-bg);
}

.doc-toc-tables > summary:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: -2px;
}

.doc-toc-chevron {
    font-size: 0.75em;
    transition: transform 0.15s ease;
}

.doc-toc-tables[open] > summary .doc-toc-chevron {
    transform: rotate(90deg);
}

.doc-toc-tables > .list-group > .list-group-item:last-child {
    border-bottom: 0;
}

.doc-section {
    scroll-margin-top: 5rem;
}

.doc-code {
    position: relative;
}

.doc-code pre,
.doc-pre {
    background-color: var(--brand-navy-dark);
    color: #f8f9fa;
    padding: 0.85rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.85rem;
    white-space: pre;
    overflow-x: auto;
}

.doc-copy {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    background-color: #f8f9fa;
}

/* ---------- Schéma BDD ---------- */
.schema-viewport {
    position: relative;
    height: calc(100vh - 260px);
    min-height: 420px;
    overflow: hidden;
    background-color: #fff;
    background-image: radial-gradient(#dee2e6 1px, transparent 1px);
    background-size: 20px 20px;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.schema-viewport:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: -2px;
}

.schema-viewport.sv-panning {
    cursor: grabbing;
}

.schema-viewport.sv-linking,
.schema-viewport.sv-linking .sv-head {
    cursor: crosshair;
}

.schema-viewport svg {
    display: block;
}

.schema-status {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    background-color: rgba(255, 255, 255, 0.92);
    box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.15);
    pointer-events: none;
}

.schema-status[hidden] {
    display: none;
}

/* ---------- Documentation : tables réductibles ---------- */
.doc-table-toggle {
    padding: 0.75rem 1rem;
    border: 0;
    border-radius: 0;
    font-weight: 600;
}

.doc-table-toggle .doc-chevron {
    display: inline-block;
    transition: transform 0.2s ease;
}

.doc-table-toggle:not(.collapsed) .doc-chevron {
    transform: rotate(90deg);
}

.doc-description {
    white-space: pre-line;
}

/* ---------- Documentation : tester la connexion ---------- */
/* Encart de la requête : GET <serveur>/api/v1/data/<table>?<paramètres> */
.api-request {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.5rem 0.5rem 0.75rem;
    border: 1px solid var(--brand-grey);
    border-left: 4px solid var(--bs-primary);
    border-radius: 0.375rem;
    background-color: #fff;
}

.api-method {
    padding: 0.2rem 0.55rem;
    border-radius: 0.25rem;
    background-color: var(--bs-primary);
    color: #fff;
    font: 700 0.85rem/1.4 var(--bs-font-monospace);
    letter-spacing: 0.04em;
}

.api-url {
    flex: 1 1 18rem;
    min-width: 0;
    color: var(--bs-body-color);
    font-size: 0.9rem;
    overflow-wrap: anywhere;   /* coupe une valeur très longue ; sinon retour à la ligne avant ? et & */
}

.api-url-base { color: var(--bs-secondary-color); }
.api-url-table { color: var(--bs-primary); font-weight: 700; }
.api-url-sep { color: var(--bs-secondary-color); }
.api-url-param { color: #8a5300; }
.api-url-value { color: #146c43; font-weight: 600; }

#test-connexion .form-label code,
[data-api-fields-block] code {
    color: var(--bs-primary);   /* noms de paramètres dans la charte */
}

.api-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    background-color: #fff;
    max-height: 9rem;
    overflow-y: auto;
}

.api-field .form-check-label {
    font-family: var(--bs-font-monospace);
    font-size: 0.85rem;
}

/* Résultat : barre d'état puis conteneur à défilement */
.api-response-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
}

.api-result-scroll {
    max-height: 28rem;
    overflow: auto;
    border: 1px solid var(--brand-grey);
    border-radius: 0.375rem;
    background-color: #fff;
}

.api-result-table thead th {
    position: sticky;     /* en-têtes visibles pendant le défilement */
    top: 0;
    z-index: 1;
    background-color: #eef0f6;
    color: var(--bs-primary);
    white-space: nowrap;
}

.api-result-table td {
    white-space: nowrap;
    max-width: 24rem;
    overflow: hidden;
    text-overflow: ellipsis;
}

.api-result-json {
    margin: 0;
    padding: 0.85rem 1rem;
    min-height: 100%;
    background-color: var(--brand-navy-dark);
    color: #f8f9fa;
    font-size: 0.85rem;
}

.connection-facts dt {
    font-weight: 600;
    color: var(--bs-secondary-color);
}

/* ---------- Page Tables : actions sur plusieurs tables ---------- */
.bulk-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid var(--brand-grey);
    border-radius: 0.375rem;
    background-color: #f8f9fb;
}

.bulk-toolbar.has-selection {
    border-color: var(--bs-primary);
    background-color: rgba(var(--bs-primary-rgb), 0.06);
}

.bulk-count {
    font-weight: 600;
}

.bulk-col {
    width: 2.5rem;
    text-align: center;
}

/* ---------- Page Tables : grille des champs ---------- */
.column-grid td input[type="text"] {
    min-width: 10rem;
}

/* ---------- Bouton « Remonter en haut » ---------- */
.back-to-top {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 1050;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 50%;
    padding: 0;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.2);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.back-to-top.show {
    opacity: 1;
    visibility: visible;
}

@media (prefers-reduced-motion: reduce) {
    .back-to-top,
    .doc-table-toggle .doc-chevron {
        transition: none;
    }
}

/* ---------- Cartes repliables (classe collapsible-card, voir main.js) ----------
   Repliées par défaut quand JavaScript est actif (classe « js » posée par nav.js) ;
   sans JavaScript, tout reste affiché. */
.js .collapsible-card > .card-header {
    cursor: pointer;
    user-select: none;
}

.js .collapsible-card > .card-header:hover {
    background-color: var(--bs-tertiary-bg);
}

.js .collapsible-card > .card-header:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: -2px;
}

/* Avant la fin de l'initialisation, règle posée par nav.js (cartes déjà ouvertes visibles) */
.js.cards-ready .collapsible-card:not(.is-open) > :not(.card-header) {
    display: none;
}

.js .collapsible-card:not(.is-open) > .card-header {
    border-bottom: 0;
}

.card-chevron {
    display: inline-block;
    font-size: 0.8em;
    transition: transform 0.2s ease;
}

.collapsible-card.is-open > .card-header .card-chevron {
    transform: rotate(90deg);
}

@media (prefers-reduced-motion: reduce) {
    .card-chevron {
        transition: none;
    }
}

/* Page Logs : toutes les colonnes visibles sans défilement horizontal sur un écran courant */
.logs-table {
    font-size: 0.9rem;
}

.logs-table .logs-event {
    min-width: 14rem;
    max-width: 32rem;
}

/* Texte long sans espace (jeton, URL, message d'erreur) : coupé à la ligne au lieu d'élargir
   la colonne et de pousser les suivantes hors de l'écran (fréquent à 500 ou 1000 lignes) */
.logs-table .logs-event,
.logs-table .logs-event code,
.logs-table td.small code {
    overflow-wrap: anywhere;
}

.logs-table .logs-address code {
    word-break: break-all;
}

/* Liste déroulante à choix multiple (_multi_select.html) : libellé tronqué, menu défilant */
.multi-select-toggle {
    max-width: 100%;
    min-width: 12rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: start;
}

.multi-select-menu {
    max-height: 22rem;
    min-width: 16rem;
    max-width: min(32rem, 90vw);
    overflow-y: auto;
}

/* Page Tables, « Accès à la table » : une phrase par mode sous la liste déroulante */
.access-mode-help li + li {
    margin-top: .25rem;
}

/* Boutons « Modifier » en flèche : vers le bas fermé, vers le haut ouvert (Bootstrap collapse) */
.btn-toggle-chevron .bi-chevron-down {
    display: inline-block;
    transition: transform .2s ease;
}
.btn-toggle-chevron[aria-expanded="true"] .bi-chevron-down {
    transform: rotate(180deg);
}

/* Page Utilisateurs : colonne Actions sur plusieurs lignes */
.users-table .users-actions {
    min-width: 16rem;
}

/* Listes à cocher (Tables, Logs) : ligne sélectionnée bien visible, même sur une ligne zébrée ou survolée :
   fond bleu clair de la charte et barre bleue à gauche */
.table > tbody > tr:has(> td.bulk-col input:checked) > * {
    --bs-table-bg-state: rgba(44, 52, 126, .16);
}
.table > tbody > tr:has(> td.bulk-col input:checked) > td:first-child {
    box-shadow: inset 4px 0 0 var(--brand-navy);
}
.table-hover > tbody > tr:has(> td.bulk-col input:checked):hover > * {
    --bs-table-bg-state: rgba(44, 52, 126, .24);
}

/* Paramètres > Courriel de création de compte : aperçu isolé (iframe sandbox) */
.account-email-preview {
    width: 100%;
    height: 22rem;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    background: #fff;
}

/* Paramètres : un encadré par thème dans chaque carte (.runtime-group : ancien nom, conservé) */
.settings-group,
.runtime-group {
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius-lg);
    padding: 1rem 1.25rem;
    background: var(--bs-tertiary-bg);
}
.settings-group-title,
.runtime-group-title {
    float: none;
    width: auto;
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: .25rem;
}
.settings-group .runtime-env,
.runtime-group .runtime-env {
    font-size: .85em;
    opacity: .85;
}

/* Paramètres : nom de la rubrique sur une ligne (écran large) */
@media (min-width: 992px) {
    .settings-table td:first-child {
        white-space: nowrap;
    }
}
/* Paramètres : résumé du réglage lisible sur mobile (le tableau défile horizontalement) */
.settings-table td:nth-child(2) {
    min-width: 14rem;
}
