/* ─── Rendu des polices ─── */
* {
  -webkit-font-smoothing: subpixel-antialiased; }

/* Empêcher le faux gras sur la police monospace */
*[style*="font-mono"] {
  font-weight: 500 !important;
  }

/* ============================================================
   layout.css — Structure app : sidebar + topbar + contenu
   ============================================================ */

/* ─── App layout ─── */
.app-layout {
  display: block;
  min-height: 100vh;
  background: var(--bg);
}

/* ════════════════════════════════════
   SIDEBAR
════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  background: #0f172a;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Logo */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}

.sidebar-logo-icon {
  width: 34px; height: 34px;
  background: rgba(37,99,235,.3);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}

.sidebar-logo-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  flex: 1;
}

.sidebar-close {
  display: none;
  background: none; border: none;
  color: rgba(255,255,255,.4);
  font-size: 16px; cursor: pointer;
  padding: 4px;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section {
  margin-bottom: 8px;
}

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(255,255,255,.25);
  padding: 12px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  color: rgba(255,255,255,.6);
  text-decoration: none;
  transition: all .15s;
  position: relative;
}

.nav-item:hover {
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.9);
  text-decoration: none;
}

.nav-item.active {
  background: rgba(37,99,235,.25);
  color: #93c5fd;
}

.nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 20px;
  min-width: 20px;
  text-align: center;
}

.nav-badge-orange { background: var(--orange); }
.nav-badge-red    { background: var(--red); }

/* Footer sidebar */
.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  text-decoration: none;
  min-width: 0;
}

.sidebar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: rgba(37,99,235,.4);
  color: #93c5fd;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-user-info { min-width: 0; }

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 11px;
  color: rgba(255,255,255,.35);
  white-space: nowrap;
}

.sidebar-logout {
  background: none; border: none;
  color: rgba(255,255,255,.3);
  font-size: 18px; cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: all .15s;
  flex-shrink: 0;
}

.sidebar-logout:hover {
  color: #f87171;
  background: rgba(248,113,113,.1);
}

/* Overlay mobile */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 99;
  backdrop-filter: blur(2px);
}

/* ════════════════════════════════════
   MAIN WRAP
════════════════════════════════════ */
.main-wrap {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-x: hidden;
}

/* ════════════════════════════════════
   TOPBAR
════════════════════════════════════ */
.topbar {
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-menu-btn {
  display: none;
  background: none; border: none;
  font-size: 20px; cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Timer actif */
.topbar-timer {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--green-bg);
  border: 1px solid #bbf7d0;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  color: var(--green);
}

.timer-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.5s infinite;
}

.timer-ref {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(1.2); }
}

/* Bouton topbar */
.topbar-btn {
  position: relative;
  background: none; border: none;
  width: 38px; height: 38px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: background .15s;
}

.topbar-btn:hover { background: var(--surface2); }

.notif-dot {
  position: absolute;
  top: 3px; right: 3px;
  background: var(--red);
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px; height: 16px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 3px;
  border: 2px solid var(--surface);
}

/* Avatar topbar */
.topbar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: opacity .15s;
}

.topbar-avatar:hover { opacity: .85; }

/* ─── Dropdown notifications ─── */
.notif-wrap, .user-menu-wrap { position: relative; }

.notif-dropdown, .user-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
  z-index: 200;
}

.notif-dropdown { width: 340px; }
.user-dropdown  { width: 220px; }

.notif-dropdown.open, .user-dropdown.open { display: block; }

.notif-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px 10px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.notif-list { max-height: 320px; overflow-y: auto; }

.notif-item {
  display: flex; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: background .15s;
}

.notif-item:hover { background: var(--surface2); }
.notif-item.unread { background: var(--blue-bg); }

.notif-item-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}

.notif-item-text { min-width: 0; }

