/* =========================================================================
   Frais pro - feuille de styles principale
   Direction : un carnet de route. Fond papier froid, reglures fines,
   colonnes teintees comme le tableau papier, chiffres en chasse fixe.
   ========================================================================= */

:root {
  color-scheme: light;

  /* Encre et papier */
  --paper: #f2f4f7;
  --sheet: #ffffff;
  --ink: #16212e;
  --ink-soft: #5a6878;
  --ink-faint: #8b98a6;
  --rule: #dde3ea;
  --rule-strong: #c3ccd7;

  /* Categories du tableau papier */
  --c-hotel: #2563eb;
  --c-gasoil: #ea7317;
  --c-peage: #d9a406;
  --c-divers: #16a34a;
  --c-autre: #7c3aed;

  /* Teintes de fond des colonnes (tres claires) */
  --c-hotel-bg: #eaf1ff;
  --c-gasoil-bg: #fff0e2;
  --c-peage-bg: #fdf6dd;
  --c-divers-bg: #e8f7ee;
  --c-autre-bg: #f2ecfe;

  /* Etats */
  --ok: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(22, 33, 46, 0.06);
  --shadow: 0 6px 20px rgba(22, 33, 46, 0.09);
  --shadow-lg: 0 18px 50px rgba(22, 33, 46, 0.22);

  --font-body: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-num: "SF Mono", "Segoe UI Mono", "Roboto Mono", "DejaVu Sans Mono", ui-monospace, monospace;

  --header-h: 62px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --paper: #10161d;
  --sheet: #18202a;
  --ink: #e8edf3;
  --ink-soft: #a6b3c1;
  --ink-faint: #7c8a99;
  --rule: #2a3541;
  --rule-strong: #3a4756;

  --c-hotel-bg: #16233b;
  --c-gasoil-bg: #2e1d0f;
  --c-peage-bg: #2c2610;
  --c-divers-bg: #10281a;
  --c-autre-bg: #221833;

  --danger-bg: #3b1717;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.6);
}

* {
  box-sizing: border-box;
}

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

body {
  background-color: var(--paper);
  background-image: linear-gradient(var(--rule) 1px, transparent 1px);
  background-size: 100% 28px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--c-hotel);
  outline-offset: 2px;
  border-radius: 4px;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

/* ---------- Boutons ------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--sheet);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  border-color: var(--ink-soft);
}

.btn:active {
  transform: translateY(1px);
}

.btn--primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--sheet);
}

.btn--primary:hover {
  background: #0d1720;
}

[data-theme="dark"] .btn--primary:hover {
  background: #f5f8fb;
}

.btn--accent {
  background: var(--c-hotel);
  border-color: var(--c-hotel);
  color: #fff;
}

.btn--danger {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
}

.btn--ghost:hover {
  background: rgba(125, 140, 155, 0.14);
  border-color: transparent;
}

.btn--icon {
  min-width: 38px;
  padding: 0 10px;
}

.btn--sm {
  min-height: 30px;
  padding: 0 9px;
  font-size: 13px;
}

/* ---------- Ecran de connexion ------------------------------------------ */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login__card {
  width: min(400px, 100%);
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 30px 28px 26px;
}

.login__mark {
  display: flex;
  gap: 5px;
  margin-bottom: 20px;
}

.login__mark span {
  height: 6px;
  flex: 1;
  border-radius: 3px;
}

.login__title {
  font-size: 24px;
  margin-bottom: 4px;
}

.login__lead {
  color: var(--ink-soft);
  margin: 0 0 22px;
  font-size: 14px;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field__label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.field__control {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--sheet);
}

.field__control:focus {
  border-color: var(--c-hotel);
}

.field__hint {
  font-size: 12px;
  color: var(--ink-faint);
  margin-top: 5px;
}

.message {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(185, 28, 28, 0.3);
}

/* ---------- En-tete ------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--header-h);
  padding: 0 20px;
  background: var(--sheet);
  border-bottom: 1px solid var(--rule);
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand__name {
  font-size: 19px;
  letter-spacing: -0.02em;
}

.brand__tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
}

.topbar__spacer {
  flex: 1;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn--mobile-link {
  background: linear-gradient(180deg, var(--c-divers), #10823a);
  border-color: #10823a;
  color: #fff;
  font-size: 15px;
  padding: 0 16px;
  min-height: 40px;
  box-shadow: 0 3px 0 rgba(16, 130, 58, 0.35);
}

.btn--mobile-link:hover {
  border-color: #0c6b2f;
}

/* Pastille de synchronisation */
.sync {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 12px 5px 10px;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: var(--sheet);
  font-size: 13px;
  line-height: 1.15;
}

.sync__dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex: none;
}

.sync__text {
  font-weight: 650;
}

.sync__time {
  display: block;
  font-size: 11px;
  color: var(--ink-faint);
  font-weight: 400;
}

.sync[data-state="synced"] .sync__dot {
  background: var(--ok);
}

.sync[data-state="syncing"] .sync__dot {
  background: var(--c-hotel);
  animation: pulse 1s ease-in-out infinite;
}

.sync[data-state="pending"] .sync__dot {
  background: var(--warn);
}

.sync[data-state="offline"] .sync__dot {
  background: var(--ink-faint);
}

.sync[data-state="error"] .sync__dot {
  background: var(--danger);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.25;
  }
}

/* ---------- Mise en page ------------------------------------------------- */

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 22px 20px 80px;
}

/* ---------- Totalisateur (element signature) ----------------------------- */

.totaliser {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px 16px;
  margin-bottom: 18px;
}

.totaliser__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.totaliser__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-faint);
  font-weight: 700;
}

.totaliser__amount {
  font-size: 42px;
  font-weight: 700;
  line-height: 1;
  margin-top: 4px;
}

