@import url('https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600;700;800&family=JetBrains+Mono:wght@400;500;700&display=swap');

/* ══ TOKENS ═══════════════════════════════════════════════════════ */
:root {
  --bg:       #C4C4C4;
  --card:     #FFFFFF;
  --surface:  #EBEBEB;
  --border:   #B0B0B0;
  --ink:      #1A1A1A;
  --muted:    #666666;
  --faint:    #999999;

  --red:      #ED1C24;
  --red-hover:#414042;
  --red-glow: rgba(237,28,36,.18);

  --ok:       #1A7A4A;
  --ok-bg:    #E8F5EE;
  --ok-border:#A3D9B8;
  --err:      #ED1C24;
  --err-bg:   #FEE8E8;
  --warn:     #B45309;
  --warn-bg:  #FEF3C7;

  --mono:     'JetBrains Mono', monospace;
  --sans:     'Open Sans', sans-serif;

  --radius:   6px;
  --shadow:   0 1px 4px rgba(0,0,0,.12), 0 4px 16px rgba(0,0,0,.06);
  --shadow-sm:0 1px 3px rgba(0,0,0,.10);
}

/* ══ RESET ════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  /* Subtle noise texture on background */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='4' height='4'%3E%3Crect width='4' height='4' fill='%23C4C4C4'/%3E%3Crect x='0' y='0' width='1' height='1' fill='%23BBBBBB' opacity='.4'/%3E%3Crect x='2' y='2' width='1' height='1' fill='%23CBCBCB' opacity='.4'/%3E%3C/svg%3E");
}

/* ══ HEADER ═══════════════════════════════════════════════════════ */
header {
  background: var(--ink);
  color: #fff;
  padding: 0 40px;
  display: flex;
  align-items: stretch;
  gap: 0;
  height: 58px;
  border-bottom: 3px solid var(--red);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,.3);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-right: 28px;
  border-right: 1px solid #333;
}

.logo {
  width: 34px;
  height: 34px;
  background: var(--red);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  clip-path: polygon(0 0, 100% 0, 100% 75%, 50% 100%, 0 75%);
}

header h1 {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: .01em;
  text-transform: uppercase;
}
header p {
  font-size: .68rem;
  color: #888;
  margin-top: 1px;
  letter-spacing: .04em;
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

#cacheInfo {
  font-family: var(--mono);
  font-size: .68rem;
  color: #666;
  background: #111;
  padding: 3px 10px;
  border-radius: 3px;
}

