/*
 * Single stylesheet, served on GET /style.css.
 * The CSP forbids any style in the HTML: everything goes through this file.
 * Designed for a phone first; the media queries widen it afterwards.
 * La Graine 34 charter (taken from lagraine34.org). All colours are defined
 * here, once; the rest of the file only uses these variables.
 */

/* Fonts served by us (CSP: font-src 'self'), Latin subset. */
@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/roboto-latin-400-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Roboto";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/fonts/roboto-latin-700-normal.woff2") format("woff2");
}

@font-face {
  font-family: "Voltaire";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/voltaire-latin-400-normal.woff2") format("woff2");
}

:root {
  /* Main green: header, buttons, links. White text on it (5.34:1). */
  --vert-principal: #227a44;
  /* Hover: the main green darkened by 25% (mixed with black). */
  --vert-principal-survol: #1a5c33;
  /* Bright green: decoration only (rules, banner). Never under text. */
  --vert-vif: #23a455;
  /* Red: errors and the logout button only. */
  --rouge: #ec111b;
  --rouge-survol: #b10d14; /* the red darkened by 25% */
  --texte: #202020;
  --texte-secondaire: #707070;
  --bordure: #b7b4b4; /* decorative rules, never alone for a field */
  --blanc: #ffffff;
  --noir: #000000; /* ticket printing only */
  /* Alternate detail rows: 5% of the main green in white. */
  --fond-alterne: #f4f8f6;

  --police-titre: "Voltaire", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --police-texte:
    "Roboto", system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial,
    sans-serif;
  --tactile: 2.75rem; /* 44 px: comfortable finger target size */
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--blanc);
  color: var(--texte);
  font-family: var(--police-texte);
  font-size: 1rem;
  line-height: 1.5;
  overflow-wrap: anywhere; /* a long text never overflows the page */
}

/* ---------- Header: logo + tool name, main green background ---------- */

.entete {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 4px solid var(--vert-vif); /* decorative banner */
  background: var(--vert-principal);
  color: var(--blanc);
}

/* The logo has an opaque white background: it sits in a white pill. */
.logo {
  display: block;
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
  background: var(--blanc);
  line-height: 0;
}

.logo img {
  display: block;
  max-width: 100%;
  height: auto;
}

.nom-outil {
  font-family: var(--police-titre);
  font-size: 1.25rem;
  line-height: 1.2;
}

.page {
  margin: 0 auto;
  padding: 1rem;
  max-width: 44rem;
}

h1,
h2 {
  font-family: var(--police-titre);
  font-weight: 400; /* Voltaire only exists in regular weight: no faux bold */
}

h1 {
  margin: 0 0 1rem;
  font-size: 1.5rem;
  line-height: 1.25;
}

h2 {
  margin: 1.5rem 0 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 2px solid var(--vert-vif);
  font-size: 1.1rem;
}

p {
  margin: 0 0 0.75rem;
}

a {
  color: var(--vert-principal);
  text-underline-offset: 0.15em;
}

a:hover {
  color: var(--vert-principal-survol);
}

:focus-visible {
  outline: 3px solid var(--vert-principal);
  outline-offset: 2px;
}

/* ---------- Forms (login, filters) ---------- */

label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="datetime-local"] {
  display: block;
  width: 100%;
  min-height: var(--tactile);
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--texte-secondaire); /* 4.95:1: a field's border must be visible */
  border-radius: 0.375rem;
  background: var(--blanc);
  color: inherit;
  font: inherit; /* 16 px: avoids automatic zoom on iOS */
}

button {
  min-height: var(--tactile);
  padding: 0.5rem 1.25rem;
  border: 2px solid var(--vert-principal);
  border-radius: 0.375rem;
  background: var(--vert-principal);
  color: var(--blanc);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  border-color: var(--vert-principal-survol);
  background: var(--vert-principal-survol);
}

/* Logout: the only red button, outlined (red on white, 4.50:1). */
form[action="/deconnexion"] button {
  border-color: var(--rouge);
  background: var(--blanc);
  color: var(--rouge);
}

form[action="/deconnexion"] button:hover {
  border-color: var(--rouge-survol);
  background: var(--rouge-survol);
  color: var(--blanc);
}

form[action="/deconnexion"] {
  margin-top: 1rem;
}

