/* ══════════════════════════════════════════════════════
   FACTUREPRO v2.0 — MAIN STYLESHEET
   Part 1: Reset, Base, Auth, Sidebar, Layout
   ══════════════════════════════════════════════════════ */
@import url('variables.css');

/* ── RESET & BASE ── */
*,*::before,*::after { box-sizing:border-box; margin:0; padding:0; }
html { font-size:14px; scroll-behavior:smooth; -webkit-text-size-adjust:100%; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--gold); text-decoration:none; }
a:hover { color: var(--gold-light); }
img { max-width:100%; display:block; }
button { cursor:pointer; font-family:inherit; border:none; outline:none; }
input,select,textarea {
  font-family: var(--font-ui);
  font-size: 0.93rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  outline: none;
  transition: border var(--t-fast), box-shadow var(--t-fast);
  width: 100%;
}
input:focus,select:focus,textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(200,160,48,0.15);
}
input::placeholder,textarea::placeholder { color: var(--text-faint); }
select { appearance:none; background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238a9bb8'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat:no-repeat; background-position:right 12px center; padding-right:32px; }
textarea { resize:vertical; min-height:80px; }
::-webkit-scrollbar { width:6px; height:6px; }
::-webkit-scrollbar-track { background:var(--bg-2); }
::-webkit-scrollbar-thumb { background:var(--surface-3); border-radius:3px; }
::-webkit-scrollbar-thumb:hover { background:var(--gold-dark); }

/* ══ SPLASH SCREEN ══ */
#splash-screen {
  position: fixed;
  inset: 0;
  background: #0d1420;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.5s ease, transform 0.5s ease;
}
#splash-screen.hidden {
  opacity: 0;
  transform: scale(1.05);
  pointer-events: none;
}
.splash-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: splashIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
@keyframes splashIn {
  from { opacity: 0; transform: translateY(30px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.splash-logo {
  animation: craneSwing 1.5s ease-in-out infinite alternate;
  transform-origin: 60px 16px;
}
@keyframes craneSwing {
  from { transform: rotate(-3deg); }
  to   { transform: rotate(3deg); }
}
.splash-brand {
  font-size: 2rem;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: -1px;
}
.splash-sub {
  font-size: 0.85rem;
  color: #c8a030;
  font-weight: 700;
  letter-spacing: 4px;
  text-transform: uppercase;
}
.splash-loader {
  width: 160px;
  height: 3px;
  background: rgba(255,255,255,0.1);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 20px;
}
.splash-bar {
  height: 100%;
  background: linear-gradient(90deg, #c8a030, #f0d060, #c8a030);
  border-radius: 10px;
  animation: splashLoad 1.8s ease-in-out forwards;
}
@keyframes splashLoad {
  0%   { width: 0%; }
  60%  { width: 80%; }
  90%  { width: 95%; }
  100% { width: 100%; }
}

/* ── AUTH SCREEN ── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--bg) 0%, var(--navy-dark) 50%, var(--bg) 100%);
  padding: var(--gap-lg);
  position: relative;
  overflow: hidden;
}
#auth-screen::before {
  content: '';
  position: absolute;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background: radial-gradient(circle at 30% 40%, rgba(200,160,48,0.06) 0%, transparent 50%),
              radial-gradient(circle at 70% 60%, rgba(64,144,240,0.04) 0%, transparent 50%);
  animation: spin 60s linear infinite;
  pointer-events: none;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--gap-2xl) var(--gap-xl);
  width: 100%;
  max-width: 420px;
  position: relative;
  z-index: 1;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  animation: scaleIn 0.5s ease;
}
.auth-logo {
  text-align: center;
  margin-bottom: var(--gap-lg);
}
.auth-logo h1 {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 2px;
  text-transform: uppercase;
}
.auth-logo p {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: var(--gap-xs);
}
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: var(--gap-lg);
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--border);
}
.auth-tabs .tab-btn {
  flex: 1;
  padding: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  background: transparent;
  color: var(--text-muted);
  transition: all var(--t-base);
}
.auth-tabs .tab-btn.active {
  background: var(--gold);
  color: var(--navy-dark);
}
.auth-tabs .tab-btn:hover:not(.active) {
  background: var(--surface-2);
  color: var(--text);
}
.auth-form { display:none; }
.auth-form.active,
.auth-form[style*="display: block"],
.auth-form[style*="display:block"] { display:block; }
.auth-form .form-group {
  margin-bottom: var(--gap-md);
}
.auth-form label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.auth-form input {
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
}
.auth-form input:focus {
  background: var(--surface);
  border-color: var(--gold);
}
#auth_err {
  color: var(--red);
  font-size: 0.82rem;
  text-align: center;
  min-height: 20px;
  margin-bottom: var(--gap-sm);
}

/* ── APP LAYOUT ── */
#app-screen {
  display: none;
  min-height: 100vh;
}

/* ── SIDEBAR ── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: var(--z-sticky);
  transition: width var(--t-slow), transform var(--t-slow);
  overflow: hidden;
}
.sidebar-brand {
  padding: var(--gap-lg) var(--gap-md);
  border-bottom: 1px solid var(--border);
  text-align: center;
}
.sidebar-brand h2 {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 2px;
  text-transform: uppercase;
}
.sidebar-brand small {
  color: var(--text-faint);
  font-size: 0.7rem;
  letter-spacing: 1px;
}
.sidebar-nav {
  flex: 1;
  padding: var(--gap-md) var(--gap-sm);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-btn {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: 11px 14px;
  border-radius: var(--r-sm);
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  transition: all var(--t-fast);
  white-space: nowrap;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
}
.nav-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.nav-btn.active {
  background: linear-gradient(135deg, rgba(200,160,48,0.12), rgba(200,160,48,0.05));
  color: var(--gold);
  border-color: rgba(200,160,48,0.2);
  font-weight: 600;
}
.nav-btn .nav-icon {
  font-size: 1.15rem;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}
.nav-btn .nav-label { flex:1; }
.nav-separator {
  height: 1px;
  background: var(--border);
  margin: var(--gap-sm) var(--gap-sm);
}

/* Sidebar user section */
.sidebar-user {
  padding: var(--gap-md);
  border-top: 1px solid var(--border);
  position: relative;
}
.user-trigger {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  width: 100%;
  padding: 8px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  transition: background var(--t-fast);
  cursor: pointer;
}
.user-trigger:hover { background: var(--surface-3); }
.user-badge {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: var(--navy-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.user-email {
  font-size: 0.78rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.user-menu {
  display: none;
  position: absolute;
  bottom: 100%;
  left: var(--gap-md);
  right: var(--gap-md);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  margin-bottom: var(--gap-xs);
}
.user-menu.open { display:block; animation: fadeIn 0.2s ease; }
.user-menu button {
  width: 100%;
  padding: 10px 14px;
  background: transparent;
  color: var(--text-muted);
  text-align: left;
  font-size: 0.85rem;
  transition: all var(--t-fast);
}
.user-menu button:hover { background: var(--surface-3); color: var(--text); }
.user-menu .logout-btn { color: var(--red); }
.user-menu .logout-btn:hover { background: var(--red-bg); }

/* PWA install button */
#pwa-install-btn {
  display: none;
  align-items: center;
  justify-content: center;
  gap: var(--gap-sm);
  margin: 0 var(--gap-sm) var(--gap-sm);
  padding: 10px;
  border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: var(--navy-dark);
  font-weight: 600;
  font-size: 0.82rem;
  transition: opacity var(--t-fast);
}
#pwa-install-btn:hover { opacity:0.9; }

/* Sync indicator */
.sync-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 var(--gap-md) var(--gap-sm);
  font-size: 0.72rem;
  color: var(--text-faint);
}
.sync-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}
.sync-dot.syncing {
  background: var(--orange);
  animation: pulse 1s ease infinite;
}

/* ── MAIN CONTENT ── */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  transition: margin-left var(--t-slow);
}
.page-header {
  padding: var(--gap-lg) var(--gap-xl);
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.page-header h1 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 1px;
}
.page-header p {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-top: 2px;
}
.page-body {
  padding: var(--gap-xl);
}

/* ── PAGES ── */
.page { display:none; animation: fadeIn 0.35s ease; }
.page.active { display:block; }

/* ══════════════════════════════════════════════════════
   Part 2: Buttons, Cards, Dashboard, Tables, Forms
   ══════════════════════════════════════════════════════ */

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-sm);
  padding: 11px 22px;
  border-radius: var(--r-sm);
  font-size: 0.88rem;
  font-weight: 600;
  transition: all var(--t-base);
  white-space: nowrap;
  border: 1px solid transparent;
}
.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: var(--navy-dark);
  box-shadow: var(--shadow-gold);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(200,160,48,0.35);
}
.btn-primary:active { transform:translateY(0); }
.btn-primary:disabled { opacity:0.5; cursor:not-allowed; transform:none; }
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-3); border-color: var(--gold); color: var(--gold); }
.btn-outline {
  background: transparent;
  color: var(--gold);
  border: 1px solid rgba(200,160,48,0.3);
}
.btn-outline:hover { background: rgba(200,160,48,0.08); border-color: var(--gold); }
.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(240,80,96,0.2);
}
.btn-danger:hover { background: rgba(240,80,96,0.2); }
.btn-sm { padding:7px 14px; font-size:0.8rem; }
.btn-block { width:100%; }
.btn-group { display:flex; gap:var(--gap-sm); flex-wrap:wrap; }

