:root {
  color-scheme: light;
  --pg-canvas: #f6f7f9;
  --pg-surface: #ffffff;
  --pg-chrome: #fafafb;
  --pg-ink: #22242b;
  --pg-muted: #606571;
  --pg-line: #e4e6eb;
  --pg-control-border: #838892;
  --pg-soft: #eff0f3;
  --pg-accent: #b62956;
  --pg-on-accent: #ffffff;
  --pg-accent-soft: #fbedf2;
  --pg-good: #276149;
  --pg-good-bg: #edf6f0;
  --pg-warning: #87540b;
  --pg-warning-bg: #fbf3e3;
  --pg-info: #3d5879;
  --pg-info-bg: #eef3f9;
  --pg-danger: #b42318;
  --pg-danger-bg: #fff1f0;
  --pg-overlay: #20222c38;
  --bg: var(--pg-canvas);
  --bg-deep: var(--pg-canvas);
  --ink: var(--pg-ink);
  --muted: var(--pg-muted);
  --line: var(--pg-line);
  --card: var(--pg-surface);
  --card-strong: var(--pg-surface);
  --accent: var(--pg-accent);
  --accent-deep: var(--pg-accent);
  --accent-soft: var(--pg-accent-soft);
  --success: var(--pg-good);
  --danger: var(--pg-danger);
  --shadow: none;
  --radius-xl: 8px;
  --radius-lg: 6px;
  --radius-md: 5px;
}

html {
  background: var(--pg-canvas);
  scroll-behavior: auto;
}

