/* -------------------------------------------------------------------------
   Portail client PosValis — feuille de style unique, mobile first.
   ------------------------------------------------------------------------- */

:root {
  --bg:        #f4f6fb;
  --surface:   #ffffff;
  --ink:       #0f172a;
  --ink-soft:  #475569;
  --muted:     #94a3b8;
  --line:      #e2e8f0;
  --brand:     #1d4ed8;
  --brand-dk:  #1e3a8a;
  --brand-lt:  #dbeafe;
  --up:        #047857;
  --down:      #b91c1c;
  --radius:    14px;
  --shadow:    0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --nav-w:     236px;
  --topbar-h:  60px;
  color-scheme: light;
}



* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--brand); }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.02rem; }

.skip {
  position: absolute; left: -9999px;
  background: var(--brand); color: #fff; padding: .6rem 1rem; z-index: 100;
}
.skip:focus { left: .5rem; top: .5rem; }

/* ------------------------------------------------------------------ topbar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: .75rem;
  height: var(--topbar-h);
  padding: 0 .9rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.burger {
  display: grid; place-items: center;
  width: 40px; height: 40px; flex: none;
  border: 1px solid var(--line); border-radius: 10px;
  background: transparent; color: var(--ink); cursor: pointer;
}
.burger svg { width: 20px; height: 20px; }

.brand { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.brand-mark {
  display: grid; place-items: center;
  width: 34px; height: 34px; flex: none;
  border-radius: 9px;
  background: var(--brand); color: #fff;
  font-weight: 700; font-size: .8rem; letter-spacing: .04em;
}
.brand-txt { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.brand-txt strong { font-size: .93rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-txt small { color: var(--muted); font-size: .76rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.who { display: none; color: var(--ink-soft); font-size: .86rem; }
@media (min-width: 560px) { .who { display: inline; } }

.btn-icon {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  border: 1px solid var(--line); border-radius: 10px;
  color: var(--ink-soft); text-decoration: none;
}
.btn-icon svg { width: 18px; height: 18px; }
.btn-icon:hover { background: var(--brand-lt); color: var(--brand); }

/* --------------------------------------------------------------- structure */
.shell { display: flex; align-items: flex-start; }

.nav {
  position: fixed; inset: var(--topbar-h) auto 0 0; z-index: 39;
  width: var(--nav-w);
  display: flex; flex-direction: column; gap: .15rem;
  padding: .9rem .7rem;
  background: var(--surface);
  border-right: 1px solid var(--line);
  transform: translateX(-100%);
  transition: transform .2s ease;
  overflow-y: auto;
}
.nav.is-open { transform: none; box-shadow: var(--shadow); }

.nav-link {
  display: flex; align-items: center; gap: .65rem;
  padding: .62rem .7rem;
  border-radius: 10px;
  color: var(--ink-soft); text-decoration: none; font-weight: 500;
}
.nav-link svg { width: 18px; height: 18px; flex: none; }
.nav-link:hover { background: var(--bg); color: var(--ink); }
.nav-link.is-active { background: var(--brand-lt); color: var(--brand-dk); font-weight: 600; }

.nav-foot { margin-top: auto; padding: .8rem .7rem 0; border-top: 1px solid var(--line); }
.nav-foot p { margin: 0; font-size: .78rem; line-height: 1.45; }

.main {
  flex: 1; min-width: 0;
  padding: 1rem .9rem 2.5rem;
}

.page-head { margin-bottom: .9rem; }
.page-sub { margin: .2rem 0 0; color: var(--muted); font-size: .87rem; }

/* ----------------------------------------------------------------- filtres */
.filters {
  display: flex; flex-wrap: wrap; gap: .6rem;
  padding: .75rem;
  margin-bottom: 1.1rem;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.field { display: flex; flex-direction: column; gap: .25rem; flex: 1 1 160px; min-width: 0; }
.field label { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }
.field.is-hidden { display: none; }

select, input[type="date"], input[type="text"], input[type="password"], input[type="search"] {
  width: 100%;
  padding: .5rem .6rem;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg); color: var(--ink);
  font: inherit; font-size: .9rem;
}
select:focus, input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem .95rem;
  border: 1px solid transparent; border-radius: 9px;
  background: var(--brand); color: #fff;
  font: inherit; font-weight: 600; font-size: .9rem;
  text-decoration: none; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn-ghost:hover { background: var(--bg); color: var(--ink); filter: none; }
.btn-block { width: 100%; }

