/* ============ ANALYSE — design admin data-dense ============ */
:root {
  --primary: #1E40AF;
  --primary-600: #1D4ED8;
  --primary-soft: #DBEAFE;
  --accent: #F59E0B;
  --accent-soft: #FEF3C7;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --text: #0F172A;
  --text-muted: #475569;
  --sidebar-bg: #0B1533;
  --sidebar-text: #C7D2E5;
  --ok: #15803D;   --ok-soft: #DCFCE7;
  --bad: #B91C1C;  --bad-soft: #FEE2E2;
  --warn: #B45309; --warn-soft: #FEF3C7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; }
body {
  font-family: 'Fira Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}
a { color: var(--primary-600); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; }
svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ---------- structure ---------- */
.app { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.content { padding: 22px 26px 40px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- sidebar ---------- */
.sidebar {
  width: 250px; flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark {
  width: 38px; height: 38px; border-radius: 9px;
  background: linear-gradient(135deg, #2563EB, #1E40AF);
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-mark.big { width: 54px; height: 54px; border-radius: 13px; }
.brand-mark.big svg { width: 28px; height: 28px; }
.brand-name { font-weight: 700; letter-spacing: .06em; color: #fff; font-size: 1.02rem; }
.brand-sub { font-size: .72rem; color: #7C8BA8; }

.nav { flex: 1; padding: 14px 10px; overflow-y: auto; }
.nav-section {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .12em;
  color: #64748B; padding: 14px 10px 6px;
}
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 8px; margin-bottom: 2px;
  color: var(--sidebar-text); font-size: .92rem; font-weight: 450;
  transition: background .18s, color .18s; cursor: pointer;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-link.active {
  background: linear-gradient(90deg, rgba(37,99,235,.28), rgba(37,99,235,.10));
  color: #fff; font-weight: 600;
  box-shadow: inset 3px 0 0 #3B82F6;
}
.nav-link.disabled { color: #55637F; cursor: default; }
.nav-link.disabled:hover { background: none; color: #55637F; }
.badge-soon {
  margin-left: auto; font-size: .62rem; font-weight: 600;
  background: rgba(245,158,11,.18); color: #FBBF24;
  border-radius: 999px; padding: 2px 8px; letter-spacing: .04em;
}

.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, #F59E0B, #D97706);
  color: #fff; font-weight: 700; font-size: .8rem;
  display: flex; align-items: center; justify-content: center;
}
.avatar.big { width: 54px; height: 54px; font-size: 1.15rem; border-radius: 14px; }
.user-meta { min-width: 0; }
.user-name { color: #fff; font-size: .88rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .72rem; color: #7C8BA8; }
.logout-form { margin-left: auto; }

/* ---------- topbar ---------- */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 14px 26px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 1.18rem; font-weight: 700; }
.env-badge {
  font-size: .74rem; color: var(--text-muted);
  background: var(--bg); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 999px;
  font-family: 'Fira Code', monospace;
}

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin-bottom: 14px; flex-wrap: wrap;
}
.card-head h2 { font-size: 1rem; font-weight: 700; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-upload { grid-template-columns: 5fr 7fr; }
.link { font-size: .85rem; font-weight: 600; }
.muted { color: var(--text-muted); font-size: .84rem; }
.small { font-size: .8rem; }
.empty { color: var(--text-muted); padding: 18px 4px; }
.hint { font-size: .8rem; color: var(--text-muted); margin-top: 10px; }

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpi-grid-5 { grid-template-columns: repeat(5, 1fr); }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; display: flex; align-items: center; gap: 13px;
}
.kpi-value { font-size: 1.35rem; font-weight: 700; font-family: 'Fira Code', monospace; letter-spacing: -.02em; }
.kpi-label { font-size: .78rem; color: var(--text-muted); }
.kpi-icon {
  width: 42px; height: 42px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.kpi-icon svg { width: 21px; height: 21px; }
.kpi-icon.blue   { background: #DBEAFE; color: #1D4ED8; }
.kpi-icon.indigo { background: #E0E7FF; color: #4338CA; }
.kpi-icon.amber  { background: #FEF3C7; color: #B45309; }
.kpi-icon.green  { background: #DCFCE7; color: #15803D; }
.kpi-action { cursor: pointer; transition: border-color .18s, box-shadow .18s; }
.kpi-action:hover { border-color: var(--primary-600); box-shadow: 0 3px 10px rgba(29,78,216,.14); text-decoration: none; }
.kpi-bad  { border-left: 4px solid var(--bad); }
.kpi-bad .kpi-value { color: var(--bad); }
.kpi-warn { border-left: 4px solid var(--warn); }
.kpi-warn .kpi-value { color: var(--warn); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table-wrap.tall { max-height: 520px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
thead th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); font-weight: 600;
  padding: 8px 10px; border-bottom: 2px solid var(--border);
  background: var(--surface); position: sticky; top: 0;
}
tbody td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: #F1F5FB; }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-family: 'Fira Code', monospace; font-size: .82rem; white-space: nowrap; }
thead th.num { font-family: 'Fira Sans', sans-serif; }
.mono { font-family: 'Fira Code', monospace; font-size: .8rem; white-space: nowrap; }
.strong { font-weight: 600; }
.clip { max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-link { cursor: pointer; }
.neg { color: var(--bad); font-weight: 600; }
.pos { color: var(--ok); font-weight: 600; }

/* ---------- tags / badges ---------- */
.tag {
  display: inline-block; font-size: .72rem; font-weight: 600;
  border-radius: 999px; padding: 2px 10px;
  background: var(--bg); color: var(--text-muted); border: 1px solid var(--border);
  white-space: nowrap;
}
.tag-ok   { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag-bad  { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.tag-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag-type { background: var(--primary-soft); color: var(--primary); border-color: transparent; text-transform: capitalize; }

/* ---------- boutons & formulaires ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px; border-radius: 8px; border: 1px solid transparent;
  font-weight: 600; font-size: .9rem; cursor: pointer;
  transition: background .18s, border-color .18s, box-shadow .18s;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary-600); color: #fff; }
.btn-primary:hover { background: var(--primary); box-shadow: 0 3px 10px rgba(29,78,216,.28); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: #B6C2D4; background: var(--bg); }
.btn-accent { background: var(--accent); color: #3B2A00; }
.btn-accent:hover { background: #D97706; color: #fff; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .6; cursor: wait; }

.icon-btn {
  background: none; border: none; cursor: pointer; color: #8CA0BE;
  padding: 6px; border-radius: 7px; display: flex;
  transition: background .18s, color .18s;
}
.icon-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.icon-btn.danger { color: #A3AFC4; }
.icon-btn.danger:hover { background: var(--bad-soft); color: var(--bad); }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; }
.field label { font-size: .8rem; font-weight: 600; color: var(--text-muted); }
.field input, .field select {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font: inherit; font-size: .9rem; background: var(--surface); color: var(--text);
  min-height: 40px;
}
.field input:focus, .field select:focus {
  outline: 2px solid var(--primary-600); outline-offset: 1px; border-color: var(--primary-600);
}
.field input[type="file"] { padding: 8px; background: var(--bg); cursor: pointer; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.search-form { display: flex; gap: 8px; }
.search-form input {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px;
  font: inherit; font-size: .88rem; width: 260px; max-width: 100%;
}
.search-form input:focus { outline: 2px solid var(--primary-600); outline-offset: 1px; }

/* ---------- sélecteur de type de fichier ---------- */
.type-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.type-option input { position: absolute; opacity: 0; }
.type-box {
  border: 1.5px solid var(--border); border-radius: 10px;
  padding: 13px 11px; display: flex; flex-direction: column; gap: 4px;
  cursor: pointer; transition: border-color .18s, background .18s; height: 100%;
}
.type-box svg { width: 20px; height: 20px; color: var(--text-muted); margin-bottom: 3px; }
.type-name { font-weight: 700; font-size: .9rem; }
.type-desc { font-size: .74rem; color: var(--text-muted); }
.type-option input:checked + .type-box {
  border-color: var(--primary-600); background: var(--primary-soft);
}
.type-option input:checked + .type-box svg { color: var(--primary-600); }
.type-option input:focus-visible + .type-box { outline: 2px solid var(--primary-600); outline-offset: 2px; }
.type-option.is-disabled .type-box { opacity: .55; cursor: not-allowed; background: var(--bg); }

/* ---------- alertes ---------- */
.alert { padding: 11px 14px; border-radius: 8px; font-size: .9rem; margin-bottom: 4px; }
.alert-ok { background: var(--ok-soft); color: var(--ok); border: 1px solid #A7E3BD; }
.alert-error { background: var(--bad-soft); color: var(--bad); border: 1px solid #F5B5B5; }
.alert-warn { background: var(--warn-soft); color: #8B5E00; border: 1px solid #F2D492; }

/* ---------- saisie des CIF (ARA) ---------- */
.cif-input {
  width: 120px; padding: 5px 8px; text-align: right;
  border: 1px solid var(--border); border-radius: 6px;
  font: inherit; font-size: .82rem; font-variant-numeric: tabular-nums;
}
.cif-input:focus { outline: none; border-color: var(--primary-600); box-shadow: 0 0 0 2px var(--primary-soft); }
tr.row-todo .cif-input { background: var(--warn-soft); border-color: #F2D492; }
tr.row-ok > td { background: var(--ok-soft); }
.kpi-card.kpi-ok { border-left: 3px solid var(--ok); }

/* ---------- gestion des utilisateurs ---------- */
.actions-cell { white-space: nowrap; }
.btn-icon {
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
  width: 28px; height: 28px; border-radius: 7px; font-size: .85rem; line-height: 1;
  color: var(--text-muted); margin-right: 2px;
}
.btn-icon:hover { border-color: var(--primary-600); color: var(--primary-600); background: var(--primary-soft); }
.btn-icon-danger:hover { border-color: var(--bad); color: var(--bad); background: var(--bad-soft); }
tr.row-off > td { opacity: .55; }
tr.edit-row > td { background: var(--primary-soft); }
.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; padding: 6px 0; }
.inline-form .field { margin: 0; }
.inline-form input, .inline-form select { min-width: 150px; }
a.user-name { color: inherit; }
a.user-name:hover { text-decoration: underline; }
a.avatar { text-decoration: none; }

/* ---------- synthèse transverse ---------- */
.link-chip {
  display: inline-block; padding: 1px 6px; margin: 1px 2px 1px 0;
  border-radius: 5px; background: var(--primary-soft); color: var(--primary-600);
  font-size: .7rem; font-weight: 600; white-space: nowrap;
}
.link-chip:hover { background: var(--primary-600); color: #fff; text-decoration: none; }
tr.row-total > td { background: var(--warn-soft); font-weight: 700; }

/* ---------- filtres analyse ---------- */
.filter-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 14px; }
.filter-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 2px; }

.hidden { display: none !important; }

/* ---------- colonnes de statistiques import / export (accueil) ---------- */
.stat-columns {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 18px; margin-bottom: 20px;
}
.stat-col {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  box-shadow: var(--shadow-sm); border-top: 3px solid var(--primary-600);
}
.stat-col-export { border-top-color: #16a34a; }
.stat-col-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.stat-col-head h2 { font-size: 1rem; margin: 0; }
.stat-col-icon {
  display: grid; place-items: center; width: 34px; height: 34px;
  border-radius: 9px; background: var(--primary-soft); color: var(--primary-600);
}
.stat-col-icon svg { width: 19px; height: 19px; }
.stat-col-export .stat-col-icon { background: rgba(22, 163, 74, .12); color: #16a34a; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat-item { border-left: 2px solid var(--border); padding-left: 12px; }
.stat-value { font-size: 1.45rem; font-weight: 700; letter-spacing: -.02em; }
.stat-label { font-size: .74rem; color: var(--text-muted); margin-top: 2px; line-height: 1.3; }
.tag-export { background: rgba(22, 163, 74, .12); color: #15803d; }

/* ---------- onglets (Importation / Exportation) ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab {
  padding: 9px 16px; font-size: .87rem; font-weight: 600; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.is-active { color: var(--primary-600); border-bottom-color: var(--primary-600); }

/* ---------- puce filtre entreprise (analyse QPT) ---------- */
.ent-filter-chip {
  display: flex; align-items: center; gap: 8px; min-height: 40px;
  padding: 6px 10px; border: 1px solid var(--primary-600);
  background: var(--primary-soft); border-radius: 8px;
  font-size: .85rem; font-weight: 600; color: var(--primary);
}
.ent-filter-chip .clip { max-width: 100%; }
.chip-remove {
  margin-left: auto; color: var(--primary); font-weight: 700;
  padding: 2px 7px; border-radius: 6px; line-height: 1;
}
.chip-remove:hover { background: var(--primary-600); color: #fff; text-decoration: none; }

/* ---------- barre de statuts ---------- */
.status-track {
  display: flex; height: 14px; border-radius: 999px; overflow: hidden;
  background: var(--bg); border: 1px solid var(--border);
}
.status-seg { height: 100%; min-width: 3px; }
.st-ok    { background: #22C55E; }
.st-bad   { background: #EF4444; }
.st-warn  { background: #F59E0B; }
.st-grey  { background: #94A3B8; }
.st-muted { background: #CBD5E1; }
.status-legend { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 10px; font-size: .82rem; color: var(--text-muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.st-ok { background: #22C55E; } .dot.st-bad { background: #EF4444; }
.dot.st-warn { background: #F59E0B; } .dot.st-grey { background: #94A3B8; } .dot.st-muted { background: #CBD5E1; }

/* ---------- pagination ---------- */
.pagination {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border);
}
.page-btn {
  min-width: 34px; padding: 6px 11px; text-align: center;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: .85rem; font-weight: 600; color: var(--text);
  background: var(--surface); cursor: pointer;
  transition: border-color .18s, background .18s;
}
.page-btn:hover { border-color: var(--primary-600); text-decoration: none; background: var(--primary-soft); }
.page-btn.is-current { background: var(--primary-600); border-color: var(--primary-600); color: #fff; cursor: default; }
.page-btn.is-disabled { opacity: .45; pointer-events: none; }
.page-ellipsis { color: var(--text-muted); padding: 0 2px; }
.page-info { margin-left: auto; font-size: .82rem; color: var(--text-muted); }
.search-form select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font: inherit; font-size: .85rem; background: var(--surface); cursor: pointer;
}

/* ---------- entreprise ---------- */
.ent-head-card { padding: 20px 22px; }
.ent-identity { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.ent-name { font-size: 1.15rem; font-weight: 700; }
.ent-nif { font-size: .88rem; color: var(--text-muted); }

/* ---------- login ---------- */
.login-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(900px 500px at 15% -10%, rgba(37,99,235,.20), transparent 60%),
    radial-gradient(700px 420px at 110% 110%, rgba(245,158,11,.14), transparent 60%),
    var(--sidebar-bg);
  padding: 20px;
}
.login-panel {
  display: grid; grid-template-columns: 1.1fr 1fr; max-width: 880px; width: 100%;
  background: var(--surface); border-radius: 18px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(2, 8, 30, .45);
}
.login-left {
  background: linear-gradient(160deg, #10224E, #0B1533);
  color: #DCE5F5; padding: 44px 38px; display: flex; align-items: center;
}
.login-brand h1 { margin: 18px 0 8px; letter-spacing: .08em; color: #fff; }
.login-brand p { font-size: .92rem; color: #A9B7D2; }
.login-features { margin-top: 22px; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.login-features li {
  font-size: .85rem; padding-left: 24px; position: relative; color: #C3CFE4;
}
.login-features li::before {
  content: ''; position: absolute; left: 0; top: 4px;
  width: 14px; height: 14px; border-radius: 50%;
  background: rgba(245,158,11,.2);
  box-shadow: inset 0 0 0 4px rgba(245,158,11,.9);
}
.login-right { padding: 44px 38px; display: flex; align-items: center; }
.login-form { width: 100%; }
.login-form h2 { font-size: 1.3rem; }
.login-form .muted { margin-bottom: 20px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .kpi-grid, .kpi-grid-5 { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-upload { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .sidebar { display: none; }
  .kpi-grid, .kpi-grid-5, .filter-grid { grid-template-columns: 1fr; }
  .login-panel { grid-template-columns: 1fr; }
  .login-left { display: none; }
  .content { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
