/* ════════════════════════════════════════════════════════════
   ESPACE MEMBRE — RénovPilot
   CSS partagé : layout sidebar + topbar + cartes + utilities
   Cohérent avec le site vitrine (palette sapin/bronze/prussian).
════════════════════════════════════════════════════════════ */

:root {
  --bg: #FAFAFA; --bg-2: #FFFFFF; --bg-3: #F4F4F7; --bg-4: #EDEDF1;
  --line: rgba(10,10,18,.08); --line-2: rgba(10,10,18,.14); --line-3: rgba(10,10,18,.24);
  --text: #0A0A12; --text-2: #4A4A58; --text-3: #7A7A8A; --text-4: #B5B5C0;

  --sapin: #0F5132; --sapin-2: #1B7E55; --sapin-3: #2D9E73; --sapin-soft: #EAF3EE;
  --prussian: #0A2540; --prussian-2: #153D66; --prussian-3: #2C6AA5; --prussian-soft: #E9EFF5;
  --gold: #B89560; --gold-2: #D3A86B; --gold-soft: #F5EFE2;
  --ok: #1B7E55; --warn: #B89560; --danger: #B4384A; --info: #2C6AA5;

  --r-xs: 6px; --r-sm: 10px; --r-md: 14px; --r-lg: 20px; --r-pill: 999px;
  --sh-1: 0 1px 2px rgba(15,20,35,.06), 0 4px 14px rgba(15,20,35,.04);
  --sh-2: 0 2px 6px rgba(15,20,35,.06), 0 16px 40px rgba(15,20,35,.06);
  --grad-brand: linear-gradient(135deg, #1B7E55 0%, #0F5132 50%, #153D66 100%);
  --grad-text: linear-gradient(100deg, #0A0A12 0%, #0F5132 50%, #153D66 100%);
  --ease: cubic-bezier(.2,.7,.2,1);
  --ease-spring: cubic-bezier(.16,1.1,.3,1);

  --sidebar-w: 244px;
  --topbar-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg-3); color: var(--text);
  font-family: "Inter Tight", system-ui, -apple-system, sans-serif;
  font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

/* Cacher le contenu pendant que l'auth check + render shell se font.
   Évite le flash où le main apparaît sans la sidebar entre 2 pages. */
body:not(.app-ready) .app-shell { visibility: hidden; }
body.app-ready .app-shell { visibility: visible; animation: fade-in .15s ease-out; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
h1, h2, h3, h4 { margin: 0; color: var(--text); font-weight: 700; letter-spacing: -0.022em; line-height: 1.2; }
h1 { font-size: 28px; letter-spacing: -0.03em; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); }
p { margin: 0; color: var(--text-2); }
a { color: var(--sapin); text-decoration: none; }
a:hover { color: var(--sapin-2); }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; color: inherit; }
.mono { font-family: "JetBrains Mono", ui-monospace, monospace; font-feature-settings: "tnum"; }

::selection { background: rgba(15,81,50,.25); }

/* ═══ Layout principal ════════════════════════════════════ */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-areas: "sidebar main";
  min-height: 100vh;
}
.sidebar { grid-area: sidebar; }
.main    { grid-area: main; }
@media (max-width: 880px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "main";
  }
}

/* ═══ Sidebar ═════════════════════════════════════════════ */
.sidebar {
  background: linear-gradient(180deg, #0A2540 0%, #061830 100%);
  color: rgba(255,255,255,.85);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
  padding: 18px 14px 18px 18px;
  z-index: 30;
}
@media (max-width: 880px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform .25s var(--ease);
    box-shadow: 4px 0 24px rgba(0,0,0,.2);
  }
  .sidebar.open { transform: translateX(0); }
}

.sidebar-brand {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 4px 6px 18px; margin-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  color: #fff; text-decoration: none;
}
.sidebar-brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, #1B7E55, #0F5132);
  border: 1px solid rgba(184,149,96,.4);
  display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 14px;
  flex-shrink: 0;
}
.sidebar-brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.sidebar-brand-name em { font-style: normal; color: var(--gold-2); }

.sidebar-section {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  color: rgba(255,255,255,.4);
  padding: 14px 8px 6px;
}

