/* ====================================================================
   Composants partagés : shell d'application, topbar, cards, tables,
   pills, boutons, perms-box, toasts, modals, tag de proto
   ==================================================================== */

/* -------------- Shell d'application (par rôle) -------------- */
.app {
  display: none;
  min-height: 100vh;
}
.app.active {
  display: block;
}

/* Top bar — différente par rôle */
.topbar {
  background: white;
  border-bottom: 1px solid var(--line);
  padding: 12px 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}
.topbar-brand {
  font-family: "Fraunces", serif;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  padding-right: 14px;
  border-right: 1px solid var(--line);
}
.topbar-context {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.topbar-context .role-tag {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--current-role-color, var(--ink-3));
  font-weight: 600;
}
.topbar-context .module-name {
  font-size: 14px;
  color: var(--ink);
  font-weight: 500;
  font-family: "Fraunces", serif;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 4px;
  background: var(--paper-2);
  cursor: pointer;
  transition: background 0.15s;
}
.user-chip:hover {
  background: var(--line);
}
.user-chip-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--current-role-soft, var(--paper));
  color: var(--current-role-color, var(--ink));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Fraunces", serif;
  font-weight: 600;
  font-size: 12px;
}
.user-chip-name {
  font-size: 13px;
  font-weight: 500;
}
.user-chip-role {
  font-size: 10px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.switch-link {
  font-size: 12px;
  color: var(--ink-3);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 4px;
  transition: all 0.15s;
}
.switch-link:hover {
  background: var(--paper-2);
  color: var(--ink);
}

/* Bandeau "vous êtes en mode démo" */
.demo-banner {
  background: var(--ink);
  color: var(--paper);
  padding: 8px 32px;
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.demo-banner .label {
  color: var(--ink-4);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 10px;
  font-weight: 600;
}
.demo-banner a {
  color: var(--paper);
  text-decoration: underline;
  cursor: pointer;
}

.main-content {
  padding: 32px 48px 64px;
  max-width: 1400px;
  margin: 0 auto;
}

/* Header de page */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.page-title {
  font-family: "Fraunces", serif;
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -0.02em;
}
.page-meta {
  font-size: 12px;
  color: var(--ink-3);
  text-align: right;
}
.page-meta strong {
  color: var(--ink);
  display: block;
  font-size: 13px;
}
.badge-period {
  display: inline-block;
  background: var(--ink);
  color: var(--paper);
  padding: 4px 10px;
  border-radius: 3px;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  margin-top: 6px;
}

/* -------------- Composants réutilisables -------------- */
.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 20px 22px;
}

.card-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--ink-3);
  margin-bottom: 8px;
}

.kpi-value {
  font-family: "Fraunces", serif;
  font-size: 34px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1;
  transition: color 0.3s ease;
}
.kpi-value.flash {
  color: var(--accent);
}

.kpi-sub {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 6px;
}
.kpi-sub .up {
  color: var(--green);
  font-weight: 500;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 28px 0 14px;
}
.section-title {
  font-family: "Fraunces", serif;
  font-size: 19px;
  font-weight: 500;
}

.table {
  width: 100%;
  background: white;
  border: 1px solid var(--line);
  border-radius: 4px;
  border-collapse: collapse;
  overflow: hidden;
}
.table th {
  text-align: left;
  padding: 12px 16px;
  background: var(--paper-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  border-bottom: 1px solid var(--line);
  font-weight: 500;
}
.table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.table tr:last-child td {
  border-bottom: none;
}
.table tr:hover td {
  background: var(--paper-2);
}
.table .num {
  font-family: "JetBrains Mono", monospace;
  text-align: right;
}
.table tr {
  transition: background 0.3s ease;
}
.table tr.just-validated td {
  background: var(--green-soft) !important;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: all 0.3s ease;
}
.pill::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}
.pill-validated {
  background: var(--green-soft);
  color: var(--green);
}
.pill-pending {
  background: var(--amber-soft);
  color: var(--amber);
}
.pill-disputed {
  background: var(--red-soft);
  color: var(--red);
}
.pill-draft {
  background: var(--paper-2);
  color: var(--ink-3);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  font-family: inherit;
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--ink);
  color: var(--paper);
}
.btn-primary:hover:not(:disabled) {
  background: var(--ink-2);
}
.btn-ghost {
  background: transparent;
  border-color: var(--line-2);
  color: var(--ink-2);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--paper-2);
  border-color: var(--ink-3);
}
.btn-accent {
  background: var(--accent);
  color: white;
}
.btn-accent:hover:not(:disabled) {
  background: #9c3a18;
}