.ic-btn {
  width: 34px; height: 34px;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  transition: all var(--t-fast);
  border: 1px solid transparent;
}
.ic-btn:hover { background: var(--surface-2); border-color: var(--border); color: var(--text); }

/* ── CARDS ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--gap-lg);
  transition: border-color var(--t-base);
}
.card:hover { border-color: rgba(200,160,48,0.25); }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--gap-md);
}
.card-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

/* ── BADGES ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.badge-paid { background: var(--green-bg); color: var(--green); }
.badge-pend { background: var(--orange-bg); color: var(--orange); }
.badge-overdue { background: var(--red-bg); color: var(--red); }
.badge-info { background: var(--blue-bg); color: var(--blue); }

/* ── DASHBOARD ── */
/* Period filter */
.period-bar {
  display: flex;
  gap: 4px;
  margin-bottom: var(--gap-lg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 4px;
  width: fit-content;
}
.pbtn {
  padding: 8px 16px;
  border-radius: var(--r-sm);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  transition: all var(--t-fast);
}
.pbtn:hover { color: var(--text); background: var(--surface-2); }
.pbtn.active {
  background: var(--gold);
  color: var(--navy-dark);
  font-weight: 600;
}

/* KPI grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--gap-md);
  margin-bottom: var(--gap-xl);
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--gap-lg);
  display: flex;
  flex-direction: column;
  gap: var(--gap-xs);
  transition: all var(--t-base);
  position: relative;
  overflow: hidden;
}
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--gold), var(--gold-light));
  opacity: 0;
  transition: opacity var(--t-base);
}
.kpi-card:hover::before { opacity: 1; }
.kpi-card:hover { border-color: rgba(200,160,48,0.25); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.kpi-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.kpi-value {
  font-family: var(--font-heading);
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.kpi-value.gold { color: var(--gold); }
.kpi-value.green { color: var(--green); }
.kpi-value.orange { color: var(--orange); }
.kpi-sub {
  font-size: 0.75rem;
  color: var(--text-faint);
}

/* ── BAR CHART ── */
.chart-row {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: var(--gap-lg);
  margin-bottom: var(--gap-xl);
}
/* ══ RELANCE AUTOMATIQUE ══ */
.relance-card {
  border: 1px solid rgba(255,68,68,0.35) !important;
  animation: relance-pulse 2.5s ease-in-out infinite;
  margin-bottom: var(--gap-xl);
}
@keyframes relance-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,68,68,0); }
  50%       { box-shadow: 0 0 12px 4px rgba(255,68,68,0.2); }
}

