:root {
  --bg: #f3f5f2;
  --card: #fff;
  --ink: #00153d;
  --muted: #5a6478;
  --faint: #8a93a3;
  --accent: #55a51c;
  --accent-dark: #3f7e14;
  --navy: #00153d;
  --line: #e1e6df;
  --line-soft: #eef2eb;
  --airtel: #e40613;
  --vodacom: #b8000b;
  --orange: #f26b00;
  --africell: #5b2a9e;
  --inconnu: #8a918d;
  --danger: #a61b1b;
  --in: #3f7e14;
  --out: #b4400d;
  --deposit: #1d5fa3;
  --withdrawal: #8a4b08;
  --cash: #4b5a52;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 21, 61, 0.05);
  --pad: clamp(12px, 3vw, 24px);
  --content: 1100px;
  --touch: 44px;
  --top-z: 40;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  padding-left: var(--safe-l);
  padding-right: var(--safe-r);
}
img, svg, video { max-width: 100%; height: auto; }
button, input, select, textarea { font: inherit; max-width: 100%; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
strong, b, .amt, .balance-amount, td, .hbar-val, .metric b { font-variant-numeric: tabular-nums; }

/* ---------- Connexion ---------- */
.auth-body {
  display: grid;
  place-items: center;
  padding: max(16px, var(--safe-t)) var(--pad) max(24px, var(--safe-b));
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(900px 380px at 8% -10%, rgba(85, 165, 28, 0.12), transparent 55%),
    radial-gradient(700px 320px at 100% 0%, rgba(0, 21, 61, 0.06), transparent 50%),
    #f3f5f2;
}
.auth-body .auth-card {
  background: #fff;
}
.auth-body .brand-auth .sub { color: var(--muted); }
.brand-auth {
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}
.brand-wordmark {
  width: min(260px, 100%);
  height: auto;
  display: block;
}
.auth-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  padding: clamp(20px, 4vw, 28px);
  box-shadow: var(--shadow);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand img {
  display: block;
  border-radius: 10px;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  object-fit: cover;
}
.brand > div { min-width: 0; }
.brand h1 { margin: 0; }
.brand .sub {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auth-card .brand { margin-bottom: 4px; }
.auth-card .brand img { width: 56px; height: 56px; }
.auth-card h1 { margin: 0; color: var(--accent); font-size: clamp(1.2rem, 4vw, 1.35rem); }
.auth-tabs { display: flex; gap: 8px; margin-top: 16px; }
.auth-tabs .ghost { flex: 1; min-height: var(--touch); }
.shop-fields { margin: 14px 0; }
.shop-fields-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.shop-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  align-items: center;
}
.shop-row input { flex: 1; min-width: 0; }
.shop-row .shop-remove {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
}
.okmsg { color: var(--accent); min-height: 1.2em; }
.auth-card label { display: grid; gap: 6px; margin: 14px 0; font-size: 0.88rem; color: var(--muted); }
.auth-card input, .toolbar input, .toolbar select, .panel input,
.panel select, .filters input, .filters select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 12px;
  font: inherit;
  background: #fff;
  min-height: var(--touch);
  color: var(--ink);
}
.auth-card input:focus, .toolbar input:focus, .toolbar select:focus,
.panel input:focus, .filters input:focus, .filters select:focus {
  outline: 2px solid rgba(10, 92, 67, 0.25);
  outline-offset: 1px;
  border-color: #8fb5a5;
}