.totaliser__meta {
  color: var(--ink-soft);
  font-size: 13px;
  text-align: right;
}

.totaliser__bar {
  display: flex;
  height: 14px;
  margin: 16px 0 12px;
  border-radius: 7px;
  overflow: hidden;
  background: repeating-linear-gradient(
    90deg,
    var(--rule) 0 6px,
    transparent 6px 12px
  );
}

.totaliser__seg {
  height: 100%;
  transition: width 0.35s ease;
}

.totaliser__legend {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.legend-item {
  border-top: 3px solid var(--legend-color, var(--rule));
  padding-top: 8px;
}

.legend-item__name {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.legend-item__value {
  font-size: 18px;
  font-weight: 650;
}

.legend-item__share {
  font-size: 12px;
  color: var(--ink-faint);
}

/* ---------- Barre d'outils ----------------------------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.monthnav {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--sheet);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  padding: 4px 6px;
}

.monthnav__label {
  min-width: 148px;
  text-align: center;
  font-weight: 650;
  text-transform: capitalize;
}

.toolbar__group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.control {
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--sheet);
}

.control--search {
  min-width: 210px;
}

/* ---------- Tableau ------------------------------------------------------ */

.sheet {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
}

table.ledger {
  width: 100%;
  border-collapse: collapse;
  min-width: 940px;
}

.ledger th,
.ledger td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--rule);
  text-align: right;
  vertical-align: middle;
}

.ledger thead th {
  position: sticky;
  top: var(--header-h);
  z-index: 10;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #fff;
  border-bottom: 2px solid rgba(0, 0, 0, 0.12);
  white-space: nowrap;
}

.col-date {
  text-align: left !important;
  width: 168px;
}

.col-actions {
  width: 118px;
  text-align: center !important;
}

.col-total {
  width: 130px;
}

th.col-date,
th.col-total,
th.col-actions {
  background: var(--ink);
}

th.col-hotel {
  background: var(--c-hotel);
}

th.col-gasoil {
  background: var(--c-gasoil);
}

th.col-peage {
  background: var(--c-peage);
}

th.col-divers {
  background: var(--c-divers);
}

th.col-autre {
  background: var(--c-autre);
}

.ledger tbody td.cell-hotel {
  background: var(--c-hotel-bg);
}

.ledger tbody td.cell-gasoil {
  background: var(--c-gasoil-bg);
}

.ledger tbody td.cell-peage {
  background: var(--c-peage-bg);
}

.ledger tbody td.cell-divers {
  background: var(--c-divers-bg);
}

.ledger tbody td.cell-autre {
  background: var(--c-autre-bg);
}

.ledger tbody tr:hover td {
  box-shadow: inset 0 0 0 9999px rgba(37, 99, 235, 0.045);
}

.ledger td.cell-date {
  text-align: left;
  border-right: 1px solid var(--rule);
  font-weight: 650;
  white-space: nowrap;
}

.ledger td.cell-total {
  font-weight: 700;
  border-left: 1px solid var(--rule);
}

.day-start td {
  border-top: 2px solid var(--rule-strong);
}

.entry-note {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--ink-soft);
  text-align: right;
}

.entry-vendor {
  color: var(--ink-faint);
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.ledger tfoot td {
  background: var(--paper);
  font-weight: 700;
  border-top: 2px solid var(--rule-strong);
  border-bottom: none;
}

.ledger tfoot .foot-label {
  text-align: left;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}

.empty {
  padding: 56px 24px;
  text-align: center;
  color: var(--ink-soft);
}

.empty__title {
  font-size: 18px;
  color: var(--ink);
  margin-bottom: 6px;
}

/* ---------- Fenetres modales --------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(11, 18, 26, 0.55);
  animation: fade 0.15s ease;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

.modal__card {
  width: min(560px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--sheet);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 22px 24px 20px;
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal__title {
  font-size: 20px;
}

.modal__actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.chips {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.chip {
  border: 2px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--sheet);
  padding: 9px 4px;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  text-align: center;
}

.chip[aria-pressed="true"] {
  border-color: var(--chip-color);
  background: var(--chip-bg);
  color: var(--chip-color);
}

.qr-holder {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 8px 0 4px;
}

#qr-canvas {
  border: 12px solid #fff;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  image-rendering: pixelated;
  width: 260px;
  height: 260px;
}

.qr-url {
  font-family: var(--font-num);
  font-size: 13px;
  word-break: break-all;
  text-align: center;
  color: var(--ink-soft);
}

/* ---------- Notifications ------------------------------------------------ */

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  display: grid;
  gap: 8px;
  max-width: 340px;
}

.toast {
  background: var(--ink);
  color: #fff;
  padding: 11px 15px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 14px;
  animation: rise 0.18s ease;
}

.toast--error {
  background: var(--danger);
}

.toast--ok {
  background: var(--ok);
}

@keyframes rise {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
}

/* ---------- Impression --------------------------------------------------- */

.print-head {
  display: none;
}

@media print {
  body {
    background: #fff;
  }

  .topbar,
  .toolbar,
  .col-actions,
  .cell-actions,
  .toasts,
  .modal {
    display: none !important;
  }

  .page {
    padding: 0;
    max-width: none;
  }

  .print-head {
    display: block;
    margin-bottom: 12px;
  }

  .sheet,
  .totaliser {
    box-shadow: none;
    border-color: #999;
  }

  .ledger thead th {
    position: static;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .ledger tbody td {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* ---------- Ecrans etroits ----------------------------------------------- */

@media (max-width: 900px) {
  .totaliser__legend {
    grid-template-columns: repeat(2, 1fr);
  }

  .totaliser__amount {
    font-size: 34px;
  }

  .topbar {
    padding: 0 12px;
    gap: 10px;
  }

  .brand__tag {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
