:root {
  --bg: #f4f8fc;
  --surface: #ffffff;
  --border: #dde6ef;
  --text: #1a1a1a;
  --text-muted: #6b7a8c;
  --primary: #5ba8e4;
  --primary-dark: #3a8bcb;
  --primary-soft: #e4f1fb;
  --primary-softer: #f2f8fd;
  --sidebar-bg: #c9e2f6;
  --sidebar-text: #1a1a1a;
  --sidebar-muted: #3f5266;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --success: #1a7f37;
  --success-bg: #e6f4ea;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a {
  color: var(--text);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

/* ---------- Layout ---------- */

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
}

.sidebar .brand {
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0 1.25rem 1rem;
  color: var(--text);
  text-decoration: none;
  display: block;
}
.sidebar .brand:hover {
  color: var(--primary-dark);
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.sidebar nav a {
  color: var(--sidebar-text);
  padding: 0.6rem 1.25rem;
  margin: 0 0.5rem;
  border-radius: 6px;
  display: block;
}
.sidebar nav a:hover {
  background: rgba(255, 255, 255, 0.45);
  text-decoration: none;
}
.sidebar nav a.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(58, 139, 203, 0.15);
  font-weight: 600;
}

.sidebar nav a.sidebar-back {
  color: var(--sidebar-muted);
  font-size: 0.85rem;
  padding-bottom: 0.3rem;
}
.sidebar-patient-name {
  padding: 0.3rem 1.25rem 0.6rem;
  color: var(--text);
  font-weight: 700;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.3rem;
}
.sidebar nav a.sub-item {
  padding-left: 2.1rem;
  font-size: 0.85rem;
}

.sidebar .sidebar-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--sidebar-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.sidebar-user {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Language switch: plain text codes, the current one softly highlighted. */
.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  flex-shrink: 0;
}
.lang-option {
  background: none;
  border: none;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--sidebar-muted);
  cursor: pointer;
}
.lang-option:hover {
  color: var(--sidebar-text);
  background: rgba(255, 255, 255, 0.35);
}
.lang-option.active {
  color: var(--sidebar-text);
  font-weight: 600;
  background: rgba(255, 255, 255, 0.45);
  cursor: default;
}
.lang-sep {
  color: var(--sidebar-muted);
  opacity: 0.6;
  font-size: 0.7rem;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.2rem 1.25rem;
  font-size: 0.82rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar .user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
}

#view {
  padding: 1rem 1.25rem;
  flex: 1;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.patient-banner {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}
.patient-banner-main {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.patient-banner-main strong {
  font-size: 1.05rem;
}
.patient-banner-referents {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
  font-size: 0.82rem;
  flex: 1;
}
.patient-banner #edit-referents-btn {
  margin-left: auto;
}

.page-header h1 {
  font-size: 1.4rem;
  margin: 0;
}

/* ---------- Login ---------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 320px;
}

.login-card h1 {
  margin-top: 0;
  font-size: 1.3rem;
  color: var(--text);
}

/* ---------- Cards / surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

/* ---------- Forms ---------- */

.field {
  margin-bottom: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text);
}

.field input,
.field select,
.field textarea {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.field textarea {
  resize: vertical;
  min-height: 70px;
}

.field-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.field-row > .field {
  flex: 1;
  min-width: 160px;
}

.checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}
.checkbox-field label {
  font-weight: 500;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
}
.btn:hover {
  background: var(--primary-softer);
}
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--text);
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--primary-dark);
}
.btn-danger {
  background: var(--danger-bg);
  border-color: #f3b4ae;
  color: var(--danger);
}
.btn-sm {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
}
.btn-block {
  width: 100%;
  justify-content: center;
}
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* ---------- Tables ---------- */

table.data-table {
  width: 100%;
  border-collapse: collapse;
}
table.data-table th,
table.data-table td {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
table.data-table th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}
table.data-table tbody tr:hover {
  background: var(--primary-softer);
}

.empty-state {
  color: var(--text-muted);
  padding: 2rem;
  text-align: center;
}

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.tabs button,
.tabs a.tab-link {
  background: none;
  border: none;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  color: var(--text-muted);
  font-weight: 500;
  border-bottom: 2px solid transparent;
}
.tabs a.tab-link { text-decoration: none; }
.tabs button.active,
.tabs a.tab-link.active {
  color: var(--text);
  border-bottom-color: var(--primary);
}

/* ---------- Badges ---------- */

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--primary-soft);
  color: var(--text);
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: #fff4e5; color: #92610a; }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 40, 60, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 480px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-box h2 {
  margin-top: 0;
  font-size: 1.1rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

/* ---------- Toasts ---------- */

#toast-root {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  padding: 0.65rem 1rem;
  border-radius: 6px;
  background: var(--text);
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  max-width: 320px;
}
.toast-error { background: var(--danger); }
.toast-success { background: var(--success); }

/* ---------- Misc ---------- */

.muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mt-1 { margin-top: 1rem; }
.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.search-input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  min-width: 240px;
}

/* ---------- Agenda layout (calendar + tasks panel) ---------- */

.agenda-fit {
  display: flex;
  flex-direction: column;
  /* height is set in JS (fitAgendaHeight) to exactly fill the viewport
     below the toolbar, so the week view never needs a page scrollbar. */
}

.agenda-layout {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  flex: 1;
  min-height: 0;
}
.agenda-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.agenda-tasks-panel {
  flex-shrink: 0;
  max-height: 160px;
  overflow-y: auto;
  padding: 0.6rem 1rem;
  margin: 0;
}
.agenda-tasks-panel .task-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  column-gap: 1.25rem;
  margin-top: 0.4rem;
}
.agenda-tasks-panel .task-item:last-child {
  border-bottom: 1px solid var(--border);
}
.task-panel-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.task-panel-header h3 {
  margin-right: auto !important;
}

@media (max-width: 960px) {
  .agenda-fit {
    height: auto !important;
  }
  .cal-toolbar-row {
    flex-wrap: wrap;
  }
  .agenda-tasks-panel {
    max-height: 50vh;
  }
  /* height:auto above leaves the flex column no height to share out:
     flex:1 + min-height:0 (desktop rules) then collapsed the grid to its
     header row, ignoring height:70vh. Fixed size instead of flexing. */
  /* (.agenda-layout > .agenda-main: more specific than the plain
     .cal-grid-wrap rule further down, which would otherwise win.) */
  .agenda-layout {
    flex: none;
  }
  .agenda-layout > .agenda-main {
    flex: none;
    height: 70vh;
  }
}

.task-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.task-item {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.task-item:last-child {
  border-bottom: none;
}
.task-item-done .task-item-title {
  text-decoration: line-through;
  color: var(--text-muted);
}
.task-checkbox {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
  font-size: 0.7rem;
  line-height: 1;
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}
.task-item-body {
  min-width: 0;
}
.task-item-title {
  font-size: 0.85rem;
  font-weight: 500;
}
.task-item-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.task-overdue {
  color: var(--danger);
  font-weight: 600;
}

/* ---------- Calendar (Agenda) ---------- */

/* Two fixed logical rows (nav/selectors, then actions) instead of one row
   that relies on flex-wrap to split itself -- nested flex-wrap made the
   wrap point unpredictable (1-3 lines depending on window width), which
   threw off fitAgendaHeight()'s height budget for the grid below it. */
.cal-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.cal-toolbar-row {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.4rem;
  min-width: 0;
}
.cal-range {
  font-size: 1rem;
  margin: 0 0.4rem;
  white-space: nowrap;
}
.cal-toolbar-row select {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 220px;
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
  text-overflow: ellipsis;
}
.cal-toolbar-row .btn {
  white-space: nowrap;
  flex-shrink: 0;
}
.cal-toolbar-actions {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
}

.cal-legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.cal-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.cal-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.cal-grid-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex: 1;
  min-height: 0;
}
/* #cal-grid-content (direct child, set in agenda.js) has no height of its
   own, so .cal-grid's height:100% would otherwise resolve against an
   auto-height parent (a no-op per spec) and collapse to content size. */
.cal-grid-wrap > div {
  height: 100%;
}

