/*
  Style de l'application artisans.

  Principe : sobre et net. Le seul élément marquant est le fond à motifs
  d'outils du métier, très discret, façon fond de messagerie. Tout le
  contenu est posé sur des surfaces pleines pour rester lisible dehors.

  La couleur de l'artisan (--brand-accent, donnée par la page) ne sert
  qu'en thème clair. Le thème sombre a ses couleurs fixes.
*/

/* --- Police : Atkinson Hyperlegible Next, dessinée pour la lisibilité --- */

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("../fonts/atkinson-hyperlegible-next-latin-400-normal.e8da57bc0c3d.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("../fonts/atkinson-hyperlegible-next-latin-600-normal.9204a77cef78.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("../fonts/atkinson-hyperlegible-next-latin-700-normal.617b4197a93a.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* --- Couleurs : thème clair --- */

:root {
  --bg: #d5dbd8;
  --pattern: rgb(23 32 38 / 0.12);
  --surface: #f3f5f4;
  --field: #fcfdfc;
  --ink: #172026;
  --muted: #4a565e;
  --line: #b9c2be;
  --accent: var(--brand-accent, #2b4c7e);
  --on-accent: var(--brand-on-accent, #ffffff);
  --accent-ink: var(--brand-accent-ink, #2b4c7e);
  --topbar-bg: var(--accent);
  --topbar-ink: var(--on-accent);
  --danger: #b3261e;

  --side-width: 248px;
  --tabs-height: 64px;
  --radius: 14px;
  color-scheme: light;
}

/* --- Couleurs : thème sombre (réglage du téléphone, ou choix de l'artisan) --- */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1518;
    --pattern: rgb(255 255 255 / 0.055);
    --surface: #192127;
    --field: #141b20;
    --ink: #e8edef;
    --muted: #9ba8b0;
    --line: #2a353d;
    --accent: #8fb4e3;
    --on-accent: #0f1518;
    --accent-ink: #9cc0ec;
    --topbar-bg: var(--surface);
    --topbar-ink: var(--ink);
    --danger: #ff8a80;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1518;
  --pattern: rgb(255 255 255 / 0.055);
  --surface: #192127;
  --field: #141b20;
  --ink: #e8edef;
  --muted: #9ba8b0;
  --line: #2a353d;
  --accent: #8fb4e3;
  --on-accent: #0f1518;
  --accent-ink: #9cc0ec;
  --topbar-bg: var(--surface);
  --topbar-ink: var(--ink);
  --danger: #ff8a80;
  color-scheme: dark;
}

/* --- Base --- */

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

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* Fond à motifs du métier : une couleur unie découpée par le dessin */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-color: var(--pattern);
  -webkit-mask-image: var(--pattern-url);
  mask-image: var(--pattern-url);
  -webkit-mask-size: 360px 360px;
  mask-size: 360px 360px;
  -webkit-mask-repeat: repeat;
  mask-repeat: repeat;
}

h1,
h2,
p {
  margin: 0;
}

a {
  color: var(--accent-ink);
}

:focus-visible {
  outline: 3px solid var(--accent-ink);
  outline-offset: 2px;
  border-radius: 6px;
}

.icon {
  width: 24px;
  height: 24px;
  flex: none;
}

/* --- Bandeau du haut : nom de l'entreprise --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: env(safe-area-inset-top) 8px 0 16px;
  background: var(--topbar-bg);
  color: var(--topbar-ink);
  border-bottom: 1px solid color-mix(in srgb, var(--topbar-ink) 14%, transparent);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar__logo {
  flex: none;
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 6px;
  background: #ffffff;
}

.topbar__name {
  font-size: 1.0625rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar :focus-visible {
  outline-color: currentColor;
}

/* --- Réglages et déconnexion ---
   Téléphone : seule la roue crantée, en haut à droite (la déconnexion
   est dans l'écran Réglages). Ordinateur : les deux, en bas du menu. */

.actions {
  display: flex;
  flex: none;
}

.actions__logout {
  display: none;
  margin: 0;
}

.action {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 0;
  font: inherit;
  color: inherit;
  text-decoration: none;
  background: transparent;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}

.action:hover {
  background: color-mix(in srgb, currentColor 12%, transparent);
}

/* Le texte reste lisible par les lecteurs d'écran, sans s'afficher */
.action__label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --- Onglets : barre en bas sur téléphone --- */

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.tab {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: var(--tabs-height);
  padding: 6px 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
}

.tab__label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab.is-active {
  color: var(--accent-ink);
}

/* Trait de couleur au-dessus de l'onglet ouvert */
.tab.is-active::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 22%;
  right: 22%;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent-ink);
}

.tab:focus-visible {
  outline-offset: -4px;
}

/* --- Contenu d'une page --- */

.page {
  padding: 24px 16px calc(var(--tabs-height) + env(safe-area-inset-bottom) + 32px);
}

.page__inner {
  max-width: 720px;
  margin: 0 auto;
}

.page__title {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.section {
  margin-top: 28px;
}

.section__heading {
  margin-bottom: 10px;
  font-size: 1.0625rem;
  font-weight: 600;
}

/* Écran vide : dit ce qui apparaîtra ici */
.empty {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.empty__icon {
  flex: none;
  width: 30px;
  height: 30px;
  margin-top: 2px;
  color: var(--accent-ink);
}

.empty__title {
  font-weight: 600;
}

.empty__hint {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.9375rem;
}

/* Écran vide secondaire : une simple ligne */
.empty--plain {
  padding: 14px 18px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  border-style: dashed;
}

/* --- Formulaires --- */

.field {
  margin-top: 18px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.field input:not([type="checkbox"], [type="radio"], [type="color"], [type="file"]),
.field select {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  font: inherit;
  color: var(--ink);
  background: var(--field);
  border: 1.5px solid var(--line);
  border-radius: 10px;
}

.field input:not([type="checkbox"], [type="radio"], [type="color"], [type="file"]):focus,
.field select:focus {
  border-color: var(--accent-ink);
  outline: 3px solid color-mix(in srgb, var(--accent-ink) 30%, transparent);
  outline-offset: 0;
}

.field input[type="color"] {
  display: block;
  width: 84px;
  height: 52px;
  padding: 4px;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.field input[type="file"] {
  display: block;
  max-width: 100%;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--muted);
}

.field input[type="file"]::file-selector-button {
  min-height: 44px;
  margin-right: 12px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.field__error {
  margin-top: 6px;
  color: var(--danger);
  font-size: 0.9375rem;
  font-weight: 600;
}

.hint {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.9375rem;
}

/* Bloc qui regroupe des réglages */
.panel {
  padding: 2px 18px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* Choix unique sous forme de boutons côte à côte (thème) */
.choices {
  min-width: 0;
  margin: 18px 0 0;
  padding: 0;
  border: 0;
}

.choices legend {
  margin-bottom: 6px;
  padding: 0;
  font-weight: 600;
}

.choices__list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.choice {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 8px 4px;
  text-align: center;
  font-size: 0.9375rem;
  font-weight: 600;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.choice input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.choice:has(input:checked) {
  color: var(--accent-ink);
  border-color: var(--accent-ink);
  background: color-mix(in srgb, var(--accent-ink) 12%, var(--surface));
}

.choice:has(input:focus-visible) {
  outline: 3px solid var(--accent-ink);
  outline-offset: 2px;
}

.logo-current {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 12px;
}

.logo-current__image {
  width: 72px;
  height: 72px;
  object-fit: contain;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-weight: 400;
  cursor: pointer;
}

.check input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent-ink);
}

.module-list {
  margin: 0;
  padding: 16px 18px 16px 36px;
}

.settings__save {
  margin-top: 22px;
}

/* Message de confirmation après une action */
.flash {
  margin-bottom: 18px;
  padding: 12px 14px;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent-ink);
  border-radius: 10px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 12px 20px;
  font: inherit;
  font-weight: 700;
  color: var(--on-accent);
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
}

.button--wide {
  width: 100%;
}

/* Bouton secondaire : contour seulement */
.button--quiet {
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
}

.form-error {
  margin-top: 14px;
  padding: 12px 14px;
  color: var(--danger);
  background: color-mix(in srgb, var(--danger) 9%, var(--surface));
  border-radius: 10px;
  font-weight: 600;
}

/* --- Page de connexion --- */

.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.auth__card {
  width: 100%;
  max-width: 400px;
  padding: 28px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
}

.auth__company {
  color: var(--muted);
  font-weight: 600;
}

.auth__title {
  margin-top: 2px;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
}

.auth__submit {
  margin-top: 26px;
}

/* --- Ordinateur : les onglets passent dans un menu à gauche --- */

@media (min-width: 960px) {
  .topbar {
    position: fixed;
    top: 0;
    left: 0;
    /* Au-dessus du menu, pour que le bas du menu (réglages) reste visible */
    z-index: 21;
    width: var(--side-width);
    min-height: 72px;
    padding: 0 12px 0 22px;
  }

  .tabs {
    top: 72px;
    right: auto;
    width: var(--side-width);
    flex-direction: column;
    gap: 4px;
    padding: 16px 12px;
    border-top: 0;
    border-right: 1px solid var(--line);
  }

  .tab,
  .action {
    flex: none;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    width: auto;
    height: auto;
    min-height: 48px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.2;
  }

  .tab:hover,
  .action:hover {
    background: color-mix(in srgb, var(--ink) 6%, transparent);
  }

  .tab.is-active,
  .action.is-active {
    color: var(--accent-ink);
    background: color-mix(in srgb, var(--accent-ink) 12%, transparent);
  }

  .tab.is-active::before {
    display: none;
  }

  /* Réglages et déconnexion : en bas du menu de gauche */
  .actions {
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 21;
    width: var(--side-width);
    flex-direction: column;
    gap: 4px;
    padding: 12px;
    color: var(--muted);
    background: var(--surface);
    border-top: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

  .actions__logout {
    display: block;
  }

  .actions .action {
    width: 100%;
    text-align: left;
  }

  .actions :focus-visible {
    outline-color: var(--accent-ink);
  }

  .action__label {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip-path: none;
  }

  /* La déconnexion de l'écran Réglages ne sert que sur téléphone */
  .logout-mobile {
    display: none;
  }

  .page {
    margin-left: var(--side-width);
    padding: 44px 48px 64px;
  }

  .page__inner {
    margin: 0;
  }

  .page__title {
    font-size: 2rem;
  }
}
