/* =====================================================================
   APPLI CHAI VR 2 - styles.css
   Theme bourgogne, mobile-first, vanilla CSS, no framework.
   ===================================================================== */

/* ---------------------------------------------------------------
   1. Variables (theme bourgogne)
   --------------------------------------------------------------- */
:root {
  --c-primary: #8B0000;
  --c-primary-hover: #6d0000;
  --c-bg: #faf8f5;
  --c-text: #2a2a2a;
  --c-muted: #6c6c6c;
  --c-border: #d8d4cf;
  --c-success: #2d7a3a;
  --c-warn: #c47b1f;
  --c-danger: #b03030;

  --c-card: #ffffff;
  --c-overlay: rgba(20, 20, 20, 0.55);

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen, Ubuntu, Cantarell, "Helvetica Neue", Arial, sans-serif;

  --header-h: 56px;
  /* Hauteur REELLE du header.nav-main, mise a jour dynamiquement par
     nav.js (ResizeObserver). Fallback = --header-h. Utilisee partout ou
     un element doit s'aligner sous le header sticky (thead sticky des
     tableaux, panneau lateral sticky du schema chai), pour que l'aligne-
     ment reste correct meme quand le header wrap sur 2 lignes (8 items
     menu admin sur viewports moyens). Cf bug catalogues -1 ligne. */
  --header-h-actual: 56px;
}

/* ---------------------------------------------------------------
   2. Reset minimal
   --------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-stack);
  font-size: 16px;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img,
svg {
  max-width: 100%;
  display: block;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}

a {
  color: var(--c-primary);
  text-decoration: none;
}
a:hover,
a:focus-visible {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 var(--space-3) 0;
  font-weight: 600;
  line-height: 1.25;
}

h1 {
  font-size: 1.5rem;
}
h2 {
  font-size: 1.25rem;
}
h3 {
  font-size: 1.1rem;
}

p {
  margin: 0 0 var(--space-3) 0;
}

/* ---------------------------------------------------------------
   3. Layout
   --------------------------------------------------------------- */
.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: var(--space-4);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.page-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

@media (min-width: 768px) {
  .page {
    padding: var(--space-5);
  }
}

@media (min-width: 1024px) {
  .page {
    padding: var(--space-6);
  }
}

/* ---------------------------------------------------------------
   4. Header navigation
   --------------------------------------------------------------- */
header.nav-main {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--c-primary);
  color: #fff;
  box-shadow: var(--shadow-md);
  /* min-height (et non height) : le header doit grandir si les nav-links wrap
     sur plusieurs lignes, sinon les liens debordent par-dessous et masquent
     la 1re ligne du contenu (bug -1 ligne sur les 3 catalogues
     zones/vins/cuves rapporte le 2026-05-07). */
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding: var(--space-1) var(--space-4);
  row-gap: var(--space-1);
}

header.nav-main .nav-brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: #fff;
  margin-right: var(--space-4);
  white-space: nowrap;
}

header.nav-main .nav-brand:hover,
header.nav-main .nav-brand:focus-visible {
  text-decoration: none;
}

header.nav-main .nav-links {
  display: flex;
  gap: var(--space-1);
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  flex-wrap: wrap;
  overflow-x: auto;
}

header.nav-main .nav-links a {
  color: #fff;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  display: inline-block;
  font-size: 0.95rem;
  white-space: nowrap;
}

header.nav-main .nav-links a:hover,
header.nav-main .nav-links a:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  text-decoration: none;
}

header.nav-main .nav-links a.active,
header.nav-main .nav-links a[aria-current="page"] {
  background: rgba(255, 255, 255, 0.2);
  font-weight: 600;
}

header.nav-main .nav-user {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-left: var(--space-3);
  font-size: 0.9rem;
}

header.nav-main .nav-user .nav-user-info {
  text-align: right;
  line-height: 1.2;
  display: none;
}

header.nav-main .nav-user .nav-user-info .nav-user-role {
  font-size: 0.75rem;
  opacity: 0.8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

@media (min-width: 768px) {
  header.nav-main .nav-user .nav-user-info {
    display: block;
  }
}

header.nav-main .nav-logout {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
header.nav-main .nav-logout:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* ---------------------------------------------------------------
   5. Boutons
   --------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease,
    color 0.15s ease, transform 0.05s ease;
  background: #fff;
  color: var(--c-text);
  border-color: var(--c-border);
  text-decoration: none;
}
.btn:hover:not(:disabled) {
  background: #f1ede8;
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--c-primary);
  color: #fff;
  border-color: var(--c-primary);
}
.btn-primary:hover:not(:disabled) {
  background: var(--c-primary-hover);
  border-color: var(--c-primary-hover);
}

