:root {
  color-scheme: light;
  --bg: #f9fafb;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --muted-2: #9ca3af;
  --line: #e5e7eb;
  --line-soft: #f3f4f6;
  --header: #f9fafb;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --accent-soft: #eff6ff;
  --accent-border: #93c5fd;
  --danger: #c81e1e;
  --danger-soft: #fdf2f2;
  --positive: #057a55;
  --positive-soft: #f0fdf4;
  --warning: #9f580a;
  --warning-soft: #fdf6e3;
  --neutral-soft: #f3f4f6;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
  --shadow-soft: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --sidebar-bg: #111827;
  --sidebar-bg-active: #1f2a3d;
  --sidebar-ink: #d1d5db;
  --sidebar-ink-muted: #9ca3af;
  --sidebar-line: rgba(255, 255, 255, 0.08);
  --sidebar-width: 256px;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #0f172a, #1e293b);
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.28);
}

.login-card h1 {
  color: var(--ink);
}

.login-card p,
.login-card small {
  color: var(--muted);
}

h1 {
  margin: 0 0 4px;
  font-size: 25px;
  letter-spacing: 0;
}

p {
  margin: 0;
  color: var(--muted);
}

.app-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  color: var(--sidebar-ink);
  padding: 18px 12px;
  gap: 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 14px;
  border-bottom: 1px solid var(--sidebar-line);
  margin-bottom: 4px;
}

.sidebar-brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  flex: none;
}

.sidebar-brand-text {
  display: grid;
  line-height: 1.25;
}

.sidebar-brand-text strong {
  color: #fff;
  font-size: 15px;
}

.sidebar-brand-text span {
  color: var(--sidebar-ink-muted);
  font-size: 11px;
}

.main-content {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 14px 30px;
  background: var(--panel);
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}

.topbar-title-group {
  display: grid;
  gap: 2px;
  min-width: 0;
}

#pageTitle {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  color: var(--ink);
}

.topbar-subtitle {
  color: var(--muted);
  font-size: 13px;
}

.import-box {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-user {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--sidebar-line);
}

.user-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-box span {
  color: var(--sidebar-ink);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.user-box .secondary-button {
  padding: 8px 10px;
  background: transparent;
  color: var(--sidebar-ink);
  border: 1px solid var(--sidebar-line);
}

.user-box .secondary-button:hover {
  background: rgba(255, 255, 255, 0.06);
}

.admin-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 10px;
  border-top: 1px solid var(--sidebar-line);
  border-bottom: 1px solid var(--sidebar-line);
}

.admin-bar strong {
  display: block;
  color: #fff;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.admin-bar span {
  color: var(--sidebar-ink-muted);
  font-size: 11px;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.admin-actions button {
  padding: 7px 10px;
  border: 1px solid var(--sidebar-line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--sidebar-ink);
  box-shadow: none;
  font-size: 12px;
}

.admin-actions button:hover {
  background: var(--accent);
  color: #fff;
  filter: none;
}

input,
button {
  font: inherit;
}

input[type="file"],
input[type="search"],
select {
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  padding: 9px 10px;
  background: #f9fafb;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input[type="search"]:hover,
select:hover {
  border-color: #9ca3af;
}

button {
  border: 0;
  border-radius: var(--radius);
  padding: 10px 18px;
  background: var(--accent-2);
  color: #fff;
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  box-shadow: none;
  transition: background-color 0.12s ease, box-shadow 0.12s ease;
}

button:hover {
  background: #1e40af;
  filter: none;
  transform: none;
  box-shadow: none;
}

button:active {
  transform: none;
  background: #1e3a8a;
}

button:disabled {
  cursor: not-allowed;
  filter: none;
  transform: none;
  opacity: 0.55;
  box-shadow: none;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.25);
  border-color: var(--accent);
}

main {
  padding: 20px 30px 30px;
  flex: 1 1 auto;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

/* Les 4 indicateurs globaux du haut de page sont masques dans ces vues ; seul le bandeau direct
   de <main> est vise (les cartes propres a chaque vue, dans #managementView, restent visibles). */
body[data-view="compta"] main > .kpis,
body[data-view="tablem"] main > .kpis,
body[data-view="rapportdetaille"] main > .kpis {
  display: none;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow-soft);
}

.stat-card-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  flex: none;
}

.stat-card-icon svg {
  width: 20px;
  height: 20px;
}

.stat-card-icon-accent {
  background: var(--accent-soft);
  color: var(--accent-2);
}

.stat-card-icon-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.stat-card-icon-positive {
  background: var(--positive-soft);
  color: var(--positive);
}

.stat-card-icon-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.stat-card-body {
  min-width: 0;
}

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

.stat-card-value {
  display: block;
  margin-top: 3px;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-positive {
  background: var(--positive-soft);
  color: var(--positive);
}

.badge-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-neutral {
  background: var(--neutral-soft);
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-x: visible;
  padding: 0;
}

.tab {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 8px;
  background: transparent;
  color: var(--sidebar-ink);
  padding: 10px 12px;
  min-width: 0;
  position: relative;
  box-shadow: none;
  font-weight: 500;
  text-align: left;
  justify-content: flex-start;
}

.tab:hover {
  background: rgba(255, 255, 255, 0.06);
  filter: none;
}

.tab.active {
  background: var(--sidebar-bg-active);
  color: #fff;
  box-shadow: none;
}

.tab.active::after {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 999px;
  background: var(--accent);
}

.tab-icon {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--sidebar-ink-muted);
}

