/* Soleco Apps — système de style commun (repris de la page Base de Données v2).
   Une classe par composant. Pour changer une couleur : le token.
   Chargé par toutes les pages : <link rel="stylesheet" href="/shared/base.css">
   Chaque page ajoute ensuite son <style> pour ses composants propres.
   Les couleurs pilotées depuis « Gestion de la page » du portail sont injectées
   à l'exécution par shared/auth.js (style#cfg-css). */

:root {
  --bg:            #f4f5f7;
  --surface:       #ffffff;
  --surface-2:     #eef0f3;
  --surface-sunk:  #f8f9fb;
  --text:          #1c1e21;
  --muted:         #6b7280;
  --border:        #d9dce1;
  --border-strong: #b9bec6;
  --accent:        #b8860b;
  --accent-weak:   rgba(184, 134, 11, 0.12);
  --accent-text:   #ffffff;
  --ok:            #1a7f37;
  --ok-weak:       rgba(26, 127, 55, 0.12);
  --danger:        #c1362e;
  --danger-weak:   rgba(193, 54, 46, 0.12);
  --warn:          #e07a1f;
  --info:          #2f7fd4;
  --focus:         rgba(184, 134, 11, 0.35);
  --shadow:        0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.08);
  --radius:        10px;
  --radius-sm:     7px;
  --radius-pill:   999px;
  --btn-ok:            #1a7f37;
  --btn-ok-texte:      #ffffff;
  --btn-annuler:       #c1362e;
  --btn-annuler-texte: #ffffff;
  --btn-lien:          #fcdc49;
  --btn-lien-texte:    #181818;
  --statut-ok:   #2e9e4f;
  --statut-info: #2f7fd4;
  --statut-warn: #e07a1f;
  --statut-off:  #8b8b8b;
  --badge-texte: #b8860b;
  --font:          -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --nav-w:         58px;
  --nav-w-open:    210px;
  --brand-w:       520px;
  --head-h:        88px;
}
:root[data-theme="dark"] {
  --bg:#161616; --surface:#1e1e1e; --surface-2:#262626; --surface-sunk:#141414;
  --text:#ededed; --muted:#a8a8a8; --border:rgba(255,255,255,.10);
  --border-strong:rgba(255,255,255,.20); --accent:#fcdc49;
  --accent-weak:rgba(252,220,73,.14); --accent-text:#181818;
  --ok:#7fe3a4; --ok-weak:rgba(52,199,89,.16);
  --danger:#ff8b7b; --danger-weak:rgba(255,139,123,.16);
  --warn:#ff9f1c; --info:#3d8bff;
  --focus:rgba(252,220,73,.30);
  --shadow:0 1px 2px rgba(0,0,0,.4),0 18px 40px rgba(0,0,0,.35);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#161616; --surface:#1e1e1e; --surface-2:#262626; --surface-sunk:#141414;
    --text:#ededed; --muted:#a8a8a8; --border:rgba(255,255,255,.10);
    --border-strong:rgba(255,255,255,.20); --accent:#fcdc49;
    --accent-weak:rgba(252,220,73,.14); --accent-text:#181818;
    --ok:#7fe3a4; --ok-weak:rgba(52,199,89,.16);
    --danger:#ff8b7b; --danger-weak:rgba(255,139,123,.16);
    --warn:#ff9f1c; --info:#3d8bff;
    --focus:rgba(252,220,73,.30);
    --shadow:0 1px 2px rgba(0,0,0,.4),0 18px 40px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: var(--fs, 14px); line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-weight: 700; }
img { max-width: 100%; }

