/* ==========================================================================
   Portail Photo — Design System "Portail Pro"
   Épuré, responsive, sombre par défaut, zéro dépendance externe.
   ========================================================================== */

:root {
  --bg: #0f1115;
  --bg-elevated: #171a21;
  --bg-card: #1c2029;
  --border: #2a2f3a;
  --text: #eef0f4;
  --text-muted: #9198a8;
  --accent: #5b8def;
  --accent-hover: #78a3f5;
  --success: #37c26b;
  --danger: #e5525a;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

/* Garantit que l'attribut HTML `hidden` masque TOUJOURS l'élément, même si une règle plus bas
   (ex. .modal, .lightbox) lui donne par ailleurs `display: flex`. Sans ce filet de sécurité, une
   feuille de style d'auteur peut neutraliser silencieusement `hidden`, laissant modales et
   visionneuse affichées en permanence par-dessus tout le reste. */
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
h1, h2 { margin: 0 0 12px; font-weight: 650; letter-spacing: -0.01em; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 14px; font-weight: 550;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .05s ease;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #0b0f16; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-card); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--bg-card); color: var(--text); }
.btn-block { width: 100%; justify-content: center; }
.btn-upload { position: relative; overflow: hidden; }

/* ---------- Barre supérieure ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.topbar-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.brand-mark, .login-brand-mark { color: var(--accent); font-size: 18px; }
.breadcrumb { flex: 1; display: flex; gap: 6px; align-items: center; overflow-x: auto; font-size: 14px; color: var(--text-muted); }
.breadcrumb a, .breadcrumb span { white-space: nowrap; }
.breadcrumb .crumb-sep { opacity: .4; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.user-chip {
  display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2;
  padding: 4px 10px; border-radius: var(--radius); background: var(--bg-card); border: 1px solid var(--border);
}
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Explorateur ---------- */
.explorer { padding: 18px 20px 60px; max-width: 1400px; margin: 0 auto; }
.explorer-toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }

.upload-progress {
  flex: 1 1 200px; height: 8px; background: var(--bg-card); border-radius: 999px; position: relative; overflow: hidden;
  border: 1px solid var(--border);
}
.upload-progress-bar { height: 100%; width: 0%; background: var(--accent); transition: width .15s ease; }
.upload-progress-label { position: absolute; right: 0; top: -22px; font-size: 12px; color: var(--text-muted); }

.dropzone { position: relative; min-height: 200px; border-radius: var(--radius-lg); transition: background .15s ease; }
.dropzone.drag-over { background: rgba(91, 141, 239, 0.08); outline: 2px dashed var(--accent); outline-offset: -8px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}

.tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .1s ease, border-color .15s ease;
  position: relative;
}
.tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.tile-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  background: #12151b center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; color: var(--text-muted);
}
.tile-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-label { padding: 8px 10px; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.tile-label .icon { opacity: .7; }
.tile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tile.vote-yes { box-shadow: 0 0 0 3px var(--success), var(--shadow); }
.tile.vote-no { box-shadow: 0 0 0 3px var(--danger), var(--shadow); }

.tile-download {
  position: absolute; bottom: 44px; right: 8px;
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(15,17,21,.85); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text); font-size: 14px;
  opacity: .85; transition: opacity .15s ease, background .15s ease;
}
.tile-download:hover { opacity: 1; background: rgba(15,17,21,1); }

.empty-state, .loading-state { text-align: center; color: var(--text-muted); padding: 60px 0; }

/* ---------- Menu contextuel ---------- */
.context-menu {
  position: fixed; z-index: 100;
  list-style: none; margin: 0; padding: 6px;
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); min-width: 170px;
}
.context-menu li { padding: 8px 12px; border-radius: 6px; font-size: 14px; cursor: pointer; }
.context-menu li:hover { background: var(--bg-elevated); }
.context-menu li.danger { color: var(--danger); }
.context-menu li[aria-disabled="true"] { opacity: .35; cursor: not-allowed; pointer-events: none; }

/* ---------- Lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; background: rgba(6,7,10,.96); z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-image { max-width: 88vw; max-height: 80vh; border-radius: 6px; box-shadow: var(--shadow); }
.lightbox-close { position: absolute; top: 18px; right: 22px; background: none; border: none; color: var(--text); font-size: 22px; cursor: pointer; }
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,.08); border: none; color: var(--text);
  width: 46px; height: 46px; border-radius: 50%; font-size: 26px; cursor: pointer;
}
.lightbox-prev { left: 20px; } .lightbox-next { right: 20px; }
.lightbox-nav:hover { background: rgba(255,255,255,.18); }

.vote-bar { display: flex; gap: 10px; background: var(--bg-card); padding: 10px; border-radius: 999px; border: 1px solid var(--border); }
.vote-btn { border: none; border-radius: 999px; padding: 10px 18px; font-weight: 600; cursor: pointer; font-size: 14px; }
.vote-yes { background: var(--success); color: #06210f; }
.vote-no { background: var(--danger); color: #2b0608; }
.vote-neutral { background: var(--bg-elevated); color: var(--text-muted); border: 1px solid var(--border); }
.vote-btn.active { outline: 2px solid var(--text); }

/* ---------- Contrôles de la visionneuse (vote + note en étoiles), empilés en bas ---------- */
.lightbox-controls { position: absolute; bottom: 30px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.star-rating {
  display: flex; gap: 4px; background: var(--bg-card); padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--border);
}
.star { font-size: 22px; line-height: 1; color: var(--border); cursor: default; user-select: none; }
.star-rating[data-editable="1"] .star { cursor: pointer; transition: transform .1s, color .1s; }
.star-rating[data-editable="1"] .star:hover { transform: scale(1.15); color: #f5b942; }
.star.filled { color: #f5b942; }

/* Petit badge d'étoiles sur chaque vignette de la grille (lecture seule) */
.tile-rating {
  position: absolute; bottom: 4px; left: 4px; font-size: 11px; color: #f5b942;
  background: rgba(0,0,0,.55); padding: 1px 5px; border-radius: 4px; letter-spacing: 1px;
}

/* ---------- Modales ---------- */
.modal { position: fixed; inset: 0; background: rgba(6,7,10,.7); display: flex; align-items: center; justify-content: center; z-index: 150; }
.modal-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 22px; width: 360px; box-shadow: var(--shadow); }
.modal-card input, .modal-card select {
  width: 100%; padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); margin-top: 10px; font-size: 14px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Toasts ---------- */
.toast-container { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 300; }
.toast { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; font-size: 14px; box-shadow: var(--shadow); animation: toast-in .15s ease; }
.toast.error { border-color: var(--danger); color: #ffb3b6; }
.toast.success { border-color: var(--success); color: #b7f0cb; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Connexion ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: radial-gradient(circle at top, #191d27, var(--bg)); }
.login-card { width: 360px; background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px; box-shadow: var(--shadow); }
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand p { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
.login-form input {
  padding: 11px 12px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); font-size: 14px;
}
.login-form input:focus { outline: none; border-color: var(--accent); }
.login-footnote { margin-top: 18px; font-size: 11.5px; color: var(--text-muted); text-align: center; line-height: 1.5; }
.alert { padding: 10px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; }
.alert-error { background: rgba(229,82,90,.12); color: #ffb3b6; border: 1px solid rgba(229,82,90,.3); }

/* ---------- Page contrat ---------- */
.contract-page { max-width: 1080px; margin: 40px auto; padding: 0 20px; }
.contract-layout { display: grid; grid-template-columns: 300px 1fr; gap: 20px; align-items: start; }
.contract-sidebar { display: flex; flex-direction: column; gap: 20px; position: sticky; top: 20px; }
.contract-main { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
@media (max-width: 800px) {
  .contract-layout { grid-template-columns: 1fr; }
  .contract-sidebar { position: static; order: 2; }
  .contract-main { order: 1; }
}
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; }

.admin-warning-banner {
  max-width: 1080px; margin: 16px auto 0; padding: 12px 20px;
  background: rgba(224,169,48,.12); border: 1px solid rgba(224,169,48,.4);
  border-radius: var(--radius); color: #e0a930; font-size: 13px; line-height: 1.5;
}
.admin-warning-banner code { background: rgba(0,0,0,.25); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.stacked-form { display: flex; flex-direction: column; gap: 12px; }
.stacked-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
.stacked-form input, .stacked-form textarea {
  padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); font-size: 14px; font-family: inherit;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { min-width: 0; }
.form-sep { border: none; border-top: 1px solid var(--border); margin: 6px 0; }
.checkbox-row {
  display: flex; align-items: flex-start; gap: 10px; font-size: 13px; color: var(--text);
  cursor: pointer; padding: 2px 0;
}
.checkbox-row input[type="checkbox"] { margin-top: 3px; width: 16px; height: 16px; flex-shrink: 0; accent-color: var(--accent); }
.checkbox-row span { line-height: 1.4; }

.history-row {
  display: flex; flex-direction: column; gap: 8px; padding: 10px 0;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.history-row:last-child { border-bottom: none; }
.history-row-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.history-date { color: var(--text); font-weight: 550; }
.history-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.history-main .history-title { font-size: 14px; color: var(--text); overflow-wrap: anywhere; }
.history-main .history-date { font-size: 12.5px; color: var(--text-muted); font-weight: 400; }
.history-badge { padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.history-badge.signed { background: rgba(55,194,107,.15); color: var(--success); }
.history-badge.pending { background: rgba(224,169,48,.15); color: #e0a930; }
.muted { color: var(--text-muted); font-size: 13px; }
.model-group { padding: 14px 0; border-bottom: 1px solid var(--border); }
.model-group:last-child { border-bottom: none; }
.model-group-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; gap: 8px; }
.model-group-header strong { font-size: 14px; }
.contract-row-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.contract-row-actions .btn { padding: 4px 9px; font-size: 12px; }

/* ---------- Modale de confirmation maison (remplace confirm() natif du navigateur, qui affiche
   toujours l'adresse IP/domaine du site — moins clair et moins soigné pour l'utilisateur) ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 22px; max-width: 400px; width: 100%;
}
.modal-box p { margin: 0 0 18px; font-size: 14px; line-height: 1.5; color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Sélecteur de brouillon (modèle ayant plusieurs contrats en attente) ---------- */
.draft-picker { margin-bottom: 18px; padding-bottom: 18px; border-bottom: 1px solid var(--border); }
.draft-picker-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.draft-pill {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text); cursor: pointer; font-size: 13px; font-weight: 550;
}
.draft-pill:hover { border-color: var(--accent); }
.draft-pill.selected { border-color: var(--accent); background: rgba(91,141,239,.16); color: var(--accent-hover); }
.session-summary {
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin: 16px 0; font-size: 13px; line-height: 1.7;
}
.session-summary dt { color: var(--text-muted); display: inline; }
.session-summary dd { display: inline; margin: 0 16px 0 4px; color: var(--text); font-weight: 550; }
.feedback { margin-top: 12px; font-size: 13px; }
#signature-pad { width: 100%; max-width: 500px; background: #fff; border-radius: var(--radius); touch-action: none; margin-top: 14px; }
.sign-actions { display: flex; gap: 10px; margin-top: 14px; }

@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; }
  .breadcrumb { order: 3; width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}