.tab.active .tab-icon {
  color: #fff;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

body[data-view="accueil"] .toolbar,
body[data-view="saisie"] .toolbar,
body[data-view="gestion"] .toolbar,
body[data-view="rapports"] .toolbar,
body[data-view="recettesGestion"] .toolbar,
body[data-view="chargesGestion"] .toolbar,
body[data-view="receptionGestion"] .toolbar,
body[data-view="alertes"] .toolbar,
body[data-view="donnees"] .toolbar,
body[data-view="rh"] .toolbar,
body[data-view="compta"] .toolbar,
body[data-view="creances"] .toolbar,
body[data-view="devis"] .toolbar,
body[data-view="direction"] .toolbar,
body[data-view="tablem"] .toolbar,
body[data-view="rapportdetaille"] .toolbar,
body[data-view="parametres"] .toolbar {
  display: none;
}

#search {
  width: min(520px, 100%);
}

.data-date-filters {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.data-date-filters label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.8rem;
}

.data-date-filters input {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
}

#sourceSheet {
  min-width: min(480px, 100%);
}

#rowCount {
  color: var(--muted);
  white-space: nowrap;
}

.sheet-wrap {
  min-height: 160px;
  max-height: calc(100vh - 190px);
  overflow: auto;
  background: #fbfcfe;
}

body[data-view="accueil"] .sheet-wrap,
body[data-view="saisie"] .sheet-wrap,
body[data-view="gestion"] .sheet-wrap,
body[data-view="rapports"] .sheet-wrap,
body[data-view="alertes"] .sheet-wrap,
body[data-view="donnees"] .sheet-wrap,
body[data-view="rh"] .sheet-wrap,
body[data-view="compta"] .sheet-wrap,
body[data-view="creances"] .sheet-wrap,
body[data-view="devis"] .sheet-wrap,
body[data-view="direction"] .sheet-wrap,
body[data-view="tablem"] .sheet-wrap,
body[data-view="rapportdetaille"] .sheet-wrap,
body[data-view="parametres"] .sheet-wrap {
  max-height: none;
  overflow: visible;
}

.management {
  display: none;
  padding: 18px;
}

.management.active {
  display: block;
}

.home-layout {
  display: grid;
  gap: 18px;
}

.home-hero {
  display: grid;
  grid-template-columns: minmax(280px, 1.4fr) minmax(260px, 0.8fr);
  gap: 14px;
}

.home-section {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.home-section header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.home-section h2,
.home-section h3 {
  margin: 0;
  font-size: 17px;
  color: #111827;
}

.home-section p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.steps {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.step {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: start;
}

.step-number {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.step strong {
  display: block;
  margin-bottom: 2px;
}

.step span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 14px;
  padding: 16px;
}

.module-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: #fbfcfe;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.module-card:hover {
  border-color: #c5d3e3;
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}

.module-card h3 {
  margin-bottom: 6px;
}

.module-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.module-card button + button {
  margin-left: 6px;
}

.module-grid.compact {
  grid-template-columns: 1fr;
}

.admin-status .status-pill strong {
  font-size: 16px;
  overflow-wrap: anywhere;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 18px;
}

.secondary-button {
  background: #fff;
  color: #374151;
  border: 1px solid #d1d5db;
  font-weight: 500;
}

.secondary-button:hover {
  background: #f9fafb;
}

.report-page {
  display: grid;
  gap: 14px;
}

.report-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.report-head h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.report-head p {
  color: var(--muted);
  font-size: 13px;
}

.period-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.report-filters {
  display: grid;
  justify-items: end;
  gap: 10px;
}

.period-switcher button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  box-shadow: none;
}

.period-switcher button.active {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-2);
}

.period-switcher button:hover {
  background: #f8fafc;
  filter: none;
}

.period-switcher button.active:hover {
  background: var(--accent-soft);
  color: var(--accent-2);
}

.date-filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  align-items: end;
}

.date-filters label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.date-filters input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 9px;
  font: inherit;
  color: var(--ink);
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 14px;
}

.chart-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.chart-card.wide {
  grid-column: 1 / -1;
}

.chart-card h3 {
  margin: 0;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  font-size: 15px;
  color: #111827;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  padding: 16px;
}

.metric-tile {
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fff;
  padding: 13px;
  display: grid;
  align-content: space-between;
  gap: 10px;
}

.metric-tile span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.metric-tile strong {
  color: var(--ink);
  font-size: 19px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.bar-chart {
  display: grid;
  gap: 9px;
  padding: 14px;
}

.bar-row {
  display: grid;
  grid-template-columns: 120px 1fr 110px;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: #edf2f7;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: var(--w);
  border-radius: inherit;
  background: var(--accent-2);
}

.bar-fill.alt {
  background: #0d9488;
}

.bar-fill.negative {
  background: var(--danger);
}

.bar-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #374151;
}

.export-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-2);
  font-weight: 700;
  text-decoration: none;
}

.empty-state {
  padding: 22px;
  color: var(--muted);
  font-size: 13px;
  background: #fbfcfe;
}

.grid-dashboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 14px;
}

.management-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.management-card.wide {
  grid-column: 1 / -1;
}

.management-card h2 {
  margin: 0;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  font-size: 15px;
}

.mini-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.mini-table th,
.mini-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.mini-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #6b7280;
  background: var(--header);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line);
}

.mini-table tr:hover td {
  background: #f9fafb;
}

.mini-table tbody tr:last-child td {
  border-bottom: 0;
}

.mini-table td:last-child,
.mini-table th:last-child {
  text-align: right;
}

.status-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
  padding: 16px 18px;
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 13px;
  background: #fff;
}

.status-pill span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.status-pill strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.entry-page {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  padding: 8px 0;
}

