/* ------------------------------------------------------------------ *
 * Portail des annonces AndCo — feuille de style
 * ------------------------------------------------------------------ */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #6b7280;
  --line: #e3e6ec;
  --brand: #1f5fd0;
  --brand-dark: #17479c;
  --ok: #14835a;
  --warn: #b4761a;
  --err: #c0392b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  letter-spacing: .5px;
  padding: 8px 12px;
  border-radius: var(--radius);
}
.topbar h1 { font-size: 16px; margin: 0; }
.badge { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.badge.ok { color: var(--ok); font-weight: 600; }
.badge.error { color: var(--err); font-weight: 600; }
.badge.warn { color: var(--warn); font-weight: 600; }

.auth { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.auth input { min-width: 320px; }

/* ---------------------------------------------------------- inputs */
input, select, button {
  font: inherit;
  color: inherit;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
input:focus, select:focus { outline: 2px solid #cfdef8; border-color: var(--brand); }

button { cursor: pointer; background: #fff; }
button:hover { border-color: #c6ccd8; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--brand-dark); }
button.ghost { background: #f8f9fb; }
button.mini { padding: 3px 8px; font-size: 12px; }

/* ---------------------------------------------------------- layout */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  padding: 16px 20px 40px;
  align-items: start;
}
/* ---------------------------------------------------------------- */
/* Affichage mobile / tablette                                       */
/* ---------------------------------------------------------------- */
.only-mobile { display: none; }

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 10px 10px calc(28px + env(safe-area-inset-bottom));
  }
  .only-mobile { display: inline-flex; }
  .only-desktop { display: none !important; }

  /* Barre du haut compacte */
  .topbar {
    padding: max(10px, env(safe-area-inset-top)) 10px 10px;
    gap: 8px;
  }
  .topbar h1 { font-size: 14px; }
  .logo { padding: 6px 9px; font-size: 13px; }
  .brand { gap: 8px; flex: 1 1 auto; }
  .brand-text { min-width: 0; }
  .brand-text h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .auth { flex: 1 1 100%; gap: 6px; }
  .auth input { flex: 1 1 100%; min-width: 0; min-height: 44px; }
  .auth button { flex: 0 0 auto; min-height: 44px; }

  /* Filtres en feuille plein écran */
  .filters {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(94vw, 420px);
    max-height: none;
    z-index: 45;
    display: flex;
    flex-direction: column;
    padding: 0;
    border-radius: 0 16px 16px 0;
    transform: translateX(-102%);
    transition: transform .24s cubic-bezier(.22, .61, .36, 1);
  }
  .filters.open { transform: none; box-shadow: 14px 0 44px rgba(15, 25, 45, .25); }
  .sheet-head {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: max(10px, env(safe-area-inset-top)) 14px 10px;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
  }
  .sheet-head h2 { margin: 0; font-size: 16px; font-weight: 650; flex: 1; }
  .filters-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px 14px 18px;
  }
  .sheet-foot {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: var(--panel);
    border-top: 1px solid var(--line);
    margin: 0;
  }
  .sheet-foot button { min-height: 46px; }
  .drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 22, 38, .5);
    z-index: 40;
  }

  /* Onglets defilants */
  .tabs {
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 6px 8px 0;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 11px 14px; min-height: 44px; }
  .panel { padding: 10px; }

  /* Boutons et champs plus tactiles */
  button, select, input[type="date"], input[type="number"] { min-height: 42px; }
  button.mini { min-height: 36px; }
  .checks { gap: 8px; }
  .check { min-height: 34px; }

  /* Tableaux -> cartes */
  .table-wrap { max-height: none; overflow: visible; border: none; }
  table thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; max-width: 100%; }
  tbody tr.row {
    border: 1px solid var(--line);
    border-radius: 12px;
    margin-bottom: 10px;
    padding: 10px 12px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(20, 30, 50, .05);
  }
  tbody tr.row:active { background: #f4f8ff; }
  tbody td {
    display: flex;
    gap: 10px;
    align-items: baseline;
    border: none;
    padding: 3px 0;
    min-width: 0;
  }
  tbody td::before {
    content: attr(data-label);
    flex: 0 0 40%;
    color: var(--muted);
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
  }
  tbody td:not([data-label])::before { display: none; }
  td.title-cell { min-width: 0; font-weight: 600; }
  td.empty { display: block; text-align: center; }
  .pagination { position: sticky; bottom: 0; background: var(--panel); padding: 8px 0; }
  .toast { bottom: calc(16px + env(safe-area-inset-bottom)); }
}

.filters {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow: auto;
}
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sheet-head h2 {
  flex: 1;
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
}
.filter-section { margin-bottom: 16px; }
.filter-section h3 {
  margin: 0 0 8px;
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
}
.sheet-foot { display: flex; gap: 8px; margin-top: 12px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select { width: 100%; }

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0 0 12px;
  padding: 8px 10px 10px;
}
legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
.checks { display: flex; flex-direction: column; gap: 4px; }
.checks.scroll { max-height: 190px; overflow: auto; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.check input { width: auto; padding: 0; }

/* --- recherche par nom de societe --- */
.row { display: flex; gap: 6px; align-items: center; }
.row input { flex: 1; width: auto; }
.company-field .hint { min-height: 14px; }
#company-entity { width: 100%; margin-top: 6px; }
.chip {
  display: inline-block;
  background: #e7effd;
  color: var(--brand);
  border-radius: 999px;
  padding: 0 8px;
  font-size: 11.5px;
  font-weight: 600;
}
.hidden { display: none !important; }

.switch { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 12px; font-size: 13px; }
.switch input { width: auto; }

.dates { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.actions { display: flex; gap: 8px; margin-top: 8px; }
.hint { font-size: 11.5px; color: var(--muted); margin: 10px 0 0; }

/* ---------------------------------------------------------- contenu */
.content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 6px 10px 0; }
.tab {
  border: 1px solid transparent;
  border-bottom: none;
  background: transparent;
  border-radius: 8px 8px 0 0;
  padding: 8px 14px;
  color: var(--muted);
}
.tab.active { background: #f2f5fb; border-color: var(--line); color: var(--ink); font-weight: 600; }
.tab span { background: #e7ecf6; border-radius: 999px; padding: 0 7px; font-size: 12px; margin-left: 4px; }

.panel { display: none; padding: 12px; }
.panel.active { display: block; }

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.toolbar .spacer { flex: 1; }
.inline { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); font-size: 12.5px; }

.table-wrap { overflow: auto; max-height: 62vh; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
thead th {
  position: sticky;
  top: 0;
  background: #f7f9fc;
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  font-size: 12px;
  color: #46506a;
  cursor: pointer;
  user-select: none;
}
thead th.sorted-asc::after { content: " ▲"; font-size: 9px; }
thead th.sorted-desc::after { content: " ▼"; font-size: 9px; }
tbody td { padding: 8px 10px; border-bottom: 1px solid #f0f2f6; vertical-align: top; }
tbody tr.row:hover { background: #f6f9ff; cursor: pointer; }
td.mono, .mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; }
td.title-cell { min-width: 240px; }
td.small { font-size: 12px; color: #4b5563; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.empty { text-align: center; color: var(--muted); padding: 26px; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  background: #eef1f6;
  color: #495267;
  white-space: nowrap;
}
.tag.ok { background: #e3f7ee; color: var(--ok); }
.tag.warn { background: #fdf1de; color: var(--warn); }
.tag.info { background: #e7effd; color: var(--brand); }
.tag.muted { background: #f0f0f2; color: #6b7280; }

.pagination { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 10px; }

/* ---------------------------------------------------------- cartes */
.cards { display: flex; flex-wrap: wrap; gap: 10px; }
.card {
  background: #f7f9fc;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 150px;
}
.card b { display: block; font-size: 22px; }
.card span { font-size: 12px; color: var(--muted); }
.card.wide { flex: 1 1 320px; }
.card.wide b { font-size: 14px; margin-bottom: 6px; }

/* ---------------------------------------------------------- modale */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(18, 24, 38, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-card {
  background: #fff;
  border-radius: 12px;
  max-width: 900px;
  width: 100%;
  max-height: 88vh;
  overflow: auto;
  padding: 20px 22px;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
}
.modal-card h2 { margin: 0 0 4px; font-size: 18px; }
.modal-card h3 { margin: 18px 0 8px; font-size: 14px; text-transform: uppercase; color: var(--muted); letter-spacing: .5px; }
.kv-grid, .fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px 18px; }
.kv { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed #e8ebf1; padding: 4px 0; }
.kv span { color: var(--muted); font-size: 12.5px; }
.kv b { font-weight: 600; text-align: right; word-break: break-word; }
.mini-table { font-size: 12.5px; }
.link { text-decoration: none; display: inline-block; padding: 7px 12px; }

/* ---------------------------------------------------------- toast */
.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #22293a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  transition: .2s;
  z-index: 60;
  max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--err); }

/* ---------------------------------------------------------- PWA / veilles */
.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 10px;
  font-size: 15px;
  line-height: 1;
  position: relative;
}
.icon-btn:hover { background: #f4f7fc; }

.badge-count {
  display: inline-block;
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--err);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
}
#bell .badge-count { position: absolute; top: -7px; right: -7px; min-width: 17px; padding: 0 5px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }

.watch-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; }
.watch-options { display: flex; flex-direction: column; gap: 8px; }
.watch-list { display: grid; gap: 10px; margin-top: 12px; }
.watch-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fff; }
.watch-card.has-new { border-color: var(--brand); box-shadow: 0 0 0 2px #e7effd; }
.watch-card header { display: flex; align-items: center; gap: 10px; }
.watch-card h4 { margin: 0; font-size: 14px; flex: 1; word-break: break-word; }
.watch-preview { margin: 6px 0 0; padding-left: 18px; font-size: 12.5px; }
.watch-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
button.danger { color: var(--err); border-color: #f1d4d0; }
.notify-settings { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.tiny { width: 70px; }
#watch-filters:empty { display: none; }

@media (max-width: 980px) {
  .watch-form { grid-template-columns: 1fr; }
  .watch-options { flex-direction: row; align-items: center; justify-content: space-between; }
  .watch-actions button { flex: 1 1 auto; }
}

/* ---------------------------------------------------------------- */
/* Application mobile : coquille (barre d'app, onglets en bas)        */
/* ---------------------------------------------------------------- */
.card-list { display: none; }

@media (max-width: 980px) {
  body {
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
    background: #eef1f6;
  }

  /* --- barre d'application --- */
  .topbar {
    min-height: 56px;
    padding: max(8px, env(safe-area-inset-top)) 10px 8px;
    align-items: center;
    box-shadow: 0 1px 0 rgba(20, 30, 50, .06);
    gap: 6px;
  }
  .brand { flex: 1 1 auto; min-width: 0; gap: 6px; }
  .brand-text { min-width: 0; }
  #app-title { font-size: 17px; font-weight: 650; letter-spacing: -.2px; }
  #user-badge { font-size: 11.5px; }
  .auth { flex: 0 0 auto; gap: 6px; }
  .icon-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    font-size: 17px;
  }
  #install { border-radius: 12px; }

  /* --- contenu : ce sont les cartes qui portent le style --- */
  .content { background: transparent; border: none; border-radius: 0; }
  .panel { padding: 0; }
  .toolbar { padding: 0 2px; }

  /* --- onglets en bas --- */
  .tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    background: rgba(255, 255, 255, .96);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar-item {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 2px;
    border: none;
    background: none;
    border-radius: 12px;
    color: var(--muted);
    position: relative;
    font-size: 11px;
  }
  .tabbar-item.active { color: var(--brand); background: #eef3fd; font-weight: 600; }
  .tabbar-icon { font-size: 19px; line-height: 1; }
  .tabbar-label { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .tabbar-badge {
    position: absolute;
    top: 2px;
    left: 50%;
    transform: translateX(8px);
    min-width: 17px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--err);
    color: #fff;
    font-size: 10.5px;
    font-weight: 700;
    text-align: center;
  }
}

/* ---------------------------------------------------------------- */
/* Application mobile : cartes, etat vide, feuille, squelettes       */
/* ---------------------------------------------------------------- */
@media (max-width: 980px) {
  body.drawer-open { overflow: hidden; }

  /* --- haut de page compact : le contenu commence tout de suite --- */
  .layout { padding: 8px 8px calc(20px + env(safe-area-inset-bottom)); }
  .panel { padding: 0; }
  .toolbar { margin: 0 0 8px; padding: 0 2px; gap: 6px; min-height: 34px; }
  .toolbar button { min-height: 34px; padding: 5px 10px; font-size: 12.5px; }
  .toolbar select { min-height: 34px; padding: 4px 8px; font-size: 12.5px; }
  #offers-status-line { font-size: 11.5px; line-height: 1.2; }
  #resp-search { flex: 1 1 100%; }
  .list-footer { padding-top: 8px; }
  .filters-body { padding: 8px 14px 14px; }

  /* --- cases a cocher en pastilles tactiles --- */
  .checks { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .checks.scroll { max-height: 176px; overflow-y: auto; padding-right: 2px; }
  .check {
    flex: 0 0 auto;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 7px 12px;
    background: #fff;
    font-size: 12.5px;
    min-height: 36px;
    user-select: none;
  }
  .check input {
    appearance: none;
    width: 0;
    height: 0;
    margin: 0;
    padding: 0;
    border: 0;
  }
  .check.selected { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
  .check.selected span::after { content: " ✓"; font-size: 11px; }
  .switch { align-items: center; gap: 10px; font-size: 13px; }
  .switch input { flex: 0 0 auto; width: 20px; height: 20px; }
  .filter-section { margin-bottom: 14px; }
  .filter-section h3 { font-size: 11.5px; }

  .card-list { display: flex; flex-direction: column; gap: 10px; padding: 2px; }

  .card {
    background: #fff;
    border: 1px solid #e6eaf2;
    border-radius: 16px;
    padding: 13px 14px;
    box-shadow: 0 1px 2px rgba(21, 33, 61, .05);
    min-width: 0;
    transition: background .12s ease, transform .12s ease;
  }
  .offer-card,
  .response-card { cursor: pointer; }
  .offer-card:active,
  .response-card:active { background: #f7faff; transform: scale(.995); }

  .card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
  .card-ref { margin-left: auto; font-size: 11px; color: var(--muted); white-space: nowrap; }
  .card-title { margin: 0 0 4px; font-size: 15px; font-weight: 650; line-height: 1.3; }
  .card-company { margin: 0 0 10px; font-size: 13px; }
  .card-company b { font-weight: 650; }

  .card-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 12px;
    margin: 0;
    padding: 9px 0 0;
    border-top: 1px solid #f0f2f7;
  }
  .card-meta > div { min-width: 0; }
  .card-meta > div.wide { grid-column: 1 / -1; }
  .card-meta dt {
    margin: 0;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--muted);
  }
  .card-meta dd { margin: 1px 0 0; font-size: 12.5px; }

  .card-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
  .card-cta { margin-left: auto; font-size: 12.5px; font-weight: 600; color: var(--brand); white-space: nowrap; }

  .empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 40px 16px;
    text-align: center;
    color: var(--muted);
  }
  .empty-icon { font-size: 34px; }
  .empty-state p { margin: 0; }

  .list-footer { display: flex; justify-content: center; padding: 12px 2px 4px; }
  #load-more { width: 100%; min-height: 46px; border-radius: 14px; }

  /* fiche = feuille glissante depuis le bas */
  .modal { align-items: flex-end; padding: 0; }
  .modal-card {
    border-radius: 18px 18px 0 0;
    max-height: 92dvh;
    width: 100%;
    padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
    animation: sheet-up .22s ease-out;
  }
  .sheet-handle {
    width: 42px;
    height: 4px;
    border-radius: 999px;
    background: #d7dce6;
    margin: 0 auto 10px;
  }
  .modal-close { top: 6px; right: 8px; }

  /* squelettes de chargement */
  .skeleton-card .sk {
    height: 12px;
    border-radius: 6px;
    margin-bottom: 9px;
    background: linear-gradient(90deg, #eef1f6 25%, #e3e8f1 37%, #eef1f6 63%);
    background-size: 400% 100%;
    animation: sk 1.3s ease infinite;
  }
  .sk-30 { width: 30%; }
  .sk-40 { width: 40%; }
  .sk-60 { width: 60%; }
  .sk-80 { width: 80%; }
}

@keyframes sheet-up {
  from { transform: translateY(16px); opacity: .6; }
  to { transform: none; opacity: 1; }
}

@keyframes sk {
  from { background-position: 100% 50%; }
  to { background-position: 0 50%; }
}


/* 1. Rien ne doit elargir la page. */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* "clip" ne cree pas de conteneur de defilement : le sticky continue de marcher. */
@supports (overflow-x: clip) {
  html,
  body { overflow-x: clip; }
}

body { overscroll-behavior-x: none; }

img, svg, canvas, video, iframe { max-width: 100%; height: auto; }

/* 2. Les enfants de flex/grid doivent pouvoir se reduire. */
.layout > *,
.content,
.panel,
.filters,
.cards,
.card,
.watch-list,
.watch-card,
.chips,
.toolbar,
.notify-settings,
.kv,
.kv-grid,
.fields { min-width: 0; }

.card.wide { flex: 1 1 auto; min-width: 0; }
.kv-grid,
.fields { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
.kv b,
.kv span { min-width: 0; overflow-wrap: anywhere; }

/* 3. Coupure des textes longs (references, titres, societes, villes...). */
td,
th,
.chip,
.badge,
.mono,
.title-cell,
.watch-card h4,
.watch-preview li,
.modal-card,
.toast,
.mini-table td,
#company-hint,
#watch-feedback,
#filter-hint,
#offers-status-line,
#user-badge {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* 4. Hauteurs basees sur l'ecran reel (barres du navigateur prises en compte). */
.modal-card { max-height: 88dvh; width: min(900px, 100%); }

@media (max-width: 980px) {
  /* Ordre de cascade : la base `.filters` est definie plus bas dans ce fichier,
     il faut donc re-declarer ces proprietes ici, sinon le tiroir reste dans le
     flux (sticky) et pousse tout le contenu d'un ecran vers le bas. */
  .filters {
    position: fixed;
    top: 0;
    right: auto;
    bottom: 0;
    left: 0;
    width: min(94vw, 420px);
    max-height: none;
    height: auto;
    z-index: 45;
    padding: 0;
    border-radius: 0 16px 16px 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: translateX(-102%);
    transition: transform .24s cubic-bezier(.22, .61, .36, 1);
  }
  .filters.open { transform: none; box-shadow: 14px 0 44px rgba(15, 25, 45, .25); }

  .content { overflow: visible; }              /* ne pas clipper la pagination */
  .modal { padding: 8px; align-items: flex-start; }
  .modal-card {
    max-height: 92dvh;
    width: 100%;
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
  }
  .filters-body { max-height: none; }
  .toolbar { gap: 6px; }
  .toolbar > * { min-width: 0; }
  .pagination { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .layout { padding: 8px 8px calc(20px + env(safe-area-inset-bottom)); }
  .panel { padding: 8px; }
  .tab { padding: 10px 11px; font-size: 13px; }
  tbody td::before { flex: 0 0 36%; }
  .auth button { padding: 7px 9px; }
  #user-badge { max-width: 58vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* 5. Application installee : encoches, barre d'etat, pas de bouton « Installer ». */
@media (display-mode: standalone) {
  body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .topbar { padding-top: max(12px, env(safe-area-inset-top)); }
  #install { display: none; }
}

@media (display-mode: fullscreen) {
  .topbar { padding-top: max(12px, env(safe-area-inset-top)); }
}