.sidebar-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: var(--r-sm);
  color: rgba(255,255,255,.7);
  font-size: 13.5px; font-weight: 500;
  text-decoration: none; cursor: pointer;
  transition: background .15s, color .15s;
  border: 1px solid transparent;
  margin-bottom: 1px;
}
.sidebar-link:hover { background: rgba(255,255,255,.05); color: #fff; }
.sidebar-link.active {
  background: rgba(184,149,96,.16); color: var(--gold-2);
  border-color: rgba(184,149,96,.25);
}
.sidebar-link svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .85; }
.sidebar-link.active svg { color: var(--gold-2); opacity: 1; }
.sidebar-link .badge {
  margin-left: auto;
  font-size: 10px; padding: 2px 7px; border-radius: 999px;
  background: rgba(255,255,255,.1); color: rgba(255,255,255,.85); font-weight: 700;
}
.sidebar-link.active .badge { background: var(--gold); color: #fff; }

.sidebar-cta {
  margin-top: auto; padding: 14px 12px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-cta-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 13px; border-radius: var(--r-sm);
  background: linear-gradient(135deg, #B89560, #D3A86B);
  color: #fff !important; font-weight: 600; font-size: 13px;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(184,149,96,.3);
  transition: transform .2s var(--ease-spring), box-shadow .2s;
}
.sidebar-cta-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(184,149,96,.45); }
.sidebar-cta-btn svg { width: 14px; height: 14px; }

.sidebar-user {
  margin-top: 12px; padding: 12px;
  background: rgba(255,255,255,.04);
  border-radius: var(--r-sm);
  display: flex; align-items: center; gap: 10px;
  border: 1px solid rgba(255,255,255,.08);
}
.sidebar-user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--gold-2));
  color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.sidebar-user-meta { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-mail { font-size: 11px; color: rgba(255,255,255,.55); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-logout {
  background: none; border: none; color: rgba(255,255,255,.5);
  display: grid; place-items: center; padding: 4px;
  border-radius: 6px; transition: color .15s, background .15s;
}
.sidebar-user-logout:hover { color: var(--danger); background: rgba(180,56,74,.12); }
.sidebar-user-logout svg { width: 16px; height: 16px; }

/* ═══ Main content ════════════════════════════════════════ */
.main { display: flex; flex-direction: column; min-width: 0; }

/* Topbar interne (≠ topbar du site public) */
.topbar-app {
  height: var(--topbar-h);
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  padding: 0 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar-app-left { display: inline-flex; align-items: center; gap: 14px; min-width: 0; }
.topbar-app-burger {
  display: none; width: 36px; height: 36px;
  border: 1px solid var(--line-2); background: var(--bg-2); border-radius: 9px;
  align-items: center; justify-content: center;
}
@media (max-width: 880px) { .topbar-app-burger { display: inline-flex; } }
.topbar-app-burger svg { width: 18px; height: 18px; }

.topbar-app-title { font-size: 17px; font-weight: 700; letter-spacing: -0.012em; }
.topbar-app-sub   { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }

.topbar-app-right { display: inline-flex; align-items: center; gap: 8px; }
.topbar-app-btn {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--bg-3); border: 1px solid var(--line);
  display: grid; place-items: center;
  cursor: pointer; transition: background .15s, border-color .15s;
  position: relative;
}
.topbar-app-btn:hover { background: var(--bg-4); border-color: var(--line-2); }
.topbar-app-btn svg { width: 16px; height: 16px; color: var(--text-2); }
.topbar-app-btn .dot {
  position: absolute; top: 7px; right: 7px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--danger); border: 1.5px solid var(--bg-2);
}
.topbar-app-cta {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px; border-radius: var(--r-pill);
  background: var(--grad-brand); color: #fff; font-weight: 600; font-size: 13px;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(15,81,50,.25);
  transition: transform .2s var(--ease-spring), box-shadow .2s;
}
.topbar-app-cta:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(15,81,50,.35); color: #fff; }
.topbar-app-cta svg { width: 14px; height: 14px; }

/* Page wrapper */
.page {
  padding: 32px 32px 64px;
  max-width: 1240px; margin: 0 auto;
  width: 100%;
}
@media (max-width: 720px) { .page { padding: 22px 18px 40px; } }
.page-head {
  margin-bottom: 28px;
  display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 16px;
}
.page-head h1 + p { color: var(--text-2); margin-top: 6px; font-size: 14.5px; }

/* ═══ Cards ═══════════════════════════════════════════════ */
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 22px;
  box-shadow: var(--sh-1);
  transition: box-shadow .18s, border-color .18s;
}
.card-hover:hover { box-shadow: var(--sh-2); border-color: var(--line-2); }
.card-h {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 16px; padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.card-h h3 { font-size: 15px; }

/* KPI cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.kpi-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: 18px 20px; box-shadow: var(--sh-1); }
.kpi-label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-3);
}
.kpi-label svg { width: 13px; height: 13px; }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -0.025em; margin-top: 6px; color: var(--text); font-variant-numeric: tabular-nums; }
.kpi-value.gradient { background: var(--grad-text); -webkit-background-clip: text; background-clip: text; color: transparent; }
.kpi-sub { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.kpi-sub strong { color: var(--text); font-weight: 600; }
.kpi-delta { font-size: 11.5px; font-weight: 700; }
.kpi-delta.up { color: var(--ok); }
.kpi-delta.down { color: var(--danger); }
.kpi-delta.neutral { color: var(--text-3); }

/* ═══ Buttons ═════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 10px 18px; border-radius: var(--r-pill);
  font-size: 13.5px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer;
  font-family: inherit; text-decoration: none;
  transition: transform .18s var(--ease-spring), box-shadow .18s, background .18s, border-color .18s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn svg { width: 14px; height: 14px; }
.btn-primary { background: var(--text); color: #fff; }
.btn-primary:hover { background: var(--prussian); color: #fff; }
.btn-brand { background: var(--grad-brand); color: #fff; box-shadow: 0 2px 8px rgba(15,81,50,.25); }
.btn-brand:hover { box-shadow: 0 4px 14px rgba(15,81,50,.35); color: #fff; }
.btn-ghost { background: var(--bg-2); color: var(--text); border-color: var(--line-2); }
.btn-ghost:hover { background: var(--bg-3); border-color: var(--line-3); color: var(--text); }
.btn-gold { background: var(--gold); color: #fff; box-shadow: 0 2px 8px rgba(184,149,96,.25); }
.btn-gold:hover { background: #A8854F; color: #fff; box-shadow: 0 4px 14px rgba(184,149,96,.35); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #962C3E; color: #fff; }
.btn-sm { padding: 7px 13px; font-size: 12.5px; }
.btn-lg { padding: 13px 24px; font-size: 14.5px; }

/* ═══ Tags & badges ══════════════════════════════════════ */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 700;
  padding: 3px 9px; border-radius: var(--r-pill);
  letter-spacing: .015em;
}
.tag.ok        { background: rgba(27,126,85,.13); color: var(--sapin); }
.tag.warn      { background: rgba(184,149,96,.18); color: #8A6C3E; }
.tag.danger    { background: rgba(180,56,74,.13); color: var(--danger); }
.tag.info      { background: rgba(44,106,165,.13); color: var(--info); }
.tag.muted     { background: var(--bg-3); color: var(--text-3); }

/* ═══ Forms ═══════════════════════════════════════════════ */
.field { margin-bottom: 16px; }
.field-label {
  display: block; font-size: 12.5px; font-weight: 600;
  color: var(--text-2); margin-bottom: 6px;
}
.field-input, .field-select, .field-textarea {
  width: 100%;
  padding: 11px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2); background: var(--bg-2);
  font-family: inherit; font-size: 14px; color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.field-input:focus, .field-select:focus, .field-textarea:focus {
  outline: none; border-color: var(--sapin);
  box-shadow: 0 0 0 3px rgba(27,126,85,.12);
}
.field-error { font-size: 12px; color: var(--danger); margin-top: 4px; }
.field-hint  { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ═══ Table ═══════════════════════════════════════════════ */
.tbl {
  width: 100%; border-collapse: collapse; font-size: 13.5px;
  background: var(--bg-2); border-radius: var(--r-md); overflow: hidden;
  border: 1px solid var(--line);
}
.tbl th {
  text-align: left; padding: 12px 16px;
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-3);
  background: var(--bg-3); border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.tbl td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: var(--bg-3); }
.tbl .num { font-variant-numeric: tabular-nums; text-align: right; font-family: "JetBrains Mono", monospace; }

/* ═══ Empty state ═════════════════════════════════════════ */
.empty {
  text-align: center; padding: 60px 24px;
  color: var(--text-3);
}
.empty-icon {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--bg-3); color: var(--text-3);
  display: inline-grid; place-items: center; margin-bottom: 16px;
}
.empty-icon svg { width: 28px; height: 28px; }
.empty h3 { color: var(--text-2); margin-bottom: 6px; }
.empty p  { font-size: 13.5px; }