body,
button,
input,
select,
textarea {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body,
body.is-authenticated {
  /* Un plancher de 320 px forcait un defilement horizontal des que la fenetre
     CSS descendait en dessous : c'est exactement ce que produit un texte
     agrandi a 150 %, ou un petit telephone zoome. La mise en page tient sans
     ce plancher. Regle R6 et WCAG 2.2 (reflow). */
  min-width: 0;
  color: var(--pg-ink) !important;
  background: var(--pg-canvas) !important;
  font-size: 14px;
  line-height: 1.45;
}

body::before,
body.is-authenticated::before {
  display: none !important;
  content: none;
}

h1,
h2,
h3,
.metric-value {
  font-family: inherit;
  letter-spacing: 0;
}

button,
label[for],
summary {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[role="button"]:focus-visible,
label[for]:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--pg-accent) 30%, transparent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Connexion */

/* La mise en page de la connexion appartient desormais a paola-studio.css,
   qui compose les deux volets. Les regles d'aplatissement qui vivaient ici
   forcaient une carte unique de 420 pixels et sont donc retirees. */

.auth-card-header {
  text-align: left;
}

.auth-monogram,
.app-monogram {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 7px;
  color: var(--pg-on-accent);
  background: var(--pg-accent);
  font-size: 22px;
  font-weight: 500;
  line-height: 1;
}

.auth-product {
  margin: 12px 0 28px;
  font-size: 17px;
  font-weight: 600;
}

.auth-product span {
  color: var(--pg-muted);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
}


.auth-intro {
  margin: 7px 0 24px;
  color: var(--pg-muted);
  font-size: 13px;
}

.auth-form {
  gap: 16px;
}

.auth-field > span:first-child,
.filters-stack label > span,
.accounting-mobile-edit-grid label > span {
  margin-bottom: 6px;
  color: var(--pg-muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

.auth-input-wrap {
  min-height: 42px;
  border: 1px solid var(--pg-control-border);
  border-radius: 5px;
  background: var(--pg-surface);
  box-shadow: none;
}

.auth-input-wrap:focus-within {
  border-color: var(--pg-accent);
  box-shadow: 0 0 0 3px #b6295626;
}

.auth-input-wrap input {
  min-height: 40px;
  border: 0;
  color: var(--pg-ink);
  background: transparent;
}

.auth-input-icon,
.auth-password-toggle {
  color: var(--pg-muted);
}

.auth-help-text {
  margin: 20px 0 0;
  color: var(--pg-muted);
  font-size: 12px;
  text-align: center;
}

.auth-loader-view {
  min-height: 260px;
}

.auth-loader-ring,
.action-loader-ring,
.import-loader {
  border-color: var(--pg-accent-soft);
  border-top-color: var(--pg-accent);
  box-shadow: none;
}

/* Shell */

body.is-authenticated {
  overflow-x: hidden;
}

body.is-authenticated #app-shell,
body.is-authenticated .app-shell {
  display: grid;
  grid-template-columns: 176px minmax(0, 1fr);
  grid-template-rows: 54px minmax(0, 1fr);
  gap: 0;
  width: 100% !important;
  min-height: 100vh;
  margin: 0;
  padding: 0 !important;
}

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 50;
  display: flex;
  width: 176px;
  flex-direction: column;
  padding: 22px 12px 14px;
  overflow-y: auto;
  border-right: 1px solid var(--pg-line);
  background: var(--pg-chrome);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 7px 26px;
}

.app-brand-copy {
  min-width: 0;
}

.app-brand-copy strong {
  display: block;
  color: var(--pg-ink);
  font-size: 20px;
  font-weight: 500;
  line-height: 1;
}

.app-brand-copy small {
  display: block;
  margin-top: 5px;
  color: var(--pg-muted);
  font-size: 11px;
}

body.is-authenticated .app-sidebar .tabs-bar {
  position: static !important;
  z-index: auto !important;
  display: grid !important;
  grid-column: auto !important;
  grid-row: auto !important;
  width: 100%;
  max-height: none !important;
  gap: 4px !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: visible !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

.app-sidebar .tab-button,
.app-nav-group summary {
  display: flex;
  width: 100%;
  min-height: 38px;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 9px 10px;
  border: 0;
  border-radius: 5px;
  color: var(--pg-muted);
  background: transparent;
  box-shadow: none;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  text-align: left;
}

.app-sidebar .tab-button:hover,
.app-nav-group summary:hover {
  color: var(--pg-ink);
  background: var(--pg-soft);
}

.app-sidebar .tab-button.is-active {
  color: var(--pg-accent) !important;
  background: var(--pg-accent-soft) !important;
  box-shadow: none !important;
}

.app-nav-group {
  border-top: 1px solid var(--pg-line);
  margin-top: 10px;
  padding-top: 10px;
}

.app-nav-group summary {
  cursor: pointer;
  list-style: none;
}

.app-nav-group summary::-webkit-details-marker {
  display: none;
}

.app-nav-group summary::after {
  content: "⌄";
  margin-left: auto;
  font-size: 12px;
}

.app-nav-group:not([open]) summary::after {
  transform: rotate(-90deg);
}

.app-nav-group.has-active-view > summary {
  color: var(--pg-accent);
}

.app-nav-submenu {
  display: grid;
  gap: 2px;
  padding: 3px 0 4px 21px;
}

.app-nav-submenu .tab-button {
  min-height: 31px;
  padding: 6px 8px;
  font-size: 12px;
}

/* Le pied de navigation ne doit jamais recouvrir les destinations quand la
   hauteur est courte, par exemple un telephone en paysage ou un zoom a 200 %.
   La liste devient la zone defilante et le pied garde sa taille. La regle
   authentifiee plus haut fige overflow et max-height : il faut la meme force
   pour les lever. */
body.is-authenticated .app-sidebar > .tabs-bar {
  min-height: 0;
  flex: 0 1 auto;
  overflow-y: auto !important;
}

.app-sidebar-footer {
  display: grid;
  gap: 8px;
  margin-top: auto;
  padding-top: 60px;
  flex-shrink: 0;
}

@media (max-height: 560px) {
  .app-sidebar-footer {
    padding-top: 16px;
  }
}

.app-account {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 30px;
  gap: 8px;
  align-items: center;
  padding: 12px 4px 0;
  border-top: 1px solid var(--pg-line);
}

.app-avatar {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  color: var(--pg-ink);
  background: var(--pg-soft);
  font-size: 10px;
  font-weight: 600;
}

.app-account-copy {
  min-width: 0;
}

.app-account-copy strong,
.app-account-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-account-copy strong {
  font-size: 12px;
  font-weight: 600;
}

.app-account-copy small {
  margin-top: 2px;
  color: var(--pg-muted);
  font-size: 11px;
}

.icon-button {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--pg-muted);
  background: transparent;
  box-shadow: none;
  font-size: 18px;
}

.icon-button:hover {
  color: var(--pg-ink);
  background: var(--pg-soft);
}

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  grid-column: 2;
  grid-row: 1;
  display: flex;
  min-width: 0;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--pg-line);
  background: color-mix(in srgb, var(--pg-surface) 94%, transparent);
  backdrop-filter: blur(12px);
}

.app-breadcrumb {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--pg-muted);
  font-size: 12px;
}