.bar-chart-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 200px;
  padding: var(--gap-md) 0;
}
.bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
}
.bar-amt {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}
.bar-col {
  flex: 1;
  width: 100%;
  max-width: 48px;
  display: flex;
  align-items: flex-end;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  overflow: hidden;
}
.bar {
  width: 100%;
  background: linear-gradient(180deg, var(--gold), var(--gold-dark));
  border-radius: var(--r-sm) var(--r-sm) 0 0;
  transition: height 0.6s cubic-bezier(0.4,0,0.2,1);
  min-height: 2px;
}
.bar-lbl {
  font-size: 0.72rem;
  color: var(--text-faint);
  text-transform: uppercase;
  font-weight: 500;
}

/* ── DONUT ── */
.donut-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--gap-md);
}
.donut-chart {
  position: relative;
  width: 140px; height: 140px;
}
.donut-chart svg { width:100%; height:100%; transform: rotate(-90deg); }
.donut-chart circle {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dasharray 0.6s ease;
}
.donut-paid { stroke: var(--green); }
.donut-pend { stroke: var(--orange); }
.donut-pct {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}
.donut-legend {
  display: flex;
  flex-direction: column;
  gap: var(--gap-xs);
  font-size: 0.78rem;
  color: var(--text-muted);
}
.donut-legend span::before {
  content: '';
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
#leg_paid::before { background: var(--green); }
#leg_pend::before { background: var(--orange); }

/* ── TABLES ── */
.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 480px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
}
.table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #1a2e4a;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
thead th {
  padding: 12px 14px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
tbody tr { transition: background var(--t-fast); }
tbody tr:hover { background: rgba(200,160,48,0.03); }
tbody tr:last-child td { border-bottom: none; }
td.r, th.r { text-align: right; }
td.c, th.c { text-align: center; }
.table-empty {
  padding: var(--gap-2xl);
  text-align: center;
  color: var(--text-faint);
  font-size: 0.9rem;
}
.table-empty .empty-icon { font-size: 2.5rem; margin-bottom: var(--gap-sm); opacity: 0.4; }

/* ── SEARCH BAR ── */
.search-bar {
  position: relative;
  max-width: 360px;
}
.search-bar input {
  padding-left: 38px;
  background: var(--bg-2);
}
.search-bar::before {
  content: '🔍';
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  pointer-events: none;
}

/* ── TOOLBAR ── */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-md);
  margin-bottom: var(--gap-lg);
  flex-wrap: wrap;
}
.toolbar-left { display:flex; align-items:center; gap:var(--gap-md); flex-wrap:wrap; }
.toolbar-right { display:flex; align-items:center; gap:var(--gap-sm); }

