/* =========================================================
   UniHub — Design tokens
   Palette neutre et professionnelle, indépendante de tout
   secteur métier particulier (banque, télécom, administration...).
   ========================================================= */

:root {
  color-scheme: light;

  /* Surfaces */
  --surface-0: #f5f6f8;      /* fond général de l'app */
  --surface-1: #ffffff;      /* cartes, tableaux, panneaux */
  --surface-2: #f9fafb;      /* zones alternées / hover léger */
  --surface-sidebar: #10192b; /* sidebar sombre, neutre */
  --surface-overlay: rgba(15, 23, 42, 0.55);

  /* Texte */
  --text-primary: #0f172a;
  --text-secondary: #52555c;
  --text-muted: #898781;
  --text-on-dark: #f5f6f8;
  --text-on-dark-muted: #97a2b8;

  /* Bordures */
  --border-hairline: #e3e5ea;
  --border-strong: #cdd1d9;

  /* Marque / accent (bleu — slot catégoriel 1 du palette validé) */
  --brand-50: #eaf2fc;
  --brand-100: #cde2fb;
  --brand-400: #3987e5;
  --brand-500: #2a78d6;
  --brand-600: #1c5cab;
  --brand-700: #104281;

  /* Statuts (palette fixe, jamais réutilisée pour des séries) */
  --status-good: #0ca30c;
  --status-good-bg: #e7f7e7;
  --status-warning: #b3790a;
  --status-warning-bg: #fdf1d9;
  --status-serious: #c15a36;
  --status-serious-bg: #fbe9e1;
  --status-critical: #d03b3b;
  --status-critical-bg: #fbe4e4;
  --status-neutral: #52555c;
  --status-neutral-bg: #eceef1;

  /* Catégoriel (graphiques) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #4a3aa7;

  /* Rayon / ombre */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.16);

  /* Typo */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --sidebar-width: 264px;
  --topbar-height: 64px;
}

* { box-sizing: border-box; }

html, body, #root {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--surface-0);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: 14px;
}

a { color: var(--brand-600); text-decoration: none; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

/* ---------- Layout ---------- */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.main-area {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.page-content {
  padding: 28px 32px 48px;
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 22px;
  color: var(--text-primary);
}

.page-header p.subtitle {
  margin: 6px 0 0;
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 640px;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--surface-sidebar);
  color: var(--text-on-dark);
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand .brand-name {
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  line-height: 1.1;
}

.sidebar-brand .brand-sub {
  font-size: 11px;
  color: var(--text-on-dark-muted);
  letter-spacing: 0.02em;
}

.sidebar-nav {
  flex: 1;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.sidebar-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-on-dark-muted);
  padding: 14px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-on-dark-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-item svg { flex-shrink: 0; width: 18px; height: 18px; }

.nav-item:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
}

.nav-item.active {
  background: var(--brand-500);
  color: #fff;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-group-trigger {
  width: 100%;
  border: none;
  text-align: left;
}

.nav-group-chevron {
  margin-left: auto;
  width: 16px;
  height: 16px;
  transition: transform 0.15s;
}

.nav-group-chevron.open {
  transform: rotate(180deg);
}

.nav-submenu {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-left: 10px;
  padding-left: 10px;
  border-left: 1px solid rgba(255,255,255,0.12);
}

.nav-subrow {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-subitem {
  flex: 1;
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text-on-dark-muted);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.nav-subitem:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
}

.nav-subitem.active {
  background: rgba(59, 130, 246, 0.22);
  color: #fff;
}

.nav-subadd {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-on-dark-muted);
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.nav-subadd:hover {
  color: #fff;
  border-color: rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.1);
}

.sidebar-footer {
  padding: 14px 20px 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 12px;
  color: var(--text-on-dark-muted);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.sidebar-user-info {
  min-width: 0;
  flex: 1;
}

.sidebar-user-name {
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 11px;
  color: var(--text-on-dark-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logout {
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.06);
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.sidebar-logout:hover {
  background: rgba(255,255,255,0.12);
}

.sidebar-version {
  font-size: 11px;
  line-height: 1.4;
}

/* ---------- Login ---------- */
.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: linear-gradient(145deg, #edf2f7, #f8fafc);
}

.login-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background: radial-gradient(circle at 20% 20%, #1f3f6b, #0f172a 55%);
}

.login-hero-panel {
  max-width: 460px;
  color: #e2e8f0;
}

.login-hero-panel h1 {
  font-size: 44px;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
  color: #fff;
}

.login-hero-panel p {
  margin: 0;
  font-size: 17px;
  line-height: 1.5;
}

.login-card-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.login-card {
  width: 100%;
  max-width: 520px;
  padding: 24px;
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.login-alert {
  margin-bottom: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid #fcd34d;
  background: #fffbeb;
  color: #92400e;
  padding: 10px 12px;
  font-size: 13px;
}

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-height);
  background: var(--surface-1);
  border-bottom: 1px solid var(--border-hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--brand-500);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600;
}

/* ---------- Cards / stat tiles ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.card-pad { padding: 22px 24px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

.stat-tile {
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-tile .stat-label {
  font-size: 12.5px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-tile .stat-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}

.stat-tile .stat-value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: proportional-nums;
  color: var(--text-primary);
}

.stat-tile .stat-delta { font-size: 12px; color: var(--text-muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--brand-500); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }

.btn-secondary {
  background: var(--surface-1);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-2); }

.btn-danger { background: var(--surface-1); color: var(--status-critical); border-color: var(--status-critical-bg); }
.btn-danger:hover { background: var(--status-critical-bg); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text-primary); }

.btn-sm { padding: 6px 11px; font-size: 12.5px; }

.icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-hairline);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-primary); }
.icon-btn svg { width: 15px; height: 15px; }

/* ---------- Filters bar ---------- */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.input, .select, textarea.textarea {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 13.5px;
  color: var(--text-primary);
  background: var(--surface-1);
  outline: none;
  min-width: 0;
}

.input:focus, .select:focus, textarea.textarea:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-50);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  background: var(--surface-1);
  min-width: 220px;
}
.search-box svg { width: 15px; height: 15px; color: var(--text-muted); }
.search-box input { border: none; outline: none; flex: 1; background: transparent; }

