/* ---------- Jetons de couleur : clair par défaut, sombre selon le système ou le choix de l'utilisateur ---------- */
:root {
  color-scheme: light dark;

  --bg: #fcfcfd;
  --bg-sidebar: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #eeeff2;
  --surface-3: #e3e5e9;
  --border: #e2e4e8;
  --border-strong: #cbced4;
  --text: #16181d;
  --text-2: #5b616b;
  --text-3: #858b95;
  --accent: #4f4fc9;
  --accent-bg: #5b5bd6;
  --accent-fg: #ffffff;
  --accent-soft: #ececfb;
  --accent-soft-text: #3c3ba8;
  --danger: #c4323f;
  --danger-soft: #fcedee;
  --success: #1c7f50;
  --success-soft: #e6f5ec;
  --warning: #9a6200;
  --warning-soft: #fdf3e0;
  --code-bg: #f5f6f8;
  --scrim: rgb(12 14 18 / 0.38);
  --shadow-sm: 0 1px 2px rgb(16 18 24 / 0.06);
  --shadow-md: 0 1px 3px rgb(16 18 24 / 0.06), 0 6px 20px rgb(16 18 24 / 0.08);
  --shadow-lg: 0 2px 6px rgb(16 18 24 / 0.08), 0 16px 48px rgb(16 18 24 / 0.16);

  --hl-keyword: #5a3fc0;
  --hl-string: #1d7446;
  --hl-number: #a45400;
  --hl-comment: #858b95;
  --hl-title: #1e5bb8;
  --hl-type: #a3366a;
  --hl-attr: #2a6a88;
  --hl-meta: #6b7280;

  --font-ui: 'Instrument Sans Variable', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-prose: 'Literata Variable', ui-serif, Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono Variable', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #1a1b1e;
    --bg-sidebar: #141518;
    --surface: #232428;
    --surface-2: #2b2d32;
    --surface-3: #35373d;
    --border: #303338;
    --border-strong: #464a52;
    --text: #ecedf0;
    --text-2: #a3a8b2;
    --text-3: #767c87;
    --accent: #a6a4ff;
    --accent-bg: #6c69e0;
    --accent-fg: #ffffff;
    --accent-soft: #2b2a4a;
    --accent-soft-text: #c9c7ff;
    --danger: #f28a92;
    --danger-soft: #3b2327;
    --success: #5cc894;
    --success-soft: #1d3329;
    --warning: #e5b55c;
    --warning-soft: #3a2f1a;
    --code-bg: #141518;
    --scrim: rgb(0 0 0 / 0.55);
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow-md: 0 1px 3px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 2px 8px rgb(0 0 0 / 0.45), 0 18px 48px rgb(0 0 0 / 0.55);
    --hl-keyword: #b6a9ff;
    --hl-string: #86d3a6;
    --hl-number: #f1b46e;
    --hl-comment: #7a808b;
    --hl-title: #8fb9ff;
    --hl-type: #f29cc6;
    --hl-attr: #86c6e2;
    --hl-meta: #9aa3af;
  }
}

:root[data-theme='light'] {
  color-scheme: light;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #1a1b1e;
  --bg-sidebar: #141518;
  --surface: #232428;
  --surface-2: #2b2d32;
  --surface-3: #35373d;
  --border: #303338;
  --border-strong: #464a52;
  --text: #ecedf0;
  --text-2: #a3a8b2;
  --text-3: #767c87;
  --accent: #a6a4ff;
  --accent-bg: #6c69e0;
  --accent-fg: #ffffff;
  --accent-soft: #2b2a4a;
  --accent-soft-text: #c9c7ff;
  --danger: #f28a92;
  --danger-soft: #3b2327;
  --success: #5cc894;
  --success-soft: #1d3329;
  --warning: #e5b55c;
  --warning-soft: #3a2f1a;
  --code-bg: #141518;
  --scrim: rgb(0 0 0 / 0.55);
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow-md: 0 1px 3px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 2px 8px rgb(0 0 0 / 0.45), 0 18px 48px rgb(0 0 0 / 0.55);
  --hl-keyword: #b6a9ff;
  --hl-string: #86d3a6;
  --hl-number: #f1b46e;
  --hl-comment: #7a808b;
  --hl-title: #8fb9ff;
  --hl-type: #f29cc6;
  --hl-attr: #86c6e2;
  --hl-meta: #9aa3af;
}

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  accent-color: var(--accent-bg);
  scrollbar-color: var(--border-strong) transparent;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
}

a {
  color: var(--accent);
}

img,
svg {
  display: block;
}

:focus-visible {
  outline: 2px solid var(--accent-bg);
  outline-offset: 2px;
}