/* ═══ Loading state ═══════════════════════════════════════ */
.loader {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--bg-3); border-top-color: var(--sapin);
  border-radius: 50%; animation: spin .7s linear infinite;
  vertical-align: -3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skel {
  background: linear-gradient(90deg, var(--bg-3) 0%, var(--bg-4) 50%, var(--bg-3) 100%);
  background-size: 200% 100%;
  animation: skel 1.4s ease-in-out infinite;
  border-radius: 6px;
}
@keyframes skel { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ═══ Toast ═══════════════════════════════════════════════ */
.toast-wrap {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 1000;
  pointer-events: none;
}
.toast {
  background: var(--bg-2); border: 1px solid var(--line-2);
  border-radius: var(--r-md); padding: 14px 18px;
  box-shadow: 0 8px 32px rgba(15,20,35,.12);
  display: flex; align-items: flex-start; gap: 12px;
  max-width: 380px; min-width: 280px;
  pointer-events: auto;
  animation: toast-in .25s var(--ease-spring);
}
.toast.ok    { border-left: 3px solid var(--ok); }
.toast.warn  { border-left: 3px solid var(--warn); }
.toast.error { border-left: 3px solid var(--danger); }
.toast-title { font-size: 13.5px; font-weight: 700; }
.toast-body  { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }
