:root {
  --gts-navy: #122a52;
  --gts-navy-dark: #0c1d3b;
  --gts-orange: #f47b20;
  --gts-orange-dark: #d96812;
  --gts-blue: #2fb4e8;
  --gts-bg: #eef1f8;
  --gts-border: #e6eaf2;
  --gts-text: #1c2534;
  --gts-text-muted: #7a8499;
  --sidebar-width: 260px;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(18,42,82,.05), 0 1px 3px rgba(18,42,82,.06);
  --shadow-md: 0 4px 14px rgba(18,42,82,.08);
  --shadow-lg: 0 12px 32px rgba(18,42,82,.14);
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gts-bg);
  background-image: radial-gradient(circle at 0% 0%, rgba(47,180,232,.06), transparent 40%),
                     radial-gradient(circle at 100% 0%, rgba(244,123,32,.05), transparent 40%);
  background-attachment: fixed;
  color: var(--gts-text);
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; transition: color .15s ease; }

::selection { background: rgba(244,123,32,.25); }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c7cee0; border-radius: 20px; }
::-webkit-scrollbar-thumb:hover { background: #aeb8d1; }

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

.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(190deg, var(--gts-navy) 0%, var(--gts-navy-dark) 100%);
  color: #fff;
  flex-shrink: 0;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: transform .25s ease;
  box-shadow: 4px 0 24px rgba(0,0,0,.12);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: 1.3rem 1.3rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand img { height: 42px; background: #fff; border-radius: 10px; padding: 4px; box-shadow: var(--shadow-sm); }
.sidebar-brand .brand-text { line-height: 1.15; }
.sidebar-brand .brand-text strong { font-size: 1.05rem; letter-spacing: .5px; display:block; }
.sidebar-brand .brand-text span { font-size: .64rem; color: #93a2c4; text-transform: uppercase; letter-spacing: .6px; }

.sidebar-nav { flex: 1; padding: 1.1rem .8rem; overflow-y: auto; }
.sidebar-nav .nav-section { color: #6f7fa3; font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; padding: 1.1rem .7rem .4rem; }
.sidebar-nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: .75rem;
  color: #ccd6ec;
  padding: .65rem .85rem;
  border-radius: 10px;
  font-size: .89rem;
  margin-bottom: .2rem;
  font-weight: 500;
  transition: background .15s ease, color .15s ease, transform .15s ease;
}
.sidebar-nav a i { font-size: 1.08rem; width: 20px; text-align: center; }
.sidebar-nav a:hover { background: rgba(255,255,255,.08); color: #fff; transform: translateX(2px); }
.sidebar-nav a.active { background: linear-gradient(90deg, var(--gts-orange), #ff9142); color: #fff; box-shadow: 0 4px 12px rgba(244,123,32,.35); }
.sidebar-nav a.active:hover { transform: none; }

.sidebar-footer { padding: 1rem 1.3rem; border-top: 1px solid rgba(255,255,255,.08); font-size: .76rem; color: #7d8bab; }

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

.topbar {
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--gts-border);
  padding: .95rem 1.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 900;
}
.topbar h1 { font-size: 1.2rem; margin: 0; font-weight: 800; color: var(--gts-navy); letter-spacing: -.2px; }
.topbar .page-subtitle { font-size: .8rem; color: var(--gts-text-muted); margin-top: 1px; }

.topbar-user { display: flex; align-items: center; gap: .7rem; cursor: pointer; padding: .3rem .5rem; border-radius: 10px; transition: background .15s ease; }
.topbar-user:hover { background: #f2f4fa; }
.topbar-user .avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gts-orange), #ff9a4d); color: #fff; display: flex;
  align-items: center; justify-content: center; font-weight: 700; font-size: .85rem;
  box-shadow: var(--shadow-sm);
}
.topbar-user .user-meta { line-height: 1.15; }
.topbar-user .user-meta strong { font-size: .85rem; display: block; color: var(--gts-navy); }
.topbar-user .user-meta span { font-size: .72rem; color: var(--gts-text-muted); text-transform: capitalize; }

.page-body { padding: 1.8rem; flex: 1; }

.btn-toggle-sidebar { display: none; background: none; border: none; font-size: 1.3rem; color: var(--gts-navy); }

/* ---------- Cards / Stats ---------- */
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 1.3rem 1.4rem;
  border: 1px solid var(--gts-border);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 100%;
  transition: transform .18s ease, box-shadow .18s ease;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-card .stat-icon {
  width: 52px; height: 52px; border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.35rem; color: #fff; flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.stat-card .stat-label { font-size: .78rem; color: var(--gts-text-muted); margin-bottom: .2rem; font-weight: 500; }
.stat-card .stat-value { font-size: 1.4rem; font-weight: 800; color: var(--gts-navy); letter-spacing: -.3px; }

.card-panel {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--gts-border);
  box-shadow: var(--shadow-sm);
  padding: 1.4rem;
}
.card-panel .panel-title { font-weight: 800; color: var(--gts-navy); margin-bottom: 1rem; font-size: 1.02rem; letter-spacing: -.2px; }

/* ---------- Tables ---------- */
.table-gts { width: 100%; border-collapse: separate; border-spacing: 0; }
.table-gts thead th {
  background: #f5f7fc;
  color: var(--gts-navy);
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .8rem .9rem;
  text-align: left;
  border-bottom: 2px solid var(--gts-border);
  white-space: nowrap;
}
.table-gts thead th:first-child { border-top-left-radius: 10px; }
.table-gts thead th:last-child { border-top-right-radius: 10px; }
.table-gts tbody td { padding: .8rem .9rem; border-bottom: 1px solid var(--gts-border); font-size: .87rem; vertical-align: middle; }
.table-gts tbody tr { transition: background .12s ease; }
.table-gts tbody tr:hover { background: #f7f9fd; }
.table-gts tbody tr:last-child td { border-bottom: none; }
.table-gts tfoot td { padding: .8rem .9rem; background: #f9fafd; }

.badge-status { display: inline-flex; align-items: center; gap: .35rem; padding: .28rem .65rem; border-radius: 20px; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.badge-status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-emise { background: #e6f0ff; color: #1d4ed8; }
.badge-payee { background: #e1f8ed; color: #0f9d58; }
.badge-brouillon { background: #eef0f4; color: #6b7685; }
.badge-annulee { background: #fde8e8; color: #d92d20; }

/* ---------- Forms ---------- */
.form-label { font-weight: 600; font-size: .84rem; color: var(--gts-navy); margin-bottom: .35rem; }
.form-control, .form-select {
  border-radius: 9px;
  border: 1px solid #dbe1ec;
  padding: .58rem .85rem;
  font-size: .89rem;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:focus, .form-select:focus {
  border-color: var(--gts-blue);
  box-shadow: 0 0 0 .18rem rgba(47,180,232,.15);
}
.form-control::placeholder { color: #adb5c4; }

/* ---------- Buttons ---------- */
.btn { transition: transform .12s ease, box-shadow .12s ease, background .15s ease; }

.btn-gts-primary {
  background: linear-gradient(135deg, var(--gts-orange), #ff9142);
  border-color: var(--gts-orange);
  color: #fff;
  font-weight: 600;
  border-radius: 9px;
  padding: .58rem 1.15rem;
  box-shadow: 0 4px 12px rgba(244,123,32,.28);
}
.btn-gts-primary:hover { background: var(--gts-orange-dark); border-color: var(--gts-orange-dark); color: #fff; transform: translateY(-1px); box-shadow: 0 6px 16px rgba(244,123,32,.35); }

.btn-gts-navy {
  background: var(--gts-navy);
  border-color: var(--gts-navy);
  color: #fff;
  font-weight: 600;
  border-radius: 9px;
  padding: .58rem 1.15rem;
}
.btn-gts-navy:hover { background: var(--gts-navy-dark); border-color: var(--gts-navy-dark); color: #fff; transform: translateY(-1px); }

.btn-outline-gts {
  border: 1px solid #dbe1ec;
  color: var(--gts-navy);
  border-radius: 9px;
  background: #fff;
  font-weight: 500;
}
.btn-outline-gts:hover { background: #f5f7fc; color: var(--gts-navy); border-color: #c7cee0; transform: translateY(-1px); }

.item-row .form-control, .item-row .form-select { font-size: .84rem; padding: .42rem .6rem; }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 15% 20%, #1c3768, var(--gts-navy-dark) 55%);
}
.login-page::before, .login-page::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(10px);
}
.login-page::before { width: 420px; height: 420px; background: rgba(244,123,32,.18); top: -140px; right: -120px; }
.login-page::after { width: 320px; height: 320px; background: rgba(47,180,232,.16); bottom: -120px; left: -80px; }
.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 2.4rem 2.5rem;
  width: 100%;
  max-width: 410px;
  box-shadow: 0 30px 70px rgba(0,0,0,.35);
  position: relative;
  z-index: 1;
}
.login-card img { height: 62px; display: block; margin: 0 auto 1.1rem; }

/* ---------- Sidebar overlay (mobile) ---------- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(12,20,40,.45);
  z-index: 999;
  opacity: 0;
  transition: opacity .2s ease;
}
.sidebar-overlay.show { display: block; opacity: 1; }
body.sidebar-locked { overflow: hidden; }

@media (max-width: 991px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .btn-toggle-sidebar { display: block; }
}

/* ==================================================================
   RESPONSIVE - tablette et mobile
   ================================================================== */
@media (max-width: 768px) {
  .page-body { padding: 1.1rem; }
  .card-panel { padding: 1.1rem; border-radius: 12px; }
  .card-panel .panel-title { font-size: .95rem; }

  .topbar { padding: .7rem .9rem; }
  .topbar h1 { font-size: 1.02rem; }
  .topbar .page-subtitle { display: none; }
  .topbar-user .user-meta { display: none; }
  .topbar-user .avatar { width: 34px; height: 34px; }

  .stat-card { padding: .9rem 1rem; gap: .7rem; border-radius: 12px; }
  .stat-card .stat-icon { width: 42px; height: 42px; font-size: 1.05rem; border-radius: 10px; }
  .stat-card .stat-label { font-size: .7rem; }
  .stat-card .stat-value { font-size: 1.1rem; }

  .row.g-3 { --bs-gutter-x: .6rem; --bs-gutter-y: .6rem; }

  /* Barres d'outils (recherche + bouton d'action) : empilees et pleine largeur */
  .card-panel > .d-flex.justify-content-between.flex-wrap {
    flex-direction: column;
    align-items: stretch !important;
  }
  .card-panel > .d-flex.justify-content-between.flex-wrap > a.btn,
  .card-panel > .d-flex.justify-content-between.flex-wrap > button.btn {
    width: 100%;
    text-align: center;
  }

  /* Formulaires de recherche / filtres : chaque champ prend toute la largeur */
  form.d-flex { flex-wrap: wrap; }
  form.d-flex .form-control,
  form.d-flex .form-select {
    flex: 1 1 100%;
    width: 100% !important;
    min-width: 0 !important;
  }
  form.d-flex button[type="submit"] { flex: 1 1 100%; width: 100%; }

  /* Boutons d'action empiles (Enregistrer/Annuler, Modifier/Nouvelle facture...) */
  .card-panel div.d-flex.gap-2:not(.flex-wrap) { flex-direction: column; }
  .card-panel div.d-flex.gap-2:not(.flex-wrap) > .btn { width: 100%; text-align: center; }

  /* Tables : defilement tactile fluide */
  .table-responsive { -webkit-overflow-scrolling: touch; }
  .table-gts thead th, .table-gts tbody td { padding: .6rem .65rem; font-size: .82rem; }

  /* Formulaires : espacer un peu moins */
  .form-label { font-size: .8rem; }

  .login-card { padding: 2rem 1.5rem; max-width: 92vw; }
}

@media (max-width: 420px) {
  .stat-card .stat-value { font-size: 1rem; }
  .topbar h1 { font-size: .95rem; }
  .sidebar-brand .brand-text strong { font-size: .95rem; }
}
