/* Dernière couche de l'en-tête : une ligne sur ordinateur, deux sur téléphone.
   Le conteneur tient compte du rail latéral et du zoom de l'interface. */
#app .crm-topbar-frame{container-name:crm-workspace;container-type:inline-size;position:relative;z-index:200;flex:none;width:100%;min-width:0}
body #app .mn #crm-topbar.topbar[data-layout="compact"]{
  display:flex!important;flex-wrap:nowrap!important;align-items:center!important;gap:8px!important;
  height:auto!important;min-height:62px!important;margin:0!important;padding:10px 14px!important;
  border:0!important;border-bottom:1px solid var(--glass-line)!important;border-radius:0!important;
  background:var(--glass-surface)!important;box-shadow:0 1px 0 var(--glass-edge)!important;
  position:relative!important;z-index:200;overflow:visible!important;box-sizing:border-box;
}
#crm-topbar:before{display:none!important}
body #app .mn #crm-topbar .crm-topbar-context{display:contents}
body #app .mn #crm-topbar>.sp{display:none!important}
body #app .mn #crm-topbar .mobile-nav-toggle{order:0;flex:0 0 40px;width:40px;height:40px;margin:0}
body #app .mn #crm-topbar .tb-title{order:1;flex:0 1 165px;min-width:80px;max-width:210px!important;font-size:18px!important;font-weight:650!important;line-height:1.25!important;white-space:nowrap!important;overflow:hidden;text-overflow:ellipsis;padding-left:10px!important;grid-area:auto!important}
body #app .mn #crm-topbar .v1184-agency-context{order:2;flex:0 1 135px;min-width:60px;max-width:150px;height:32px;padding:6px 10px;box-sizing:border-box;margin:0!important;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;font-size:11px;font-weight:600;display:block;grid-area:auto!important}
#crm-topbar .v1184-agency-context i{display:inline-block;margin-right:3px;width:6px;height:6px;box-shadow:none}
body #app .mn #crm-topbar .v110-search{order:3;display:block!important;flex:1 1 230px!important;min-width:100px!important;max-width:480px;width:auto!important;margin:0!important;grid-area:auto!important}
body #app .mn #crm-topbar .v110-search-box{height:38px!important;padding:0 10px;border-radius:12px;background:var(--glass-inset)}
#crm-topbar .v110-search-input{font-size:12px}
#crm-topbar .v110-search-shortcut{display:none}
body #app .mn #crm-topbar #topbar-extra{order:4;display:flex!important;flex:0 1 245px!important;min-width:145px!important;max-width:275px;width:auto!important;padding:0!important;margin-left:auto;position:static;overflow:visible!important;grid-area:auto!important}
body #app .mn #crm-topbar #topbar-extra:empty{display:none!important}
body #app .mn #crm-topbar #btn-new-mandat{order:5;flex:0 0 auto;width:auto;min-height:38px!important;height:38px;margin:0;padding:0 11px!important;white-space:nowrap;font-size:11px!important;grid-area:auto!important}
body #app .mn #crm-topbar #dsa-refresh-button{order:6;display:inline-flex;align-items:center;justify-content:center;gap:6px;flex:0 0 auto;min-height:38px;height:38px;margin:0;padding:0 10px;border:1px solid var(--glass-line);border-radius:11px;background:var(--glass-inset);color:var(--ink);font:600 11px/1.3 Inter,Arial,sans-serif;white-space:nowrap;cursor:pointer;grid-area:auto!important}
#crm-topbar #dsa-refresh-button svg{display:block;flex:none;width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
#crm-topbar #dsa-refresh-button:disabled{opacity:.55;cursor:wait}
@keyframes dsa-refresh-turn{to{transform:rotate(360deg)}}
@media(prefers-reduced-motion:no-preference){#crm-topbar #dsa-refresh-button:disabled svg{animation:dsa-refresh-turn .9s linear infinite}}
@media(hover:hover){#crm-topbar #dsa-refresh-button:not(:disabled):hover{background:var(--glass-hover)}}
body #app .mn #crm-topbar #dsa-privacy-toggle{order:7;flex:0 0 36px;width:36px!important;height:38px!important;min-height:38px!important;padding:0!important;margin:0!important;border-radius:11px;grid-area:auto!important}
body #app .mn #crm-topbar #sync-status{order:8;flex:0 0 30px;width:30px!important;min-width:30px!important;max-width:30px!important;height:30px!important;min-height:30px!important;margin:0!important;padding:0!important;justify-content:center;font-size:0!important;grid-area:auto!important}
#crm-topbar #sync-status:before{content:"●";font-size:11px;color:var(--ink3)}
#crm-topbar #sync-status[data-sync-status=ok]:before{color:var(--grn)}
#crm-topbar #sync-status:is([data-sync-status=pending],[data-sync-status=error],[data-sync-status=conflict]):before{color:var(--acc)}
#crm-topbar #sync-status:is([data-sync-status=saving],[data-sync-status=offline]):before{color:var(--amb)}
body #app .mn #crm-topbar #mobile-search-toggle{display:none!important;grid-area:auto!important}

/* Mois précédent/suivant accessibles directement, autres périodes dans le panneau. */
#crm-topbar .dsa-period-toolbar{width:100%;display:block;position:static;min-width:0}
#crm-topbar .dsa-period-switcher{display:flex;align-items:center;width:100%;min-width:0;border:1px solid var(--glass-line);border-radius:12px;background:var(--glass-surface);box-shadow:inset 0 1px 0 var(--glass-highlight)}
#crm-topbar #dsa-period-toggle{flex:1;min-width:0;width:auto;height:38px;display:flex;align-items:center;gap:6px;padding:0 8px;border:0;border-radius:12px;background:transparent;box-shadow:none;color:var(--ink);font:600 12px/1.3 Inter,Arial,sans-serif;cursor:pointer;white-space:nowrap}
#crm-topbar .dsa-period-quick{flex:0 0 30px;width:30px;height:38px;min-height:38px!important;padding:0;border:0;border-radius:10px;background:transparent;color:var(--glass-red);font:22px/1 Arial,sans-serif;cursor:pointer}
#crm-topbar #dsa-period-quick-prev{border-right:1px solid var(--glass-line)}
#crm-topbar #dsa-period-quick-next{border-left:1px solid var(--glass-line)}
#crm-topbar .dsa-period-quick:disabled{opacity:.3;cursor:default}
@media(hover:hover){#crm-topbar .dsa-period-quick:not(:disabled):hover{background:var(--glass-hover)}}
#dsa-period-toggle svg,#dsa-period-toggle i{flex:none;color:var(--glass-red)}
#dsa-period-toggle span{min-width:0;overflow:hidden;text-overflow:ellipsis;text-transform:capitalize}
#dsa-period-toggle i{font-style:normal;margin-left:auto}
#dsa-period-toggle[aria-expanded=true] i{transform:rotate(180deg)}
#crm-topbar #dsa-period-panel{position:absolute;right:12px;top:calc(100% + 6px);z-index:250;display:grid;gap:14px;width:360px;max-width:calc(100% - 24px);max-height:min(70dvh,460px);overflow-y:auto;padding:18px;box-sizing:border-box;border:1px solid var(--glass-line);border-radius:20px;background:var(--bg);box-shadow:0 18px 50px rgba(20,30,45,.17),inset 0 1px 0 var(--glass-highlight);color:var(--ink)}
#crm-topbar #dsa-period-panel[hidden]{display:none!important}
#dsa-period-panel>header{display:flex;align-items:center;justify-content:space-between;gap:12px}
#dsa-period-panel>header strong{font-size:14px;font-weight:650}
#dsa-period-panel [data-period-close]{width:36px;height:36px;border:0;border-radius:10px;background:var(--bg2);color:var(--ink);font:24px/1 Arial,sans-serif;cursor:pointer}
#crm-topbar #dsa-period-panel .dsa-period-choice{display:grid;grid-template-columns:1fr;gap:6px;width:100%;padding:0;border:0;border-radius:0;box-shadow:none;background:none;backdrop-filter:none}
#crm-topbar #dsa-period-panel .dsa-period-choice select{width:100%;height:44px;min-width:0;flex:none;font-size:16px!important;border-radius:12px}
#crm-topbar #dsa-period-panel .dsa-period-month{width:100%;height:44px;justify-content:space-between}
#crm-topbar #dsa-period-panel .dsa-period-month button{width:44px;min-height:42px;flex:none}
#crm-topbar #dsa-period-panel .dsa-period-month-label{min-width:0;flex:1;width:auto;font-size:14px}
#crm-topbar #dsa-period-panel .dsa-period-range{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:10px;width:100%;min-width:0}
#crm-topbar #dsa-period-panel .dsa-period-range label{display:grid;gap:6px;min-width:0}
#crm-topbar #dsa-period-panel .dsa-period-range input{width:100%;height:44px;min-width:0;padding:0 5px;font-size:16px!important}
#crm-topbar #dsa-period-panel :is(.dsa-period-apply,#dsa-period-error){grid-column:1/-1;height:auto;min-height:0}
#crm-topbar #dsa-period-panel .dsa-period-apply{height:44px;border-radius:12px}
#crm-topbar #dsa-period-error[hidden]{display:none!important}
#crm-topbar :is(button,select,input):focus-visible{outline:2px solid var(--glass-red);outline-offset:3px}

@container crm-workspace (max-width:1050px){
  body #app .mn #crm-topbar .tb-title{flex-basis:130px;max-width:160px!important;font-size:16px!important}
  body #app .mn #crm-topbar .v1184-agency-context{flex-basis:100px;max-width:115px;padding-inline:7px;font-size:10px}
  body #app .mn #crm-topbar #topbar-extra{flex-basis:220px!important;max-width:245px}
  body #app .mn #crm-topbar #btn-new-mandat{flex:0 0 38px;width:38px;padding:0!important;font-size:0!important}
  #crm-topbar #btn-new-mandat:after{content:"+";font-size:23px;font-weight:500}
  body #app .mn #crm-topbar #dsa-refresh-button{flex:0 0 38px;width:38px;padding:0}
  #crm-topbar #dsa-refresh-button .dsa-refresh-label{display:none}
}
@container crm-workspace (max-width:720px){
  body #app .mn #crm-topbar.topbar[data-layout="compact"]{display:grid!important;grid-template-columns:44px minmax(0,1fr) 44px 44px 44px 28px!important;grid-template-rows:none!important;gap:6px!important;padding:6px 10px!important;padding-top:max(6px,env(safe-area-inset-top))!important;min-height:56px!important}
  body #app .mn #crm-topbar .mobile-nav-toggle{grid-area:1/1!important;width:44px;height:44px}
  body #app .mn #crm-topbar .tb-title{grid-area:1/2!important;min-width:0;max-width:none!important;padding-left:0!important;font-size:15px!important}
  #crm-topbar .tb-title:before{display:none!important}
  body #app .mn #crm-topbar #mobile-search-toggle{grid-area:1/3!important;display:grid!important;place-items:center;width:44px;height:44px;padding:0;border:1px solid var(--glass-line);border-radius:12px;background:var(--glass-inset);color:var(--ink);font:26px Arial,sans-serif;cursor:pointer}
  body #app .mn #crm-topbar #dsa-refresh-button{grid-area:1/4!important;width:44px;height:44px;min-height:44px;padding:0}
  #crm-topbar #dsa-refresh-button .dsa-refresh-label{display:none}
  body #app .mn #crm-topbar #dsa-privacy-toggle{grid-area:1/5!important;width:44px!important;height:44px!important;min-height:44px!important}
  body #app .mn #crm-topbar #sync-status{grid-area:1/6!important;min-width:28px!important;width:28px!important;max-width:28px!important}
  body #app .mn #crm-topbar .crm-topbar-context{display:flex;align-items:center;gap:8px;grid-area:2/1/3/-1;width:100%;min-width:0}
  body #app .mn #crm-topbar .v1184-agency-context{flex:0 1 110px;max-width:130px;min-width:55px;height:30px;font-size:10px}
  body #app .mn #crm-topbar #topbar-extra{flex:1 1 160px!important;min-width:0!important;max-width:none;width:auto!important;margin-left:auto}
  body #app .mn #crm-topbar #btn-new-mandat{height:44px;min-height:44px!important;flex-basis:38px;font-size:0!important;padding:0!important}
  #crm-topbar #dsa-period-toggle{height:44px;padding:0 4px;gap:4px}
  #crm-topbar .dsa-period-quick{flex-basis:44px;width:44px;height:44px;min-height:44px!important}
  #crm-topbar .dsa-period-switcher[data-period-mode=month] #dsa-period-toggle svg{display:none}
  body #app .mn #crm-topbar .v110-search{display:none!important;grid-area:3/1/4/-1!important;width:100%!important;max-width:none;min-width:0!important}
  body #app .mn #crm-topbar.mobile-search-open .v110-search{display:block!important}
  body #app .mn #crm-topbar .v110-search-box{height:44px!important}
  #crm-topbar .v110-search-input{font-size:16px!important}
  #crm-topbar .v110-search-results{position:absolute!important;left:0!important;right:0!important;top:calc(100% + 6px)!important;width:100%!important;max-height:50dvh!important}
  #crm-topbar #dsa-period-panel{right:10px;max-width:calc(100% - 20px);padding:14px;gap:12px;border-radius:16px}
}
@media(forced-colors:active){#crm-topbar #dsa-period-panel,#crm-topbar .dsa-period-switcher,#crm-topbar .dsa-period-quick{border-color:ButtonText;box-shadow:none}#crm-topbar #sync-status:before{color:CanvasText}}

/* Repli téléphone, également sans prise en charge des container queries. */
@media(max-width:680px){
  body #app .mn #crm-topbar.topbar[data-layout="compact"]{display:grid!important;grid-template-columns:44px minmax(0,1fr) 44px 44px 44px 28px!important;grid-template-rows:none!important;gap:6px!important;padding:6px 10px!important;padding-top:max(6px,env(safe-area-inset-top))!important;min-height:56px!important}
  body #app .mn #crm-topbar .mobile-nav-toggle{grid-area:1/1!important;width:44px;height:44px}
  body #app .mn #crm-topbar .tb-title{grid-area:1/2!important;min-width:0;max-width:none!important;padding-left:0!important;font-size:15px!important}
  #crm-topbar .tb-title:before{display:none!important}
  body #app .mn #crm-topbar #mobile-search-toggle{grid-area:1/3!important;display:grid!important;place-items:center;width:44px;height:44px;padding:0;border:1px solid var(--glass-line);border-radius:12px;background:var(--glass-inset);color:var(--ink);font:26px Arial,sans-serif;cursor:pointer}
  body #app .mn #crm-topbar #dsa-refresh-button{grid-area:1/4!important;width:44px;height:44px;min-height:44px;padding:0}
  #crm-topbar #dsa-refresh-button .dsa-refresh-label{display:none}
  body #app .mn #crm-topbar #dsa-privacy-toggle{grid-area:1/5!important;width:44px!important;height:44px!important;min-height:44px!important}
  body #app .mn #crm-topbar #sync-status{grid-area:1/6!important;min-width:28px!important;width:28px!important;max-width:28px!important}
  body #app .mn #crm-topbar .crm-topbar-context{display:flex;align-items:center;gap:8px;grid-area:2/1/3/-1;width:100%;min-width:0}
  body #app .mn #crm-topbar .v1184-agency-context{flex:0 1 110px;max-width:130px;min-width:55px;height:30px;font-size:10px}
  body #app .mn #crm-topbar #topbar-extra{flex:1 1 160px!important;min-width:0!important;max-width:none;width:auto!important;margin-left:auto}
  body #app .mn #crm-topbar #btn-new-mandat{height:44px;min-height:44px!important;flex-basis:38px;font-size:0!important;padding:0!important}
  #crm-topbar #dsa-period-toggle{height:44px;padding:0 4px;gap:4px}
  #crm-topbar .dsa-period-quick{flex-basis:44px;width:44px;height:44px;min-height:44px!important}
  #crm-topbar .dsa-period-switcher[data-period-mode=month] #dsa-period-toggle svg{display:none}
  body #app .mn #crm-topbar .v110-search{display:none!important;grid-area:3/1/4/-1!important;width:100%!important;max-width:none;min-width:0!important}
  body #app .mn #crm-topbar.mobile-search-open .v110-search{display:block!important}
  body #app .mn #crm-topbar .v110-search-box{height:44px!important}
  #crm-topbar .v110-search-input{font-size:16px!important}
  #crm-topbar .v110-search-results{position:absolute!important;left:0!important;right:0!important;top:calc(100% + 6px)!important;width:100%!important;max-height:50dvh!important}
  #crm-topbar #dsa-period-panel{right:10px;max-width:calc(100% - 20px);padding:14px;gap:12px;border-radius:16px}
}
@media(min-width:1181px){@container crm-workspace (max-width:720px){body #app .mn #crm-topbar .tb-title{grid-area:1/1/2/3!important}}}

#crm-topbar #sync-status:is([data-sync-status=error],[data-sync-status=conflict]):before{content:"!";font-weight:800}
#crm-topbar #sync-status:is([data-sync-status=pending],[data-sync-status=saving]):before{content:"↻";font-size:15px}

@media(max-width:680px){#crm-topbar #btn-new-mandat:after{content:"+";font-size:23px;font-weight:500}}

/* Keep the controls clear of the system UI in portrait and landscape. */
@media (max-width: 1180px) {
  #app.v1125-transform-zoom {
    top: var(--crm-visible-top, 0px) !important;
  }

  body #app .mn #crm-topbar.topbar[data-layout="compact"] {
    padding-top: calc(env(safe-area-inset-top, 0px) + 8px) !important;
    padding-left: calc(env(safe-area-inset-left, 0px) + 10px) !important;
    padding-right: calc(env(safe-area-inset-right, 0px) + 10px) !important;
  }

  #app > .sb .mobile-nav-close {
    margin-top: calc(env(safe-area-inset-top, 0px) + 8px);
  }
}

/* Sur téléphone, la zone au-dessus du premier bouton appartient au cadre
   de l'application. Sa hauteur est comprise dans celle du viewport visible. */
@media (max-width: 720px), (pointer: coarse) and (max-width: 1180px) and (max-height: 540px) {
  body {
    --crm-phone-gap: 24px;
    --crm-phone-clearance: calc(env(safe-area-inset-top, 0px) + var(--crm-phone-gap));
    --crm-phone-header: var(--bg);
  }
  body.dark { --crm-phone-header: var(--bg2); }

  body #app {
    box-sizing: border-box;
    border-top: var(--crm-phone-clearance) solid var(--crm-phone-header);
  }
  body #app .mn #crm-topbar.topbar[data-layout="compact"] {
    padding-top: 8px !important;
    background: var(--crm-phone-header) !important;
    box-shadow: none !important;
    --glass-surface: var(--crm-phone-header);
    --glass-inset: var(--bg2);
  }
  body #app .crm-topbar-frame,
  body #app .mn #crm-topbar.topbar[data-layout="compact"],
  body #app #crm-topbar :is(button, input, .v110-search-box, .dsa-period-choice, .dsa-period-month) {
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
  }
  body #app > .sb {
    top: var(--crm-visible-top, 0px) !important;
    height: var(--dsa-mobile-height, 100dvh) !important;
  }
  body #app > .sb .mobile-nav-close {
    margin-top: calc(var(--crm-phone-clearance) + 8px);
  }
  body:not(.mobile-nav-open) #app > .mobile-nav-scrim { visibility: hidden; }
}
@media (orientation: landscape) and (pointer: coarse) and (max-width: 1180px) and (max-height: 540px) {
  body { --crm-phone-gap: 8px; }
}