.entry-menu {
  position: sticky;
  top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcfe;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.entry-menu header {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.entry-menu h2 {
  margin: 0 0 5px;
  font-size: 17px;
}

.entry-menu p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.entry-switcher {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.entry-switcher button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 13px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  box-shadow: none;
}

.entry-switcher button span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.entry-switcher button.active {
  background: var(--accent-soft);
  color: var(--accent-2);
  border-color: var(--accent-border);
}

body[data-role]:not([data-role="admin"]) .admin-only {
  display: none;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 14px;
}

.settings-page {
  display: grid;
  gap: 14px;
}

.subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px;
  background: var(--header);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.subnav button {
  background: transparent;
  color: var(--muted);
  box-shadow: none;
  padding: 8px 14px;
  font-size: 13px;
}

.subnav button:hover {
  background: #fff;
  color: var(--ink);
  transform: none;
  box-shadow: var(--shadow-soft);
}

.subnav button.active {
  background: #fff;
  color: var(--accent-2);
  box-shadow: var(--shadow-soft);
}

.sheet tbody tr {
  cursor: pointer;
}

.settings-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.settings-card.wide {
  grid-column: 1 / -1;
}

.settings-intro {
  padding-bottom: 10px;
}

.settings-intro p {
  padding: 0 16px 6px;
  color: var(--muted);
  font-size: 13px;
}

.settings-card h2 {
  margin: 0;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  font-size: 15px;
}

.settings-card form {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.settings-inline-form {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  align-items: end;
}

.settings-inline-form .full {
  grid-column: 1 / -1;
}

.settings-form-section {
  display: grid;
  gap: 3px;
  margin-top: 4px;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: #f7fafb;
}

.settings-form-section strong {
  font-size: 13px;
}

.settings-form-section span {
  color: var(--muted);
  font-size: 12px;
}

.user-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.checkbox-field label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.checkbox-field label:has(input:checked) {
  border-color: var(--accent-border);
  background: var(--accent-soft);
}

.checkbox-field label:has(input:disabled) {
  opacity: 0.55;
}

.planning-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.planning-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 14px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.planning-table select {
  width: 100%;
  min-width: 140px;
}

.settings-list {
  margin: 14px 14px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.settings-list:last-child {
  margin-bottom: 14px;
}

.settings-list h3 {
  margin: 0;
  padding: 12px 14px;
  color: #374151;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--header);
  border-bottom: 1px solid var(--line);
}

.settings-toggle {
  padding: 7px 9px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  box-shadow: none;
}

.row-actions {
  min-width: 180px;
  white-space: nowrap;
}

.row-actions button,
.password-reset {
  margin: 2px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  box-shadow: none;
}

.danger-button {
  border-color: #f3b4ae !important;
  color: var(--danger) !important;
}

.edit-dialog {
  width: min(860px, calc(100vw - 28px));
  height: min(760px, calc(100dvh - 28px));
  max-height: calc(100dvh - 28px);
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  box-shadow: 0 30px 80px rgba(16, 24, 40, 0.3);
  overflow: hidden;
}

.edit-dialog::backdrop {
  background: rgba(15, 23, 42, 0.62);
}

.edit-dialog-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100%;
  max-height: calc(100dvh - 28px);
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.edit-dialog-card > header,
.edit-dialog-card > footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 18px;
  background: #f8fafc;
}

.edit-dialog-card > header {
  border-bottom: 1px solid var(--line);
}

.edit-dialog-card > footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
}

.edit-dialog-card header span {
  color: var(--muted);
  font-size: 11px;
}

.edit-dialog-card header h2 {
  margin: 2px 0 0;
  font-size: 18px;
}

.dialog-close {
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  box-shadow: none;
}

.edit-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 12px;
  padding: 18px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.edit-form-grid .full {
  grid-column: 1 / -1;
}

.entry-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.entry-form {
  display: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.entry-form.active {
  display: block;
}

.entry-form h2 {
  margin: 0;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  font-size: 17px;
}

.form-note {
  margin: 0;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: #fbfcfe;
  font-size: 13px;
  line-height: 1.45;
}

.form-note-warning {
  color: var(--warning);
  background: #fffaf3;
  font-weight: 600;
}

.form-section-title {
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: #374151;
  font-size: 13px;
  font-weight: 700;
}

.form-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 18px;
}

.field.full,
.computed-box,
.entry-form button[type="submit"] {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 5px;
}

.field label {
  color: #374151;
  font-size: 13px;
  font-weight: 500;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: var(--radius);
  padding: 9px 10px;
  font: inherit;
  background: #f9fafb;
  transition: border-color 0.12s ease;
}

.field input:hover,
.field select:hover,
.field textarea:hover {
  border-color: #9ca3af;
}

.field textarea {
  resize: vertical;
  min-height: 38px;
}

.computed-box {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 13px;
  border: 1px solid #cbd8f4;
  border-radius: 10px;
  background: #f6f8ff;
}

.computed-box div {
  min-width: 0;
}

.computed-box span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.computed-box strong {
  display: block;
  margin-top: 2px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.tablem-progress-bar {
  height: 22px;
  border-radius: 999px;
  background: #eef1f7;
  overflow: hidden;
  margin: 10px 0 6px;
}

.tablem-progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease;
}

.tablem-progress-label {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin: 0 0 6px;
}

.tablem-palier {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-2);
  margin: 0 0 14px;
}

.mini-chart {
  width: 100%;
  height: auto;
  max-height: 220px;
}

.trend-up {
  color: var(--positive);
  font-weight: 700;
}

.trend-down {
  color: var(--danger);
  font-weight: 700;
}

.trend-flat {
  color: var(--muted);
  font-weight: 600;
}

.sheet {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  background: #fff;
}

.sheet th,
.sheet td {
  border-bottom: 1px solid var(--line);
  padding: 10px 14px;
  min-width: 120px;
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f9fafb;
  color: #6b7280;
  text-align: left;
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sheet tbody tr:hover td {
  background: #f9fafb;
}

.sheet td:first-child,
.sheet th:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: #f9fafb;
  border-right: 1px solid var(--line);
  min-width: 58px;
  width: 58px;
  text-align: right;
  color: var(--muted-2);
}

.sheet th:first-child {
  z-index: 4;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.positive {
  color: var(--positive);
}

.negative {
  color: var(--danger);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #111827;
  color: #fff;
  box-shadow: 0 18px 44px rgba(16, 24, 40, 0.22);
}

@media (min-width: 1100px) {
  .home-layout,
  .report-page,
  .entry-page,
  .settings-grid,
  .grid-dashboard {
    max-width: 1440px;
    margin: 0 auto;
  }
}

@media (max-width: 820px) {
  .edit-dialog {
    width: calc(100vw - 16px);
    height: calc(100dvh - 16px);
    max-height: calc(100dvh - 16px);
  }

  .edit-dialog-card {
    max-height: calc(100dvh - 16px);
  }

  .import-box,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    padding: 12px 16px;
  }

  .sidebar {
    width: 72px;
    flex: 0 0 72px;
    padding: 14px 6px;
  }

  .sidebar-brand {
    justify-content: center;
    padding: 6px 0 12px;
  }

  .sidebar-brand-text,
  .admin-bar {
    display: none;
  }

  .tab {
    justify-content: center;
    padding: 12px 6px;
  }

  .tab span:not(.tab-icon) {
    display: none;
  }

  .tab.active::after {
    left: 2px;
    right: auto;
    width: 3px;
  }

  .user-box {
    flex-direction: column;
    gap: 6px;
  }

  .user-box span {
    display: none;
  }

  .user-box .secondary-button {
    font-size: 10px;
    padding: 6px 4px;
    width: 100%;
  }

  .tabs {
    padding: 0;
  }

  .kpis {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .grid-dashboard {
    grid-template-columns: 1fr;
  }

  .home-hero,
  .module-grid,
  .report-grid {
    grid-template-columns: 1fr;
  }

  .report-head {
    align-items: stretch;
    flex-direction: column;
  }

  .report-filters,
  .date-filters {
    justify-items: stretch;
    justify-content: stretch;
  }

  .date-filters label,
  .date-filters button {
    width: 100%;
  }

  .bar-row {
    grid-template-columns: 88px 1fr;
  }

  .bar-value {
    grid-column: 2;
    text-align: left;
  }

  .entry-page,
  .entry-layout,
  .form-body,
  .edit-form-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .user-form-actions,
  .edit-dialog-card > footer {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .entry-menu {
    position: static;
  }

  .computed-box {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-row {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  main {
    padding: 16px;
  }
}

/* ---------- Graphiques dynamiques (SVG maison) ---------- */
:root {
  --chart-blue: #2563eb;
  --chart-green: #057a55;
  --chart-orange: #d97706;
  --chart-red: #c81e1e;
  --chart-teal: #0d9488;
  --chart-violet: #7c3aed;
  --chart-grey: #6b7280;
}

.chart-wrap {
  position: relative;
  width: 100%;
  min-height: 80px;
}

.chart-svg {
  display: block;
  max-width: 100%;
  touch-action: pan-y;
}

.chart-grid {
  stroke: var(--line);
  stroke-width: 1;
}

.chart-zero {
  stroke: var(--muted-2);
}

.chart-axis {
  fill: var(--muted);
  font-variant-numeric: tabular-nums;
}

.chart-cursor {
  stroke: var(--muted-2);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--muted);
}

.chart-legend span,
.chart-tooltip i {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-legend i,
.chart-tooltip i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
}

.chart-legend i {
  margin-right: 0;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 150px;
  max-width: 280px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #111827;
  color: #f9fafb;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.chart-tooltip[hidden] {
  display: none;
}

.chart-tooltip-title {
  font-weight: 700;
  margin-bottom: 2px;
  text-transform: capitalize;
}

.chart-tooltip-extra {
  color: #d1d5db;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  margin-top: 3px;
  padding-top: 3px;
}

.settings-card-body {
  padding: 14px 16px;
  display: grid;
  gap: 12px;
}

.settings-card-body .kpis {
  margin-bottom: 0;
}

/* Dans les cartes de reglages : colonnes automatiques (4 colonnes fixes debordent des cartes). */
.settings-card .kpis {
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
}

.settings-card .kpis.kpis-3 {
  grid-template-columns: repeat(auto-fit, minmax(min(105px, 100%), 1fr));
  gap: 8px;
}

.kpis-3 .stat-card {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 10px 12px;
}

.kpis-3 .stat-card-icon {
  display: none;
}

.kpis-3 .stat-card-value {
  font-size: 16px;
}

.settings-card .stat-card-label {
  overflow-wrap: anywhere;
}

.stat-card-sub {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Compta : bandeaux et pagination ---------- */
.compta-banner {
  margin: 0 16px 14px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 14px;
}

.settings-card-body .compta-banner {
  margin: 0;
}

.compta-banner-ok {
  background: var(--positive-soft);
  border-color: #86efac;
  color: var(--positive);
}

.compta-banner-warn {
  background: var(--warning-soft);
  border-color: #fcd34d;
  color: var(--warning);
}

.compta-banner-info {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-2);
}

.compta-lock-note {
  color: var(--warning);
}

#clotureRepartirButton:disabled,
#clotureRepartirForm.is-locked input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.compta-subtitle {
  margin: 4px 16px;
}

.compta-pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 16px;
}

.compta-parts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
}

.compta-parts {
  min-width: 380px;
  font-size: 12px;
}

.compta-parts span {
  white-space: nowrap;
}

.compta-pagination .form-note {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
}

.compta-parts b {
  font-weight: 600;
}

.settings-card > .kpis {
  margin-top: 14px;
}

.settings-card > .subnav {
  margin-top: 12px;
}

.settings-card > .kpis,
.settings-card > .subnav,
.settings-card > .settings-inline-form,
.settings-card > .field {
  margin-left: 16px;
  margin-right: 16px;
}

.settings-card > .settings-inline-form {
  margin-left: 0;
  margin-right: 0;
}

.tablem-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.tablem-toolbar .form-note {
  background: none;
  border: 0;
  padding: 0;
}

.tablem-note {
  padding: 0 16px 14px;
  margin: 0;
}

/* ---------- Rapport detaille ---------- */
.rapport-page {
  gap: 16px;
}

.rapport-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 20px;
}