.app-breadcrumb strong {
  overflow: hidden;
  color: var(--pg-ink);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.assistant-toggle {
  min-height: 32px;
  padding: 6px 9px;
  border: 0;
}

body.is-authenticated .workspace {
  display: block !important;
  grid-column: 2 !important;
  grid-row: 2 !important;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  margin: 0 !important;
  padding: 24px !important;
}

.view-heading {
  display: flex;
  min-height: 65px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.view-heading h1 {
  margin: 0;
  max-width: none;
  color: var(--pg-ink);
  font-size: 26px;
  font-weight: 600;
  line-height: 1.2;
}

.view-summary {
  margin: 6px 0 0;
  color: var(--pg-muted);
  font-size: 13px;
}

.view-heading .section-kicker {
  margin-bottom: 5px;
}

.view-heading .status-message {
  max-width: 480px;
  margin: 0;
}

.tab-view {
  width: 100%;
  min-width: 0;
}

/* Panneau assistant */

body.is-authenticated .assistant-home-panel {
  position: fixed;
  inset: 54px 0 0 auto;
  z-index: 80;
  width: min(440px, 100%);
  margin: 0;
  padding: 22px;
  overflow-y: auto;
  border: 0;
  border-left: 1px solid var(--pg-line);
  border-radius: 0;
  color: var(--pg-ink);
  background: var(--pg-surface);
  box-shadow: -12px 0 32px #20222c12;
}

body.is-authenticated::after {
  position: fixed;
  inset: 54px 0 0 176px;
  z-index: 70;
  display: none;
  content: "";
  background: var(--pg-overlay);
}

body.is-authenticated.is-assistant-open::after {
  display: block;
}

.assistant-home-panel .assistant-chat-list {
  max-height: 48vh;
  border-color: var(--pg-line);
}

.assistant-chat-form textarea {
  min-height: 110px;
}

/* Composants */

body.is-authenticated .panel,
body.is-authenticated .metric-card,
body.is-authenticated .detail-card,
body.is-authenticated .contract-card,
body.is-authenticated .health-card,
body.is-authenticated .year-card,
body.is-authenticated .ranking-card {
  border-color: var(--pg-line) !important;
  color: var(--pg-ink);
  background: var(--pg-surface) !important;
  background-image: none !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
}

body.is-authenticated .panel::after,
body.is-authenticated .metric-card::after,
body.is-authenticated .detail-card::after,
body.is-authenticated .contract-card::after {
  display: none;
  content: none;
}

body.is-authenticated .panel {
  padding: 20px;
  overflow: visible;
  border-radius: 8px !important;
}

body.is-authenticated .metric-card,
body.is-authenticated .detail-card,
body.is-authenticated .contract-card,
body.is-authenticated .health-card,
body.is-authenticated .year-card,
body.is-authenticated .ranking-card {
  border-radius: 6px !important;
}

.section-heading {
  position: relative;
  z-index: 1;
  margin-bottom: 16px;
}

.section-heading.row {
  align-items: center;
}

.section-heading h2,
.section-heading h3,
.detail-block h3 {
  color: var(--pg-ink);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.eyebrow,
.section-kicker,
.month-chip,
.meta-label {
  color: var(--pg-muted) !important;
  font-size: 11px !important;
  font-weight: 500 !important;
  letter-spacing: 0 !important;
  text-transform: uppercase;
}

.secondary-button,
.ghost-button,
.primary-button,
.danger-button,
.mobile-panel-toggle,
label.inline-file-button {
  min-height: 36px;
  padding: 8px 11px;
  border: 1px solid var(--pg-control-border);
  border-radius: 5px;
  color: var(--pg-ink);
  background: var(--pg-surface);
  background-image: none;
  box-shadow: none;
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  text-align: center;
}

.secondary-button,
.primary-button {
  border-color: var(--pg-accent) !important;
  color: var(--pg-on-accent) !important;
  background: var(--pg-accent) !important;
  box-shadow: none !important;
}

.ghost-button:hover,
label.inline-file-button:hover {
  border-color: var(--pg-line);
  background: var(--pg-soft);
}

.secondary-button:hover,
.primary-button:hover {
  background: #992045 !important;
}

.danger-button,
.ghost-button.danger-button {
  border-color: #b4231840 !important;
  color: var(--pg-danger) !important;
  background: var(--pg-danger-bg) !important;
}

button:disabled,
.secondary-button:disabled,
.ghost-button:disabled {
  cursor: default;
  opacity: 0.48;
  box-shadow: none;
}

input,
select,
textarea {
  min-height: 36px;
  border: 1px solid var(--pg-control-border);
  border-radius: 5px;
  color: var(--pg-ink);
  background: var(--pg-surface);
  box-shadow: none;
  font-size: 13px;
}

textarea {
  padding: 9px 10px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: #777c86;
  opacity: 1;
}

input[type="checkbox"],
input[type="radio"] {
  width: 15px;
  min-height: 15px;
  accent-color: var(--pg-accent);
}

.results-count,
.meta-pill,
.amount-pill,
.status-pill,
.review-pill,
.accounting-status-pill,
.tag {
  border: 0;
  border-radius: 4px;
  color: var(--pg-muted);
  background: var(--pg-soft);
  box-shadow: none;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
}

.amount-pill {
  color: var(--pg-ink);
  font-variant-numeric: tabular-nums;
}

.review-pill.is-complete,
.status-paye,
.success-card .metric-value,
.accounting-status-pill.is-complete {
  color: var(--pg-good);
  background: var(--pg-good-bg);
}

.review-pill.is-review,
.review-pill.is-missing,
.warning-card .metric-value,
.table-cell-alert,
.accounting-status-pill.is-review {
  color: var(--pg-warning);
}

.empty-list,
.empty-state {
  padding: 36px 16px;
  border: 1px dashed var(--pg-line);
  border-radius: 6px;
  color: var(--pg-muted);
  background: var(--pg-chrome);
  font-size: 13px;
  text-align: center;
}

.status-message {
  min-height: 0;
  color: var(--pg-good);
  font-size: 12px;
}

.status-message:empty {
  display: none;
}

.status-message.is-error {
  color: var(--pg-danger);
}

.table-subline,
.muted-copy,
.meta-text,
.contract-snippet,
.detail-text {
  color: var(--pg-muted);
  font-size: 12px;
}

/* Pilotage */

#dashboard-overview {
  gap: 20px;
}

.deals-dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  border-block: 1px solid var(--pg-line);
}

body.is-authenticated .deals-dashboard-grid .metric-card {
  min-height: 110px;
  padding: 16px;
  border: 0 !important;
  border-left: 1px solid var(--pg-line) !important;
  border-radius: 0 !important;
}

body.is-authenticated .deals-dashboard-grid .metric-card:first-child {
  border-left: 0 !important;
}

.deals-dashboard-grid .dashboard-secondary-metric,
#dashboard-view:not(.is-dashboard-expanded) .contracts-dashboard-panel,
#dashboard-view:not(.is-dashboard-expanded) .insights-grid {
  display: none;
}

