:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --border: #e5e9f0;
  --border-strong: #cbd2dc;
  --text: #1f2937;
  --muted: #6b7280;
  --muted-light: #9ca3af;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #dbeafe;
  --success: #10b981;
  --success-light: #d1fae5;
  --warn: #f59e0b;
  --warn-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --visio: #8b5cf6;
  --visio-light: #ede9fe;
  --cabinet: #2563eb;
  --cabinet-light: #dbeafe;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }

/* ========== Lucide icons ========== */
.icon {
  display: inline-block;
  vertical-align: -0.18em;
  flex-shrink: 0;
}

[data-icon] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

/* In tabs / titles, color follows surrounding text */
.tab .icon { stroke: currentColor; }
.specialty-title .icon { color: var(--primary); }
.doctor-card .icon { color: var(--primary); }

/* In badge: invert color to white-on-color */
.badge .icon { stroke: currentColor; width: 14px; height: 14px; vertical-align: -0.2em; margin-right: 4px; }

/* In header */
header .icon { stroke: currentColor; }

/* Action buttons keep their color */
.btn .icon { color: currentColor; margin-right: 4px; vertical-align: -0.18em; }
.btn-small .icon { width: 14px; height: 14px; margin-right: 3px; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ========== Header ========== */

header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 100%);
  color: #fff;
  padding: 18px 28px;
  box-shadow: var(--shadow-md);
}

header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

header .meta {
  margin-top: 6px;
  font-size: 12px;
  opacity: 0.85;
}

header .meta code {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 11px;
}

/* ========== Layout ========== */

main {
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 24px;
}

footer {
  text-align: center;
  padding: 20px;
  color: var(--muted-light);
  font-size: 12px;
}

footer code { font-size: 11px; }

/* ========== Tabs ========== */

.tabs {
  display: flex;
  gap: 4px;
  background: var(--panel);
  padding: 6px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
  overflow-x: auto;
}

