/* Marketing (MKT), Pierre & Sol : style commun aux applications Analyse des ventes et Sync. */
:root {
  --navy: #1F4E79;
  --navy-dark: #173B5C;
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --ink: #1F2933;
  --muted: #5F6B7A;
  --line: #CFD6DE;
  --line-soft: #E4E8ED;
  --th: #F7F8FA;
  --total: #EEF2F6;
  --quote: #E8EEF4;
  --ok: #2E7D4F;
  --ok-soft: #E3F1E8;
  --warn: #B7791F;
  --warn-soft: #FDF1DA;
  --err: #B42318;
  --err-soft: #FDE4E1;
  --orange: #F28C1E;
  --s0: #1F4E79; --s1: #4F7CA8; --s2: #8FB3D6; --s3: #F28C1E; --s4: #6B7C8F; --s5: #2E7D4F;
  --font: system-ui, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 14px/1.45 var(--font); font-variant-numeric: tabular-nums; }
a { color: var(--navy); }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }
h1 { font-size: 20px; font-weight: 700; margin: 0 0 .35rem; }
h2 { font-size: 15px; font-weight: 700; margin: 0 0 .6rem; }
h3 { font-size: 13.5px; font-weight: 700; margin: 1rem 0 .4rem; }
code { background: var(--line-soft); padding: 1px 5px; border-radius: 3px; font-size: .9em; word-break: break-all; }
.muted { color: var(--muted); }
.small, small { font-size: 12.5px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* En-tête (identique Analyse / Sync) */
.top { display: flex; align-items: center; gap: 20px; background: var(--navy); color: #fff; padding: 8px 20px; min-height: 56px; position: sticky; top: 0; z-index: 30; }
.logo { display: flex; align-items: center; gap: 12px; text-decoration: none; flex: none; }
.logo img { height: 40px; width: auto; background: #fff; padding: 3px 5px; border-radius: 6px; display: block; }
.brand { color: #fff; font-size: 15px; font-weight: 700; line-height: 1.2; }
.brand span { display: block; font-size: 11px; font-weight: 400; letter-spacing: .66px; }
.top nav { display: flex; gap: 2px 16px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.top nav::-webkit-scrollbar { display: none; }
.top nav a { color: #fff; text-decoration: none; padding: 6px 2px; border-bottom: 2px solid transparent; white-space: nowrap; }
.top nav a:hover { border-bottom-color: rgba(255,255,255,.5); }
.top nav a.on { font-weight: 600; border-bottom-color: #fff; }
.um { position: relative; flex: none; }
.um summary { list-style: none; cursor: pointer; color: #fff; font-size: 13.5px; padding: 5px 10px; border: 1px solid rgba(255,255,255,.55); border-radius: 5px; white-space: nowrap; }
.um summary::-webkit-details-marker { display: none; }
.um summary:hover { background: rgba(255,255,255,.1); }
.um-panel { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: 6px; min-width: 200px; padding: 6px; box-shadow: 0 8px 24px rgba(31,41,51,.18); }
.um-role { display: block; padding: 4px 10px 6px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line-soft); margin-bottom: 4px; }
.um-panel a, .um-panel button { display: block; width: 100%; text-align: left; padding: 7px 10px; color: var(--ink); text-decoration: none; background: none; border: 0; font: inherit; border-radius: 4px; cursor: pointer; }
.um-panel a:hover, .um-panel button:hover { background: var(--bg); }
.um-panel form { border-top: 1px solid var(--line-soft); margin-top: 4px; padding-top: 4px; }
.quote { background: var(--quote); color: #334E68; text-align: center; font-size: 12.5px; padding: 6px 20px; border-bottom: 1px solid var(--line-soft); }

/* Page */
.page { padding: 18px 20px 40px; max-width: 1600px; margin: 0 auto; }
.page-title { margin-bottom: 12px; }
.page-title p { margin: 0; max-width: 90ch; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 14px; }
.panel { background: var(--surface); border: 1px solid var(--line-soft); border-radius: 6px; padding: 14px 16px; margin-bottom: 14px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.panel-head h2 { margin: 0; }
.cols-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); gap: 14px; margin-bottom: 14px; }
.cols-2 > .panel { margin-bottom: 0; }
.empty { color: var(--muted); font-style: italic; margin: 6px 0; }
.more { display: inline-block; margin-top: 8px; font-size: 13px; }

/* Messages */
.flash { padding: 9px 12px; border-radius: 4px; margin-bottom: 10px; border: 1px solid #B7DCC4; background: var(--ok-soft); }
.flash-err { border-color: #F4B9B2; background: var(--err-soft); }
.flash-warn { border-color: #F2D59A; background: var(--warn-soft); }
.alerts { display: grid; gap: 6px; margin-bottom: 14px; }
.alert { display: block; padding: 8px 12px; border-radius: 4px; text-decoration: none; color: var(--ink); border: 1px solid; }
.alert-erreur { background: var(--err-soft); border-color: #F4B9B2; }
.alert-attention { background: var(--warn-soft); border-color: #F2D59A; }
.alert-info { background: #EEF2F6; border-color: var(--line); }
.src-status { margin: 4px 0; font-size: 12.5px; padding-left: 14px; position: relative; color: var(--muted); }
.src-status::before { content: ""; position: absolute; left: 0; top: .45em; width: 8px; height: 8px; border-radius: 50%; background: #A9B4C0; }
.src-status.ok::before { background: var(--ok); }
.src-status.warn::before { background: var(--warn); }
.src-status.err::before { background: var(--err); }

/* Bandeau des ventes J-1 */
.hero-sales { display: grid; grid-template-columns: minmax(220px, 1fr) 2fr; gap: 18px; background: var(--surface); border: 1px solid var(--line-soft); border-radius: 6px; padding: 16px; margin-bottom: 14px; }
.hero-figure { display: flex; flex-direction: column; justify-content: center; }
.hero-label { color: var(--muted); font-size: 13px; }
.hero-value { font-size: 30px; font-weight: 700; color: var(--navy); margin: 2px 0; }
.hero-value small { font-size: 13px; font-weight: 600; color: var(--muted); }
.hero-sub { color: var(--muted); font-size: 13px; }
.strata { display: flex; flex-direction: column; justify-content: center; gap: 4px; min-height: 120px; }
.stratum { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 10px; color: #fff; min-height: 30px; width: var(--w); min-width: fit-content; border-radius: 4px; font-size: 13px; }
.stratum-name { font-weight: 600; white-space: nowrap; }
.stratum-val { white-space: nowrap; }
.stratum.s0 { background: var(--s0); } .stratum.s1 { background: var(--s1); } .stratum.s2 { background: var(--s2); color: var(--ink); }
.stratum.s3 { background: var(--s3); } .stratum.s4 { background: var(--s4); } .stratum.s5 { background: var(--s5); }

/* Indicateurs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line-soft); border-radius: 6px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 19px; font-weight: 700; color: var(--ink); }
.kpi-note { font-size: 11.5px; color: var(--muted); }
.delta { font-size: 12px; font-weight: 600; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--err); }

/* Barre de période (boutons Jour / Semaine… comme Analyse) */
.period { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center; margin-bottom: 14px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.chip, .btn { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; font: 400 13px var(--font); color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 4px; text-decoration: none; cursor: pointer; line-height: 1.35; }
.chip:hover, .btn:hover { border-color: var(--navy); }
.chip.on, .btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy-dark); color: #fff; }
.btn[disabled] { opacity: .6; cursor: progress; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 7px 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px; }
.tabs a[aria-current="page"] { color: var(--navy); font-weight: 600; border-bottom-color: var(--navy); }

/* Formulaires */
input, select, textarea { font: 13px var(--font); color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; max-width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--navy); outline: none; box-shadow: 0 0 0 3px rgba(31,78,121,.15); }
textarea { width: 100%; resize: vertical; }
label { display: inline-flex; align-items: center; gap: 6px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { flex-direction: column; align-items: stretch; gap: 3px; font-weight: 600; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px 16px; align-items: start; }
.form-grid h2 { margin: 8px 0 0; }
.form-grid .wide, .form-grid fieldset, .form-grid h2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; align-items: stretch; gap: 3px; }
.field > span { font-weight: 600; font-size: 13px; }
.field small { color: var(--muted); }
fieldset { border: 1px solid var(--line-soft); border-radius: 6px; padding: 10px 12px 12px; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px 16px; }
legend { font-weight: 700; padding: 0 4px; }
.check { display: inline-flex; align-items: center; gap: 6px; }
.link { background: none; border: 0; color: var(--navy); cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }
.link.danger { color: var(--err); }
.row { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin: 6px 0; }
.inline { display: inline; }
.tag { display: inline-block; font-size: 11px; font-style: normal; font-weight: 600; padding: 1px 6px; border-radius: 3px; background: var(--line-soft); color: var(--muted); vertical-align: middle; }
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.inline-filter input { min-width: 240px; }

/* Tableaux (en-têtes et totaux figés, comme Analyse) */
.table-wrap { overflow: auto; max-height: 72vh; background: #fff; border: 1px solid var(--line-soft); border-radius: 6px; }
.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px; background: #fff; }
.grid th, .grid td { padding: 6px 8px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; }
.grid thead th { position: sticky; top: 0; background: var(--th); z-index: 2; font-weight: 600; white-space: nowrap; padding-right: 20px; }
.grid thead tr.totals th { top: 31px; background: var(--total); font-weight: 700; z-index: 2; border-bottom: 1px solid var(--line); }
.grid .num { text-align: right; white-space: nowrap; }
.grid tbody tr:hover td { background: #F5F8FB; }
.grid .sort { background: none; border: 0; font: inherit; color: inherit; cursor: pointer; padding: 0; }
.grid .sort::after { content: " ⇅"; color: #A9B4C0; font-size: 10px; }
.grid th[aria-sort="descending"] .sort::after { content: " ▾"; color: var(--navy); }
.grid th[aria-sort="ascending"] .sort::after { content: " ▴"; color: var(--navy); }
.grid td { max-width: 460px; overflow-wrap: anywhere; }
.grid td a { color: var(--navy); }

/* Divers */
.chart-box { position: relative; height: 280px; }
.ai-note .prose { max-width: 90ch; }
.prose h4 { margin: 12px 0 4px; font-size: 14px; }
.prose p, .prose ul { margin: 4px 0 8px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.examples { display: flex; flex-wrap: wrap; gap: 6px; }
.qa { border-top: 1px solid var(--line-soft); padding: 8px 0; }
.qa summary { cursor: pointer; display: flex; justify-content: space-between; gap: 12px; font-weight: 600; }
.qa summary small { color: var(--muted); font-weight: 400; white-space: nowrap; }
.jobs { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 10px; }
.job { border: 1px solid var(--line-soft); border-radius: 6px; padding: 10px 12px; }
.job.off { background: #F9FAFB; }
.job h3 { margin: 0 0 4px; }
.src-list { list-style: none; padding: 0; margin: 0; }
.src-list li { padding: 7px 0; border-bottom: 1px solid var(--line-soft); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.edit-user summary { cursor: pointer; color: var(--navy); }
.edit-user form { margin-top: 8px; }
.checks { list-style: none; padding: 0; font-size: 13px; }
.checks .ok { color: var(--ok); } .checks .ko { color: var(--err); font-weight: 600; }

/* Connexion et installation */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; background: var(--bg); }
.login { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line-soft); border-top: 4px solid var(--navy); border-radius: 6px; padding: 22px; }
.login.wide-login { max-width: 560px; }
.login-head { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; }
.login-logo { height: 46px; width: auto; }
.login-head h1 { margin: 0; color: var(--navy); }
.login-head p { margin: 0; color: var(--muted); font-size: 11px; letter-spacing: .66px; }

@media (max-width: 900px) {
  .top { flex-wrap: wrap; padding: 8px 12px; }
  .top nav { order: 3; flex-basis: 100%; margin-left: 0; }
  .um { margin-left: auto; }
  .hero-sales, .cols-2 { grid-template-columns: 1fr; }
  .page { padding: 12px 10px 30px; }
  .stratum { width: 100%; }
}
.howto { font-size: 12.5px; background: #F7F8FA; border: 1px solid var(--line-soft); border-radius: 4px; padding: 6px 10px; }
.howto summary { cursor: pointer; color: var(--navy); font-weight: 600; }
.howto ol { margin: 6px 0 2px; padding-left: 20px; }
.howto li { margin: 3px 0; }

/* Boutons de période par encart */
.panel-head .chips { display: flex; flex-wrap: wrap; gap: 4px; }
.panel-head .chips .chip { padding: 3px 9px; font-size: 12px; }
.panel-period { margin: -4px 0 8px; font-size: 12px; color: var(--muted); }

/* Colonnes déplaçables et redimensionnables */
.table-tools { display: flex; justify-content: flex-end; padding: 2px 6px; background: #fff; }
.grid thead tr:first-child th { cursor: grab; position: sticky; }
.grid thead tr:first-child th.drag-over { box-shadow: inset 3px 0 0 var(--orange); }
.grid thead tr:first-child th.dragging { opacity: .5; }
.col-resizer { position: absolute; top: 0; right: 0; width: 7px; height: 100%; cursor: col-resize; z-index: 3; }
.col-resizer:hover, .col-resizer.active { background: rgba(31,78,121,.25); }
.grid.sized { table-layout: fixed; }
.grid.sized td, .grid.sized th { overflow: hidden; text-overflow: ellipsis; }

/* Calendrier */
.legend { display: inline-flex; flex-wrap: wrap; gap: 4px 12px; margin-left: auto; font-size: 12px; }
.lg::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; background: var(--c); margin-right: 5px; vertical-align: -1px; }
.year-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; user-select: none; }
.month h3 { margin: 0 0 4px; font-size: 13px; color: var(--navy); }
.mgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.mgrid .wd { font-size: 10px; color: var(--muted); text-align: center; }
.mgrid .day { font-size: 11.5px; text-align: center; padding: 4px 0; border-radius: 3px; background: #F7F8FA; }
.mgrid .day.empty { background: none; }
.year-grid[data-editable] .day:not(.empty) { cursor: pointer; }
.year-grid[data-editable] .day:not(.empty):hover { outline: 2px solid var(--navy); }
.mgrid .day.has-ev { color: #fff; font-weight: 700; text-shadow: 0 0 2px rgba(0,0,0,.35); }
.mgrid .day.today { outline: 2px solid var(--orange); }
.mgrid .day.sel { outline: 2px dashed var(--navy); background: var(--quote); color: var(--ink); }
.timeline { font-size: 12.5px; }
.tl-months { display: grid; grid-template-columns: repeat(12, 1fr); margin-left: 40%; color: var(--muted); font-size: 11px; border-bottom: 1px solid var(--line-soft); }
.tl-row { display: grid; grid-template-columns: 40% 60%; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--line-soft); }
.tl-row:target { background: var(--quote); }
.tl-label { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; padding-right: 10px; }
.tl-dates { color: var(--muted); white-space: nowrap; }
.tl-track { position: relative; height: 14px; background: repeating-linear-gradient(90deg, #F7F8FA 0 calc(100%/12 - 1px), var(--line-soft) calc(100%/12 - 1px) calc(100%/12)); border-radius: 3px; }
.tl-bar { position: absolute; top: 2px; height: 10px; border-radius: 3px; min-width: 4px; }
.ev-dialog { border: 1px solid var(--line); border-radius: 8px; padding: 18px; max-width: 620px; width: 95%; }
.ev-dialog::backdrop { background: rgba(31,41,51,.35); }
.ev-banner { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: -6px 0 14px; font-size: 12px; }
.ev-banner-label { color: var(--muted); }
.ev-pill { border-left: 4px solid var(--c); background: #fff; border-radius: 3px; padding: 2px 8px; text-decoration: none; color: var(--ink); border-top: 1px solid var(--line-soft); border-right: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
@media (max-width: 900px) { .tl-row { grid-template-columns: 1fr; } .tl-months { margin-left: 0; } }

/* Santé du site */
.hero-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 14px; margin-bottom: 14px; align-items: stretch; }
.hero-row .hero-sales { margin-bottom: 0; }
.health-card { background: #fff; border: 1px solid var(--line-soft); border-left: 6px solid #A9B4C0; border-radius: 6px; padding: 12px 14px; height: 100%; }
.health-card.hc-vert { border-left-color: var(--ok); }
.health-card.hc-orange { border-left-color: var(--warn); }
.health-card.hc-rouge { border-left-color: var(--err); background: #FFF8F7; }
.hc-head { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); margin-bottom: 8px; }
.hc-dot { width: 12px; height: 12px; border-radius: 50%; background: #A9B4C0; flex: none; }
.hc-vert .hc-dot { background: var(--ok); } .hc-orange .hc-dot { background: var(--warn); } .hc-rouge .hc-dot { background: var(--err); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.hc-at { margin-left: auto; color: var(--muted); font-size: 12px; }
.hc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.hc-grid span { display: block; font-size: 11.5px; color: var(--muted); }
.hc-grid b { font-size: 15px; }
.hc-reasons { margin: 8px 0 0; padding-left: 18px; font-size: 12px; color: var(--err); }
@media (max-width: 900px) { .hero-row { grid-template-columns: 1fr; } }

/* Tableaux compacts : titres sur 2 lignes, colonnes chiffrées étroites, libellés lisibles */
.grid thead tr:first-child th { white-space: normal; vertical-align: bottom; line-height: 1.2; padding-right: 14px; }
.grid thead tr:first-child th.num { max-width: 7.5em; min-width: 4.5em; }
.grid thead tr:first-child th.txt { min-width: 9em; }
.grid th .sort { text-align: inherit; line-height: 1.2; }
.grid th.num .sort { text-align: right; }
.grid .sort::after { font-size: 9px; }
.grid td { max-width: 22em; }
.grid td a { word-break: normal; overflow-wrap: break-word; hyphens: auto; }
@media (max-width: 1400px) {
  .grid { font-size: 12px; }
  .grid th, .grid td { padding: 4px 6px; }
  .grid thead tr:first-child th { padding-right: 12px; }
  .grid thead tr.totals th { top: 40px; }
}

/* Titres de colonnes : alignés en haut et centrés */
.grid thead tr:first-child th, .grid thead tr:first-child th.num, .grid thead tr:first-child th.txt { vertical-align: top; text-align: center; }
.grid thead tr:first-child th .sort, .grid th.num .sort { text-align: center; width: 100%; }
.hero-margin { display: block; margin-top: 6px; font-size: 13.5px; }
.hero-margin small { display: block; font-size: 12px; }

/* Produits tendance */
.trend-list { margin: 0; padding-left: 26px; display: grid; gap: 8px; }
.trend-list li { padding: 8px 10px; border: 1px solid var(--line-soft); border-radius: 6px; background: #FBFCFD; }
.trend-list li::marker { font-weight: 700; color: var(--navy); }
.trend-main { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; }
.trend-name { font-weight: 700; font-size: 14px; }
.trend-signal { font-size: 13px; }
.trend-stock { font-size: 12.5px; margin-left: auto; }
.trend-corr { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.trend-corr .up { color: var(--ok); } .trend-corr .down { color: var(--err); }
.trend-flags { margin-top: 3px; font-size: 11.5px; color: var(--warn); }