.notif-item-title {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.notif-item-time { font-size: 11px; color: var(--text-light); }

.notif-empty, .notif-loading {
  padding: 24px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.notif-footer {
  padding: 10px 16px;
  text-align: center;
  border-top: 1px solid var(--border);
  font-size: 13px;
}

.user-dropdown-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.user-dropdown-header strong {
  display: block;
  font-size: 13px;
}

.user-dropdown-header span {
  font-size: 12px;
  color: var(--text-muted);
}

.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
  transition: background .15s;
}

.user-dropdown-item:hover { background: var(--surface2); text-decoration: none; }

/* ════════════════════════════════════
   CONTENU PRINCIPAL
════════════════════════════════════ */
.main-content {
  flex: 1;
  padding: 24px 28px;
  max-width: none;
  width: 100%;
}

/* ─── Page header ─── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

.page-header-left h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
  margin-bottom: 4px;
}

.page-header-left p {
  color: var(--text-muted);
  font-size: 14px;
}

.page-header-actions {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}

/* ─── Stat cards ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color .15s, box-shadow .15s;
}

.stat-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}

.stat-card-header {
  display: flex; justify-content: space-between; align-items: center;
}

.stat-card-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.stat-card-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}

.icon-blue   { background: var(--blue-bg); }
.icon-green  { background: var(--green-bg); }
.icon-orange { background: var(--orange-bg); }
.icon-red    { background: var(--red-bg); }
.icon-purple { background: var(--purple-bg); }

.stat-card-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1;
}

.stat-card-sub {
  font-size: 12px;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 4px;
}

.trend-up   { color: var(--green); }
.trend-down { color: var(--red); }

/* ─── Cards universelles ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
}

.card-body { padding: 20px; }

.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface2);
  font-size: 13px;
}

/* ─── Dashboard grid ─── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 20px;
}

.dashboard-grid-full { grid-column: 1 / -1; }

/* ─── Tables ─── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  padding: 8px 10px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  -webkit-font-smoothing: subpixel-antialiased; }

.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
  -webkit-font-smoothing: subpixel-antialiased; }

/* Cellules qui peuvent wrapper (libellés longs) */
.data-table td.wrap,
.data-table td:first-child {
  white-space: normal;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Montants — toujours sur une ligne */
.data-table td.amount,
.data-table td[style*="font-mono"],
.data-table td[style*="monospace"] {
  white-space: nowrap;
  font-weight: 500 !important;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tbody tr:hover { background: var(--surface2); }

/* ─── Workflow steps ─── */
.workflow-steps {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.workflow-step {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.workflow-step:last-child { border-bottom: none; }

.wf-bullet {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  flex-shrink: 0;
}

.wf-done    { background: var(--green-bg);  color: var(--green); }
.wf-active  { background: var(--blue-bg);   color: var(--primary); }
.wf-pending { background: var(--surface2);  color: var(--text-muted); }
.wf-blocked { background: var(--red-bg);    color: var(--red); }

.wf-name { font-size: 13px; font-weight: 500; flex: 1; }
.wf-meta { font-size: 11px; color: var(--text-muted); }

/* ─── Timeline notifications ─── */
.timeline { display: flex; flex-direction: column; }

.timeline-item {
  display: flex; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.timeline-item:last-child { border-bottom: none; }

.timeline-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; flex-shrink: 0;
}

.timeline-body { min-width: 0; }

.timeline-title {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.timeline-sub { font-size: 12px; color: var(--text-muted); }

/* ─── Empty state ─── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state h3 { font-size: 15px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.empty-state p  { font-size: 13px; }

/* ─── Filtres ─── */
.filters-bar {
  display: flex; gap: 10px; align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-input {
  height: 38px; padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}

.filter-input:focus { border-color: var(--primary); }

/* ─── Responsive ─── */
@media (max-width: 1024px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-close { display: block; }
  .sidebar-overlay.open { display: block; }
  .main-wrap { margin-left: 0; max-width: 100%; }
  .topbar-menu-btn { display: flex; }
  .main-content { padding: 20px 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .page-header { flex-direction: column; }
  .topbar-title { font-size: 14px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .main-content { padding: 16px 12px; }
}
/* ════════════════════════════════════════════════
   RESPONSIVE MOBILE — améliorations
   ════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Empêche la page entière de déborder horizontalement */
  .main-content { overflow-x: hidden; padding: 16px 12px; }

  /* Tables larges : deviennent scrollables horizontalement (sans casser la mise en page) */
  .data-table,
  .balance-table,
  .line-table,
  .lite-table,
  .lines-table {
    display: block;
    width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .data-table th, .data-table td,
  .balance-table th, .balance-table td {
    padding: 8px 10px;
    font-size: 12px;
  }

  /* En-tête de page : titre puis boutons en pleine largeur, qui s'enroulent */
  .page-header { flex-direction: column; align-items: stretch; gap: 12px; }
  .page-header-actions { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
  .page-header-actions .btn { flex: 1 1 auto; justify-content: center; white-space: nowrap; }
  .page-header h1 { font-size: 20px; }

  /* Formulaires multi-colonnes -> une seule colonne */
  .form-row { display: grid !important; grid-template-columns: 1fr !important; gap: 12px; }
  .pc-grid  { grid-template-columns: 1fr !important; }

  /* Topbar compacte */
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-title { font-size: 14px; }
  .topbar-actions { gap: 6px; }
  .dossier-badge { margin-left: 6px; gap: 6px; }
  .dossier-badge-pill { max-width: 48vw; font-size: 12px; padding: 5px 10px; }

  /* Cibles tactiles + lisibilité */
  .btn { min-height: 42px; }
  .card { border-radius: 10px; }
  .filter-input, .form-control { font-size: 16px; } /* évite le zoom auto iOS */
}

/* En mode dossier sur petit écran, le badge suffit : on masque le titre redondant */
@media (max-width: 600px) {
  .topbar:has(.dossier-badge) .topbar-title { display: none; }
  .dossier-badge-pill { max-width: 56vw; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .main-content { padding: 14px 10px; }
  .page-header-actions .btn { font-size: 13px; padding: 8px 10px; }
}

/* ─── Conteneur scrollable pour tableaux larges (anti-débordement) ─── */
.table-wrap { width:100%; max-width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
.table-wrap .data-table { margin:0; }

/* responsive sidebar 14" : sidebar plus fine -> plus de place au contenu */
@media (max-width: 1366px) { :root { --sidebar-w: 220px; } }
@media (max-width: 1100px) { :root { --sidebar-w: 200px; } }

/* ─── Visionneuse fiche facture : responsive ─── */
.fv-doc-layout { display:grid; grid-template-columns: minmax(0,65fr) minmax(0,35fr); gap:24px; align-items:start; }
.fv-pdf-mobile { display:none; }
@media (max-width: 1100px) {
  .fv-doc-layout { grid-template-columns: 1fr; }
  .fv-doc-layout > .card[style*="sticky"] { position: static !important; }
}
@media (max-width: 820px) {
  .fv-pdf-embed { display:none; }
  .fv-pdf-mobile { display:block; }
}
