:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #d8dee9;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --header-bg: #1e3a5f;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); text-decoration: underline; }

.site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: linear-gradient(135deg, #1e3a5f, #2563eb);
  color: #fff;
  padding: 0.75rem 1.5rem;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.15);
}

.site-header a { color: #fff; text-decoration: none; }
.site-header a:hover { opacity: 0.9; text-decoration: none; }

.brand { font-weight: 600; font-size: 1.1rem; }

.header-brand {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  min-width: 0;
}

.nav-main {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  justify-self: center;
}

.nav-main a { font-size: 0.9rem; opacity: 0.95; }

.nav-main--empty {
  /* Placeholder pour conserver la grille à 3 colonnes */
  min-width: 0;
}

.nav-actions {
  justify-self: end;
  display: flex;
  align-items: center;
}

.nav-main a.nav-active {
  opacity: 1;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Menu « Plus » */
.nav-more {
  position: relative;
}

.nav-more summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.9rem;
  opacity: 0.95;
  user-select: none;
}

.nav-more summary::-webkit-details-marker { display: none; }

.nav-more summary::after {
  content: ' ▾';
  font-size: 0.75em;
  opacity: 0.85;
}

.nav-more[open] summary,
.nav-more-active summary {
  opacity: 1;
  font-weight: 600;
}

.nav-more-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.5rem);
  min-width: 11rem;
  padding: 0.4rem 0;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.18);
  z-index: 1200;
}

.nav-more-panel a {
  display: block;
  padding: 0.45rem 1rem;
  color: var(--text);
  font-size: 0.9rem;
  opacity: 1;
  white-space: nowrap;
}

.nav-more-panel a:hover {
  background: #f1f5f9;
  color: var(--accent);
  text-decoration: none;
  opacity: 1;
}

.nav-more-panel a.nav-more-current {
  font-weight: 600;
  color: var(--accent);
}

.nav-more-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.35rem 0;
}

.form-hint {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}

.nav-more-user {
  font-weight: normal;
  opacity: 0.75;
  font-size: 0.88em;
}

.copro-badge {
  background: rgba(255,255,255,0.15);
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  font-size: 0.85rem;
}

