/* FacturePro — Professional + Responsive UI */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Cairo:wght@400;600;700&display=swap');

:root {
  --brand: #006233;
  --brand-hover: #00512a;
  --surface: #ffffff;
  --page: #f8fafc;
  --border: #e2e8f0;
  --muted: #64748b;
  --text: #0f172a;
  --radius: 1rem;
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 12px rgba(15,23,42,.08);
}

html { scroll-behavior: smooth; }
body {
  font-family: Inter, system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--page);
  color: var(--text);
}
.font-arabic, .font-arabic * { font-family: Cairo, Tahoma, Arial, sans-serif !important; }
[dir="rtl"] .nav-item { text-align: right; }

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  border-radius: 0.75rem;
  color: #475569;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: all .15s ease;
  text-align: left;
  min-height: 44px;
}
.dark .nav-item { color: #94a3b8; }
.nav-item:hover { background: #f1f5f9; color: #0f172a; }
.dark .nav-item:hover { background: #1e293b; color: #f1f5f9; }
.nav-item.active { background: #e7f5ee; color: #006233; font-weight: 600; }
.dark .nav-item.active { background: #04301b; color: #6ee7b7; }

.card, .stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.dark .card, .dark .stat-card { background: #0f172a; border-color: #1e293b; }
.stat-card { padding: 1.25rem 1.35rem; transition: box-shadow .2s, transform .15s; }
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-label { font-size: 0.8125rem; font-weight: 500; color: var(--muted); }
.stat-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; margin-top: 0.5rem; line-height: 1.2; color: var(--text); }
.dark .stat-value { color: #f8fafc; }
.stat-icon { width: 2.5rem; height: 2.5rem; border-radius: 0.75rem; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table thead th {
  padding: 0.75rem 1rem; text-align: left; font-size: 0.6875rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em; color: #64748b;
  background: #f8fafc; border-bottom: 1px solid var(--border);
}
.dark .data-table thead th { background: #0f172a; border-color: #1e293b; color: #94a3b8; }
.data-table tbody td { padding: 0.875rem 1rem; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.dark .data-table tbody td { border-color: #1e293b; }
.data-table tbody tr:hover { background: #f8fafc; }
.dark .data-table tbody tr:hover { background: #1e293b80; }
.data-table tbody tr:last-child td { border-bottom: none; }

.badge-brouillon { display:inline-flex;align-items:center;gap:5px;padding:4px 12px;border-radius:9999px;font-size:12px;font-weight:500;background:#f3f4f6;color:#374151;border:1px solid #e5e7eb; }
.badge-envoyee { display:inline-flex;align-items:center;gap:5px;padding:4px 12px;border-radius:9999px;font-size:12px;font-weight:500;background:#fef3c7;color:#92400e;border:1px solid #fde68a; }
.badge-payee { display:inline-flex;align-items:center;gap:5px;padding:4px 12px;border-radius:9999px;font-size:12px;font-weight:500;background:#d1fae5;color:#065f46;border:1px solid #a7f3d0; }
.badge-enretard { display:inline-flex;align-items:center;gap:5px;padding:4px 12px;border-radius:9999px;font-size:12px;font-weight:500;background:#fee2e2;color:#991b1b;border:1px solid #fecaca; }
.badge-annulee { display:inline-flex;align-items:center;gap:5px;padding:4px 12px;border-radius:9999px;font-size:12px;font-weight:500;background:#f3f4f6;color:#9ca3af;text-decoration:line-through;border:1px solid #e5e7eb; }

.btn-primary {
  display:inline-flex;align-items:center;justify-content:center;gap:0.5rem;
  border-radius:0.75rem;padding:0.625rem 1.125rem;min-height:44px;
  font-size:0.875rem;font-weight:600;background:var(--brand);color:#fff;border:none;cursor:pointer;
  box-shadow:0 1px 2px rgba(0,98,51,.28);
}
.btn-primary:hover { background: var(--brand-hover); }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary {
  display:inline-flex;align-items:center;gap:0.5rem;border-radius:0.75rem;
  padding:0.625rem 1rem;min-height:44px;font-size:0.875rem;font-weight:500;
  background:#fff;color:#334155;border:1px solid var(--border);cursor:pointer;
}
.dark .btn-secondary { background:#0f172a;color:#e2e8f0;border-color:#334155; }
.btn-secondary:hover { background:#f8fafc; }
.btn-danger {
  display:inline-flex;align-items:center;gap:0.5rem;border-radius:0.75rem;
  padding:0.625rem 1rem;min-height:44px;font-size:0.875rem;font-weight:500;
  background:#dc2626;color:#fff;border:none;cursor:pointer;
}
.btn-ghost {
  display:inline-flex;align-items:center;justify-content:center;
  border-radius:0.5rem;padding:0.4rem;min-width:40px;min-height:40px;
  border:none;background:transparent;color:#64748b;cursor:pointer;
}
.btn-ghost:hover { background:#f1f5f9;color:#0f172a; }
.dark .btn-ghost:hover { background:#1e293b;color:#f1f5f9; }

.form-input, .form-select {
  width:100%;border-radius:0.75rem;border:1px solid var(--border);
  background:#fff;padding:0.625rem 0.875rem;font-size:0.875rem;outline:none;
  min-height:44px;transition:border-color .15s,box-shadow .15s;
}
.dark .form-input, .dark .form-select { background:#0f172a;border-color:#334155;color:#f1f5f9; }
.form-input:focus, .form-select:focus {
  border-color:#059669;box-shadow:0 0 0 3px rgba(5,150,105,.18);
}
.form-label { display:block;font-size:0.75rem;font-weight:500;color:var(--muted);margin-bottom:0.35rem; }

.modal-backdrop {
  position:fixed;inset:0;z-index:50;display:flex;align-items:flex-end;justify-content:center;
  background:rgba(15,23,42,.45);padding:0;backdrop-filter:blur(4px);
}
@media (min-width:640px){ .modal-backdrop{align-items:center;padding:1.5rem;} }
.modal {
  width:100%;max-width:36rem;max-height:90vh;overflow-y:auto;
  background:#fff;border-radius:1.25rem 1.25rem 0 0;box-shadow:0 25px 50px rgba(0,0,0,.2);
}
@media (min-width:640px){ .modal{border-radius:1.25rem;} }
.dark .modal { background:#0f172a; }
.modal.max-w-3xl { max-width:48rem; }
.modal-header {
  display:flex;align-items:center;justify-content:space-between;
  padding:1.15rem 1.35rem;border-bottom:1px solid var(--border);
}
.dark .modal-header { border-color:#1e293b; }
.modal-body { padding:1.35rem; }
.modal-footer {
  display:flex;justify-content:flex-end;gap:0.5rem;flex-wrap:wrap;
  padding:1rem 1.35rem;border-top:1px solid var(--border);
}
.dark .modal-footer { border-color:#1e293b; }

.invoice-paper {
  background:#fff;color:#0f172a;box-shadow:0 25px 50px rgba(15,23,42,.12);
  width:100%;max-width:210mm;min-height:297mm;margin:0 auto;border-radius:2px;
}

.section-title { font-size:1.0625rem;font-weight:600;letter-spacing:-0.01em;color:var(--text); }
.dark .section-title { color:#f1f5f9; }

.safe-area {
  padding-top:env(safe-area-inset-top);
  padding-bottom:env(safe-area-inset-bottom);
  padding-left:env(safe-area-inset-left);
  padding-right:env(safe-area-inset-right);
}

body.sidebar-open { overflow:hidden; }

@media (max-width:639px){
  .stat-card{padding:1rem;}
  .stat-value{font-size:1.25rem;}
  .stat-icon{width:2.25rem;height:2.25rem;}
  .data-table thead th,.data-table tbody td{padding:0.65rem 0.75rem;font-size:0.8125rem;}
  .overflow-x-auto{-webkit-overflow-scrolling:touch;overscroll-behavior-x:contain;}
  .modal{max-height:92vh;}
  .modal-body{padding:1rem;}
  #preview-body{padding:0.75rem!important;}
  .item-row{grid-template-columns:repeat(12,minmax(0,1fr));}
}

@media (min-width:640px) and (max-width:1023px){
  .stat-value{font-size:1.35rem;}
  #sidebar{width:15rem;}
}

@media (min-width:1024px){
  .stat-value{font-size:1.6rem;}
}

@media (max-width:767px){
  #sidebar{width:min(18rem,85vw);box-shadow:0 0 40px rgba(0,0,0,.2);}
}

@media (max-height:500px) and (orientation:landscape){
  .stat-card{padding:0.75rem 1rem;}
  .stat-value{font-size:1.1rem;margin-top:0.25rem;}
}

@media (max-width:360px){
  .stat-value{font-size:1.1rem;}
  .btn-primary,.btn-secondary{font-size:0.8125rem;padding:0.5rem 0.75rem;}
}

@media print{
  #sidebar,header,.btn-primary,.btn-secondary,#preview-root>div:first-child{display:none!important;}
  #preview-root{position:static!important;display:block!important;}
  .invoice-paper{box-shadow:none!important;max-width:100%!important;}
}

@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{animation-duration:0.01ms!important;transition-duration:0.01ms!important;}
}

::-webkit-scrollbar{width:6px;height:6px;}
::-webkit-scrollbar-thumb{background:#cbd5e1;border-radius:3px;}
.dark ::-webkit-scrollbar-thumb{background:#475569;}

.invoice-cards{display:none}
.inv-card{background:var(--surface);border:1px solid var(--border);border-radius:14px;
  padding:14px;box-shadow:var(--shadow);margin-bottom:10px}
.dark .inv-card{background:#0f172a;border-color:#1e293b}
.inv-card .l1{display:flex;align-items:center;gap:8px;margin-bottom:7px}
.inv-card .l1 .no{font-size:13px;font-weight:700;letter-spacing:-.01em}
.inv-card .l1 .badge-wrap{margin-left:auto}
.inv-card .l2{font-size:15px;font-weight:600;letter-spacing:-.01em;margin-bottom:5px}
.inv-card .l3{display:flex;align-items:baseline;gap:10px;font-size:13px;color:var(--muted)}
.inv-card .l3 .amt{margin-left:auto;font-size:15px;font-weight:700;color:var(--text);
  font-variant-numeric:tabular-nums}
.dark .inv-card .l3 .amt{color:#f8fafc}
.inv-card .l4{display:flex;gap:2px;margin-top:10px;padding-top:10px;
  border-top:1px solid var(--border)}
.dark .inv-card .l4{border-color:#1e293b}
@media (max-width:768px){
  .data-table{display:none}
  .invoice-cards{display:block}
}

#boot-skeleton{padding:4px}
.sk{background:linear-gradient(90deg,#eef2f6 25%,#e2e8f0 37%,#eef2f6 63%);
  background-size:400% 100%;animation:sk 1.3s ease-in-out infinite;border-radius:8px}
.dark .sk{background:linear-gradient(90deg,#1e293b 25%,#334155 37%,#1e293b 63%);background-size:400% 100%}
@keyframes sk{0%{background-position:100% 50%}100%{background-position:0 50%}}
.sk-kpis{display:grid;grid-template-columns:repeat(4,1fr);gap:16px;margin-bottom:24px}
@media(max-width:900px){.sk-kpis{grid-template-columns:repeat(2,1fr)}}
@media(max-width:560px){.sk-kpis{grid-template-columns:1fr}}
.sk-card{border:1px solid var(--border);border-radius:16px;padding:20px;background:var(--surface)}
.dark .sk-card{background:#0f172a;border-color:#1e293b}
.sk-line{height:12px;margin-bottom:10px}
.sk-line.lg{height:26px;width:65%;margin-top:14px}
.sk-line.sm{width:45%}
.sk-row{height:44px;margin-bottom:8px}

.btn-primary,.btn-secondary,.btn-danger,.btn-ghost{
  transition:transform .12s cubic-bezier(.34,1.4,.64,1),background .16s,box-shadow .16s}
.btn-primary:active,.btn-secondary:active,.btn-danger:active,.btn-ghost:active{transform:scale(.96)}
.nav-item:active{transform:scale(.985)}
.stat-card{will-change:transform}

.count{font-variant-numeric:tabular-nums}

.empty-state{display:flex;flex-direction:column;align-items:center;text-align:center;padding:56px 24px}
.empty-state svg{width:150px;height:120px;margin-bottom:20px}
.empty-state h3{font-size:18px;font-weight:700;margin-bottom:6px}
.empty-state p{font-size:14px;color:var(--muted);max-width:22rem;margin-bottom:22px}

#confetti{position:fixed;inset:0;pointer-events:none;z-index:200}
@media(prefers-reduced-motion:reduce){
  .sk{animation:none}
  .btn-primary:active,.btn-secondary:active,.btn-danger:active,.btn-ghost:active{transform:none}
}

@media (max-width:767px){
  #sidebar.-translate-x-full{transform:translateX(-100%)!important}
  [dir="rtl"] #sidebar.-translate-x-full{transform:translateX(100%)!important}
  #sidebar.translate-x-0{transform:translateX(0)!important}
  [dir="rtl"] #sidebar{box-shadow:0 0 40px rgba(0,0,0,.2)}
}

.invoice-paper,.invoice-paper *{direction:ltr!important;unicode-bidi:isolate}
.invoice-paper{text-align:left}

.filter-chips{display:flex;gap:8px;overflow-x:auto;padding:2px 2px 10px;margin-bottom:4px;
  -webkit-overflow-scrolling:touch;scrollbar-width:none}
.filter-chips::-webkit-scrollbar{display:none}
.filter-chips .chip{flex:0 0 auto;display:inline-flex;align-items:center;gap:6px;
  min-height:40px;padding:0 14px;border-radius:9999px;font-size:13px;font-weight:600;
  white-space:nowrap;cursor:pointer;background:var(--surface);color:var(--text);
  border:1px solid var(--border);transition:background .15s,border-color .15s,color .15s}
.filter-chips .chip:hover{border-color:#006233}
.filter-chips .chip-on{background:#006233;color:#fff;border-color:#006233}
.filter-chips .chip-n{display:inline-flex;align-items:center;justify-content:center;
  min-width:20px;height:20px;padding:0 6px;border-radius:9999px;font-size:11px;font-weight:700;
  background:rgba(0,0,0,.07);color:inherit}
.filter-chips .chip-on .chip-n{background:rgba(255,255,255,.24)}
.dark .filter-chips .chip{background:#0f172a;border-color:#1e293b;color:#e2e8f0}
.dark .filter-chips .chip-n{background:rgba(255,255,255,.10)}
.dark .filter-chips .chip-on{background:#006233;color:#fff;border-color:#006233}

.inv-card .badge-wrap{margin-left:auto;margin-inline-start:auto;margin-inline-end:0}
.card-status{appearance:none;-webkit-appearance:none;border-radius:9999px;
  min-height:36px;padding:0 30px 0 14px;font-size:12px;font-weight:600;cursor:pointer;
  max-width:150px;text-overflow:ellipsis;
  background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat:no-repeat;background-position:right 10px center;background-size:11px}
[dir="rtl"] .card-status{padding:0 14px 0 30px;background-position:left 10px center}
.card-status:focus-visible{outline:2px solid #006233;outline-offset:2px}

/* ===== Premium visual polish (design refresh) — CSS only ===== */
.dark body,
.dark {
  --page: #0b1220;
  --surface: #111827;
  --border: #1f2937;
  --text: #f8fafc;
  --muted: #94a3b8;
}
.dark body { background: #0b1220; }

:root {
  --brand: #006233;
  --brand-soft: #e7f5ee;
  --paid: #059669;
  --pending: #d97706;
  --overdue: #dc2626;
  --month: #0284c7;
}

.stat-card {
  position: relative;
  overflow: hidden;
  border-radius: 1.1rem;
}
.stat-card::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: 4px 0 0 4px;
  background: var(--brand);
  opacity: .85;
}
.dark .stat-card {
  background: linear-gradient(180deg, #111827 0%, #0f172a 100%);
  border-color: #1e293b;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(15,23,42,.12);
}
.dark .stat-card:hover {
  box-shadow: 0 12px 32px rgba(0,0,0,.35);
}

.stat-card .w-10.h-10.rounded-xl.bg-emerald-100 { background: #d1fae5 !important; }
.stat-card .w-10.h-10.rounded-xl.bg-blue-100 { background: #dbeafe !important; }
.stat-card .w-10.h-10.rounded-xl.bg-red-100 { background: #fee2e2 !important; }
.stat-card .w-10.h-10.rounded-xl.bg-sky-100 { background: #e0f2fe !important; }
.dark .stat-card .w-10.h-10.rounded-xl.bg-emerald-100 { background: rgba(16,185,129,.18) !important; }
.dark .stat-card .w-10.h-10.rounded-xl.bg-blue-100 { background: rgba(59,130,246,.18) !important; }
.dark .stat-card .w-10.h-10.rounded-xl.bg-red-100 { background: rgba(239,68,68,.18) !important; }
.dark .stat-card .w-10.h-10.rounded-xl.bg-sky-100 { background: rgba(14,165,233,.18) !important; }

.dark #sidebar {
  background: #0a0f1a !important;
  border-color: #1e293b !important;
}
.dark .nav-item.active {
  background: rgba(0,98,51,.28);
  color: #6ee7b7;
  box-shadow: inset 3px 0 0 #10b981;
}

.btn-primary {
  background: linear-gradient(180deg, #067a3f 0%, #006233 100%);
  box-shadow: 0 6px 16px rgba(0,98,51,.28);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #078a47 0%, #00512a 100%);
}

.dark .data-table thead th {
  background: #0a0f1a;
  color: #94a3b8;
}
.dark .card {
  background: #111827;
  border-color: #1e293b;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}

.dark .badge-payee { background: rgba(16,185,129,.18); color: #6ee7b7; border-color: rgba(16,185,129,.3); }
.dark .badge-enretard { background: rgba(239,68,68,.18); color: #fca5a5; border-color: rgba(239,68,68,.3); }
.dark .badge-envoyee { background: rgba(245,158,11,.18); color: #fcd34d; border-color: rgba(245,158,11,.3); }
.dark .badge-brouillon { background: rgba(148,163,184,.12); color: #cbd5e1; border-color: rgba(148,163,184,.2); }

.dark .inv-card {
  background: #111827;
  border-color: #1e293b;
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
}

.dark #app {
  background: radial-gradient(1200px 600px at 10% -10%, rgba(0,98,51,.12), transparent 50%), #0b1220;
}


/* ---- Codes that must never be reordered by the bidi algorithm ----
   In Arabic, "05-468" rendered as "468-05" and the RIB's digit groups
   came out in reverse order. These are legal and banking identifiers:
   they are always read left-to-right, in both languages. ---- */
.ltr-code{direction:ltr;unicode-bidi:isolate;}
[dir="rtl"] input.ltr-code,
[dir="rtl"] textarea.ltr-code{direction:ltr;text-align:right;}
