/* ── Variables ─────────────────────────────── */
:root {
  --bg:          #f9f8f6;
  --surface:     #ffffff;
  --surface-2:   #f4f2ef;
  --border:      #e5e0d8;
  --border-strong: #ccc9c2;

  --text:        #1a1a1a;
  --text-muted:  #6b6b6b;
  --text-light:  #9ca3af;

  --accent:      #01696f;
  --accent-h:    #015459;
  --accent-bg:   #e6f4f4;

  --danger:      #dc2626;
  --danger-bg:   #fee2e2;
  --danger-text: #991b1b;

  --sidebar-w:   240px;
  --bottom-h:    64px;
  --radius:      8px;
  --radius-lg:   12px;
  --shadow:      0 2px 8px rgba(0,0,0,.08);
  --shadow-lg:   0 8px 24px rgba(0,0,0,.12);
}

/* ── Reset ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: 'Satoshi', -apple-system, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  width: 100%;
  padding: 8px 12px;
  transition: border-color .15s;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input.input-error, textarea.input-error { border-color: var(--danger); }
textarea { resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

/* ── Layout ────────────────────────────────── */
#app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
}
.sidebar-brand svg { width: 22px; height: 22px; }
.sidebar-nav { padding: 12px 12px; display: flex; flex-direction: column; gap: 2px; }

/* Nav items (shared sidebar + bottom-nav) */
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--accent); }

/* Main */
#app-main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
}
.page-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 32px 64px;
}

/* Bottom nav (mobile only) */
#bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding: 0 8px;
  justify-content: space-around;
  align-items: center;
}
#bottom-nav .nav-item {
  flex-direction: column;
  gap: 3px;
  padding: 6px 14px;
  font-size: 11px;
  border-radius: var(--radius);
}
#bottom-nav .nav-item svg { width: 20px; height: 20px; }

/* ── Page header ────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}
.page-header h1 { font-size: 24px; font-weight: 700; }
.page-header .text-muted { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── Buttons ────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-outline { background: transparent; color: var(--text); border: 1.5px solid var(--border-strong); }
.btn-outline:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 12px; font-size: 13px; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 6px;
  color: var(--text-muted);
  transition: background .15s, color .15s;
}
.btn-icon svg { width: 15px; height: 15px; }
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon--danger:hover { background: var(--danger-bg); color: var(--danger); }

/* ── Search ─────────────────────────────────── */
.search-wrap {
  position: relative;
  margin-bottom: 20px;
  max-width: 380px;
}
.search-wrap svg {
  position: absolute;
  left: 10px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}
.search-input { padding-left: 36px; }