/* ---------- Boutons ---------- */
.auth-card button, button {
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 14px;
  font: inherit;
  font-size: 0.92rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  min-height: var(--touch);
}
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.ghost { background: #fff; color: var(--ink); border-color: var(--line); }
button.ghost:hover { border-color: #c9cecb; background: #fafafa; }
button.ghost.active { background: var(--ink); border-color: var(--ink); color: #fff; }
button.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.accent:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
button.danger { background: #fff; color: var(--danger); border-color: var(--line); }
.sub { color: var(--muted); margin: 4px 0 0; font-size: 0.88rem; }
.err { color: var(--danger); min-height: 1.2em; }

/* ---------- En-tête sticky (style app = aperçu) ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: var(--top-z);
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: calc(12px + var(--safe-t)) max(var(--pad), calc((100% - var(--content)) / 2)) 0;
  box-shadow: none;
}
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.top .brand {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.brand-wordmark-header {
  display: block;
  height: 42px;
  width: auto;
  max-width: min(220px, 58vw);
  object-fit: contain;
}
.top .brand .sub { margin: 0; font-size: 0.8rem; }
.top .brand h1 { margin: 0; font-size: 1.15rem; color: var(--accent); letter-spacing: -0.01em; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.card.kpi.deposit { border-left: 3px solid var(--accent); }
.card.kpi.withdrawal { border-left: 3px solid var(--out); }

.menu-toggle {
  display: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.menu-toggle-bars,
.menu-toggle-bars::before,
.menu-toggle-bars::after {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--ink);
  border-radius: 1px;
  position: relative;
}
.menu-toggle-bars::before,
.menu-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
}
.menu-toggle-bars::before { top: -6px; }
.menu-toggle-bars::after { top: 6px; }
body.drawer-open .menu-toggle-bars { background: transparent; }
body.drawer-open .menu-toggle-bars::before { top: 0; transform: rotate(45deg); }
body.drawer-open .menu-toggle-bars::after { top: 0; transform: rotate(-45deg); }

.nav-tabs {
  display: none;
  margin-top: 8px;
  gap: 0;
  border-top: 1px solid var(--line-soft);
}
.nav-wrap {
  position: relative;
  margin-top: 10px;
}
.nav-wrap::before,
.nav-wrap::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 2px;
  width: 28px;
  pointer-events: none;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.15s;
}
.nav-wrap::before {
  left: 0;
  background: linear-gradient(90deg, #fff, transparent);
}
.nav-wrap::after {
  right: 0;
  background: linear-gradient(270deg, #fff, transparent);
}
.nav-wrap.can-left::before,
.nav-wrap.can-right::after { opacity: 1; }
.nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 0;
}
.nav::-webkit-scrollbar { display: none; }
.nav button, .nav button.ghost, .nav button.danger,
.nav-tabs button, .nav-tabs button.ghost {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  padding: 12px 12px;
  white-space: nowrap;
  scroll-snap-align: start;
  min-height: var(--touch);
  flex: 0 0 auto;
}
.nav button:hover, .nav-tabs button:hover { color: var(--ink); }
.nav button.ghost.active,
.nav-tabs button.ghost.active {
  background: none;
  color: var(--ink);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.nav .nav-short, .nav-tabs .nav-short { display: none; }
.nav #logout {
  margin-left: auto;
  color: var(--danger);
  position: sticky;
  right: 0;
  background: linear-gradient(90deg, transparent, #fff 28%);
  padding-left: 18px;
}

/* Menu latéral mobile */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--top-z) + 1);
  background: rgba(27, 31, 29, 0.4);
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: calc(var(--top-z) + 2);
  width: min(300px, 86vw);
  height: 100%;
  height: 100dvh;
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08);
  padding: calc(12px + var(--safe-t)) 0 calc(20px + var(--safe-b));
  display: flex;
  flex-direction: column;
  transform: translateX(0);
}
.drawer[hidden], .drawer-backdrop[hidden] { display: none !important; }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 16px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.drawer-head .ghost {
  min-width: 40px;
  min-height: 40px;
  padding: 0;
}
.drawer-nav {
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 2px;
  overflow-y: auto;
}
.drawer-nav button {
  width: 100%;
  text-align: left;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  padding: 14px 14px;
  min-height: 48px;
  font-size: 1rem;
}
.drawer-nav button.ghost.active {
  background: #eef7f2;
  color: var(--accent);
  border: none;
  font-weight: 600;
}
.drawer-nav button.danger {
  margin-top: 8px;
  color: var(--danger);
  border-top: 1px solid var(--line-soft);
  border-radius: 0;
}

