/* assets/css/app.css */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --radius: 12px;
}

body.dark {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #263248;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }
.stack-md > * + * { margin-top: 14px; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.login-brand h1 { margin: 0; font-size: 20px; }
.login-brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.brand-badge {
  width: 42px; height: 42px; border-radius: 10px;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.brand-badge.sm { width: 32px; height: 32px; font-size: 13px; }

/* Shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 245px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-header {
  display: flex; align-items: center; gap: 10px;
  padding: 16px; border-bottom: 1px solid var(--border);
}
.brand-title { font-weight: 700; font-size: 16px; }
.nav-menu { flex: 1; padding: 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 10px 12px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); cursor: pointer; font-size: 14px;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .7; }
.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.session-user strong { display: block; font-size: 13px; }
.session-user span { font-size: 12px; color: var(--muted); }

.main-column { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 58px; background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 20px; display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.page-title { margin: 0; font-size: 18px; }
.workspace { padding: 20px; display: flex; flex-direction: column; gap: 16px; }

/* Cards & Panels */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 22px; font-weight: 700; margin: 6px 0 2px; }
.kpi-sub { font-size: 12px; color: var(--muted); }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: 10px; margin-bottom: 12px;
}
.filters-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* Inputs & Buttons */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 13.5px;
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }

.btn {
  padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; font-size: 13px; font-weight: 600;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-btn { background: transparent; border: 0; color: var(--text); font-size: 18px; cursor: pointer; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }

.badge { padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-ok { background: rgba(34, 197, 94, .15); color: var(--success); }
.badge-warn { background: rgba(245, 158, 11, .15); color: var(--warning); }

/* Pagination */
.pagination-bar {
  display: flex; flex-wrap: wrap; justify-content: space-between;
  align-items: center; gap: 10px; margin-top: 12px; font-size: 12.5px; color: var(--muted);
}
.pagination-controls { display: flex; align-items: center; gap: 8px; }
.page-size-select { width: auto; padding: 4px 8px; font-size: 12px; }

/* Barre de progression */
.progress-wrap {
  margin-top: 14px; padding: 12px;
  border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border);
}
.progress-header { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 6px; }
.progress-track { width: 100%; height: 10px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); transition: width .2s ease; }

/* Fiche client & Aperçu logo */
.client-sheet-card {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; background: var(--surface-2);
}
.client-sheet-head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px;
}
.logo-preview-box {
  min-height: 68px; border: 1px dashed var(--border); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; padding: 8px; color: var(--muted);
  background: var(--surface);
}

/* Modal & Toast */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .6);
  display: grid; place-items: center; padding: 16px; z-index: 50;
}
.modal-card {
  width: 100%; max-width: 560px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.modal-card.modal-lg { max-width: 780px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px; max-height: 80vh; overflow-y: auto; }

.toast-container { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--primary); color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.alert-danger { background: rgba(239, 68, 68, .15); color: var(--danger); padding: 10px; border-radius: 8px; font-size: 13px; }

.mobile-only { display: none; }
@media (max-width: 820px) {
  .mobile-only { display: inline-flex; }
  .sidebar { position: fixed; left: -260px; z-index: 40; transition: left .2s ease; }
  .sidebar.open { left: 0; }
}

/* IMPRESSION ATTRAYANTE & ADAPTÉE : 1, 2 OU 3 FACTURES PAR PAGE */
@media print {
  @page { margin: 8mm; size: A4 portrait; }
  body * { visibility: hidden; }
  #printSheet, #printSheet * { visibility: visible; }
  #printSheet {
    position: absolute; left: 0; top: 0; width: 100%;
    background: #ffffff !important; color: #0f172a !important;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  }

  .print-sheet-page {
    page-break-after: always;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 278mm;
  }
  .print-sheet-page:last-child { page-break-after: auto; }

  .inv-card {
    border: 1.5px solid #1e293b;
    border-radius: 8px;
    background: #ffffff;
    color: #0f172a;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
  }

  /* 1 facture par page : police large et aérée */
  .inv-card.per-1 {
    height: 274mm;
    padding: 18px 22px;
    font-size: 13.5px;
  }
  .inv-card.per-1 .inv-company-name { font-size: 19px; }
  .inv-card.per-1 .inv-summary-table th,
  .inv-card.per-1 .inv-summary-table td { padding: 10px 12px; font-size: 13.5px; }

  /* 2 factures par page : police moyenne équilibrée */
  .inv-card.per-2 {
    height: 134mm;
    padding: 11px 15px;
    font-size: 11.5px;
  }
  .inv-card.per-2 .inv-company-name { font-size: 15px; }
  .inv-card.per-2 .inv-logo { max-height: 34px; }
  .inv-card.per-2 .inv-summary-table th,
  .inv-card.per-2 .inv-summary-table td { padding: 6px 8px; font-size: 11.5px; }

  /* 3 factures par page : police compacte mais nette */
  .inv-card.per-3 {
    height: 89mm;
    padding: 7px 12px;
    font-size: 9.8px;
  }
  .inv-card.per-3 .inv-company-name { font-size: 12.5px; }
  .inv-card.per-3 .inv-logo { max-height: 25px; }
  .inv-card.per-3 .inv-header { padding-bottom: 4px; margin-bottom: 5px; }
  .inv-card.per-3 .inv-info-grid { margin-bottom: 5px; gap: 6px; }
  .inv-card.per-3 .inv-summary-table th,
  .inv-card.per-3 .inv-summary-table td { padding: 4px 6px; font-size: 9.8px; }
  .inv-card.per-3 .inv-words-line { margin-top: 4px; font-size: 9.5px; }
  .inv-card.per-3 .inv-footer { margin-top: 4px; padding-top: 3px; font-size: 9px; }

  .inv-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #1e40af;
    padding-bottom: 7px;
    margin-bottom: 8px;
  }
  .inv-brand { display: flex; align-items: center; gap: 10px; }
  .inv-logo { max-height: 44px; max-width: 110px; object-fit: contain; }
  .inv-logo-fallback {
    width: 34px; height: 34px; border-radius: 6px;
    background: #1e40af; color: #fff; font-weight: 700;
    display: grid; place-items: center;
  }
  .inv-company-name { font-weight: 800; color: #0f172a; }
  .inv-company-meta { color: #475569; font-size: 0.88em; }
  .inv-doc-badge {
    background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe;
    padding: 4px 10px; border-radius: 5px; font-weight: 700; font-size: 0.85em;
    letter-spacing: .5px;
  }

  .inv-info-grid {
    display: grid;
    grid-template-columns: 1.35fr 1fr;
    gap: 12px;
    margin-bottom: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: 6px 10px;
  }
  .inv-dates-col { text-align: right; }
  .inv-info-grid .lbl { color: #475569; }

  .inv-summary-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 2px;
  }
  .inv-summary-table th {
    background: #1e293b;
    color: #ffffff;
    border: 1px solid #1e293b;
    text-align: left;
  }
  .inv-summary-table td {
    border: 1px solid #cbd5e1;
    color: #0f172a;
  }
  .inv-total-cell {
    background: #eff6ff;
    color: #1e3a8a !important;
  }

  .inv-words-line {
    margin-top: 6px;
    padding: 5px 8px;
    background: #f1f5f9;
    border-left: 3px solid #1e40af;
    font-size: 0.92em;
  }
  .inv-words-line span { color: #334155; margin-right: 4px; }

  .inv-footer {
    margin-top: 6px;
    padding-top: 5px;
    border-top: 1px dashed #94a3b8;
    text-align: center;
    color: #475569;
    font-size: 0.88em;
  }
}
