/* =====================================================
   SIGMA-TIC — Design System
   Direction: Indigo profond + accent ambre, sobre & moderne
   ===================================================== */

:root {
  /* Palette */
  --primary:        #1e1b4b;   /* indigo-950 profond */
  --primary-600:    #312e81;
  --primary-500:    #4338ca;
  --primary-400:    #6366f1;
  --primary-50:     #eef2ff;

  --accent:         #d97706;   /* ambre */
  --accent-light:   #fef3c7;

  --bg:             #f8fafc;
  --surface:        #ffffff;
  --surface-2:      #f1f5f9;
  --border:         #e2e8f0;
  --border-strong:  #cbd5e1;

  --text:           #0f172a;
  --text-muted:     #64748b;
  --text-light:     #94a3b8;

  --success:        #059669;
  --success-bg:     #d1fae5;
  --warning:        #d97706;
  --warning-bg:     #fef3c7;
  --danger:         #dc2626;
  --danger-bg:      #fee2e2;
  --info:           #2563eb;
  --info-bg:        #dbeafe;

  --shadow-sm:      0 1px 2px 0 rgb(15 23 42 / 0.05);
  --shadow:         0 1px 3px 0 rgb(15 23 42 / 0.06), 0 1px 2px -1px rgb(15 23 42 / 0.04);
  --shadow-md:      0 4px 6px -1px rgb(15 23 42 / 0.08), 0 2px 4px -2px rgb(15 23 42 / 0.04);
  --shadow-lg:      0 10px 25px -5px rgb(15 23 42 / 0.08), 0 8px 10px -6px rgb(15 23 42 / 0.04);

  --radius:         10px;
  --radius-lg:      14px;
  --radius-sm:      6px;

  --sidebar-width:  264px;

  /* Hiérarchie z-index — strict & cohérent */
  --z-topbar:       40;
  --z-sidebar:      60;
  --z-backdrop:     80;
  --z-sidebar-mobile: 90;
  --z-modal:        200;
}

/* Reset & base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Manrope', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1,h2,h3,h4,h5 {
  margin: 0 0 .5rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
}
h1 { font-size: 1.75rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.15rem; }

.serif { font-family: 'Fraunces', Georgia, serif; }

a { color: var(--primary-500); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =====================================================
   LAYOUT — Sidebar + Content
   ===================================================== */
.app { min-height: 100vh; display: flex; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--primary);
  color: #cbd5e1;
  padding: 1.5rem 0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  z-index: var(--z-sidebar);
  border-right: 1px solid rgba(0, 0, 0, 0.25);
  box-shadow: 1px 0 3px rgba(15, 23, 42, 0.08);
}

.sidebar-brand {
  padding: 0 1.5rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 1rem;
}
.sidebar-brand .logo {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.sidebar-brand .logo::before {
  content: '';
  display: inline-block;
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 8px;
  position: relative;
}
.sidebar-brand .slogan {
  font-size: .75rem;
  color: #a5b4fc;
  margin-top: .35rem;
  font-weight: 500;
}

.sidebar-nav { flex: 1; padding: 0 .75rem; }
.sidebar-section {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a5b4fc;
  padding: 1rem .75rem .35rem;
  font-weight: 600;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .65rem .75rem;
  color: #cbd5e1;
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
  font-weight: 500;
  font-size: .92rem;
  transition: background .15s, color .15s;
}
.sidebar-link:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
  text-decoration: none;
}
.sidebar-link.active {
  background: var(--primary-500);
  color: #fff;
}
.sidebar-link i {
  width: 18px; height: 18px;
  stroke-width: 2;
}

