/* =========================================================
   MOTO TOP — feuille de style unique
   Couleurs du logo : orange #F39200, rouge #E52421, noir, blanc
   ========================================================= */

:root {
  --orange: #F39200;
  --rouge: #E52421;
  --noir: #141312;
  --grad: linear-gradient(135deg, #F7A21B 0%, #F39200 45%, #E52421 100%);

  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --border: #e6e1d9;
  --border-strong: #d4cdc2;
  --text: #1c1b19;
  --muted: #6e6960;
  --accent: #e07f00;           /* orange lisible sur fond clair */
  --accent-ink: #b85f00;
  --accent-soft: rgba(243,146,0,.12);
  --ok: #18804a;      --ok-soft: rgba(24,128,74,.12);
  --warn: #b86e00;    --warn-soft: rgba(243,146,0,.14);
  --danger: #cf2418;  --danger-soft: rgba(229,36,33,.11);
  --info: #2c62c9;    --info-soft: rgba(44,98,201,.11);
  --shadow: 0 1px 2px rgba(28,27,25,.05), 0 4px 16px rgba(28,27,25,.05);
  --shadow-lg: 0 12px 40px rgba(28,27,25,.18);
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 248px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f0e0d;
  --surface: #1a1918;
  --surface-2: #211f1d;
  --border: #2d2a27;
  --border-strong: #3c3834;
  --text: #f2efea;
  --muted: #a49d93;
  --accent: #ffa31f;
  --accent-ink: #ffb54d;
  --accent-soft: rgba(255,163,31,.14);
  --ok: #3cc47c;      --ok-soft: rgba(60,196,124,.14);
  --warn: #ffb547;    --warn-soft: rgba(255,181,71,.14);
  --danger: #ff5a4e;  --danger-soft: rgba(255,90,78,.14);
  --info: #6c9dff;    --info-soft: rgba(108,157,255,.14);
  --shadow: 0 1px 2px rgba(0,0,0,.35);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--text); background: var(--bg); }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
img { max-width: 100%; }
.ico { flex-shrink: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }
.inline { display: inline; margin: 0; }
.hidden { display: none !important; }
.stack > * + * { margin-top: .9rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: .6rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grow { flex: 1 1 auto; }
.mt { margin-top: 1rem; }
.mb { margin-bottom: 1rem; }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }

