/* ============================================================
   Clear'Invoice — Contrôle Référentiel
   CSS principal — Ventya Design System
   ============================================================ */

/* ── Variables ──────────────────────────────────────────────── */
:root {
  /* Palette Ventya */
  --blue:          #1B4F8A;
  --blue-dark:     #143d6b;
  --blue-light:    #d6e4f0;
  --orange:        #E8833A;
  --orange-light:  #fef0e6;
  --green:         #1a7a4a;
  --green-light:   #d6f0e4;
  --red:           #c0392b;
  --red-light:     #fdecea;
  --yellow:        #b7950b;
  --yellow-light:  #fef9e7;
  --purple:        #6c3483;
  --purple-light:  #f4ecf7;

  /* Neutres */
  --grey-900:  #1a1a2e;
  --grey-800:  #212529;
  --grey-700:  #374151;
  --grey-500:  #6b7280;
  --grey-400:  #9ca3af;
  --grey-200:  #e5e7eb;
  --grey-100:  #f3f4f6;
  --grey-50:   #f9fafb;
  --white:     #ffffff;

  /* Layout */
  --sidebar-w:       240px;
  --topbar-h:        56px;
  --border-radius:   8px;
  --border-radius-sm:4px;
  --shadow-sm:       0 1px 3px rgba(0,0,0,.08);
  --shadow-md:       0 4px 12px rgba(0,0,0,.10);
  --shadow-lg:       0 8px 24px rgba(0,0,0,.12);

  /* Transitions */
  --transition: .18s ease;

  /* Typography */
  --font:      'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Consolas', monospace;
}

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  color: var(--grey-700);
  background: var(--grey-50);
  line-height: 1.6;
  display: flex;
  min-height: 100vh;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; display: block; }

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--blue);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
  overflow-y: auto;
}

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}

.sidebar-logo {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -.5px;
}
.logo-ci  { color: var(--white); }
.logo-inv { color: #7ec8e3; }

.sidebar-tenant {
  font-size: .75rem;
  color: rgba(255,255,255,.6);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-section {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.4);
  padding: 12px 16px 4px;
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: rgba(255,255,255,.82);
  font-size: .875rem;
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  border-radius: 0;
  position: relative;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255,255,255,.12);
  color: var(--white);
  text-decoration: none;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: #7ec8e3;
}

.nav-icon { font-size: 1rem; flex-shrink: 0; }

.badge-count {
  margin-left: auto;
  background: var(--orange);
  color: var(--white);
  font-size: .7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
}

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,.12);
  padding: 8px 0;
}

.nav-logout { color: rgba(255,100,100,.8); }
.nav-logout:hover { color: #ff6b6b; background: rgba(255,0,0,.08); }

/* ── Main wrapper ───────────────────────────────────────────── */
.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ─────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--grey-200);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--grey-700);
}

.topbar-breadcrumb {
  font-size: .9rem;
  font-weight: 600;
  color: var(--grey-700);
  flex: 1;
}

.topbar-right { display: flex; align-items: center; gap: 12px; }

/* ── Main content ───────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
}

/* ── Footer ─────────────────────────────────────────────────── */
.app-footer {
  padding: 12px 24px;
  font-size: .75rem;
  color: var(--grey-400);
  border-top: 1px solid var(--grey-200);
  background: var(--white);
}