/* -------------------------------------------------------------------- KPIs */
.kpis {
  display: grid; gap: .7rem;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  margin-bottom: 1.1rem;
}
.kpi {
  display: flex; flex-direction: column; gap: .2rem;
  padding: .85rem .9rem;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kpi-label { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; }
/* Les montants sont affichés en entier : la taille s'adapte aux valeurs longues. */
.kpi-value {
  font-size: clamp(1.1rem, 4.6vw, 1.45rem);
  font-weight: 680; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.kpi-value-long { font-size: clamp(.95rem, 3.6vw, 1.2rem); }
.kpi-hint, .kpi-var { font-size: .79rem; color: var(--muted); }
.kpi-var.up { color: var(--up); }
.kpi-var.down { color: var(--down); }

/* ------------------------------------------------------------------ cartes */
.grid { display: grid; gap: .9rem; grid-template-columns: 1fr; margin-bottom: .9rem; }
.grid-2 { grid-template-columns: 1fr; }

.card {
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: .95rem;
  min-width: 0;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: .6rem; margin-bottom: .8rem; }
.card-head .muted { font-size: .8rem; }
.muted { color: var(--muted); }

.chart-wrap { position: relative; height: 260px; }
.chart-wrap.tall { height: 320px; }

.empty {
  margin: 0; padding: 1.6rem .8rem;
  text-align: center; color: var(--muted); font-size: .9rem;
}

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .89rem; }
th, td { padding: .55rem .6rem; text-align: left; white-space: nowrap; }
th {
  position: sticky; top: 0;
  background: var(--surface);
  color: var(--muted); font-weight: 600; font-size: .76rem;
  text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 1px solid var(--line);
}
td { border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--bg); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 650; border-top: 2px solid var(--line); border-bottom: 0; }

/* Barre de proportion dans les tableaux de classement. */
.bar { position: relative; display: block; height: 6px; border-radius: 3px; background: var(--brand-lt); min-width: 4px; }
.bar > i { position: absolute; inset: 0; width: var(--w, 0%); background: var(--brand); border-radius: 3px; }

.badge {
  display: inline-block; padding: .12rem .45rem;
  border-radius: 999px; background: var(--brand-lt); color: var(--brand-dk);
  font-size: .74rem; font-weight: 600;
}

/* ------------------------------------------------- administration comptes */
.btn-sm { padding: .32rem .6rem; font-size: .8rem; }
.btn-danger { color: var(--down); border-color: color-mix(in srgb, var(--down) 35%, var(--line)); }
.btn-danger:hover { background: color-mix(in srgb, var(--down) 12%, transparent); color: var(--down); }

form.inline { display: inline-flex; gap: .35rem; }
td.actions { white-space: nowrap; }
td.actions > * { vertical-align: middle; }

/* Deuxième ligne d'information dans une cellule (nom, périmètre…). */
.sous { display: block; color: var(--muted); font-size: .78rem; font-weight: 400; }

.badge-ok  { background: color-mix(in srgb, var(--up) 18%, transparent); color: var(--up); }
.badge-off { background: color-mix(in srgb, var(--down) 15%, transparent); color: var(--down); }

.alert-ok {
  background: color-mix(in srgb, var(--up) 15%, transparent);
  color: var(--up);
}

.form-grid {
  display: grid; gap: .9rem;
  grid-template-columns: 1fr;
}
.form-grid .field { flex: none; }
.form-grid .field-wide { grid-column: 1 / -1; }
.form-grid fieldset { margin: 0; padding: .8rem; border: 1px solid var(--line); border-radius: 10px; }
.form-grid legend { padding: 0 .35rem; color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }

.check { display: flex; align-items: center; gap: .45rem; font-size: .9rem; padding: .2rem 0; }
.check input { width: auto; accent-color: var(--brand); }
.check-list {
  display: grid; gap: .1rem .9rem;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  max-height: 230px; overflow-y: auto;
}
.check.is-hidden { display: none; }

@media (min-width: 700px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
}

/* --------------------------------------------------------------- en direct */
.live { border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); }
.live .card-head h2 { display: flex; align-items: center; gap: .5rem; }