.tab {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.tab:hover { background: var(--bg); color: var(--text); }

.tab.active {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.tab.active:hover { background: var(--primary-dark); }

.tab.tab-mini { flex: 0 0 auto; padding: 10px 14px; }

.tab-icon { font-size: 16px; }

/* ========== Panels ========== */

.panel {
  animation: fadeIn 0.2s ease;
}

.panel.hidden { display: none; }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ========== Cards ========== */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
  transition: box-shadow 0.15s ease;
}

.card:hover { box-shadow: var(--shadow-md); }

.card h3 {
  margin: 0 0 12px 0;
  font-size: 15px;
  font-weight: 600;
}

/* ========== Specialty groups ========== */

.specialty-section { margin-bottom: 24px; }

.specialty-title {
  margin: 0 0 12px 0;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

/* ========== Doctor cards grid (legacy) ========== */

.cards-grid {
  display: block;
}

.cards-grid-inner {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

/* ========== Practitioner cards (3-level hierarchy) ========== */

.practitioners-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.practitioner-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow 0.15s ease;
}

.practitioner-card:hover { box-shadow: var(--shadow-md); }

.practitioner-card.practitioner-off {
  opacity: 0.55;
  background: #fafafa;
}

.practitioner-card > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.15s ease;
  user-select: none;
}

.practitioner-card > summary::-webkit-details-marker { display: none; }

.practitioner-card > summary:hover { background: var(--bg); }

.practitioner-card .chevron {
  color: var(--muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
  display: inline-flex;
}

.practitioner-card[open] .chevron { transform: rotate(180deg); }

.practitioner-info {
  flex: 1;
  min-width: 0;
}

.practitioner-name {
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.practitioner-name a { color: inherit; }
.practitioner-name .icon { color: var(--muted-light); opacity: 0.6; }

.practitioner-summary {
  margin-top: 2px;
}

.practitioner-toggle {
  flex-shrink: 0;
}

.motifs-list {
  border-top: 1px solid var(--border);
  background: #fcfcfd;
  padding: 8px 12px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.motifs-list.settings { padding: 6px 8px 8px 8px; }

.motif-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.motif-card.disabled { opacity: 0.45; }
.motif-card.has-slot { border-left: 3px solid var(--success); }

.motif-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

.motif-name {
  flex: 1;
  font-size: 13px;
  word-break: break-word;
}

.motif-meta {
  font-size: 12px;
  justify-content: space-between;
}

.motif-slot {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.motif-slot .slot-time {
  font-weight: 600;
  color: var(--success);
  font-size: 13px;
}

.motif-slot .no-slot {
  color: var(--muted-light);
  font-style: italic;
  font-size: 12px;
}

/* Slots panel — practitioner pliable, motif sub-section */
.motif-slots-section {
  margin: 6px 0 6px 4px;
  padding-left: 8px;
  border-left: 2px solid var(--border);
}

.motif-slots-section h5 {
  margin: 0 0 6px 0;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Settings: sub-toggles disabled when practitioner OFF */
.practitioner-card.practitioner-off .target-row input.toggle,
.practitioner-card.practitioner-off .motif-card input.toggle {
  pointer-events: none;
}

/* ========== Slots panel — sub-tabs by specialty ========== */

.slots-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 18px;
  overflow-x: auto;
}

.slots-tab {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: var(--muted);
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: color 0.15s, border-color 0.15s;
}

.slots-tab:hover { color: var(--text); }

.slots-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.slots-tab-count {
  background: var(--bg);
  color: var(--muted);
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.slots-tab.active .slots-tab-count {
  background: var(--primary-light);
  color: var(--primary);
}

/* Practitioner card in slots view */

.slots-practitioner-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.slots-practitioner-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.slots-practitioner-name {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.slots-practitioner-name a {
  color: inherit;
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.slots-practitioner-name .icon {
  color: var(--muted-light);
  opacity: 0.6;
  vertical-align: -0.1em;
}

.slots-practitioner-count {
  font-size: 13px;
  color: var(--success);
  font-weight: 500;
}

.slots-practitioner-count strong { font-weight: 700; }

.slots-motifs {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.slots-motif {
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.slots-motif-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.slots-motif-name {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
}

.slots-days {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.slots-day-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 4px 0;
}

.slots-day-label {
  flex-shrink: 0;
  width: 90px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: lowercase;
  padding-top: 4px;
}

.slots-day-label::first-letter { text-transform: uppercase; }

.slots-times {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

@media (max-width: 600px) {
  .slots-day-row { flex-direction: column; gap: 4px; }
  .slots-day-label { width: auto; padding-top: 0; }
  .slots-tabs { gap: 4px; }
  .slots-tab { padding: 10px 10px; font-size: 13px; }
}

.doctor-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: all 0.15s ease;
}

.doctor-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.doctor-card.disabled {
  opacity: 0.55;
  background: #fafafa;
}

.doctor-card.has-slot {
  border-left: 3px solid var(--success);
}

.doctor-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.doctor-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  flex: 1;
  word-wrap: break-word;
}

.doctor-name a { color: inherit; }

.slot-display {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.slot-display .slot-time {
  font-weight: 600;
  color: var(--success);
  font-size: 14px;
}

.slot-display .no-slot {
  color: var(--muted-light);
  font-style: italic;
}

.doctor-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 4px;
}

.doctor-footer .seen-at {
  font-size: 11px;
  color: var(--muted-light);
}

/* ========== Slots tab (per-day breakdown) ========== */

.doctor-slots-section {
  margin-bottom: 20px;
}

.doctor-slots-section h3 {
  margin: 0 0 10px 0;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.day-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.day-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.day-item summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.15s ease;
}

.day-item summary::-webkit-details-marker { display: none; }
.day-item summary::before {
  content: "▸";
  margin-right: 8px;
  color: var(--muted);
  transition: transform 0.15s ease;
  display: inline-block;
}

.day-item[open] summary::before { transform: rotate(90deg); }

.day-item summary:hover { background: var(--bg); }

.day-item .day-label { font-weight: 500; }

.day-item .slot-count {
  background: var(--success-light);
  color: var(--success);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.slot-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
  background: #fafbfc;
}

.slot-chip {
  background: var(--success-light);
  color: var(--success);
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 600;
}

/* Slot chip en tant que lien Doctolib : cliquable, hover plus foncé, pas de
   soulignement parasite. min-height pour respecter les touch targets iOS. */
a.slot-chip {
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  transition: background 0.15s, transform 0.05s;
}
a.slot-chip:hover {
  background: var(--success);
  color: #fff;
}
a.slot-chip:active {
  transform: scale(0.96);
}

/* Le label de jour devient aussi un lien Doctolib (même URL avec date). */
a.slots-day-label {
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: color 0.15s;
}
a.slots-day-label:hover {
  color: var(--primary);
}

.slots-empty {
  text-align: center;
  padding: 32px;
  color: var(--muted);
}

/* ========== Add method tabs (auto/manual) ========== */

.add-method-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.add-method-tab {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.add-method-tab:hover { color: var(--text); }

.add-method-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.add-method-pane.hidden { display: none; }

.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  font-weight: normal !important;
  cursor: pointer;
}

.checkbox-label input { width: auto !important; }

/* ========== Motives result list ========== */

.motives-result {
  margin-top: 16px;
  padding: 14px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fafbfc;
}

.motives-result.hidden { display: none; }

.motives-result h4 {
  margin: 0 0 12px 0;
  font-size: 14px;
}

.motive-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}

.motive-item:hover { border-color: var(--primary-light); }

.motive-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
}

.motive-item .label {
  flex: 1;
  font-size: 13px;
}

.motive-item input[type="text"] {
  flex: 2;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  font: inherit;
  font-size: 13px;
  background: transparent;
}

.motive-item input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--panel);
}

/* ========== Settings forms ========== */

.form-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.form-card input,
.form-card select {
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-card input:focus,
.form-card select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 4px;
}

.feedback {
  font-size: 13px;
  font-weight: 500;
}

.feedback.success { color: var(--success); }
.feedback.error { color: var(--danger); }

/* ========== Targets list (settings) ========== */

.targets-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.target-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
}

.target-row .name { flex: 1; font-weight: 500; }
.target-row .name input {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  font: inherit;
  padding: 4px 6px;
  border-radius: 4px;
}
.target-row .name input:hover { border-color: var(--border); }
.target-row .name input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--panel);
}

.target-row .row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.target-row .specialty-input {
  width: 130px;
  border: 1px solid transparent;
  background: transparent;
  font: inherit;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.window-cell {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  flex-shrink: 0;
}

.window-cell .window-label {
  font-size: 10px;
  color: var(--muted-light);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.window-cell input {
  width: 56px;
  padding: 2px 4px !important;
  border: 1px solid var(--border) !important;
  border-radius: 4px !important;
  font-size: 12px !important;
  text-align: center;
  background: var(--panel) !important;
  font: inherit;
  font-variant-numeric: tabular-nums;
}

.window-cell input:focus {
  outline: none;
  border-color: var(--primary) !important;
}

.target-row .specialty-input::placeholder { color: var(--muted-light); font-style: italic; }
.target-row .specialty-input:hover { border-color: var(--border); }
.target-row .specialty-input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--panel);
}

/* ========== Buttons ========== */

.btn {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.15s ease;
}

.btn:hover { background: var(--bg); border-color: var(--muted-light); }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger-light);
}

