/* =============================================================================
   PRESTATIONS MARTIN -- Theme global
   ============================================================================= */

:root {
  --color-primary: #2C5530;        /* vert vigne sobre */
  --color-primary-dark: #1F3D22;
  --color-secondary: #8B6F47;      /* terre */
  --color-bg: #F7F6F2;
  --color-surface: #FFFFFF;
  --color-text: #1F2528;
  --color-text-muted: #5C6770;
  --color-border: #E1E0DA;
  --color-success: #2F8F4E;
  --color-warn: #E0A82E;
  --color-error: #C0392B;
  --color-info: #2C7DA0;

  --radius: 6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.5;
}

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

h1, h2, h3 { color: var(--color-primary-dark); margin: 0 0 0.5em 0; }
h1 { font-size: 1.8rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }

/* --- Layout ----------------------------------------------------------------*/
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* --- Nav -------------------------------------------------------------------*/
.nav {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  box-shadow: var(--shadow-sm);
}
.nav__brand {
  font-weight: 600;
  color: var(--color-primary-dark);
  font-size: 1.1rem;
}
.nav__links {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  flex: 1;
}
.nav__link {
  color: var(--color-text);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius);
}
.nav__link:hover { background: var(--color-bg); text-decoration: none; }
.nav__link--active { background: var(--color-primary); color: #fff; }
.nav__link--active:hover { background: var(--color-primary-dark); }
.nav__right { display: flex; align-items: center; gap: 0.75rem; }
.nav__user { color: var(--color-text-muted); font-size: 0.9rem; }

/* --- Forms -----------------------------------------------------------------*/
.input, .select, .textarea {
  display: block;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font: inherit;
  background: var(--color-surface);
  color: var(--color-text);
}
.input:focus, .select:focus, .textarea:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: -1px;
  border-color: var(--color-primary);
}
.label {
  display: block;
  margin-bottom: 0.3rem;
  font-weight: 500;
  color: var(--color-text);
  font-size: 0.95rem;
}
.field { margin-bottom: 1rem; }
.help { font-size: 0.85rem; color: var(--color-text-muted); margin-top: 0.25rem; }
.error { color: var(--color-error); font-size: 0.85rem; margin-top: 0.25rem; }

