/* ─── Variables ─────────────────────────────────────────────────── */
:root {
  --gold:          #c8a030;
  --gold-hover:    #b08922;
  --gold-light:    #f5edcf;
  --bg:            #f4f3ef;
  --card:          #ffffff;
  --border:        #e3e0d8;
  --text:          #2a2a2a;
  --text-light:    #6b6860;
  --danger:        #c0392b;
  --danger-hover:  #a93226;
  --danger-light:  #fdecea;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.07), 0 1px 8px rgba(0,0,0,.04);
  --shadow-md:     0 2px 8px rgba(0,0,0,.09), 0 4px 20px rgba(0,0,0,.06);
  --radius:        10px;
  --radius-sm:     6px;
  --font:          -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

/* ─── Reset minimal ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }

/* ─── Header ─────────────────────────────────────────────────────── */
.header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.header-logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -.01em;
  color: var(--text);
  flex-shrink: 0;
}
.header-search {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex: 1;
  max-width: 340px;
}
.header-search-input {
  flex: 1;
  min-width: 0;
}
.header-search-btn {
  flex-shrink: 0;
  padding: .35rem .55rem;
}
.header-nav {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin-left: auto;
}
.nav-link {
  padding: .35rem .75rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  color: var(--text-light);
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.nav-link:hover {
  background: var(--bg);
  color: var(--text);
}
.nav-link.active {
  background: var(--gold-light);
  color: var(--gold);
  font-weight: 600;
}
.nav-logout:hover {
  background: var(--danger-light);
  color: var(--danger);
}

/* ─── Main layout ────────────────────────────────────────────────── */
.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
}

/* ─── Card ───────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

/* ─── Page header ────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  gap: 1rem;
}
.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--text);
}
.page-sub {
  font-size: .85rem;
  color: var(--text-light);
  margin-top: .15rem;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .85rem;
  color: var(--text-light);
  transition: color .15s;
}
.back-link:hover { color: var(--gold); }
.btn-link-sm {
  background: none;
  border: none;
  color: var(--gold);
  font-size: .75rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-transform: uppercase;
  letter-spacing: .04em;
  transition: color .15s;
}
.btn-link-sm:hover { color: var(--gold-hover); }

/* ─── Buttons ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .5rem 1.1rem;
  border-radius: 20px;
  font-size: .875rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  white-space: nowrap;
  line-height: 1;
}
.btn-primary {
  background: var(--gold);
  color: #fff;
  border-color: var(--gold);
}
.btn-primary:hover {
  background: var(--gold-hover);
  border-color: var(--gold-hover);
  box-shadow: 0 2px 8px rgba(200,160,48,.35);
}
.btn-ghost {
  background: transparent;
  color: var(--text-light);
  border-color: var(--border);
}
.btn-ghost:hover {
  background: var(--bg);
  color: var(--text);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger-hover); }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: .35rem .8rem; font-size: .8rem; }

/* icon buttons in table */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  color: var(--text-light);
  transition: background .15s, color .15s, border-color .15s;
  flex-shrink: 0;
}
.btn-edit:hover  { background: var(--gold-light); color: var(--gold); border-color: var(--gold); }
.btn-delete:hover { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }

/* ─── Table ──────────────────────────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
.table thead tr { border-bottom: 2px solid var(--border); }
.table th {
  padding: .75rem 1rem;
  text-align: left;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-light);
  white-space: nowrap;
  user-select: none;
  position: relative;
}
.th-sort { cursor: pointer; }
.th-sort:hover .th-text { color: var(--text); }
.th-sort::after { content: " ↕"; opacity: .3; font-size: .65rem; }
.th-sort.sort-asc::after  { content: " ↑"; opacity: .8; color: var(--gold); }
.th-sort.sort-desc::after { content: " ↓"; opacity: .8; color: var(--gold); }
.th-filterable { padding-right: 2rem; }
.th-actions { width: 90px; text-align: center; }

.th-text { vertical-align: middle; }

.th-filter-btn {
  position: absolute;
  right: .4rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  padding: .15rem .2rem;
  border-radius: 3px;
  line-height: 1;
  opacity: .5;
  transition: opacity .15s, color .15s, background .15s;
  display: inline-flex;
  align-items: center;
}
.th-filter-btn:hover,
.th-filter-btn.active {
  opacity: 1;
  color: var(--gold);
  background: var(--gold-light);
}

/* ─── Filter dropdown ───────────────────────────────────────────── */
.filter-dropdown {
  position: fixed;
  top: 0;
  left: 0;
  min-width: 180px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 500;
  padding: .5rem;
}
.filter-dropdown-checks {
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: .5rem;
}
.filter-dropdown-checks label {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .3rem .4rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: .82rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  white-space: nowrap;
  transition: background .1s;
}
.filter-dropdown-checks label:hover { background: var(--bg); }
.filter-dropdown-checks input[type="checkbox"] {
  width: 14px;
  height: 14px;
  accent-color: var(--gold);
  flex-shrink: 0;
}
.filter-dropdown-actions {
  display: flex;
  gap: .4rem;
  justify-content: flex-end;
  border-top: 1px solid var(--border);
  padding-top: .4rem;
}
.th-filter-indicator {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  margin-left: .2rem;
  vertical-align: middle;
}

/* ─── Inline edit badge ─────────────────────────────────────────── */
.inline-edit-badge {
  cursor: pointer;
  transition: opacity .15s, box-shadow .15s;
}
.inline-edit-badge:hover {
  opacity: .85;
  box-shadow: 0 0 0 2px var(--gold);
}
.inline-edit-badge.popup-open {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  opacity: 1;
}

/* ─── Popup badge (liste flottante) ──────────────────────────────── */
.badge-popup {
  position: fixed;
  z-index: 600;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  min-width: 165px;
  max-width: 250px;
  padding: .3rem 0;
  overflow: hidden;
}
.badge-popup-option {
  display: block;
  width: 100%;
  background: none;
  border: none;
  padding: .48rem .9rem;
  font-size: .83rem;
  font-family: var(--font);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background .1s;
  white-space: nowrap;
}
.badge-popup-option:hover {
  background: var(--bg);
}
.badge-popup-option--current {
  font-weight: 600;
  color: var(--gold-hover);
  background: var(--gold-light);
}
.badge-popup-option--current:hover {
  background: var(--gold-light);
}