/* -------------- Permissions box (partagé entre rôles) -------------- */
.perms-box {
  background: var(--current-role-soft, var(--paper-2));
  border-left: 3px solid var(--current-role-color, var(--ink));
  padding: 14px 18px;
  border-radius: 4px;
  margin-bottom: 24px;
  font-size: 12px;
  color: var(--ink-2);
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.perms-box-label {
  font-weight: 600;
  color: var(--current-role-color, var(--ink));
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 10px;
  margin-bottom: 4px;
}
.perms-box ul {
  display: inline;
  padding: 0;
  margin: 0;
  list-style: none;
}
.perms-box ul li {
  display: inline;
}
.perms-box ul li:not(:last-child)::after {
  content: " · ";
  color: var(--ink-3);
}

/* -------------- Toasts -------------- */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--ink);
  color: var(--paper);
  padding: 14px 20px;
  border-radius: 4px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  animation: slideIn 0.3s ease;
  max-width: 360px;
  border-left: 3px solid var(--green);
}
.toast.toast-warn {
  border-left-color: var(--amber);
}
.toast.toast-error {
  border-left-color: var(--red);
}
.toast strong {
  font-family: "Fraunces", serif;
  font-size: 14px;
  display: block;
  margin-bottom: 2px;
  font-weight: 500;
}
@keyframes slideIn {
  from {
    transform: translateX(20px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.audit-row-new {
  background: var(--role-admin-soft) !important;
  animation: highlightFade 2s ease forwards;
}
@keyframes highlightFade {
  0% {
    background: var(--role-admin-soft);
  }
  100% {
    background: white;
  }
}

/* -------------- Modal -------------- */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 25, 0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.show {
  display: flex;
}
.modal {
  background: white;
  border-radius: 6px;
  padding: 28px;
  width: 480px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}
.modal h3 {
  font-family: "Fraunces", serif;
  font-size: 22px;
  font-weight: 500;
  margin-bottom: 8px;
}
.modal textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px;
  font-family: inherit;
  font-size: 13px;
  margin: 16px 0;
  resize: vertical;
  min-height: 80px;
}
.modal textarea:focus {
  outline: none;
  border-color: var(--role-commercial);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* -------------- Demo tag -------------- */
.proto-tag {
  position: fixed;
  top: 12px;
  right: 12px;
  background: var(--accent);
  color: white;
  padding: 4px 10px;
  border-radius: 3px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  z-index: 100;
  font-weight: 500;
}

/* ====================================================================
   Responsive — tablet (≤1024px) et mobile (≤640px)
   ==================================================================== */

@media (max-width: 1024px) {
  .topbar {
    padding: 12px 20px;
  }
  .demo-banner {
    padding: 8px 20px;
  }
  .main-content {
    padding: 24px 24px 48px;
  }
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
  .page-title {
    font-size: 26px;
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 14px;
  }
  .topbar-left {
    gap: 10px;
  }
  .topbar-brand {
    padding-right: 10px;
    font-size: 16px;
  }
  .topbar-context .module-name {
    font-size: 13px;
  }
  .topbar-right {
    gap: 8px;
    flex-wrap: wrap;
  }
  .user-chip {
    padding: 5px 10px;
  }
  .user-chip-name {
    font-size: 12px;
  }

  .demo-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 8px 14px;
  }

  .main-content {
    padding: 18px 14px 40px;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 16px;
  }
  .page-title {
    font-size: 22px;
  }
  .page-meta {
    text-align: left;
  }

  .grid-3 {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 20px;
  }

  .card {
    padding: 16px 18px;
  }
  .kpi-value {
    font-size: 28px;
  }

  .section-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    margin: 22px 0 12px;
  }
  .section-title {
    font-size: 17px;
  }

  /* Tables : scroll horizontal sans casser le markup */
  .table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  .table thead,
  .table tbody,
  .table tr {
    /* le table devient block, on garde la cohérence visuelle */
    display: table;
    width: 100%;
    table-layout: auto;
  }
  .table th,
  .table td {
    padding: 10px 12px;
    font-size: 12px;
  }

  .perms-box {
    flex-direction: column;
    gap: 6px;
    padding: 12px 14px;
  }

  .toast-container {
    right: 12px;
    left: 12px;
    bottom: 12px;
  }
  .toast {
    max-width: none;
  }

  .modal {
    padding: 22px 18px;
  }
  .modal h3 {
    font-size: 19px;
  }
}
