/* DBM Core v1.3 — Design System
   Charte : bleu marine DBM, bleu technologique, surfaces claires.
   Conçu d'abord pour mobile, puis tablette et desktop.
*/
:root{
  --dbm-navy-950:#071a3c;
  --dbm-navy-900:#0b2554;
  --dbm-navy-800:#123468;
  --dbm-blue-600:#1769aa;
  --dbm-blue-500:#2463ff;
  --dbm-blue-100:#eaf1ff;
  --dbm-bg:#f4f7fb;
  --dbm-surface:#ffffff;
  --dbm-surface-soft:#f8fafd;
  --dbm-border:#dce5f1;
  --dbm-text:#13213a;
  --dbm-muted:#65728a;
  --dbm-success:#148044;
  --dbm-danger:#b42336;
  --dbm-warning:#8a5a00;
  --dbm-radius-sm:8px;
  --dbm-radius-md:12px;
  --dbm-radius-lg:16px;
  --dbm-shadow-sm:0 6px 18px rgba(10,35,78,.06);
  --dbm-shadow-md:0 14px 34px rgba(10,35,78,.10);
  --dbm-sidebar-width:264px;
  --dbm-content-max:1600px;
}

html{
  width:100%;
  min-width:0;
  max-width:100%;
  overflow-x:hidden;
  scroll-behavior:smooth;
}

body.dbm-body{
  width:100%;
  min-width:0;
  max-width:100%;
  min-height:100vh;
  margin:0;
  overflow-x:hidden;
  background:var(--dbm-bg);
  color:var(--dbm-text);
  font-family:Inter, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
}

/* Neutralise le centrage réservé aux pages de connexion dès qu'une interface CRM existe. */
body.dbm-body:has(.crm-shell),
body.dbm-body:has(.ged-app){
  display:block;
  place-items:initial;
}

img,svg,video,canvas,iframe{
  max-width:100%;
}

button,input,select,textarea{
  max-width:100%;
}

button,a,input,select,textarea{
  -webkit-tap-highlight-color:transparent;
}

:focus-visible{
  outline:3px solid rgba(36,99,255,.32);
  outline-offset:2px;
}

.dbm-skip-link{
  position:fixed;
  top:8px;
  left:8px;
  z-index:5000;
  transform:translateY(-150%);
  padding:10px 14px;
  border-radius:8px;
  background:#fff;
  color:var(--dbm-navy-900);
  font-weight:800;
  box-shadow:var(--dbm-shadow-md);
}
.dbm-skip-link:focus{transform:none}

/* Socle général */
.crm-shell,.ged-app{
  width:100%;
  min-width:0;
  max-width:100%;
}

.crm-main,.ged-main{
  min-width:0;
  max-width:100%;
}

.crm-main{
  width:100%;
  padding:clamp(18px,2.4vw,36px);
}

.crm-main > *{
  max-width:var(--dbm-content-max);
  margin-left:auto;
  margin-right:auto;
}

.crm-sidebar{
  background:
    radial-gradient(circle at 20% 0%,rgba(36,99,255,.18),transparent 34%),
    linear-gradient(180deg,var(--dbm-navy-900),var(--dbm-navy-950));
  box-shadow:8px 0 30px rgba(7,26,60,.08);
}

.crm-brand{
  letter-spacing:-.025em;
}

.crm-brand strong{
  font-size:1.55rem;
}

.crm-nav a{
  min-width:0;
  transition:background-color .18s ease,color .18s ease,transform .18s ease;
}

.crm-nav a:hover{
  transform:translateX(2px);
}

.crm-header{
  width:100%;
  min-width:0;
}

.crm-header h1{
  font-size:clamp(1.85rem,3vw,2.65rem);
  line-height:1.12;
  letter-spacing:-.035em;
}

/* Bouton mobile injecté par dbm-ui.js */
.dbm-mobile-bar{
  display:none;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  width:100%;
  margin:0 0 18px;
  padding:10px 12px;
  border:1px solid var(--dbm-border);
  border-radius:12px;
  background:rgba(255,255,255,.94);
  box-shadow:var(--dbm-shadow-sm);
  backdrop-filter:blur(10px);
}