/* --- Buttons ---------------------------------------------------------------*/
.btn {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  border: 1px solid var(--color-primary);
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius);
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  min-height: 44px;             /* mobile-friendly */
}
.btn:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--ghost {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn--ghost:hover { background: var(--color-bg); border-color: var(--color-text-muted); }
.btn--danger { background: var(--color-error); border-color: var(--color-error); }
.btn--danger:hover { background: #8E2A1F; border-color: #8E2A1F; }
.btn--block { display: block; width: 100%; }

/* --- Card ------------------------------------------------------------------*/
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  margin-bottom: 1rem;
}

/* --- Table -----------------------------------------------------------------*/
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.table th, .table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}
.table th { background: var(--color-bg); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover { background: var(--color-bg); }

/* --- Badges ----------------------------------------------------------------*/
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.badge--success { background: #DCEFE0; color: #1F6B2C; border-color: #B6DCBE; }
.badge--warn    { background: #FBEFD0; color: #7A5908; border-color: #EDD9A0; }
.badge--error   { background: #F7D7D1; color: #7A1F12; border-color: #ECBAAF; }
.badge--info    { background: #D6EAF3; color: #1A4C6E; border-color: #B3D6E6; }

/* --- Notifications ---------------------------------------------------------*/
#martin-notify {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 360px;
}
.notify {
  background: var(--color-surface);
  border-left: 4px solid var(--color-info);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.3s, transform 0.3s;
  font-size: 0.95rem;
}
.notify--show { opacity: 1; transform: translateX(0); }
.notify--success { border-left-color: var(--color-success); }
.notify--warn    { border-left-color: var(--color-warn); }
.notify--error   { border-left-color: var(--color-error); }
.notify--info    { border-left-color: var(--color-info); }

/* --- Login page -----------------------------------------------------------*/
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2rem;
}
.login-card h1 {
  text-align: center;
  margin-bottom: 1.5rem;
}

/* --- Toolbar (au-dessus des tables) ---------------------------------------*/
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.toolbar__left, .toolbar__right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.toggle-archived { cursor: pointer; display: inline-flex; align-items: center; gap: 0.4rem; }

/* --- Modal -----------------------------------------------------------------*/
.modal-backdrop {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  padding: 1rem;
}
.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal__header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal__title { margin: 0; }
.modal__close {
  background: transparent;
  border: 0;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0;
  line-height: 1;
}
.modal__body { padding: 1.25rem; }
.modal__footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Forme en grille (cas produits qui a 8 champs) */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
}
.form-grid .field--full { grid-column: 1 / -1; }
@media (max-width: 600px) {
  .form-grid { grid-template-columns: 1fr; }
}

/* --- Etat archivе / inactif (visuel discret) ------------------------------*/
.row--archived td { color: var(--color-text-muted); font-style: italic; }
.actions-cell { white-space: nowrap; }
.actions-cell .btn { padding: 0.3rem 0.6rem; min-height: 0; font-size: 0.85rem; margin-left: 0.25rem; }

/* --- Empty state ----------------------------------------------------------*/
.empty {
  text-align: center;
  padding: 2rem;
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
}

/* --- Declarer un travail (mobile-first) -----------------------------------*/
.declarer-host .card { margin-bottom: 1rem; }
.declarer-host h3 { margin-top: 0; }

.chip-list { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
.chip {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  cursor: pointer;
  font-size: 0.95rem;
  user-select: none;
  min-height: 40px;
}
.chip--active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.produit-row {
  display: grid;
  grid-template-columns: 1fr 100px 80px 36px;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  background: var(--color-surface);
}
.produit-row__nom { font-weight: 500; }
.produit-row .btn-remove {
  width: 36px; height: 36px; padding: 0; min-height: 0;
  border: 1px solid var(--color-error);
  color: var(--color-error);
  background: transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
}
.produit-row .btn-remove:hover { background: var(--color-error); color: #fff; }
@media (max-width: 600px) {
  .produit-row { grid-template-columns: 1fr; }
  .produit-row__nom { font-size: 1rem; }
  .produit-row .btn-remove { width: 100%; height: auto; padding: 0.4rem; font-size: 0.9rem; }
  .produit-row .btn-remove::before { content: 'Supprimer '; }
}

/* --- PDF render host (hors viewport) --------------------------------------*/
.pdf-render-host {
  position: absolute;
  left: -10000px;
  top: 0;
  width: 210mm;          /* A4 portrait */
  background: #fff;
}
.pdf-page {
  width: 210mm;
  min-height: 297mm;
  padding: 18mm 15mm;
  box-sizing: border-box;
  color: #1F2528;
  font-family: var(--font-sans);
  font-size: 11pt;
  line-height: 1.4;
}
.pdf-header {
  border-bottom: 3px solid var(--color-primary);
  padding-bottom: 8mm;
  margin-bottom: 8mm;
}
.pdf-header__brand {
  font-size: 18pt;
  font-weight: 700;
  color: var(--color-primary-dark);
  letter-spacing: 0.5px;
}
.pdf-header__sub {
  color: var(--color-text-muted);
  font-size: 9pt;
  margin-top: 2mm;
}
.pdf-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4mm 8mm;
  margin-bottom: 8mm;
}
.pdf-meta__label { font-size: 8pt; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.pdf-meta__value { font-size: 11pt; font-weight: 500; margin-top: 1mm; }
.pdf-section { margin-bottom: 6mm; }
.pdf-section h3 { font-size: 11pt; color: var(--color-primary-dark); margin-bottom: 3mm; }
.pdf-table { width: 100%; border-collapse: collapse; font-size: 9pt; }
.pdf-table th, .pdf-table td { border: 1px solid #ccc; padding: 2mm 3mm; text-align: left; }
.pdf-table th { background: #F2F0EA; font-weight: 600; }
.pdf-footer { margin-top: 12mm; padding-top: 4mm; border-top: 1px solid #ccc; font-size: 8pt; color: var(--color-text-muted); }

/* --- Mobile ---------------------------------------------------------------*/
@media (max-width: 768px) {
  .nav { flex-direction: column; align-items: stretch; gap: 0.5rem; padding: 0.5rem 0.75rem; }
  .nav__links { gap: 0.25rem; }
  .nav__link { font-size: 0.9rem; padding: 0.4rem 0.6rem; }
  .container { padding: 0.75rem; }
  .table { font-size: 0.9rem; }
  .table th, .table td { padding: 0.4rem; }
  .input, .select, .textarea, .btn {
    font-size: 16px;            /* iOS : evite zoom auto si font-size < 16 */
    min-height: 44px;
  }
}