.live-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--up);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--up) 70%, transparent);
  animation: pulse 2.4s ease-out infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--up) 65%, transparent); }
  70%  { box-shadow: 0 0 0 9px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.live-total {
  margin: 0;
  font-size: clamp(2.2rem, 9vw, 3.4rem);
  font-weight: 700; letter-spacing: -.03em; line-height: 1.05;
  font-variant-numeric: tabular-nums;
  transition: color .5s ease;
}
.live-total-sm { font-size: clamp(1.6rem, 6vw, 2.2rem); }
.live-sous { margin: .25rem 0 0; color: var(--muted); font-size: .85rem; }

/* Passage au vert le temps de l'animation quand le montant progresse. */
.live-total.is-up, .live-val.is-up { color: var(--up); }

.live-rank { list-style: none; margin: 1rem 0 0; padding: 0; }
.live-row {
  display: grid; align-items: center; gap: .1rem .6rem;
  grid-template-columns: 1.6rem 1fr auto;
  padding: .5rem 0;
  border-top: 1px solid var(--line);
  transition: transform .45s cubic-bezier(.2, .7, .3, 1);
}
.live-row:first-child { border-top: 0; }
.live-pos {
  grid-row: span 2;
  display: grid; place-items: center;
  width: 1.6rem; height: 1.6rem;
  border-radius: 50%;
  background: var(--bg); color: var(--muted);
  font-size: .75rem; font-weight: 700;
}
.live-row:first-child .live-pos { background: var(--brand-lt); color: var(--brand-dk); }
.live-nom { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.live-val { font-variant-numeric: tabular-nums; font-weight: 650; transition: color .5s ease; }
.live-row .bar { grid-column: 2 / -1; margin-top: .2rem; }

@media (prefers-reduced-motion: reduce) {
  .live-dot { animation: none; }
  .live-row { transition: none; }
}

/* ------------------------------------------------------------------- login */
.login-page {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 1.2rem;
  background: linear-gradient(160deg, var(--brand-dk), var(--bg) 55%);
}
.login-card {
  width: 100%; max-width: 380px;
  padding: 1.6rem 1.4rem;
  background: var(--surface);
  border-radius: 18px; box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
}
.login-card .brand-mark { width: 46px; height: 46px; font-size: 1rem; margin-bottom: .9rem; }
.login-card h1 { font-size: 1.25rem; }
.login-card p.sub { margin: .3rem 0 1.3rem; color: var(--muted); font-size: .88rem; }
.login-card label { display: block; margin: 0 0 .25rem; font-size: .8rem; color: var(--ink-soft); font-weight: 500; }
.login-card .field { margin-bottom: .9rem; flex: none; }
.alert {
  margin: 0 0 1rem; padding: .6rem .75rem;
  border-radius: 9px;
  background: #fee2e2; color: #991b1b;
  font-size: .87rem;
}
@media (prefers-color-scheme: dark) { .alert { background: #3f1d1d; color: #fca5a5; } }

/* -------------------------------------------------------------------- pied */
.foot {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 1rem .9rem;
  border-top: 1px solid var(--line);
  color: var(--muted); font-size: .78rem;
}

/* ---------------------------------------------------------------- tablette */
@media (min-width: 700px) {
  .main { padding: 1.4rem 1.4rem 3rem; }
  h1 { font-size: 1.6rem; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .chart-wrap { height: 300px; }
}

/* ------------------------------------------------------------------ bureau */
@media (min-width: 1024px) {
  .burger { display: none; }
  .nav { transform: none; box-shadow: none; }
  .main { margin-left: var(--nav-w); }
  .foot { margin-left: var(--nav-w); }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}

/* ------------------------------------------------- relevé CA + TVA + encaissements */
table.dense { font-size: .82rem; }
table.dense th, table.dense td { padding: .34rem .5rem; }
table.dense tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--bg) 55%, transparent); }
/* Trait de séparation avant chaque groupe de colonnes (taux, encaissements). */
table.dense .sep { border-left: 1px solid var(--line); }
.table-releve { max-height: 70vh; overflow: auto; }
.table-releve thead th { position: sticky; top: 0; z-index: 2; }
.table-releve tfoot td { position: sticky; bottom: 0; background: var(--surface); }

.actions-head { display: flex; flex-wrap: wrap; gap: .4rem; }
.print-only { display: none; }

@media print {
  .topbar, .nav, .filters, .foot, .burger, .actions-head, .skip { display: none !important; }
  .main { margin: 0; padding: 0; }
  .card { break-inside: auto; box-shadow: none; border: 0; padding: 0; }
  .print-only { display: block; margin-bottom: .6rem; }
  .print-only h2 { font-size: 1.05rem; }
  .print-only p { margin: .15rem 0 0; font-size: .8rem; }

  /* Le relevé doit s'imprimer en entier, sans zone de défilement. */
  .table-releve { max-height: none; overflow: visible; }
  table.dense { font-size: 7.4pt; width: 100%; }
  table.dense th, table.dense td { padding: .12rem .22rem; }
  thead { display: table-header-group; }          /* en-têtes répétés à chaque page */
  tr { break-inside: avoid; }
  .page-sub, h1 { color: #000; }
}

@page { size: A4 landscape; margin: 10mm; }

/* ------------------------------------------------------------ edition prix */
.table-prix-wrap { max-height: 72vh; overflow: auto; }
.table-prix { min-width: 760px; }
.table-prix thead th { position: sticky; top: 0; z-index: 2; }
.table-prix thead th:first-child,
.table-prix tbody td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
}

.price-input {
  width: 88px;
  min-width: 88px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  padding: .38rem .48rem;
}

@media (max-width: 700px) {
  .price-input {
    width: 78px;
    min-width: 78px;
  }
}
