/* ============================================================
 * tresorerie-v2.css — Refonte UI/UX page Trésorerie (Module fix)
 *
 * Hiérarchie:
 *   1. .treso-kpis           - 4 KPIs en haut (Trésorerie, Encaissé, À encaisser, À payer)
 *   2. .treso-toolbar        - Tabs + actions (synchro, export, print)
 *   3. .alert-bandeau        - Bandeau recouvrement si retards
 *   4. .treso-columns        - 2 colonnes équilibrées Entrées / Sorties
 *   5. .treso-recap          - Récapitulatif annuel + Cartes bancaires (bas)
 *
 * Stricte utilisation des tokens aslane-tokens.css (--*).
 * ============================================================ */

/* ---------- Conteneur racine ---------- */
.treso-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-4);
  font-family: var(--font-body);
}

.treso-shell h1 {
  font-family: var(--font-heading);
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  color: var(--color-gray-900);
  margin: 0 0 var(--space-4) 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ============================================================
 * Zone 1 — KPIs Header (4 cards)
 * ============================================================ */
.treso-kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.kpi-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  box-shadow: var(--shadow-sm);
  border-left: 3px solid var(--color-gray-300);
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: var(--transition-fast);
}

.kpi-card:hover {
  box-shadow: var(--shadow-md);
}

.kpi-card.kpi-primary { border-left-color: var(--color-info); }
.kpi-card.kpi-success { border-left-color: var(--color-success); }
.kpi-card.kpi-warning { border-left-color: var(--color-warning); }
.kpi-card.kpi-danger  { border-left-color: var(--color-danger); }

.kpi-label {
  font-size: var(--text-xs);
  color: var(--color-gray-600);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.kpi-label .kpi-icon { font-size: var(--text-sm); }

.kpi-value {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  color: var(--color-gray-900);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.kpi-card.kpi-success .kpi-value { color: var(--color-success-dark); }
.kpi-card.kpi-danger .kpi-value  { color: var(--color-danger-dark); }
.kpi-card.kpi-warning .kpi-value { color: var(--color-warning-dark); }
.kpi-card.kpi-primary .kpi-value { color: var(--color-info-dark); }

.kpi-meta {
  font-size: var(--text-xs);
  color: var(--color-gray-500);
  font-weight: var(--font-medium);
}

/* ============================================================
 * Zone 2 — Toolbar (tabs + actions)
 * ============================================================ */
.treso-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  margin-bottom: var(--space-4);
}

.treso-tabs {
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
}

.treso-tabs .tab-btn {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--color-gray-700);
  cursor: pointer;
  transition: var(--transition-fast);
  font-family: var(--font-body);
}

.treso-tabs .tab-btn:hover {
  background: var(--color-gray-100);
  color: var(--color-gray-900);
}

.treso-tabs .tab-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
  box-shadow: 0 1px 4px rgba(217, 4, 41, 0.25);
}

.treso-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.treso-actions .month-selector,
.treso-actions select.tb-select {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-gray-300);
  border-radius: var(--radius-md);
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  color: var(--color-gray-900);
  background: var(--bg-card);
  cursor: pointer;
}

.treso-actions .btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-gray-200);
  background: var(--bg-card);
  color: var(--color-gray-700);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-base);
  transition: var(--transition-fast);
}

.treso-actions .btn-icon:hover {
  background: var(--color-gray-100);
  border-color: var(--color-gray-300);
  color: var(--color-gray-900);
}

.treso-actions .btn-icon.btn-icon-primary {
  background: var(--color-info-light);
  border-color: var(--color-info);
  color: var(--color-info-dark);
}

.treso-actions .btn-icon.btn-icon-primary:hover {
  background: var(--color-info);
  color: #fff;
}

/* ============================================================
 * Zone 3 — Bandeau recouvrement / alerte
 * ============================================================ */
.alert-bandeau {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
}

.alert-bandeau.alert-warning {
  background: var(--color-warning-light);
  border: 1px solid var(--color-warning);
  color: var(--color-warning-dark);
}

.alert-bandeau.alert-danger {
  background: var(--color-danger-light);
  border: 1px solid var(--color-danger);
  color: var(--color-danger-dark);
}

.alert-bandeau .alert-icon {
  font-size: var(--text-xl);
  flex-shrink: 0;
}

.alert-bandeau .alert-content {
  flex: 1;
  line-height: 1.5;
}

