/* ══════════════════════════════════════════════════════════
       BASE
    ══════════════════════════════════════════════════════════ */
body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  background: var(--bg);
}

/* ── Topbar ─────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  flex-shrink: 0;
}
.topbar-logo {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
  color: var(--amber-d);
}
.topbar-logo span {
  color: var(--ink);
}
.topbar-sep {
  width: 1.5px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
}
.topbar-title {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--ink2);
}
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}
.role-chip {
  padding: 4px 10px;
  border-radius: var(--r-full);
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  border: 1.5px solid transparent;
  white-space: nowrap;
}
.role-chip.patron {
  background: var(--amber-l);
  border-color: var(--border-d);
  color: var(--amber-dd);
}
.role-chip.manager {
  background: var(--blue-l);
  border-color: #bfdbfe;
  color: #1d4ed8;
}
.role-chip.caissiere {
  background: var(--green-l);
  border-color: #a7f3d0;
  color: #065f46;
}
.btn-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 11px;
  border-radius: var(--r-full);
  background: var(--surface2);
  border: 1.5px solid var(--border);
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--ink2);
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
}
.btn-nav:hover {
  border-color: var(--amber-d);
  color: var(--amber-d);
}
.btn-ico {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  font-size: 0.82rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast);
  flex-shrink: 0;
}
.btn-ico:hover {
  border-color: var(--rust);
  background: var(--rust-l);
}

/* ── Contenu ────────────────────────────────────────────── */
.main {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
}

/* ══════════════════════════════════════════════════════════
       FILTRES
    ══════════════════════════════════════════════════════════ */
.filtres-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.filtres-titre {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--ink2);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Raccourcis rapides */
.periode-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.p-pill {
  padding: 6px 12px;
  border-radius: var(--r-full);
  border: 1.5px solid var(--border);
  background: var(--surface2);
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--ink3);
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.p-pill:hover {
  border-color: var(--amber);
  color: var(--amber-dd);
}
.p-pill.active {
  background: var(--amber);
  border-color: var(--amber-d);
  color: var(--ink);
}

/* Ligne de filtres */
.filtres-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.filtre-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filtre-group label {
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--ink3);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.filtre-input {
  padding: 9px 12px;
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--ink);
  outline: none;
  cursor: pointer;
  transition: border-color var(--t-fast);
}
.filtre-input:focus {
  border-color: var(--amber);
}
.filtre-input[type="date"] {
  max-width: 148px;
}

.btn-appliquer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--r-md);
  background: var(--amber);
  border: none;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 900;
  cursor: pointer;
  transition: all var(--t-fast);
  white-space: nowrap;
  box-shadow: 0 3px 10px rgba(245, 158, 11, 0.3);
  align-self: flex-end;
}
.btn-appliquer:hover {
  background: var(--amber-d);
}
.btn-appliquer:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.btn-reset {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 9px 14px;
  border-radius: var(--r-md);
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--ink3);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
  transition: all var(--t-fast);
  align-self: flex-end;
}
.btn-reset:hover {
  border-color: var(--rust);
  color: var(--rust);
  background: var(--rust-l);
}

/* ══════════════════════════════════════════════════════════
       STATS PÉRIODE
    ══════════════════════════════════════════════════════════ */
.stats-periode {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.sp-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sp-card.highlight {
  background: var(--amber-l);
  border-color: var(--border-d);
}
.sp-label {
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--ink3);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.sp-val {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--ink);
  line-height: 1;
}
.sp-card.highlight .sp-val {
  color: var(--amber-d);
  font-size: 1.7rem;
}
.sp-sub {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--ink3);
}

/* ══════════════════════════════════════════════════════════
       GRAPHIQUE BARRES
    ══════════════════════════════════════════════════════════ */
.chart-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.chart-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}
.chart-title {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--ink);
}
.chart-sub {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ink3);
  margin-top: 2px;
}

/* Graphique barres SVG */
.bar-chart-wrap {
  position: relative;
  overflow: hidden;
}
.bar-chart-svg {
  width: 100%;
  display: block;
  overflow: visible;
}

/* Tooltip */
.chart-tooltip {
  position: absolute;
  background: var(--ink);
  color: white;
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 0.72rem;
  font-weight: 800;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  white-space: nowrap;
  transform: translate(-50%, -110%);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chart-tooltip.show {
  opacity: 1;
}
.chart-tooltip .ct-date {
  font-size: 0.65rem;
  opacity: 0.75;
  font-weight: 700;
}
.chart-tooltip .ct-val {
  font-size: 0.8rem;
  font-weight: 900;
}

/* ══════════════════════════════════════════════════════════
       ANALYSE 2 COLONNES
    ══════════════════════════════════════════════════════════ */
.analyse-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.analyse-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.analyse-titre {
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--ink);
}

/* Répartition catégories */
.cat-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cat-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.cat-name {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--ink);
}
.cat-total {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--amber-d);
  white-space: nowrap;
}
.cat-bar-wrap {
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.cat-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s ease;
}
.cat-sub {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--ink3);
}

/* Couleurs catégories */
.cat-color-biere {
  background: #f59e0b;
}
.cat-color-vin {
  background: #7c3aed;
}
.cat-color-whisky {
  background: #92400e;
}
.cat-color-eau {
  background: #0ea5e9;
}
.cat-color-sucre {
  background: #ec4899;
}
.cat-color-food {
  background: #10b981;
}
.cat-color-autre {
  background: #6b7280;
}