.welcome-banner {
  margin-bottom: 14px;
  border-color: #0b6e4f !important;
  position: relative;
  padding-right: 44px;
}
.welcome-banner .welcome-close {
  position: absolute;
  top: 8px;
  right: 8px;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
}
.toolbar #periodSelect {
  width: auto;
  min-width: min(180px, 100%);
  flex: 1 1 160px;
}

main {
  max-width: var(--content);
  margin: 0 auto;
  padding: 14px var(--pad) calc(40px + var(--safe-b));
  width: 100%;
}
.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 4px 0 14px;
  align-items: center;
}
.toolbar select {
  width: auto;
  min-width: min(220px, 100%);
  margin-right: 2px;
  flex: 1 1 180px;
}
.toolbar .period {
  padding: 8px 12px;
  font-size: 0.88rem;
  flex: 0 1 auto;
}
#periodLabel { color: var(--muted); font-size: 0.86rem; margin-left: 4px; }

/* ---------- Cartes ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr));
  gap: 10px;
}
.card, .op, .panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card span { color: var(--muted); font-size: 0.8rem; }
.card strong {
  display: block;
  font-size: clamp(1.1rem, 2.5vw, 1.3rem);
  font-weight: 600;
  margin-top: 6px;
  letter-spacing: -0.01em;
  word-break: break-word;
}
.kpis .kpi small, .card small { display: block; margin-top: 4px; color: var(--faint); font-size: 0.78rem; }
.kpi.in strong { color: var(--in); }
.kpi.out strong { color: var(--out); }
.trend { font-weight: 600; }
.trend.up { color: var(--in); }
.trend.down { color: var(--out); }

.op, .balance { --opc: var(--inconnu); }
.airtel { --opc: var(--airtel); }
.vodacom { --opc: var(--vodacom); }
.orange { --opc: var(--orange); }
.africell { --opc: var(--africell); }
.op h3, .balance-head h3 { display: flex; align-items: center; gap: 8px; }
.op h3::before, .balance-head h3::before {
  content: ""; width: 10px; height: 10px; border-radius: 2px; background: var(--opc); flex: none;
}
.ops {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  gap: 10px;
}
.op h3 { margin: 0 0 10px; font-size: 0.95rem; font-weight: 600; text-transform: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border-top: 1px solid var(--line-soft); }
.metric { padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.metric b { display: block; margin-top: 2px; font-weight: 600; }
.metric small { color: var(--muted); font-size: 0.78rem; }
.metric.in b { color: var(--in); }
.metric.out b { color: var(--out); }
.op .sub, .op p { font-size: 0.84rem; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { background: var(--line-soft); color: var(--ink); border-radius: 4px; padding: 3px 7px; font-size: 0.78rem; }

/* ---------- Tableaux ---------- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line-soft); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 500; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }

.list {
  display: grid;
  gap: 0;
  margin-top: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.list:empty { display: none; }
.list > p { padding: 12px 16px; margin: 0; }
.tx { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); }
.tx:last-child { border-bottom: none; }
.tx .meta { color: var(--faint); font-size: 0.8rem; margin-top: 4px; word-break: break-word; }
.tx-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.tx-head strong { font-weight: 600; }
.tx-head .amt { margin-left: auto; font-weight: 600; font-size: 1rem; }
.amt.in { color: var(--in); }
.amt.out { color: var(--out); }
.badge { font-size: 0.75rem; font-weight: 500; color: var(--muted); }
.badge::before {
  content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  margin-right: 5px; vertical-align: 1px; background: var(--faint);
}
.badge.in::before { background: var(--in); }
.badge.out::before { background: var(--out); }
.flow {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin: 6px 0 4px;
  font-size: 0.86rem;
  color: var(--muted);
}
.node { background: none; border: none; padding: 0; color: var(--ink); font-size: 0.86rem; min-height: 0; }
.node.via { font-weight: 500; display: inline-flex; align-items: center; gap: 5px; }
.node.via::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--opc, var(--inconnu)); }
button.node-num {
  cursor: pointer; font: inherit; font-size: 0.86rem; color: var(--accent);
  text-decoration: underline; text-underline-offset: 2px; text-decoration-color: #b7cfc5;
  min-height: 0; padding: 2px 0;
}
.arrow { color: var(--faint); }
.explain { margin: 4px 0; font-size: 0.88rem; color: #3d4541; line-height: 1.45; }
.tx details summary { cursor: pointer; color: var(--faint); font-size: 0.8rem; margin-top: 4px; }
.raw {
  margin-top: 6px; font-family: Consolas, ui-monospace, monospace; font-size: 0.78rem;
  color: #3d4541; white-space: pre-wrap; word-break: break-word;
  background: var(--bg); padding: 8px; border-radius: 4px;
}
.why { font-size: 0.84rem; color: #8a5a00; margin: 4px 0 -4px; }

.kind-tag {
  display: inline-block; font-size: 0.75rem; font-weight: 600;
  padding: 2px 8px; border-radius: 4px; border: 1px solid;
}
.kind-tag.deposit { color: var(--deposit); border-color: #c4d6ea; background: #f2f7fc; }
.kind-tag.withdrawal { color: var(--withdrawal); border-color: #e8d5bd; background: #fcf7f0; }
.kind-tag.bundle { color: #0a5c43; border-color: #b8d4c8; background: #eef7f2; }
.kind-tag.airtime { color: #1d5fa3; border-color: #c4d6ea; background: #f2f7fc; }
.product-tag { margin-top: 6px; font-size: 0.86rem; color: var(--accent); font-weight: 500; }
.kpi.bundle strong { color: #0a5c43; }
.kpi.airtime strong { color: #1d5fa3; }
table.plain { width: 100%; border-collapse: collapse; font-size: 0.9rem; border: none; background: transparent; }
table.plain th, table.plain td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line-soft); }
table.plain th { color: var(--muted); font-weight: 500; font-size: 0.8rem; text-transform: none; letter-spacing: 0; }
.amt.deposit { color: var(--deposit); }
.amt.withdrawal { color: var(--withdrawal); }
.kpi.deposit strong { color: var(--deposit); }
.kpi.withdrawal strong { color: var(--withdrawal); }
.card[data-goto] { cursor: pointer; transition: border-color 0.12s, transform 0.12s; }
.card[data-goto]:hover { border-color: #c9cecb; }
.card[data-goto]:active { transform: scale(0.99); }
.node.via.cash { font-weight: 400; color: var(--muted); }
.effects { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 0.84rem; color: var(--muted); margin: 2px 0 4px; }
.effects b { font-weight: 600; }
.def-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.def-grid > div { line-height: 1.55; }
.def-grid .kind-tag { margin-right: 6px; }
.def-grid .sub { display: block; margin-top: 4px; }
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: 10px;
  vertical-align: middle;
}
.seg button { padding: 6px 10px; font-size: 0.82rem; font-weight: 400; min-height: 36px; }
.live { font-size: 0.8rem; color: var(--in); margin-left: auto; white-space: nowrap; }
table.compact th, table.compact td { padding: 8px 6px; font-size: 0.86rem; }
table.compact, .table-wrap table.compact { border: none; min-width: 0; }
table.compact .dot { margin-right: 6px; }

.bar { height: 8px; background: var(--line-soft); border-radius: 2px; overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; font-size: 0.8rem; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 5px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 16px; }
.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: 10px;
}
h2 {
  margin: 26px 0 10px;
  font-size: 0.95rem;
  font-weight: 600;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 0;
}
h2.section-title { margin-top: 8px; }
h3 { margin: 0 0 10px; font-size: 0.92rem; font-weight: 600; }

.device-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
  gap: 10px;
  margin-bottom: 8px;
}
.device-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.device-card h3 { margin: 0 0 8px; font-size: 0.95rem; color: var(--ink); }
.device-row {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 6px 0; font-size: 0.88rem; border-bottom: 1px solid var(--line-soft);
}
.device-row:last-child { border-bottom: none; }
.device-row > span:first-child { color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 0.8rem; font-weight: 500; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--in); }
.pill.warn { color: #9a6200; }
.pill.off { color: var(--danger); }
.pill + .pill, td .pill { margin-left: 8px; }

footer {
  max-width: var(--content);
  margin: 0 auto;
  padding: 0 var(--pad) calc(28px + var(--safe-b));
  color: var(--muted);
  font-size: 0.84rem;
}
#devicesTable, #tableWrap, #settingsShops, #settingsDevices, .table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  border-radius: var(--radius);
}
#devicesTable table, #settingsShops table, #settingsDevices table, .table-wrap table { min-width: 560px; }

.range { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; width: 100%; }
.range input {
  width: auto; flex: 1 1 140px; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px; font: inherit; min-height: var(--touch); background: #fff;
}
button.link {
  background: none; border: none; color: var(--accent); padding: 0 4px;
  font-size: 0.86rem; cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
  min-height: 0;
}
button.link.strong { font-weight: 600; font-size: 0.9rem; }
.center { text-align: center; }
.empty { padding: 10px 0; color: var(--muted); }
.pos { color: var(--in); }
.neg { color: var(--out); }

.alerts { display: grid; gap: 6px; margin-bottom: 14px; }
.alert {
  background: #fff; border: 1px solid var(--line); border-left: 3px solid;
  border-radius: var(--radius); padding: 10px 14px; font-size: 0.88rem;
}
.alert.danger { border-left-color: var(--danger); }
.alert.warn { border-left-color: #c98a00; }
.alert.info { border-left-color: #7c8b84; }
.insights {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 16px 12px 34px; margin: 0; display: grid; gap: 5px;
  font-size: 0.9rem; color: #3d4541; box-shadow: var(--shadow);
}

.balance-cards, .balance-detail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  gap: 10px;
}
.balance {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; font-size: 0.86rem; color: var(--muted); box-shadow: var(--shadow);
}
.balance-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.balance-head h3 { margin: 0; color: var(--ink); }
.balance-amount {
  font-size: clamp(1.25rem, 3vw, 1.5rem); font-weight: 600; color: var(--ink);
  margin: 10px 0 6px; letter-spacing: -0.02em; word-break: break-word;
}
.balance b { color: var(--ink); font-weight: 600; }
.bal-group + .bal-group { margin-top: 18px; }
.bal-group-head {
  display: flex; justify-content: space-between; align-items: baseline;
  flex-wrap: wrap; gap: 6px; margin-bottom: 8px; padding-bottom: 6px;
  border-bottom: 1px solid var(--line); font-size: 0.86rem; color: var(--muted);
}
.bal-group-head h3 { margin: 0; font-size: 0.95rem; color: var(--ink); }
.bal-group-head b { color: var(--ink); }
.bal-history-btn { margin-top: 8px; width: 100%; }
.balance.open { grid-column: 1 / -1; }
.balance.open .bal-history-btn { width: auto; max-width: 100%; }
.bal-history { overflow-x: auto; margin-top: 10px; border-top: 1px solid var(--line-soft); padding-top: 8px; }
.bal-table { width: 100%; font-size: 0.8rem; }
.bal-table th, .bal-table td { padding: 4px 6px 4px 0; white-space: nowrap; }
.cur-tag {
  font-size: 0.7rem; font-weight: 600; color: var(--muted);
  border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px;
}
.explain-box { margin-bottom: 14px; font-size: 0.88rem; color: #3d4541; line-height: 1.5; }
.gaps { margin-top: 12px; border-top: 1px solid var(--line-soft); padding-top: 8px; font-size: 0.84rem; }
.gap { padding: 8px 0; border-top: 1px solid var(--line-soft); }
.gap:first-of-type { border-top: none; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 12px; }
.filters input, .filters select { flex: 1 1 160px; min-width: 0; width: auto; }
.filters button { flex: 0 0 auto; }

.chart { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.cols {
  display: flex; align-items: flex-end; gap: 4px; height: 170px;
  min-width: min-content; padding-top: 6px; border-bottom: 1px solid var(--line);
}
.col { flex: 1 0 22px; display: flex; flex-direction: column; align-items: center; height: 100%; }
.col .bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.col .bars i { display: block; width: 42%; min-height: 1px; border-radius: 1px 1px 0 0; }
.col .bar-a { background: var(--in); }
.col .bar-b { background: var(--out); }
.col span { font-size: 0.66rem; color: var(--faint); margin-top: 4px; white-space: nowrap; }
.hbar {
  display: grid; grid-template-columns: minmax(80px, 130px) 1fr auto;
  align-items: center; gap: 10px; margin: 7px 0; font-size: 0.84rem;
}
.hbar-track { background: var(--line-soft); border-radius: 1px; height: 8px; overflow: hidden; }
.hbar-track i { display: block; height: 100%; border-radius: 1px; }
.hbar-val { color: var(--muted); white-space: nowrap; }

.panel form.filters,
#expenseForm {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}
.panel form.filters label,
#expenseForm label {
  display: grid;
  gap: 6px;
  flex: 1 1 140px;
  min-width: 0;
  font-size: 0.88rem;
  color: var(--muted);
}
.panel form.filters button,
#expenseForm button { flex: 0 0 auto; align-self: end; }

/* ========== Tablette ========== */
@media (max-width: 1024px) {
  :root { --content: 960px; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

/* ========== Petite tablette / grand téléphone ========== */
@media (max-width: 900px) {
  .top { padding-left: var(--pad); padding-right: var(--pad); }
  .menu-toggle { display: inline-flex; }
  .nav-desktop { display: none !important; }
  .nav-tabs {
    display: flex;
    width: calc(100% + 2 * var(--pad));
    margin-left: calc(-1 * var(--pad));
    margin-right: calc(-1 * var(--pad));
    padding: 0;
  }
  .nav-tabs button {
    flex: 1 1 0;
    padding: 10px 3px;
    font-size: 0.72rem;
    line-height: 1.2;
    text-align: center;
    min-height: 48px;
  }
  .nav-tabs .nav-full { display: none; }
  .nav-tabs .nav-short { display: inline; }
  body.drawer-open { overflow: hidden; }
  .def-grid { grid-template-columns: 1fr; }
  .seg {
    display: flex;
    width: 100%;
    margin: 8px 0 0;
  }
  .seg button { flex: 1 1 auto; }
  h2 .seg { margin-left: 0; }
  .live { margin-left: 0; width: 100%; }
  .balance.open .bal-history-btn { width: 100%; }
}

@media (min-width: 901px) {
  .nav-tabs { display: none !important; }
  .menu-toggle, .drawer, .drawer-backdrop { display: none !important; }
}

/* ========== Téléphone ========== */
@media (max-width: 640px) {
  body { font-size: 14px; }
  .top { padding-top: calc(8px + var(--safe-t)); }
  .top .brand img { width: 34px; height: 34px; }
  .top .brand h1 { font-size: 1.02rem; }
  .top .brand .sub { font-size: 0.78rem; }
  main { padding-top: 12px; padding-bottom: calc(28px + var(--safe-b)); }
  .toolbar { gap: 8px; }
  .toolbar select,
  .toolbar #periodSelect {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
    width: auto;
  }
  .toolbar #reload { flex: 1 1 auto; }
  #periodLabel { width: 100%; margin: 2px 0 0; }
  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card, .op, .panel, .device-card, .balance { padding: 12px; }
  .card strong { font-size: 1.08rem; }
  .ops, .device-cards, .balance-cards, .balance-detail, .panel-grid {
    grid-template-columns: 1fr;
  }
  .hbar { grid-template-columns: 88px 1fr auto; gap: 8px; }
  .balance-amount { font-size: 1.3rem; }
  .filters input, .filters select { flex: 1 1 100%; }
  .filters button { flex: 1 1 calc(50% - 4px); }
  .tx { padding: 12px; }
  .tx-head .amt { width: 100%; margin-left: 0; margin-top: 2px; text-align: left; }
  .flow { font-size: 0.82rem; }
  th, td { padding: 8px; font-size: 0.84rem; }
  .auth-body { padding: 16px 14px max(20px, var(--safe-b)); align-items: start; }
  .auth-card { width: 100%; border-radius: var(--radius); }
  .auth-card .brand { flex-direction: row; }
  .range { width: 100%; }
  .range input { flex: 1 1 100%; }
  #expenseForm label { flex: 1 1 100%; }
  #expenseForm button { width: 100%; }
  table.plain { font-size: 0.84rem; }
  table.plain th, table.plain td { padding: 8px 4px; }
  .insights { padding-left: 28px; }
  #devicesTable table, #settingsShops table, #settingsDevices table, .table-wrap table {
    min-width: 480px;
  }
}