/* Main button of the ticket, above the "Changer la plage horaire" link. */
.telechargement {
  margin: 0 0 0.5rem;
}

/* Shortcuts of the filters page */
.raccourcis {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.raccourcis a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tactile);
  padding: 0 1rem;
  border: 1px solid var(--vert-principal);
  border-radius: 999px;
  background: var(--blanc);
  text-decoration: none;
  font-weight: 600;
}

.raccourcis a:hover {
  background: var(--vert-principal-survol);
  color: var(--blanc);
}

/*
 * Messages. The error is red on white (4.50:1, the threshold), but never
 * by colour alone: ⚠ icon and "Erreur :" label in the HTML, thick line on
 * the left. The warning stays neutral (dark text).
 */
.erreur,
.avertissement {
  padding: 0.75rem 1rem;
  border: 1px solid var(--bordure);
  border-left-width: 0.5rem;
  border-radius: 0.375rem;
  background: var(--blanc);
  font-weight: 600;
}

.erreur {
  border-color: var(--rouge);
  color: var(--rouge);
}

.erreur .icone {
  font-weight: 700;
}

.avertissement {
  border-left-color: var(--vert-vif);
  color: var(--texte);
}

/* ---------- End-of-service ticket ---------- */

.ticket {
  display: block;
  padding: 1rem;
  border: 1px solid var(--bordure);
  border-radius: 0.5rem;
  background: var(--blanc);
}

.commercant {
  margin-bottom: 0.25rem;
  font-size: 1.2rem;
  font-weight: 700;
}

.periode {
  margin-bottom: 0.25rem;
  font-weight: 600;
}

.generation,
.unite {
  color: var(--texte-secondaire);
}

/* Summary: label on the left, amount on the right */
.resume {
  margin: 0;
}

.resume > div {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px dotted var(--bordure);
}

.resume dt,
.resume dd {
  margin: 0;
}

.resume dd {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

.resume .net {
  border-bottom: 0;
  border-top: 2px solid var(--vert-vif);
  font-size: 1.15rem;
  font-weight: 700;
}

/*
 * Detail: on a small screen each transaction is a small block
 * (date + amount on the first line, then counterparty, description, number).
 * The order in the HTML is: date, number, counterparty, description, amount.
 */
.detail {
  margin: 0;
  padding: 0;
  list-style: none;
}

.ligne {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "date montant"
    "contrepartie contrepartie"
    "description description"
    "numero numero";
  column-gap: 1rem;
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--bordure);
  break-inside: avoid;
  page-break-inside: avoid;
}

/* Alternate rows, discreet (dark text on them: 15:1) */
.ligne:nth-child(even) {
  background: var(--fond-alterne);
}

.ligne > * {
  min-width: 0; /* lets long texts wrap */
}

.date {
  grid-area: date;
  color: var(--texte-secondaire);
  font-variant-numeric: tabular-nums;
}

.montant {
  grid-area: montant;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}

.contrepartie {
  grid-area: contrepartie;
  font-weight: 600;
}

.description {
  grid-area: description;
}

.numero {
  grid-area: numero;
  color: var(--texte-secondaire);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.vide {
  padding: 1rem 0;
  color: var(--texte-secondaire);
  font-style: italic;
}

.actions {
  margin-top: 1.5rem;
}

.actions a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tactile);
}

/* ---------- Cash register page (/caisse): payments received, readable from a distance ---------- */

/* Header: logo, title (the only h1 of the page) and logout button on the right. */
.caisse-entete h1 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.2;
}

.caisse-entete form[action="/deconnexion"] {
  margin: 0 0 0 auto;
}