/* Top produits mini */
.mini-top {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.mini-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
}
.mi-rank {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 900;
  flex-shrink: 0;
}
.mi-rank.r1 {
  background: var(--amber);
  color: var(--ink);
}
.mi-rank.rn {
  background: var(--surface2);
  color: var(--ink3);
  border: 1.5px solid var(--border-d);
}
.mi-ico {
  font-size: 1.05rem;
  flex-shrink: 0;
}
.mi-info {
  flex: 1;
  min-width: 0;
}
.mi-nom {
  font-size: 0.78rem;
  font-weight: 900;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mi-qty {
  font-size: 0.63rem;
  font-weight: 700;
  color: var(--ink3);
}
.mi-val {
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--amber-d);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ══════════════════════════════════════════════════════════
       TABLEAU VENTES DÉTAILLÉES
    ══════════════════════════════════════════════════════════ */
.table-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.table-title {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--ink);
}
.table-count {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ink3);
}

/* Recherche dans le tableau */
.table-search {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  padding: 8px 12px;
  transition: border-color var(--t-fast);
  max-width: 240px;
  flex: 1;
}
.table-search:focus-within {
  border-color: var(--amber);
}
.table-search input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink);
  min-width: 0;
}
.table-search input::placeholder {
  color: var(--ink4);
  font-weight: 600;
}

.table-wrapper {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}
thead tr {
  background: var(--surface2);
  border-bottom: 2px solid var(--border);
}
thead th {
  padding: 10px 13px;
  text-align: left;
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--ink3);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: color var(--t-fast);
}
thead th:hover {
  color: var(--amber-d);
}
thead th.sorted {
  color: var(--amber-dd);
}
thead th .sort-arrow {
  font-size: 0.6rem;
  margin-left: 3px;
}

tbody tr {
  border-bottom: 1.5px solid var(--border);
  transition: background var(--t-fast);
}
tbody tr:last-child {
  border-bottom: none;
}
tbody tr:hover {
  background: var(--bg);
}

tbody td {
  padding: 10px 13px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink);
  vertical-align: middle;
  white-space: nowrap;
}

.td-produit-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}
.td-ico {
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  background: var(--surface2);
  border: 1.5px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  flex-shrink: 0;
}
.td-nom {
  font-size: 0.83rem;
  font-weight: 900;
  color: var(--ink);
}
.td-cat {
  font-size: 0.63rem;
  font-weight: 700;
  color: var(--ink4);
  margin-top: 1px;
}

.badge-cat {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  border-radius: var(--r-full);
  font-size: 0.63rem;
  font-weight: 800;
  background: var(--surface2);
  color: var(--ink3);
  border: 1px solid var(--border);
}

.montant-cell {
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--amber-d);
}

.badge-caissiere {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--r-full);
  background: var(--green-l);
  color: #065f46;
  font-size: 0.68rem;
  font-weight: 800;
  border: 1px solid #a7f3d0;
}

.time-cell {
  color: var(--ink3);
  font-size: 0.78rem;
  font-weight: 700;
}

/* Pied de tableau */
.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface2);
  border-top: 1.5px solid var(--border);
  gap: 10px;
  flex-wrap: wrap;
}
.tf-total {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink2);
}
.tf-total strong {
  font-family: var(--font-display);
  font-size: 0.92rem;
  color: var(--amber-d);
}

/* Skeleton */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--border) 25%,
    var(--surface2) 50%,
    var(--border) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.3s infinite;
  border-radius: 6px;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* État vide */
.empty-state {
  padding: 48px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.empty-state .es-ico {
  font-size: 3rem;
  opacity: 0.3;
}
.empty-state .es-title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
  color: var(--ink2);
}
.empty-state .es-sub {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink3);
}

/* ══════════════════════════════════════════════════════════
       RESPONSIVE
    ══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .stats-periode {
    grid-template-columns: repeat(2, 1fr);
  }
  .analyse-grid {
    grid-template-columns: 1fr;
  }
  .sp-val {
    font-size: 1.3rem;
  }
  .sp-card.highlight .sp-val {
    font-size: 1.5rem;
  }
  /* Masquer colonnes secondaires tableau */
  .col-caissiere {
    display: none;
  }
  .col-cat {
    display: none;
  }
}
@media (max-width: 540px) {
  .filtres-row {
    flex-direction: column;
  }
  .filtre-input[type="date"] {
    max-width: 100%;
  }
  .filtre-group {
    width: 100%;
  }
  .filtre-input {
    width: 100%;
  }
  .btn-appliquer {
    width: 100%;
    justify-content: center;
  }
  .btn-reset {
    width: 100%;
    justify-content: center;
  }
  .main {
    padding: 12px;
    gap: 14px;
  }
  .col-prix-unit {
    display: none;
  }
  .table-search {
    max-width: 100%;
  }
}
@media (max-width: 420px) {
  .stats-periode {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .sp-val {
    font-size: 1.15rem;
  }
  .sp-label {
    font-size: 0.6rem;
  }
  .periode-pills {
    gap: 4px;
  }
  .p-pill {
    font-size: 0.65rem;
    padding: 5px 9px;
  }
}