.rapport-period-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  padding: 0;
}

.rapport-period-form label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
}

.rapport-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.rapport-header h2 {
  margin: 0;
  font-size: 22px;
}

.rapport-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.rapport-header p.rapport-source-note,
p.rapport-source-note {
  margin: 6px 0 0;
  font-size: 12.5px;
  font-style: italic;
  color: var(--muted);
}

.rapport-kpis {
  display: grid;
  gap: 14px;
}

.rapport-kpis-big {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.rapport-kpis-small {
  grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
}

@media (max-width: 1099px) {
  .rapport-kpis-big {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1100px) {
  .rapport-kpis-big {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 600px) {
  .rapport-kpis-big {
    grid-template-columns: minmax(0, 1fr);
  }
}

.rapport-kpi {
  display: grid;
  gap: 4px;
  align-content: start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: var(--shadow-soft);
  min-width: 0;
}

.rapport-kpi.big {
  padding: 20px 22px;
  border-top: 4px solid var(--accent);
}

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

.rapport-kpi-value {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.rapport-kpi.big .rapport-kpi-value {
  font-size: 32px;
}

.rapport-kpi-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  font-size: 13px;
}

.rapport-delta {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.rapport-delta.tone-good {
  color: var(--positive);
}

.rapport-delta.tone-bad {
  color: var(--danger);
}

.rapport-delta.tone-flat {
  color: var(--muted);
}

.rapport-kpi-prev {
  color: var(--muted);
  font-size: 12px;
}

.rapport-part {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
  white-space: nowrap;
}

.rapport-part small {
  color: var(--muted);
}

.rapport-table tfoot td {
  font-weight: 700;
  vertical-align: top;
}

.rapport-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}

.rapport-bars .bar-value small {
  color: var(--muted);
  margin-left: 4px;
}

/* Libelle + valeur sur une ligne, barre pleine largeur dessous : lisible meme en demi-carte. */
.rapport-bars .bar-row {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
}

.rapport-bars .bar-track {
  grid-column: 1 / -1;
  grid-row: 2;
}

.rapport-bars .bar-value {
  white-space: nowrap;
}

.rapport-bars .bar-track {
  height: 12px;
}

.presentation-exit {
  display: none;
}

/* ---------- Mode presentation (projecteur) ---------- */
body.presentation .sidebar,
body.presentation .topbar,
body.presentation .toolbar {
  display: none;
}

body.presentation main {
  padding: 24px 40px;
}

body.presentation .panel {
  border: 0;
  box-shadow: none;
  background: transparent;
}

body.presentation .management {
  padding: 0;
}

body.presentation .rapport-page,
body.presentation .rapport-grid {
  max-width: none;
}

body.presentation .rapport-page {
  font-size: clamp(15px, 1.15vw, 20px);
}

body.presentation .rapport-header h2 {
  font-size: 34px;
}

body.presentation .rapport-header p {
  font-size: 20px;
}

body.presentation .rapport-kpi-label {
  font-size: 15px;
}

body.presentation .rapport-kpi-value {
  font-size: clamp(20px, 2.1vw, 34px);
}

body.presentation .rapport-kpi.big .rapport-kpi-value {
  font-size: clamp(26px, 3.2vw, 52px);
}

body.presentation .rapport-kpi-foot {
  font-size: 18px;
}

body.presentation .rapport-kpi-prev {
  font-size: 15px;
}

body.presentation .settings-card h2 {
  font-size: 22px;
}

body.presentation .bar-row {
  font-size: 18px;
}

body.presentation .mini-table {
  font-size: 17px;
}

body.presentation .chart-legend {
  font-size: 16px;
}

body.presentation .chart-tooltip {
  font-size: 15px;
}

body.presentation .presentation-exit {
  display: block;
  position: fixed;
  top: 10px;
  right: 14px;
  z-index: 40;
  opacity: 0.6;
  font-size: 12px;
  padding: 6px 10px;
}

body.presentation .presentation-exit:hover {
  opacity: 1;
}

@media (min-width: 1100px) {
  .rapport-page.settings-page {
    max-width: 1440px;
    margin: 0 auto;
    width: 100%;
  }
}

@media (max-width: 820px) {
  .rapport-actions {
    margin-left: 0;
  }

  .rapport-kpi.big .rapport-kpi-value {
    font-size: 26px;
  }

  .rapport-bars .bar-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .rapport-bars .bar-label {
    grid-column: 1;
  }

  .rapport-bars .bar-value {
    grid-column: 1;
    grid-row: 2;
    text-align: left;
  }

  .rapport-bars .bar-track {
    grid-row: 3;
  }
}

/* =====================================================================
   Refonte "logiciel de gestion" : tableaux denses, barres de filtres,
   formulaires en grille, cartes. Place avant l'impression pour que
   @media print garde la main.
   ===================================================================== */
:root {
  --row-h: 38px;
  --ctl-h: 36px;
  --line-strong: #d5d9e0;
  --zebra: #fafbfc;
  --th-bg: #f1f3f6;
  --hover-row: #eef4ff;
}

/* Largeur : on exploite l'ecran, avec un plafond raisonnable */
main {
  width: 100%;
  max-width: 1640px;
  margin: 0 auto;
  padding: 18px 28px 32px;
}

@media (min-width: 1100px) {
  .home-layout,
  .report-page,
  .entry-page,
  .settings-grid,
  .grid-dashboard {
    max-width: none;
    width: 100%;
    margin: 0;
  }
}

.settings-page {
  width: 100%;
  gap: 14px;
}

.settings-grid {
  width: 100%;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr));
  gap: 16px;
  align-items: start;
}

/* Les vues de gestion n'ont plus le double cadre panneau + cartes */
body[data-view="accueil"] .panel,
body[data-view="saisie"] .panel,
body[data-view="gestion"] .panel,
body[data-view="rapports"] .panel,
body[data-view="alertes"] .panel,
body[data-view="donnees"] .panel,
body[data-view="rh"] .panel,
body[data-view="compta"] .panel,
body[data-view="creances"] .panel,
body[data-view="devis"] .panel,
body[data-view="direction"] .panel,
body[data-view="tablem"] .panel,
body[data-view="parametres"] .panel {
  background: transparent;
  border: 0;
  box-shadow: none;
  overflow: visible;
}

body[data-view="accueil"] .management,
body[data-view="saisie"] .management,
body[data-view="gestion"] .management,
body[data-view="rapports"] .management,
body[data-view="alertes"] .management,
body[data-view="donnees"] .management,
body[data-view="rh"] .management,
body[data-view="compta"] .management,
body[data-view="creances"] .management,
body[data-view="devis"] .management,
body[data-view="direction"] .management,
body[data-view="tablem"] .management,
body[data-view="parametres"] .management {
  padding: 0;
}

/* ---------- Controles ---------- */
button {
  padding: 8px 16px;
  min-height: var(--ctl-h);
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.2;
}

input[type="file"],
input[type="search"],
select {
  min-height: var(--ctl-h);
  padding: 6px 10px;
  border-radius: 6px;
  background: #fff;
  font-size: 13.5px;
}

.field {
  gap: 4px;
  min-width: 0;
}

.field label {
  color: #4b5563;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.field input,
.field select,
.field textarea {
  border-radius: 6px;
  padding: 6px 10px;
  background: #fff;
  font-size: 13.5px;
}

.field input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.field select {
  height: var(--ctl-h);
}

.field input:disabled,
.field select:disabled {
  background: var(--neutral-soft);
  color: var(--muted);
}

.secondary-button,
.ghost-button {
  background: #fff;
  color: #374151;
  border: 1px solid #d1d5db;
}

.ghost-button {
  border-color: transparent;
  color: var(--muted);
}

.ghost-button:hover {
  background: var(--neutral-soft);
  color: var(--ink);
}

/* ---------- Cartes et sections ---------- */
.settings-card,
.management-card {
  border-radius: 10px;
  box-shadow: var(--shadow-soft);
}

.settings-card h2,
.management-card h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #fff;
  color: var(--ink);
  font-size: 14.5px;
  font-weight: 650;
  letter-spacing: 0;
}

.settings-card > p:not(.form-note),
.settings-card > .settings-intro-text {
  padding: 10px 16px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.form-note {
  padding: 9px 16px;
  font-size: 12.5px;
}

.settings-card > .form-note {
  background: transparent;
  border-bottom: 0;
}

.settings-list {
  margin: 12px 16px 0;
  border-radius: 8px;
}

.settings-list:last-child {
  margin-bottom: 14px;
}

.settings-list h3,
.settings-list h4 {
  margin: 0;
  padding: 10px 14px;
  background: var(--header);
  border-bottom: 1px solid var(--line);
  color: #374151;
  font-size: 12.5px;
  font-weight: 650;
}

/* ---------- KPI ---------- */
.stat-card {
  gap: 12px;
  padding: 12px 14px;
  border-radius: 10px;
}

.stat-card-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
}

.stat-card-label {
  font-size: 11px;
  letter-spacing: 0.05em;
}

.stat-card-value {
  margin-top: 2px;
  font-size: 18px;
  font-weight: 700;
}

.stat-card-sub {
  font-size: 11.5px;
}

.settings-card .kpis {
  grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
  gap: 10px;
}

/* ---------- Sous-navigation ---------- */
.subnav {
  gap: 2px;
  padding: 3px;
  border-radius: 8px;
  width: fit-content;
  max-width: 100%;
  overflow-x: auto;
}

.subnav button {
  min-height: 30px;
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 13px;
  white-space: nowrap;
}

/* ---------- Barre de filtres ---------- */
.settings-card form.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 12px;
  margin: 12px 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--header);
}

