/* Cyspera Cockpit — Finance (vert) · charte UI Scientis/Cyspera */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

/* ── Variables ──────────────────────────────────────────────────────────────── */
:root {
  /* Neutres */
  --bg:            #F8FAFC;
  --surface:       #FFFFFF;
  --surface-muted: #F1F5F9;
  --border:        #E2E8F0;
  --border-strong: #CBD5E1;
  --text:          #0F172A;
  --text-muted:    #475569;
  --text-subtle:   #94A3B8;

  /* États sémantiques */
  --success: #16A34A;
  --warning: #D97706;
  --danger:  #DC2626;
  --info:    #0284C7;

  /* Finance — accent vert */
  --accent-50:  #ECFDF5;
  --accent-100: #D1FAE5;
  --accent-500: #10B981;
  --accent-600: #059669;
  --accent-700: #047857;

  /* Rayons */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Ombres */
  --shadow-sm: 0 1px 2px 0 rgb(15 23 42 / .04);
  --shadow:    0 1px 3px 0 rgb(15 23 42 / .08), 0 1px 2px -1px rgb(15 23 42 / .04);
  --shadow-md: 0 4px 6px -1px rgb(15 23 42 / .08), 0 2px 4px -2px rgb(15 23 42 / .04);
}

/* ── Reset ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

/* ── Topbar ─────────────────────────────────────────────────────────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 56px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.011em;
  flex-shrink: 0;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  padding-left: 20px;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}
.topbar-link:hover  { background: var(--surface-muted); color: var(--text); }
.topbar-link.active { background: var(--accent-50); color: var(--accent-700); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Boutons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  transition: background .15s, color .15s, border-color .15s;
  text-decoration: none;
  white-space: nowrap;
  padding: 0 16px;
  height: 36px;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--accent-600); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-700); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-muted); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-muted); color: var(--text); }

.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-lg { height: 40px; padding: 0 20px; font-size: 14px; }

/* ── Sélecteur de période ────────────────────────────────────────────────────── */
.period-tabs {
  display: flex;
  gap: 2px;
  background: var(--surface-muted);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.period-tab {
  padding: 4px 12px;
  border: none;
  border-radius: 4px;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}
.period-tab:hover { color: var(--text); }
.period-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.container { max-width: 1200px; margin: 0 auto; padding: 0 24px; }
.main { padding: 32px 0 48px; }

/* ── En-tête de page ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.011em;
}

/* ── KPI Cards ───────────────────────────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

@media (max-width: 900px) { .cards-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 580px) { .cards-grid { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

.card-label {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-subtle);
  margin-bottom: 10px;
}

.card-value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -.011em;
  color: var(--text);
  margin-bottom: 4px;
  font-variant-numeric: tabular-nums;
}

.card-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.card-change {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 8px;
  height: 22px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
}
.card-change.up      { background: rgb(22  163 74  / .08); color: var(--success); }
.card-change.down    { background: rgb(220 38  38  / .08); color: var(--danger);  }
.card-change.neutral { background: var(--surface-muted);   color: var(--text-muted); }

/* ── Charts ──────────────────────────────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

@media (max-width: 700px) { .charts-grid { grid-template-columns: 1fr; } }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

.chart-card-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 20px;
}

.chart-wrap {
  position: relative;
  height: 230px;
  display: flex;
  justify-content: center;
}

/* ── Footer ──────────────────────────────────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--border);
  padding: 16px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.footer-meta { font-size: 12px; color: var(--text-subtle); }
.footer-link { font-size: 13px; font-weight: 500; color: var(--accent-600); }
.footer-link:hover { color: var(--accent-700); text-decoration: underline; }

/* ── Login ───────────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}

.login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.login-brand-logo { margin-bottom: 16px; }

.login-brand-name {
  font-size: 28px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.011em;
}

.login-brand-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Formulaires ─────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-input::placeholder { color: var(--text-subtle); }
.form-input:focus {
  border-color: var(--accent-500);
  box-shadow: 0 0 0 3px rgb(16 185 129 / .12);
}

.form-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.form-row .form-group { flex: 1; margin-bottom: 0; }

/* ── Alertes ─────────────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 16px;
  border-left: 2px solid;
}

.alert-error   { background: rgb(220 38  38  / .06); border-color: var(--danger);  color: var(--danger);  }
.alert-success { background: rgb(22  163 74  / .06); border-color: var(--success); color: var(--success); }
.alert-info    { background: rgb(2   132 199 / .06); border-color: var(--info);    color: var(--info);    }

/* ── État chargement ─────────────────────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  color: var(--text-muted);
  font-size: 14px;
  grid-column: 1 / -1;
}

/* ── Panel générique (factures) ──────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-top: 16px;
}

.panel-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-muted);
}

/* ── Lignes de facture ───────────────────────────────────────────────────────── */
.invoice-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  transition: background .1s;
}
.invoice-item:last-child { border-bottom: none; }
.invoice-item:hover { background: var(--surface-muted); }

.invoice-item-name { font-weight: 500; }
.invoice-item-meta { font-size: 12px; color: var(--text-subtle); margin-top: 2px; }

/* ── Panneau de génération ───────────────────────────────────────────────────── */
.gen-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}

.gen-panel-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
}

/* ── Mobile ──────────────────────────────────────────────────────────────────── */
@media (max-width: 580px) {
  .topbar    { padding: 0 16px; }
  .container { padding: 0 16px; }
  .topbar-nav { display: none; }
  /* Le dropdown de mois reste visible sur mobile (plus compact que les tabs) */
}