#dashboard-view.is-dashboard-expanded .deals-dashboard-grid {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

#dashboard-view.is-dashboard-expanded .deals-dashboard-grid .dashboard-secondary-metric {
  display: grid;
  border-top: 1px solid var(--pg-line) !important;
}

.metric-label {
  margin: 0 0 8px;
  color: var(--pg-muted) !important;
  font-size: 12px !important;
  font-weight: 500 !important;
  letter-spacing: 0 !important;
  text-transform: none;
}

body.is-authenticated .metric-value {
  color: var(--pg-ink);
  font-size: 27px !important;
  font-weight: 600 !important;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

body.is-authenticated .metric-foot {
  margin-top: 8px;
  color: var(--pg-muted);
  font-size: 11px;
  font-weight: 400 !important;
  line-height: 1.35;
}

.contracts-dashboard-grid,
.invoice-kpis,
.duplicates-summary,
.admin-diagnostics-grid {
  gap: 12px;
}

.insights-grid {
  gap: 20px;
}

.ranking-card,
.year-card,
.health-card {
  padding: 14px;
}

/* Écrans métier */

.deals-grid,
.invoices-grid,
.content-grid,
.accounting-grid {
  align-items: start;
  gap: 16px;
}

.deals-grid,
.invoices-grid {
  grid-template-columns: 226px minmax(0, 1fr);
}

.content-grid {
  grid-template-columns: 226px minmax(340px, 0.9fr) minmax(360px, 1.1fr);
}

.accounting-grid {
  grid-template-columns: 226px minmax(0, 1fr);
}

.filters-panel,
.deals-side-panel,
.invoices-side-panel,
.accounting-side-panel {
  position: sticky;
  top: 78px;
}

.filters-stack,
.compact-stack {
  gap: 12px;
}

.upload-zone {
  min-height: 96px;
  padding: 14px;
  border: 1px dashed var(--pg-control-border);
  border-radius: 6px;
  color: var(--pg-muted);
  background: var(--pg-chrome);
  box-shadow: none;
}

.upload-zone:hover {
  border-color: var(--pg-accent);
  color: var(--pg-accent);
  background: var(--pg-accent-soft);
}

.upload-title {
  color: var(--pg-ink);
  font-size: 13px;
  font-weight: 600;
}

.upload-caption {
  color: var(--pg-muted);
  font-size: 11px;
  line-height: 1.4;
}

.invoice-toolbar,
.contracts-toolbar-shell {
  gap: 12px;
  margin-bottom: 14px;
  padding: 10px;
  border: 1px solid var(--pg-line);
  border-radius: 6px;
  background: var(--pg-chrome);
  box-shadow: none;
}

.detail-actions,
.section-actions,
.row-actions,
.accounting-inline-actions {
  gap: 7px;
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--pg-line);
  border-radius: 6px;
  background: var(--pg-surface);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  color: var(--pg-ink);
  font-size: 12px;
}

.stats-table th {
  padding: 10px 8px;
  border-bottom: 1px solid var(--pg-line);
  color: var(--pg-muted);
  background: var(--pg-chrome);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
  text-align: left;
  text-transform: none;
}

.stats-table td {
  padding: 11px 8px;
  border-bottom: 1px solid var(--pg-line);
  vertical-align: middle;
}

.stats-table tbody tr:hover td {
  background: var(--pg-chrome);
}

.stats-table tr.is-selected-row td {
  background: var(--pg-accent-soft);
}

.deals-stats-table {
  min-width: 860px;
  table-layout: fixed;
}

.deals-stats-table .deal-select-cell {
  width: 44px !important;
}