/* ===== COQUILLE : brand fixe + barre latérale rail + topbar ===== */
.sidebar {
  position: fixed; left: 0; top: var(--head-h); bottom: 0; z-index: 20;
  width: var(--nav-w);
  background: var(--surface); border-right: 1px solid var(--border);
  overflow: hidden; transition: width .16s ease;
  display: flex; flex-direction: column;
}
.sidebar:hover, .sidebar.open { width: var(--nav-w-open); overflow-y: auto; box-shadow: var(--shadow); }
.sidebar.hidden { display: none; }
.sidebar__logo {
  position: fixed; left: 0; top: 0; z-index: 25;
  width: var(--brand-w); height: var(--head-h);
  display: flex; align-items: center; gap: 14px;
  padding: 12px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.sidebar__logo img { width: 84px; height: 58px; flex: 0 0 84px; object-fit: contain; }
.brand__text { display: grid; gap: 5px; min-width: 0; }
.sidebar__title {
  font-weight: 800; font-size: 25px; line-height: 1.05;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.nav { padding: 8px 7px; display: grid; gap: 2px; grid-template-columns: minmax(0, 1fr); }
.nav__btn {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-width: 0; overflow: hidden;
  appearance: none; border: 0; cursor: pointer; font: inherit;
  padding: 10px 9px 10px 12px; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); font-weight: 700;
  white-space: nowrap; text-align: left;
}
.nav__btn:hover { background: var(--surface-2); color: var(--text); }
.nav__btn.active { background: var(--accent); color: var(--accent-text); }
.nav__btn svg { flex: 0 0 22px; width: 22px; height: 22px; }
.nav__label { opacity: 0; transition: opacity .12s; }
.sidebar:hover .nav__label, .sidebar.open .nav__label { opacity: 1; }
.sidebar:not(:hover):not(.open) .nav__label { display: none; }

.app { min-height: 100vh; padding-left: var(--nav-w); display: flex; flex-direction: column; }
.app--nonav { padding-left: 0; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 14px;
  min-height: var(--head-h);
  padding: 14px 20px 14px calc(var(--brand-w) - var(--nav-w) + 24px);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.app--nonav .topbar { padding-left: calc(var(--brand-w) + 24px); }
.topbar__title {
  display: block;
  font-size: 13px; font-weight: 400; line-height: 1.2;
  color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar__spacer { flex: 1; }
.topbar__status, #status { font-size: 12px; color: var(--muted); text-align: right; max-width: 34vw; }
.topbar__user, #who { font-size: 12px; color: var(--muted); white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; }
#who b { color: var(--text); }
.version, #sideVersion {
  font-size: 10px; color: var(--muted);
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: 2px 8px; white-space: nowrap;
  align-self: flex-start; margin: auto 7px 10px;
}
.topsearch { position: relative; }
.topsearch input {
  width: 520px; max-width: 48vw; padding: 10px 12px; font-size: 14px;
  border-radius: var(--radius-sm);
}
.content { padding: 18px 20px 40px; width: 100%; }

/* ===== COMPOSANTS ===== */
/* Code couleur des boutons (toutes les pages) :
   - gris  (défaut)        : modifier, actualiser, filtrer, neutre
   - vert  .btn--ok        : sauvegarder, enregistrer, valider
   - rouge .btn--danger    : annuler, fermer, supprimer
   - jaune .btn--primary   : boutons de formulaire, action principale
   - jaune .btn--lien      : lien externe (Google Maps…), aller à une autre page  */
button, .btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 700;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  transition: filter .12s;
}
button:hover, .btn:hover { filter: brightness(1.05); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn:disabled { opacity: .5; cursor: default; transform: none; }
button.primary, .btn--primary,
button.small.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.small, .btn--sm { padding: 5px 10px; font-size: 12px; }
.btn--ok, .btn--enregistrer { background: var(--ok-weak); color: var(--ok); border-color: var(--ok); }
.btn--danger, .btn--annuler { background: var(--danger-weak); color: var(--danger); border-color: var(--danger); }
.btn--lien    { background: var(--btn-lien); color: var(--btn-lien-texte); border-color: var(--btn-lien); }
.btn--ghost   { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.iconbtn {
  appearance: none; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  font-size: 15px; line-height: 1; display: grid; place-items: center; padding: 0;
}
.iconbtn:hover { filter: brightness(1.06); }

input, select, textarea, .input, .select, .textarea {
  width: 100%; font: inherit; color: var(--text);
  padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-sunk);
  outline: none;
}
textarea, .textarea { min-height: 60px; resize: vertical; }
input:focus, select:focus, textarea:focus,
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
input[readonly], textarea[readonly], .input[readonly], .textarea[readonly] {
  border-color: var(--border); background: transparent; color: var(--muted); cursor: default;
}
input[type="checkbox"], input[type="radio"] { width: auto; }
input[type="color"] { padding: 2px; height: 34px; }
select.appswitch, .topsearch select { width: auto; max-width: 200px; min-height: 32px; padding: 4px 8px; font-size: 12px; }

.fieldgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px 16px; }
.field { display: grid; gap: 5px; min-width: 0; }
.field--wide { grid-column: 1 / -1; }
.label { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .02em; }
label.f { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.hidden { display: none !important; }
[hidden] { display: none !important; }
.err { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 1em; }
.sub { color: var(--muted); font-size: 13px; }
.lnk { color: var(--accent); cursor: pointer; font-size: 13px; }
/* liens cliquables (téléphones, e-mails, liens externes) : jaune, pas le bleu navigateur */
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a.lien-tel, a.lien-mail { color: var(--accent); }
h2.sec { margin: 0 0 14px; font-size: 18px; }
h3.grp { font-size: 13px; margin: 18px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

.page-head { margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 21px; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.pagerow { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.pagerow .card__count { font-weight: 700; color: var(--text); }
.subtabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.subtabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; padding: 8px 4px; color: var(--muted); border-radius: 0; }
.subtabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 700; }

/* ===== cartes ===== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 16px; overflow: hidden;
}
.card__head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.card__title { font-size: 15px; }
.card__count { font-size: 12px; color: var(--muted); }
.card__actions { margin-left: auto; display: flex; gap: 8px; flex-shrink: 0; }
.card__body { padding: 16px; }
.card__body--flush { padding: 0; }

/* cartes « en cours » (msg collationnés / accès sur sites) : MÊME taille partout */
.edfCards, .accessCards {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(272px, 300px));
  gap: 10px; margin-bottom: 16px; justify-content: start;
}
.edfCard, .accessCard {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--accent); border-radius: var(--radius-sm);
  padding: 12px; min-height: 108px; cursor: pointer;
}
.edfCard:hover, .accessCard:hover { border-color: var(--accent); }
.edfCard__head, .accessCard__head { display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 6px; }
.edfCard h4, .accessCard h4 { font-size: 14px; margin: 0; }
.edfCard .meta, .accessCard .meta { display: flex; flex-wrap: wrap; gap: 4px 12px; color: var(--muted); font-size: 12px; }

/* carte de connexion (shared/auth.js) — dans #gate, prime sur .card des pages */
#gate .card { max-width: 420px; margin: 6vh auto 0; padding: 24px; border-left: 1px solid var(--border); }
#gate .card h2 { margin: 0 0 4px; }
.jg { display: flex; gap: 4px; margin-top: 6px; }
.jg i { flex: 1; height: 6px; border-radius: 999px; background: var(--border); }
.jg i.on { background: #e0a83b; } .jg i.on.s3 { background: #6bbf59; } .jg i.on.s4 { background: #3a9d3a; }

/* ===== tables ===== */
.tablewrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table, .table { width: 100%; border-collapse: collapse; }
table { font-size: 13px; }
.table th, .table td, table th, table td {
  padding: 8px 12px; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.table th, table th {
  background: var(--surface-2); color: var(--muted);
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700;
  white-space: nowrap;
}
.table th { position: sticky; top: 0; z-index: 1; cursor: pointer; user-select: none; }
.table th .tri { margin-left: 5px; font-size: 9px; letter-spacing: -1px; color: var(--border); }
.table th .tri b { color: var(--accent); font-weight: 400; }
.table th:hover .tri { color: var(--muted); }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.centre, .table td.centre { text-align: center; }
.table tr.filtre td { padding: 4px 6px; background: var(--surface-sunk); position: sticky; top: 33px; z-index: 1; }
.table tr:last-child td { border-bottom: none; }
.table--rows tbody tr.ligne { cursor: pointer; }
.table--rows tbody tr.ligne:hover, tbody tr:hover { background: var(--accent-weak); }
.input--f {
  padding: 4px 8px 4px 24px; font-size: 12px; border-radius: 5px;
  background-image: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 5h18l-7 8v6l-4 2v-8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 6px center; background-size: 12px;
}

/* ===== petits composants ===== */
.tag, .pill { display: inline-block; padding: 1px 7px; border-radius: var(--radius-pill); font-size: 11px; background: var(--surface-2); border: 1px solid var(--border); }
.tag.warn, .pill.warn { color: var(--danger); border-color: var(--danger); }
.tag.ok, .pill.ok { color: var(--ok); }
.badge { display: inline-block; padding: 2px 8px; border-radius: var(--radius-pill); background: var(--accent-weak); color: var(--badge-texte); font-size: 11px; font-weight: 700; }
.empty { padding: 14px 16px; border-radius: var(--radius-sm); background: var(--surface-sunk); color: var(--muted); font-size: 13px; text-align: center; }
.statut { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; font-size: 12px; font-weight: 700; }
.statut i { width: 11px; height: 11px; flex: 0 0 11px; border-radius: 50%; background: currentColor; }
.statut--ok { color: var(--statut-ok); } .statut--info { color: var(--statut-info); }
.statut--warn { color: var(--statut-warn); } .statut--off { color: var(--statut-off); }

.cfg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin: 8px 0 4px; }
.cfg-item { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

dialog {
  position: relative;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  color: var(--text); max-width: 480px; width: 92vw; padding: 20px; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2, dialog h3 { padding-right: 34px; }

.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(0,0,0,.5); padding: 16px; }
.modal__box { width: min(640px, 100%); max-height: 88vh; overflow: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; position: relative; }
.modal__box h3 { margin-bottom: 14px; padding-right: 34px; }
.modal__actions { display: flex; gap: 10px; align-items: center; justify-content: flex-end; flex-wrap: nowrap; margin-top: 16px; }
/* croix de fermeture : collée dans l'angle haut-droit, la croix elle-même est rouge */
.modal__close {
  appearance: none; cursor: pointer;
  position: absolute; top: 4px; right: 4px; width: 38px; height: 38px; padding: 0;
  border: 0; background: transparent; color: var(--danger);
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); line-height: 0;
}
.modal__close svg { display: block; width: 18px; height: 18px; }
.modal__close:hover { filter: brightness(1.2); }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 10px 16px; font-size: 13px; z-index: 60;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.toast.show { opacity: 1; }
.toast--ok { border-left-color: var(--ok); }
.toast--err { border-left-color: var(--danger); }

@media (max-width: 1200px) { .topsearch input { width: 320px; } }
@media (max-width: 980px)  { .topsearch input { width: 220px; max-width: 42vw; } }
@media (max-width: 700px) {
  .sidebar__logo { width: var(--nav-w); padding: 8px 9px; }
  .sidebar__logo img { width: 40px; height: 40px; flex-basis: 40px; }
  .brand__text { display: none; }
  .topbar, .app--nonav .topbar { padding-left: 20px; }
  .topbar__status, #status { display: none; }
  .content { padding: 12px 10px 40px; }
}