/* ── Dropdown de sélection de mois ──────────────────────────────────────────── */
.period-select {
  height: 32px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  /* Chevron SVG custom pour remplacer l'icône native */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2394A3B8' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  -webkit-appearance: none;
  appearance: none;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  white-space: nowrap;
  max-width: 180px;
}
.period-select:hover { border-color: var(--border-strong); }
.period-select:focus {
  border-color: var(--accent-500);
  box-shadow: 0 0 0 3px rgb(16 185 129 / .12);
}

/* ── Modal SKU ───────────────────────────────────────────────────────────────── */
.sku-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgb(15 23 42 / .45);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.sku-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.sku-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sku-modal-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.sku-modal-close {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  line-height: 1;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  transition: background .15s, color .15s;
}
.sku-modal-close:hover { background: var(--surface-muted); color: var(--text); }

.sku-modal-body {
  overflow-y: auto;
  padding: 14px 20px 18px;
}

/* ── Bouton détail par card ──────────────────────────────────────────────────── */
.card-detail-btn {
  display: inline-block;
  margin-top: 10px;
  padding: 0;
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 12px;
  color: var(--accent-600);
  cursor: pointer;
  font-weight: 500;
  transition: color .15s;
}
.card-detail-btn:hover { color: var(--accent-700); text-decoration: underline; }

.sku-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: fixed;
}

.sku-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-subtle);
  padding: 0 6px 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}

.sku-table td {
  padding: 4px 6px 4px 0;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sku-table .sku-td-product { width: 55%; }
.sku-table .sku-td-sku     { width: 25%; color: var(--text-muted); font-family: monospace; font-size: 11px; }
.sku-table .sku-td-num     { width: 20%; text-align: right; font-variant-numeric: tabular-nums; color: var(--text-muted); }
.sku-table .sku-td-empty   { text-align: center; color: var(--text-subtle); padding: 8px 0; }

.card { position: relative; }

/* ── Bannière Grand Total ────────────────────────────────────────────────────── */
.grand-total-banner {
  grid-column: 1 / -1;
  background: var(--accent-50);
  border: 1px solid var(--accent-100);
  border-radius: var(--radius-lg);
  padding: 18px 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.grand-total-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--accent-700);
  min-width: 100px;
}

.grand-total-value {
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -.011em;
  color: var(--accent-600);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.grand-total-sub {
  font-size: 13px;
  color: var(--accent-700);
  opacity: .75;
}

/* ─────────────────────────────────────────────────────────────────────────────
   CRM Nav — topbar flottant · logo tuile · user block · section-header · period-dropdown
   ──────────────────────────────────────────────────────────────────────────── */

/* Topbar : coins arrondis + ombre, flotte sur le fond de page, max 1300px centré */
.topbar {
  width: calc(100% - 32px);
  max-width: 1300px;
  margin: 8px auto;
  border-bottom: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  top: 8px;
}

/* Aligner le contenu principal sur la même largeur */
.container { max-width: 1300px; }

/* Logo tuile carrée verte */
.logo-tile {
  width: 32px;
  height: 32px;
  background: var(--accent-600);
  border-radius: 8px;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: -.01em;
}

/* Nav links : ajouter gap pour les icônes */
.topbar-link { gap: 6px; }

/* Lien actif : pill pleine verte (override du subtle accent-50) */
.topbar-link.active {
  background: var(--accent-600);
  color: #fff;
}
.topbar-link.active:hover { background: var(--accent-700); color: #fff; }

/* ── Bloc utilisateur (droite topbar) ──────────────────────────────────────── */
.topbar-user {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-md);
  transition: background .15s;
  user-select: none;
}
.topbar-user:hover { background: var(--surface-muted); }

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-100);
  color: var(--accent-700);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: .02em;
}

.user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.user-role-badge {
  font-size: 11px;
  color: var(--text-muted);
}

.user-chevron {
  color: var(--text-subtle);
  flex-shrink: 0;
  transition: transform .2s;
}
.topbar-user.open .user-chevron { transform: rotate(180deg); }

.user-dropdown {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  min-width: 160px;
  z-index: 200;
  overflow: hidden;
}
.topbar-user.open .user-dropdown { display: block; }

.user-dropdown-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 9px 14px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: background .1s;
  text-align: left;
}
.user-dropdown-item:hover { background: var(--surface-muted); }

/* ── Total row : banner à gauche + controls (mois + refresh) à droite ──────── */
.total-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

#total-banner {
  flex: 1;
  min-width: 0;
}

#total-banner .grand-total-banner {
  margin-bottom: 0;
}

.total-row-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Period dropdown (pill verte custom) ───────────────────────────────────── */
.period-dropdown-wrap {
  position: relative;
  display: inline-block;
}

.period-dropdown-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  background: var(--accent-600);
  color: #fff;
  border: none;
  border-radius: 17px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.period-dropdown-btn:hover { background: var(--accent-700); }

.period-dropdown-list {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  min-width: 160px;
  z-index: 200;
  overflow: hidden;
  max-height: 280px;
  overflow-y: auto;
}
.period-dropdown-wrap.open .period-dropdown-list { display: block; }

.period-dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 14px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  transition: background .1s, color .1s;
}
.period-dropdown-item:hover { background: var(--surface-muted); color: var(--text); }
.period-dropdown-item.active {
  background: var(--accent-50);
  color: var(--accent-700);
  font-weight: 500;
}

/* ── Pill secondaire (Refresh) ─────────────────────────────────────────────── */
.btn-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 17px;
  background: var(--surface);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.btn-pill:hover:not(:disabled) { background: var(--surface-muted); color: var(--text); }
.btn-pill:disabled { opacity: .5; cursor: not-allowed; }

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .user-info { display: none; }
  .user-chevron { display: none; }
}
@media (max-width: 580px) {
  .topbar { margin: 6px 8px; padding: 0 12px; }
  .section-header { flex-direction: column; align-items: flex-start; gap: 12px; }
}