.btn-secondary {
  background: #fff;
  color: var(--c-primary);
  border-color: var(--c-primary);
}
.btn-secondary:hover:not(:disabled) {
  background: rgba(139, 0, 0, 0.06);
}

.btn-danger {
  background: var(--c-danger);
  color: #fff;
  border-color: var(--c-danger);
}
.btn-danger:hover:not(:disabled) {
  background: #8d1d1d;
  border-color: #8d1d1d;
}

.btn-icon {
  padding: var(--space-2);
  background: transparent;
  border: 1px solid transparent;
  color: var(--c-muted);
  border-radius: var(--radius-sm);
}
.btn-icon:hover:not(:disabled) {
  background: #f1ede8;
  color: var(--c-text);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.85rem;
}

/* ---------------------------------------------------------------
   6. Inputs et champs
   --------------------------------------------------------------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

.field label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--c-text);
}

.field .field-help {
  font-size: 0.8rem;
  color: var(--c-muted);
}

.field .field-error {
  font-size: 0.8rem;
  color: var(--c-danger);
  min-height: 1em;
}

.input,
select.input,
textarea.input {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 1rem;
  font-family: inherit;
  color: var(--c-text);
  line-height: 1.4;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus,
select.input:focus,
textarea.input:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(139, 0, 0, 0.15);
}
.input:disabled {
  background: #f5f3ef;
  color: var(--c-muted);
}
.input.input-invalid {
  border-color: var(--c-danger);
}

.input-color {
  width: 56px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
}

.input-color-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.input-color-row .input {
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
}

/* ---------------------------------------------------------------
   7. Tableaux
   --------------------------------------------------------------- */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  background: var(--c-card);
  box-shadow: var(--shadow-sm);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.table th,
.table td {
  text-align: left;
  padding: var(--space-3);
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
}

.table th {
  background: #f5f1eb;
  font-weight: 600;
  color: var(--c-text);
  white-space: nowrap;
}

.table tbody tr:nth-child(even) td {
  background: #fbf9f6;
}

.table tbody tr:hover td {
  background: #f3ede5;
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table .col-actions {
  width: 1%;
  white-space: nowrap;
}

.table .col-actions .btn {
  margin-right: var(--space-1);
}

/* RETIRE 2026-05-07 : la regle `.table thead th { position: sticky; ... }`
   provoquait une separation visuelle entre le <thead> <tr> et ses <th>
   cells dans Chrome (les <th> sticky-pinned migraient hors du <tr>, qui
   restait visuellement vide). Resultat : la 1ere ligne du tbody semblait
   manquante car les <th> reapparaissaient ENTRE C1 et C2.
   Le confort "thead toujours visible au scroll" n'est pas critique sur
   ces tableaux courts. Si besoin reactiver plus tard, le faire avec
   `position: sticky` sur <tr> ou via wrapper a part. */

/* ---------------------------------------------------------------
   8. Cards
   --------------------------------------------------------------- */
.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.card-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: 1fr;
}

@media (min-width: 768px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .card-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ---------------------------------------------------------------
   9. Badges
   --------------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.5;
  background: #efe9e1;
  color: var(--c-text);
  white-space: nowrap;
}

.badge-success {
  background: rgba(45, 122, 58, 0.12);
  color: var(--c-success);
}
.badge-warn {
  background: rgba(196, 123, 31, 0.15);
  color: var(--c-warn);
}
.badge-danger {
  background: rgba(176, 48, 48, 0.12);
  color: var(--c-danger);
}
.badge-muted {
  background: #ece7df;
  color: var(--c-muted);
}

/* Color swatch (vins) */
.color-swatch {
  display: inline-block;
  width: 24px;
  height: 24px;
  border-radius: 4px;
  border: 1px solid var(--c-border);
  vertical-align: middle;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
}

/* ---------------------------------------------------------------
   10. Toasts
   --------------------------------------------------------------- */
.toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: calc(100vw - 2 * var(--space-4));
  pointer-events: none;
}

.toast {
  background: #ffffff;
  border: 1px solid var(--c-border);
  border-left: 4px solid var(--c-muted);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: 0.9rem;
  max-width: 360px;
  animation: toast-in 0.2s ease-out;
  pointer-events: auto;
  word-wrap: break-word;
}

.toast.toast-info {
  border-left-color: var(--c-primary);
}
.toast.toast-success {
  border-left-color: var(--c-success);
}
.toast.toast-warning {
  border-left-color: var(--c-warn);
}
.toast.toast-error {
  border-left-color: var(--c-danger);
}

.toast.toast-leaving {
  animation: toast-out 0.2s ease-in forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(20px);
  }
}