.btn-danger:hover { background: var(--danger-light); }

.btn-small { padding: 4px 10px; font-size: 12px; }

/* ========== Switch (toggle) ========== */

.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #cbd2dc;
  transition: 0.2s;
  border-radius: 22px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
}

.switch input:checked + .slider { background-color: var(--success); }
.switch input:checked + .slider:before { transform: translateX(16px); }

/* ========== Badges ========== */

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge.visio { background: var(--visio-light); color: var(--visio); }
.badge.cabinet { background: var(--cabinet-light); color: var(--cabinet); }
.badge.dry { background: var(--warn-light); color: var(--warn); }
.badge.error { background: var(--danger-light); color: var(--danger); }
.badge.muted-badge { background: var(--bg); color: var(--muted); }

/* ========== Misc ========== */

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none; }

code {
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12.5px;
  font-family: "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
}

/* ========== Logs ========== */

.logs {
  background: #1e293b;
  color: #cbd5e1;
  padding: 14px 16px;
  border-radius: var(--radius);
  max-height: 70vh;
  overflow-y: auto;
  font-family: "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
}

/* ========== Key-value list ========== */

.kv {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
}

.kv dt { font-weight: 600; color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; }

/* ========== Responsive ========== */

@media (max-width: 700px) {
  header {
    padding: 14px 16px;
    /* respect iOS notch */
    padding-top: max(14px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  main { padding: 0 14px; margin: 16px auto; }
  .panel-header { flex-direction: column; align-items: flex-start; }
  .cards-grid-inner { grid-template-columns: 1fr; }
  .tab { padding: 12px 8px; font-size: 12px; }
  .tab .tab-label { display: none; }
  .tab-icon .icon { width: 22px; height: 22px; }

  /* Touch targets (Apple HIG / Material): 44px min */
  .btn, button.btn, input[type="checkbox"].toggle + .slider {
    min-height: 44px;
  }
  .btn-small {
    min-height: 36px;
  }

  /* Avoid iOS auto-zoom on input focus (font-size must be ≥ 16px) */
  input[type="text"], input[type="url"], input[type="email"], input[type="number"],
  input[type="password"], input[type="search"], textarea, select {
    font-size: 16px;
  }

  /* Doctor cards: more breathing room on mobile */
  .doctor-card { padding: 18px 18px; }
  .target-row {
    flex-wrap: wrap;
    gap: 8px;
  }
  .target-row .specialty-input { width: 100%; }
}

/* ========== OS-specific theming ========== */

/* iOS / iPadOS — Cupertino-ish polish */
.os-ios {
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
}

.os-ios .btn {
  border-radius: 999px;          /* pill buttons, very iOS */
  padding: 9px 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.os-ios .btn-small {
  padding: 5px 12px;
}

.os-ios .tab.active {
  border-radius: 8px;
  font-weight: 600;
}

.os-ios .switch {
  width: 51px;
  height: 31px;            /* exact iOS switch dimensions */
}
.os-ios .slider { border-radius: 31px; }
.os-ios .slider:before {
  height: 27px;
  width: 27px;
  left: 2px;
  bottom: 2px;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 3px 1px rgba(0, 0, 0, 0.06);
}
.os-ios .switch input:checked + .slider:before { transform: translateX(20px); }

.os-ios input[type="text"],
.os-ios input[type="url"],
.os-ios input[type="number"],
.os-ios input[type="email"] {
  border-radius: 10px;
}

.os-ios .card,
.os-ios .doctor-card {
  border-radius: 14px;
}

/* Android — Material-ish */
.os-android {
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.10);
  --shadow-lg: 0 14px 28px rgba(0, 0, 0, 0.20), 0 10px 10px rgba(0, 0, 0, 0.10);
}

.os-android body {
  font-family: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.os-android .btn {
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 12px;
  font-weight: 600;
  padding: 9px 16px;
  position: relative;
  overflow: hidden;
}

.os-android .btn:active::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.2);
  animation: ripple 0.4s linear;
}

@keyframes ripple {
  from { opacity: 1; }
  to { opacity: 0; }
}

.os-android .card,
.os-android .doctor-card {
  border-radius: 4px;
}

.os-android .badge {
  border-radius: 4px;
  text-transform: none;
}

.os-android .tab.active {
  border-radius: 4px;
}

/* Mobile-only iOS-style sticky tabs (better thumb-reach on tall phones) */
.is-mobile .tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  margin-bottom: 16px;
}

/* ========== Login page ========== */
.login-body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--primary-light), var(--bg) 70%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  /* Compense la safe-area iOS (encoche + barre du bas) */
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.login-shell {
  width: 100%;
  max-width: 380px;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--primary);
  margin-bottom: 4px;
}

.login-brand h1 {
  font-size: 1.4rem;
  margin: 0;
  color: var(--text);
  font-weight: 600;
}

.login-subtitle {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 0.95rem;
}

.login-error {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.login-card label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  margin: 14px 0 6px;
}

.login-card input[type="text"],
.login-card input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
  /* iOS : empêcher l'auto-zoom au focus (font-size >= 16px) */
  -webkit-appearance: none;
  appearance: none;
}

.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.login-card .btn-primary {
  width: 100%;
  margin-top: 22px;
  padding: 13px 16px;
  font-size: 1rem;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.login-card .btn-primary:hover {
  background: var(--primary-dark);
}

.login-card .btn-primary:active {
  transform: translateY(1px);
}

/* Bouton logout dans la page Réglages */
.logout-row {
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: 0.9rem;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-logout:hover {
  background: var(--danger);
  color: #fff;
}
