:root {
  --navy: #00425E;
  --navy-light: #0a5678;
  --turq: #409CB8;
  --turq-light: #e3f1f5;
  --orange: #FBAC2F;
  --orange-light: #fff3de;
  --bg: #f5f7f8;
  --card: #ffffff;
  --text: #1c2b33;
  --text-muted: #6b7c85;
  --border: #e2e8eb;
  --danger: #c0392b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,66,94,0.08), 0 1px 2px rgba(0,66,94,0.06);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 14px;
}
a { color: var(--navy); }
.app { max-width: 1080px; margin: 0 auto; padding: 20px 20px 60px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--navy); color: #fff; padding: 18px 24px;
  border-radius: var(--radius); margin-bottom: 20px; flex-wrap: wrap; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(135deg, var(--orange), var(--turq));
  display: flex; align-items: center; justify-content: center; font-size: 16px;
}
.brand-text h1 { font-family: Georgia, 'Times New Roman', serif; font-size: 18px; margin: 0; font-weight: 700; }
.brand-text p { margin: 1px 0 0; font-size: 11.5px; color: #bcd7e2; }
.topbar-right { font-size: 12.5px; color: #eaf4f7; display: flex; align-items: center; white-space: nowrap; }
.topbar-right span { font-weight: 600; margin-right: 14px; }
.topbar-right a { color: #fff; text-decoration: none; opacity: 0.85; }
.topbar-right a:hover { opacity: 1; text-decoration: underline; }

.tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.tab-btn {
  padding: 9px 18px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); color: var(--text-muted); font-weight: 600;
  cursor: pointer; font-size: 13px; text-decoration: none; display: inline-block;
}
.tab-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.tab-btn:not(.active):hover { border-color: var(--turq); color: var(--navy); }

.stats-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 20px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; box-shadow: var(--shadow); }
.stat-card .num { font-size: 19px; font-weight: 700; color: var(--navy); font-family: Georgia, serif; }
.stat-card .label { font-size: 10.5px; color: var(--text-muted); margin-top: 1px; }
.stat-card-link { display: block; text-decoration: none; transition: transform .1s ease, box-shadow .1s ease; }
.stat-card-link:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0,0,0,0.08); }
.stat-card-danger .num { color: var(--danger); }
.stat-card-active { border-color: var(--turq); border-width: 2px; box-shadow: 0 0 0 2px rgba(64,156,184,0.15); }