.admin-link {
  color: #888;
  font-size: .75rem;
  font-weight: 700;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 7px 16px;
  border: 1px solid #333;
  border-radius: var(--radius);
  transition: all .18s;
}
.admin-link:hover { background: #333; color: #fff; border-color: #555; }

/* ══ MAIN LAYOUT ══════════════════════════════════════════════════ */
main { max-width: 1080px; margin: 0 auto; padding: 28px 40px 60px; }

/* ══ PIPELINE TRACKER ════════════════════════════════════════════ */
.pipeline {
  display: flex;
  align-items: center;
  margin-bottom: 24px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.ps {
  flex: 1;
  padding: 10px 14px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background .2s;
  position: relative;
}
.ps.active { background: var(--ink); }
.ps.done   { background: var(--ok-bg); }

.ps-n {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .66rem;
  font-weight: 700;
  font-family: var(--mono);
  color: var(--muted);
  flex-shrink: 0;
  transition: all .2s;
}
.ps.active .ps-n { background: var(--red); color: #fff; }
.ps.done   .ps-n { background: var(--ok); color: #fff; }

.ps-info h4 { font-size: .75rem; font-weight: 700; }
.ps-info p  { font-size: .65rem; color: var(--muted); margin-top: 1px; }
.ps.active .ps-info h4 { color: #fff; }
.ps.active .ps-info p  { color: #777; }
.ps.done   .ps-info p  { color: var(--ok); }

.pa { color: var(--border); font-size: 1rem; padding: 0 2px; flex-shrink: 0; }

/* ══ CARDS ════════════════════════════════════════════════════════ */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  position: relative;
}

/* Red left accent on cards */
.card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 3px;
  background: var(--red);
  border-radius: var(--radius) 0 0 var(--radius);
}

.card-title {
  font-size: .78rem;
  font-weight: 800;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink);
}

.card-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
  margin-left: 8px;
}

/* ══ SECTION LABEL ════════════════════════════════════════════════ */
.section-label {
  font-size: .68rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .1em;
  margin-bottom: 6px;
}

/* ══ IMPORT TABS ══════════════════════════════════════════════════ */
.import-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.import-tab {
  flex: 1;
  padding: 9px 16px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: var(--sans);
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-right: 1px solid var(--border);
}
.import-tab:last-child { border-right: none; }
.import-tab:hover  { background: #DDD; color: var(--ink); }
.import-tab.active {
  background: var(--red);
  color: #fff;
}

/* ══ DROP ZONE ════════════════════════════════════════════════════ */
.drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  position: relative;
  background: var(--surface);
  transition: all .2s;
}
.drop:hover, .drop.drag {
  border-color: var(--red);
  background: #F5E8E8;
}
.drop input[type=file] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.drop-ico { font-size: 1.8rem; margin-bottom: 6px; }
.drop p   { color: var(--muted); font-size: .83rem; }
.drop p strong { color: var(--red); }
.drop small { display: block; margin-top: 5px; font-size: .68rem; color: var(--faint); font-family: var(--mono); }

.file-ok {
  display: none;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 14px;
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
  border-radius: var(--radius);
  font-size: .78rem;
  font-weight: 600;
  color: var(--ok);
  font-family: var(--mono);
}

/* ══ FORM INPUTS ══════════════════════════════════════════════════ */
label {
  display: block;
  font-size: .68rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

input[type=text] {
  width: 100%;
  padding: 10px 13px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  font-family: var(--mono);
  font-size: .83rem;
  outline: none;
  transition: border-color .18s, box-shadow .18s;
}
input[type=text]:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-glow);
  background: #fff;
}

/* ══ NOTICES ══════════════════════════════════════════════════════ */
.notice {
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: .78rem;
  margin-bottom: 14px;
  line-height: 1.6;
  border-left: 3px solid;
}
.notice.info { background: #EEF3FF; border-color: #7B9EFF; color: #1A3A8A; }
.notice.ok   { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.notice.warn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }

/* ══ BUTTONS ══════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--sans);
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .18s, transform .1s, box-shadow .18s;
  text-transform: uppercase;
  letter-spacing: .06em;
  position: relative;
  overflow: hidden;
}
.btn:active  { transform: scale(.97); }
.btn:disabled { opacity: .35; cursor: not-allowed; }

.btn-run {
  background: var(--red);
  color: #fff;
  box-shadow: 0 3px 10px var(--red-glow);
}
.btn-run:hover:not(:disabled) {
  background: var(--red-hover);
  box-shadow: 0 4px 14px rgba(65,64,66,.3);
}

.btn-stop {
  background: var(--ink);
  color: #fff;
}
.btn-stop:hover:not(:disabled) { background: #333; }

.btn-export {
  background: var(--red);
  color: #fff;
}
.btn-export:hover:not(:disabled) { background: var(--red-hover); }

.btn-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ══ PROGRESS ═════════════════════════════════════════════════════ */
#progSection { margin-top: 20px; display: none; }

.prog-hd {
  display: flex;
  justify-content: space-between;
  font-size: .72rem;
  font-family: var(--mono);
  margin-bottom: 6px;
  color: var(--muted);
}

.prog-bar {
  height: 5px;
  background: var(--surface);
  border-radius: 0;
  overflow: hidden;
  margin-bottom: 14px;
  border: 1px solid var(--border);
}

.prog-fill {
  height: 100%;
  background: var(--red);
  border-radius: 0;
  transition: width .4s ease;
  width: 0%;
  position: relative;
}
.prog-fill::after {
  content: '';
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 30px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.4));
}