/* ---------- Table ---------- */
.table-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-hairline);
  white-space: nowrap;
}

.data-table tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-hairline);
  color: var(--text-primary);
  vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tbody tr.clickable:hover { background: var(--surface-2); }

.cell-muted { color: var(--text-secondary); }
.cell-mono { font-variant-numeric: tabular-nums; }

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.table-pagination-summary {
  color: var(--text-secondary);
  font-size: 12.5px;
}

.table-pagination-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.table-pagination-controls .select {
  width: 70px;
}

.table-pagination-label,
.table-pagination-page {
  color: var(--text-secondary);
  font-size: 12.5px;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }

.badge-good { background: var(--status-good-bg); color: var(--status-good); }
.badge-warning { background: var(--status-warning-bg); color: var(--status-warning); }
.badge-serious { background: var(--status-serious-bg); color: var(--status-serious); }
.badge-critical { background: var(--status-critical-bg); color: var(--status-critical); }
.badge-neutral { background: var(--status-neutral-bg); color: var(--status-neutral); }
.badge-brand { background: var(--brand-50); color: var(--brand-600); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--surface-overlay);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 20px;
  overflow-y: auto;
  z-index: 100;
}

.modal-card {
  background: var(--surface-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  overflow: hidden;
}

.modal-card.modal-wide { max-width: 780px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-hairline);
}

.modal-header h2 { font-size: 16px; }

.modal-body { padding: 22px; display: flex; flex-direction: column; gap: 16px; max-height: 70vh; overflow-y: auto; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--border-hairline);
  background: var(--surface-2);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-grid .span-2 { grid-column: 1 / -1; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border-hairline);
  margin-bottom: 20px;
}

.tab-item {
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab-item.active {
  color: var(--brand-600);
  border-bottom-color: var(--brand-500);
}

/* ---------- Timeline ---------- */
.timeline { display: flex; flex-direction: column; }

.timeline-item {
  display: flex;
  gap: 14px;
  position: relative;
  padding-bottom: 22px;
}

.timeline-item:last-child { padding-bottom: 0; }

.timeline-marker {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--brand-500);
  margin-top: 4px;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.timeline-item:not(:last-child)::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 16px;
  bottom: -6px;
  width: 2px;
  background: var(--border-hairline);
}

.timeline-content .timeline-title { font-size: 13.5px; font-weight: 600; color: var(--text-primary); }
.timeline-content .timeline-date { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ---------- Misc ---------- */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.flex-row { display: flex; align-items: center; gap: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.divider { height: 1px; background: var(--border-hairline); margin: 18px 0; }

.pill-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 999px;
  border: 1px solid var(--border-hairline);
}

.pill-toggle button {
  border: none;
  background: transparent;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.pill-toggle button.active {
  background: var(--surface-1);
  color: var(--brand-600);
  box-shadow: var(--shadow-sm);
}

.doc-list { display: flex; flex-direction: column; gap: 10px; }

.doc-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  background: var(--surface-1);
}

.doc-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--brand-50);
  color: var(--brand-600);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.doc-meta { font-size: 12px; color: var(--text-muted); }

.kv-list { display: flex; flex-direction: column; gap: 12px; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; padding: 4px 0; }
.kv-row .kv-label { color: var(--text-secondary); }
.kv-row .kv-value { color: var(--text-primary); font-weight: 500; text-align: right; }

.code-block {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  overflow-x: auto;
  white-space: pre;
}

.toggle-switch {
  width: 40px; height: 22px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  border: none;
  flex-shrink: 0;
}
.toggle-switch.on { background: var(--status-good); }
.toggle-switch .knob {
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.toggle-switch.on .knob { transform: translateX(18px); }

.helper-text { font-size: 12px; color: var(--text-muted); }

/* ---------- Agent documentaire ---------- */
.agent-query-form {
  display: flex;
  gap: 14px;
  align-items: flex-end;
}

.agent-query-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.agent-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.agent-response-text {
  margin: 0;
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
}

.agent-detail-block {
  margin: 0;
  white-space: pre-wrap;
  background: var(--surface-2);
  border: 1px solid var(--border-hairline);
  border-radius: var(--radius-md);
  padding: 12px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  color: var(--text-primary);
  line-height: 1.5;
}

@media (max-width: 900px) {
  .form-grid { grid-template-columns: 1fr; }
  .agent-query-form { flex-direction: column; align-items: stretch; }
  .agent-query-actions { justify-content: flex-end; }
  .agent-grid { grid-template-columns: 1fr; }
  .sidebar { transform: translateX(-100%); }
  .main-area { margin-left: 0; }
  .login-shell { grid-template-columns: 1fr; }
  .login-hero { display: none; }
}
/*$vite$:1*/