/* ───── Thème ───── */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --line: #dfe3ea;
  --line-strong: #c9cfd9;
  --text: #14171c;
  --muted: #667085;
  --accent: #d9480f;
  --on-accent: #ffffff;
  --accent-soft: rgba(217, 72, 15, 0.09);
  --accent-ring: rgba(217, 72, 15, 0.22);
  --ok: #12925f;
  --ok-soft: rgba(18, 146, 95, 0.09);
  --danger: #c92a2a;
  --danger-soft: rgba(201, 42, 42, 0.07);
  --info: #2563c9;
  --info-soft: rgba(37, 99, 201, 0.07);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --line: #2a2f3a;
    --line-strong: #3a4150;
    --text: #eceef2;
    --muted: #8b93a3;
    --accent: #ff8a3d;
    --on-accent: #1d0f03;
    --accent-soft: rgba(255, 138, 61, 0.12);
    --accent-ring: rgba(255, 138, 61, 0.28);
    --ok: #3ddc97;
    --ok-soft: rgba(61, 220, 151, 0.09);
    --danger: #ff8787;
    --danger-soft: rgba(255, 107, 107, 0.09);
    --info: #7fb0ff;
    --info-soft: rgba(110, 160, 255, 0.09);
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }

html, body { width: 400px; height: 600px; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Noto Sans Arabic", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
svg { flex: none; display: block; }
[dir="rtl"] .flip { transform: scaleX(-1); }

/* Page ouverte hors extension : on présente le popup comme une carte centrée. */
html.standalone, html.standalone body { width: 100%; height: 100%; }
html.standalone body { display: grid; place-items: center; overflow: auto; }
html.standalone .app {
  width: 400px; max-width: 100%; height: 600px; max-height: 100%;
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  box-shadow: 0 20px 50px rgba(16, 24, 40, 0.14);
}

.app { display: flex; flex-direction: column; height: 100%; background: var(--bg); }

/* ───── En-tête ───── */
.top {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.top img { border-radius: 8px; }
.brand { flex: 1; min-width: 0; }
.brand h1 { font-size: 14.5px; font-weight: 700; letter-spacing: -0.2px; line-height: 1.2; }
.brand p { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lang {
  display: flex; align-items: center; gap: 5px; padding-inline: 8px 2px; height: 28px;
  border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: var(--bg);
}
.lang:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.lang select {
  border: 0; background: transparent; color: var(--text); font: inherit; font-size: 12px; font-weight: 600;
  outline: none; cursor: pointer; padding: 0; width: auto;
}

/* ───── Étapes ───── */
.steps {
  list-style: none; display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  font-size: 11.5px; font-weight: 600; color: var(--muted);
}
.steps li { display: flex; align-items: center; gap: 6px; }
.steps li + li::before { content: ""; width: 22px; height: 1px; background: var(--line-strong); margin-inline-end: 2px; }
.steps i {
  display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
  border: 1px solid var(--line-strong); font-style: normal; font-size: 10.5px; font-weight: 700;
}
.steps li.active { color: var(--text); }
.steps li.active i { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.steps li.done i { background: var(--ok-soft); border-color: transparent; color: var(--ok); }

/* ───── Vues ───── */
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; padding: 4px 16px 16px; }
.view.scroll { overflow-y: auto; }
#view-result { padding-bottom: 0; }

/* ───── Onglets ───── */
.tabs {
  flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 3px;
  background: var(--surface-2); border-radius: var(--radius);
}
.tab {
  padding: 7px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; transition: 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow), 0 0 0 1px var(--line); }

.pane { display: flex; flex-direction: column; gap: 10px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ───── Champs ───── */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font-size: 11.5px; font-weight: 600; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; gap: 10px; }
.field.inline > span { flex: none; }
input[type="text"], input[type="password"], input[type="search"], textarea, .field select {
  width: 100%; padding: 8px 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  font: inherit; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { resize: none; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; word-break: break-all; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.65; }
input:focus, textarea:focus, .field select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
[dir="rtl"] input[dir="ltr"], [dir="rtl"] textarea[dir="ltr"] { text-align: right; }

/* ───── Interrupteur ───── */
.switch {
  flex: none; display: flex; align-items: center; gap: 10px; padding: 9px 11px; cursor: pointer; user-select: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-text { flex: 1; min-width: 0; }
.switch-text b { display: block; font-weight: 600; }
.switch-text small { display: block; color: var(--muted); font-size: 11.5px; }
.track { flex: none; width: 34px; height: 20px; border-radius: 20px; background: var(--line-strong); position: relative; transition: 0.18s; }
.track::after {
  content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); transition: 0.18s;
}
.switch input:checked ~ .track { background: var(--accent); }
.switch input:checked ~ .track::after { transform: translateX(14px); }
[dir="rtl"] .switch input:checked ~ .track::after { transform: translateX(-14px); }
.switch input:focus-visible ~ .track { box-shadow: 0 0 0 3px var(--accent-ring); }

/* ───── Boutons ───── */
.actions { display: flex; gap: 8px; }
.btn {
  flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 14px; border-radius: 9px; border: 1px solid transparent;
  font: inherit; font-weight: 650; cursor: pointer; transition: 0.15s; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.primary:active { filter: brightness(0.96); }
.btn.ghost { background: var(--surface); border-color: var(--line); color: var(--text); box-shadow: var(--shadow); }
.btn.ghost:hover { border-color: var(--line-strong); background: var(--surface-2); }
.btn.wide { width: 100%; padding: 11px; font-size: 13.5px; }
.btn.small { padding: 6px 14px; font-size: 12px; }
.actions .btn { flex: 1; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
.btn:focus-visible, .link:focus-visible, .tab:focus-visible, .type:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-ring); }

.link {
  display: inline-flex; align-items: center; gap: 4px;
  background: none; border: 0; padding: 2px 5px; color: var(--accent);
  font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; border-radius: 6px;
}
.link:hover { background: var(--accent-soft); }
.link.center { align-self: center; color: var(--muted); }
.link.center:hover { color: var(--accent); }

/* ───── Messages ───── */
.note {
  flex: none; display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px;
  border-radius: 9px; font-size: 12px; line-height: 1.4;
}
.note svg { margin-top: 1px; }
.note.danger { background: var(--danger-soft); color: var(--danger); }
.note.info { background: var(--info-soft); color: var(--info); }
.note.info span { color: var(--text); }

.section-head {
  flex: none; display: flex; justify-content: space-between; align-items: center;
  font-size: 11.5px; font-weight: 600; color: var(--muted);
}
.section-head b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* ───── Historique ───── */
#history-box { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.history { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.history button {
  width: 100%; display: flex; justify-content: space-between; gap: 10px; align-items: center;
  padding: 8px 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  color: var(--text); font: inherit; cursor: pointer; text-align: start; transition: 0.15s; box-shadow: var(--shadow);
}
.history button:hover { border-color: var(--accent); }
.history .h-host { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history .h-meta { color: var(--muted); font-size: 11.5px; flex: none; }

/* ───── Chargement ───── */
.loader { margin: auto 0; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 16px 40px; text-align: center; }
.loader strong { font-size: 13.5px; }
.loader span { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; min-height: 17px; }
.spinner {
  width: 32px; height: 32px; border-radius: 50%; margin-bottom: 8px;
  border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.bar { width: 100%; height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 6px 0 12px; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width 0.25s; }
.bar.indeterminate i { width: 35%; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-110%); } to { transform: translateX(300%); } }

/* ───── Résultat ───── */
.result-top { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 24px; }
.back { margin-inline-start: -5px; }
.account {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  font-size: 11.5px; color: var(--muted); white-space: nowrap;
}
.account .badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 20px;
  font-weight: 650; background: var(--ok-soft); color: var(--ok);
}
.account .badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.account .badge.bad { background: var(--danger-soft); color: var(--danger); }
.account .tag { padding: 2px 7px; border-radius: 20px; border: 1px solid var(--line); font-weight: 600; }
.account .exp { overflow: hidden; text-overflow: ellipsis; }

.types { flex: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.type {
  position: relative; display: flex; flex-direction: column; gap: 1px; padding: 8px 10px; text-align: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  color: var(--muted); font: inherit; cursor: pointer; transition: 0.15s;
}
.type .t-box {
  position: absolute; top: 8px; inset-inline-end: 8px;
  display: grid; place-items: center; width: 15px; height: 15px; border-radius: 4px;
  border: 1.5px solid var(--line-strong); color: transparent;
}
.type strong { font-size: 16px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; letter-spacing: -0.3px; line-height: 1.25; }
.type .t-label { display: flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.type.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.type.on .t-label { color: var(--accent); }
.type.on .t-box { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.type:not(.on) strong { color: var(--muted); }
.type:disabled { opacity: 0.5; cursor: default; }

.search { flex: none; }
.groups {
  flex: 1; min-height: 60px; list-style: none; padding: 4px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.groups::-webkit-scrollbar, .view.scroll::-webkit-scrollbar { width: 8px; }
.groups::-webkit-scrollbar-thumb, .view.scroll::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
.groups label { display: flex; align-items: center; gap: 9px; padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.groups label:hover { background: var(--surface-2); }
.groups input { accent-color: var(--accent); width: 15px; height: 15px; flex: none; margin: 0; }
.groups .g-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.groups .g-count { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.groups .empty { padding: 18px; text-align: center; color: var(--muted); }

/* ───── Pied : enregistrement ───── */
.foot {
  flex: none; display: flex; flex-direction: column; gap: 9px;
  margin: 0 -16px; padding: 11px 16px 14px;
  background: var(--surface); border-top: 1px solid var(--line);
}
.done-msg { display: flex; align-items: center; gap: 9px; }
.done-msg > div { flex: 1; min-width: 0; }
.done-msg b { display: block; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: start; }
.done-msg small { color: var(--muted); font-size: 11.5px; }
.check { flex: none; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); }
.hint { color: var(--muted); font-size: 11px; line-height: 1.35; }
[dir="rtl"] .done-msg b { text-align: right; }

/* Version web sur téléphone : plein écran, et 16px dans les champs pour éviter le zoom iOS. */
@media (max-width: 520px) {
  html.standalone body { display: block; overflow: hidden; }
  html.standalone .app { width: 100%; height: 100dvh; max-height: none; border: 0; border-radius: 0; box-shadow: none; }
  html.standalone input[type="text"], html.standalone input[type="password"], html.standalone input[type="search"],
  html.standalone textarea, html.standalone .field select { font-size: 16px; }
}
