/* OVERRIDE COLORS */

:root {
    --kendo-color-primary: #dc4344 !important;
    --kendo-color-primary-hover: #c23d3e !important;
    --kendo-color-primary-active: #a83637 !important;
}

/* GENERAL */

html, body {
    font-family: Inter, 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* dvh : exclut la barre d'adresse mobile (fallback vh ci-dessus) */
    margin: 0;
    overflow: hidden;
}

a {
    color: var(--kendo-color-on-app-surface);
}

a:hover {
    color: var(--kendo-color-primary);
    text-decoration: none;
}

h1, h2, h3 {
    margin: .67em 0 .3em;
    font-weight: normal;
}

h1 {
    font-size: 42px;
}

    h1:focus:not(:focus-visible) {
        outline: none;
    }

/* A11Y : indicateur de focus clavier visible (n'apparaît pas au clic souris) */

a:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
.k-drawer-item:focus-visible {
    outline: 2px solid var(--kendo-color-primary);
    outline-offset: 2px;
}

h2 {
    font-size: 32px;
}

h3 {
    font-size: 24px;
}

/* SCROLLBAR - Theme sombre */

/* Firefox */
* {
    scrollbar-color: #4a4a4a #2a2a2a;
}

/* Webkit (Chrome, Edge, Safari) */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: #2a2a2a;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #4a4a4a;
    border-radius: 4px;
    border: 2px solid #2a2a2a;
}

::-webkit-scrollbar-thumb:hover {
    background: #5a5a5a;
}

::-webkit-scrollbar-thumb:active {
    background: #6a6a6a;
}

/* HEADER */

div.appbar-top {
    position: relative;
    z-index: 1;
}

.appbar-top > div {
    line-height: 2.4;
}

#app-title {
    display: flex;
    gap: .2em;
    align-items: center;
    margin: 0;
    padding: 0;
    font-size: 1.2em;
}

#app-title strong {
    font-weight: 500;
}

#app-title sup {
    font-size: .4em;
}

#app-title a,
#app-title a:hover {
    text-decoration: none;
    color: inherit;
}

/* HEADER : LOGO */

#logo-container {
    display: flex;
    align-items: center;
    padding: 0 10px;
}

.header-logo {
    height: 40px;
    width: auto;
}

@media (max-width: 768px) {
    .header-logo {
        height: 30px;
    }
}

/* HEADER : compact par paliers */

@media (max-width: 1024px) {
    /* Le titre de l'app est redondant avec le logo : on le masque en tablette/mobile.
       Préfixe .appbar-top requis : le thème Kendo cible .k-appbar .k-appbar-section (spécificité supérieure) */
    .appbar-top .appbar-sec-title {
        display: none;
    }
}