.db-badge {
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.db-badge-import {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
}

main {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  padding: 1.5rem;
}

footer {
  text-align: center;
  padding: 1rem;
  color: var(--muted);
  font-size: 0.8rem;
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.75rem; color: var(--muted); font-weight: 600; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}
.stat-card-hit {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: 6px;
  padding: 0.25rem;
  transition: background 0.15s ease;
}
.stat-card-hit:hover {
  background: #f1f5f9;
  text-decoration: none;
}
.stat-card-hit:hover .value { color: var(--accent-dark); }
.stat-card .value { font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-card .label { color: var(--muted); font-size: 0.85rem; }
.dashboard-column {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.dashboard-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}
.dashboard-header { margin-bottom: 1.25rem; }
.dashboard-stats { margin: 0; }
.copro-switcher { margin: 0; }
.copro-switcher-select {
  font-size: 1.5rem;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0.15rem 0 0.15rem 1.35rem;
  cursor: pointer;
  font-family: inherit;
  max-width: 100%;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 0.1rem center;
}
.copro-switcher-select:hover { color: var(--accent); }
.copro-switcher-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-weight: 500; margin-bottom: 0.35rem; font-size: 0.9rem; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
}
.form-group textarea { min-height: 80px; resize: vertical; }

.radio-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-weight: normal;
  cursor: pointer;
}
.radio-label input { width: auto; margin: 0; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.form-check { display: flex; align-items: center; gap: 0.5rem; }
.form-check-group { display: flex; flex-wrap: wrap; gap: 0.75rem 1.25rem; }
.form-check input { width: auto; }

.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1rem; }

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  min-width: 0;
  max-width: 100%;
}
.table-wrap.card {
  padding: 0;
}
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  min-width: 0;
  max-width: 100%;
}
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { border: 1px solid var(--border); padding: 0.5rem 0.65rem; text-align: left; vertical-align: top; }
th { background: var(--header-bg); color: #fff; font-weight: 600; }
tbody tr:nth-child(even) { background: #f8fafc; }
tbody tr:hover { background: #e8f0fe; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-muted { background: #f1f5f9; color: var(--muted); }
.badge-warning { background: #fef3c7; color: #92400e; }

.flash-messages { margin-bottom: 1rem; }
.alert {
  padding: 0.65rem 1rem;
  border-radius: 6px;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: #e0f2fe; color: #075985; border: 1px solid #bae6fd; }

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a5f, #2563eb);
}
.login-box {
  background: var(--surface);
  padding: 2rem;
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}
.login-box h1 { text-align: center; margin-bottom: 1.5rem; }

.search-bar { margin-bottom: 1rem; display: flex; gap: 0.5rem; }
.search-bar input { flex: 1; padding: 0.5rem 0.65rem; border: 1px solid var(--border); border-radius: 6px; }
.filter-form { margin-bottom: 0; padding: 0.75rem 1rem; }
.filter-form .filter-search { margin-bottom: 0.5rem; }
.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.search-input-wrap input {
  width: 100%;
  padding: 0.5rem 2rem 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
}
.search-clear {
  position: absolute;
  right: 0.35rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}
.search-clear:hover { color: var(--text); background: #f1f5f9; }
.filter-form .filter-roles { margin-top: 0.25rem; }

/* Combobox (autocomplétion) */
.combobox {
  position: relative;
}
.combobox-input {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
}
.combobox-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}
.combobox-list {
  position: absolute;
  z-index: 1300;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  margin: 0;
  padding: 0.25rem 0;
  list-style: none;
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.15);
}
.combobox-option {
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  font-size: 0.9rem;
}
.combobox-option:hover,
.combobox-option.is-active {
  background: #e8f0fe;
  color: var(--accent-dark);
}
.combobox-empty {
  padding: 0.45rem 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-style: italic;
}

.filter-roles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  font-size: 0.88rem;
  color: var(--muted);
}
.filter-roles .form-check { font-size: inherit; color: inherit; }
.personnes-results { transition: opacity 0.15s ease; }
.personnes-results.is-loading { opacity: 0.55; pointer-events: none; }

.contact-block { border: 1px dashed var(--border); padding: 0.75rem; border-radius: 6px; margin-bottom: 0.5rem; }
.inline-form { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: end; margin-top: 0.5rem; }
.inline-form .form-group { margin-bottom: 0; flex: 1; min-width: 120px; }

.role-person-block {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.role-person-block:last-of-type { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.role-person-name { display: block; margin-bottom: 0.35rem; }
.role-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.65rem;
  margin-left: 0.5rem;
  padding: 0.3rem 0;
  font-size: 0.9rem;
}
.role-line-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  flex: 1 1 12rem;
}
.role-line-dates { color: var(--muted); white-space: nowrap; }
.role-line-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  flex: 0 0 auto;
}
.role-action-form {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
}
.input-date-compact {
  padding: 0.28rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: inherit;
  width: 8.5rem;
}

.modal {
  border: none;
  border-radius: 12px;
  padding: 0;
  max-width: 32rem;
  width: calc(100% - 2rem);
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.2);
}
.modal::backdrop {
  background: rgba(15, 23, 42, 0.45);
}
.modal-panel { margin: 0; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}
.modal-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}
.modal-close:hover { color: var(--text); background: #f1f5f9; }
.modal-body { padding: 1.25rem; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  background: #f8fafc;
  border-radius: 0 0 12px 12px;
}

.tantiemes-table { margin: 0; }
.tantiemes-table th:last-child,
.tantiemes-table td:last-child { width: 40%; }
.tantiemes-designation { font-weight: 500; }
.tantiemes-input {
  width: 100%;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  box-sizing: border-box;
}

.compteur-block {
  margin: 0;
  padding: 0.85rem 0;
  border-top: 1px solid var(--border);
}
.compteur-block:first-of-type { padding-top: 0.5rem; }
.compteur-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
}
.compteur-line-main {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  flex: 1;
  min-width: min(100%, 12rem);
}
.compteur-title {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.compteur-meta { color: var(--muted); font-weight: normal; }

.section-title { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.5rem; }

.historique { font-size: 0.85rem; color: var(--muted); }
.entity-meta { font-size: 0.78rem; margin: -0.35rem 0 0.85rem; }
.entity-meta-inline { font-size: 0.75rem; }

/* Infobulle personne (listing lots) */
/* Scroll sur .table-scroll pour ne pas clipper les infobulles (position:fixed via JS) */
.table-wrap--tips { overflow: visible; }
.table-wrap--tips td { overflow: visible; }

.lot-personnes-col { line-height: 1.45; vertical-align: top; }
.lot-personne-ligne { display: block; }
.lot-personne-ligne + .lot-personne-ligne { margin-top: 0.35rem; }

.personne-tip {
  position: relative;
  display: inline;
  white-space: normal;
}

.personne-tip-panel {
  display: none;
  position: absolute;
  left: 60px;
  top: 100%;
  z-index: 1100;
  width: max-content;
  min-width: 260px;
  max-width: min(480px, 92vw);
  padding: 0.65rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.18);
  font-size: 0.82rem;
  line-height: 1.45;
  text-align: left;
  color: var(--text);
  pointer-events: auto;
  user-select: text;
  cursor: text;
  overflow-wrap: anywhere;
}