.deals-stats-table .deal-date-cell {
  width: 84px !important;
}

.deals-stats-table .deal-client-cell {
  width: 18% !important;
}

.deals-stats-table .deal-contract-cell {
  width: 24% !important;
}

.deals-stats-table .deal-payment-cell {
  width: 20% !important;
}

.deals-stats-table .deal-invoice-cell {
  width: 14% !important;
}

.deals-stats-table .deal-actions-cell {
  width: 128px !important;
}

.deal-table-amount {
  margin-top: 7px;
  color: var(--pg-ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.deal-table-contract {
  margin-top: 6px;
}

.deal-table-contract .link-button {
  min-height: 0;
  padding: 0;
  border: 0;
  color: var(--pg-accent);
  background: transparent;
  font-size: 11px;
  text-align: left;
}

html body.is-authenticated .deals-stats-table .deal-actions-cell .row-actions {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 5px !important;
}

html body.is-authenticated .deals-stats-table .deal-actions-cell .row-actions > button {
  width: auto !important;
  min-width: 0 !important;
  min-height: 30px !important;
  padding: 5px 6px !important;
  font-size: 11px !important;
}

html body.is-authenticated .deals-stats-table .deal-actions-cell .row-actions > button:first-child {
  grid-column: 1 / -1;
}

html body.is-authenticated .deals-stats-table .deal-actions-cell .row-actions > button:nth-child(2):last-child {
  grid-column: 1 / -1;
}

.sort-button {
  color: inherit;
  font-size: inherit;
  font-weight: 500;
}

.sort-button.is-active {
  color: var(--pg-accent);
}

.contract-card {
  padding: 14px;
}

.contract-card:hover,
.contract-card.is-active,
.contract-card.is-selected {
  border-color: var(--pg-accent) !important;
  background: var(--pg-accent-soft) !important;
  transform: none;
}

.contract-title {
  font-size: 13px;
  font-weight: 600;
}

.contract-select-toggle {
  border-color: var(--pg-control-border);
  border-radius: 4px;
  color: var(--pg-muted);
  background: var(--pg-surface);
}

.contract-select-toggle.is-selected {
  border-color: var(--pg-accent);
  color: var(--pg-on-accent);
  background: var(--pg-accent);
}

.details-panel,
.invoice-preview-panel {
  position: sticky;
  top: 78px;
  max-height: calc(100vh - 102px);
  overflow-y: auto !important;
}

.month-group,
.cards-stack,
.duplicates-layout,
.review-queue-list {
  gap: 12px;
}

.duplicates-layout {
  grid-template-columns: minmax(220px, 0.35fr) minmax(0, 1fr);
}

.duplicates-layout > :nth-child(n + 3) {
  grid-column: 2;
}

.list-pagination {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--pg-line);
}

.pagination-button {
  min-width: 34px;
  padding-inline: 8px;
}

.pagination-button.is-active,
.sort-pill-button.is-active {
  border-color: var(--pg-accent);
  color: var(--pg-accent);
  background: var(--pg-accent-soft);
}

.accounting-quick-actions-panel {
  margin-bottom: 16px;
}

.accounting-primary-actions {
  gap: 12px;
}

.accounting-primary-action {
  min-height: 74px;
}

.action-loader {
  background: var(--pg-overlay);
}

.action-loader-card {
  width: min(390px, calc(100% - 32px));
  padding: 24px;
  border: 1px solid var(--pg-line);
  border-radius: 8px;
  background: var(--pg-surface);
  box-shadow: 0 16px 48px #20222c24;
}

.mobile-tab-nav {
  display: none;
}

@media (max-width: 1180px) {
  body.is-authenticated #app-shell,
  body.is-authenticated .app-shell {
    grid-template-columns: 60px minmax(0, 1fr);
  }

  .app-sidebar {
    width: 60px;
    padding-inline: 8px;
  }

  .app-brand {
    justify-content: center;
    padding-inline: 0;
  }

  .app-brand-copy,
  .app-sidebar .tab-label,
  .app-account-copy,
  .app-nav-group summary::after {
    display: none;
  }

  .app-sidebar .tab-button,
  .app-nav-group summary {
    justify-content: center;
    padding-inline: 8px;
  }

  .app-nav-submenu {
    padding-left: 0;
  }

  .app-nav-submenu .tab-button {
    min-height: 9px;
    padding: 5px;
  }

  .app-nav-submenu .tab-button::before {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: currentColor;
    content: "";
  }

  .app-account {
    grid-template-columns: 30px;
    justify-content: center;
  }

  .app-account .logout-button {
    margin-top: 3px;
  }

  body.is-authenticated::after {
    left: 60px;
  }

  .content-grid {
    grid-template-columns: 210px minmax(0, 1fr);
  }

  .content-grid .details-panel:not(.is-floating-open) {
    position: static;
    grid-column: 1 / -1;
    max-height: none;
  }
}

@media (max-width: 767px) {
  body.is-authenticated {
    padding-bottom: calc(66px + env(safe-area-inset-bottom));
  }

  body.is-authenticated #app-shell,
  body.is-authenticated .app-shell {
    display: block;
    min-height: 100vh;
  }

  .app-sidebar {
    display: none;
  }

  .app-topbar {
    position: sticky;
    grid-column: auto;
    min-height: 53px;
    padding: 10px 16px;
  }

  .app-breadcrumb > span:first-child,
  .app-breadcrumb > span:nth-child(2) {
    display: none;
  }

  .app-breadcrumb strong {
    color: var(--pg-ink);
    font-size: 16px;
    font-weight: 600;
  }

  body.is-authenticated .workspace {
    display: block !important;
    width: 100% !important;
    padding: 20px 16px 16px !important;
  }

  .view-heading {
    min-height: 0;
    margin-bottom: 18px;
  }

  .view-heading h1 {
    font-size: 24px;
  }

  .view-summary {
    max-width: 38ch;
    font-size: 12px;
  }

  .view-heading .status-message {
    /* Il flotte au-dessus de la navigation basse : il informe, il ne doit
       jamais intercepter l'appui destine a ce qu'il recouvre. Regle R4. */
    pointer-events: none;
    position: fixed;
    right: 12px;
    bottom: calc(72px + env(safe-area-inset-bottom));
    left: 12px;
    z-index: 110;
    padding: 10px;
    border: 1px solid var(--pg-line);
    border-radius: 6px;
    background: var(--pg-surface);
    box-shadow: 0 8px 24px #20222c1c;
  }

  body.is-authenticated .mobile-tab-nav {
    position: fixed !important;
    inset: auto 0 0 0;
    z-index: 100;
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    min-height: 62px;
    gap: 0 !important;
    margin: 0 !important;
    padding: 5px 6px calc(5px + env(safe-area-inset-bottom)) !important;
    border: 0 !important;
    border-top: 1px solid var(--pg-line) !important;
    border-radius: 0 !important;
    background: var(--pg-surface) !important;
    box-shadow: 0 -8px 22px #20222c0a !important;
  }

  .mobile-primary-tab,
  body.is-authenticated .mobile-tab-trigger {
    position: static !important;
    display: flex;
    min-width: 0;
    min-height: 52px !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px !important;
    border: 0 !important;
    border-radius: 5px !important;
    color: var(--pg-muted);
    background: transparent !important;
    background-image: none !important;
    box-shadow: none !important;
    font-size: 11px;
    font-weight: 500;
  }

  .mobile-primary-tab > span:first-child,
  .mobile-tab-trigger > span:first-child {
    min-height: 18px;
    font-size: 17px;
    line-height: 1;
  }

  .mobile-primary-tab.is-active,
  .mobile-tab-trigger[aria-expanded="true"],
  .mobile-tab-nav:has(.mobile-tab-option.is-active) .mobile-tab-trigger {
    color: var(--pg-accent);
    background: var(--pg-accent-soft) !important;
  }

  body.is-authenticated .mobile-tab-menu {
    position: absolute !important;
    right: 8px !important;
    bottom: calc(100% + 6px);
    left: 8px !important;
    top: auto !important;
    z-index: 105 !important;
    display: grid;
    gap: 3px !important;
    max-height: min(68vh, 480px);
    padding: 8px;
    overflow-y: auto;
    border: 1px solid var(--pg-line);
    border-radius: 8px;
    background: var(--pg-surface);
    box-shadow: 0 12px 32px #20222c24;
  }

  body.is-authenticated .mobile-tab-menu[hidden] {
    display: none !important;
  }

  body.is-authenticated .mobile-tab-option {
    min-height: 44px;
    padding: 10px 12px;
    border-radius: 5px;
    color: var(--pg-ink);
    background: transparent;
    font-size: 13px;
    text-align: left;
  }

  body.is-authenticated .mobile-tab-option::after {
    display: none;
    content: none !important;
  }

  /* La feuille heritee styles.css impose encore l'ancienne charte ici, avec un
     degrade vert en !important. Il faut la meme force pour rendre a l'element
     actif la couleur d'accent du produit. */
  body.is-authenticated .mobile-tab-option.is-active {
    color: var(--pg-accent) !important;
    background: var(--pg-accent-soft) !important;
  }

  /* Sections du menu Plus : elles reprennent la hierarchie de la barre
     laterale, pour qu'une liste de huit entrees redevienne lisible. */
  body.is-authenticated .mobile-tab-section {
    display: grid;
    gap: 2px;
  }

  body.is-authenticated .mobile-tab-section + .mobile-tab-section {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--pg-line);
  }

  body.is-authenticated .mobile-tab-section-title {
    margin: 0 0 2px;
    padding: 0 12px;
    color: var(--pg-ink-soft, #766a74);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  body.is-authenticated::after {
    inset: 53px 0 0;
  }

  body.is-authenticated .assistant-home-panel {
    inset: 53px 0 calc(62px + env(safe-area-inset-bottom));
    width: 100%;
    padding: 18px 16px;
    border-left: 0;
    box-shadow: none;
  }

  body.is-authenticated .panel {
    padding: 16px !important;
    border-radius: 8px !important;
  }

  .deals-dashboard-grid,
  #dashboard-view.is-dashboard-expanded .deals-dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.is-authenticated .deals-dashboard-grid .metric-card,
  body.is-authenticated .deals-dashboard-grid .metric-card:first-child {
    min-height: 105px;
    padding: 14px !important;
    border-top: 1px solid var(--pg-line) !important;
    border-left: 1px solid var(--pg-line) !important;
  }

  body.is-authenticated .deals-dashboard-grid .metric-card:nth-child(odd) {
    border-left: 0 !important;
  }

  body.is-authenticated .deals-dashboard-grid .metric-card:nth-child(-n + 2) {
    border-top: 0 !important;
  }

  body.is-authenticated .metric-value {
    font-size: 24px !important;
  }

  .deals-grid,
  .invoices-grid,
  .content-grid,
  .accounting-grid,
  .duplicates-layout,
  .insights-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
  }

  .duplicates-layout > :nth-child(n + 3),
  .content-grid .details-panel {
    grid-column: 1;
  }

  .filters-panel,
  .deals-side-panel,
  .invoices-side-panel,
  .accounting-side-panel,
  .details-panel:not(.is-floating-open),
  .invoice-preview-panel:not(.is-floating-open) {
    position: static;
    max-height: none;
  }

  body.is-authenticated .mobile-panel-toggle {
    display: flex !important;
    min-height: 44px;
    align-items: center;
    justify-content: space-between;
    border-color: var(--pg-control-border) !important;
    border-radius: 5px !important;
    color: var(--pg-ink) !important;
    background: var(--pg-surface) !important;
    box-shadow: none !important;
  }

  .mobile-collapsible-panel:not(.is-mobile-open) > :not(.section-heading):not(.mobile-panel-toggle) {
    display: none;
  }

  .accounting-quick-actions-panel {
    display: block;
  }

  body.is-authenticated .accounting-primary-action {
    min-height: 74px !important;
    padding: 12px !important;
    border-radius: 6px !important;
  }

  .section-heading.row,
  #contracts-view .section-heading.row {
    display: flex !important;
    grid-template-columns: none !important;
    flex-wrap: wrap;
    align-items: flex-start !important;
    gap: 10px !important;
  }

  .detail-actions,
  .section-actions {
    flex-wrap: wrap;
  }

  .secondary-button,
  .ghost-button,
  .primary-button,
  label.inline-file-button,
  input,
  select {
    min-height: 44px;
  }

  input,
  textarea {
    font-size: 16px;
  }

  select {
    font-size: 13px;
  }

  .table-shell {
    max-width: 100%;
  }
}

