/* =====================================================================
   Pilot — feuille de style
   ===================================================================== */

:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --sidebar-w: 240px;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .05), 0 4px 12px rgba(0, 0, 0, .04);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

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

h1, h2, h3 { margin: 0 0 .6em; line-height: 1.25; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

/* ---------- Layout sidebar + content ---------- */
body.has-sidebar { padding-left: var(--sidebar-w); }

.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.2rem 0;
  z-index: 50;
  overflow-y: auto;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: 0 1.2rem 1.2rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
}
.sidebar .brand:hover { text-decoration: none; }
.sidebar .brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}
.sidebar .brand-text { font-weight: 700; font-size: 1.15rem; }

.sidebar-nav {
  flex: 1;
  padding: .8rem 0;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.nav-group {
  display: flex;
  flex-direction: column;
  padding: .3rem 0;
}
.nav-group + .nav-group { border-top: 1px solid var(--border); margin-top: .4rem; padding-top: .8rem; }
.nav-title {
  padding: 0 1.2rem .35rem;
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
}
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .55rem 1.2rem;
  color: var(--text);
  border-left: 3px solid transparent;
  font-size: .94rem;
}
.sidebar-nav a:hover { background: var(--bg); text-decoration: none; border-left-color: var(--border); }
.sidebar-nav a.active { background: #eff6ff; border-left-color: var(--primary); color: var(--primary); }
.sidebar-nav a.nav-cta {
  margin: .3rem 1rem;
  padding: .5rem .8rem;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  justify-content: center;
  border-left: none;
}
.sidebar-nav a.nav-cta:hover { background: var(--primary-dark); border-left: none; }

.sidebar-footer {
  padding: .8rem 1.2rem;
  border-top: 1px solid var(--border);
}
.user-info { display: flex; flex-direction: column; gap: .15rem; }
.user-name { font-weight: 600; }
.user-logout { font-size: .85rem; color: var(--muted); }
.user-logout:hover { color: var(--danger); }
.sidebar-version {
  margin-top: .6rem;
  font-size: .78rem;
  color: var(--muted);
}
.sidebar-version a { color: var(--muted); }
.sidebar-version a:hover { color: var(--primary); }

/* Bouton burger mobile */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: .8rem; left: .8rem;
  width: 40px; height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  z-index: 60;
}