/* ---------- Structure ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  display: flex; flex-direction: column;
  background: var(--noir); color: #e9e5df;
  border-right: 1px solid #000;
}
.brand { display: block; padding: 18px 20px 10px; }
.brand img { display: block; width: 100%; max-width: 190px; height: auto; margin: 0 auto; filter: drop-shadow(0 2px 6px rgba(0,0,0,.4)); }
.nav { flex: 1; overflow-y: auto; padding: 6px 12px 16px; scrollbar-width: thin; scrollbar-color: #3a3632 transparent; }
.nav-group { margin: 16px 10px 6px; font-size: .72rem; font-weight: 600; letter-spacing: .06em; color: #8c857b; }
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; margin: 2px 0;
  border-radius: 10px; color: #d9d4cc; font-weight: 500; position: relative;
}
.nav-link:hover { background: #24221f; color: #fff; text-decoration: none; }
.nav-link.active { background: rgba(243,146,0,.16); color: #fff; }
.nav-link.active::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 4px 4px 0; background: var(--grad); }
.nav-link.active .ico { color: var(--orange); }
.sidebar-foot { padding: 12px; border-top: 1px solid #2a2724; }
.me { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; color: #e9e5df; }
.me:hover { background: #24221f; text-decoration: none; }
.me-txt { display: flex; flex-direction: column; min-width: 0; }
.me-txt strong { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-txt small { color: #9b948a; font-size: .78rem; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: var(--grad); flex-shrink: 0; }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 12px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.page-title { font-size: 1.3rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; gap: 6px; align-items: center; }
.content { padding: 24px 28px 48px; max-width: 1400px; width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer;
}
.icon-btn:hover { border-color: var(--border-strong); text-decoration: none; }
.when-dark { display: none; }
:root[data-theme="dark"] .when-dark { display: inline; }
:root[data-theme="dark"] .when-light { display: none; }
.only-mobile { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 960px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 35; background: rgba(0,0,0,.45); }
  .sidebar.open + .sidebar-backdrop { display: block; }
  .main { margin-left: 0; }
  .only-mobile { display: inline-grid; }
  .topbar { padding: 10px 14px; }
  .content { padding: 16px 14px 40px; }
  .page-title { font-size: 1.1rem; }
}

/* ---------- Cartes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card + .card, .card + .grid, .grid + .card, .toolbar + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush .card-head { padding: 16px 20px 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-side { grid-template-columns: minmax(0,1fr) 340px; align-items: start; }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .grid-side { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.stat { display: flex; flex-direction: column; gap: 4px; }
.stat-label { color: var(--muted); font-size: .85rem; display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 1.7rem; font-weight: 750; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-value.accent { color: var(--accent); }
.stat-sub { color: var(--muted); font-size: .82rem; }
a.stat-card { color: inherit; display: flex; transition: border-color .15s, transform .15s; }
.grid > .card + .card, .grid > * + .card { margin-top: 0; }
a.stat-card:hover { text-decoration: none; border-color: var(--orange); transform: translateY(-1px); }

.empty-state { text-align: center; padding: 48px 20px; }
.empty-ico { color: var(--accent); margin-bottom: 10px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 40px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap; text-decoration: none; transition: filter .15s, background .15s, border-color .15s;
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--grad); border-color: transparent; color: #fff; text-shadow: 0 1px 1px rgba(0,0,0,.15); }
.btn-primary:hover { filter: brightness(1.06); border-color: transparent; }
.btn-dark { background: var(--noir); border-color: var(--noir); color: #fff; }
:root[data-theme="dark"] .btn-dark { background: #2a2826; border-color: #3a3632; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-ok { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.btn-ok:hover { background: var(--ok); color: #fff; }
.btn-sm { min-height: 32px; padding: 5px 11px; font-size: .86rem; border-radius: 8px; }
.btn-lg { min-height: 50px; padding: 12px 22px; font-size: 1.05rem; border-radius: 12px; }
.btn-block { width: 100%; }
.btn-icon { width: 34px; min-height: 34px; padding: 0; }

/* ---------- Formulaires ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span, .label { font-size: .86rem; font-weight: 600; color: var(--muted); }
.field .hint { font-size: .8rem; color: var(--muted); font-weight: 400; }
.req::after { content: " *"; color: var(--rouge); }
.input, .select, .textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit;
}
.textarea { min-height: 90px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--orange); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-lg { min-height: 50px; font-size: 1.05rem; }
.input-money { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--orange); }

/* Saisie rapide sur une ligne (réception) */
.quick { display: grid; gap: 10px; grid-template-columns: 1.3fr 1fr 1fr 2fr auto; align-items: end; }
@media (max-width: 1000px) { .quick { grid-template-columns: 1fr 1fr; } .quick .full-sm { grid-column: 1 / -1; } }

/* Barre d'outils (filtres) */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.toolbar .field { min-width: 140px; }
.toolbar .search { flex: 1 1 260px; position: relative; }
.search .ico { position: absolute; left: 12px; bottom: 11px; color: var(--muted); pointer-events: none; }
.search .input { padding-left: 38px; }

/* Segments (onglets / filtres rapides) */
.seg { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; flex-wrap: wrap; }
.seg a, .seg button { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 9px; border: 0; background: transparent; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.seg a:hover, .seg button:hover { text-decoration: none; background: var(--surface); }
.seg .on { background: var(--surface); box-shadow: var(--shadow); color: var(--accent-ink); }
.seg .count { font-size: .78rem; padding: 1px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent-ink); }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: .8rem; font-weight: 650; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions > * { margin-left: 4px; }
.table tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border-strong); }
.table-sm th, .table-sm td { padding: 8px 12px; }
.cell-main { font-weight: 600; }
.cell-sub { display: block; font-size: .82rem; color: var(--muted); }
.plaque {
  display: inline-block; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-weight: 700; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 6px; border: 1.5px solid var(--border-strong); background: var(--surface); font-size: .86rem; white-space: nowrap;
}
.amount-pos { color: var(--ok); }
.amount-neg { color: var(--danger); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 99px; font-size: .78rem; font-weight: 650; white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-accent { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* ---------- Messages ---------- */
.flash { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px; margin-bottom: 14px; font-weight: 500; border: 1px solid transparent; }
.flash-success { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--danger-soft); color: var(--danger); }
.flash-info { background: var(--info-soft); color: var(--info); }
.flash-warn { background: var(--warn-soft); color: var(--warn); }
.flash-x { margin-left: auto; border: 0; background: transparent; color: inherit; font-size: 1.3rem; line-height: 1; cursor: pointer; opacity: .7; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 14px; flex-wrap: wrap; }

/* ---------- Fenêtre modale ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(0,0,0,.5); visibility: hidden; opacity: 0; pointer-events: none; transition: opacity .15s; }
.modal.open { visibility: visible; opacity: 1; pointer-events: auto; }
.modal-box { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 22px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-head h2 { margin: 0; }

/* ---------- Connexion ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background:
  radial-gradient(1200px 500px at 50% -10%, rgba(243,146,0,.22), transparent 60%),
  radial-gradient(800px 400px at 100% 100%, rgba(229,36,33,.14), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lg); padding: 30px 28px 24px; }
.login-logo { display: block; width: 260px; max-width: 90%; margin: 0 auto 4px; }
.login-sub { text-align: center; color: var(--muted); margin-bottom: 20px; }
.login-foot { text-align: center; color: var(--muted); font-size: .8rem; margin: 18px 0 0; }

/* ---------- Caisse (tactile) ---------- */
.pos { display: grid; grid-template-columns: minmax(0,1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .pos { grid-template-columns: 1fr; } }
.pos-display { background: var(--noir); color: #fff; border-radius: var(--radius); padding: 16px 20px; text-align: right; }
.pos-display small { display: block; color: #a8a199; text-align: left; font-size: .85rem; }
.pos-display .val { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.pos-display.neg .val { color: #ff7b70; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.keypad button { min-height: 62px; font-size: 1.45rem; font-weight: 700; border-radius: 12px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; }
.keypad button:active { transform: scale(.97); background: var(--surface-2); }
.choice-grid { display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); }
.choice-grid.two { grid-template-columns: repeat(2, 1fr); }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice span { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; min-height: 70px; padding: 10px; border-radius: 12px; border: 2px solid var(--border-strong); background: var(--surface); font-weight: 700; cursor: pointer; text-align: center; }
.choice input:checked + span { border-color: var(--orange); background: var(--accent-soft); color: var(--accent-ink); }
.choice input:focus-visible + span { outline: 2px solid var(--orange); outline-offset: 2px; }
.choice.rembourse input:checked + span { border-color: var(--rouge); background: var(--danger-soft); color: var(--danger); }

/* ---------- Grille de droits ---------- */
.rights th, .rights td { text-align: center; }
.rights th:first-child, .rights td:first-child { text-align: left; }
.rights .def { font-size: .72rem; color: var(--muted); display: block; font-weight: 400; }
.rights input { width: 20px; height: 20px; accent-color: var(--orange); }
.rights tr.diff td:first-child::after { content: " · personnalisé"; color: var(--accent-ink); font-size: .78rem; font-weight: 600; }

/* ---------- Divers ---------- */
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
pre.code { text-align: left; white-space: pre-wrap; background: var(--surface-2); padding: 12px; border-radius: 8px; font-size: .85rem; }
.total-line { display: flex; justify-content: space-between; padding: 6px 0; }
.total-line.big { font-size: 1.15rem; font-weight: 750; border-top: 2px solid var(--border-strong); margin-top: 6px; padding-top: 10px; }

/* ---------- Impression ---------- */
@media print {
  body { background: #fff; color: #000; font-size: 12px; }
  .sidebar, .sidebar-backdrop, .topbar, .no-print, .flash, .pagination, .toolbar, .btn { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .table th { background: #eee !important; }
  a { color: #000; }
}