/* ── FORM SECTIONS ── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--gap-lg);
  margin-bottom: var(--gap-xl);
}
.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--gap-lg);
}
.form-section-title {
  font-family: var(--font-heading);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: var(--gap-md);
  padding-bottom: var(--gap-sm);
  border-bottom: 1px solid var(--border);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap-md);
  margin-bottom: var(--gap-md);
}
.form-group {
  margin-bottom: var(--gap-md);
}
.form-group:last-child { margin-bottom: 0; }
.form-group label,
label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

/* ── ITEMS (line items) ── */
.items-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--gap-lg);
  margin-bottom: var(--gap-lg);
}
.item-row {
  display: grid;
  grid-template-columns: 1fr 80px 100px 36px;
  gap: var(--gap-sm);
  margin-bottom: var(--gap-sm);
  align-items: center;
}
.item-row input {
  background: var(--bg-2);
  border: 1px solid var(--border-subtle);
  padding: 9px 12px;
  font-size: 0.85rem;
}
.item-row input:focus {
  border-color: var(--gold);
  background: var(--surface);
}
.btn-rm {
  width: 34px; height: 34px;
  border-radius: var(--r-sm);
  background: var(--red-bg);
  color: var(--red);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast);
  border: 1px solid transparent;
}
.btn-rm:hover { background: rgba(240,80,96,0.2); border-color: var(--red); }
.btn-add-item {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: 8px 16px;
  border-radius: var(--r-sm);
  background: rgba(200,160,48,0.08);
  color: var(--gold);
  font-size: 0.82rem;
  font-weight: 600;
  transition: all var(--t-fast);
  border: 1px dashed rgba(200,160,48,0.3);
  margin-top: var(--gap-sm);
}
.btn-add-item:hover { background: rgba(200,160,48,0.15); border-color: var(--gold); }

/* ── FORMAT SWITCHER ── */
.format-switcher {
  display: flex;
  gap: var(--gap-sm);
  margin-bottom: var(--gap-lg);
}
.format-btn {
  padding: 8px 20px;
  border-radius: var(--r-sm);
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid rgba(200,160,48,0.3);
  color: var(--gold);
  background: transparent;
  transition: all var(--t-fast);
}
.format-btn.active,
.format-btn[style*="background:var(--gold)"],
.format-btn[style*="background: var(--gold)"] {
  background: var(--gold) !important;
  color: var(--navy-dark) !important;
  border-color: var(--gold) !important;
}

/* ── LANGUAGE SWITCHER ── */
.lang-switcher {
  display: flex;
  gap: var(--gap-sm);
}
.lang-btn {
  padding: 6px 14px;
  border-radius: var(--r-sm);
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid rgba(200,160,48,0.3);
  color: var(--gold);
  background: transparent;
  transition: all var(--t-fast);
}
.lang-btn.active { background: var(--gold); color: var(--navy-dark); border-color: var(--gold); }

/* ── ACTION BAR (below document forms) ── */
.action-bar {
  display: flex;
  gap: var(--gap-sm);
  flex-wrap: wrap;
  margin-bottom: var(--gap-xl);
  padding: var(--gap-md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}

/* ── SETTINGS ── */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--gap-lg);
}
.logo-preview {
  width: 80px; height: 80px;
  border-radius: var(--r-md);
  object-fit: contain;
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 4px;
}

/* ══════════════════════════════════════════════════════
   Part 3: Modals, Toast, Document Preview
   ══════════════════════════════════════════════════════ */

/* ── MODALS ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  align-items: center;
  justify-content: center;
  padding: var(--gap-lg);
}
.modal-overlay[style*="display: flex"],
.modal-overlay[style*="display:flex"] { display:flex !important; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: scaleIn 0.3s ease;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--gap-lg) var(--gap-lg) var(--gap-md);
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 1px;
}
.modal-close {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast);
}
.modal-close:hover { background: var(--red-bg); color: var(--red); }
.modal-body {
  padding: var(--gap-lg);
}
.modal-footer {
  padding: var(--gap-md) var(--gap-lg) var(--gap-lg);
  display: flex;
  gap: var(--gap-sm);
  justify-content: flex-end;
}

/* ── TOAST ── */
#toast {
  position: fixed;
  bottom: 30px;
  right: 30px;
  background: var(--surface-2);
  color: var(--text);
  padding: 14px 24px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-toast);
  opacity: 0;
  transform: translateX(120%);
  transition: all 0.4s cubic-bezier(0.4,0,0.2,1);
  pointer-events: none;
  max-width: 400px;
}
#toast.show {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
  animation: toastIn 0.4s ease;
}

/* ── DOCUMENT PREVIEW (shared) ── */
.doc-preview-wrap {
  margin-top: var(--gap-xl);
}
.doc-preview-label {
  font-family: var(--font-heading);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: var(--gap-md);
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
}
.doc-preview-label::before {
  content: '';
  width: 3px; height: 18px;
  background: var(--gold);
  border-radius: 2px;
}