/* ---------------------------------------------------------------
   11. Modal (dialog)
   --------------------------------------------------------------- */
dialog.modal {
  border: none;
  padding: 0;
  border-radius: var(--radius-md);
  background: var(--c-card);
  color: var(--c-text);
  max-width: 90vw;
  width: 480px;
  box-shadow: var(--shadow-lg);
}

dialog.modal::backdrop {
  background: var(--c-overlay);
  animation: fade-in 0.15s ease-out;
}

dialog.modal[open] {
  animation: fade-in 0.15s ease-out;
}

dialog.modal .modal-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

dialog.modal .modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

dialog.modal .modal-body {
  padding: var(--space-5);
}

dialog.modal .modal-footer {
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--c-border);
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  background: #faf8f5;
  border-bottom-left-radius: var(--radius-md);
  border-bottom-right-radius: var(--radius-md);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ---------------------------------------------------------------
   12. Spinner / loader
   --------------------------------------------------------------- */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}

.spinner.spinner-dark {
  border: 2px solid rgba(0, 0, 0, 0.15);
  border-top-color: var(--c-primary);
}

.spinner.spinner-lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

.loader-block {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6);
  color: var(--c-muted);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------------------------------------------------------------
   13. Etats vides / messages
   --------------------------------------------------------------- */
.empty-state {
  padding: var(--space-6);
  text-align: center;
  color: var(--c-muted);
  font-size: 0.95rem;
}

.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  border: 1px solid var(--c-border);
  margin-bottom: var(--space-4);
}

.alert-error {
  background: rgba(176, 48, 48, 0.08);
  border-color: rgba(176, 48, 48, 0.3);
  color: var(--c-danger);
}

/* ---------------------------------------------------------------
   14. Page de login (specifique)
   --------------------------------------------------------------- */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-4);
  background: linear-gradient(
    135deg,
    var(--c-bg) 0%,
    #efe5d8 100%
  );
}

.login-card {
  background: var(--c-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
  width: 100%;
  max-width: 400px;
}

.login-card .login-title {
  text-align: center;
  margin-bottom: var(--space-2);
  color: var(--c-primary);
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 1px;
}

.login-card .login-subtitle {
  text-align: center;
  color: var(--c-muted);
  font-size: 0.9rem;
  margin-bottom: var(--space-5);
}

.login-card .login-extra {
  text-align: center;
  margin-top: var(--space-4);
  font-size: 0.85rem;
}

.login-card .btn-primary {
  width: 100%;
}

/* ---------------------------------------------------------------
   15. Utilitaires
   --------------------------------------------------------------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.text-muted {
  color: var(--c-muted);
}

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.flex {
  display: flex;
}

.flex-gap {
  gap: var(--space-3);
}

.mt-0 {
  margin-top: 0 !important;
}

.mt-3 {
  margin-top: var(--space-3);
}

.mb-0 {
  margin-bottom: 0 !important;
}

.mb-3 {
  margin-bottom: var(--space-3);
}

/* Largeur auto pour un <select> ou <input> dans une barre d'actions
   (utile dans .page-actions ou .filters-row). */
.input-auto {
  width: auto;
}

/* Variante du modal-footer utilisee hors d'un dialog (footer flush du formulaire) :
   pas de padding, pas de border, contenu aligne a droite. */
.modal-footer-flush {
  justify-content: flex-end;
  padding: 0;
  border: 0;
}

.hidden {
  display: none !important;
}

/* ---------------------------------------------------------------
   16. Page etroite (formulaires centres : change-password, etc.)
   --------------------------------------------------------------- */
.page-narrow {
  max-width: 560px;
}

/* ---------------------------------------------------------------
   17. Bouton warn (orange, distinct de btn-danger)
   --------------------------------------------------------------- */
.btn-warn {
  background: var(--c-warn);
  color: #fff;
  border-color: var(--c-warn);
}
.btn-warn:hover,
.btn-warn:focus-visible {
  background: #a86618;
  border-color: #a86618;
  color: #fff;
}
.btn-warn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ---------------------------------------------------------------
   18. Liste de regles (politique mot de passe)
   --------------------------------------------------------------- */
.policy-list {
  list-style: none;
  margin: var(--space-2) 0;
  padding: 0;
  font-size: 0.9rem;
}
.policy-list li {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 2px 0;
  color: var(--c-muted);
  transition: color 0.15s;
}
.policy-list li.policy-ok {
  color: var(--c-success);
}
.policy-list li.policy-ko {
  color: var(--c-danger);
}
.policy-list .policy-icon {
  display: inline-block;
  width: 1.1em;
  text-align: center;
  font-weight: 700;
}