.settings-card form.filter-bar > button[type="submit"] {
  grid-column: auto;
  justify-self: auto;
  min-width: 0;
}

.filter-bar .field {
  flex: 0 1 170px;
  min-width: 130px;
}

.filter-bar .field.grow {
  flex: 1 1 240px;
}

.filter-bar button {
  height: var(--ctl-h);
  padding: 0 16px;
}

.filter-bar .ghost-button {
  padding: 0 10px;
}

/* ---------- Formulaires de saisie : grille multi-colonnes ---------- */
.settings-card form {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 190px), 1fr));
  gap: 12px 14px;
  align-items: end;
  padding: 14px 16px;
}

.settings-card form > .full,
.settings-card form > .form-note,
.settings-card form > .settings-form-section,
.settings-card form > h3,
.settings-card form > h4,
.settings-card form > .computed-box,
.settings-card form > .user-form-actions,
.settings-card form > .form-actions {
  grid-column: 1 / -1;
}

.settings-card form > button[type="submit"],
.settings-card form > .form-actions {
  grid-column: 1 / -1;
  justify-self: end;
  width: auto;
  min-width: 170px;
}

.settings-card form > .form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.entry-form .form-body {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr));
  gap: 12px 16px;
  align-items: end;
}

.entry-form button[type="submit"] {
  justify-self: end;
  width: auto;
  min-width: 190px;
}