/* ── INVOICE / DOCUMENT (white A4 preview) ── */
.invoice-doc,
#invoice,
#invoice-f2,
#devis-doc,
#commande-doc {
  background: #ffffff;
  color: #1a1a2e;
  max-width: 794px;
  margin: 0 auto;
  padding: 40px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  font-family: 'Inter', Arial, sans-serif;
  font-size: 12px;
  line-height: 1.5;
  position: relative;
}
/* Document header area */
.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 2px solid #1a2e5a;
}
.inv-header .company-info h2 {
  font-family: var(--font-heading);
  font-size: 22px;
  font-weight: 700;
  color: #1a2e5a;
  margin-bottom: 4px;
}
.inv-header .company-info p,
.inv-header .company-info .co-details {
  font-size: 11px;
  color: #555;
  line-height: 1.6;
  white-space: pre-line;
}
.inv-header .inv-logo img {
  max-height: 60px;
  max-width: 140px;
  object-fit: contain;
}
/* Doc title */
.doc-type-title {
  font-family: var(--font-heading);
  font-size: 28px;
  font-weight: 700;
  color: #1a2e5a;
  text-align: right;
  text-transform: uppercase;
  letter-spacing: 3px;
}
/* Meta info (number, date) */
.inv-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
}
.inv-meta .meta-left,
.inv-meta .meta-right {
  font-size: 11px;
}
.inv-meta strong {
  color: #1a2e5a;
}
/* Client block */
.inv-client-block {
  background: #f7f8fc;
  border: 1px solid #e0e4ef;
  border-left: 3px solid #C8A030;
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 24px;
}
.inv-client-block .block-label {
  font-size: 9px;
  font-weight: 700;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}