.sidebar-user {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  gap: .75rem;
}
.sidebar-user .avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
}
.sidebar-user .name { color: #fff; font-weight: 600; font-size: .85rem; }
.sidebar-user .role { color: #a5b4fc; font-size: .7rem; }
.sidebar-user a.logout-link {
  color: #a5b4fc;
  margin-left: auto;
}
.sidebar-user a.logout-link:hover { color: #fff; }

.main {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  min-height: 64px;
}
.topbar .page-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.topbar .page-subtitle {
  color: var(--text-muted);
  font-size: .85rem;
  margin-top: 2px;
}
.topbar-actions { display: flex; gap: .5rem; align-items: center; }

.content { padding: 2rem; max-width: 1400px; }

/* =====================================================
   CARDS
   ===================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.card-body { padding: 1.5rem; }
.card-body.no-padding { padding: 0; }

/* KPI cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--primary-500);
}
.kpi.kpi-amber::before { background: var(--accent); }
.kpi.kpi-green::before { background: var(--success); }
.kpi.kpi-red::before { background: var(--danger); }

.kpi .kpi-label {
  font-size: .8rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: .25rem;
}
.kpi .kpi-value {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}
.kpi .kpi-hint {
  font-size: .8rem;
  color: var(--text-light);
  margin-top: .25rem;
}

/* =====================================================
   FORMULAIRES
   ===================================================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem 1.25rem;
}
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-grid.cols-1 { grid-template-columns: 1fr; }
.form-grid .full { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; }
.field label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .35rem;
}
.field .hint { font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }
.field .required { color: var(--danger); }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=tel], input[type=date], input[type=search], textarea, select {
  width: 100%;
  font-family: inherit;
  font-size: .9rem;
  padding: .55rem .75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgb(67 56 202 / 0.12);
}
textarea { resize: vertical; min-height: 80px; }

select { cursor: pointer; }

/* =====================================================
   BOUTONS
   ===================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .55rem 1rem;
  font-family: inherit;
  font-size: .88rem;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: all .15s;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn i { width: 16px; height: 16px; stroke-width: 2.2; }

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

.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #b45309; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.btn-outline {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-outline:hover { background: var(--surface-2); border-color: var(--text-muted); }

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

.btn-sm { padding: .35rem .65rem; font-size: .8rem; }
.btn-lg { padding: .75rem 1.5rem; font-size: 1rem; }

/* =====================================================
   TABLEAUX
   ===================================================== */
.table-wrap { overflow-x: auto; }
table.table {
  width: 100%;
  border-collapse: collapse;
}
table.table th {
  text-align: left;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
  padding: .85rem 1.25rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.table td {
  padding: .9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
  vertical-align: middle;
}
table.table tbody tr:hover { background: var(--surface-2); }
table.table tbody tr:last-child td { border-bottom: none; }

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-light { color: var(--text-light); }
.font-mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: .85em; }
.font-bold { font-weight: 700; }
.text-strong { font-weight: 600; color: var(--text); }

/* =====================================================
   BADGES
   ===================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .22rem .55rem;
  font-size: .72rem;
  font-weight: 600;
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.badge-gray   { background: #f1f5f9; color: #475569; }
.badge-blue   { background: var(--info-bg); color: var(--info); }
.badge-green  { background: var(--success-bg); color: var(--success); }
.badge-red    { background: var(--danger-bg); color: var(--danger); }
.badge-amber  { background: var(--warning-bg); color: var(--warning); }
.badge-indigo { background: var(--primary-50); color: var(--primary-500); }

/* =====================================================
   ALERTES / FLASH
   ===================================================== */
.flash {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .85rem 1.1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-size: .9rem;
  border: 1px solid;
}
.flash-success { background: var(--success-bg); color: var(--success); border-color: #a7f3d0; }
.flash-error   { background: var(--danger-bg);  color: var(--danger);  border-color: #fecaca; }
.flash-info    { background: var(--info-bg);    color: var(--info);    border-color: #bfdbfe; }
.flash-warning { background: var(--warning-bg); color: var(--warning); border-color: #fde68a; }

/* =====================================================
   AUTH PAGE (login)
   ===================================================== */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
}
.auth-aside {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-500) 100%);
  color: #fff;
  padding: 3rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.auth-aside::after {
  content: '';
  position: absolute;
  inset: auto -100px -100px auto;
  width: 400px; height: 400px;
  background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
  opacity: 0.25;
  border-radius: 50%;
}
.auth-aside .brand {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 2.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}
.auth-aside .brand-sub {
  color: #a5b4fc;
  font-size: 1rem;
  margin-top: .25rem;
}
.auth-aside .pitch {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.9rem;
  font-weight: 400;
  line-height: 1.25;
  letter-spacing: -0.02em;
  position: relative;
  z-index: 2;
  max-width: 460px;
}
.auth-aside .pitch em {
  font-style: italic;
  color: var(--accent-light);
}
.auth-aside .credits {
  color: #a5b4fc;
  font-size: .85rem;
  position: relative;
  z-index: 2;
}

.auth-form-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
}
.auth-form {
  width: 100%;
  max-width: 380px;
}
.auth-form h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 2rem;
  font-weight: 600;
  margin-bottom: .25rem;
}
.auth-form p.lead {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

@media (max-width: 900px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
}

/* =====================================================
   DIVERS
   ===================================================== */
.row-actions { display: flex; gap: .35rem; }

.empty-state {
  padding: 4rem 2rem;
  text-align: center;
  color: var(--text-muted);
}
.empty-state i {
  width: 48px; height: 48px;
  color: var(--text-light);
  margin-bottom: 1rem;
}
.empty-state h3 { color: var(--text); margin-bottom: .35rem; }
.empty-state p { margin: 0 0 1rem; }

.divider { height: 1px; background: var(--border); margin: 1.5rem 0; }

.search-bar {
  display: flex;
  gap: .5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.search-bar input { max-width: 320px; }

.page-actions {
  display: flex;
  gap: .5rem;
  align-items: center;
  flex-wrap: wrap;
}

/* Lignes dynamiques (formulaire document) */
.lines-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}
.lines-table th {
  text-align: left;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 700;
  padding: .65rem .5rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.lines-table td {
  padding: .35rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.lines-table input, .lines-table textarea {
  padding: .4rem .55rem;
  font-size: .85rem;
}
.lines-table .total-cell {
  text-align: right;
  font-weight: 700;
  color: var(--text);
  padding-top: .8rem;
  font-family: 'JetBrains Mono', monospace;
}
.lines-table .remove-line {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  padding: .4rem;
  border-radius: var(--radius-sm);
}
.lines-table .remove-line:hover { color: var(--danger); background: var(--danger-bg); }

.totals-box {
  margin-left: auto;
  width: 320px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
}
.totals-box .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .35rem 0;
  font-size: .9rem;
}
.totals-box .row.total {
  border-top: 1px solid var(--border-strong);
  margin-top: .35rem;
  padding-top: .65rem;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--primary);
}

/* =====================================================
   PRINT (factures imprimables)
   ===================================================== */
@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main { margin-left: 0; }
  .content { padding: 0; max-width: 100%; }
  body { background: #fff; }
  .card { border: none; box-shadow: none; }
}

/* =====================================================
   MENU UTILISATEUR (dropdown topbar)
   ===================================================== */
.user-menu {
  position: relative;
  flex-shrink: 0;
}
.user-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  padding: .35rem .55rem .35rem .35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
}
.user-menu-btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.user-menu-btn.active {
  border-color: var(--primary-400);
  background: var(--primary-50);
}
.user-menu-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .82rem;
  flex-shrink: 0;
}
.user-menu-info { text-align: left; min-width: 0; }
.user-menu-name {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.user-menu-role {
  font-size: .68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}
.user-menu-caret {
  width: 16px; height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform .15s;
}
.user-menu-btn.active .user-menu-caret { transform: rotate(180deg); }

.user-menu-dropdown {
  position: absolute;
  top: calc(100% + .5rem);
  right: 0;
  min-width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: .35rem;
  z-index: calc(var(--z-topbar) + 5);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity .15s, transform .15s, visibility .15s;
}
.user-menu-dropdown.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.user-menu-header {
  padding: .65rem .85rem .75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: .35rem;
}
.user-menu-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .55rem .75rem;
  color: var(--text);
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-size: .88rem;
  transition: background .12s;
}
.user-menu-item:hover {
  background: var(--surface-2);
  text-decoration: none;
}
.user-menu-item i {
  width: 18px; height: 18px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.user-menu-item-title { font-weight: 600; }
.user-menu-item-sub { font-size: .72rem; color: var(--text-muted); margin-top: 1px; }
.user-menu-item-danger { color: var(--danger); }
.user-menu-item-danger:hover { background: var(--danger-bg); }
.user-menu-item-danger i { color: var(--danger); }

.user-menu-divider {
  height: 1px;
  background: var(--border);
  margin: .35rem 0;
}

/* Sur mobile, masquer le texte du bouton (garde juste avatar + chevron) */
@media (max-width: 700px) {
  .user-menu-info { display: none; }
  .user-menu-btn { padding: .25rem .4rem .25rem .25rem; }
  .user-menu-dropdown { min-width: 240px; }
}
.sidebar-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: .5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--surface-2); }
.sidebar-toggle i { width: 20px; height: 20px; }

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  z-index: var(--z-backdrop);
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s ease, visibility .25s ease;
}
.sidebar-backdrop.open {
  opacity: 1;
  visibility: visible;
}