.alert-bandeau .alert-content strong { font-weight: var(--font-bold); }

.alert-bandeau .alert-action {
  font-weight: var(--font-semibold);
  text-decoration: none;
  color: inherit;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid currentColor;
  font-size: var(--text-xs);
  white-space: nowrap;
}

.alert-bandeau .alert-action:hover {
  background: rgba(0,0,0,0.06);
}

/* Chips pour résumer les retards */
.alert-chips {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-top: var(--space-2);
}

.alert-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  background: var(--bg-card);
  border: 1px solid var(--color-gray-200);
  color: var(--color-gray-800);
}

/* ============================================================
 * Zone 4 — Deux colonnes Entrées / Sorties
 * ============================================================ */
.treso-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-6);
  margin-bottom: var(--space-8);
  align-items: start;
}

.treso-column {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: var(--space-3);
  border-bottom: 2px solid var(--color-gray-100);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
  gap: var(--space-2);
}

.column-header h2 {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.treso-entrees .column-header h2 { color: var(--color-success-dark); }
.treso-sorties .column-header h2 { color: var(--color-danger-dark); }

.column-header .column-meta {
  font-size: var(--text-xs);
  color: var(--color-gray-500);
  font-weight: var(--font-medium);
}

.column-filters {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}

.column-filters input[type="search"],
.column-filters select {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--color-gray-800);
  background: var(--bg-card);
  font-family: var(--font-body);
}

.column-filters input[type="search"] { flex: 1; min-width: 150px; }
.column-filters input[type="search"]:focus,
.column-filters select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(217, 4, 41, 0.12);
}

/* Sections collapsibles */
.treso-section {
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
  background: var(--color-gray-50);
  border: 1px solid var(--color-gray-100);
}

.treso-section > summary {
  cursor: pointer;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  list-style: none;
  user-select: none;
  border-radius: var(--radius-md);
}

.treso-section > summary::-webkit-details-marker { display: none; }
.treso-section > summary::before {
  content: '▶';
  font-size: 9px;
  color: var(--color-gray-500);
  transition: transform 0.15s;
  flex-shrink: 0;
}
.treso-section[open] > summary::before { transform: rotate(90deg); }

.treso-section > summary:hover { background: var(--color-gray-100); }

.section-icon { font-size: var(--text-base); }

.section-title {
  font-family: var(--font-heading);
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  color: var(--color-gray-800);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-count {
  font-size: var(--text-xs);
  color: var(--color-gray-500);
  font-weight: var(--font-medium);
  background: var(--bg-card);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.section-total {
  font-weight: var(--font-bold);
  font-variant-numeric: tabular-nums;
  color: var(--color-gray-900);
  white-space: nowrap;
}

.treso-section .section-body {
  padding: 0 var(--space-2) var(--space-2);
}

/* Tables */
.treso-table {
  width: 100%;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.treso-table th {
  background: var(--color-gray-100);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  text-align: left;
  color: var(--color-gray-700);
  font-weight: var(--font-semibold);
}

.treso-table th.num, .treso-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.treso-table td {
  padding: var(--space-3);
  border-top: 1px solid var(--color-gray-100);
  color: var(--color-gray-800);
  line-height: 1.6;
}

.treso-table tbody tr:hover { background: var(--color-gray-50); }

/* Footer colonne */
.column-footer {
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--color-gray-100);
  border-radius: var(--radius-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-heading);
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
}

.column-footer .total-value { font-variant-numeric: tabular-nums; }

.treso-entrees .column-footer {
  background: var(--color-success-light);
  color: var(--color-success-dark);
}
.treso-sorties .column-footer {
  background: var(--color-danger-light);
  color: var(--color-danger-dark);
}

/* ============================================================
 * Badges Statut (unifiés sur toute la page)
 * ============================================================ */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  white-space: nowrap;
  line-height: 1.4;
}

.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}