/* ── Filters ────────────────────────────────── */
.filters {
  display: flex;
  gap: 6px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.filter-btn {
  padding: 5px 14px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  background: var(--surface);
  transition: all .15s;
}
.filter-btn:hover { border-color: var(--accent); color: var(--accent); }
.filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Table ──────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; }
thead { background: var(--surface-2); }
th {
  text-align: left;
  padding: 10px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
td {
  padding: 12px 16px;
  font-size: 14px;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}
tr:hover td { background: #faf9f7; }
.cell-truncate { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { display: flex; gap: 2px; }

/* ── Cards grid ─────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-title { font-weight: 600; font-size: 15px; }
.card-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.card-desc { font-size: 13px; color: var(--text-muted); }
.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}
.card-meta span { display: flex; align-items: center; gap: 5px; }
.card-meta svg { width: 13px; height: 13px; }
.card-total { font-weight: 600; color: var(--text); font-size: 15px; }
.card-actions { display: flex; align-items: center; gap: 6px; margin-top: 4px; border-top: 1px solid var(--border); padding-top: 12px; }
.card-actions .btn-sm { flex-shrink: 0; }
.card-actions .spacer { flex: 1; }

/* ── Badges ─────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-gray   { background: #f3f4f6; color: #374151; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-green  { background: #dcfce7; color: #166534; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-amber  { background: #fef3c7; color: #92400e; }

/* ── Empty state ────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 64px 32px;
  color: var(--text-muted);
}
.empty-state svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: 15px; }
.empty-state .text-muted { font-size: 13px; margin-top: 6px; }

/* ── Form ───────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-section { margin-top: 20px; }
.form-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.form-stack { display: flex; flex-direction: column; gap: 14px; }

/* Lignes de prestation */
.lignes-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.lignes-table th {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 6px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.lignes-table td { padding: 4px 4px; vertical-align: middle; }
.lignes-table td:last-child { width: 32px; }
.col-desc { width: 45%; }
.col-qte  { width: 12%; }
.col-pu   { width: 18%; }
.col-total { width: 18%; font-weight: 600; color: var(--text-muted); white-space: nowrap; padding-left: 8px; }
.lignes-total {
  text-align: right;
  font-size: 15px;
  font-weight: 700;
  margin-top: 10px;
  color: var(--text);
}
.lignes-total span { color: var(--text-muted); font-weight: 500; font-size: 13px; }

/* ── Modal ──────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
#modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
#modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: translateY(8px);
  transition: transform .2s;
}
#modal-overlay.open #modal-box { transform: translateY(0); }
.modal-wide { max-width: 720px; }
#modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#modal-title { font-size: 17px; font-weight: 700; }
#modal-close {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  color: var(--text-muted);
  transition: background .15s;
}
#modal-close svg { width: 17px; height: 17px; }
#modal-close:hover { background: var(--surface-2); }
#modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
#modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Toast ──────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--text);
  color: #fff;
  padding: 10px 20px;
  border-radius: 100px;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 300;
  white-space: nowrap;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.toast-error { background: var(--danger); }

/* ── Misc ───────────────────────────────────── */
.text-muted { color: var(--text-muted); }
a.text-link { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.mention-tva {
  font-size: 12px;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 8px 12px;
  margin-top: 8px;
}
.statut-select-wrap { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.statut-chip {
  padding: 5px 14px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  border: 1.5px solid var(--border);
  cursor: pointer;
  transition: all .15s;
  background: var(--surface);
}
.statut-chip.selected { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); }

/* Facture table in list */
.facture-num { font-family: monospace; font-size: 13px; font-weight: 600; }

/* ── Settings ───────────────────────────────── */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
}
.settings-card h2 { font-size: 16px; font-weight: 700; margin-bottom: 20px; }

/* ── Print view ─────────────────────────────── */
.print-header-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.print-header-bar h2 { font-size: 15px; font-weight: 600; flex: 1; }

.invoice-page {
  background: #fff;
  max-width: 794px;
  margin: 0 auto;
  padding: 48px;
  box-shadow: var(--shadow-lg);
  border-radius: var(--radius-lg);
}
.invoice-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 40px; }
.invoice-company { max-width: 280px; }
.invoice-company h2 { font-size: 20px; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.invoice-company p { font-size: 13px; color: var(--text-muted); line-height: 1.6; }
.invoice-meta { text-align: right; }
.invoice-meta .invoice-label { font-size: 28px; font-weight: 700; color: var(--text); }
.invoice-meta .invoice-num { font-size: 15px; color: var(--accent); font-weight: 600; margin-top: 4px; }
.invoice-meta .invoice-date { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.invoice-to { margin-bottom: 32px; }
.invoice-to-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); margin-bottom: 8px; }
.invoice-to-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: inline-block;
  min-width: 240px;
}
.invoice-to-box strong { font-size: 15px; font-weight: 600; }
.invoice-to-box p { font-size: 13px; color: var(--text-muted); margin-top: 4px; line-height: 1.6; }
.invoice-lines { margin-bottom: 24px; }
.invoice-lines table { width: 100%; border-collapse: collapse; }
.invoice-lines th {
  background: var(--surface-2);
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}
.invoice-lines td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
.invoice-lines .text-right { text-align: right; }
.invoice-total {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 28px;
}
.invoice-total-box {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-width: 220px;
}
.invoice-total-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 16px;
  font-size: 14px;
}
.invoice-total-row.total {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
}
.invoice-footer { border-top: 1px solid var(--border); padding-top: 16px; }
.invoice-footer p { font-size: 12px; color: var(--text-muted); line-height: 1.7; }
.invoice-tva {
  font-size: 11px;
  font-style: italic;
  color: var(--text-muted);
  margin-top: 12px;
}
.invoice-bank { margin-top: 16px; }
.invoice-bank strong { font-size: 13px; font-weight: 600; display: block; margin-bottom: 4px; }
.invoice-bank p { font-size: 12px; color: var(--text-muted); line-height: 1.8; font-family: monospace; }

/* ── Print mode (body class) ─────────────────── */
body.print-mode #sidebar,
body.print-mode #bottom-nav { display: none !important; }
body.print-mode #app-main { margin-left: 0; }
body.print-mode .page-content { padding: 0; max-width: 100%; }

/* ── Responsive ─────────────────────────────── */
@media (max-width: 768px) {
  #sidebar { display: none; }
  #app-main { margin-left: 0; }
  #bottom-nav { display: flex; }
  .page-content { padding: 20px 16px calc(var(--bottom-h) + 20px); }
  .page-header { flex-wrap: wrap; }
  .form-row { grid-template-columns: 1fr; }
  .cards-grid { grid-template-columns: 1fr; }
  .table-wrap { border-radius: var(--radius); }
  .invoice-page { padding: 24px 20px; }
  .invoice-header { flex-direction: column; gap: 20px; }
  .invoice-meta { text-align: left; }
}

/* ── @media print ───────────────────────────── */
/* ── Auth screen ────────────────────────────── */
#auth-screen,
#set-password-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.auth-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 28px;
  justify-content: center;
}
.auth-brand svg { width: 26px; height: 26px; }

/* ── Sidebar footer / logout ────────────────── */
.sidebar-footer {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid var(--border);
}
.btn-logout {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  transition: background .15s, color .15s;
}
.btn-logout:hover { background: var(--danger-bg); color: var(--danger); }
.btn-logout svg { width: 18px; height: 18px; }

/* ── Loading state ──────────────────────────── */
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: var(--text-muted);
}

@media print {
  body { background: #fff; }
  #sidebar, #bottom-nav, #toast, #modal-overlay,
  .print-header-bar, .no-print { display: none !important; }
  #app-main { margin-left: 0; }
  .page-content { padding: 0; }
  .invoice-page {
    box-shadow: none;
    border-radius: 0;
    max-width: 100%;
    padding: 0;
    page-break-inside: avoid;
  }
  @page { size: A4; margin: 20mm 15mm; }
}