/* ---------- Modale d'ajout de tâche ---------- */
dialog.modal {
  border: none; border-radius: 12px; padding: 0; width: 540px; max-width: 92vw;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
dialog.modal::backdrop { background: rgba(0,20,30,0.5); }
.modal-header {
  background: var(--navy); color: #fff; padding: 16px 20px; border-radius: 12px 12px 0 0;
  display: flex; justify-content: space-between; align-items: center;
}
.modal-close-x { background: none; border: none; color: #fff; font-size: 18px; cursor: pointer; line-height: 1; padding: 4px; }
.modal-close-x:hover { opacity: 0.75; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.card h2 { font-family: Georgia, serif; font-size: 16px; margin: 0 0 14px; color: var(--navy); }

.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.search-input, select.filter-select, .field input, .field select, .field textarea {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
  outline: none; font-family: inherit; background: #fff; color: var(--text);
}
.search-input { flex: 1; min-width: 180px; }
.search-input:focus, select:focus, .field input:focus, .field textarea:focus { border-color: var(--turq); }

.btn { padding: 9px 16px; border-radius: 8px; border: none; font-weight: 600; font-size: 13px; cursor: pointer; text-decoration: none; display: inline-block; }
.btn-primary { background: var(--orange); color: #402600; }
.btn-primary:hover { opacity: 0.9; }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--navy); }
.btn-outline:hover { border-color: var(--turq); }
.btn-danger { background: #fdeceb; color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); padding: 8px 10px; border-bottom: 2px solid var(--border); }
thead th a.sort-link { color: var(--text-muted); text-decoration: none; cursor: pointer; }
thead th a.sort-link:hover { color: var(--navy); }
thead th a.sort-link.active { color: var(--navy); }
.sort-icon { display: inline-block; font-size: 10px; color: #b8c4ca; }
thead th a.sort-link:hover .sort-icon { color: var(--turq); }
.sort-icon.active { color: var(--orange); font-size: 11px; font-weight: 700; }
tbody td { padding: 11px 10px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tbody tr:hover { background: #fafcfd; }
.name-cell { font-weight: 600; color: var(--navy); }
.nowrap-cell { white-space: nowrap; }
.sub-cell { color: var(--text-muted); font-size: 12px; }
.row-link { color: inherit; text-decoration: none; display: block; }
.next-action-cell { font-size: 15px; color: var(--text); font-weight: 600; }
.next-action-cell .action-date { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
.status-select {
  border: none; border-radius: 999px; padding: 6px 12px; font-size: 12px; font-weight: 700;
  font-family: inherit; cursor: pointer; max-width: 100%;
}
.status-select:hover { opacity: 0.85; }
.status-select:focus { outline: 2px solid var(--turq); outline-offset: 1px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.empty-state { text-align: center; padding: 50px 20px; color: var(--text-muted); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--navy); margin-bottom: 5px; }
.field input, .field select, .field textarea { width: 100%; }
.field textarea { resize: vertical; min-height: 70px; }
.field-hint { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.form-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; align-items: center; }

.auth-wrap { max-width: 420px; margin: 60px auto; }
.auth-card { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 30px; border: 1px solid var(--border); }
.auth-logo { display: block; margin: 0 auto 18px; max-width: 280px; width: 100%; height: auto; }
.auth-card h1 { font-family: Georgia, serif; color: var(--navy); font-size: 22px; margin: 0 0 6px; text-align: center; }
.auth-card p.sub { text-align: center; color: var(--text-muted); font-size: 13px; margin: 0 0 22px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .btn { width: 100%; padding: 11px; font-size: 14px; }
.auth-links { text-align: center; margin-top: 16px; font-size: 13px; }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: #fdeceb; color: var(--danger); border: 1px solid #f3c9c4; }
.alert-success { background: #e9f7ef; color: #1c6b3c; border: 1px solid #bde5cc; }

.footer-note { text-align: center; font-size: 11.5px; color: var(--text-muted); margin-top: 28px; }

@media (max-width: 700px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- Nouvelle mise en page (barre latérale) ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--navy); color: #fff;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { padding: 20px 18px 18px; border-bottom: 1px solid rgba(255,255,255,0.12); }
.sidebar-brand-link { display: inline-block; }
.sidebar-logo { display: block; height: 40px; width: auto; }
.sidebar-brand-sub { margin: 8px 0 0; font-size: 11.5px; color: #bcd7e2; }
.sidebar-nav { flex: 1; padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: #d7e7ee; text-decoration: none; font-size: 13.5px; font-weight: 600;
}
.sidebar-link .icn { font-size: 15px; width: 18px; text-align: center; }
.sidebar-link:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar-link.active { background: var(--orange); color: #402600; }
.sidebar-footer { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,0.12); font-size: 12.5px; }
.sidebar-footer .advisor-name { font-weight: 700; margin-bottom: 4px; }
.sidebar-footer a { color: #bcd7e2; text-decoration: none; }
.sidebar-footer a:hover { color: #fff; text-decoration: underline; }
.main { flex: 1; min-width: 0; padding: 22px 26px 60px; }

/* ---------- Fiche contact : sous-navigation verticale ---------- */
.contact-shell { display: flex; gap: 18px; align-items: flex-start; }
.contact-subnav {
  width: 220px; flex-shrink: 0; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.contact-subnav .who { padding: 16px 16px 12px; font-family: Georgia, serif; font-weight: 700; color: var(--navy); font-size: 15px; border-bottom: 1px solid var(--border); }
.contact-subnav a {
  display: flex; align-items: center; gap: 9px; padding: 10px 16px; font-size: 13px;
  color: var(--text); text-decoration: none; border-left: 3px solid transparent;
}
.contact-subnav a .icn { width: 16px; text-align: center; }
.contact-subnav a:hover { background: #f7fafb; }
.contact-subnav a.active { background: var(--turq-light); border-left-color: var(--turq); color: var(--navy); font-weight: 700; }
.contact-content { flex: 1; min-width: 0; }

.pill-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.pill-check {
  display: flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--border);
  border-radius: 999px; font-size: 12.5px; cursor: pointer; user-select: none; background: #fff;
}
.pill-check input { margin: 0; }
.pill-check.checked { background: var(--turq-light); border-color: var(--turq); color: var(--navy); font-weight: 600; }
a.pill-check { text-decoration: none; color: var(--text); }

.task-filter-bar {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 14px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.task-filter-group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.task-filter-label { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-right: 2px; }

.repeatable-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; margin-bottom: 10px; align-items: center; }
.repeatable-row.relations { grid-template-columns: 1fr 1fr auto; }
.subtle-btn { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 16px; padding: 4px 8px; }
.add-link { color: var(--turq); font-weight: 600; font-size: 13px; text-decoration: none; display: inline-block; margin-top: 4px; }

.trip-card { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.trip-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.rdv-done { opacity: 0.6; background: #fafbfc; }

/* ---------- Relations : cartes repliables (compact) ---------- */
.rel-card { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; overflow: hidden; }
.rel-summary {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer; list-style: none; font-size: 13.5px; background: #fafbfc;
}
.rel-summary::-webkit-details-marker { display: none; }
.rel-summary::before { content: "▸"; color: var(--turq); font-size: 11px; margin-right: 8px; flex-shrink: 0; }
.rel-card[open] .rel-summary::before { content: "▾"; }
.rel-card[open] .rel-summary { border-bottom: 1px solid var(--border); }
.rel-summary-name { font-weight: 700; color: var(--navy); flex: 1; min-width: 0; }
.rel-summary-meta { white-space: nowrap; font-size: 12px; }
.rel-card-body { padding: 14px 16px; }
.passport-info-cell { font-size: 14px; color: var(--text); font-weight: 600; }

/* ---------- Automatisations ---------- */
.automation-row {
  display: flex; align-items: center; gap: 14px; padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.automation-row:last-child { border-bottom: none; }
.automation-toggle-form { flex-shrink: 0; }
.toggle-switch {
  width: 42px; height: 24px; border-radius: 999px; border: none; background: #d8dee1;
  position: relative; cursor: pointer; padding: 0; flex-shrink: 0;
}
.toggle-switch.on { background: var(--turq); }
.toggle-knob {
  position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: left .15s ease; box-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.toggle-switch.on .toggle-knob { left: 21px; }
.automation-info { flex: 1; min-width: 0; }
.automation-label { display: flex; align-items: center; gap: 6px; font-size: 13.5px; color: var(--navy); }
.automation-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ---------- Tâches ---------- */
.task-row {
  display: grid;
  grid-template-columns: 32px 1fr 130px 2fr 110px 32px;
  align-items: center;
  gap: 14px;
  padding: 12px 6px;
  border-bottom: 1px solid var(--border);
}
.task-group { margin-bottom: 6px; }
.task-group-header {
  font-size: 12.5px; font-weight: 600; padding: 10px 4px 6px; display: flex; align-items: center; gap: 7px;
}
.task-group-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.task-group-label { color: var(--text); }
.task-group-count {
  border-radius: 999px; min-width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 11px; padding: 0 6px; font-weight: 700;
}
.task-row:last-child { border-bottom: none; }
.task-row.done .task-client, .task-row.done .task-desc-col { text-decoration: line-through; color: var(--text-muted); }
.task-info { flex: 1; min-width: 0; }
.task-desc { color: var(--navy); font-weight: 600; text-decoration: none; font-size: 13.5px; }
.task-desc:hover { text-decoration: underline; }
.task-row-simple { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--border); }
.task-row-simple:last-child { border-bottom: none; }
.task-row-simple.done .task-desc { text-decoration: line-through; color: var(--text-muted); }
.task-checkbox {
  width: 22px; height: 22px; border-radius: 5px; border: 2px solid var(--border); background: #fff;
  cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 13px; font-weight: 700; padding: 0;
}
.task-checkbox.checked { background: var(--turq); border-color: var(--turq); }
.task-client { color: var(--navy); font-weight: 700; text-decoration: none; font-size: 13.5px; line-height: 1.3; min-width: 0; }
.task-client:hover { text-decoration: underline; }
.task-client-sub { display: block; color: var(--text-muted); font-weight: 500; font-size: 11.5px; }
.task-type-badge { white-space: nowrap; font-size: 11.5px; }
.task-desc-col { font-size: 13.5px; color: var(--text); min-width: 0; }
.task-auto-tag { color: var(--turq); font-size: 11px; font-weight: 700; margin-left: 6px; white-space: nowrap; }
.task-date-col { font-size: 13px; font-weight: 700; color: var(--navy); text-align: right; white-space: nowrap; }
.task-time { display: block; font-weight: 500; color: var(--text-muted); font-size: 11.5px; }
.task-overdue, .task-overdue .task-time { color: var(--danger); }
.task-overdue-tag { font-size: 10.5px; font-weight: 700; color: var(--danger); }
.file-row { display: flex; align-items: center; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.file-row:last-child { border-bottom: none; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; flex-wrap: wrap; }
  .sidebar-nav { flex-direction: row; }
  .contact-shell { flex-direction: column; }
  .contact-subnav { width: 100%; }
}

/* ---------- Calendrier ---------- */
.cal-legend { display: flex; gap: 14px; align-items: center; }
.cal-legend-item { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-muted); font-weight: 600; }
.cal-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 16px; }
.cal-weekday { text-align: center; font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; padding-bottom: 4px; }
.cal-day {
  min-height: 100px; border: 1px solid var(--border); border-radius: 8px; padding: 6px;
  background: #fff; overflow-y: auto; max-height: 150px;
}
.cal-day.empty { background: #fafbfc; border-style: dashed; border-color: #ececec; }
.cal-day.today { border-color: var(--orange); border-width: 2px; background: #fffaf0; }
.cal-daynum { font-size: 12px; font-weight: 700; color: var(--navy); margin-bottom: 4px; }
.cal-day.today .cal-daynum { color: var(--orange); }
.cal-event {
  display: block; font-size: 10.5px; padding: 3px 6px; border-radius: 6px; margin-bottom: 3px;
  color: #fff; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cal-event:hover { opacity: 0.85; }

@media (max-width: 900px) {
  .calendar-grid { grid-template-columns: repeat(7, minmax(60px, 1fr)); overflow-x: auto; }
  .cal-day { min-height: 70px; font-size: 11px; }
}

@media (max-width: 700px) {
  .task-row {
    grid-template-columns: 28px 1fr 32px;
    grid-template-areas: "check client del" ". type ." ". desc ." ". date .";
    row-gap: 4px;
  }
  .task-checkbox { grid-area: check; }
  .task-client { grid-area: client; }
  .task-type-badge { grid-area: type; justify-self: start; }
  .task-desc-col { grid-area: desc; }
  .task-date-col { grid-area: date; text-align: left; }
  .task-row > .subtle-btn { grid-area: del; }
}