/* ========== Très petit téléphone ========== */
@media (max-width: 380px) {
  .cards { grid-template-columns: 1fr; }
  .toolbar select,
  .toolbar #periodSelect { flex: 1 1 100%; }
  .nav-tabs button { font-size: 0.72rem; padding: 10px 2px; }
  .grid2 { grid-template-columns: 1fr; }
  .auth-card .brand img { width: 48px; height: 48px; }
  .hbar { grid-template-columns: 1fr; gap: 4px; }
  .hbar-val { justify-self: start; }
}

/* ========== Grand écran ---------- */
@media (min-width: 1280px) {
  :root { --content: 1180px; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}

/* ========== Impression / paysage téléphone ---------- */
@media (max-height: 480px) and (orientation: landscape) {
  .auth-body { align-items: start; padding-top: 12px; }
  .top { position: relative; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .card[data-goto] { transition: none; }
  .nav-wrap::before, .nav-wrap::after { transition: none; }
}

@media (hover: none) {
  button.ghost:hover { background: #fff; border-color: var(--line); }
  .card[data-goto]:hover { border-color: var(--line); }
}

/* ---------- Clôture de journée / rapport ---------- */
.day-close-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(85, 165, 28, 0.35);
  background: linear-gradient(90deg, rgba(85, 165, 28, 0.1), rgba(0, 21, 61, 0.04));
  border-radius: var(--radius);
}
.day-close-banner strong { color: var(--navy); }
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: max(12px, var(--safe-t)) var(--pad) max(12px, var(--safe-b));
}
.modal[hidden] { display: none !important; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 21, 61, 0.45);
}
.modal-card {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  max-height: min(90dvh, 920px);
  overflow: auto;
  background: var(--card);
  border-radius: calc(var(--radius) + 4px);
  border: 1px solid var(--line);
  box-shadow: 0 16px 48px rgba(0, 21, 61, 0.22);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--card);
}
.modal-head h2 { margin: 0; font-size: 1.1rem; }
.modal-body { padding: 16px; }
.modal-actions {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  position: sticky;
  bottom: 0;
  background: var(--card);
}
.modal-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}
.note-field { display: grid; gap: 4px; font-size: 0.9rem; color: var(--muted); }
.note-field input {
  min-height: var(--touch);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
}
.day-report-hero {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}
.day-report-hero img {
  height: 48px;
  width: auto;
  max-width: 180px;
  object-fit: contain;
  background: transparent;
  border-radius: 0;
  padding: 0;
}
.day-report .cards { margin: 10px 0 14px; }
.day-report-lines {
  margin: 0;
  padding-left: 18px;
  color: var(--ink);
}
.day-report-lines li { margin: 4px 0; }
.day-report-meta { color: var(--muted); font-size: 0.88rem; margin-top: 12px; }

@media print {
  body * { visibility: hidden !important; }
  #dayCloseModal, #dayCloseModal * { visibility: visible !important; }
  #dayCloseModal {
    position: static !important;
    display: block !important;
    padding: 0 !important;
    background: #fff !important;
  }
  .modal-backdrop, .no-print, .modal-head button { display: none !important; }
  .modal-card {
    box-shadow: none !important;
    border: none !important;
    max-height: none !important;
    width: 100% !important;
  }
}
