/* =====================================================================
   StockLink — feuille de style
   Pensée pour des connexions lentes et des écrans modestes : pas de
   police externe, pas de framework, tout tient en un seul fichier.
   ===================================================================== */

:root {
  --brand:        #0b6b4f;
  --brand-dark:   #085139;
  --brand-light:  #e6f4ef;
  --accent:       #d97706;

  --bg:           #f4f6f8;
  --surface:      #ffffff;
  --border:       #e2e6ea;
  --text:         #16202a;
  --text-soft:    #5d6b7a;
  --danger:       #c0392b;
  --success:      #17864f;

  --radius:       10px;
  --shadow:       0 1px 3px rgba(16, 32, 42, .08), 0 1px 2px rgba(16, 32, 42, .04);
  --shadow-lg:    0 10px 30px rgba(16, 32, 42, .14);

  --topbar-h:     58px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

img { max-width: 100%; display: block; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

/* ---------- Boutons ------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit; font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f0f3f5; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger { color: var(--danger); border-color: #f0c8c3; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 11px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.link-btn {
  background: none; border: 0; padding: 0;
  color: var(--brand); font: inherit; cursor: pointer; text-decoration: underline;
}

.icon-btn {
  position: relative;
  width: 38px; height: 38px;
  border: 0; border-radius: 50%;
  background: #eef1f4; font-size: 17px; cursor: pointer;
}
.icon-btn:hover { background: #e2e7eb; }

.badge {
  position: absolute; top: -3px; right: -3px;
  min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px;
  background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px;
}

/* ---------- Formulaires -------------------------------------------- */
label { display: block; margin-bottom: 13px; font-size: 13px; font-weight: 600; color: var(--text-soft); }
label small { display: block; margin-top: 4px; font-weight: 400; font-size: 12px; }

input, select, textarea {
  width: 100%;
  margin-top: 5px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font: inherit; color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}
textarea { resize: vertical; min-height: 78px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-error {
  min-height: 20px; margin-bottom: 8px;
  color: var(--danger); font-size: 13px; font-weight: 600;
}

/* ---------- Écran de connexion ------------------------------------- */
.auth-screen {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 20px;
  background: linear-gradient(150deg, var(--brand) 0%, var(--brand-dark) 55%, #04301f 100%);
}
.auth-card {
  width: 100%; max-width: 440px;
  padding: 30px;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-logo { font-size: 40px; }
.auth-brand h1 { margin: 6px 0 2px; font-size: 25px; }
.auth-brand p { margin: 0; color: var(--text-soft); font-size: 14px; }

.auth-tabs { display: flex; gap: 6px; margin-bottom: 20px; background: #eef1f4; padding: 4px; border-radius: 9px; }
.auth-tab {
  flex: 1; padding: 8px; border: 0; border-radius: 6px;
  background: transparent; font: inherit; font-weight: 600;
  color: var(--text-soft); cursor: pointer;
}
.auth-tab.is-active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow); }

/* ---------- Barre supérieure --------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1400px; height: 100%; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 20px;
}
.brand { font-size: 18px; font-weight: 800; color: var(--brand); white-space: nowrap; }
.brand:hover { text-decoration: none; }

.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.tabs a {
  padding: 8px 14px; border-radius: 8px;
  color: var(--text-soft); font-weight: 600; font-size: 14px; white-space: nowrap;
}
.tabs a:hover { background: #f0f3f5; text-decoration: none; }
.tabs a.is-active { background: var(--brand-light); color: var(--brand); }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-menu { position: relative; }
.user-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 5px;
  border: 1px solid var(--border); border-radius: 22px;
  background: var(--surface); font: inherit; font-weight: 600; cursor: pointer;
  max-width: 190px;
}
.user-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--brand-light); object-fit: cover; flex-shrink: 0;
}

.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px);
  min-width: 200px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  z-index: 50;
}
.dropdown a, .dropdown button {
  display: block; width: 100%; padding: 9px 12px;
  border: 0; border-radius: 7px; background: none;
  font: inherit; text-align: left; color: var(--text); cursor: pointer;
}
.dropdown a:hover, .dropdown button:hover { background: #f0f3f5; text-decoration: none; }

/* ---------- Mise en page -------------------------------------------
   Une seule colonne par défaut. Les colonnes publicitaires sont ajoutées
   par les classes .has-left / .has-right, posées en JavaScript uniquement
   quand une publicité est réellement disponible. Sans publicité, le
   contenu occupe toute la largeur au lieu de laisser un vide.
   ------------------------------------------------------------------- */
.layout {
  max-width: 1640px; margin: 0 auto; padding: 20px 16px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 22px;
  align-items: start;
}
.view { min-width: 0; }

/* La colonne de droite apparaît dès qu'il y a la place. */
@media (min-width: 1000px) {
  .layout.has-right { grid-template-columns: minmax(0, 1fr) 280px; }
}

/* Les DEUX colonnes dès 1280 px, ce qui couvre les écrans de portable
   courants (1366 px). Le rail gauche est volontairement plus étroit :
   à cette largeur, il reste environ 800 px au contenu, ce qui suffit
   largement pour le fil et les tableaux de stock. */
@media (min-width: 1280px) {
  .layout.has-left { grid-template-columns: 200px minmax(0, 1fr); }
  .layout.has-left.has-right { grid-template-columns: 200px minmax(0, 1fr) 280px; }
}

/* Grand écran : les deux colonnes reprennent de l'ampleur. */
@media (min-width: 1560px) {
  .layout.has-left { grid-template-columns: 260px minmax(0, 1fr); }
  .layout.has-left.has-right { grid-template-columns: 260px minmax(0, 1fr) 300px; }
}

/* ---------- Cartes -------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head h2 { margin: 0; font-size: 16px; }
.card-body { padding: 18px; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 22px; }

/* ---------- Statistiques -------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  padding: 15px 17px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.stat-label { font-size: 12px; font-weight: 600; color: var(--text-soft); text-transform: uppercase; letter-spacing: .03em; }
.stat-value { font-size: 24px; font-weight: 800; margin-top: 3px; }
.stat-value.warn { color: var(--accent); }
.stat-value.bad  { color: var(--danger); }
.stat-value.good { color: var(--success); }

/* ---------- Tableaux ------------------------------------------------ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-soft); background: #fafbfc; }
tbody tr:hover { background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Zone d'image dans le formulaire produit */
.image-drop {
  position: relative;
  width: 100%; aspect-ratio: 1;
  margin-top: 5px;
  display: grid; place-items: center; gap: 4px;
  border: 2px dashed var(--border); border-radius: 10px;
  background: #fafbfc; color: var(--text-soft);
  overflow: hidden;
}
.image-drop span { font-size: 27px; }
.image-drop small { font-size: 12px; }
.image-drop img { width: 100%; height: 100%; object-fit: cover; }
.image-drop-status {
  position: absolute; inset: auto 0 0 0;
  padding: 4px; text-align: center;
  background: rgba(22, 32, 42, .75); color: #fff;
  font-size: 12px; font-weight: 600;
}

/* Vignette de produit dans la liste du stock */
.thumb {
  width: 46px; height: 46px; flex-shrink: 0;
  border-radius: 8px; object-fit: cover;
  background: #eef1f4; border: 1px solid var(--border);
}
.thumb-placeholder {
  display: grid; place-items: center;
  font-size: 19px; color: var(--text-soft);
}
.product-cell { display: flex; align-items: center; gap: 11px; }

.pill { display: inline-block; padding: 2px 9px; border-radius: 11px; font-size: 12px; font-weight: 700; }
.pill-ok    { background: #e3f4ec; color: var(--success); }
.pill-warn  { background: #fdf1de; color: var(--accent); }
.pill-bad   { background: #fbe6e3; color: var(--danger); }
.pill-muted { background: #eef1f4; color: var(--text-soft); }

/* ---------- Fil d'actualité ----------------------------------------- */
.composer { padding: 16px 18px; }
.composer textarea { min-height: 66px; }
.composer-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; }

.post { padding: 0; }
.post-head { display: flex; align-items: center; gap: 11px; padding: 14px 18px 10px; }
.post-head .avatar { width: 42px; height: 42px; }
.post-shop { font-weight: 700; }
.post-meta { font-size: 12.5px; color: var(--text-soft); }
.post-body { padding: 0 18px 12px; white-space: pre-wrap; word-break: break-word; }
.post-media { display: grid; gap: 2px; grid-template-columns: 1fr; }
.post-media.multi { grid-template-columns: 1fr 1fr; }
.post-media img { width: 100%; max-height: 420px; object-fit: cover; }

.post-product {
  display: flex; gap: 13px; align-items: center;
  margin: 0 18px 13px; padding: 11px;
  background: var(--brand-light); border-radius: 9px;
}
.post-product img { width: 62px; height: 62px; border-radius: 7px; object-fit: cover; flex-shrink: 0; }
.post-product .price { font-size: 17px; font-weight: 800; color: var(--brand); }

.post-actions { display: flex; gap: 4px; padding: 6px 12px; border-top: 1px solid var(--border); }
.post-actions button {
  flex: 1; padding: 8px; border: 0; border-radius: 7px;
  background: none; font: inherit; font-weight: 600; font-size: 13.5px;
  color: var(--text-soft); cursor: pointer;
}
.post-actions button:hover { background: #f0f3f5; }
.post-actions button.liked { color: var(--brand); }

.comments { padding: 10px 18px 14px; border-top: 1px solid var(--border); background: #fafbfc; }
.comment { display: flex; gap: 9px; margin-bottom: 9px; font-size: 14px; }
.comment .bubble { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 7px 12px; }
.comment strong { display: block; font-size: 12.5px; }

/* ---------- Boutiques ----------------------------------------------- */
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.shop-card { padding: 16px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.shop-card .avatar { width: 58px; height: 58px; margin: 0 auto 9px; }
.shop-card h3 { margin: 0 0 2px; font-size: 15px; }
.shop-card .muted { font-size: 12.5px; color: var(--text-soft); }

/* ---------- Publicités ---------------------------------------------- */
.ads-rail { position: sticky; top: calc(var(--topbar-h) + 20px); }
/* L'attribut hidden doit gagner : sans cela le display:block du navigateur
   laisserait une colonne vide. */
.ads-rail[hidden] { display: none; }
/* Sous 1000 px, aucune colonne latérale, même si des pubs sont disponibles :
   sur mobile, la monétisation passe par l'interstitiel. */
@media (max-width: 999px) { .ads-rail { display: none; } }
/* Entre 1000 et 1280 px, seule la colonne de droite tient. */
@media (max-width: 1279px) { .ads-rail-left { display: none; } }
.ads-rail-label {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-soft); margin-bottom: 8px;
}
.ad-banner {
  display: block; margin-bottom: 13px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.ad-banner:hover { text-decoration: none; box-shadow: var(--shadow-lg); }
.ad-banner img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.ad-banner-body { padding: 11px 13px; }
.ad-banner-body strong { display: block; font-size: 14px; color: var(--text); }
.ad-banner-body span { font-size: 12.5px; color: var(--text-soft); }
.ad-advertiser { font-size: 11px; color: var(--text-soft); margin-top: 5px; }
.ads-cta {
  display: block; padding: 11px; text-align: center;
  border: 1px dashed var(--border); border-radius: var(--radius);
  font-size: 13px; font-weight: 600; color: var(--text-soft);
}

/* ---------- Permissions d'administration ----------------------------- */
.perm-list { display: grid; gap: 8px; margin-top: 5px; }
.perm-row {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 11px 13px; margin: 0;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-weight: 400; color: var(--text);
}
.perm-row strong { font-size: 14px; }
.perm-row .muted { font-size: 12.5px; line-height: 1.45; }
.perm-row.is-granted { border-color: var(--brand); background: var(--brand-light); }
.perm-row.is-denied { opacity: .55; }
.perm-choice { cursor: pointer; }
.perm-choice:hover { border-color: #c9d3db; }
.perm-choice:has(input:checked) { border-color: var(--brand); background: var(--brand-light); }

/* ---------- Choix de l'emplacement publicitaire ---------------------- */
.placement-grid {
  display: grid; gap: 11px;
  grid-template-columns: repeat(auto-fit, minmax(235px, 1fr));
  margin-top: 5px;
}
.placement-card {
  display: block; margin: 0; padding: 13px 15px;
  border: 2px solid var(--border); border-radius: var(--radius);
  background: var(--surface); cursor: pointer;
  font-weight: 400; color: var(--text);
  transition: border-color .15s, background .15s;
}
.placement-card:hover { border-color: #c9d3db; }
.placement-card.is-selected { border-color: var(--brand); background: var(--brand-light); }

.placement-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 6px;
}
.placement-head strong { font-size: 14.5px; }
.placement-desc { margin: 0 0 9px; font-size: 12.5px; color: var(--text-soft); line-height: 1.45; }
.placement-specs {
  display: grid; gap: 3px; margin-bottom: 9px;
  font-size: 12px; color: var(--text-soft);
}
.placement-price {
  font-size: 15px; font-weight: 800; color: var(--brand);
  padding-top: 8px; border-top: 1px solid var(--border);
}
.placement-price small { font-weight: 600; font-size: 11.5px; color: var(--text-soft); }

/* Aperçu du visuel envoyé (image, GIF ou vidéo) */
.media-preview {
  margin-top: 10px; padding: 11px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: #fafbfc;
}
.media-preview img, .media-preview video {
  max-width: 320px; border-radius: 8px; margin-bottom: 8px;
}

/* Une bannière vidéo se comporte comme une image dans la colonne. */
.ad-banner video { width: 100%; display: block; }

/* ---------- Interstitiel 5 secondes ---------------------------------- */
.interstitial {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  padding: 20px; background: rgba(9, 18, 24, .88);
}
.interstitial-box {
  width: 100%; max-width: 560px;
  background: var(--surface); border-radius: 13px; overflow: hidden;
  box-shadow: var(--shadow-lg);
}
.interstitial-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 15px; border-bottom: 1px solid var(--border);
}
.ad-tag {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-soft);
}
.skip-btn {
  padding: 7px 15px; border: 1px solid var(--border); border-radius: 19px;
  background: var(--surface); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.skip-btn:disabled { color: var(--text-soft); cursor: default; }
.skip-btn:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.interstitial img { width: 100%; max-height: 62vh; object-fit: cover; }
.interstitial-caption { padding: 15px 18px; }
.interstitial-caption strong { display: block; font-size: 17px; color: var(--text); }
.interstitial-caption span { color: var(--text-soft); font-size: 14px; }

/* ---------- Panneau notifications ------------------------------------ */
.panel {
  position: fixed; top: calc(var(--topbar-h) + 6px); right: 16px; z-index: 45;
  width: 370px; max-height: 74vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.panel-head {
  position: sticky; top: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.notif { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
.notif.unread { background: var(--brand-light); }
.notif time { display: block; font-size: 12px; color: var(--text-soft); margin-top: 2px; }

/* ---------- Divers ---------------------------------------------------- */
.loader, .empty { padding: 46px 20px; text-align: center; color: var(--text-soft); }
.empty-icon { font-size: 34px; display: block; margin-bottom: 8px; }
.muted { color: var(--text-soft); }
.toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; margin-top: 0; min-width: 165px; }
.grow { flex: 1; }

.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; }
.toast {
  padding: 11px 19px; border-radius: 8px;
  background: #16202a; color: #fff; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow-lg);
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---------- Écrans étroits -------------------------------------------- */
@media (max-width: 640px) {
  .topbar-inner { gap: 10px; padding: 0 10px; }
  .brand span + * { display: none; }
  .user-chip span { display: none; }
  .layout { padding: 12px 8px; }
  .form-row { grid-template-columns: 1fr; }
  .panel { right: 8px; left: 8px; width: auto; }
  .auth-card { padding: 22px; }
}
