/* =====================================================================
   ThePackengers Portal — système de design
   Inspiration : Apple (sobriété, précision typographique, profondeur)
   + Porsche (rouge mesuré, noir profond, mécanique soignée).
   ===================================================================== */
:root {
  /* Surfaces */
  --bg: #0a0a0c;
  --bg-elev: #111114;
  --surface: #17171b;
  --surface-2: #1d1d22;
  --surface-hover: #232329;
  --line: #2a2a31;
  --line-soft: #1f1f25;

  /* Texte */
  --text: #f4f4f6;
  --text-2: #a9a9b4;
  --text-3: #6e6e78;

  /* Accent Porsche */
  --accent: #d5001c;
  --accent-600: #b80018;
  --accent-soft: rgba(213, 0, 28, 0.14);

  /* États */
  --green: #34c759;
  --orange: #ff9f0a;
  --red: #ff453a;
  --blue: #0a84ff;
  --gray: #8e8e93;

  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 22px;
  --shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 18px 50px -20px rgba(0,0,0,.8);
  --ring: 0 0 0 4px rgba(213,0,28,.18);
  --ease: cubic-bezier(.22,.61,.36,1);

  --sidebar-w: 264px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  letter-spacing: -0.01em;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
::selection { background: var(--accent-soft); }

/* Scrollbar discrète */
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: #303039; border-radius: 99px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #41414c; background-clip: padding-box; }

/* =================== LOGIN =================== */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(900px 600px at 85% -10%, rgba(213,0,28,.16), transparent 60%),
    radial-gradient(700px 500px at 0% 110%, rgba(10,132,255,.08), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 400px; background: linear-gradient(180deg, var(--surface), var(--bg-elev));
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 40px 36px; box-shadow: var(--shadow); text-align: center;
}
.login-logo { width: 56px; height: 56px; margin: 0 auto 22px; display: block; }
.login-brands { display: flex; align-items: center; justify-content: center; gap: 18px; margin-bottom: 26px; }
.brand-tile { display: flex; align-items: center; gap: 10px; }
.brand-tile img { width: 38px; height: 38px; object-fit: contain; border-radius: 9px; }
.brand-tile span { display: flex; flex-direction: column; font-size: 14px; font-weight: 600; line-height: 1.15; text-align: left; }
.brand-tile small { font-size: 11px; color: var(--text-3); font-weight: 500; }
.brand-sep { width: 1px; height: 34px; background: var(--line); }
.nav-group-logo { width: 18px; height: 18px; object-fit: contain; border-radius: 5px; margin-right: 8px; vertical-align: middle; }
.login h1 { font-size: 23px; margin: 0 0 6px; font-weight: 650; letter-spacing: -0.02em; }
.login p { color: var(--text-2); font-size: 14px; margin: 0 0 30px; line-height: 1.5; }
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 12px; width: 100%;
  padding: 13px 18px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: #fff; color: #1a1a1a; font-size: 15px; font-weight: 550; cursor: pointer;
  transition: transform .18s var(--ease), box-shadow .18s var(--ease);
}
.btn-google:hover { transform: translateY(-1px); box-shadow: 0 10px 30px -12px rgba(0,0,0,.7); }
.login-note { margin-top: 26px; font-size: 12.5px; color: var(--text-3); }
.login-err {
  background: var(--accent-soft); color: #ff8b8b; border: 1px solid rgba(213,0,28,.3);
  padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 22px;
}

/* =================== APP SHELL =================== */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--bg-elev), var(--bg));
  border-right: 1px solid var(--line-soft); padding: 22px 16px; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 10px 22px; }
.brand img { width: 34px; height: 34px; }
.brand-name { font-weight: 650; font-size: 16px; letter-spacing: -0.02em; }
.brand-sub { font-size: 11px; color: var(--text-3); letter-spacing: .04em; text-transform: uppercase; }

.nav-group-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .07em; padding: 16px 12px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 11px;
  color: var(--text-2); font-size: 14.5px; font-weight: 500; cursor: pointer; margin-bottom: 2px;
  transition: background .16s var(--ease), color .16s var(--ease);
}
.nav-item svg { width: 19px; height: 19px; flex: none; opacity: .9; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.nav-item.active svg { color: var(--accent); opacity: 1; }
.nav-badge { margin-left: auto; background: var(--accent); color: #fff; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; }

.sidebar-footer { margin-top: auto; border-top: 1px solid var(--line-soft); padding-top: 14px; }
.user-chip { display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 12px; }
.user-chip:hover { background: var(--surface); }
.avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--surface-2); flex: none; display: grid; place-items: center; font-size: 13px; font-weight: 600; color: var(--text-2); }
.user-meta { min-width: 0; }
.user-name { font-size: 13.5px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-3); }

/* =================== MAIN =================== */
.main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px;
  padding: 18px 32px; background: rgba(10,10,12,.72); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar h1 { font-size: 21px; font-weight: 650; margin: 0; letter-spacing: -0.02em; }