/* "En direct": small, in the header; a dot and a word (never the colour alone). */
.caisse-direct {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.caisse-direct-point {
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  background: #5fe08a; /* bright green, readable on the main green; the word carries the meaning */
}

/* Sound and notifications: the button and, next to it, the state in words (the colour only underlines it). */
.caisse-son,
.caisse-notif,
.caisse-actualiser {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin: 0 0 1rem;
}

.caisse-son button,
.caisse-notif button,
.caisse-actualiser button {
  min-height: var(--tactile);
}

.caisse-son-etat,
.caisse-notif-etat {
  color: var(--texte-secondaire);
}

.caisse-son-actif .caisse-son-etat,
.caisse-notif-actif .caisse-notif-etat {
  color: var(--vert-principal);
  font-weight: 700;
}

/* Before the first payment. */
.caisse-vide {
  padding: 2rem 1rem;
  border: 2px dashed var(--bordure);
  border-radius: 0.75rem;
  color: var(--texte-secondaire);
  text-align: center;
}

.caisse-vide p {
  margin: 0;
}

.caisse-vide-titre {
  margin-bottom: 0.25rem;
  color: var(--texte);
  font-family: var(--police-titre);
  font-size: 1.5rem;
}

/* The zones the script updates take no room of their own. */
.caisse-zone {
  display: contents;
}

/* The script hides a line with the hidden attribute: it wins over display rules of the classes. */
[hidden] {
  display: none !important;
}

.caisse-etat {
  margin-bottom: 1rem;
  font-size: 1.15rem;
}

/* Banner of the listening (reconnecting, unreadable): the warning or error style, an icon and a sentence. */
.caisse-bandeau {
  margin: 0 0 1rem;
  font-size: 1.1rem;
}

.caisse-bandeau .icone {
  font-weight: 700;
}

/* The latest payment: a big ticket, amount in very large type (3 rem at least). */
.caisse-gros {
  margin-bottom: 1.5rem;
  padding: 1rem 1.25rem;
  border: 3px solid var(--vert-principal);
  border-radius: 0.75rem;
  background: var(--blanc);
}

.caisse-gros p {
  margin: 0 0 0.25rem;
}

/* A new payment: a light green background that fades out (CSS only, no script). It comes on top of the "Nouveau" word. */
.caisse-gros-neuf {
  animation: caisse-fond-neuf 6s ease-out forwards;
}

@keyframes caisse-fond-neuf {
  from {
    background-color: #d6efdf;
  }
  to {
    background-color: var(--blanc);
  }
}

@media (prefers-reduced-motion: reduce) {
  .caisse-gros-neuf {
    animation: none;
    background-color: #eaf6ee;
  }
}

/* "Nouveau" is a word, the colour only underlines it. */
.caisse-nouveau,
.caisse-nouveau-petit {
  display: inline-block;
  padding: 0.125rem 0.75rem;
  border-radius: 999px;
  background: var(--vert-principal);
  color: var(--blanc);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.caisse-nouveau-petit {
  padding: 0 0.5rem;
  font-size: 0.8rem;
}

.caisse-gros-payeur {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.25;
}

.caisse-gros .caisse-gros-montant {
  margin: 0.75rem 0;
  font-family: var(--police-titre);
  font-size: clamp(3rem, 12vw, 6rem);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

/* Amount not known yet: a sentence, not a figure. */
.caisse-gros-attente {
  font-size: 1.5rem;
  font-style: italic;
}

.caisse-gros-payeur {
  margin-bottom: 0.25rem;
}

.caisse-gros .caisse-gros-heure {
  color: var(--texte);
  font-size: 1.65rem;
  font-variant-numeric: tabular-nums;
}

/* Description: much smaller than the date line, grey. */
.caisse-gros .caisse-gros-description {
  margin-top: 0.5rem;
  color: var(--texte-secondaire);
  font-size: 1rem;
}

.caisse-gros-numero {
  color: var(--texte-secondaire);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

/* Previous payments: time | payer and, under it, the description | transaction number | amount.
   Narrow screen (phone): the number moves under the payer and the description. */
.caisse-precedents {
  margin: 0;
  padding: 0;
  list-style: none;
}

.caisse-ligne {
  display: grid;
  grid-template-columns: 6.25rem minmax(0, 1fr) auto;
  grid-template-areas:
    "heure qui montant"
    ". numero .";
  column-gap: 0.75rem;
  align-items: baseline;
  padding: 0.6rem 0.5rem;
  border-bottom: 1px solid var(--bordure);
  font-size: 1.15rem;
}

.caisse-ligne:nth-child(even) {
  background: var(--fond-alterne);
}

/* Date and time on ONE line, "12/11 17:21" included. */
.caisse-heure {
  grid-area: heure;
  color: var(--texte-secondaire);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.caisse-qui {
  grid-area: qui;
  min-width: 0;
}

.caisse-payeur {
  display: block;
  font-weight: 700;
}

/* Description: small, grey, one line cut with an ellipsis. */
.caisse-description {
  display: block;
  overflow: hidden;
  color: var(--texte-secondaire);
  font-size: 0.9rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Transaction number: small, grey, same look as the one of the last payment. Absent from the page when there is none. */
.caisse-numero {
  grid-area: numero;
  color: var(--texte-secondaire);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.caisse-montant {
  grid-area: montant;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}

.caisse-actualisation {
  margin-top: 1.5rem;
  color: var(--texte-secondaire);
}

/* ---------- Wider: tablet and computer ---------- */

@media (min-width: 40rem) {
  .entete {
    padding: 0.75rem 2rem;
  }

  .page {
    padding: 2rem 1rem;
  }

  h1 {
    font-size: 1.75rem;
  }

  .ticket {
    padding: 1.5rem 2rem;
  }

  .caisse-entete h1 {
    font-size: 1.5rem;
  }

  .caisse-gros {
    padding: 1.5rem 2rem;
  }

  .caisse-ligne {
    grid-template-columns: 8.5rem minmax(0, 1fr) auto;
    column-gap: 1rem;
    font-size: 1.3rem;
  }

  .caisse-heure {
    font-size: 1.15rem;
  }

  .caisse-description {
    font-size: 1rem;
  }

  /* One table row: date | counterparty | amount, then number | description */
  .ligne {
    grid-template-columns: 9rem minmax(0, 1fr) auto;
    grid-template-areas:
      "date contrepartie montant"
      "numero description description";
  }

  input[type="text"],
  input[type="password"],
  input[type="datetime-local"] {
    max-width: 22rem;
  }
}

/* ---------- Wide enough (tablet in landscape, computer): the transaction number gets a column of its own ----------
   Fixed widths for the number and for the amount, so that the numbers line up from one row to the next. The two 1fr columns
   (name and empty space) are equal: the number sits in the middle of the free space between the name and the amount.
   Narrower than this, the number stays under the name. */
@media (min-width: 48rem) {
  .caisse-ligne {
    grid-template-columns: 8.5rem minmax(0, 1fr) 8rem minmax(0, 1fr) 8rem;
    grid-template-areas: "heure qui numero . montant";
  }

  .caisse-numero {
    text-align: center;
  }
}

/* ---------- Printing: narrow ticket (~80 mm), black on white ---------- */

@media print {
  @page {
    size: 80mm auto;
    margin: 4mm;
  }

  html,
  body {
    width: 72mm; /* 80 mm minus the margins */
    max-width: 72mm;
    margin: 0;
    padding: 0;
    background: var(--blanc);
    color: var(--noir);
    font-size: 10pt;
    line-height: 1.3;
  }

  /* Ticket: black on white, no coloured background. */
  .page {
    padding: 0;
    max-width: 72mm;
  }

  .entete {
    padding: 0 0 2mm;
    border-bottom: 1px solid var(--noir);
    background: var(--blanc);
    color: var(--noir);
  }

  /*
   * The logo (green and dark grey on white) goes grayscale, without the
   * pill; the tool name stays black.
   */
  .logo {
    padding: 0;
    border-radius: 0;
  }

  .logo img {
    filter: grayscale(1);
  }

  .nom-outil {
    font-size: 10pt;
  }

  .ligne:nth-child(even) {
    background: var(--blanc);
  }

  .ligne {
    padding: 0.3rem 0;
  }

  .erreur,
  .avertissement {
    border-color: var(--noir);
    color: var(--noir);
  }

  /* Nothing clickable on paper */
  a,
  button,
  form,
  .actions,
  .raccourcis {
    display: none !important;
  }

  .ticket {
    padding: 0;
    border: 0;
    border-radius: 0;
  }

  h1 {
    margin-bottom: 0.5rem;
    font-size: 13pt;
  }

  h2 {
    margin-top: 0.75rem;
    border-bottom: 1px solid var(--noir);
    font-size: 11pt;
    break-after: avoid;
  }

  .generation,
  .unite,
  .date,
  .numero {
    color: var(--noir);
  }

  .numero {
    font-size: 8pt;
  }

  .resume > div,
  .ligne {
    border-bottom: 1px dotted var(--noir);
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .resume .net {
    border-top: 1px solid var(--noir);
  }

  /* Same narrow layout as on a phone, whatever the page */
  .ligne {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "date montant"
      "contrepartie contrepartie"
      "description description"
      "numero numero";
  }

  .avertissement {
    border: 1px solid var(--noir);
    border-left-width: 4px;
  }
}