::selection {
  background: color-mix(in srgb, var(--accent-bg) 28%, transparent);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

.icon {
  flex: none;
}

/* ---------- Marque : deux bulles de dialogue ---------- */
.mark {
  width: 24px;
  height: 24px;
  flex: none;
  overflow: visible;
}

.mark-a {
  fill: var(--accent-bg);
}

.mark-b {
  fill: var(--mark-bg, var(--bg));
  stroke: var(--accent-bg);
  stroke-width: 2.4;
  stroke-linejoin: round;
}

.mark.is-live .mark-a {
  animation: turn-a 1.6s ease-in-out infinite;
}

.mark.is-live .mark-b {
  animation: turn-b 1.6s ease-in-out infinite;
}

@keyframes turn-a {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.28;
  }
}

@keyframes turn-b {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mark.is-live .mark-a,
  .mark.is-live .mark-b {
    animation: none;
  }
}

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 0.12s, border-color 0.12s;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn:disabled {
  opacity: 0.55;
}

.btn-primary {
  border-color: transparent;
  background: var(--accent-bg);
  color: var(--accent-fg);
}

.btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent-bg) 88%, black);
}

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

.btn-danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--danger) 88%, black);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-2);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn-sm {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
  border-radius: 8px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-2);
  transition: background-color 0.12s, color 0.12s;
}

.icon-btn:hover:not(:disabled),
.icon-btn[aria-expanded='true'] {
  background: var(--surface-2);
  color: var(--text);
}

/* ---------- Champs ---------- */
.field {
  display: grid;
  gap: 6px;
}

.field > label,
.field > .label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}

.field .hint {
  font-size: 12.5px;
  color: var(--text-3);
}

.input,
.select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
}

.select {
  padding-right: 8px;
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--accent-bg);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent-bg) 22%, transparent);
}

.input::placeholder {
  color: var(--text-3);
}

.password-field {
  position: relative;
}

.password-field .input {
  padding-right: 46px;
}

.password-field .icon-btn {
  position: absolute;
  top: 3px;
  right: 3px;
}

.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 14px;
}

/* Évite le zoom automatique d'iOS sur les champs. */
@media (max-width: 760px) {
  .input,
  .select {
    font-size: 16px;
  }
}

/* ---------- Menus (popover) ---------- */
.menu {
  position: fixed;
  inset: auto;
  margin: 0;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 16px));
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: auto;
  max-height: calc(100dvh - 16px);
}

.menu.is-fallback {
  z-index: 1000;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: inherit;
  font-size: 14px;
  text-align: start;
  text-decoration: none;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: var(--surface-2);
  outline: none;
}

.menu-item .icon {
  color: var(--text-2);
}

.menu-item.danger,
.menu-item.danger .icon {
  color: var(--danger);
}

.menu-item .menu-text {
  display: grid;
  gap: 1px;
  flex: 1;
  min-width: 0;
}

.menu-item .menu-sub {
  font-size: 12.5px;
  color: var(--text-3);
  line-height: 1.35;
}

.menu-item .menu-check {
  width: 18px;
  color: var(--accent);
}

.menu-trailing {
  display: grid;
  flex: none;
  color: var(--text-3);
}

.menu-note {
  max-width: 280px;
  margin: 0;
  padding: 4px 10px 8px;
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.45;
}

.menu-sep {
  height: 1px;
  margin: 6px 4px;
  background: var(--border);
}

.menu-label {
  padding: 8px 10px 4px;
  font-size: 12px;
  color: var(--text-3);
}

.switch {
  position: relative;
  width: 34px;
  height: 20px;
  flex: none;
  border-radius: 999px;
  background: var(--surface-3);
  transition: background-color 0.15s;
}

.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.25);
  transition: translate 0.15s;
}

[aria-checked='true'] > .switch {
  background: var(--accent-bg);
}

[aria-checked='true'] > .switch::after {
  translate: 14px 0;
}

/* ---------- Boîtes de dialogue ---------- */
.modal {
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: auto;
}

.modal::backdrop {
  background: var(--scrim);
}

.modal form {
  display: grid;
}

.modal-body {
  display: grid;
  gap: 14px;
  padding: 22px 22px 6px;
}

.modal-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  line-height: 1.3;
}

.modal-text {
  margin: 0;
  color: var(--text-2);
  font-size: 14.5px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 22px 20px;
}

.secret {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 14px;
}

.secret code {
  flex: 1;
  overflow-wrap: anywhere;
}

@media (max-width: 480px) {
  .modal-actions .btn {
    flex: 1;
  }
}

/* ---------- Notifications ---------- */
.toasts {
  position: fixed;
  inset: auto 0 calc(20px + var(--safe-bottom)) 0;
  margin: 0 auto;
  width: max-content;
  max-width: calc(100vw - 24px);
  padding: 0;
  border: 0;
  background: transparent;
  display: grid;
  justify-items: center;
  gap: 8px;
  overflow: visible;
  pointer-events: none;
  z-index: 1000;
}

.toast {
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
}

.toast.error {
  background: var(--danger);
  color: #fff;
}

/* ---------- Divers ---------- */
.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-soft-text);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge.accent {
  background: var(--accent-soft);
  color: var(--accent-soft-text);
}

.badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge.success {
  background: var(--success-soft);
  color: var(--success);
}

.badge.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent-bg);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    rotate: 360deg;
  }
}