.topbar .spacer { flex: 1; }
.content { padding: 28px 32px 64px; max-width: 1320px; }

/* Cartes & grilles */
.grid { display: grid; gap: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.card {
  background: linear-gradient(180deg, var(--surface), var(--bg-elev));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
}
.stat-label { font-size: 12.5px; color: var(--text-2); font-weight: 500; display: flex; align-items: center; gap: 8px; }
.stat-value { font-size: 32px; font-weight: 660; margin-top: 10px; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: 12.5px; color: var(--text-3); margin-top: 4px; }
.stat-value.accent { color: var(--accent); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.vert { background: var(--green);} .dot.orange { background: var(--orange);} .dot.rouge { background: var(--red);} .dot.gris { background: var(--gray);} .dot.blue{background:var(--blue);}

.section-title { font-size: 15px; font-weight: 600; margin: 30px 0 14px; letter-spacing: -0.01em; }

/* Boutons */
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font-size: 14px; font-weight: 550; cursor: pointer; transition: all .16s var(--ease); white-space: nowrap;
}
.btn:hover { background: var(--surface-hover); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn svg { width: 17px; height: 17px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-600); }
.btn.ghost { background: transparent; }
.btn.danger { color: #ff8b8b; border-color: rgba(213,0,28,.3); background: var(--accent-soft); }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.btn-icon { padding: 8px; }

/* Champs */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; color: var(--text); font-size: 14px; font-family: inherit; transition: border .16s, box-shadow .16s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
textarea.input { resize: vertical; min-height: 70px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-fieldset { border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 18px 18px 20px; margin-bottom: 18px; }
.form-fieldset legend { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 0 8px; }

/* Tableaux */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-elev); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; padding: 13px 14px; color: var(--text-2); font-weight: 550; font-size: 12px;
  text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--line); white-space: nowrap;
  position: sticky; top: 0; background: var(--bg-elev);
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); color: var(--text); white-space: nowrap; vertical-align: middle; }
tbody tr { transition: background .12s; cursor: pointer; }
tbody tr:hover { background: var(--surface); }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }

/* Badges d'état */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 550; border: 1px solid transparent; }
.badge.vert { background: rgba(52,199,89,.14); color: #6ee787; }
.badge.orange { background: rgba(255,159,10,.14); color: #ffce7a; }
.badge.rouge { background: rgba(255,69,58,.16); color: #ff9a91; }
.badge.gris { background: rgba(142,142,147,.16); color: #c2c2cb; }
.badge.blue { background: rgba(10,132,255,.16); color: #7fb8ff; }

/* Toolbar de page */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 380px; }
.search input { padding-left: 38px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--text-3); }

/* Modale */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5,5,7,.6); backdrop-filter: blur(6px);
  display: grid; place-items: center; z-index: 100; padding: 24px; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  width: 100%; max-width: 880px; max-height: 90vh; overflow: auto; background: var(--bg-elev);
  border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: 0 40px 100px -30px rgba(0,0,0,.9);
  transform: scale(.97) translateY(8px); transition: transform .22s var(--ease);
}
.modal-backdrop.open .modal { transform: none; }
.modal-head { display: flex; align-items: center; padding: 22px 26px; border-bottom: 1px solid var(--line-soft); position: sticky; top: 0; background: var(--bg-elev); z-index: 2; }
.modal-head h2 { font-size: 18px; font-weight: 620; margin: 0; }
.modal-body { padding: 24px 26px; }
.modal-foot { display: flex; gap: 12px; justify-content: flex-end; padding: 18px 26px; border-top: 1px solid var(--line-soft); position: sticky; bottom: 0; background: var(--bg-elev); }

/* Toast */
.toast-wrap { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 13px 16px; font-size: 14px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px; animation: slideIn .25s var(--ease); }
.toast.ok { border-left: 3px solid var(--green); }
.toast.err { border-left: 3px solid var(--red); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* Charts */
.chart-card { min-height: 0; }
.chart-card canvas { max-height: 280px; }

/* Empty */
.empty { text-align: center; padding: 64px 24px; color: var(--text-3); }
.empty svg { width: 46px; height: 46px; opacity: .4; margin-bottom: 14px; }

/* Divers */
.row-actions { display: flex; gap: 6px; opacity: 0; transition: opacity .15s; }
tbody tr:hover .row-actions { opacity: 1; }
.hidden { display: none !important; }
.pill-tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.pill-tabs button { border: none; background: transparent; color: var(--text-2); padding: 7px 16px; border-radius: 9px; font-size: 13.5px; font-weight: 550; cursor: pointer; transition: all .15s; }
.pill-tabs button.active { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 6px 14px -8px rgba(0,0,0,.6); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); z-index: 50; transition: transform .25s var(--ease); width: 280px; }
  .sidebar.open { transform: none; }
  .content, .topbar { padding-left: 18px; padding-right: 18px; }
  .menu-toggle { display: inline-flex !important; }
}
.menu-toggle { display: none; }