/* Empêcher le scroll du body quand la sidebar est ouverte */
body.sidebar-open { overflow: hidden; }

/* Modal au-dessus de tout */
.modal-backdrop { z-index: var(--z-modal); }

/* =====================================================
   RESPONSIVE
   ===================================================== */

/* Tablette : sidebar plus étroite */
@media (max-width: 1100px) {
  :root { --sidebar-width: 230px; }
  .content { padding: 1.5rem; }
  .topbar { padding: 1rem 1.5rem; }
}

/* Mobile : sidebar en off-canvas + hamburger */
@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: var(--z-sidebar-mobile);
    width: 280px;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.35);
    border-right: none;
  }
  .sidebar.open { transform: translateX(0); }

  .main {
    margin-left: 0;
    /* S'assurer que le main occupe toute la largeur sans se cacher sous la sidebar */
    width: 100%;
    min-height: 100vh;
  }

  .sidebar-toggle { display: inline-flex; }

  .topbar {
    padding: .8rem 1rem;
    gap: .75rem;
    min-height: 56px;
  }
  .topbar > div:first-child { flex: 1; min-width: 0; }
  .topbar .page-title {
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar .page-subtitle {
    font-size: .75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .topbar-actions { flex-shrink: 0; }
  .topbar-actions .btn { padding: .45rem .75rem; font-size: .82rem; }

  .content { padding: 1rem; }

  .kpi-grid { gap: .75rem; }
  .kpi { padding: 1rem; }
  .kpi .kpi-value { font-size: 1.4rem; }

  .form-grid,
  .form-grid.cols-3 { grid-template-columns: 1fr; gap: .75rem; }

  .card-header {
    padding: .9rem 1rem;
    flex-wrap: wrap;
    gap: .5rem;
  }
  .card-header > div:last-child { flex-wrap: wrap; }
  .card-body { padding: 1rem; }

  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.2rem; }
  h3 { font-size: 1rem; }

  /* Tableaux : scroll horizontal naturel */
  .table-wrap { 
    overflow-x: auto; 
    -webkit-overflow-scrolling: touch;
    margin: 0 -1rem;
  }
  .table-wrap table { min-width: 600px; }
  table.table th, table.table td {
    padding: .7rem .85rem;
    font-size: .82rem;
  }
  table.table th { font-size: .65rem; }

  /* Recherche */
  .search-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .search-bar input,
  .search-bar select {
    max-width: 100%;
    width: 100%;
  }

  /* Lignes du document : scroll horizontal forcé */
  .lines-table {
    min-width: 700px;
  }

  /* Totaux : pleine largeur sur mobile */
  .totals-box {
    width: 100% !important;
    margin-left: 0 !important;
  }
  .totals-box .row.total { font-size: 1.1rem; }

  /* Modal pleine largeur sur petit écran */
  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal {
    max-width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
  }

  /* Row actions plus compactes */
  .row-actions { gap: .15rem; }
  .row-actions .btn { padding: .3rem; }

  /* Buttons */
  .btn-lg { padding: .65rem 1.1rem; font-size: .9rem; }

  /* Empty states */
  .empty-state { padding: 2.5rem 1rem; }

  /* Page actions wrap */
  .page-actions { width: 100%; justify-content: stretch; }
  .page-actions .btn { flex: 1; justify-content: center; }
}