.form-panel {
  margin: 12px 16px;
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.form-panel > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  background: var(--accent-soft);
  color: var(--accent-2);
  font-size: 13.5px;
  font-weight: 650;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.form-panel > summary::-webkit-details-marker {
  display: none;
}

.form-panel > summary small {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.form-panel[open] > summary {
  border-bottom: 1px solid var(--accent-border);
}

.form-panel-plus {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  transition: transform 0.15s ease;
}

.form-panel[open] .form-panel-plus {
  transform: rotate(45deg);
}

.settings-card .form-panel form {
  padding: 14px;
}

/* ---------- Tableaux ---------- */
.table-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.table-scroll {
  margin: 0 16px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: auto;
  max-height: min(68vh, 640px);
  -webkit-overflow-scrolling: touch;
}

.table-meta + .table-scroll {
  margin-top: 0;
}

.settings-list .table-scroll,
.management-card .table-scroll {
  margin: 0;
  border: 0;
  border-radius: 0;
}

.settings-list .table-meta,
.management-card .table-meta {
  padding: 8px 14px 6px;
}

.mini-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: 13px;
}

.mini-table th,
.mini-table td {
  height: var(--row-h);
  padding: 0 12px;
  border-bottom: 1px solid #eceff3;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

.mini-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 34px;
  background: var(--th-bg);
  border-bottom: 1px solid var(--line-strong);
  color: #4b5563;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.mini-table td:last-child,
.mini-table th:last-child {
  text-align: left;
}

.mini-table td.num,
.mini-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.mini-table td.num {
  font-feature-settings: "tnum";
  color: var(--ink);
}

.mini-table td.col-date,
.mini-table th.col-date {
  width: 1%;
  min-width: 92px;
  color: #374151;
}

.mini-table td.col-actions,
.mini-table th.col-actions {
  width: 1%;
  text-align: right;
}

.mini-table td.cell-text {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-table tbody tr:nth-child(even) td {
  background: var(--zebra);
}

.mini-table tbody tr:hover td {
  background: var(--hover-row);
}

.mini-table tbody tr:last-child td {
  border-bottom: 0;
}

.mini-table tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 1;
  height: 40px;
  background: var(--th-bg);
  border-top: 2px solid var(--line-strong);
  border-bottom: 0;
  color: var(--ink);
  font-weight: 700;
}

.mini-table td button {
  min-height: 28px;
  padding: 3px 10px;
  border: 1px solid var(--accent-border);
  border-radius: 6px;
  background: #fff;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 600;
}

.mini-table td button:hover {
  background: var(--accent-soft);
}

.mini-table td button.danger-button {
  background: #fff;
}

.mini-table td button.danger-button:hover {
  background: var(--danger-soft);
}

.mini-table td.col-actions {
  white-space: nowrap;
}

.mini-table td.cell-badge {
  width: 1%;
}

.badge {
  padding: 2px 9px;
  font-size: 11.5px;
  letter-spacing: 0.02em;
  border-bottom: 0;
  line-height: 1.5;
}

.badge-account {
  background: var(--accent-soft);
  color: var(--accent-2);
}

.table-empty {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin: 8px 16px 16px;
  padding: 28px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--muted-2);
  font-size: 13px;
}

.table-empty strong {
  color: var(--muted);
  font-weight: 600;
}

.settings-list .table-empty,
.management-card .table-empty {
  margin: 0;
  border: 0;
  border-radius: 0;
}

.compta-pagination {
  padding: 4px 16px 14px;
}

.planning-scroll {
  border-radius: 8px;
}

.compta-parts {
  min-width: 420px;
  gap: 4px;
  padding: 6px 0;
}

.compta-parts span {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--neutral-soft);
  font-size: 11.5px;
}