.dbm-mobile-brand{
  min-width:0;
  color:var(--dbm-navy-900);
  font-weight:900;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

.dbm-menu-toggle{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  min-height:42px;
  padding:9px 12px;
  border:0;
  border-radius:9px;
  background:var(--dbm-navy-900);
  color:#fff;
  font:inherit;
  font-weight:800;
  cursor:pointer;
}

.dbm-menu-toggle-lines{
  position:relative;
  width:18px;
  height:14px;
}
.dbm-menu-toggle-lines::before,
.dbm-menu-toggle-lines::after,
.dbm-menu-toggle-lines{
  border-top:2px solid currentColor;
}
.dbm-menu-toggle-lines::before,
.dbm-menu-toggle-lines::after{
  content:"";
  position:absolute;
  left:0;
  width:18px;
}
.dbm-menu-toggle-lines::before{top:4px}
.dbm-menu-toggle-lines::after{top:10px}

.dbm-mobile-overlay{
  position:fixed;
  inset:0;
  z-index:1090;
  background:rgba(5,18,44,.55);
  backdrop-filter:blur(2px);
}

/* Composants communs */
.panel,.metric-card,.directory-card,.sales-card,
.pipeline-summary article,.request-stat,.kpi-grid article,
.ged-toolbar,.ged-content,.ged-stats article{
  border-color:var(--dbm-border);
  box-shadow:var(--dbm-shadow-sm);
}

.panel,.metric-card,.directory-card,.sales-card,
.pipeline-summary article,.kpi-grid article{
  border-radius:var(--dbm-radius-md);
}

.primary-link,.action-button,.ged-primary-btn{
  background:linear-gradient(135deg,var(--dbm-blue-500),var(--dbm-blue-600));
  color:#fff;
  box-shadow:0 8px 18px rgba(36,99,255,.16);
}

.primary-link,.secondary-link,.action-button,
.ged-primary-btn,.ged-secondary-btn,button{
  min-height:42px;
  align-items:center;
  justify-content:center;
}

.primary-link:hover,.action-button:hover,.ged-primary-btn:hover{
  filter:brightness(.96);
  transform:translateY(-1px);
}

input,select,textarea{
  min-height:43px;
}

textarea{
  min-height:110px;
  resize:vertical;
}

.table-wrap,.contact-table-wrap{
  width:100%;
  max-width:100%;
  overflow-x:auto;
  -webkit-overflow-scrolling:touch;
  border-radius:12px;
}

table{
  max-width:100%;
}

.flash,.ged-alert{
  border:1px solid transparent;
}

.flash.success,.ged-alert.success{
  border-color:#b9e8ca;
}

.flash.error,.ged-alert.error{
  border-color:#ffc8d0;
}

/* Responsive : tablette et mobile */
@media (max-width: 900px){
  .crm-shell{
    display:block;
  }

  .crm-sidebar{
    position:fixed;
    inset:0 auto 0 0;
    z-index:1100;
    width:min(86vw,320px);
    height:100dvh;
    padding:22px 16px;
    overflow-y:auto;
    transform:translateX(-105%);
    transition:transform .24s ease;
    box-shadow:18px 0 45px rgba(4,17,41,.26);
  }

  body.dbm-sidebar-open{
    overflow:hidden;
  }

  body.dbm-sidebar-open .crm-sidebar{
    transform:translateX(0);
  }

  .crm-nav{
    display:grid;
    grid-template-columns:1fr;
  }

  .crm-nav a{
    text-align:left;
    white-space:normal;
  }

  .dbm-mobile-bar{
    display:flex;
    position:sticky;
    top:8px;
    z-index:100;
  }

  .crm-main{
    padding:16px;
  }

  .crm-header{
    flex-direction:column;
    gap:12px;
  }

  .header-meta{
    width:100%;
    text-align:left;
  }

  .header-actions{
    width:100%;
    flex-wrap:wrap;
  }

  .header-actions > *{
    flex:1 1 180px;
    white-space:normal;
  }

  .directory-filters,.pipeline-filters,.filter-form{
    grid-template-columns:repeat(2,minmax(0,1fr));
  }

  .directory-grid,.sales-grid,.ged-grid{
    grid-template-columns:repeat(2,minmax(0,1fr));
  }

  .company-detail-grid,.request-detail-grid,.lead-edit-grid{
    grid-template-columns:1fr;
  }
}

@media (max-width: 640px){
  .crm-main{
    padding:12px;
  }

  .crm-header h1{
    font-size:1.8rem;
  }

  .metric-grid,.pipeline-summary,.request-stats,
  .kpi-grid,.ged-stats{
    grid-template-columns:1fr;
  }

  .directory-grid,.sales-grid,.ged-grid,
  .directory-filters,.pipeline-filters,.filter-form,
  .form-grid,.detail-list,.request-meta,
  .ged-form-grid,.quote-item-row{
    grid-template-columns:1fr;
  }

  .dashboard-grid,.dash-grid{
    grid-template-columns:1fr;
  }

  .panel,.metric-card,.directory-card,.sales-card,
  .pipeline-summary article,.kpi-grid article,
  .ged-content,.ged-toolbar{
    padding:16px;
  }

  .header-actions{
    flex-direction:column;
  }

  .header-actions > *{
    width:100%;
    flex-basis:auto;
  }

  .status-form,.quick-actions,.ged-actions,.document-actions{
    flex-direction:column;
    align-items:stretch;
  }

  .status-form > *,.quick-actions > *,.ged-actions > *,
  .document-actions > *{
    width:100%;
  }

  .ged-toolbar,.ged-topbar{
    flex-direction:column;
    align-items:stretch;
  }

  .ged-search{
    min-width:0;
    width:100%;
  }

  .ged-filters{
    display:grid;
    grid-template-columns:repeat(2,minmax(0,1fr));
    width:100%;
  }

  .ged-filters button{
    width:100%;
  }

  .quote-totals{
    width:100%;
    justify-content:stretch;
  }

  .quote-totals div{
    min-width:0;
    width:100%;
  }
}

@media (max-width: 380px){
  .crm-main{padding:9px}
  .dbm-mobile-bar{padding:8px}
  .dbm-mobile-brand{font-size:.92rem}
  .crm-header h1{font-size:1.55rem}
  .ged-filters{grid-template-columns:1fr}
}

/* Réduction des animations pour l'accessibilité */
@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{
    scroll-behavior:auto!important;
    transition:none!important;
    animation:none!important;
  }
}