.logbox {
  background: #111;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-family: var(--mono);
  font-size: .7rem;
  color: #888;
  max-height: 140px;
  overflow-y: auto;
  border: 1px solid #2a2a2a;
}
.ll { padding: 1px 0; line-height: 1.7; }
.lok   { color: #4ade80; }
.lerr  { color: #f87171; }
.lwarn { color: #fbbf24; }
.linfo { color: #60a5fa; }

/* ══ STATS ════════════════════════════════════════════════════════ */
.stats {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.stat {
  flex: 1;
  min-width: 100px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  position: relative;
  overflow: hidden;
}
.stat::before {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--border);
}

.sv { font-size: 1.55rem; font-weight: 800; line-height: 1; }
.sl { font-size: .65rem; color: var(--muted); margin-top: 3px; text-transform: uppercase; letter-spacing: .07em; font-weight: 600; }

/* ══ TABLE ════════════════════════════════════════════════════════ */
.tbl-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: none;
}

table { width: 100%; border-collapse: collapse; font-size: .78rem; }

thead { background: var(--ink); }
th {
  padding: 10px 13px;
  text-align: left;
  font-size: .64rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #888;
  border-bottom: 1px solid #333;
  font-family: var(--mono);
  white-space: nowrap;
  font-weight: 500;
}

td {
  padding: 9px 13px;
  border-bottom: 1px solid var(--surface);
  vertical-align: top;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #F5F5F5; }

.ca  { font-weight: 600; }
.cs  { color: var(--muted); font-size: .69rem; margin-top: 2px; font-family: var(--mono); }
.cn  { font-weight: 700; }
.cpa { color: var(--muted); font-size: .7rem; margin-top: 2px; }
.cd  { font-family: var(--mono); font-weight: 700; color: var(--red); white-space: nowrap; font-size: .78rem; }
.ci  { color: var(--faint); font-family: var(--mono); font-size: .7rem; }

.tok  { background: var(--ok-bg); color: var(--ok); padding: 2px 8px; border-radius: 3px; font-size: .66rem; font-weight: 700; white-space: nowrap; text-transform: uppercase; letter-spacing: .05em; }
.terr { background: var(--err-bg); color: var(--err); padding: 2px 8px; border-radius: 3px; font-size: .66rem; font-weight: 700; white-space: nowrap; text-transform: uppercase; letter-spacing: .05em; }

/* ── 2ème enseigne ──────────────────────────────────────────────── */
.row-enseigne2 td { background: #FAFAFA; border-bottom: 1px solid var(--surface); }
.row-enseigne2:hover td { background: #F0F0F0; }
.row-enseigne2 .cn  { color: var(--muted); font-weight: 600; }
.row-enseigne2 .cpa { font-size: .69rem; }
.row-enseigne2 .cd  { color: var(--muted); font-weight: 600; }

.rank-badge {
  display: inline-block;
  font-size: .6rem;
  font-weight: 800;
  padding: 1px 7px;
  border-radius: 2px;
  margin-bottom: 3px;
  vertical-align: middle;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.rank-1 { background: var(--red); color: #fff; }
.rank-2 { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }

/* ══ SESSIONS ═════════════════════════════════════════════════════ */
.sess-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--surface);
  font-size: .8rem;
  transition: background .15s;
}
.sess-row:last-child { border-bottom: none; }
.sess-row:hover { background: var(--surface); }

.sess-nom  { font-weight: 700; flex: 1; }
.sess-meta { color: var(--muted); font-size: .7rem; font-family: var(--mono); }
.sess-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ══ SAVED BANNER ═════════════════════════════════════════════════ */
#savedBanner {
  display: none;
  align-items: center;
  gap: 12px;
  background: var(--ok-bg);
  border: 1px solid var(--ok-border);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 14px;
  font-size: .78rem;
  color: var(--ok);
  font-family: var(--mono);
}

#resultsCard { display: none; }

/* ══ SIRET BADGES ═════════════════════════════════════════════════ */
.siret-badge {
  display: inline-block;
  background: #111;
  color: #4ade80;
  font-family: var(--mono);
  font-size: .67rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 3px;
  margin: 2px 3px 2px 0;
}
.siret-badge.err    { background: #2A0000; color: #f87171; }
.siret-badge.cached { background: #0D1F3C; color: #93c5fd; }

/* ══ DB PREVIEW ═══════════════════════════════════════════════════ */
.db-preview {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: .78rem;
  display: flex;
  align-items: center;
  gap: 16px;
}
.db-stat { text-align: center; }
.db-stat .v { font-size: 1.3rem; font-weight: 800; color: var(--red); }
.db-stat .l { font-size: .65rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* ══ SCROLLBAR ════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ══ ANIMATIONS ═══════════════════════════════════════════════════ */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.card { animation: slideIn .22s ease both; }

/* Stagger cards */
.card:nth-child(1) { animation-delay: .04s; }
.card:nth-child(2) { animation-delay: .08s; }
.card:nth-child(3) { animation-delay: .12s; }
.card:nth-child(4) { animation-delay: .16s; }
