/* ===========================================================================
   Service Coding — feuille de style unique
   Palette : bleu professionnel + vert émeraude, fond clair.
   Toutes les couleurs sont pilotées par les variables ci-dessous.
   =========================================================================== */

:root {
  /* --- couleurs demandées ------------------------------------------------ */
  --primary-blue:       #1565c0;
  --primary-blue-dark:  #0b4a8f;
  --emerald:            #10b981;
  --emerald-dark:       #047857;
  --background:         #eef2f8;
  --card:               #ffffff;
  --text:               #0f2033;
  --muted:              #5c718a;

  /* --- déclinaisons ------------------------------------------------------ */
  --primary-blue-soft:  #e8f1fc;
  --emerald-soft:       #e6f7f0;
  --amber:              #c2410c;
  --amber-soft:         #fdeee4;
  --violet:             #6d28d9;
  --violet-soft:        #f0eafc;
  --slate-soft:         #eef1f5;
  --border:             #dbe3ee;
  --border-strong:      #c4d2e4;

  --radius-sm:  10px;
  --radius:     16px;
  --radius-lg:  22px;

  --shadow-sm:  0 1px 2px rgba(11, 42, 74, .06), 0 1px 3px rgba(11, 42, 74, .05);
  --shadow:     0 2px 6px rgba(11, 42, 74, .07), 0 8px 22px rgba(11, 42, 74, .07);
  --shadow-lg:  0 10px 40px rgba(11, 42, 74, .22);

  --header-grad: linear-gradient(150deg, var(--primary-blue) 0%, var(--primary-blue-dark) 68%, #063567 100%);
  --code-grad:   linear-gradient(145deg, #2b7fd4 0%, var(--primary-blue) 45%, var(--primary-blue-dark) 100%);

  --font: "Segoe UI", system-ui, -apple-system, "Inter", "Helvetica Neue", Arial, sans-serif;
  --tap: 48px;

  color-scheme: light;
}

/* --- base ---------------------------------------------------------------- */
* { box-sizing: border-box; }

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(74px + env(safe-area-inset-bottom));
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
button { font: inherit; color: inherit; }

.wrap { width: 100%; max-width: 880px; margin: 0 auto; padding: 0 16px; }

/* l'attribut hidden doit toujours l'emporter sur un display: flex/grid */
[hidden] { display: none !important; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: #fff; color: var(--primary-blue-dark);
  padding: 12px 18px; border-radius: 0 0 var(--radius-sm) 0; font-weight: 600;
}
.skip-link:focus { left: 0; }

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

/* --- en-tête ------------------------------------------------------------- */
.app-header {
  background: var(--header-grad);
  color: #fff;
  padding: calc(18px + env(safe-area-inset-top)) 0 22px;
  border-radius: 0 0 26px 26px;
  box-shadow: 0 8px 26px rgba(6, 43, 84, .24);
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }

/* --- sélecteur de langue (toujours visible) ------------------------------ */
/* flex: none — le sélecteur ne doit jamais être comprimé ni poussé hors écran */
.lang-switch {
  margin-left: auto;
  flex: none;
  display: flex; gap: 3px;
  padding: 3px;
  background: rgba(255, 255, 255, .13);
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 999px;
}

.lang-btn {
  display: grid; place-items: center;
  width: 40px; height: 38px; padding: 0;
  border: 0; border-radius: 999px;
  background: transparent;
  cursor: pointer;
  transition: background .14s ease;
}
.lang-btn:hover { background: rgba(255, 255, 255, .14); }

/* état actif : pastille blanche + drapeau à pleine opacité.
   L'inactif est atténué — l'information ne repose donc pas sur la couleur
   seule, et aria-pressed la porte pour les lecteurs d'écran. */
.lang-btn.is-active {
  background: #fff;
  box-shadow: 0 1px 4px rgba(6, 43, 84, .28);
}

.lang-btn .flag {
  width: 24px; height: 16px; flex: none; display: block;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(8, 32, 58, .28);
  opacity: .55;
  transition: opacity .14s ease;
}
.lang-btn.is-active .flag,
.lang-btn:hover .flag { opacity: 1; }

.brand-mark {
  width: 42px; height: 42px; flex: none;
  display: grid; place-items: center;
  border-radius: 13px;
  background: rgba(255, 255, 255, .16);
  border: 1px solid rgba(255, 255, 255, .28);
  font-weight: 800; font-size: 15px; letter-spacing: .5px;
}

/* min-width: 0 — sans cela un titre en nowrap refuse de rétrécir et pousse
   le sélecteur de langue hors de l'écran sur les petits téléphones */
.brand-text { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
/* le titre s'adapte à la largeur pour rester sur une seule ligne,
   des petits iPhone jusqu'au bureau */
.brand-title {
  font-size: clamp(13px, 4.2vw, 22px);
  letter-spacing: clamp(.2px, .3vw, 1.6px);
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;   /* filet de sécurité */
}
.brand-sub {
  font-size: 13px; color: rgba(255, 255, 255, .82); letter-spacing: .2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.pickers { display: grid; gap: 14px; }

.field-label {
  display: block;
  font-size: 12.5px; font-weight: 700; letter-spacing: .7px; text-transform: uppercase;
  color: rgba(255, 255, 255, .8);
  margin-bottom: 6px;
}

.field-help { margin: 6px 2px 0; font-size: 12.5px; color: rgba(255, 255, 255, .7); }

/* select ------------------------------------------------------------------ */
.select-wrap { position: relative; }

.select {
  -webkit-appearance: none; appearance: none;
  width: 100%; min-height: var(--tap);
  padding: 13px 44px 13px 16px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: var(--card); color: var(--text);
  font-size: 16px; font-weight: 600;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
.select:focus { border-color: var(--emerald); }

.select-arrow {
  position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
  color: var(--primary-blue); font-size: 15px; pointer-events: none;
}

/* recherche --------------------------------------------------------------- */
.search-wrap { position: relative; display: flex; align-items: center; }

.search-icon {
  position: absolute; left: 15px; display: flex;
  color: var(--primary-blue); pointer-events: none;
}

.search-input {
  width: 100%; min-height: var(--tap);
  padding: 13px 46px 13px 45px;
  border: 1px solid transparent; border-radius: var(--radius);
  background: var(--card); color: var(--text);
  font-size: 16px; font-family: inherit;
  box-shadow: var(--shadow-sm);
  -webkit-appearance: none; appearance: none;
}
.search-input::placeholder { color: #8ea0b6; }
.search-input:focus { border-color: var(--emerald); outline: none; box-shadow: 0 0 0 3px rgba(16, 185, 129, .35); }
.search-input::-webkit-search-cancel-button { display: none; }

.clear-btn {
  position: absolute; right: 8px;
  width: 34px; height: 34px; border: 0; border-radius: 50%;
  background: var(--slate-soft); color: var(--muted);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.clear-btn:hover { background: var(--border); }

/* --- onglets ------------------------------------------------------------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: rgba(255, 255, 255, .96);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.tabs-inner { display: flex; gap: 4px; }

.tab {
  position: relative;
  flex: 1; min-height: 62px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: 0; background: none; cursor: pointer;
  color: var(--muted); font-size: 12px; font-weight: 600;
  border-radius: var(--radius-sm);
}
.tab svg { width: 22px; height: 22px; }
.tab.is-active { color: var(--primary-blue); }
.tab.is-active svg { stroke-width: 2.4; }

.tab-badge {
  position: absolute; top: 8px; left: 50%; margin-left: 6px;
  min-width: 18px; height: 18px; padding: 0 5px;
  display: grid; place-items: center;
  border-radius: 9px; background: var(--emerald); color: #fff;
  font-size: 11px; font-weight: 700;
}

/* --- contenu ------------------------------------------------------------- */
.main { padding-top: 20px; padding-bottom: 24px; }
.view { animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.results-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.results-title { font-size: 14px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); }
.results-count { font-size: 13px; font-weight: 600; color: var(--muted); }

.section-title { font-size: 20px; font-weight: 800; letter-spacing: -.2px; }
.section-sub { margin: 4px 0 18px; color: var(--muted); font-size: 14px; }

.results { display: grid; gap: 12px; }

/* --- carte de résultat --------------------------------------------------- */
.card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: center;
  width: 100%;
  padding: 16px;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.card:hover { transform: translateY(-1px); box-shadow: var(--shadow); border-color: var(--border-strong); }
.card:active { transform: translateY(0) scale(.995); }

.code-badge {
  width: 78px; height: 78px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--code-grad);
  color: #fff;
  font-weight: 800; font-size: 21px; letter-spacing: .4px;
  box-shadow: 0 4px 14px rgba(21, 101, 192, .34);
}
.code-badge--len5 { font-size: 18px; }
/* le cercle de la fiche s'adapte à la hauteur d'écran disponible (iPhone SE
   comme iPad) pour que toute la fiche tienne sans défilement */
.code-badge--lg {
  width: clamp(86px, 22vh, 122px); height: clamp(86px, 22vh, 122px);
  font-size: clamp(24px, 6vh, 33px);
  box-shadow: 0 8px 24px rgba(21, 101, 192, .32);
}
.code-badge--lg.code-badge--len5 { font-size: clamp(20px, 5vh, 28px); }

.card-body { min-width: 0; display: grid; gap: 7px; }

/* break-word et non anywhere : un mot n'est coupé que s'il ne tient pas seul
   sur une ligne (« Ventilateurs » ne doit jamais devenir « Ve / ntilateurs ») */
.card-title {
  font-size: 16px; font-weight: 700; line-height: 1.3;
  overflow-wrap: break-word;
}
.card-context { font-size: 13.5px; color: var(--muted); overflow-wrap: break-word; }
.card-extra { font-size: 12.5px; font-weight: 700; color: var(--primary-blue); }
.card-title em, .detail-row dd em { color: var(--muted); font-weight: 500; }
.card-body > .status-chip { justify-self: start; }
.sheet-status { display: flex; justify-content: center; }
.card-category {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; letter-spacing: .3px;
  color: var(--primary-blue-dark);
}
.cat-key {
  display: inline-grid; place-items: center;
  min-width: 26px; padding: 1px 5px;
  border-radius: 6px; background: var(--primary-blue-soft);
  color: var(--primary-blue-dark);
  font-size: 11px; font-weight: 700; letter-spacing: .5px;
}

mark { background: #fff3bf; color: inherit; border-radius: 3px; padding: 0 1px; }

/* --- pastille de statut -------------------------------------------------- */
.status-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px 5px 8px;
  border-radius: 999px;
  font-size: 12px; font-weight: 800; letter-spacing: .5px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.status-chip .st-icon { display: flex; }
.status-chip .st-icon svg { width: 15px; height: 15px; }

.status-chip--lg { font-size: 13.5px; padding: 8px 16px 8px 12px; }
.status-chip--lg .st-icon svg { width: 18px; height: 18px; }

.status-abo        { background: var(--emerald-soft); color: var(--emerald-dark); border-color: #b9ead6; }
.status-facturer   { background: var(--amber-soft);   color: var(--amber);        border-color: #f6d3bf; }
.status-validation { background: var(--violet-soft);  color: var(--violet);       border-color: #d9cbf6; }
.status-inconnu    { background: var(--slate-soft);   color: var(--muted);        border-color: var(--border-strong); }

/* --- états --------------------------------------------------------------- */
.state {
  display: none;
  padding: 34px 22px;
  text-align: center;
  background: var(--card);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--muted);
}
.state.is-visible { display: block; }
.state .state-icon { font-size: 30px; line-height: 1; margin-bottom: 10px; }
.state .state-title { font-size: 17px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.state .state-text { font-size: 14px; max-width: 34ch; margin: 0 auto; }

/* --- catégories ---------------------------------------------------------- */
.category-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; }

.cat-card {
  display: flex; flex-direction: column; gap: 8px;
  min-height: 108px; padding: 15px;
  background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer; text-align: left;
  transition: transform .12s ease, box-shadow .12s ease;
}
.cat-card:hover { transform: translateY(-1px); box-shadow: var(--shadow); }

.cat-key-lg {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 11px; background: var(--primary-blue-soft); color: var(--primary-blue-dark);
  font-weight: 800; font-size: 13px; letter-spacing: .5px;
}
.cat-name { font-size: 14.5px; font-weight: 700; line-height: 1.25; }
.cat-count { font-size: 12.5px; color: var(--muted); }

.back-btn {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 40px; margin-bottom: 12px; padding: 0 4px;
  border: 0; background: none; cursor: pointer;
  color: var(--primary-blue); font-size: 14px; font-weight: 700;
}

/* --- pied de page -------------------------------------------------------- */
.app-footer { padding: 4px 0 20px; }
.footer-inner { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }

.offline-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 600; color: var(--muted);
  box-shadow: var(--shadow-sm);
}
.offline-badge .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); flex: none; }
.offline-badge.is-ready { color: var(--emerald-dark); border-color: #b9ead6; background: var(--emerald-soft); }
.offline-badge.is-ready .dot { background: var(--emerald); }
.offline-badge.is-offline { color: var(--primary-blue-dark); border-color: #bcd6f2; background: var(--primary-blue-soft); }
.offline-badge.is-offline .dot { background: var(--primary-blue); }

.data-meta { font-size: 11.5px; color: #93a4b8; }

/* --- fiche détaillée ----------------------------------------------------- */
/* La fiche est centrée et tient dans un seul écran, y compris sur iPhone.
   dvh (et non vh) : sur iOS Safari, vh ignore la barre d'outils et la fiche
   passerait sous le bord bas de l'écran. */
.sheet {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
}
.sheet[hidden] { display: none; }

.sheet-backdrop { position: absolute; inset: 0; background: rgba(8, 32, 58, .5); animation: fade .16s ease; }

.sheet-panel {
  position: relative; z-index: 1;
  width: 100%; max-width: 560px;
  max-height: 96vh;
  max-height: 96dvh;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 18px 18px 20px;
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: rise .22s cubic-bezier(.22, 1, .36, 1);
}
@keyframes rise { from { transform: translateY(18px); opacity: .6; } to { transform: none; opacity: 1; } }

.sheet-close {
  position: absolute; top: 10px; right: 10px;
  width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: var(--slate-soft); color: var(--muted);
  font-size: 22px; line-height: 1; cursor: pointer;
}

.sheet-body { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.detail-list { width: 100%; margin: 4px 0 0; display: grid; }

/* Mobile : libellé au-dessus de la valeur — la description dispose ainsi de
   toute la largeur et ne se coupe plus en plein mot. */
.detail-row {
  display: grid; grid-template-columns: 1fr; gap: 2px;
  padding: 9px 2px; border-top: 1px solid var(--border);
}
.detail-row dt { font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); }
.detail-row dd { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.35; overflow-wrap: break-word; }
/* description et catégorie : une partie par ligne */
.detail-row dd .path-part { display: block; }
.detail-row dd .path-part .cat-key { margin-bottom: 3px; }
.detail-row dd .path-part:not(.path-part--last) {
  font-size: 13px; font-weight: 700; letter-spacing: .3px;
  color: var(--muted);
  margin-bottom: 1px;
}

@media (min-width: 560px) {
  .sheet-panel { padding: 24px 24px 26px; }
  .sheet-body { gap: 13px; }
  .detail-row {
    grid-template-columns: 132px 1fr; gap: 14px; align-items: baseline;
    padding: 12px 2px;
  }
  .detail-row dt { font-size: 12px; }
}

.sheet-note {
  width: 100%; padding: 10px 12px;
  background: var(--slate-soft); border-radius: var(--radius-sm);
  font-size: 12.5px; line-height: 1.35; color: var(--muted);
}

.fav-btn {
  width: 100%; min-height: 46px; margin-top: 2px;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--card); color: var(--primary-blue-dark);
  font-size: 15px; font-weight: 700; cursor: pointer;
}
.fav-btn .fav-star { color: var(--border-strong); font-size: 18px; }
.fav-btn[aria-pressed="true"] { background: var(--emerald-soft); border-color: #b9ead6; color: var(--emerald-dark); }
.fav-btn[aria-pressed="true"] .fav-star { color: var(--emerald); }

/* --- tablette / bureau --------------------------------------------------- */
/* très petits écrans : on resserre pour garder « SERVICE CODING » sur une ligne */
@media (max-width: 420px) {
  .brand { gap: 10px; }
  .brand-mark { width: 38px; height: 38px; border-radius: 12px; font-size: 14px; }
  .brand-sub { font-size: 12px; }
  .lang-switch { padding: 3px; gap: 2px; }
  .lang-btn { width: 38px; height: 36px; }
  .lang-btn .flag { width: 22px; height: 15px; }
}

@media (min-width: 720px) {
  body { padding-bottom: 0; }

  .app-header { padding-top: 26px; padding-bottom: 26px; }
  .brand-title { font-size: 22px; }
  .pickers { grid-template-columns: minmax(230px, 300px) 1fr; align-items: start; gap: 18px; }

  .tabs {
    position: static; background: none; backdrop-filter: none; border: 0;
    padding: 18px 0 0;
  }
  .tabs-inner {
    gap: 8px; max-width: 880px;
    background: var(--card); border: 1px solid var(--border);
    border-radius: 999px; padding: 5px; box-shadow: var(--shadow-sm);
  }
  .tab { flex-direction: row; gap: 8px; min-height: 44px; font-size: 14px; border-radius: 999px; }
  .tab.is-active { background: var(--primary-blue-soft); }
  .tab-badge { position: static; margin: 0; }

  .main { padding-top: 22px; }

  .card { padding: 18px 22px; gap: 20px; }
  .code-badge { width: 86px; height: 86px; font-size: 23px; }
  .code-badge--len5 { font-size: 19px; }

  .sheet { padding: 24px; }
}

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