/* =============================================================================
   MAFY : thème visuel global (shinydashboard / AdminLTE 2)
   ============================================================================= */
:root {
  --mafy-navy:    #08306b;
  --mafy-blue:    #1f78b4;
  --mafy-sky:     #4fc3f7;
  --mafy-green:   #00875a;
  --mafy-bg:      #f2f5f9;
  --mafy-sidebar: #0f1c2e;
  --mafy-text:    #2b3a4a;
  --mafy-muted:   #7a8a9c;
  --mafy-radius:  12px;
  --mafy-shadow:  0 2px 10px rgba(15, 28, 46, .08);
  --mafy-shadow-h:0 8px 24px rgba(15, 28, 46, .16);
}

body, h1, h2, h3, h4, h5, h6, .main-header .logo {
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif !important;
}
body { color: var(--mafy-text); }
.content-wrapper, .right-side { background: var(--mafy-bg) !important; }

/* ----------------------------------------------------------- En-tête fixe -- */
.main-header { position: fixed !important; top: 0; left: 0; right: 0; z-index: 1030; }
.main-header .navbar, .main-header .logo {
  background: linear-gradient(90deg, var(--mafy-navy), var(--mafy-blue)) !important;
  border: none !important;
}
.main-header .logo { font-weight: 700; letter-spacing: 1px; font-size: 20px; }
.main-header .logo .fa, .main-header .logo .fas { color: var(--mafy-sky); margin-right: 6px; }
.main-header .navbar .sidebar-toggle:hover { background: rgba(255,255,255,.12) !important; }
.content-wrapper, .right-side { padding-top: 50px; }

.mafy-header-filtres {
  display: inline-flex; gap: 8px; align-items: center; height: 50px; padding: 0 16px;
  color: #fff; font-size: 13px;
}
.mafy-chip {
  background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.25);
  border-radius: 20px; padding: 4px 12px; white-space: nowrap;
}
.mafy-chip.warn { background: #d9534f; border-color: #d9534f; }
@media (max-width: 900px) { .mafy-header-filtres .mafy-chip.opt { display: none; } }

/* ------------------------------------------------------------ Barre latérale -- */
.main-sidebar {
  position: fixed !important; top: 0; left: 0; height: 100vh; overflow-y: auto;
  padding-top: 50px !important; background: var(--mafy-sidebar) !important;
}
.main-sidebar::-webkit-scrollbar { width: 6px; }
.main-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }

.sidebar-menu > li > a { margin: 2px 8px; border-radius: 8px; transition: background .2s; }
.sidebar-menu > li.active > a, .sidebar-menu > li > a:hover {
  background: rgba(79,195,247,.12) !important; border-left: 3px solid var(--mafy-sky) !important;
}
.sidebar-menu .treeview-menu { background: transparent !important; }
.sidebar-menu .treeview-menu > li > a { border-radius: 6px; margin: 1px 8px 1px 16px; padding: 6px 10px; }
.sidebar-menu .treeview-menu > li.active > a,
.sidebar-menu .treeview-menu > li > a:hover { color: #fff !important; background: rgba(255,255,255,.07); }
.sidebar-menu .treeview-menu > li.active > a { color: var(--mafy-sky) !important; font-weight: 600; }

.mafy-filtres { padding: 6px 14px 20px 14px; color: #cfd8e3; }
.mafy-filtre-titre {
  text-transform: uppercase; font-size: 11px; letter-spacing: 1.2px; color: var(--mafy-muted);
  margin: 18px 0 8px 0; font-weight: 700;
}
.mafy-filtre-titre .fa, .mafy-filtre-titre .fas { margin-right: 6px; color: var(--mafy-sky); }
.mafy-filtres .form-group, .mafy-filtres .shiny-input-container { margin: 0 !important; padding: 0 !important; width: 100% !important; }
.mafy-filtres .input-daterange input {
  background: rgba(255,255,255,.08); color: #fff; border: 1px solid rgba(255,255,255,.15);
  border-radius: 6px !important; height: 32px; font-size: 13px;
}
.mafy-filtres .input-daterange .input-group-addon {
  background: transparent; border: none; color: var(--mafy-muted);
}

/* Raccourcis de période */
.mafy-raccourcis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-top: 8px; }
.mafy-raccourcis .btn {
  margin: 0 !important; width: 100%; padding: 3px 0; font-size: 12px; border-radius: 14px;
  background: rgba(255,255,255,.06); color: #cfd8e3; border: 1px solid rgba(255,255,255,.15);
  transition: all .2s;
}
.mafy-raccourcis .btn:hover, .mafy-raccourcis .btn.actif {
  background: var(--mafy-sky); color: var(--mafy-navy); border-color: var(--mafy-sky);
}

/* Interrupteurs des sites */
.site-toggle .checkbox { margin: 6px 0; }
.site-toggle .checkbox label { padding-left: 0; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.site-toggle input[type=checkbox] {
  -webkit-appearance: none; appearance: none; position: relative; margin: 0;
  width: 36px; height: 20px; border-radius: 20px; background: rgba(255,255,255,.18);
  transition: background .25s; cursor: pointer; flex-shrink: 0;
}
.site-toggle input[type=checkbox]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; transition: transform .25s;
}
.site-toggle input[type=checkbox]:checked { background: var(--mafy-green); }
.site-toggle input[type=checkbox]:checked::after { transform: translateX(16px); }
.site-toggle input[type=checkbox]:focus { outline: 2px solid var(--mafy-sky); outline-offset: 2px; }

/* Type de période : boutons segmentés */
.mafy-segment .shiny-options-group { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mafy-segment .radio { margin: 0 !important; }
.mafy-segment .radio label {
  display: block; padding: 6px 4px !important; text-align: center; border-radius: 8px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.15);
  font-size: 12px; cursor: pointer; transition: all .2s;
}
.mafy-segment .radio input { display: none; }
.mafy-segment .radio label:has(input:checked) {
  background: var(--mafy-sky); color: var(--mafy-navy); font-weight: 700; border-color: var(--mafy-sky);
}
.mafy-segment .radio label:hover { border-color: var(--mafy-sky); }

.mafy-maj {
  margin-top: 22px; padding: 10px; border-radius: 8px; font-size: 11.5px; line-height: 1.6;
  background: rgba(255,255,255,.05); color: var(--mafy-muted);
}
.mafy-maj b { color: #cfd8e3; }

/* --------------------------------------------------------------------- Boîtes -- */
.box {
  border-radius: var(--mafy-radius) !important; border-top: none !important;
  box-shadow: var(--mafy-shadow) !important; transition: box-shadow .25s, transform .25s;
  overflow: hidden;
}
.box:hover { box-shadow: var(--mafy-shadow-h) !important; }
.box > .box-header { padding: 12px 15px; }
.box.box-solid > .box-header .box-title, .box > .box-header .box-title { font-size: 15px; font-weight: 600; }
.box.box-solid.box-primary > .box-header { background: linear-gradient(90deg, var(--mafy-navy), var(--mafy-blue)) !important; }
.box.box-solid.box-success > .box-header { background: linear-gradient(90deg, #006d2c, #31a354) !important; }
.box.box-solid.box-info    > .box-header { background: linear-gradient(90deg, #4a2c7a, #7b52b9) !important; }
.box.box-solid.box-warning > .box-header { background: linear-gradient(90deg, #d97706, #f5a623) !important; }
.box.box-solid.box-danger  > .box-header { background: linear-gradient(90deg, #a61b1b, #e04848) !important; }
.box.box-solid { border: none !important; }
.box-header .btn-box-tool { color: rgba(255,255,255,.85) !important; }

/* Badge « Référence de l'indicateur » : plus discret */
.box span[style*="#d9534f"] {
  background: #eef3fa !important; color: var(--mafy-navy) !important;
  border: 1px solid #d3e0ef; border-radius: 20px !important;
  font-weight: 600 !important; font-size: 11px !important; padding: 3px 10px !important;
}
.box span[style*="#d9534f"]::before { content: "\f02b"; font-family: "Font Awesome 6 Free", "Font Awesome 5 Free"; font-weight: 900; margin-right: 5px; }

/* Plein écran */
.mafy-btn-plein { background: transparent; border: none; color: rgba(255,255,255,.85); padding: 0 6px; font-size: 13px; }
.box:not(.box-solid) .mafy-btn-plein { color: var(--mafy-muted); }
.mafy-btn-plein:hover { color: #fff; }
.box.mafy-plein-ecran {
  position: fixed !important; top: 64px; left: 14px; right: 14px; bottom: 14px; z-index: 1040;
  width: auto !important; height: auto !important;
  margin: 0 !important; overflow: auto; animation: mafy-zoom .25s ease;
}
.box.mafy-plein-ecran .plotly.html-widget,
.box.mafy-plein-ecran .shiny-plot-output { height: calc(100vh - 190px) !important; }
body.mafy-voile::after {
  content: ""; position: fixed; inset: 0; background: rgba(15,28,46,.55); z-index: 1035;
}

/* -------------------------------------------------------------- Value boxes -- */
.small-box {
  border-radius: var(--mafy-radius) !important; box-shadow: var(--mafy-shadow);
  transition: transform .25s, box-shadow .25s; overflow: hidden;
}
.small-box:hover { transform: translateY(-4px); box-shadow: var(--mafy-shadow-h); }
.small-box h3 { font-size: 30px !important; font-weight: 700 !important; letter-spacing: .5px; }
.small-box p  { font-size: 13px !important; opacity: .92; }
.small-box .icon-large { opacity: .22; transition: transform .3s, opacity .3s; font-size: 60px !important; }
.small-box:hover .icon-large { transform: scale(1.12) rotate(-6deg); opacity: .35; }

.small-box.bg-blue       { background: linear-gradient(135deg, #08306b, #1f78b4) !important; }
.small-box.bg-light-blue { background: linear-gradient(135deg, #1f78b4, #4fa3d8) !important; }
.small-box.bg-aqua       { background: linear-gradient(135deg, #0891b2, #22c3e6) !important; }
.small-box.bg-green      { background: linear-gradient(135deg, #006d2c, #31a354) !important; }
.small-box.bg-olive      { background: linear-gradient(135deg, #3d7a4f, #6aa77a) !important; }
.small-box.bg-purple     { background: linear-gradient(135deg, #4a2c7a, #7b52b9) !important; }
.small-box.bg-red        { background: linear-gradient(135deg, #a61b1b, #e04848) !important; }
.small-box.bg-yellow     { background: linear-gradient(135deg, #d97706, #f5a623) !important; }
.small-box.bg-fuchsia    { background: linear-gradient(135deg, #a3135f, #e0478f) !important; }
.small-box.bg-black      { background: linear-gradient(135deg, #1f2937, #475569) !important; }
.small-box.bg-gray       { background: linear-gradient(135deg, #64748b, #94a3b8) !important; color: #fff !important; }
.small-box.bg-white      { background: #fff !important; color: var(--mafy-text) !important; border-left: 4px solid var(--mafy-blue); }
.small-box.bg-white .icon-large { color: var(--mafy-blue); }

/* -------------------------------------------------- Animations & chargement -- */
.tab-pane.active { animation: mafy-fondu .45s ease; }
@keyframes mafy-fondu { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes mafy-zoom  { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes mafy-tourne { to { transform: rotate(360deg); } }
@keyframes mafy-barre  { 0% { left: -35%; width: 35%; } 100% { left: 100%; width: 35%; } }

.recalculating { opacity: .35 !important; transition: opacity .25s; }
.html-widget-output.recalculating, .shiny-plot-output.recalculating, .shiny-html-output.recalculating { position: relative; }
.html-widget-output.recalculating::after, .shiny-plot-output.recalculating::after {
  content: ""; position: absolute; top: 50%; left: 50%; width: 34px; height: 34px; margin: -17px 0 0 -17px;
  border: 4px solid #d3e0ef; border-top-color: var(--mafy-blue); border-radius: 50%;
  animation: mafy-tourne .8s linear infinite; z-index: 5;
}

#mafy-chargement {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 2000; overflow: hidden;
  opacity: 0; transition: opacity .3s; pointer-events: none;
}
#mafy-chargement.actif { opacity: 1; }
#mafy-chargement::before {
  content: ""; position: absolute; top: 0; height: 100%; background: var(--mafy-sky);
  box-shadow: 0 0 8px var(--mafy-sky); animation: mafy-barre 1.1s ease-in-out infinite;
}

/* ------------------------------------------------------------ Tableaux DT -- */
table.dataTable thead th { background: #eef3fa; color: var(--mafy-navy); border-bottom: 2px solid #d3e0ef !important; }
table.dataTable tbody tr:hover { background: #f5f9ff !important; }
.dataTables_wrapper .dataTables_filter input { border-radius: 16px; border: 1px solid #d3e0ef; padding: 3px 10px; }
.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--mafy-blue) !important; color: #fff !important; border: none !important; border-radius: 6px;
}

/* -------------------------------------------------------------- Divers -- */
.btn-default.shiny-download-link, .btn.shiny-download-link {
  background: var(--mafy-green); color: #fff; border: none; border-radius: 20px; padding: 6px 16px;
  transition: filter .2s;
}
.btn.shiny-download-link:hover { filter: brightness(1.1); color: #fff; }
.shiny-notification { border-radius: 10px; box-shadow: var(--mafy-shadow-h); border-left: 4px solid var(--mafy-blue); }
.shiny-notification-warning { border-left-color: #f5a623; }
.shiny-output-error-validation { color: var(--mafy-muted); font-style: italic; padding: 40px 10px; text-align: center; }
