/**
 * Styles démo : la dialog vit dans <body> (pas dans .r-root),
 * plus des filets de sécurité pour les tableaux de réception.
 */

/* ---------- Champs globaux (date / number / time / search) ---------- */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="search"],
textarea {
  min-height: 38px;
  padding: 0 0.65rem;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 10px;
  background-color: var(--bg-surface-2);
  color: var(--text-primary);
  font-size: 0.9375rem;
  line-height: 1.4;
  font-family: inherit;
}

textarea {
  min-height: 72px;
  padding: 0.55rem 0.65rem;
  resize: vertical;
}

input[type="color"] {
  width: 48px;
  height: 38px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-surface-2);
  cursor: pointer;
}

.r-root .lot-table td input[type="number"],
.r-root .lot-table td input[type="date"],
.r-root .lot-table td input[type="time"] {
  min-height: 32px;
  width: 100%;
  border-radius: var(--radius-small, 8px);
}

/* ---------- Modales hors .r-root (dialog #demo-modal) ---------- */
html[data-theme-dark="1"] dialog.universal-modal .modal-content {
  background: #131a26;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
  color: #e8ecf4;
}

html[data-theme-dark="1"] dialog.universal-modal .modal-header {
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

html[data-theme-dark="1"] dialog.universal-modal .modal-header h2 {
  color: #f4f7fb;
  font-size: 1.05rem;
  font-weight: 600;
}

html[data-theme-dark="1"] dialog.universal-modal .modal-header h2 i {
  color: #7c9cff;
}

html[data-theme-dark="1"] dialog.universal-modal .modal-close-btn {
  color: rgba(215, 223, 236, 0.7);
  background: transparent;
  border: none;
  box-shadow: none;
}

html[data-theme-dark="1"] dialog.universal-modal .modal-close-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #f4f7fb;
}

html[data-theme-dark="1"] dialog.universal-modal .modal-body,
html[data-theme-dark="1"] dialog.universal-modal .form-group label {
  color: rgba(215, 223, 236, 0.88);
}

html[data-theme-dark="1"] dialog.universal-modal .modal-body label,
html[data-theme-dark="1"] dialog.universal-modal .form-group label {
  color: rgba(157, 181, 255, 0.95);
  font-size: 0.8125rem;
  font-weight: 600;
}

html[data-theme-dark="1"] dialog.universal-modal .modal-body input,
html[data-theme-dark="1"] dialog.universal-modal .modal-body select,
html[data-theme-dark="1"] dialog.universal-modal .modal-body textarea {
  background: rgba(255, 255, 255, 0.04) !important;
  color: #edf2fa !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

html[data-theme-dark="1"] dialog.universal-modal .modal-body input::placeholder,
html[data-theme-dark="1"] dialog.universal-modal .modal-body textarea::placeholder {
  color: rgba(215, 223, 236, 0.45);
}

html[data-theme-dark="1"] dialog.universal-modal .modal-footer {
  background: rgba(0, 0, 0, 0.15);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.lots-modal .lots-modal__field {
  margin-bottom: var(--unit-3, 12px);
}

.lots-modal .lots-modal__field:last-child {
  margin-bottom: 0;
}

.lots-modal .lots-modal__input,
.lots-modal .lots-modal__body select,
.lots-modal .lots-modal__body input,
.lots-modal .lots-modal__body textarea {
  width: 100%;
  min-height: 40px;
  padding: 0 var(--unit-3, 12px);
  box-sizing: border-box;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  font-size: 0.9375rem;
  background: rgba(255, 255, 255, 0.04);
  color: #edf2fa;
}

html[data-theme-dark="0"] .lots-modal .lots-modal__input,
html[data-theme-dark="0"] .lots-modal .lots-modal__body select,
html[data-theme-dark="0"] .lots-modal .lots-modal__body input,
html[data-theme-dark="0"] .lots-modal .lots-modal__body textarea {
  background: #ffffff;
  color: #0d1117;
  border: 1px solid rgba(13, 17, 23, 0.14);
}

.lots-modal .lots-modal__input:focus,
.lots-modal .lots-modal__body select:focus,
.lots-modal .lots-modal__body input:focus,
.lots-modal .lots-modal__body textarea:focus {
  outline: none;
  border-color: rgba(124, 156, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(124, 156, 255, 0.16);
}

.lots-modal .lots-modal__footer {
  padding: var(--unit-3, 12px) var(--unit-4, 16px);
  gap: var(--unit-2, 8px);
}

.lots-modal .lots-modal__btn,
dialog.universal-modal .lots-modal__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 var(--unit-4, 16px);
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  box-shadow: none;
}

.lots-modal .lots-modal__btn--cancel,
dialog.universal-modal .lots-modal__btn--cancel {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.12);
  color: rgba(215, 223, 236, 0.88);
}

html[data-theme-dark="0"] .lots-modal .lots-modal__btn--cancel,
html[data-theme-dark="0"] dialog.universal-modal .lots-modal__btn--cancel {
  background: #eef0f4;
  border-color: rgba(13, 17, 23, 0.14);
  color: #1a1a1a;
}

.lots-modal .lots-modal__btn--cancel:hover,
dialog.universal-modal .lots-modal__btn--cancel:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #f4f7fb;
}