@media (max-width: 420px) {
  .app-topbar,
  body.is-authenticated .workspace {
    padding-inline: 12px !important;
  }

  .view-summary {
    max-width: 29ch;
  }

  body.is-authenticated .panel {
    padding: 13px !important;
  }

  .deals-dashboard-panel .section-heading {
    align-items: flex-start;
  }

  #dashboard-metrics-toggle {
    width: 100%;
  }

  .metric-foot {
    overflow-wrap: anywhere;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Final compatibility layer for the legacy stylesheet's high-specificity rules. */
body.is-authenticated .app-sidebar .tabs-bar .tab-button.is-active {
  color: var(--pg-accent) !important;
  background: var(--pg-accent-soft) !important;
}


body.is-authenticated .view-heading h1,
body.is-authenticated .section-heading h2,
body.is-authenticated .section-heading h3,
body.is-authenticated .detail-block h3,
body.is-authenticated .workspace .metric-value {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
  letter-spacing: 0 !important;
}

body.is-authenticated #dashboard-view .deals-dashboard-grid > .metric-card {
  border-color: var(--pg-line) !important;
  background: var(--pg-surface) !important;
  background-image: none !important;
}

body.is-authenticated #dashboard-view .deals-dashboard-grid > .metric-card.accent {
  border-left-color: var(--pg-accent) !important;
}