/* Content */
.content {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.container {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
  flex: 1;
}

.footer {
  text-align: center;
  color: var(--muted);
  padding: 1.5rem 1rem 2rem;
  font-size: .85rem;
}
.footer a { color: var(--muted); }
.footer a:hover { color: var(--primary); }

/* Si pas connecté : pas de sidebar, mise en page centrée */
body.no-sidebar { padding-left: 0; }

/* ---------- Carte d'authentification ---------- */
.auth-card {
  max-width: 420px;
  margin: 4rem auto;
  background: var(--card);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.auth-card label { display: block; margin: .8rem 0; }
.auth-card input { width: 100%; }

/* ---------- Formulaires ---------- */
label { display: block; font-weight: 500; }
input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], input[type=url], input[type=search],
select, textarea {
  width: 100%;
  padding: .55rem .7rem;
  margin-top: .25rem;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
  border-color: var(--primary);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.form-section {
  background: var(--card);
  padding: 1.2rem 1.4rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.2rem;
}
.form-section h2 { margin-top: 0; font-size: 1.05rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.form-actions { display: flex; gap: .6rem; margin-top: 1rem; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-block;
  padding: .55rem 1rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: inherit; border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: .25rem .55rem; font-size: .85rem; }

/* ---------- Alerts ---------- */
.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error   { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .92rem;
}
table.data th, table.data td {
  padding: .65rem .8rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data thead th {
  background: #f9fafb;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .02em;
  font-size: .78rem;
}
table.data tbody tr:hover { background: #fafbff; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data img.thumb {
  width: 56px; height: 56px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--border); background: #fafafa;
}
.placeholder-thumb {
  width: 56px; height: 56px; border-radius: 6px;
  background: #f3f4f6; color: #9ca3af;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: .78rem;
  font-weight: 600;
}
.badge-success { background: #ecfdf5; color: #065f46; }
.badge-warn    { background: #fef3c7; color: #92400e; }
.badge-muted   { background: #f3f4f6; color: #4b5563; }
.profit-pos { color: var(--success); font-weight: 600; }
.profit-neg { color: var(--danger);  font-weight: 600; }
.profit-zero { color: var(--muted); }

/* Statut coloré (badge dynamique) */
.status-badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 999px;
  color: #fff;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
  text-shadow: 0 1px 1px rgba(0,0,0,.15);
}

/* En-têtes de colonnes triables */
th.sortable a {
  color: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: .25rem;
}
th.sortable a:hover { color: var(--primary); }
th.sortable .sort-indicator { opacity: .35; font-size: .75rem; }
th.sortable.sort-active .sort-indicator { opacity: 1; color: var(--primary); }

/* ---------- Dashboard cards ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
}
.stat .label { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.55rem; font-weight: 700; margin-top: .3rem; }
.stat .sub { color: var(--muted); font-size: .82rem; margin-top: .3rem; }

/* ---------- Filtres ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: .7rem;
  align-items: end;
  background: var(--card);
  padding: 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.filters .field { flex: 1 1 160px; min-width: 140px; }
.filters .field label { font-size: .8rem; color: var(--muted); }

/* ---------- Headerbar des pages ---------- */
.pagehead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

/* ---------- Form image preview ---------- */
.image-preview {
  margin-top: .5rem;
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fafafa;
}

/* ---------- Notes (style post-it) ---------- */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}
.note-card {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.note-card.note-pinned { background: #fef3c7; border-color: #f59e0b; }
.note-head { display: flex; align-items: center; gap: .5rem; }
.note-title {
  flex: 1;
  border: none;
  background: transparent;
  font-weight: 600;
  font-size: 1rem;
  padding: .2rem .4rem;
  margin: 0;
}
.note-title:focus { background: rgba(255,255,255,.7); border-radius: 4px; }
.note-body {
  border: none;
  background: transparent;
  resize: vertical;
  font: inherit;
  width: 100%;
  margin: 0;
  padding: .2rem .4rem;
}
.note-body:focus { background: rgba(255,255,255,.7); border-radius: 4px; }
.note-foot { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.note-actions { display: flex; gap: .3rem; }

/* ---------- Page changelog ---------- */
.changelog {
  background: var(--card);
  padding: 1.5rem 2rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 820px;
}
.changelog h2 {
  margin-top: 2rem;
  padding-bottom: .4rem;
  border-bottom: 2px solid var(--border);
  font-size: 1.2rem;
}
.changelog h2:first-of-type { margin-top: .5rem; }
.changelog h2 .version-tag {
  display: inline-block;
  padding: .15rem .55rem;
  margin-right: .4rem;
  background: var(--primary);
  color: #fff;
  border-radius: 6px;
  font-size: .9rem;
  font-weight: 600;
}
.changelog h2 .version-date { color: var(--muted); font-weight: 400; font-size: .92rem; margin-left: .5rem; }
.changelog h3 {
  margin-top: 1rem;
  font-size: .92rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.changelog ul { padding-left: 1.2rem; }
.changelog li { margin: .2rem 0; }
.changelog code { background: #f3f4f6; padding: .1rem .35rem; border-radius: 4px; font-family: var(--mono); font-size: .88em; }

/* ---------- Petits utilitaires ---------- */
.muted { color: var(--muted); }
.right { text-align: right; }
.center { text-align: center; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.gap-1 { gap: .5rem; }

/* =====================================================================
   Responsive — sidebar repliable sur mobile
   ===================================================================== */
@media (max-width: 900px) {
  body.has-sidebar { padding-left: 0; padding-top: 60px; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 0 0 24px rgba(0,0,0,.15);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
  body.sidebar-open .sidebar-toggle { left: calc(var(--sidebar-w) + .8rem); }
}