.lots-modal .lots-modal__btn--submit,
dialog.universal-modal .lots-modal__btn--submit {
  background: linear-gradient(180deg, #90adff 0%, #6f91ff 100%);
  color: #0d1420;
  font-weight: 600;
  box-shadow: 0 6px 16px rgba(111, 145, 255, 0.28);
}

html[data-theme-dark="0"] .lots-modal .lots-modal__btn--submit,
html[data-theme-dark="0"] dialog.universal-modal .lots-modal__btn--submit {
  background: #3e3b8c;
  color: #fff;
  box-shadow: none;
}

.lots-modal .lots-modal__btn--submit:hover,
dialog.universal-modal .lots-modal__btn--submit:hover {
  filter: brightness(1.06);
}

.lots-modal .lots-modal__btn--danger,
dialog.universal-modal .lots-modal__btn--danger {
  background: rgba(248, 113, 113, 0.14);
  border-color: rgba(248, 113, 113, 0.4);
  color: #fecaca;
  font-weight: 600;
}

html[data-theme-dark="0"] .lots-modal .lots-modal__btn--danger,
html[data-theme-dark="0"] dialog.universal-modal .lots-modal__btn--danger {
  background: rgba(220, 38, 38, 0.1);
  border-color: rgba(220, 38, 38, 0.35);
  color: #b91c1c;
}

/* Réception : boutons icône de ligne (filet de sécurité) */
.r-root .lot-table .btn-delete-row,
.r-root .lot-table .btn-remove-line {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-muted, #8b95a8);
  box-shadow: none;
}

.r-root .lot-table .btn-delete-row:hover,
.r-root .lot-table .btn-remove-line:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.18);
  border-color: rgba(248, 113, 113, 0.45);
  color: #fecaca;
}

html[data-theme-dark="0"] .r-root .lot-table .btn-delete-row,
html[data-theme-dark="0"] .r-root .lot-table .btn-remove-line {
  border-color: rgba(13, 17, 23, 0.14);
  color: #4b5563;
}

/* ---------- Choix de la version ---------- */
.version-choice {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: clamp(20px, 4vw, 36px);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-surface);
  color: var(--text-primary);
}

.version-choice::backdrop {
  background: var(--bg-base);
}

.version-choice__title {
  margin: 0 0 20px;
  color: var(--text-primary);
  font-size: clamp(1.25rem, 3vw, 1.625rem);
  line-height: 1.25;
}

.version-choice__options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}

.version-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  border: 1px solid var(--text-muted);
  border-radius: 12px;
  background: var(--bg-surface-2);
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.version-card:hover {
  border-color: var(--accent);
}

.version-card:focus-visible,
.version-choice__cancel:focus-visible,
.demo-banner button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.version-card__name {
  font-size: 1.125rem;
  font-weight: 700;
}

.version-card__text {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  line-height: 1.45;
}

.version-card__current {
  color: var(--text-primary);
  font-size: 0.8125rem;
  font-weight: 600;
}

.version-card__current[hidden] {
  display: none;
}

.version-choice__note {
  margin: 18px 0 4px;
  color: var(--text-primary);
  font-weight: 600;
}

.version-choice__hint {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.875rem;
  line-height: 1.45;
}

.version-choice__cancel {
  margin-top: 16px;
  min-height: 38px;
  padding: 0 16px;
  border: 1px solid var(--text-muted);
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
}

.version-choice__cancel[hidden] {
  display: none;
}

/* ---------- Bandeau de licence (repris du logiciel) ---------- */
.licence-banner {
  flex-shrink: 0;
  margin: 8px 16px 0;
  padding: 8px 16px;
  border: 1px solid var(--error);
  border-radius: 10px;
  background: var(--bg-surface-2);
  color: var(--text-primary);
  font-size: 0.875rem;
  line-height: 1.45;
}

.licence-banner[hidden] {
  display: none;
}

/* ---------- Premier lancement (version autonome) ---------- */
.setup-dialog {
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: clamp(18px, 4vw, 28px);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-surface);
  color: var(--text-primary);
}

.setup-dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

.setup-dialog__header h2 {
  margin: 0 0 8px;
  color: var(--text-primary);
}

.setup-dialog__header p {
  margin: 0 0 8px;
  color: var(--text-secondary);
}

.setup-dialog__demo {
  font-weight: 600;
}

/* ---------- Champs des Paramètres propres aux versions ---------- */
.demo-fieldset {
  min-width: 0;
  margin: 0 0 16px;
  padding: 0;
  border: 0;
}

.demo-fieldset > legend {
  padding: 0;
  margin-bottom: 8px;
  color: var(--text-primary);
  font-weight: 700;
}

.demo-folder {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  min-width: 0;
}

.demo-folder label {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.demo-folder input,
.demo-folder select {
  width: 100%;
  min-width: 0;
  min-height: 38px;
}

.demo-folder__row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.demo-folder__row input {
  flex: 1 1 200px;
  width: auto;
}

.demo-admin {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

#settingsTechnicienQuestion[hidden],
#settingsTechnicienEffacement [hidden] {
  display: none !important;
}

.notification {
  z-index: 40;
}

/* ---------- Contrastes (WCAG AA) ---------- */
html[data-theme-dark="1"] .inventaire-container .state-badge.state-HS {
  color: #ff8a80;
}

.pdf-preview .pdf-path {
  color: #4b5563 !important;
  opacity: 1;
}

html[data-theme-dark="0"] .inventaire-container .inventaire-stat__lbl {
  color: #4b5563;
  opacity: 1;
}

html[data-theme-dark="0"] body .r-root .historique-container .historique-lot-card .historique-lot-actions button.btn-to-recover {
  color: #14532d !important;
}

/* Filtres empilés : la base flexible ne doit pas devenir une hauteur */
@media (max-width: 640px) {
  body .r-root .recep-toolbar-compact .lot-config__field,
  body .r-root .recep-toolbar-compact .lot-config__field--search,
  body .r-root .recep-toolbar-compact .lot-config__actions {
    flex: 0 0 auto !important;
    height: auto !important;
    min-height: 0 !important;
  }
}

/* Prêts : champs d'en-tête empilés, sinon illisibles sur un téléphone */
@media (max-width: 640px) {
  body .r-root .prets-container .prets-config-grid {
    display: flex !important;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  body .r-root .prets-container .prets-config-grid > * {
    flex: 0 0 auto !important;
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
  }

  body .r-root .prets-container .prets-config-grid input,
  body .r-root .prets-container .prets-config-grid select {
    width: 100% !important;
  }
}