.cal-grid {
  display: grid;
  grid-template-columns: 50px repeat(7, minmax(78px, 1fr));
  grid-template-rows: auto 1fr;
  min-width: 600px;
  height: 100%;
}

.cal-corner {
  grid-column: 1;
  grid-row: 1;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.cal-header-cell {
  grid-row: 1;
  text-align: center;
  padding: 0.5rem 0.25rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--primary-softer);
}
.cal-header-cell.today {
  background: var(--primary-soft);
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 0 -3px 0 var(--primary);
}
.cal-header-cell.today strong {
  color: var(--text);
}

.cal-time-col {
  grid-column: 1;
  grid-row: 2;
  position: relative;
  border-right: 1px solid var(--border);
}
.cal-time-label {
  position: absolute;
  right: 6px;
  transform: translateY(-50%);
  font-size: 0.68rem;
  color: var(--text-muted);
}

.cal-days {
  grid-column: 2 / 9;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.cal-day {
  position: relative;
  border-right: 1px solid var(--border);
  /* background-size (the hour-band height, as a %) is set inline per
     column in JS, since it depends on GRID_TOTAL_HOURS. */
  background-image: linear-gradient(to bottom, var(--border) 1px, transparent 1px);
  background-repeat: repeat-y;
  cursor: pointer;
}
.cal-day:last-child {
  border-right: none;
}
.cal-day-today {
  background-color: rgba(91, 168, 228, 0.13);
}

.cal-appt {
  position: absolute;
  left: 2px;
  right: 2px;
  min-height: 14px;
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 0.72rem;
  line-height: 1.25;
  color: var(--text);
  overflow: hidden;
  cursor: grab;
  border-left: 3px solid rgba(0, 0, 0, 0.18);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
  touch-action: none;
  user-select: none;
}
.cal-appt-time {
  font-size: 10.5px;
  font-weight: 400;
  line-height: 1.3;
  opacity: 0.75;
}
.cal-appt-label {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-appt-video {
  width: 1.05em;
  height: 1.05em;
  margin-right: 0.25em;
  vertical-align: -0.15em;
  fill: currentColor;
  opacity: 0.8;
}
.cal-appt-short {
  display: flex;
  align-items: baseline;
  gap: 0.3rem;
  padding-top: 1px;
  padding-bottom: 0;
}
.cal-appt-short .cal-appt-time {
  flex-shrink: 0;
}
.cal-appt-short .cal-appt-label {
  flex: 1;
  min-width: 0;
}
.cal-appt-cancelled {
  opacity: 0.5;
  text-decoration: line-through;
}
.cal-appt-dragging {
  opacity: 0.85;
  cursor: grabbing;
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}
.cal-appt-resize {
  position: absolute;
  left: 0;
  right: 0;
  height: 6px;
  cursor: ns-resize;
}
.cal-appt-resize-top {
  top: 0;
}
.cal-appt-resize-bottom {
  bottom: 0;
}

.context-menu {
  position: fixed;
  z-index: 150;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  padding: 0.25rem;
  min-width: 180px;
  display: flex;
  flex-direction: column;
}
.context-menu[hidden] {
  display: none;
}
.context-menu-item {
  text-align: left;
  background: none;
  border: none;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text);
}
.context-menu-item:hover {
  background: rgba(91, 168, 228, 0.08);
}
.context-menu-item.danger {
  color: var(--danger);
}
.context-menu-item.danger:hover {
  background: rgba(179, 38, 30, 0.08);
}

.cal-now-line {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 2px solid var(--danger);
  z-index: 5;
  pointer-events: none;
}
.cal-now-dot {
  position: absolute;
  left: -4px;
  top: -5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
}

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; }
  .sidebar nav { flex-direction: row; overflow-x: auto; }
}

/* ---------- Paramètres > Durées par praticien ---------- */

.duration-row {
  display: grid;
  grid-template-columns: 12px 220px 90px auto;
  justify-content: start;
  align-items: center;
  gap: 0.6rem;
  padding: 0.2rem 0;
}
.duration-row input {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
}

/* ---------- Patient chart: denser layout + tasks column ---------- */

.patient-banner {
  margin-bottom: 0.75rem;
}
.patient-banner-actions {
  margin-left: auto;
  display: flex;
  gap: 0.4rem;
}
.patient-banner #edit-referents-btn {
  margin-left: 0;
}

.patient-layout {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}
.patient-main {
  flex: 1;
  min-width: 0;
}
.patient-aside {
  width: 270px;
  flex-shrink: 0;
  position: sticky;
  top: 0.75rem;
}

.dense .card {
  padding: 0.8rem 1rem;
  margin-bottom: 0.75rem;
}
.dense h3 {
  margin: 0 0 0.55rem;
  font-size: 1rem;
}
.dense .field {
  margin-bottom: 0.55rem;
  gap: 0.2rem;
}
.dense .field label {
  font-size: 0.8rem;
}
.dense .field input,
.dense .field select,
.dense .field textarea {
  padding: 0.38rem 0.55rem;
}
.dense .field-row {
  gap: 0.6rem;
}
.dense .data-table th,
.dense .data-table td {
  padding: 0.4rem 0.5rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 0.75rem;
  align-items: start;
}
.card-grid > .card,
.card-grid > div > .card {
  margin-bottom: 0;
}

.mt-05 { margin-top: 0.5rem; }
.nowrap { white-space: nowrap; }

