:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #1e3a8a;
  --primary-hover: #1e40af;
  --primary-soft: #eef2ff;
  --ok: #047857;
  --ok-soft: #ecfdf5;
  --err: #b91c1c;
  --err-soft: #fef2f2;
  --warn-soft: #fffbeb;
  --warn: #92400e;
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .75rem; }
code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: .9em; word-break: break-all; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hint { display: block; color: var(--muted); font-size: .85rem; font-weight: 400; margin-top: 4px; }
.error-text { color: var(--err); }
.js .js-hide { display: none; }

/* Barre du haut */
.topbar { background: var(--primary); color: #fff; }
.topbar-inner {
  max-width: 1000px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.topbar nav a, .topbar .linklike {
  color: #dbeafe; text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: .95rem;
}
.topbar nav a:hover, .topbar nav a.active, .topbar .linklike:hover { background: rgba(255,255,255,.15); color: #fff; }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; }
form.inline { display: inline; margin: 0; }

.container { max-width: 1000px; margin: 0 auto; padding: 24px 16px 48px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card.narrow { max-width: 640px; }
.card > h2:first-child { margin-top: 0; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }

/* Formulaires */
label { display: block; font-weight: 600; margin-bottom: 16px; }
input[type=text], input[type=email], input[type=password], select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  border: 1px solid #d1d5db; border-radius: 8px; font: inherit; background: #fff; color: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; border-color: #60a5fa; }
label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; margin-bottom: 10px; }
label.check input { margin-top: 4px; width: 18px; height: 18px; flex: none; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px 4px; margin: 0 0 16px; }
legend { font-weight: 600; padding: 0 6px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 8px; border: 1px solid #d1d5db; background: #fff; color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 5px 10px; font-size: .875rem; }
.btn.wide { width: 100%; padding: 14px; font-size: 1.05rem; }

.notice { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--primary-soft); }
.notice.success { background: var(--ok-soft); color: var(--ok); }
.notice.error { background: var(--err-soft); color: var(--err); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #f3f4f6; color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
#password-field.disabled { opacity: .45; }

/* Connexion */
.login-box { max-width: 420px; margin: 8vh auto 0; }
.center { text-align: center; }
.login-box p.center { margin: 16px 0 0; }
input[readonly] { background: #f9fafb; color: var(--muted); }

/* Dépôt */
.dropzone {
  border: 2px dashed #c7d2fe; border-radius: var(--radius); background: var(--primary-soft);
  padding: 28px 16px; text-align: center; margin-bottom: 16px; transition: background .15s, border-color .15s;
}
.dropzone.over { background: #e0e7ff; border-color: var(--primary); }
.dz-title { font-size: 1.1rem; font-weight: 600; margin: 0 0 4px; }
.dz-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.dz-buttons label.btn { margin: 0; }

.file-list { list-style: none; padding: 0; margin: 0 0 16px; }
.file-list li {
  display: flex; align-items: center; gap: 12px; padding: 8px; border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 8px;
}
.file-list .thumb {
  width: 48px; height: 48px; border-radius: 6px; background: #f3f4f6; flex: none;
  object-fit: cover; display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 700; color: var(--muted); text-transform: uppercase;
}
.file-list .info { flex: 1; min-width: 0; }
.file-list .name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .remove { background: none; border: 0; color: var(--err); font-size: 1.4rem; cursor: pointer; padding: 4px 10px; line-height: 1; }

.progress { height: 8px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
.progress .bar { height: 100%; width: 0; background: var(--primary); transition: width .2s; }

/* Tuiles des sociétés */
.company-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px;
}
.company-tile {
  --tile: hsl(var(--hue, 220) 55% 42%);
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  min-height: 132px; padding: 16px 12px; border: 2px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--text); font: inherit; cursor: pointer; text-align: center;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.company-tile:hover { border-color: var(--tile); box-shadow: 0 4px 14px rgba(15, 23, 42, .08); transform: translateY(-1px); }
.company-tile:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }
.company-tile.selected { border-color: var(--tile); box-shadow: 0 0 0 3px hsl(var(--hue, 220) 55% 42% / .18); }
.company-tile.selected::after {
  content: "✓"; position: absolute; top: 8px; right: 10px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--tile); color: #fff; font-size: .8rem; font-weight: 700; line-height: 22px;
}
.company-tile.locked { pointer-events: none; opacity: .6; }
.tile-avatar {
  width: 52px; height: 52px; border-radius: 14px; display: flex; align-items: center; justify-content: center;
  background: hsl(var(--hue, 220) 60% 94%); color: var(--tile); font-weight: 700; font-size: 1.1rem; letter-spacing: .02em;
}
.tile-name { font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.tile-drop {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center; border-radius: 10px;
  background: hsl(var(--hue, 220) 60% 96% / .95); color: var(--tile); font-weight: 700; pointer-events: none;
}
.company-tile.over { border-style: dashed; border-color: var(--tile); transform: scale(1.03); }
.company-tile.over .tile-drop { display: flex; }

.upload-panel { scroll-margin-top: 16px; }
.panel-head { margin-bottom: 12px; }
.panel-head h2 { margin: 0 0 2px; }
.panel-head #company-name { color: var(--primary); }

/* Historique */
.history-item { padding: 16px 20px; }
.history-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.history-item .files { margin: 8px 0; padding-left: 20px; }
.history-item .files li { margin: 2px 0; }
.history-item .files a.small { margin-left: 6px; }
.history-item .comment { background: #f9fafb; border-radius: 6px; padding: 8px 10px; margin: 8px 0; white-space: pre-wrap; }
.history-item form { margin-top: 8px; }
.filter select { margin: 0; min-width: 220px; }
.filter { display: flex; gap: 8px; }

/* Tableaux */
.table-wrap { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
tr.inactive td { opacity: .6; }
td:last-child { text-align: right; white-space: nowrap; }

@media (max-width: 640px) {
  .company-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .company-tile { min-height: 112px; padding: 12px 8px; }
  .tile-avatar { width: 44px; height: 44px; font-size: 1rem; }
  .container { padding: 16px 12px 40px; }
  .card { padding: 16px; }
  .topbar nav a, .topbar .linklike { padding: 6px 8px; font-size: .9rem; }
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { border-bottom: 1px solid var(--border); padding: 8px 0; }
  td { border: 0; padding: 4px 16px; text-align: left !important; }
  td[data-label]::before { content: attr(data-label) " : "; color: var(--muted); font-size: .85rem; }
  .filter select { min-width: 0; }
}