/* Pont invisible : liaison verticale nom → bulle (zone à gauche libre pour descendre) */
.personne-tip-panel::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: -10px;
  height: 10px;
}

/* Bord droit de l'écran : aligner la bulle sur la droite du nom */
.personne-tip.tip-left .personne-tip-panel {
  left: auto;
  right: 0;
}

.personne-tip.tip-left .personne-tip-panel::before {
  left: 0;
  right: 0;
}

.personne-tip.is-open .personne-tip-panel {
  display: block;
}

.personne-tip-mail {
  color: var(--accent);
  text-decoration: none;
  pointer-events: auto;
  cursor: pointer;
  white-space: nowrap;
}
.personne-tip-mail:hover {
  color: var(--accent-dark);
  text-decoration: underline;
}

.personne-tip-title {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.personne-tip-dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto max-content;
  gap: 0.25rem 0.85rem;
}

.personne-tip-dl dt {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.personne-tip-dl dd { margin: 0; white-space: nowrap; }

.personne-tip-contact { display: block; white-space: nowrap; }

.personne-tip-contact em {
  font-style: normal;
  color: var(--muted);
  font-size: 0.78rem;
}

.personne-tip-empty { margin: 0.35rem 0 0; font-size: 0.8rem; }

@media (max-width: 640px) {
  main { padding: 1rem; }
  .site-header {
    padding: 0.75rem 1rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.5rem 0.75rem;
  }
  .header-brand, .nav-actions { justify-self: unset; }
  .nav-main {
    flex: 1 1 100%;
    justify-content: flex-start;
    justify-self: unset;
    order: 3;
  }
}

/* PWA install banner */
.pwa-install-banner {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: calc(100% - 2rem);
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.15);
  font-size: 0.9rem;
}
.pwa-install-banner[hidden] { display: none; }
.pwa-install-banner .pwa-install-text { flex: 1; min-width: 0; }
.pwa-install-banner .btn { flex-shrink: 0; }
.pwa-install-banner .pwa-install-dismiss {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
}
.pwa-install-banner .pwa-install-dismiss:hover {
  color: var(--text);
  background: #f1f5f9;
}