body.is-authenticated #dashboard-view .deals-dashboard-grid > .metric-card.success-card {
  border-left-color: var(--pg-good) !important;
}

body.is-authenticated #dashboard-view .deals-dashboard-grid > .metric-card.warning-card {
  border-left-color: var(--pg-warning) !important;
}

html body.is-authenticated .primary-button,
html body.is-authenticated .secondary-button {
  border-color: var(--pg-accent) !important;
  color: var(--pg-on-accent) !important;
  background: var(--pg-accent) !important;
  background-image: none !important;
}

body.is-authenticated #dashboard-view .deals-dashboard-grid > .metric-card .metric-value {
  width: auto !important;
  padding: 0 !important;
  color: var(--pg-ink) !important;
  background: transparent !important;
}

html body.is-authenticated .workspace .metric-card .metric-value {
  width: auto !important;
  padding: 0 !important;
  background: transparent !important;
}

.accounting-side-panel .upload-actions-grid {
  display: none !important;
}

body.is-authenticated .panel::after,
body.is-authenticated .metric-card::after,
body.is-authenticated .detail-card::after {
  display: none !important;
  content: none !important;
}

html body.is-authenticated #dashboard-view:not(.is-dashboard-expanded) .dashboard-secondary-metric,
html body.is-authenticated #dashboard-view:not(.is-dashboard-expanded) .contracts-dashboard-panel,
html body.is-authenticated #dashboard-view:not(.is-dashboard-expanded) .insights-grid {
  display: none !important;
}