@media (max-width: 768px) {
    /* L'AppBar passe sur 2 rangées : outils en haut, picker licence en bas */
    .appbar-top.k-appbar {
        flex-wrap: wrap;
        height: auto;
        row-gap: 2px;
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .appbar-top .appbar-sec-logo {
        display: none;
    }

    .appbar-top .appbar-sec-licence {
        order: 10;
        flex: 1 1 100%;
    }

    /* Icône + chevron seulement : le nom prend trop de place sur téléphone */
    .user-menu-name {
        display: none;
    }
}

/* ========================================
   LAYOUT - Conteneur principal et structure
   ======================================== */

/* DRAWER MAIN */

.layout-drawer {
    flex: 1;
    align-items: stretch;
    overflow: hidden;
}

/* SIDENAV */

.layout-drawer > .k-drawer .k-drawer-items {
    margin-top: 0.5em;

    .k-icon {
        width: 16px;
    }
}

.layout-drawer > .k-drawer .k-drawer-item {
    font-size: 0.8rem;
    padding: 5px 10px;
    min-height: unset;
}

.layout-drawer > .k-drawer .k-drawer-item .k-item-text {
    font-size: 0.8rem;
}

/* Cibles tactiles du drawer : min 44px sur mobile.
   Placé APRÈS la règle de base ci-dessus (même spécificité) pour gagner par ordre source ;
   les media queries n'augmentent pas la spécificité. */
@media (max-width: 768px) {
    .layout-drawer > .k-drawer .k-drawer-item {
        min-height: 44px;
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    .layout-drawer > .k-drawer .k-drawer-item .k-item-text {
        font-size: 0.9rem;
    }
}

/* Séparateur : aucun padding, aucun fond, pas d'interaction */
.layout-drawer > .k-drawer .k-drawer-item:has(.drawer-separator) {
    padding: 0;
    background: transparent !important;
    cursor: default;
    pointer-events: none;
    min-height: unset;
}

/* Section title : aucun highlight au survol, pas de curseur pointer */
.layout-drawer > .k-drawer .k-drawer-item:has(.drawer-section-title) {
    background: transparent !important;
    cursor: default;
    pointer-events: none;
    padding: 4px 10px 2px;
}

/* MAIN CONTENT */

.layout-drawer .k-drawer-content {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 5px 10px 10px;
    min-width: 0; /* Confine le débordement des grilles dans leur conteneur, pas la page */
}

/* MAIN LAYOUT (pour LIST - EDIT) */

.layout-main {
    flex: 1;
    display: flex;
    height: calc(100vh - 200px);
    height: calc(100dvh - 200px); /* dvh : exclut la barre d'adresse mobile (fallback vh ci-dessus) */
    transition: all 0.3s ease-in-out;
}

/* LAYOUT : LIST */

.layout-list {
    flex: 0 0 60%;
    display: flex;
    flex-direction: column;
    transition: flex 0.3s ease-in-out;
    overflow: hidden;
    min-height: 0;
    min-width: 0;
}

/* Grille en pleine largeur quand le panneau d'édition est fermé */

.layout-list.list-full-width {
    flex: 0 0 100%;
}

/* LAYOUT : EDIT */

.layout-edit {
    flex: 0 0 40%;
    display: flex;
    flex-direction: column;
    animation: slideInRight 0.3s ease-in-out;
    min-width: 0;

    > * {
        margin-left: 10px;
    }
}

@keyframes spin-cw {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

.btn-refreshing .k-svg-icon {
    animation: spin-cw 0.8s linear infinite;
    display: inline-block;
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(50px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* LAYOUT ERROR */

.layout-error-container {
    background: lightyellow;
    color: #dc3545;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

.layout-error-container .layout-error-reload {
    color: #dc3545;
}

.layout-error-container .layout-error-dismiss {
    color: #dc3545;
}

/* ========================================
   LIST - Section liste/grille
   ======================================== */

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    margin-right: 10px;
}

.list-header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.list-header h4 {
    margin: 0;
    font-size: 1.2em;
}
 
.list-grid {
    flex: 1;
    margin-right: 10px;
    min-height: 0;
}

/* Scroll vertical dans le grid body (lignes), header/footer restent sticky */

.list-grid .k-grid-content {
    overflow-y: auto;
}

.list-grid .k-grid-header,
.list-grid .k-grid-footer {
    padding-inline-end: 0;
}

/* Page size selector (pour pagination dropdown) */

.page-size-selector {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.page-size-selector label {
    font-weight: 500;
}

/* Status indicators — style translucide adapté au thème sombre (texte clair, fond alpha),
   contraste ≥ 4.5:1 sur les fonds de grille du swatch dark */

.status-active {
    color: #79b8ff;
    background-color: rgba(56, 132, 255, 0.15);
    font-weight: 400;
    border: solid 1px rgba(121, 184, 255, 0.45);
    border-radius: 5px;
    padding: 1px 6px;
}

.status-inactive {
    color: #b8b8b8;
    background-color: rgba(255, 255, 255, 0.08);
    font-weight: 400;
    border: solid 1px rgba(184, 184, 184, 0.4);
    border-radius: 5px;
    padding: 1px 6px;
}

.status-success {
    color: #7ee787;
    background-color: rgba(46, 160, 67, 0.15);
    font-weight: 400;
    border: solid 1px rgba(126, 231, 135, 0.45);
    border-radius: 5px;
    padding: 1px 6px;
}

.status-error {
    color: #ff9da7;
    background-color: rgba(220, 67, 68, 0.18);
    font-weight: 400;
    border: solid 1px rgba(255, 157, 167, 0.45);
    border-radius: 5px;
    padding: 1px 6px;
}

.status-pending {
    color: #ffd66b;
    background-color: rgba(255, 196, 0, 0.14);
    font-weight: 400;
    border: solid 1px rgba(255, 214, 107, 0.45);
    border-radius: 5px;
    padding: 1px 6px;
}

/* AgentSession : rangée de session encore connectée (surlignage vert).
   Teinte translucide : fonctionne sur thème sombre (le texte garde la couleur du thème). */

.k-grid tr.row-connected > td {
    background-color: rgba(76, 175, 80, 0.18) !important;
}

.k-grid tr.row-connected > td:first-child {
    box-shadow: inset 3px 0 0 #4caf50;
}

/* AgentSession : session zombie (marquée connectée mais heartbeat mort → surlignage orange) */

.k-grid tr.row-zombie > td {
    background-color: rgba(255, 152, 0, 0.16) !important;
}

.k-grid tr.row-zombie > td:first-child {
    box-shadow: inset 3px 0 0 #ff9800;
}

/* Limiter la hauteur des lignes de la grille (gros champ texte) */

.k-grid tbody td {
    white-space: nowrap !important;
}

/* La grille ne dépasse jamais son conteneur : scroll horizontal interne (Telerik) */

.k-grid {
    max-width: 100%;
}

/* Utilitaire pour les <table> HTML natives : scroll horizontal confiné */

.table-scroll {
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

/* Style pour maintenir la row sélectionnée visible */

.k-grid tr.k-selected,
.k-grid tr.k-selected:hover {
    background-color: var(--kendo-color-primary) !important;
    color: var(--kendo-color-on-primary) !important;
}

.k-grid tr.k-selected td {
    background-color: transparent;
    color: inherit;
}

/* ========================================
   EDIT - Section panneau d'édition
   ======================================== */

.edit-panel {
    background: var(--kendo-color-surface-alt);
    border: 1px solid var(--kendo-color-border);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    height: 100%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.edit-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    border-bottom: 1px solid var(--kendo-color-border);
    background: var(--kendo-color-surface);
}

.edit-panel-header h4 {
    margin: 0;
    font-size: 1.1em;
    flex: 1;
}

/* Boutons de navigation - visibilité selon device */

.mobile-back-button {
    display: none;
}

.desktop-close-button {
    display: block;
}

.edit-panel-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    min-height: 0; /* Important pour le scroll flex */
}

.edit-panel-footer {
    height: 48px;
    display: flex;
    gap: 10px;
    border-top: 1px solid var(--kendo-color-border);
    background: var(--kendo-color-surface);
    flex-wrap: wrap;
    flex-shrink: 0; /* Empêche le footer de rétrécir */
    align-items: center;
    padding: 0 9px;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--kendo-color-subtle);
    padding: 40px 20px;
}

.empty-state p {
    font-size: 1.1em;
    line-height: 1.6;
}

/* Legacy window footer (à garder pour compatibilité) */

.window-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #ddd;
}

/* ========================================
   FENÊTRES (TelerikWindow) - Garde-fou viewport
   ======================================== */

/* Aucune fenêtre ne déborde du viewport, même avec un Width/Height inline en px
   (max-width bat le width inline émis par Telerik) */

.k-window {
    max-width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
}

.k-window-content {
    overflow: auto;
}

/* ========================================
   RESPONSIVE
   ======================================== */

/* Responsive - Mobile ET Tablettes (moins de 1024px) */

@media (max-width: 1024px) {

    /* En mode édition, cacher la grille sur mobile/tablette */

    .layout-main.editing-mode .layout-list {
        display: none;
    }

    /* Le panneau d'édition prend toute la largeur */

    .layout-main.editing-mode .layout-edit {
        flex: 1 1 100%;
        animation: slideInFromRight 0.3s ease-in-out;
    }

    @keyframes slideInFromRight {
        from {
            opacity: 0;
            transform: translateX(100%);
        }

        to {
            opacity: 1;
            transform: translateX(0);
        }
    }

    /* Afficher le bouton retour mobile, cacher le X desktop */

    .mobile-back-button {
        display: block;
        margin-right: 10px;
    }

    .desktop-close-button {
        display: none;
    }

    /* Ajuster le header du panneau d'édition */

    .edit-panel-header {
        padding: 12px 15px;
    }

    .edit-panel-header h4 {
        font-size: 1em;
    }

    /* Boutons du footer en pleine largeur sur mobile */

    .edit-panel-footer {
        flex-direction: column;
    }

    .edit-panel-footer .k-button {
        width: 100%;
    }
}

/* Responsive - Petits mobiles (moins de 640px) */

@media (max-width: 640px) {
    .layout-container {
        padding: 10px;
    }

    .layout-container h3 {
        font-size: 1.5em;
        margin-bottom: 15px;
    }

    .list-header {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    .list-header h4 {
        font-size: 1em;
    }

    .list-header .k-button {
        width: 100%;
    }

    .edit-panel-body {
        padding: 15px;
    }
}

/* Bottom AppBar — footer de monitoring */

div.appbar-bottom {
    z-index: 1;
    background-color: var(--kendo-color-surface);
    color: var(--kendo-color-subtle);
    border-top: 1px solid var(--kendo-color-border);
}

.footer-status-bar {
    display: flex;
    align-items: center;
    gap: 0;
    font-size: 0.78rem;
    padding: 0 8px;
    white-space: nowrap;
}

/* Sous mobile, la barre de statut (nowrap) dépasse le viewport : on la rend
   scrollable horizontalement plutôt que clippée, pour garder tous les services atteignables */
@media (max-width: 768px) {
    .appbar-bottom .k-appbar-section {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

.footer-service {
    color: var(--kendo-color-subtle);
}

.footer-service--down {
    color: var(--kendo-color-error);
    font-weight: 600;
}

.footer-separator {
    color: var(--kendo-color-border);
    padding: 0 6px;
}

.footer-loading {
    color: var(--kendo-color-subtle);
    font-size: 0.78rem;
}

/* ─── Grid Column Manager Dialog ─── */

.col-manager-body {
    padding: 8px 0 4px;
}

.col-manager-subtitle {
    margin: 0 0 12px;
    font-size: 0.85rem;
    color: var(--kendo-color-subtle);
}

.col-manager-select-all {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px 10px;
    border-bottom: 1px solid var(--kendo-color-border, #444);
}

.col-manager-select-all label {
    cursor: pointer;
    font-weight: 500;
    user-select: none;
}

.col-manager-list {
    max-height: 360px;
    overflow-y: auto;
    padding: 4px 0;
}

/* Chaque ligne de colonne dans la liste */
.col-manager-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 16px;
    border-radius: 4px;
    transition: background-color 0.1s;
    cursor: default;
}

.col-manager-item:hover {
    background-color: var(--kendo-color-base-hover);
}

.col-manager-item--hidden label {
    opacity: 0.5;
}

.col-manager-item--dragover {
    border-top: 2px solid var(--kendo-color-primary);
    background-color: var(--kendo-color-base-hover);
}

.col-manager-item[draggable="true"]:active {
    opacity: 0.5;
}

/* Poignée de glisser-déposer */
.col-mgr-handle {
    cursor: grab;
    color: var(--kendo-color-subtle);
    font-size: 1.1rem;
    line-height: 1;
    user-select: none;
    flex-shrink: 0;
    padding: 0 2px;
}

.col-mgr-handle:active {
    cursor: grabbing;
}

.col-manager-item label {
    cursor: pointer;
    user-select: none;
    flex: 1;
}

/* Footer du dialog */
.col-manager-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0 0;
    border-top: 1px solid var(--kendo-color-border, #444);
    margin-top: 8px;
}

.col-manager-footer-actions {
    display: flex;
    gap: 8px;
}

/* ─── Grid FilterMenu : une seule clause, pas de OR ─── */

.k-grid-filter-popup .k-filter-menu-container > :nth-child(n+3):not(.k-actions) {
    display: none !important;
}

/* ========================================
   PAGE PLEINE HAUTEUR (colonne flex)
   Le .k-drawer-content est déjà une colonne flex scrollable : ce conteneur
   propage la chaîne flex jusqu'à la grille pour qu'elle prenne la hauteur
   restante et scrolle dans son propre body.
   Pas de min-height:0 ici : si le contenu ne rentre pas (petit écran),
   le conteneur garde sa hauteur min-content et c'est le drawer qui scrolle.
   ======================================== */

.page-flex {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
}

.page-flex > .list-grid {
    min-height: 240px;
    margin-right: 0;
}

/* Barre de filtres au-dessus d'une liste */

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.hint-text {
    font-size: 0.8rem;
    color: var(--kendo-color-subtle);
}

/* ========================================
   KPI - Cartes de synthèse (« hero »)
   Une seule ligne en desktop, repli automatique en tablette/mobile.
   ======================================== */

.kpi-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.kpi-card {
    flex: 1 1 150px;
    min-width: 0;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 14px;
    border: 1px solid var(--kendo-color-border);
    border-radius: 8px;
    background-color: var(--kendo-color-surface);
    overflow: hidden;
}

/* Liseré de couleur à gauche : accent visuel discret */

.kpi-card::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 3px;
    background-color: var(--kendo-color-primary);
    opacity: 0.8;
}

.kpi-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--kendo-color-subtle);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kpi-value {
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Variante contexte (compteurs de portée) : liseré neutre */

.kpi-card--context::before {
    background-color: var(--kendo-color-border);
    opacity: 1;
}

/* Variante erreur : liseré + valeur en rouge, seulement si > 0 */

.kpi-card--error::before {
    background-color: #ff9da7;
}

.kpi-card--error .kpi-value {
    color: #ff9da7;
}

@media (max-width: 640px) {
    .kpi-card {
        flex: 1 1 40%;
        padding: 8px 12px;
    }

    .kpi-value {
        font-size: 1.25rem;
    }
}

/* Panneau autour du graphique de consommation */

.chart-card {
    border: 1px solid var(--kendo-color-border);
    border-radius: 8px;
    background-color: var(--kendo-color-surface);
    padding: 8px 12px 4px;
    margin-bottom: 12px;
}