.timeline-table tbody tr[data-consultation]:hover,
.timeline-table tbody tr[data-download]:hover,
.timeline-table tbody tr[data-prescription]:hover {
  background: var(--primary-softer);
}
.timeline-next {
  background: var(--success-bg);
}
/* Past consultation without a report (patients.js). */
.timeline-table tbody tr.tl-missing { background: #fdecec; }
.timeline-table tbody tr.tl-missing:hover { background: #fadada; }
.tl-missing-actions { display: inline-flex; gap: 0.35rem; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.timeline-table tbody tr.tl-unbilled:not(.tl-missing) { background: #fff3e0; }
.timeline-table tbody tr.tl-unbilled:not(.tl-missing):hover { background: #ffe8c7; }
.badge-unbilled { background: #fff3e0; color: #9a4b00; border: 1px solid #f5c98b; cursor: pointer; margin-left: 0.4rem; font-size: 0.75rem; vertical-align: middle; }
.btn-tardoc { background: #fff3e0; border-color: #f0a640; color: #8a4500; }
.btn-tardoc:hover { background: #ffe0b2; }
.badge-missing { background: #fdecec; color: #a12b2b; border: 1px solid #f3b9b9; cursor: pointer; margin-left: 0.4rem; font-size: 0.75rem; vertical-align: middle; }
@keyframes tl-flash { 0%, 100% { box-shadow: none; } 30%, 70% { box-shadow: inset 0 0 0 2px #d9534f; } }
.tl-flash { animation: tl-flash 1.4s ease 2; }

.patient-tasks-box.has-tasks {
  border-color: #f0c36d;
  background: #fffbf0;
}
.alert-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  background: #e8a317;
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
  margin-right: 0.4rem;
}
.task-item-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: pre-wrap;
}

.plain-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.plain-list li {
  padding: 0.15rem 0;
}
.link-btn {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--primary);
  cursor: pointer;
}

/* École / Professionnel */
.extra-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 2fr auto;
  gap: 0.4rem;
  margin-bottom: 0.35rem;
}
.extra-row input {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.contact-block {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.6rem 0.5rem;
  margin-bottom: 0.5rem;
  background: var(--primary-softer);
}
.contact-extras {
  margin-bottom: 0.3rem;
}

/* Fiche praticien */
.plain-fieldset {
  border: none;
  padding: 0;
  margin: 0;
  min-width: 0;
}
.tag-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.3rem;
}
.tag-choice {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500 !important;
  cursor: pointer;
  background: var(--surface);
}
.tag-choice:has(input:checked) {
  background: var(--primary-soft);
  border-color: var(--primary);
}
.tag-choice input {
  margin: 0;
}
.dense .card-grid {
  margin-bottom: 0.75rem;
}

@media (max-width: 1100px) {
  .patient-layout {
    flex-direction: column-reverse;
  }
  .patient-aside {
    width: 100%;
    position: static;
  }
}

/* ---------- Consultation window: transcription + report tabs ---------- */

.modal-box.modal-wide {
  max-width: 960px;
  width: 100%;
}
.consult-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.6rem;
}
.consult-tab {
  background: none;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.consult-tab.active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  font-weight: 600;
  margin-bottom: -1px;
}
.consult-tab:hover {
  color: var(--text);
}
.consult-add #consult-add-btn {
  font-weight: 700;
}
.consult-panel textarea {
  font-family: inherit;
  line-height: 1.45;
}
.report-text {
  white-space: pre-wrap;
  line-height: 1.45;
  max-height: 60vh;
  overflow-y: auto;
  padding: 0.75rem;
  background: var(--primary-softer);
  border-radius: 6px;
}
.timeline-digest td {
  background: var(--primary-softer);
}

/* ---------- Generated documents ---------- */

.form-review {
  max-height: 55vh;
  overflow-y: auto;
  padding-right: 0.4rem;
}
.form-review-check {
  display: flex;
  gap: 0.4rem;
  align-items: flex-start;
  margin: 0.3rem 0;
  font-size: 0.88rem;
}
.form-fields-table td {
  vertical-align: top;
  font-size: 0.82rem;
}
.form-fields-table select,
.form-fields-table input {
  width: 100%;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 5px;
}

/* ---------- Tableau de bord ---------- */

.dash-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.dash-header-right {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.dash-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.75rem;
  font-size: 0.85rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.dash-chip:hover {
  background: var(--primary-softer);
}
.dash-chip.warn {
  background: #fff4e0;
  border-color: #f0c98a;
}
.dash-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}
@media (max-width: 960px) {
  .dash-grid {
    grid-template-columns: 1fr;
  }
}
.dash-col > .card {
  margin-bottom: 1rem;
}
.dash-agenda,
.dash-tasks {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
}
.dash-appt {
  display: grid;
  grid-template-columns: 4px 52px 1fr auto;
  gap: 0.6rem;
  align-items: center;
  padding: 0.45rem 0.5rem 0.45rem 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.dash-appt:hover {
  background: var(--primary-softer);
}
.dash-appt.past {
  opacity: 0.6;
}
.dash-appt.current {
  background: var(--primary-soft);
}
.dash-appt-bar {
  align-self: stretch;
  border-radius: 2px;
}
.dash-appt-time {
  font-size: 0.85rem;
  line-height: 1.25;
  text-align: right;
}
.dash-appt-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.dash-appt-main strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dash-appt-main .muted {
  font-size: 0.8rem;
}
.dash-now {
  position: relative;
  border-top: 2px solid var(--danger);
  margin: 2px 0;
  height: 0;
}
.dash-now span {
  position: absolute;
  left: 0;
  top: -0.7rem;
  background: var(--danger);
  color: #fff;
  font-size: 0.7rem;
  padding: 0 0.3rem;
  border-radius: 3px;
}
.dash-tasks li {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}
.dash-tasks li:last-child {
  border-bottom: none;
}
.dash-tasks input[type="checkbox"] {
  margin-top: 0.2rem;
}
.text-warning { color: #b45309; }
.text-danger {
  color: var(--danger);
  font-weight: 600;
}

/* ---------- Pagination ---------- */

.pager {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.4rem;
  margin: 0.4rem 0;
  font-size: 0.85rem;
}
.pager select {
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 0.85rem;
}

/* ---------- Mon compte: signature / tampon ---------- */

.signature-card {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  justify-content: space-between;
}
.signature-card > div:first-child {
  flex: 1;
  min-width: 0;
}
.signature-preview {
  flex-shrink: 0;
  width: 260px;
  height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  /* checkerboard: shows that the background is really transparent */
  background-color: #fff;
  background-image: linear-gradient(45deg, #eef1f4 25%, transparent 25%), linear-gradient(-45deg, #eef1f4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef1f4 75%), linear-gradient(-45deg, transparent 75%, #eef1f4 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.signature-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}
@media (max-width: 700px) {
  .signature-card {
    flex-direction: column;
    align-items: stretch;
  }
  .signature-preview {
    width: 100%;
  }
}

/* ---------- Messagerie (Roundcube embedded) ---------- */

.mail-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}
.mail-accounts {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}
.mail-account-tab {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text);
}
.mail-account-tab.active {
  background: var(--primary-soft);
  border-color: var(--primary);
  font-weight: 600;
}
.mail-toolbar-actions {
  display: flex;
  gap: 0.4rem;
}
.mail-frame-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}
.mail-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
.mail-frame-wrap {
  position: relative;
}
.mail-frame.loading {
  visibility: hidden;
}
.mail-splash {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  z-index: 1;
}
.mail-splash-inner {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
}
.mail-splash-icon {
  font-size: 2.4rem;
  color: var(--primary);
  animation: mail-splash-pulse 1.6s ease-in-out infinite;
}
.mail-splash-title {
  font-weight: 600;
  font-size: 1.05rem;
}
.mail-splash-bar {
  width: 180px;
  height: 4px;
  border-radius: 2px;
  background: var(--primary-soft);
  overflow: hidden;
  margin-top: 0.5rem;
}
.mail-splash-bar span {
  display: block;
  width: 40%;
  height: 100%;
  border-radius: 2px;
  background: var(--primary);
  animation: mail-splash-slide 1.2s ease-in-out infinite;
}
@keyframes mail-splash-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}
@keyframes mail-splash-pulse {
  0%, 100% { opacity: 0.55; transform: scale(0.96); }
  50% { opacity: 1; transform: scale(1); }
}
.row-muted td {
  opacity: 0.55;
}
.rule-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 1rem;
  margin: 0.4rem 0;
}
.rule-patient {
  margin-left: 1.5rem;
}
.rule-patient-results {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  margin-top: 0.3rem;
}
.rule-activity td {
  vertical-align: top;
}
@media (max-width: 640px) {
  .rule-options {
    grid-template-columns: 1fr;
  }
}
.mail-presets {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.signature-preview-box {
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  background: #fff;
  min-height: 2.2rem;
}
.mail-test-result {
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  margin: 0.5rem 0;
  font-size: 0.85rem;
  background: var(--primary-softer);
  word-break: break-word;
}
.mail-test-result.ok {
  background: #e8f5e9;
  color: #1b5e20;
}
.mail-test-result.error {
  background: #fdecea;
  color: #8a1c14;
}

/* ---------- Notifications ---------- */

.bell {
  position: relative;
}
.bell-btn {
  background: none;
  border: none;
  cursor: pointer;
  position: relative;
  padding: 0.15rem 0.35rem;
  font-size: 1.05rem;
  line-height: 1;
}
.bell-count {
  position: absolute;
  top: -0.3rem;
  right: -0.35rem;
  background: var(--primary);
  color: #fff;
  font-size: 0.66rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 0.05rem 0.35rem;
  min-width: 1rem;
  text-align: center;
}
.bell-count.urgent {
  background: var(--danger);
}
.bell-panel {
  position: absolute;
  right: 0;
  top: 1.9rem;
  width: 380px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 120;
  color: var(--text);
}
.bell-panel[hidden] {
  display: none;
}
.bell-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.bell-list {
  overflow-y: auto;
}
.bell-item {
  display: flex;
  gap: 0.5rem;
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.85rem;
}
.bell-item:hover {
  background: var(--primary-softer);
}
.bell-item.unread {
  background: var(--primary-soft);
}
.bell-item.urgent .bell-kind {
  color: var(--danger);
}
.bell-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.bell-body {
  color: var(--text-muted);
  font-size: 0.8rem;
}
.bell-meta {
  font-size: 0.72rem;
}
.bell-dismiss {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  align-self: flex-start;
}
.bell-title {
  text-decoration: none;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
}
.bell-title:hover {
  color: var(--primary);
  text-decoration: underline;
}
.bell-item.read .bell-text strong {
  font-weight: 500;
}
.bell-item.read {
  opacity: 0.85;
}
.bell-all-list .bell-list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 65vh;
}
.bell-all-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.5rem;
}
.bell-empty {
  padding: 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.notify-recipients {
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.6rem;
}
.notify-recipients .check,
.notif-settings .check {
  display: block;
  padding: 0.25rem 0;
}
.inline-num {
  width: 4rem;
  padding: 0.15rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 5px;
}
.banner-followup {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}
.followup-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.78rem;
  cursor: pointer;
  background: #e8f5e9;
}
.followup-pill.status-paused {
  background: #fff4e0;
}
.followup-pill.status-ended {
  background: #eceff1;
}
@media (max-width: 600px) {
  .bell-panel {
    width: calc(100vw - 2rem);
    right: -4rem;
  }
}

#rule-form label.check {
  display: flex;
  gap: 0.4rem;
  align-items: flex-start;
  margin: 0.25rem 0;
}
#rule-form label.check input {
  margin-top: 0.2rem;
}
.rule-patient[hidden] {
  display: none;
}

/* ---- Patient chart: growth curves ("Courbes") ---- */
.growth-layout { display: grid; grid-template-columns: minmax(330px, 420px) minmax(0, 1fr); gap: 12px; margin-top: 10px; align-items: start; }
@media (max-width: 1100px) { .growth-layout { grid-template-columns: 1fr; } }
.growth-side { display: flex; flex-direction: column; gap: 10px; }
.growth-side .card, .growth-main.card { margin: 0; }
.growth-layout .small { font-size: 12px; }
.growth-layout .flex-gap, .flex-between .flex-gap { display: inline-flex; gap: 6px; align-items: center; }
.growth-entry-row { display: grid; grid-template-columns: 1.35fr 1fr 1fr .8fr; gap: 6px; }
.growth-entry-row label, .growth-profile-row label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-muted); min-width: 0; }
.growth-entry-row input, .growth-profile-row input { width: 100%; min-width: 0; padding: 5px 6px; font-size: 14px; }
.growth-bmi { display: block; padding: 6px 4px; font-size: 14px; font-weight: 600; color: var(--text); }
.growth-entry-actions { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; min-height: 30px; }
.growth-profile-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 6px; margin-bottom: 6px; }
.growth-table-card { padding: 4px 6px; max-height: 420px; overflow: auto; }
.growth-table { font-size: 13px; }
.growth-table td, .growth-table th { padding: 5px 6px; white-space: nowrap; }
.growth-table tbody tr { cursor: pointer; }
.growth-table tbody tr:hover { background: var(--primary-softer); }
.growth-table tbody tr.editing { background: var(--primary-soft); }
.growth-z { display: block; font-size: 11px; color: var(--text-muted); }
.growth-z.growth-out { color: var(--danger); font-weight: 600; }
.growth-table .icon-btn { border: 0; background: none; color: var(--text-muted); cursor: pointer; font-size: 15px; padding: 0 4px; border-radius: 4px; }
.growth-table .icon-btn:hover { color: var(--danger); background: var(--danger-bg); }
.growth-table .icon-btn.danger { color: #fff; background: var(--danger); font-size: 11px; padding: 2px 6px; }
.growth-toolbar { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.growth-toolbar .seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.growth-toolbar .seg button { border: 0; background: var(--surface); padding: 5px 14px; font: inherit; font-size: 13px; cursor: pointer; color: var(--text); }
.growth-toolbar .seg button + button { border-left: 1px solid var(--border); }
.growth-toolbar .seg button.active { background: var(--primary); color: #fff; font-weight: 600; }
.growth-chart { position: relative; }
.growth-chart svg { display: block; width: auto; max-width: 100%; height: calc(100vh - 250px); min-height: 560px; margin: 0 auto; box-shadow: 0 1px 6px rgba(0,0,0,.12); }
.growth-tip { position: absolute; z-index: 5; background: #222; color: #fff; font-size: 12px; line-height: 1.4; padding: 5px 8px; border-radius: 5px; pointer-events: none; white-space: nowrap; }
.growth-layout [hidden] { display: none !important; }
.growth-main.card { position: sticky; top: 8px; }

/* ---- Diagnoses: banner chips + Médical card ---- */
.patient-banner-dx { flex-basis: 100%; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding-top: 8px; margin-top: -2px; border-top: 1px solid var(--border); font-size: 0.82rem; }
.patient-banner-dx:empty { display: none; }
.dx-label { margin-right: 2px; }
.dx-empty { font-size: 0.82rem; }
.dx-chip { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; padding: 2px 4px 2px 8px; border: 1px solid var(--border); border-radius: 999px; background: var(--primary-softer); cursor: pointer; line-height: 1.5; }
.dx-chip:hover { border-color: var(--primary); }
.dx-chip .dx-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 32ch; }
.dx-chip.primary { background: var(--primary-soft); border-color: var(--primary); font-weight: 600; }
.dx-chip.suggested { background: #fffbea; border: 1px dashed #d4a72c; font-style: italic; font-weight: 400; }
.dx-star { color: #d4a72c; }
.dx-code { display: inline-block; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.78rem; font-style: normal; font-weight: 600; padding: 0 5px; border-radius: 4px; background: #fff; border: 1px solid var(--border); color: #2b4a66; }
.dx-code.dsm, .dx-dsm { color: #6a3fa0; }
.dx-dsm { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.74rem; font-style: normal; opacity: .85; padding-right: 4px; }
.dx-unvalidated { font-size: 0.72rem; font-style: normal; font-weight: 600; color: #8a6100; background: #fdf0c2; border-radius: 4px; padding: 0 5px; }
.dx-validate { border: 0; background: var(--success); color: #fff; width: 20px; height: 20px; border-radius: 50%; font-size: 12px; line-height: 20px; padding: 0; cursor: pointer; flex: 0 0 auto; }
.dx-validate:hover { filter: brightness(1.15); }
#diagnoses-card .dx-head-actions { display: inline-flex; gap: .4rem; align-items: center; }
.dx-list { list-style: none; margin: .6rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.dx-row { display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.dx-row.primary { border-color: var(--primary); background: var(--primary-softer); }
.dx-row.suggested { border-style: dashed; border-color: #d4a72c; background: #fffdf3; }
.dx-row.dragging { opacity: .45; }
.dx-row.drop-before { box-shadow: 0 -3px 0 var(--primary); }
.dx-row.drop-after { box-shadow: 0 3px 0 var(--primary); }
.dx-handle { cursor: grab; color: var(--text-muted); user-select: none; padding-top: 2px; letter-spacing: -2px; }
.dx-body { flex: 1; min-width: 0; }
.dx-line1 { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.dx-line2, .dx-line3 { font-size: 0.8rem; margin-top: 2px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.dx-line3:empty { display: none; }
.dx-rank { font-size: 0.7rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600; }
.dx-row.primary .dx-rank { color: var(--primary-dark); }
.dx-actions { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.dx-icon { border: 1px solid transparent; background: none; color: var(--text-muted); cursor: pointer; border-radius: 5px; padding: 1px 6px; font-size: 14px; }
.dx-icon:hover:not(:disabled) { background: var(--primary-softer); border-color: var(--border); color: var(--text); }
.dx-icon:disabled { opacity: .3; cursor: default; }
.dx-icon.danger:hover { color: var(--danger); background: var(--danger-bg); }
.dx-icon.confirm { color: #fff; background: var(--danger); font-size: 11px; }
.dx-primary-btn { color: #c9ccd1; font-size: 16px; padding-top: 0; }
.dx-primary-btn.on { color: #d4a72c; }
.dx-link { border: 0; background: none; color: var(--primary-dark); cursor: pointer; padding: 0; font-size: 0.78rem; text-decoration: underline; }
.dx-add { margin-top: .6rem; padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--primary-softer); display: flex; flex-direction: column; gap: 6px; }
.dx-add label { display: flex; flex-direction: column; gap: 3px; font-size: 0.8rem; color: var(--text-muted); }
.dx-search { position: relative; display: block; }
.dx-search input { width: 100%; }
.dx-line2 .dx-search { flex: 1; min-width: 220px; }
.dx-results { position: absolute; z-index: 30; left: 0; right: 0; top: 100%; margin: 2px 0 0; padding: 4px 0; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.12); max-height: 300px; overflow: auto; }
.dx-results[hidden] { display: none; }
.dx-results li { padding: 5px 10px; cursor: pointer; font-size: 0.85rem; color: var(--text); }
.dx-results li.active, .dx-results li:hover { background: var(--primary-soft); }
.dx-picked { font-size: 0.85rem; min-height: 1.2em; }
.dx-add-actions { display: flex; justify-content: flex-end; gap: 6px; }

/* AI draft: passages found in none of the sources, "à vérifier" */
.flag-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  margin: 0 0 0.4rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid #f0c36d;
  border-radius: 6px;
  background: #fff8e6;
  font-size: 0.8rem;
}
.flag-bar[hidden] {
  display: none;
}
.flag-title {
  color: #8a5a00;
  font-weight: 600;
  margin-right: 0.2rem;
}
.flag-chip {
  border: 1px solid #f0c36d;
  border-radius: 999px;
  background: #ffe9a8;
  padding: 0.05rem 0.5rem;
  font-size: 0.8rem;
  cursor: pointer;
}
.flag-chip:hover {
  background: #ffd970;
}
.flag-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  background: white;
  border-radius: 6px;
}
.flag-wrap > textarea {
  position: relative;
  z-index: 1;
  background: transparent !important;
}
.flag-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  color: transparent;
  border: 1px solid transparent;
  padding: 0.5rem 0.6rem;
  font-family: inherit;
  font-size: inherit;
  line-height: 1.45;
  pointer-events: none;
}
.flag-backdrop mark {
  color: transparent;
  background: #ffe066;
  border-radius: 2px;
  box-shadow: 0 0 0 1px #f0b400;
}

/* ---------- Patient autocomplete (appointment window) ---------- */
.patient-ac {
  position: relative;
}
.patient-ac input {
  width: 100%;
}
.patient-ac-list {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
}
.patient-ac-item {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
}
.patient-ac-item.active,
.patient-ac-item:hover {
  background: var(--primary-soft);
}
.patient-ac-empty {
  padding: 0.4rem 0.6rem;
}

/* The hidden attribute must win over component display rules (.field is
   display:flex, which otherwise keeps "hidden" fields on screen). */
[hidden] {
  display: none !important;
}

/* Hover preview of the quarter hour a click on the agenda will book. */
.cal-slot-hover {
  position: absolute;
  left: 2px;
  right: 2px;
  pointer-events: none;
  border-top: 2px solid var(--primary);
  background: var(--primary-soft);
  opacity: 0.85;
  font-size: 0.68rem;
  line-height: 1;
  padding: 1px 4px;
  color: var(--text);
  border-radius: 0 0 3px 3px;
  z-index: 1;
  overflow: visible;
  white-space: nowrap;
}

/* "Rendez-vous en visio" checkbox under the type select. */
.checkbox-inline {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 400;
  margin-top: 0.35rem;
  cursor: pointer;
}
.checkbox-inline input {
  width: auto;
  margin: 0;
}

/* Appointment selected by a single click (double click opens the chart). */
.cal-appt.cal-appt-selected {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  z-index: 3;
}

/* Two overlapping appointments of the same practitioner. Inset so the
   selection outline stays visible around it. */
.cal-appt.cal-appt-conflict {
  box-shadow: inset 0 0 0 2px var(--danger), 0 1px 2px rgba(0, 0, 0, 0.12);
  border-left-color: var(--danger);
}

/* Sidebar: practitioner's own space (title + indented items), then tools. */
.sidebar-group-title {
  padding: 0.5rem 1.25rem 0.25rem;
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Facturation: relevé des prestations TARDOC, factures XML. */
.billing-help { font-size: 0.82rem; margin-top: 0.8rem; line-height: 1.45; }
.billing-mode { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.2rem; }
.billing-mode label { display: inline-flex; align-items: center; gap: 0.35rem; cursor: pointer; font-weight: normal; }
.billing-mode.to-patient { background: #fff3e0; border-color: #f5c98b; }
.billing-practitioners { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; }
.billing-check { display: inline-flex; align-items: center; gap: 0.3rem; font-weight: normal; cursor: pointer; white-space: nowrap; }
.billing-filters .btn-link { background: none; border: 0; padding: 0; color: var(--primary, #2563eb); cursor: pointer; font-size: 0.8rem; font-weight: normal; }
.billing-presets { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.6rem; }
.billing-filters .field-row { flex-wrap: wrap; }
.billing-summary { align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.billing-warning { background: #fdecec; border: 1px solid #f3b4b4; color: #8a1f1f; padding: 0.4rem 0.6rem; border-radius: 6px; }
.billing-table td { vertical-align: top; }
.billing-table tr.billing-group td { border-top: 2px solid var(--border); }
.billing-table tr.billing-missing { background: #fdecec; }
.billing-label { font-size: 0.8rem; max-width: 22rem; }
.tardoc-defaults h4 { margin: 0.8rem 0 0.3rem; font-size: 0.85rem; color: var(--muted, #666); }
.tardoc-default-row { display: grid; grid-template-columns: 1fr 5.5rem 4.5rem; gap: 0.5rem; align-items: center; padding: 0.15rem 0; font-size: 0.88rem; }
.tardoc-default-row input { width: 100%; }

/* Admins only: the practice's administration, set apart at the bottom. */
.sidebar-admin {
  margin: 0.9rem 0.6rem 0;
  padding: 0.2rem 0 0.4rem;
  border-top: 2px solid var(--sidebar-muted);
  background: rgba(255, 255, 255, 0.35);
  border-radius: 0 0 6px 6px;
}
.sidebar-admin .sidebar-group-title {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.75rem;
  color: var(--sidebar-muted);
}
.sidebar-separator {
  border-top: 1px solid var(--border);
  margin: 0.6rem 1rem;
}

/* Global patient search in the topbar. */
.patient-search {
  position: relative;
  width: min(340px, 45vw);
}
.patient-search input {
  width: 100%;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  background: var(--bg, #fff);
}
.patient-search .patient-ac-list {
  z-index: 50;
}

/* Tabs of a chart section, across the top of the main window. */
.chart-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}
.chart-tab {
  padding: 0.45rem 0.9rem;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: -1px;
}
.chart-tab:hover {
  color: var(--text);
  text-decoration: none;
  background: var(--primary-softer);
}
.chart-tab.active {
  color: var(--text);
  font-weight: 600;
  background: var(--surface);
  border-color: var(--border);
}

/* Notification box: "re-scan now" buttons. */
.bell-scan {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--border);
}
.bell-scan .btn {
  font-size: 0.78rem;
}

/* Chart timeline: "+" unfolds a row's content in place. */
.timeline-table .tl-toggle {
  width: 1.8rem;
  padding-right: 0;
}
.tl-expand {
  width: 1.4rem;
  height: 1.4rem;
  line-height: 1;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface, #fff);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}
.tl-expand:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.timeline-table tr.tl-detail td {
  background: var(--bg, #f7f8fa);
  cursor: default;
}
.tl-detail-block + .tl-detail-block {
  margin-top: 0.75rem;
}
.tl-detail-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.tl-detail-text {
  white-space: pre-wrap;
  font-size: 0.85rem;
  line-height: 1.45;
  max-height: 28rem;
  overflow: auto;
}

/* Document viewer (PDF / images / text), above any open window. */
.viewer-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2vh 2vw;
}
.viewer-box {
  background: var(--surface);
  border-radius: 8px;
  width: min(1100px, 100%);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}
.viewer-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.viewer-actions {
  display: flex;
  gap: 0.4rem;
  flex: none;
}
.viewer-content {
  flex: 1;
  min-height: 0;
  background: var(--bg);
}
.viewer-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
.viewer-image {
  width: 100%;
  height: 100%;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.viewer-image img {
  max-width: 100%;
  max-height: 100%;
  cursor: zoom-in;
}
.viewer-image img.zoomed {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
}
.viewer-text {
  margin: 0;
  padding: 1rem;
  height: 100%;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 0.85rem;
}

/* Prescription editor */
.rx-modal.modal-box {
  width: min(980px, 96vw);
  max-width: none;
}
.rx-head {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-end;
}
.rx-head .rx-template-field {
  margin-left: auto;
}
.rx-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.6rem;
  background: var(--surface);
}
.rx-item-head {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}
.rx-item-head .rx-search-wrap,
.rx-item-head .rx-label {
  flex: 1;
  min-width: 0;
}
.rx-item-head .rx-drug,
.rx-item-head .rx-label {
  width: 100%;
  font-weight: 600;
}
.rx-search-wrap {
  position: relative;
}
.rx-results {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: calc(100% + 2px);
  max-height: 320px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}
.rx-result {
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}
.rx-result:hover,
.rx-result.active {
  background: var(--bg);
}
.rx-result.rx-narcotic {
  opacity: 0.75;
  cursor: not-allowed;
}
.rx-narcotic-note {
  color: var(--danger);
  font-weight: 600;
  font-size: 0.78rem;
}
.rx-result-empty {
  padding: 0.5rem 0.6rem;
}
.rx-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: flex-end;
  margin-top: 0.4rem;
}
.rx-grid .field {
  flex: 1 1 10rem;
  margin: 0;
}
.rx-grid .rx-narrow {
  flex: 0 1 7rem;
}
.rx-grid .rx-prn-text {
  flex: 1 1 16rem;
}
.rx-poso {
  margin-top: 0.5rem;
  padding: 0.4rem 0.5rem;
  background: var(--bg);
  border-radius: 6px;
}
.rx-mode {
  display: flex;
  gap: 0.75rem;
  font-size: 0.82rem;
}
.rx-steps {
  width: 100%;
  border-collapse: collapse;
  margin: 0.35rem 0;
}
.rx-steps th {
  font-size: 0.75rem;
  font-weight: 600;
  text-align: left;
  color: var(--text-muted, #667);
  padding: 0 0.25rem;
}
.rx-steps td {
  padding: 0.15rem 0.25rem;
}
.rx-steps input {
  width: 100%;
  min-width: 3rem;
}
.rx-steps .rx-days {
  max-width: 6rem;
}
.rx-times {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.rx-time {
  display: inline-flex;
  gap: 0.2rem;
}
.rx-time input[type="time"] {
  width: 6.5rem;
}
.rx-time input:not([type]) {
  width: 5rem;
}
.rx-item > .rx-instructions {
  width: 100%;
  margin-top: 0.4rem;
}
.rx-save-template {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.5rem;
}
.rx-save-template[hidden] {
  display: none;
}
.rx-lines {
  font-size: 0.8rem;
  font-style: italic;
}

/* Emails in the chart timeline */
.badge.badge-email {
  background: #e3effa;
  color: #1d5a8c;
}
.email-meta {
  font-size: 0.85rem;
  display: grid;
  gap: 0.15rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.5rem;
}
.email-body {
  white-space: pre-wrap;
  font-size: 0.88rem;
  line-height: 1.45;
  max-height: 60vh;
  overflow: auto;
}
.rx-duration-input {
  display: inline-flex;
  gap: 0.25rem;
  width: 100%;
}
.rx-duration-input input {
  width: 4.5rem;
  min-width: 3.5rem;
  flex: none;
}
.rx-duration-input select {
  flex: 1;
  min-width: 5.5rem;
}
.rx-grid .rx-duration-field {
  flex: 0 1 13rem;
}
.rx-steps td.rx-step-duration {
  width: 12rem;
}


/* Exam results (labs.js) */
.labs-table .labs-date {
  border: 1px solid transparent;
  background: transparent;
  padding: 0.1rem 0.2rem;
  font: inherit;
}
.labs-table .labs-date:hover,
.labs-table .labs-date:focus {
  border-color: var(--border);
}
.badge.labs-kind-lab { background: #e6f2ea; color: #23633a; }
.badge.labs-kind-ecg { background: #fbe9e9; color: #8a2b2b; }
.badge.labs-kind-imaging { background: #ece8f7; color: #4b3a8a; }
.labs-values {
  border-collapse: collapse;
  font-size: 0.84rem;
  margin-top: 0.4rem;
}
.labs-values td {
  padding: 0.12rem 0.75rem 0.12rem 0;
}
.labs-val {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
tr.labs-out .labs-val,
tr.labs-out td:first-child {
  color: var(--danger);
}
.labs-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}
.labs-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text);
}
.labs-chip.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}
.labs-chip.active .muted {
  color: rgba(255, 255, 255, 0.85);
}
.labs-count {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-left: 0.15rem;
}
.labs-chart-title {
  margin-bottom: 0.25rem;
}
.labs-chart {
  width: 100%;
  max-width: 760px;
  height: auto;
  display: block;
}
.labs-band { fill: rgba(46, 160, 67, 0.12); }
.labs-grid { stroke: var(--border); stroke-width: 1; }
.labs-axis { font-size: 11px; fill: #7a8794; }
.labs-line { fill: none; stroke: var(--primary); stroke-width: 2; }
.labs-point { fill: var(--surface); stroke: var(--primary); stroke-width: 2; }
.labs-point.out { stroke: var(--danger); fill: var(--danger); }
.labs-series {
  max-width: 520px;
  margin-top: 0.75rem;
}

.labs-filename {
  font-size: 0.75rem;
}

/* Cotation TARDOC (tardoc.js) */
.tardoc-box {
  margin-top: 0.75rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}
.tardoc-acts {
  width: 100%;
  border-collapse: collapse;
  margin: 0.4rem 0;
  font-size: 0.85rem;
}
.tardoc-acts td {
  padding: 0.2rem 0.4rem 0.2rem 0;
  border-bottom: 1px solid var(--border);
}
.tardoc-add {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  margin-top: 0.4rem;
}
.tardoc-add .tardoc-entry {
  flex: 1;
  min-width: 0;
}
.tardoc-minutes {
  width: 15rem;
  flex: none;
}
.tardoc-minutes input {
  width: 6rem;
}
.tardoc-limit {
  font-size: 0.75rem;
  margin-top: 0.15rem;
  line-height: 1.3;
}
.tardoc-limit.tardoc-over {
  color: var(--danger);
  font-weight: 600;
}
.tardoc-meta {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 0.4rem;
  font-size: 0.8rem;
}
.tardoc-meta input,
.tardoc-meta select {
  font-size: 0.8rem;
  padding: 0.1rem 0.3rem;
}
.tardoc-note {
  font-size: 0.78rem;
  margin-top: 0.3rem;
}

.pmail-ph {
  cursor: pointer;
  border: none;
  margin: 0.1rem 0;
  font-family: inherit;
}

/* Atelier IA */
.ailab-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
}
@media (max-width: 1100px) {
  .ailab-grid { grid-template-columns: 1fr; }
}
.ailab-col textarea {
  width: 100%;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.8rem;
}
.ailab-params {
  align-items: flex-end;
}
.ailab-output {
  width: 100%;
  font-size: 0.88rem;
  line-height: 1.45;
}
.ailab-warning {
  color: var(--danger);
  font-weight: 600;
}
.ailab-cmp {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

/* ---------- Heidi guide (scribe.js) ---------- */

.scribe-guide {
  position: fixed;
  left: 1rem;
  bottom: 1rem;
  z-index: 1500;
  width: min(380px, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  font-size: 0.85rem;
}
.scribe-guide-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; padding: 0.5rem 0.75rem; background: var(--primary-softer); border-bottom: 1px solid var(--border); }
.scribe-guide-body { padding: 0.5rem 0.75rem 0.75rem; }
.scribe-guide ol { margin: 0.25rem 0 0.5rem; padding-left: 1.3rem; }
.scribe-guide li { margin: 0.35rem 0; cursor: pointer; line-height: 1.4; }
.scribe-guide li.done { color: var(--text-muted); text-decoration: line-through; }
.scribe-guide li.done::marker { content: "✓ "; }
.scribe-guide-copy { margin: 0 0 0.25rem; color: var(--success); }
.scribe-guide-copy.error { color: var(--danger); }
.scribe-guide-pill { display: none; }
.scribe-guide.collapsed { width: auto; border: none; box-shadow: none; background: none; overflow: visible; }
.scribe-guide.collapsed .scribe-guide-head,
.scribe-guide.collapsed .scribe-guide-body { display: none; }
.scribe-guide.collapsed .scribe-guide-pill { display: inline-block; padding: 0.45rem 0.9rem; border: none; border-radius: 999px; background: var(--primary); color: #fff; cursor: pointer; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); }
@keyframes scribe-flash { 0%, 100% { box-shadow: none; } 30%, 70% { box-shadow: 0 0 0 4px var(--primary); } }
.scribe-flash { animation: scribe-flash 1.6s ease 2; }

/* ---------- Genogram (genogram.js, pages/genogram.js) ---------- */

.medical-top { display: flex; gap: 1rem; align-items: stretch; }
.medical-top > #diagnoses-card { flex: 1; min-width: 0; }
.medical-top > #genogram-thumb:empty { display: none; }
.genogram-thumb {
  display: flex; flex-direction: column; gap: 0.25rem; width: 220px; height: 100%; min-height: 120px; margin: 0;
  padding: 0.5rem; cursor: zoom-in; text-align: left; font: inherit; color: inherit;
}
.genogram-thumb:hover { border-color: var(--primary); }
.genogram-thumb-title { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); }
.genogram-thumb .genogram-svg { width: 100%; height: 120px; flex: 1; }
@media (max-width: 700px) {
  .medical-top { flex-direction: column; }
  .genogram-thumb { width: 100%; }
}
.modal-box.modal-genogram { max-width: min(1400px, 96vw); }
.genogram-large { height: 70vh; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.genogram-large .genogram-svg { width: 100%; height: 100%; }

.genogram-toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.genogram-toolbar .flex-gap { display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center; }
.genogram-help { font-size: 0.8rem; margin: 0.3rem 0 0.5rem; }
.genogram-editor { display: flex; gap: 0.75rem; align-items: flex-start; }
.genogram-canvas { position: relative; flex: 1; min-width: 0; padding: 0; overflow: hidden; background: #fff; }
.genogram-canvas svg { display: block; width: 100%; height: 68vh; min-height: 420px; touch-action: none; cursor: grab; user-select: none; }
.genogram-canvas svg.linking { cursor: crosshair; }
.genogram-linking { position: absolute; top: 0.5rem; left: 50%; transform: translateX(-50%); background: var(--primary); color: #fff; padding: 0.35rem 0.8rem; border-radius: 999px; font-size: 0.8rem; pointer-events: none; }
.genogram-panel { width: 320px; flex: 0 0 320px; max-height: 68vh; overflow: auto; margin: 0; }
.genogram-panel h4 { margin: 0 0 0.5rem; }
.genogram-panel .flex-gap { display: flex; gap: 0.4rem; }
.gg-checks { display: flex; flex-wrap: wrap; gap: 0.3rem 0.8rem; font-size: 0.85rem; margin: 0.25rem 0 0.5rem; }
.gg-checks label { display: inline-flex; align-items: center; gap: 0.3rem; font-weight: normal; }
.gg-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.5rem 0; }
.gg-error { color: var(--danger); font-size: 0.8rem; }
@media (max-width: 900px) {
  .genogram-editor { flex-direction: column; }
  .genogram-panel { width: 100%; flex: none; max-height: none; }
}

.genogram-svg, #gg-svg { font-family: inherit; }
.gg-person { cursor: move; }
.gg-selected { fill: #e3f2fd; stroke: #64b5f6; stroke-width: 1.5; }
.gg-age { font-size: 12px; font-weight: 700; fill: #222; paint-order: stroke; stroke: #fff; stroke-width: 3px; }
/* White halo: the couple / child lines pass behind the texts. */
.gg-years, .gg-name, .gg-note, .gg-union-label, .gg-household-label { paint-order: stroke; stroke: #fff; stroke-width: 3px; stroke-linejoin: round; }
.gg-years { font-size: 10px; fill: #555; }
.gg-name { font-size: 12px; font-weight: 600; fill: #222; }
.gg-note { font-size: 10px; fill: #555; }
.gg-union-label { font-size: 10px; fill: #444; }
.gg-hit { stroke: transparent; stroke-width: 14; fill: none; cursor: pointer; }
.gg-union, .gg-relation { cursor: pointer; }
.gg-household rect { fill: none; stroke: #9e9e9e; stroke-width: 1.5; stroke-dasharray: 6 5; }
.gg-household-label { font-size: 11px; fill: #757575; font-style: italic; }
.gg-legend { list-style: none; margin: 0.5rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.35rem 1.2rem; font-size: 0.8rem; }
.gg-legend li { display: inline-flex; align-items: center; gap: 0.4rem; }
.gg-sample { flex: none; }
.gg-warnings { white-space: pre-wrap; font-size: 0.75rem; background: var(--bg); padding: 0.5rem; border-radius: 6px; max-height: 160px; overflow: auto; }

/* Suivi des bilans: checks and alerts in the patient banner. */
.patient-banner-checks { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.4rem; }
.patient-banner-checks:empty { display: none; }
.check-chip { border: 1px solid var(--border, #d0d7de); background: #f6f8fa; border-radius: 999px; padding: 0.15rem 0.6rem; font-size: 0.8rem; cursor: pointer; }
.check-chip.none { background: #fff; }
.check-chip.pending { background: #eef4ff; border-color: #b6ccf5; }
.check-chip.ok { background: #e8f6ec; border-color: #a7d8b5; }
.check-chip.bad { background: #fdecea; border-color: #f1aaa3; color: #8a1c13; }
.check-chip.due { box-shadow: 0 0 0 2px #f5c98b inset; }
.check-chip.alert { background: #fff3e0; border-color: #f0b35b; color: #8a4b00; font-weight: 600; }
.check-chip .check-why { font-weight: normal; opacity: 0.8; margin-left: 0.25rem; }
.monitoring-rules input, .monitoring-rules select { min-width: 0; width: 100%; }
.monitoring-rules td:nth-child(1) { min-width: 12rem; }
.monitoring-rules td:nth-child(3) { min-width: 12rem; }
.monitoring-rules td:nth-child(2) { min-width: 8.5rem; }
.monitoring-rules td:nth-child(4) { min-width: 11rem; }
.monitoring-rules td:nth-child(5) { width: 5.5rem; }
.monitoring-rules td:nth-child(1) input { min-width: 12rem; }
.totp-qr svg { width: 180px; height: 180px; background: #fff; }

/* Aide */
.sidebar-help { color: inherit; text-decoration: none; flex-shrink: 0; font-weight: 600; }
.sidebar-help:hover { text-decoration: underline; }
.help-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 800px) { .help-layout { grid-template-columns: 1fr; } }
.help-nav { display: flex; flex-direction: column; gap: 0.15rem; padding: 0.75rem; }
.help-nav a { padding: 0.35rem 0.5rem; border-radius: 6px; color: inherit; text-decoration: none; }
.help-nav a:hover { background: #f1f4f8; }
.help-nav a.active { background: #e7effa; font-weight: 600; }
.help-section { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: #6b7280; margin: 0.4rem 0.5rem 0.2rem; }
.help-article { line-height: 1.55; max-width: 900px; }
.help-article h2 { margin-top: 0; }
.help-article h3 { margin-top: 1.4rem; }
.help-article code { background: #f3f4f6; padding: 0.05rem 0.3rem; border-radius: 4px; font-size: 0.88em; word-break: break-all; }
.help-article li { margin: 0.25rem 0; }
.help-note { background: #eef4ff; border: 1px solid #c9dafb; border-radius: 8px; padding: 0.7rem 0.9rem; margin: 0.8rem 0; }

/* Portail serveur */
.portal-lock-card { max-width: 460px; }
.portal-session { display: inline-flex; gap: 0.5rem; align-items: center; font-size: 0.85rem; }
.portal-bar { display: block; height: 6px; background: #e5e7eb; border-radius: 3px; margin-top: 0.3rem; overflow: hidden; }
.portal-bar span { display: block; height: 100%; background: #3b82f6; }
.portal-db { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (max-width: 900px) { .portal-db { grid-template-columns: 1fr; } }
.portal-db-tables { display: flex; flex-direction: column; max-height: 75vh; overflow: auto; padding: 0.5rem; font-size: 0.85rem; }
.portal-db-tables a { padding: 0.25rem 0.4rem; border-radius: 5px; color: inherit; text-decoration: none; display: flex; justify-content: space-between; gap: 0.5rem; }
.portal-db-tables a:hover { background: #f1f4f8; }
.portal-db-tables a.active { background: #e7effa; font-weight: 600; }
.portal-grid td { font-size: 0.8rem; max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.portal-grid th { font-size: 0.75rem; white-space: nowrap; }
.portal-editable { cursor: cell; }
.portal-editable:hover { background: #fff8e1; }
.portal-logs { background: #0f172a; color: #e2e8f0; padding: 0.75rem; border-radius: 8px; max-height: 60vh; overflow: auto; font-size: 0.75rem; white-space: pre-wrap; word-break: break-all; }
.help-search { margin-bottom: 1rem; max-width: 640px; }
.help-search input { width: 100%; padding: 0.55rem 0.8rem; font-size: 1rem; border-radius: 8px; }
.help-results { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.2rem; }
.help-hit { display: flex; flex-direction: column; gap: 0.1rem; padding: 0.45rem 0.6rem; border-radius: 6px; color: inherit; text-decoration: none; }
.help-hit:hover { background: #f1f4f8; }
.help-hit span { font-size: 0.85rem; color: #4b5563; }
.help-results mark, .help-article mark.help-mark { background: #fde68a; padding: 0 0.1rem; border-radius: 2px; }

/* ---------- Fiche patient > App patient (Carnet) ---------- */
.carnet-tab { display: flex; flex-direction: column; gap: 1rem; }
.carnet-tab h3 { margin: 0 0 0.6rem; }
.carnet-tab h4 { margin: 0.9rem 0 0.4rem; font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.carnet-cols { display: grid; grid-template-columns: minmax(260px, 1fr) 2fr; gap: 1rem; align-items: start; }
@media (max-width: 1000px) { .carnet-cols { grid-template-columns: 1fr; } }
.carnet-small { font-size: 0.8rem; }
.carnet-tab .mono, .carnet-code-big { font-family: ui-monospace, Consolas, monospace; letter-spacing: 0.06em; }
.carnet-tab .btn-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin: 0.5rem 0; }
.carnet-devices { margin: 0.3rem 0; padding-left: 1.1rem; }
.carnet-tool { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.45rem 0.6rem; margin-bottom: 0.35rem; }
.carnet-tool.on { border-color: var(--primary); background: var(--primary-softer); }
.carnet-tool-head { display: flex; gap: 0.5rem; align-items: flex-start; cursor: pointer; }
.carnet-tool-head input { margin-top: 0.2rem; }
.carnet-tool-head .badge { margin-left: 0.3rem; }
.carnet-tool-opts { display: flex; flex-direction: column; gap: 0.35rem; margin: 0.4rem 0 0.1rem 1.6rem; }
.carnet-tool-opts textarea { width: 100%; }
.carnet-opt { display: flex; gap: 0.4rem; align-items: center; font-size: 0.85rem; }
.carnet-data-tabs { margin-bottom: 0.6rem; flex-wrap: wrap; }
.carnet-data-tabs button { background: none; border: 0; cursor: pointer; }
.carnet-tab tr.clickable { cursor: pointer; }
.carnet-tab tr.carnet-flag td { background: var(--danger-bg); }
.carnet-detail dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 0.8rem; margin: 0; }
.carnet-detail dt { color: var(--text-muted); }
.carnet-detail dd { margin: 0; white-space: pre-line; }
.carnet-tab .table-scroll { overflow-x: auto; }
.carnet-grid th:first-child { text-align: left; white-space: nowrap; }
.carnet-grid tbody th { text-transform: none; letter-spacing: 0; font-size: 0.85rem; font-weight: 500; color: var(--text); }
.carnet-grid td { text-align: center; min-width: 3.2rem; }
.carnet-heat { background: rgb(44 116 176 / calc(var(--a) * 0.85)); color: var(--text); }
.carnet-heat.strong { color: #fff; }
.carnet-yes { background: var(--danger-bg); color: var(--danger); font-weight: 600; }
.carnet-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.5rem; margin: 0.5rem 0; }
.carnet-stats > div { border: 1px solid var(--border); border-radius: var(--radius); padding: 0.5rem 0.7rem; display: flex; flex-direction: column; }
.carnet-stats small, .carnet-stats span { color: var(--text-muted); font-size: 0.78rem; }
.carnet-stats strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.carnet-chart { margin: 0.5rem 0 0.8rem; }
.carnet-qr svg { width: 220px; height: 220px; display: block; margin: 0 auto; }
.carnet-code-big { text-align: center; font-size: 1.8rem; font-weight: 600; margin: 0.4rem 0; }
.carnet-steps { padding-left: 1.2rem; }
.seg-group { display: inline-flex; gap: 0.25rem; }

/* Line chart shared with the patient app (static/carnet/chart.js) */
.lc { position: relative; }
.lc svg { display: block; }
.lc-grid { stroke: #e6edf4; stroke-width: 1; }
.lc-axis { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.lc-line { fill: none; stroke: #2c74b0; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.lc-dot, .lc-hot { fill: #2c74b0; stroke: var(--surface); stroke-width: 2; }
.lc-cross { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; }
.lc-tip { position: absolute; pointer-events: none; white-space: nowrap; background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 0.25rem 0.5rem; font-size: 0.8rem; box-shadow: 0 2px 8px rgb(0 0 0 / 12%); display: flex; flex-direction: column; }
.lc-tip span { color: var(--text-muted); }

/* ---------- Agenda: ranges open to online booking ---------- */
.cal-online {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 0;
  pointer-events: none;
  background: repeating-linear-gradient(135deg, rgb(26 127 55 / 9%) 0 8px, rgb(26 127 55 / 15%) 8px 16px);
  border-left: 3px solid rgb(26 127 55 / 55%);
}
.cal-online span {
  position: absolute;
  bottom: 2px;
  right: 4px;
  font-size: 0.62rem;
  color: #1a6b32;
  opacity: 0.8;
}
.cal-range-mode .cal-online {
  pointer-events: auto;
  cursor: pointer;
  outline: 1px dashed rgb(26 127 55 / 70%);
}
.cal-range-mode .cal-online:hover {
  background: repeating-linear-gradient(135deg, rgb(26 127 55 / 16%) 0 8px, rgb(26 127 55 / 24%) 8px 16px);
}
.cal-range-mode .cal-appt { opacity: 0.55; }
.cal-dot-online {
  background: repeating-linear-gradient(135deg, rgb(26 127 55 / 25%) 0 3px, rgb(26 127 55 / 45%) 3px 6px);
  border: 1px solid rgb(26 127 55 / 55%);
}
.cal-online-hint {
  font-size: 0.8rem;
  color: #1a6b32;
  background: #e6f4ea;
  border-radius: var(--radius);
  padding: 0.3rem 0.6rem;
  margin: 0 0 0.4rem;
}
.cal-day-site {
  display: block;
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
}
.cal-appt-online {
  width: 1em;
  height: 1em;
  margin-right: 0.2em;
  vertical-align: -0.15em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  opacity: 0.8;
}
.range-row { display: flex; gap: 0.75rem; }
.presence-table { max-width: 760px; }
.presence-table th { width: 7rem; text-align: left; vertical-align: top; padding-top: 0.6rem; }
.presence-table td { display: flex; gap: 0.6rem; align-items: flex-start; flex-wrap: wrap; }
.presence-segs { display: flex; flex-direction: column; gap: 0.35rem; min-width: 24rem; }
.presence-seg { display: flex; gap: 0.4rem; align-items: center; }
.presence-seg select { min-width: 10rem; }
.range-row .field { flex: 1; }