/* ─── Badges — administratif ─────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 500;
  white-space: nowrap;
}
.badge-admin { background: #f3f4f6; color: #4b5563; }
.badge-admin--lm-a-faire { background: #fef2f2; color: #b91c1c; }
.badge-admin--lm-envoye  { background: #fff7ed; color: #c2410c; }
.badge-admin--lm-signe   { background: #eff6ff; color: #1d4ed8; }
.badge-admin--lm-encode  { background: #f0fdf4; color: #15803d; }

/* ─── Badges — état avancement (Etude Patrimoniale) ─────────────── */
.badge-etat { background: #f3f4f6; color: #4b5563; }
.badge-etat--non-contacte         { background: #fef2f2; color: #b91c1c; }
.badge-etat--a-commencer          { background: #fff7ed; color: #c2410c; }
.badge-etat--en-cours-de-collecte { background: #eff6ff; color: #1d4ed8; }
.badge-etat--big-fini             { background: #f0fdf4; color: #15803d; }
.badge-etat--mission-terminee     { background: #f3f4f6; color: #4b5563; }

/* ─── Badges — avancement (fiscal, ponctuel, MAHAKA) ─────────────── */
.badge-avancement { background: #f3f4f6; color: #4b5563; }
.badge-avancement--non-contacte          { background: #fef2f2; color: #b91c1c; }
.badge-avancement--en-cours-de-collecte  { background: #fff7ed; color: #c2410c; }
.badge-avancement--saisie-dr             { background: #eff6ff; color: #1d4ed8; }
.badge-avancement--edi-transmis          { background: #f0fdf4; color: #15803d; }
.badge-avancement--edi-ok                { background: #f3f4f6; color: #4b5563; }
.badge-avancement--contacte              { background: #fff7ed; color: #c2410c; }
.badge-avancement--compte-rendu-en-cours { background: #eff6ff; color: #1d4ed8; }
.badge-avancement--termine               { background: #f3f4f6; color: #4b5563; }
/* MAHAKA avancement */
.badge-avancement--proposition-faite    { background: #fff7ed; color: #c2410c; }
.badge-avancement--souscription-en-cours { background: #eff6ff; color: #1d4ed8; }
.badge-avancement--souscription-terminee { background: #f3f4f6; color: #4b5563; }

/* ─── Table cells ────────────────────────────────────────────────── */
.table tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: #faf9f6; }
.table td { padding: .7rem 1rem; vertical-align: middle; }
.td-dossier { font-weight: 600; font-family: "SF Mono", "Fira Mono", monospace; font-size: .82rem; }
.td-nom-dossier { color: var(--text-light); font-size: .875rem; }
.td-binome { font-size: .78rem; color: var(--text-light); }
.td-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem .75rem;
}

/* ─── Icône commentaire ───────────────────────────────────────────── */
.btn-comment {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--gold);
  text-decoration: none;
  margin-left: .3rem;
  vertical-align: middle;
  transition: color .15s;
  flex-shrink: 0;
}
.btn-comment:hover { color: var(--gold-hover); }

/* ─── Empty state ────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-light);
}

/* ─── Form page ──────────────────────────────────────────────────── */
.form-page { max-width: 760px; }
.form-card { padding: 1.75rem 2rem; }
.mission-form .form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem 1.5rem;
}
.field { display: flex; flex-direction: column; gap: .35rem; }
.field-full { grid-column: 1 / -1; }
.label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.required { color: var(--danger); }
.section-label {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gold);
  padding-top: .25rem;
  border-top: 1px solid var(--border);
}
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}

/* ─── Form controls ──────────────────────────────────────────────── */
.input {
  display: block;
  width: 100%;
  padding: .5rem .75rem;
  font-size: .9rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
  -webkit-appearance: none;
}
.input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(200,160,48,.15);
}
.input-sm { font-size: .85rem; padding: .35rem .65rem; }
select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b6860' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .65rem center;
  padding-right: 2rem;
}
input[type="date"].input { cursor: pointer; }
textarea.input { resize: vertical; min-height: 80px; line-height: 1.5; }

/* ─── Login page ─────────────────────────────────────────────────── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-wrapper { width: 100%; max-width: 380px; padding: 1rem; }
.login-card { padding: 2.25rem 2rem; }
.login-logo { text-align: center; margin-bottom: 1rem; }
.login-title { font-size: 1.3rem; font-weight: 700; text-align: center; letter-spacing: -.02em; }
.login-subtitle {
  font-size: .85rem; color: var(--text-light);
  text-align: center; margin-top: .3rem; margin-bottom: 1.5rem;
}
.login-form .field { margin-bottom: 1.25rem; }

/* ─── Alert ──────────────────────────────────────────────────────── */
.alert { padding: .65rem .9rem; border-radius: var(--radius-sm); font-size: .875rem; margin-bottom: 1rem; }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #f5c6c2; }

/* ─── Modal (suppression) ────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  backdrop-filter: blur(2px);
}
.modal-box {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 1.75rem 2rem;
  max-width: 400px;
  width: 90%;
}
.modal-title { font-size: 1rem; font-weight: 700; margin-bottom: .5rem; }
.modal-msg { font-size: .9rem; color: var(--text-light); margin-bottom: 1.5rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; }

/* ─── Modal historique ───────────────────────────────────────────── */
.modal-history-box {
  max-width: 580px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1.75rem;
}
.modal-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-shrink: 0;
}
.modal-history-header .modal-title { margin-bottom: 0; }
.history-content {
  overflow-y: auto;
  flex: 1;
}
.history-loading { color: var(--text-light); font-size: .9rem; }
.history-empty { color: var(--text-light); font-size: .9rem; font-style: italic; }
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}
.history-table th {
  text-align: left;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-light);
  padding: .4rem .6rem;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.history-table td {
  padding: .45rem .6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.history-table tbody tr:last-child td { border-bottom: none; }
.history-table tbody tr:hover td { background: #faf9f6; }
.history-action {
  display: inline-block;
  padding: .1rem .45rem;
  border-radius: 10px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
}
.history-action--creation  { background: #f0fdf4; color: #15803d; }
.history-action--modification { background: #eff6ff; color: #1d4ed8; }
.history-action--suppression { background: #fef2f2; color: #b91c1c; }
.history-old { color: var(--text-light); text-decoration: line-through; font-size: .8rem; }
.history-arrow { color: var(--text-light); padding: 0 .3rem; }
.history-new { font-weight: 500; }

/* ─── Search page ────────────────────────────────────────────────── */
.search-section { margin-bottom: 2rem; }
.search-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: .75rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.search-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--gold-light);
  color: var(--gold);
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 700;
  padding: .1rem .55rem;
}

/* ─── MAHAKA avancement couleurs ─────────────────────────────────── */
.badge-avancement--etude                { background: #fef2f2; color: #b91c1c; }
.badge-avancement--proposition-faite   { background: #fff7ed; color: #c2410c; }
.badge-avancement--souscription-en-cours { background: #eff6ff; color: #1d4ed8; }
.badge-avancement--souscription-terminee { background: #f0fdf4; color: #15803d; }

/* ─── MAHAKA thèmes badges ───────────────────────────────────────── */
.badge-theme {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 500;
  background: var(--gold-light);
  color: var(--gold-hover);
  white-space: nowrap;
  margin: .1rem .1rem .1rem 0;
}
.td-themes { line-height: 1.8; }

/* ─── Checkboxes thèmes (formulaire) ─────────────────────────────── */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  padding: .4rem 0;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .9rem;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
}
.checkbox-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--gold);
  flex-shrink: 0;
  cursor: pointer;
}

/* ─── Inline date edit ───────────────────────────────────────────── */
.inline-edit-date {
  cursor: pointer;
  transition: background .1s;
}
.inline-edit-date:hover {
  background: var(--gold-light) !important;
  color: var(--gold-hover);
}
.inline-edit-date.date-popup-open,
.inline-edit-date.popup-open {
  background: var(--gold-light) !important;
}

.date-popup {
  position: fixed;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: .6rem .75rem;
  z-index: 600;
  display: flex;
  flex-direction: column;
  gap: .45rem;
  min-width: 190px;
}
.date-popup-clear {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: .78rem;
  cursor: pointer;
  text-align: left;
  padding: 0;
  font-family: var(--font);
  transition: color .15s;
}
.date-popup-clear:hover { color: var(--danger); }

/* ─── Tooltip commentaire ────────────────────────────────────────── */
.comment-tooltip {
  position: fixed;
  z-index: 700;
  background: var(--text);
  color: var(--card);
  font-size: .78rem;
  font-weight: 400;
  line-height: 1.5;
  padding: .45rem .65rem;
  border-radius: var(--radius-sm);
  max-width: 280px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  pointer-events: none;
  box-shadow: 0 2px 10px rgba(0,0,0,.22);
}

/* ─── Toast confirmation ─────────────────────────────────────────── */
.inline-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #15803d;
  color: #fff;
  padding: .45rem 1.25rem;
  border-radius: 20px;
  font-size: .82rem;
  font-weight: 500;
  box-shadow: 0 2px 12px rgba(0,0,0,.2);
  z-index: 1000;
  pointer-events: none;
  opacity: 1;
  transition: opacity .4s;
  white-space: nowrap;
}
.inline-toast.fade-out { opacity: 0; }

/* ─── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .header-search { display: none; }
}
@media (max-width: 768px) {
  .main { padding: 1rem .75rem 2rem; }
  .mission-form .form-grid { grid-template-columns: 1fr; }
  .table { font-size: .8rem; }
  .table th, .table td { padding: .5rem .6rem; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .form-card { padding: 1.25rem; }
  .nav-link { padding: .3rem .5rem; font-size: .8rem; }
}