.settings-list .form-note {
  background: transparent;
  border-bottom: 0;
}

/* ---------- Rapports / cartes "chart-card" ---------- */
.report-page {
  gap: 14px;
}

.report-head {
  align-items: flex-start;
  padding: 14px 16px;
  border-radius: 10px;
}

.report-head h2 {
  font-size: 17px;
}

.report-filters {
  justify-items: end;
  gap: 8px;
}

.period-switcher {
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--header);
}

.period-switcher button {
  min-height: 30px;
  padding: 4px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.period-switcher button:hover {
  background: #fff;
  color: var(--ink);
}

.period-switcher button.active,
.period-switcher button.active:hover {
  background: #fff;
  color: var(--accent-2);
  box-shadow: var(--shadow-soft);
}

.date-filters input,
.data-date-filters input {
  height: var(--ctl-h);
  padding: 0 9px;
  border-radius: 6px;
  background: #fff;
}

.date-filters label,
.data-date-filters label {
  font-size: 12px;
}

.date-filters button,
.export-button {
  min-height: var(--ctl-h);
  padding: 0 14px;
  border-radius: 6px;
  font-size: 13px;
}

.export-button {
  padding: 0 14px;
}

.report-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr));
  gap: 14px;
  align-items: start;
}

.chart-card {
  border-radius: 10px;
}

.chart-card.wide {
  grid-column: 1 / -1;
}

.chart-card h3 {
  padding: 12px 16px;
  font-size: 14.5px;
  font-weight: 650;
}

.chart-card .table-scroll {
  margin: 0;
  border: 0;
  border-radius: 0;
}

.chart-card .table-meta {
  padding: 8px 16px 6px;
}

.chart-card .table-empty {
  margin: 0;
  border: 0;
  border-radius: 0;
}

.metric-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
  gap: 10px;
  padding: 14px 16px;
}

.metric-tile {
  min-height: 66px;
  padding: 10px 12px;
  gap: 6px;
  border-radius: 8px;
}

.metric-tile strong {
  font-size: 17px;
}

.empty-state {
  padding: 26px 16px;
  text-align: center;
  background: #fbfcfd;
  color: var(--muted-2);
  font-size: 13px;
}

.bar-chart {
  padding: 12px 16px 16px;
}

/* ---------- Tables de donnees (grille .sheet) et barre d'outils ---------- */
.toolbar {
  gap: 10px 16px;
  padding: 10px 14px;
  background: #fff;
}

#search {
  width: min(360px, 100%);
}

.data-date-filters {
  align-items: center;
  gap: 8px;
}

.data-date-filters label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
}

.data-date-filters button,
.data-date-filters .export-button {
  min-height: var(--ctl-h);
  padding: 0 14px;
}

#rowCount {
  margin-left: auto;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--neutral-soft);
  color: #374151;
  font-size: 12px;
  font-weight: 600;
}