/* ── Page header ────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--grey-800);
}

.page-subtitle {
  font-size: .85rem;
  color: var(--grey-500);
  margin-top: 2px;
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--grey-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--grey-800);
}

.card-body { padding: 20px; }
.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--grey-200);
  background: var(--grey-50);
}

/* ── Stats KPI ──────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--grey-200);
  border-radius: var(--border-radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-sm);
  border-top: 3px solid var(--blue);
}

.stat-card.orange { border-top-color: var(--orange); }
.stat-card.green  { border-top-color: var(--green);  }
.stat-card.red    { border-top-color: var(--red);    }

.stat-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--grey-500); }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--grey-800); line-height: 1.1; }
.stat-sub   { font-size: .78rem; color: var(--grey-400); }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

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

thead th {
  background: var(--grey-50);
  border-bottom: 2px solid var(--grey-200);
  padding: 10px 14px;
  text-align: left;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--grey-500);
  white-space: nowrap;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--grey-100);
  vertical-align: middle;
}

tbody tr:hover { background: var(--grey-50); }
tbody tr:last-child td { border-bottom: none; }

.td-mono { font-family: var(--font-mono); font-size: .8rem; }
.td-muted { color: var(--grey-400); font-size: .8rem; }

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: .73rem;
  font-weight: 600;
}
.badge-success   { background: var(--green-light);  color: var(--green);  }
.badge-danger    { background: var(--red-light);    color: var(--red);    }
.badge-warning   { background: var(--yellow-light); color: var(--yellow); }
.badge-secondary { background: var(--grey-100);     color: var(--grey-500); }
.badge-info      { background: var(--blue-light);   color: var(--blue);   }

.badge-role-superadmin { background: var(--purple-light); color: var(--purple); }
.badge-role-admin  { background: var(--blue-light);   color: var(--blue);   }
.badge-role-user   { background: var(--green-light);  color: var(--green);  }
.badge-role-reader { background: var(--grey-100);     color: var(--grey-500); }

/* ── Boutons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--border-radius-sm);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  line-height: 1.4;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }

.btn-primary   { background: var(--blue);   color: var(--white); border-color: var(--blue); }
.btn-primary:hover { background: var(--blue-dark); }

.btn-secondary { background: var(--white);  color: var(--grey-700); border-color: var(--grey-200); }
.btn-secondary:hover { background: var(--grey-50); }

.btn-success   { background: var(--green);  color: var(--white); border-color: var(--green); }
.btn-danger    { background: var(--red);    color: var(--white); border-color: var(--red); }
.btn-warning   { background: var(--orange); color: var(--white); border-color: var(--orange); }

.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn-full { width: 100%; justify-content: center; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Formulaires ────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }

.form-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: .85rem;
  font-weight: 500;
  color: var(--grey-700);
  margin-bottom: 6px;
}
.form-label-link { font-size: .78rem; font-weight: 400; color: var(--blue); }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--grey-200);
  border-radius: var(--border-radius-sm);
  font-size: .9rem;
  font-family: var(--font);
  color: var(--grey-800);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(27,79,138,.12);
}

.form-input.error { border-color: var(--red); }
.form-error { font-size: .78rem; color: var(--red); margin-top: 4px; }
.form-hint  { font-size: .78rem; color: var(--grey-400); margin-top: 4px; }

.form-check { display: flex; align-items: center; }
.check-label { display: flex; align-items: center; gap: 8px; font-size: .875rem; cursor: pointer; }

.input-password-wrap { position: relative; }
.input-password-wrap .form-input { padding-right: 40px; }
.password-toggle {
  position: absolute;
  right: 10px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: .9rem;
}

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

/* ── Alertes / Flash ────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--border-radius-sm);
  margin-bottom: 16px;
  font-size: .875rem;
  border-left: 4px solid;
}
.alert-success { background: var(--green-light);  color: var(--green);  border-color: var(--green);  }
.alert-error   { background: var(--red-light);    color: var(--red);    border-color: var(--red);    }
.alert-warning { background: var(--yellow-light); color: var(--yellow); border-color: var(--yellow); }
.alert-info    { background: var(--blue-light);   color: var(--blue);   border-color: var(--blue);   }

.alert-close { background: none; border: none; cursor: pointer; font-size: 1.1rem; line-height: 1; color: inherit; opacity: .6; }
.alert-close:hover { opacity: 1; }

/* ── Auth pages ─────────────────────────────────────────────── */
.auth-body { display: flex; justify-content: center; align-items: center; min-height: 100vh; background: var(--grey-100); }

.auth-container { width: 100%; max-width: 420px; padding: 24px 16px; }

.auth-card {
  background: var(--white);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}

.auth-header { text-align: center; margin-bottom: 28px; }
.auth-logo { font-size: 1.8rem; font-weight: 700; }
.auth-tagline { font-size: .85rem; color: var(--grey-500); margin-top: 4px; }

.auth-footer { text-align: center; font-size: .75rem; color: var(--grey-400); margin-top: 16px; }

/* ── Upload zone ────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--grey-200);
  border-radius: var(--border-radius);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--grey-50);
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--blue);
  background: var(--blue-light);
}

.upload-icon { font-size: 2.5rem; margin-bottom: 12px; }
.upload-text { font-size: .9rem; color: var(--grey-500); }
.upload-text strong { color: var(--blue); }
.upload-meta { font-size: .75rem; color: var(--grey-400); margin-top: 8px; }

/* ── Progress bar ───────────────────────────────────────────── */
.progress { background: var(--grey-100); border-radius: 10px; height: 8px; overflow: hidden; }
.progress-bar {
  height: 100%;
  background: var(--blue);
  border-radius: 10px;
  transition: width .3s ease;
}
.progress-bar.success { background: var(--green); }
.progress-bar.warning { background: var(--orange); }

/* ── Pagination ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: var(--border-radius-sm);
  font-size: .85rem;
  color: var(--grey-700);
  border: 1px solid var(--grey-200);
  background: var(--white);
  text-decoration: none;
  transition: all var(--transition);
}

.page-link:hover { background: var(--grey-50); text-decoration: none; }
.page-link.active { background: var(--blue); color: var(--white); border-color: var(--blue); }
.page-link.disabled { opacity: .4; pointer-events: none; }

/* ── Filters bar ────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filter-bar .form-input,
.filter-bar .form-select {
  width: auto;
  min-width: 140px;
}

.search-input-wrap { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.search-input-wrap .form-input { padding-left: 36px; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--grey-400); }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-wrapper {
    margin-left: 0;
  }
  .sidebar-toggle { display: block; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .main-content { padding: 16px; }
  .auth-card { padding: 24px 20px; }
}