.status-badge.status-encaisse,
.status-badge.status-paye         { background: #d1fae5; color: #065f46; }
.status-badge.status-attente      { background: #fef3c7; color: #92400e; }
.status-badge.status-retard,
.status-badge.status-impaye       { background: #fee2e2; color: #991b1b; }
.status-badge.status-prelevement,
.status-badge.status-credit       { background: #dbeafe; color: #1e40af; }
.status-badge.status-verifier     { background: #e5e7eb; color: #374151; }

/* ============================================================
 * Zone 5 — Récapitulatif annuel + Cartes bancaires
 * ============================================================ */
.treso-recap,
.treso-cb {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-6);
}

.treso-recap > header,
.treso-cb > header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
  gap: var(--space-2);
}

.treso-recap > header h2,
.treso-cb > header h2,
.treso-cb > h3 {
  font-family: var(--font-heading);
  font-size: var(--text-xl);
  font-weight: var(--font-bold);
  margin: 0;
  color: var(--color-gray-900);
}

/* === Camemberts récapitulatif annuel === */
.treso-charts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  align-items: stretch;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--color-gray-200);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chart-card h3 {
  font-family: var(--font-heading);
  font-size: var(--text-sm);
  font-weight: var(--font-bold);
  color: var(--color-gray-700);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 var(--space-3) 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chart-card .chart-body {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex: 1;
  min-height: 180px;
}

.chart-card .chart-svg-wrap {
  flex-shrink: 0;
  width: 170px;
  height: 170px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-card .chart-svg-wrap svg { width: 100%; height: 100%; }

.chart-card .chart-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
}

.chart-card .chart-center .center-label {
  font-size: var(--text-xs);
  color: var(--color-gray-500);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chart-card .chart-center .center-value {
  font-family: var(--font-heading);
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  color: var(--color-gray-900);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  max-width: 80px;
  text-align: center;
  word-break: break-all;
  white-space: normal;
}

.chart-card .chart-legend {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.chart-card .chart-legend-item {
  display: grid;
  grid-template-columns: 12px 1fr auto auto;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-xs);
  line-height: 1.4;
  padding: 2px 0;
}

.chart-card .chart-legend-item .swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.chart-card .chart-legend-item .label {
  color: var(--color-gray-800);
  font-weight: var(--font-semibold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart-card .chart-legend-item .amount {
  color: var(--color-gray-700);
  font-weight: var(--font-medium);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chart-card .chart-legend-item .pct {
  color: var(--color-gray-500);
  font-weight: var(--font-semibold);
  font-variant-numeric: tabular-nums;
  min-width: 42px;
  text-align: right;
}

@media (max-width: 768px) {
  .treso-charts { grid-template-columns: 1fr; gap: var(--space-3); }
  .chart-card .chart-body { flex-direction: column; gap: var(--space-3); }
  .chart-card .chart-svg-wrap { width: 150px; height: 150px; }
  .chart-card .chart-legend { width: 100%; }
}

/* ============================================================
 * Boutons utilitaires (compatibles avec existant)
 * ============================================================ */
.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border: 1px solid var(--color-primary);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: var(--transition-fast);
  font-family: var(--font-body);
}
.btn-primary:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }
.btn-primary.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--color-gray-800);
  border: 1px solid var(--color-gray-300);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  cursor: pointer;
  font-family: var(--font-body);
}
.btn-secondary:hover { background: var(--color-gray-100); }

/* ============================================================
 * Responsive — mobile/tablette
 * ============================================================ */
@media (max-width: 1024px) {
  .treso-columns { grid-template-columns: 1fr; gap: var(--space-4); }
  .treso-kpis    { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .treso-shell  { padding: var(--space-3); }
  .treso-kpis   { grid-template-columns: 1fr; gap: var(--space-3); }
  .kpi-value    { font-size: var(--text-2xl); }
  .kpi-card     { padding: var(--space-4); }
  .treso-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .treso-tabs { justify-content: flex-start; overflow-x: auto; flex-wrap: nowrap; }
  .treso-tabs .tab-btn { white-space: nowrap; }
  .treso-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .column-header h2 { font-size: var(--text-lg); }
}

/* Sticky bottom action bar mobile */
@media (max-width: 768px) {
  .treso-sticky-bar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 50;
    background: var(--bg-card);
    border-top: 1px solid var(--color-gray-200);
    padding: var(--space-3);
    display: flex;
    gap: var(--space-2);
    box-shadow: 0 -4px 12px rgba(0,0,0,0.08);
  }
  .treso-sticky-bar .btn-primary { flex: 1; }
}
@media (min-width: 769px) {
  .treso-sticky-bar { display: none; }
}

/* Print */
@media print {
  .treso-toolbar, .treso-sticky-bar, .alert-bandeau .alert-action { display: none !important; }
  .treso-columns { grid-template-columns: 1fr 1fr; }
  .treso-column { box-shadow: none; border: 1px solid var(--color-gray-300); }
}