.inv-client-block .client-data {
  font-size: 12px;
  color: #333;
  line-height: 1.6;
}
/* Subject/objet */
.inv-objet {
  margin-bottom: 20px;
  font-size: 12px;
}
.inv-objet strong { color: #1a2e5a; }

/* ── DOCUMENT TABLE ── */
.inv-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 11px;
}
.inv-table thead th {
  background: #1a2e5a;
  color: #fff;
  padding: 10px 12px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-align: left;
  border: none;
}
.inv-table thead th:first-child { border-radius: 4px 0 0 0; }
.inv-table thead th:last-child { border-radius: 0 4px 0 0; }
.inv-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
  color: #333;
  vertical-align: top;
}
.inv-table tbody tr:nth-child(even) { background: #fafbfe; }
.inv-table tbody tr:hover { background: #f0f2fa; }
.inv-table .c { text-align: center; }
.inv-table .r { text-align: right; }

/* ── TOTALS ── */
.inv-totals {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
}
.inv-totals table {
  width: 280px;
  font-size: 12px;
}
.inv-totals td {
  padding: 6px 12px;
  border: none;
}
.inv-totals .total-label {
  color: #666;
  text-align: right;
  padding-right: 16px;
}
.inv-totals .total-value {
  text-align: right;
  font-weight: 600;
  color: #1a2e5a;
}
.inv-totals .total-row-final {
  background: #1a2e5a;
  color: #fff;
  border-radius: 4px;
}
.inv-totals .total-row-final td {
  font-size: 14px;
  font-weight: 700;
  padding: 10px 12px;
}

/* Amount in words */
.inv-amount-words {
  font-size: 10px;
  color: #666;
  font-style: italic;
  margin-bottom: 20px;
  padding: 10px 14px;
  background: #f7f8fc;
  border-radius: 4px;
  border-left: 3px solid #C8A030;
}
/* Notes */
.inv-notes {
  margin-bottom: 24px;
  font-size: 11px;
  color: #555;
}
.inv-notes strong { color: #1a2e5a; display:block; margin-bottom:4px; }

/* Signatures */
.inv-signatures {
  display: flex;
  justify-content: space-between;
  margin-top: 30px;
  padding-top: 30px;
}
.inv-sig-block {
  width: 45%;
  text-align: center;
  padding-top: 50px;
  border-top: 1px dashed #ccc;
}
.inv-sig-block p {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Footer */
.inv-footer {
  margin-top: 30px;
  padding-top: 12px;
  border-top: 2px solid #1a2e5a;
  text-align: center;
  font-size: 9px;
  color: #888;
}
.inv-footer .footer-line { margin-bottom: 2px; }
.inv-footer .footer-slogan {
  font-style: italic;
  color: #C8A030;
  font-size: 10px;
}

/* Format 2 specific (modern / color accented) */
#invoice-f2 { display:none; }
#invoice-f2 .inv-header {
  border-bottom-color: #C8A030;
}
#invoice-f2 .doc-type-title {
  color: #C8A030;
}
/* Bank fields for format 2 */
#bank-fields { display:none; }
.bank-info {
  font-size: 11px;
  background: #f7f8fc;
  padding: 12px 16px;
  border-radius: 4px;
  margin-bottom: 20px;
  border: 1px solid #e0e4ef;
}
.bank-info strong { color: #1a2e5a; }

/* ── RTL SUPPORT ── */
[dir="rtl"] .sidebar { left:auto; right:0; border-right:none; border-left:1px solid var(--border); }
[dir="rtl"] .main-content { margin-left:0; margin-right:var(--sidebar-w); }
[dir="rtl"] .nav-btn { text-align:right; }
[dir="rtl"] .inv-client-block { border-left:none; border-right:3px solid #C8A030; }
[dir="rtl"] .inv-amount-words { border-left:none; border-right:3px solid #C8A030; }
[dir="rtl"] #toast { right:auto; left:30px; }
[dir="rtl"] .inv-table thead th:first-child { border-radius:0 4px 0 0; }
[dir="rtl"] .inv-table thead th:last-child { border-radius:4px 0 0 0; }
[dir="rtl"] select { background-position:left 12px center; padding-right:14px; padding-left:32px; }

/* ══════════════════════════════════════════════════════
   Part 4: Print, Responsive, Utilities
   ══════════════════════════════════════════════════════ */

/* ── LOADING / SKELETON ── */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 400% 100%;
  animation: shimmer 1.5s ease infinite;
  border-radius: var(--r-sm);
}
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── MOBILE HAMBURGER ── */
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-sticky);
  align-items: center;
  padding: 0 var(--gap-md);
  gap: var(--gap-md);
}
.hamburger {
  width: 40px; height: 40px;
  background: transparent;
  color: var(--text);
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
}
.hamburger:hover { background: var(--surface-2); }
.mobile-brand {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: calc(var(--z-sticky) - 1);
}

/* ── UTILITY CLASSES ── */
.text-gold { color: var(--gold); }
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: 0.82rem; }
.text-xs { font-size: 0.72rem; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.mt-sm { margin-top: var(--gap-sm); }
.mt-md { margin-top: var(--gap-md); }
.mt-lg { margin-top: var(--gap-lg); }
.mb-sm { margin-bottom: var(--gap-sm); }
.mb-md { margin-bottom: var(--gap-md); }
.mb-lg { margin-bottom: var(--gap-lg); }
.gap-sm { gap: var(--gap-sm); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ════ NOMA DOCUMENT UNIFIED DESIGN ════ */
.noma-doc { background: #ffffff; color: #1a1a2e; font-family: 'Inter', sans-serif; padding: 2rem; border-radius: var(--r-lg); box-shadow: 0 8px 30px rgba(0,0,0,0.2); }
.noma-doc-inner { background: #ffffff; border: 0.5px solid #d0d7e5; border-radius: 8px; overflow: hidden; }
.noma-header { padding: 2rem 2.5rem; border-bottom: 2px solid #1a2e4a; display: flex; justify-content: space-between; align-items: flex-start; }
.noma-logo-sq { width: 42px; height: 42px; background: #1a2e4a; border-radius: 6px; display: flex; align-items: center; justify-content: center; }
.noma-logo-sq span { color: #fff; font-weight: 700; font-size: 13px; letter-spacing: 1px; }
.noma-logo-img { max-height: 42px; max-width: 150px; object-fit: contain; }
.noma-co-name { margin: 0; font-size: 17px; font-weight: 700; color: #111827; letter-spacing: 0.5px; }
.noma-co-desc { margin: 0; font-size: 11px; color: #6b7280; letter-spacing: 1px; text-transform: uppercase; }
.noma-co-det { margin: 4px 0 0; font-size: 12px; color: #4b5563; line-height: 1.5; }
.noma-doc-title { margin: 0; font-size: 28px; font-weight: 700; color: #1a2e4a; letter-spacing: 2px; }
.noma-meta-txt { margin: 4px 0 0; font-size: 13px; color: #4b5563; }
.noma-meta-val { color: #111827; font-weight: 600; }
.noma-meta-date { margin: 2px 0; font-size: 12px; color: #4b5563; }
.noma-badge { margin-top: 10px; display: inline-block; background: #e8f4f0; border: 0.5px solid #5DCAA5; border-radius: 4px; padding: 4px 12px; }
.noma-badge span { font-size: 11px; color: #0F6E56; font-weight: 600; letter-spacing: 0.5px; }
.noma-badge.pending { background: rgba(200,160,48,0.1); border-color: var(--gold); }
.noma-badge.pending span { color: var(--gold); }
.noma-badge.paid { background: rgba(15,110,86,0.1); border-color: #0F6E56; }
.noma-badge.paid span { color: #0F6E56; }
.noma-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border-bottom: 0.5px solid #d0d7e5; }
.noma-client-col { padding: 1.5rem 2.5rem; border-right: 0.5px solid #d0d7e5; }
.noma-client-col:last-child { border-right: none; }
.noma-label-sm { margin: 0 0 8px; font-size: 10px; font-weight: 600; color: #9ca3af; letter-spacing: 1.5px; text-transform: uppercase; }
.noma-client-name { margin: 0; font-size: 14px; font-weight: 600; color: #111827; }
.noma-client-det { margin: 2px 0; font-size: 12px; color: #4b5563; line-height: 1.5; }
.noma-ref-bar { padding: 0.8rem 2.5rem; background: #f9fafb; border-bottom: 0.5px solid #d0d7e5; display: flex; gap: 2rem; }
.noma-table-wrap { padding: 1.5rem 2.5rem; }
.noma-table { width: 100%; border-collapse: collapse; font-size: 12.5px; table-layout: fixed; }
.noma-table th { background: #1a2e4a; padding: 10px 12px; color: #fff; font-weight: 500; font-size: 11px; letter-spacing: 0.5px; }
.noma-table td { padding: 12px; border-bottom: 0.5px solid #e5e7eb; color: #111827; }
.noma-table tr:nth-child(even) { background: #f9fafb; }
.noma-table-desc { color: #111827; }
.noma-table-sub { font-size: 11px; color: #6b7280; display: block; margin-top: 2px; }
.noma-totals-wrap { display: flex; justify-content: flex-end; padding: 0 2.5rem 1.5rem; }
.noma-totals { width: 280px; }
.noma-tot-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 0.5px solid #e5e7eb; }
.noma-tot-lbl { font-size: 12px; color: #4b5563; }
.noma-tot-val { font-size: 12px; color: #111827; }
.noma-tot-acompte { color: #0F6E56; font-weight: 600; }
.noma-tot-final { display: flex; justify-content: space-between; padding: 10px 12px; background: #1a2e4a; border-radius: 6px; margin-top: 8px; }
.noma-tot-final span { font-size: 14px; font-weight: 700; color: #fff; }
.noma-cond { margin: 0 2.5rem 1.5rem; padding: 1rem 1.25rem; background: #f9fafb; border-left: 3px solid #1a2e4a; border-radius: 0 6px 6px 0; }
.noma-cond-lbl { margin: 0 0 6px; font-size: 11px; font-weight: 600; color: #9ca3af; text-transform: uppercase; letter-spacing: 1px; }
.noma-cond-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 2rem; }
.noma-cond-grid p { margin: 2px 0; font-size: 12px; color: #4b5563; }
.noma-footer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border-top: 0.5px solid #d0d7e5; }
.noma-notes-col { padding: 1.25rem 2.5rem; border-right: 0.5px solid #d0d7e5; }
.noma-notes-col:last-child { border-right: none; text-align: right; }
.noma-sig-space { height: 52px; border-bottom: 0.5px solid #d0d7e5; margin-bottom: 6px; }
.noma-footer-bar { padding: 0.8rem 2.5rem; background: #1a2e4a; text-align: center; }
.noma-footer-txt { margin: 0; font-size: 11px; color: rgba(255,255,255,0.6); letter-spacing: 0.5px; }

/* ══════════════════════════════════════════════════════
   PRINT STYLES
   ══════════════════════════════════════════════════════ */
@media print {
  *,*::before,*::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }
  .noma-doc { padding: 0 !important; max-width: 100% !important; box-shadow: none !important; margin: 0 !important; }
  .noma-doc-inner { border: none !important; border-radius: 0 !important; }
  .noma-header { border-bottom-color: #1a2e4a !important; }
  .noma-table th { background-color: #1a2e4a !important; color: white !important; }
  .noma-table tr:nth-child(even) { background-color: #f9fafb !important; }
  .noma-tot-final { background-color: #1a2e4a !important; }
  .noma-tot-final span { color: white !important; }
  .noma-cond { border-left-color: #1a2e4a !important; background-color: #f9fafb !important; }
  .noma-footer-bar { background-color: #1a2e4a !important; }
  .noma-footer-txt { color: rgba(255,255,255,0.6) !important; }
  .noma-badge { border: 0.5px solid #5DCAA5 !important; background-color: #e8f4f0 !important; }
  .noma-badge span { color: #0F6E56 !important; }
  .noma-badge.pending { border-color: var(--gold) !important; background-color: rgba(200,160,48,0.1) !important; }
  .noma-badge.pending span { color: var(--gold) !important; }
  .noma-badge.paid { border-color: #0F6E56 !important; background-color: rgba(15,110,86,0.1) !important; }
  .noma-badge.paid span { color: #0F6E56 !important; }

  html { font-size: 11px; }
  body {
    background: #fff !important;
    color: #000 !important;
    -webkit-font-smoothing: auto;
  }

  /* Hide everything except the document */
  .sidebar,
  .mobile-header,
  .sidebar-overlay,
  .page-header,
  .form-grid,
  .form-section,
  .items-section,
  .action-bar,
  .format-switcher,
  .lang-switcher,
  .period-bar,
  .kpi-grid,
  .chart-row,
  .toolbar,
  .search-bar,
  .btn,
  .btn-group,
  .doc-preview-label,
  #toast,
  #auth-screen,
  #pwa-install-btn,
  .sync-indicator,
  .sidebar-user,
  .nav-separator,
  .table-wrap,
  .modal-overlay,
  .doc-preview-wrap > *:not(#invoice):not(#invoice-f2):not(#devis-doc):not(#commande-doc) {
    display: none !important;
  }

  .main-content {
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding: 0 !important;
  }
  .page:not(.active) { display: none !important; }
  .page.active { display: block !important; }
  .page-body { padding: 0 !important; }
  .doc-preview-wrap { margin: 0 !important; }

  /* Document styles for print */
  #invoice,
  #invoice-f2,
  #devis-doc,
  #commande-doc {
    box-shadow: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
  }
  .noma-doc-inner { margin: 0 !important; padding: 0 !important; }
  .noma-table { page-break-inside: auto; }
  .noma-table tr { page-break-inside: avoid; }
  .inv-signatures { page-break-inside: avoid; }
  .inv-footer { page-break-inside: avoid; }

  @page {
    size: A4;
    margin: 10mm;
  }
  #sign-modal { display: none !important; }
  .btn-gold { display: none !important; }
}

/* ══ SIGNATURE ÉLECTRONIQUE ══ */
.btn-gold {
  background: linear-gradient(135deg, #c8a030, #e8c35a);
  color: #1a2e4a;
  border: none;
  font-weight: 700;
  letter-spacing: 0.5px;
  box-shadow: 0 2px 8px rgba(200,160,48,0.3);
  transition: all 0.2s ease;
}
.btn-gold:hover {
  background: linear-gradient(135deg, #e8c35a, #c8a030);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(200,160,48,0.45);
}

/* ══════════════════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
   ══════════════════════════════════════════════════════ */

/* ── Tablet (≤1024px) ── */
@media screen and (max-width: 1024px) {
  .chart-row {
    grid-template-columns: 1fr;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .form-row {
    grid-template-columns: 1fr;
  }
}

/* ── Mobile (≤768px) ── */
@media screen and (max-width: 768px) {
  :root {
    --sidebar-w: 260px;
  }

  /* Show mobile header */
  .mobile-header {
    display: flex;
  }

  /* Hide sidebar by default on mobile */
  .sidebar {
    transform: translateX(-100%);
    z-index: calc(var(--z-sticky) + 1);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.open {
    display: block;
  }
  [dir="rtl"] .sidebar {
    transform: translateX(100%);
  }
  [dir="rtl"] .sidebar.open {
    transform: translateX(0);
  }

  /* Main content full width */
  .main-content {
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-top: 56px;
  }
  [dir="rtl"] .main-content {
    margin-right: 0 !important;
  }

  .page-header {
    padding: var(--gap-md) var(--gap-md);
    top: 56px;
  }
  .page-header h1 { font-size: 1.2rem; }
  .page-body { padding: var(--gap-md); }

  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .kpi-value { font-size: 1.4rem; }

  .item-row {
    grid-template-columns: 1fr 60px 80px 34px;
    gap: 4px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .toolbar-left,
  .toolbar-right {
    flex-wrap: wrap;
  }

  .period-bar {
    flex-wrap: wrap;
    width: 100%;
  }

  .action-bar {
    flex-direction: column;
  }
  .action-bar .btn { width: 100%; }

  /* Document preview scroll */
  #invoice,
  #invoice-f2,
  #devis-doc,
  #commande-doc {
    padding: 24px;
    font-size: 11px;
    max-width: 100%;
    overflow-x: auto;
  }
  .inv-header { flex-direction: column; gap: 12px; }
  .doc-type-title { text-align: left; font-size: 22px; }
  .inv-meta { flex-direction: column; gap: 8px; }
  .inv-signatures { flex-direction: column; gap: 24px; }
  .inv-sig-block { width: 100%; }

  /* Auth */
  .auth-card {
    padding: var(--gap-lg) var(--gap-md);
  }

  /* Toast */
  #toast {
    left: 16px;
    right: 16px;
    bottom: 16px;
    max-width: 100%;
    text-align: center;
  }
}

/* ── Small mobile (≤480px) ── */
@media screen and (max-width: 480px) {
  html { font-size: 13px; }

  .auth-logo h1 { font-size: 1.6rem; }

  .kpi-card { padding: var(--gap-md); }
  .kpi-value { font-size: 1.2rem; }

  .item-row {
    grid-template-columns: 1fr;
    gap: var(--gap-sm);
  }
  .item-row input { width: 100%; }

  .btn { padding: 10px 16px; font-size: 0.82rem; }

  .inv-table { font-size: 10px; }
  .inv-table thead th { padding: 8px; font-size: 9px; }
  .inv-table tbody td { padding: 8px; }

  .modal {
    max-width: 100%;
    margin: var(--gap-sm);
    border-radius: var(--r-md);
  }

  .form-section {
    padding: var(--gap-md);
  }
}