/* Très petit (smartphone < 500px) */
@media (max-width: 500px) {
  .topbar { gap: .35rem; padding: .65rem .75rem; }
  .topbar .page-subtitle { display: none; }
  .topbar .page-title { font-size: .95rem; }
  .topbar-actions .btn { padding: .45rem .65rem; font-size: .78rem; }
  .topbar-actions .btn i { width: 14px; height: 14px; }

  .kpi-grid { grid-template-columns: 1fr; }
  
  .card-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .card-header > div:last-child { width: 100%; }

  /* Auth page */
  .auth-form-wrap { padding: 1.5rem 1rem; }
  .auth-form h1 { font-size: 1.6rem; }

  /* Sidebar adaptative */
  .sidebar { width: calc(100vw - 60px); max-width: 280px; }

  /* Boutons largeur 100% dans card-header sur très petit */
  .card-header > div:last-child > .btn,
  .card-header > div:last-child > a.btn { width: 100%; justify-content: center; }
}

/* =====================================================
   MODAL (catalogue, etc.)
   ===================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  z-index: var(--z-modal);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 6vh;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 760px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { margin: 0; font-family: 'Fraunces', Georgia, serif; font-size: 1.2rem; }
.modal-close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: .4rem;
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

.modal-body {
  padding: 1rem 1.5rem;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-2);
}

.catalog-item {
  display: flex;
  align-items: center;
  gap: .8rem;
  padding: .8rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: .5rem;
  cursor: pointer;
  transition: all .15s;
}
.catalog-item:hover {
  border-color: var(--primary-400);
  background: var(--primary-50);
}
.catalog-item input[type="checkbox"] {
  width: 18px; height: 18px;
  cursor: pointer;
}
.catalog-item .ci-main { flex: 1; }
.catalog-item .ci-name {
  font-weight: 600;
  color: var(--text);
}
.catalog-item .ci-desc {
  color: var(--text-muted);
  font-size: .8rem;
  margin-top: .1rem;
}
.catalog-item .ci-price {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
}
.catalog-item .ci-meta {
  color: var(--text-light);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
}
