/* UNITEK Facturation V2 — feuille de style maison (moderne, responsive) */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1f2733;
  --muted: #667085;
  --border: #e4e8f0;
  --primary: #1a5276;
  --primary-600: #164460;
  --accent: #2e86c1;
  --ok: #1e8e5a;
  --ok-bg: #e6f6ee;
  --warn: #b7791f;
  --warn-bg: #fdf3e2;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .06), 0 1px 2px rgba(16, 24, 40, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.app-header {
  background: var(--primary);
  color: #fff;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.app-header .brand { font-weight: 700; font-size: 1.1rem; letter-spacing: .3px; }
.app-header .user { font-size: .85rem; opacity: .95; }
.app-header .user a { color: #fff; text-decoration: underline; }

.app-nav {
  background: var(--primary-600);
  padding: 0 12px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.app-nav a {
  color: #dbe7f0;
  padding: 11px 14px;
  font-size: .9rem;
  border-bottom: 3px solid transparent;
}
.app-nav a:hover { color: #fff; text-decoration: none; }
.app-nav a.active { color: #fff; border-bottom-color: var(--accent); font-weight: 600; }

.container { max-width: 1080px; margin: 24px auto; padding: 0 20px; }
.page-title { font-size: 1.4rem; margin: 0 0 18px; }

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 820px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}

.stat { text-align: left; }
.stat .value { font-size: 1.6rem; font-weight: 700; }
.stat .label { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .4px; }

/* Forms */
label { display: block; font-weight: 600; margin: 12px 0 5px; font-size: .9rem; }
.hint { color: var(--muted); font-size: .8rem; font-weight: 400; margin-top: 3px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=file], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  font-family: inherit;
  background: #fff;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; }

/* Buttons */
.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: .92rem;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--primary-600); text-decoration: none; color: #fff; }
.btn.secondary { background: #eef2f7; color: var(--ink); }
.btn.secondary:hover { background: #e2e8f0; }
.btn.danger { background: var(--danger); }
.btn.small { padding: 5px 10px; font-size: .82rem; }

/* Tables */
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
table.data th { font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
table.data tr:hover td { background: #fafbfe; }
.table-wrap { overflow-x: auto; }

/* Badges */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 600; }
.badge.brouillon { background: #eef2f7; color: #475467; }
.badge.envoyee { background: var(--warn-bg); color: var(--warn); }
.badge.payee { background: var(--ok-bg); color: var(--ok); }
.badge.en_retard { background: var(--danger-bg); color: var(--danger); }
.badge.annulee { background: #f0f0f0; color: #888; }

/* Flash */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 12px; font-size: .9rem; }
.flash.success { background: var(--ok-bg); color: var(--ok); }
.flash.error { background: var(--danger-bg); color: var(--danger); }
.flash.info { background: #e8f1fb; color: var(--primary); }

/* Login */
.login-wrap { max-width: 380px; margin: 8vh auto; }
.login-wrap .brand { text-align: center; font-size: 1.5rem; font-weight: 700; color: var(--primary); margin-bottom: 6px; }
.login-wrap .subtitle { text-align: center; color: var(--muted); margin-bottom: 22px; font-size: .9rem; }

.muted { color: var(--muted); }
.right { text-align: right; }
.mt { margin-top: 16px; }
.actions-inline { display: flex; gap: 8px; flex-wrap: wrap; }
img.asset-preview { max-height: 60px; border: 1px solid var(--border); border-radius: 6px; padding: 4px; background: #fff; }

/* --- Vague 2c : aperçu PDF inline (RG-019), montant en liste (RG-018), alertes admin (RG-016) --- */
.pdf-preview { width: 100%; height: 720px; border: 1px solid #d0d7e2; border-radius: 6px; background: #f5f6f8; margin-top: 10px; }
td.montant { white-space: nowrap; font-variant-numeric: tabular-nums; }
.alert-badge { display: inline-block; min-width: 22px; padding: 2px 8px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .78rem; font-weight: 700; text-align: center; vertical-align: middle; }
.alert-banner { display: flex; align-items: center; gap: 10px; background: var(--danger-bg); color: var(--danger); border: 1px solid #f3c2bd; border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; }
.alert-banner a { color: var(--danger); font-weight: 600; }
.badge.info { background: #e6f0fb; color: #1d4e89; }
.badge.avertissement { background: var(--warn-bg); color: var(--warn); }
.badge.erreur, .badge.critique { background: var(--danger-bg); color: var(--danger); }
tr.non-lu td { background: #fff8f7; }

/* ---------------------------------------------------------------------
   Mise en page PDF : aperçu A4 temps réel (public/societe/mise_en_page.php)
   L'aperçu raisonne en POURCENTAGES de la page : il reste exact à n'importe
   quelle largeur d'affichage, et utilise les mêmes nombres que le PDF.
   --------------------------------------------------------------------- */
.mep-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 460px); gap: 18px; align-items: start; }
@media (max-width: 1100px) { .mep-layout { grid-template-columns: 1fr; } }

.mep-sticky { position: sticky; top: 16px; }

.mep-page {
  position: relative; width: 100%; aspect-ratio: 210 / 297;
  background: #fff center/100% 100% no-repeat;
  border: 1px solid var(--border); border-radius: 4px;
  box-shadow: var(--shadow); overflow: hidden; user-select: none; touch-action: none;
}
/* La taille de police de .mep-page est posée en JS (1em = 10 pt a l'echelle) : tout ce
   qui est exprime en em suit alors exactement les proportions du PDF. Le .55rem n'est
   qu'un repli si le script ne tourne pas. */
.mep-page { font-size: .55rem; }
.mep-contenu {
  position: absolute; border: 1px dashed var(--accent); background: rgba(46, 134, 193, .06);
  color: var(--ink); overflow: hidden; padding: 2px;
}

.mep-item { position: absolute; cursor: grab; outline: 1px dashed transparent; }
.mep-item:hover, .mep-item.actif { outline-color: var(--primary); }
.mep-item:active { cursor: grabbing; }
.mep-item img { width: 100%; height: auto; display: block; pointer-events: none; }
.mep-item .mep-vide {
  display: flex; align-items: center; justify-content: center; min-height: 26px;
  border: 1px dashed var(--muted); border-radius: 3px; background: rgba(255, 255, 255, .75);
  font-size: .55rem; color: var(--muted); text-align: center; padding: 3px;
}
.mep-item .mep-nom { font-size: 1em; text-align: center; line-height: 1.2; }

.mep-champ { display: grid; grid-template-columns: 1fr 82px; gap: 8px; align-items: center; margin-bottom: 6px; }
.mep-champ label { margin: 0; font-weight: 500; font-size: .82rem; }
.mep-champ input[type=number] { margin: 0; }
.mep-champ input[type=range] { grid-column: 1 / -1; width: 100%; margin: 0; accent-color: var(--primary); }
.mep-legende { display: flex; flex-wrap: wrap; gap: 10px; font-size: .78rem; color: var(--muted); margin-top: 8px; }
.mep-legende span::before { content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 5px;
  border: 1px dashed var(--accent); vertical-align: -1px; }

/* --- Images de société : miniatures automatiques (écran Société) --------------------
   Le damier derrière la vignette n'est pas décoratif : cachet, signature et tampon sont
   des PNG transparents, et sur fond blanc on ne distingue pas un fond transparent d'un
   fond blanc opaque — or l'un se pose proprement sur le papier à en-tête, l'autre le masque. */
.asset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(215px, 1fr)); gap: 14px; }
.asset-item { border: 1px solid var(--border); border-radius: 8px; padding: 10px; background: #fff; }
.asset-entete { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.asset-entete label { margin: 0; font-weight: 600; min-width: 0; }
/* La pastille d'usage reste sur une ligne : repliee en deux, elle se lit mal et
   decale la miniature d'une carte a l'autre. */
.asset-entete .badge { flex: 0 0 auto; white-space: nowrap; }
/* Les noms de fichiers televerses sont longs (prefixe + nom d'origine) : ils doivent
   se couper dans la carte, pas deborder en silence. */
.asset-item code, .asset-item .hint { overflow-wrap: anywhere; }
.asset-vignette {
  display: flex; align-items: center; justify-content: center;
  height: 120px; padding: 6px; margin-bottom: 6px;
  border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
  background-color: #fff;
  background-image: linear-gradient(45deg, #eef1f5 25%, transparent 25%, transparent 75%, #eef1f5 75%),
                    linear-gradient(45deg, #eef1f5 25%, transparent 25%, transparent 75%, #eef1f5 75%);
  background-size: 14px 14px; background-position: 0 0, 7px 7px;
}
.asset-vignette.vide { background-image: none; background-color: var(--bg); border-style: dashed; }
.asset-vignette img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.asset-aucun { font-size: .8rem; color: var(--muted); }
.asset-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline;
  font-size: .78rem; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 1.1em; }
.asset-nouveau { color: var(--warn); font-weight: 600; }
.asset-item input[type=file] { margin-top: 8px; font-size: .82rem; }

/* --- Mise en page : aperçu fidèle + galerie des images chargées ---------------------
   La taille de police de l'aperçu est posée en JS à partir de la largeur réelle de la
   page (1em = 10pt à l'échelle) : tout ce qui est exprimé en em suit alors exactement
   les proportions du PDF, quel que soit le zoom du navigateur. */
.mep-apercu-texte { line-height: 1.25; }
.mep-contenu .mep-entete { display: flex; justify-content: space-between; gap: 1em; margin-bottom: 1.2em; }
.mep-contenu .mep-objet { width: 58%; font-weight: 700; }
.mep-contenu .mep-client { width: 40%; text-align: right; }
.mep-contenu .mep-h1 { text-align: center; font-size: 1.7em; font-weight: 700; margin: 1.1em 0 .9em; }
.mep-contenu table.mep-table { width: 100%; border-collapse: collapse; margin-top: .8em; }
.mep-contenu table.mep-table th, .mep-contenu table.mep-table td {
  border: 1px solid #000; padding: .35em .4em; font-size: 1em; text-align: left; }
.mep-contenu table.mep-table th { background: #f2f2f2; }
.mep-contenu table.mep-table .num { text-align: right; }
.mep-contenu .mep-total td { font-weight: 700; }
.mep-contenu .mep-lettres { margin-top: .8em; font-style: italic; }
.mep-contenu .mep-piedtexte { margin-top: 1.6em; font-size: .9em; color: #333;
  border-top: 1px solid #ccc; padding-top: .5em; }

.mep-page.sans-fond { background: repeating-linear-gradient(45deg, #fff, #fff 12px, #f6f7f9 12px, #f6f7f9 24px); }
.mep-sansfond-note { position: absolute; top: 6px; left: 6px; right: 6px; text-align: center;
  font-size: .72rem; color: var(--muted); background: rgba(255, 255, 255, .85);
  border: 1px dashed var(--border); border-radius: 4px; padding: 3px 6px; }

/* Aperçu agrandi : la colonne de réglages passe dessous, la page prend toute la largeur. */
.mep-layout.mep-large { grid-template-columns: 1fr; }
.mep-layout.mep-large .mep-sticky { position: static; order: -1; }
.mep-layout.mep-large .mep-page { max-width: 780px; margin: 0 auto; }

.mep-galerie { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.mep-gal-item { border: 1px solid var(--border); border-radius: 6px; padding: 7px; background: #fff; }
.mep-gal-vignette {
  display: flex; align-items: center; justify-content: center; height: 76px; margin-bottom: 5px;
  border: 1px solid var(--border); border-radius: 4px; overflow: hidden; background-color: #fff;
  background-image: linear-gradient(45deg, #eef1f5 25%, transparent 25%, transparent 75%, #eef1f5 75%),
                    linear-gradient(45deg, #eef1f5 25%, transparent 25%, transparent 75%, #eef1f5 75%);
  background-size: 12px 12px; background-position: 0 0, 6px 6px;
}
.mep-gal-vignette.vide { background-image: none; background-color: var(--bg); border-style: dashed; }
.mep-gal-vignette img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.mep-gal-nom { font-size: .8rem; font-weight: 600; }
.mep-gal-meta { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.mep-gal-item.hors-pdf { background: var(--bg); }