.sheet {
  font-size: 13px;
}

.sheet th,
.sheet td {
  height: var(--row-h);
  padding: 0 12px;
  border-bottom: 1px solid #eceff3;
}

.sheet th {
  height: 34px;
  background: var(--th-bg);
  border-bottom: 1px solid var(--line-strong);
  color: #4b5563;
  font-size: 11px;
  font-weight: 700;
}

.sheet td:first-child,
.sheet th:first-child {
  background: var(--th-bg);
  font-size: 11.5px;
  text-align: center;
}

.sheet th.num,
.sheet td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sheet td.col-date {
  min-width: 100px;
  width: 1%;
}

.sheet tbody tr:nth-child(even) td:not(:first-child) {
  background: var(--zebra);
}

.sheet tbody tr:hover td {
  background: var(--hover-row);
}

.sheet td.row-actions,
.sheet th.col-actions {
  min-width: 0;
  width: 1%;
  text-align: right;
  white-space: nowrap;
}

.sheet td.row-actions button {
  min-height: 28px;
  margin: 0 0 0 4px;
  padding: 3px 10px;
  font-size: 12px;
}

.sheet td.row-actions button:not(.secondary-button):not(.danger-button) {
  border-color: var(--accent-border);
  background: #fff;
  color: var(--accent-2);
}

.sheet th,
.sheet td {
  min-width: 90px;
  max-width: 260px;
}

.mini-table td a {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 10px;
  border: 1px solid var(--accent-border);
  border-radius: 6px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}

.mini-table td a:hover {
  background: var(--accent-soft);
}

.devis-line-row {
  display: grid;
  grid-template-columns: minmax(180px, 3fr) 90px 140px 110px auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.devis-line-row input {
  min-width: 0;
}

.planning-table th,
.planning-table td {
  padding: 4px 6px;
}

.planning-table th {
  height: auto;
  min-height: 34px;
  padding: 6px 8px;
  line-height: 1.3;
}

.planning-table select {
  min-width: 108px;
  min-height: 30px;
  padding: 3px 8px;
  font-size: 12.5px;
}

.planning-toolbar {
  padding: 12px 16px;
}

.planning-scroll {
  margin: 0 16px 16px;
}

.settings-card > h3,
.settings-card > h4,
.compta-subtitle {
  margin: 14px 16px 0;
  color: #374151;
  font-size: 13px;
  font-weight: 650;
}

.settings-card > button,
.settings-card > .action-row {
  margin: 10px 16px 14px;
}

.checkbox-field input[type="checkbox"],
.checkbox-field input[type="radio"] {
  width: 16px;
  height: 16px;
  flex: none;
  margin: 0;
  padding: 0;
}

.checkbox-field label {
  min-height: var(--ctl-h);
  padding: 6px 10px;
  color: #374151;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.recette-line-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--header);
}

.recette-line-row input,
.recette-line-row select {
  flex: 1 1 130px;
  width: auto;
  min-width: 0;
}

.recette-line-row .recette-line-designation {
  flex: 3 1 220px;
}

.recette-line-row button {
  flex: none;
}

.devis-line-row select {
  min-width: 0;
}

body.presentation main {
  max-width: none;
}

body.presentation .table-scroll {
  max-height: none;
  overflow: visible;
}

body.presentation .mini-table th,
body.presentation .mini-table td {
  height: auto;
  padding: 9px 14px;
}

body.presentation .table-meta {
  font-size: 15px;
}

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  main {
    padding: 12px;
  }

  .settings-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .settings-card form {
    grid-template-columns: minmax(0, 1fr);
  }

  .settings-card form > button[type="submit"] {
    justify-self: stretch;
  }

  .settings-card form.filter-bar {
    margin: 10px 12px;
  }

  .filter-bar .field {
    flex: 1 1 130px;
  }

  .filter-bar button {
    flex: 1 1 auto;
  }

  .table-scroll {
    margin: 0 10px 12px;
    max-height: 60vh;
  }

  .table-meta {
    padding: 8px 12px 4px;
  }

  .form-panel {
    margin: 10px 12px;
  }

  .form-panel > summary small {
    display: none;
  }

  .subnav {
    width: 100%;
    flex-wrap: nowrap;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .devis-line-row {
    grid-template-columns: 1fr 1fr;
  }

  .kpis,
  .settings-card .kpis,
  .settings-card-body .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .stat-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 10px 12px;
  }

  .stat-card-icon {
    display: none;
  }

  .stat-card-value {
    font-size: 16px;
    overflow-wrap: anywhere;
  }

  .filter-bar .field {
    flex: 1 1 110px;
  }

  #rowCount {
    margin-left: 0;
    white-space: normal;
  }

  .devis-line-description {
    grid-column: 1 / -1;
  }

  .import-box input[type="file"] {
    width: 100%;
    min-width: 0;
  }
}

/* ---------- Impression propre ---------- */
@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  body {
    background: #fff;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .sidebar,
  .topbar,
  .toolbar,
  .no-print,
  .toast,
  main > .kpis {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  main,
  .management {
    padding: 0 !important;
  }

  .panel {
    border: 0;
    box-shadow: none;
  }

  .settings-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    max-width: none;
  }

  .settings-card,
  .rapport-kpi,
  .chart-wrap {
    break-inside: avoid;
    page-break-inside: avoid;
    box-shadow: none;
  }

  .rapport-kpis-big {
    grid-template-columns: repeat(4, 1fr);
  }

  .rapport-kpis-small {
    grid-template-columns: repeat(4, 1fr);
  }

  .rapport-kpi.big .rapport-kpi-value {
    font-size: 22px;
  }

  .chart-tooltip {
    display: none !important;
  }

  .table-scroll {
    max-height: none !important;
    overflow: visible !important;
  }

  .mini-table th,
  .mini-table tfoot td {
    position: static;
  }

  .form-panel {
    display: none;
  }
}