html body.is-authenticated #dashboard-view.is-dashboard-expanded .dashboard-secondary-metric {
  display: grid !important;
}

html body.is-authenticated #assistant-drawer[hidden] {
  display: none !important;
}

@media (max-width: 767px) {
  html body.is-authenticated #app-shell.app-shell {
    width: 100% !important;
    max-width: 100% !important;
    min-height: 100vh !important;
    padding: 0 !important;
  }

  html body.is-authenticated #app-shell > .workspace > .mobile-tab-nav {
    position: fixed !important;
    inset: auto 0 0 0 !important;
    top: auto !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 62px !important;
    max-height: calc(72px + env(safe-area-inset-bottom)) !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    padding: 5px 6px calc(5px + env(safe-area-inset-bottom)) !important;
    border: 0 !important;
    border-top: 1px solid var(--pg-line) !important;
    border-radius: 0 !important;
    background: var(--pg-surface) !important;
    background-image: none !important;
  }

  html body.is-authenticated #app-shell .mobile-primary-tab,
  html body.is-authenticated #app-shell .mobile-tab-trigger {
    position: static !important;
    display: flex !important;
    width: auto !important;
    min-width: 0 !important;
    min-height: 52px !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 2px !important;
    padding: 4px !important;
    border: 0 !important;
    border-radius: 5px !important;
    color: var(--pg-muted) !important;
    background: transparent !important;
    background-image: none !important;
    box-shadow: none !important;
    font-size: 11px !important;
    line-height: 1.15 !important;
    text-align: center !important;
  }

  html body.is-authenticated #app-shell .mobile-primary-tab.is-active,
  html body.is-authenticated #app-shell .mobile-tab-trigger[aria-expanded="true"],
  html body.is-authenticated #app-shell .mobile-tab-nav:has(.mobile-tab-option.is-active) .mobile-tab-trigger {
    color: var(--pg-accent) !important;
    background: var(--pg-accent-soft) !important;
  }

  html body.is-authenticated #app-shell .mobile-tab-menu {
    position: absolute !important;
    inset: auto 8px calc(100% + 6px) 8px !important;
    top: auto !important;
    bottom: calc(100% + 6px) !important;
    max-height: min(68vh, 480px) !important;
    border: 1px solid var(--pg-line) !important;
    border-radius: 8px !important;
    background: var(--pg-surface) !important;
    background-image: none !important;
  }

  html body.is-authenticated #dashboard-view .deals-dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  html body.is-authenticated #dashboard-view .deals-dashboard-grid .metric-value {
    font-size: 19px !important;
    line-height: 1.15 !important;
    white-space: nowrap !important;
    overflow-wrap: normal !important;
  }
}

/* Barre de familles de controles. Les cinq sous-vues partagent une destination
   et se choisissent ici : on voit d'abord ce qu'il y a a traiter, on choisit la
   famille ensuite. */
.control-segments {
  display: grid;
  gap: 10px;
  margin: 0 0 18px;
}

.control-segments-total {
  margin: 0;
  color: var(--pg-ink-soft, #766a74);
  font-size: 12px;
}

.control-segments-total strong {
  color: var(--pg-ink, #29242c);
  font-size: 15px;
}

.control-segments-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.control-segment {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--pg-line);
  border-radius: 999px;
  background: var(--pg-surface, #fff);
  color: var(--pg-ink-soft, #6f626e);
  font-size: 12px;
  cursor: pointer;
  transition: background 160ms, color 160ms, border-color 160ms;
}

.control-segment:hover {
  background: var(--pg-chrome, #f9f8fa);
  color: var(--pg-ink, #29242c);
}

.control-segment.is-active {
  border-color: var(--pg-accent);
  background: var(--pg-accent-soft);
  color: var(--pg-accent);
  font-weight: 600;
}

.control-segment-count {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--pg-chrome, #f1eef1);
  color: inherit;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.control-segment.is-active .control-segment-count {
  background: #fff;
}
