/* kipass - thème sobre, mobile first, clair et sombre automatiques */

:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f0f1f6;
  --text: #151722;
  --muted: #676d80;
  --line: #e3e5ee;
  --accent: #4b57d6;
  --accent-strong: #3843b8;
  --accent-soft: #e9ebfc;
  --on-accent: #ffffff;
  --danger: #cf3f45;
  --danger-soft: #fdecec;
  --success: #1b8f63;
  --warning: #b7791f;
  --shadow: 0 1px 2px rgba(20, 23, 40, .06), 0 4px 16px rgba(20, 23, 40, .06);
  --shadow-lg: 0 12px 40px rgba(20, 23, 40, .18);
  --radius: 14px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Roboto Mono", "SFMono-Regular", Menlo, Consolas, monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1118;
    --surface: #181b25;
    --surface-2: #20242f;
    --text: #eceef5;
    --muted: #9aa0b3;
    --line: #2a2e3b;
    --accent: #8d97ff;
    --accent-strong: #a6aeff;
    --accent-soft: #252a4a;
    --on-accent: #0f1118;
    --danger: #ff7b80;
    --danger-soft: #3a1d22;
    --success: #4cc495;
    --warning: #e6b450;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
  }
}

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

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}

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

[hidden] { display: none !important; }

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

/* ---------- Mise en page ---------- */

#app { min-height: 100dvh; display: flex; flex-direction: column; }

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
}

.appbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.appbar h1 {
  flex: 1;
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.content { flex: 1; padding: 8px 16px calc(110px + var(--safe-bottom)); }

.stack { display: flex; flex-direction: column; gap: 14px; }

.brand-title { display: flex; align-items: center; gap: 10px; }
.brand-title .logo-sm { width: 30px; height: 30px; flex: none; }

/* ---------- Boutons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .15s, transform .05s, opacity .15s;
  user-select: none;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn svg { width: 20px; height: 20px; flex: none; }

.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-secondary { background: var(--accent-soft); color: var(--accent-strong); }
.btn-ghost { background: transparent; color: var(--accent-strong); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 44px; height: 44px;
  padding: 0 10px;
  border: 0; border-radius: 12px;
  background: transparent; color: var(--text);
  cursor: pointer;
  font-weight: 600; font-size: .9rem;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; flex: none; }
.icon-btn.small { min-width: 40px; height: 40px; }
.icon-btn.small svg { width: 20px; height: 20px; }
.icon-btn.accent { color: var(--accent-strong); }

.link {
  background: none; border: 0; padding: 8px 4px;
  color: var(--accent-strong); font-weight: 600; cursor: pointer;
  text-decoration: none;
}

/* Bouton Ajouter : centré en bas, large, dans la zone naturelle du pouce. */
.fab {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(20px + var(--safe-bottom));
  z-index: 20;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: min(280px, calc(100% - 48px));
  height: 60px;
  margin: 0 auto;
  padding: 0 24px;
  border: 0; border-radius: 999px;
  background: var(--accent); color: var(--on-accent);
  font-weight: 650; font-size: 1rem;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
}
.fab svg { width: 24px; height: 24px; }
.fab:active { transform: scale(.97); }

/* ---------- Champs ---------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field-label {
  font-size: .85rem; font-weight: 600; color: var(--muted);
}
.hint { font-size: .82rem; color: var(--muted); }
.field .error { font-size: .85rem; color: var(--danger); font-weight: 500; }

.input-wrap {
  display: flex; align-items: center;
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  transition: border-color .15s, box-shadow .15s;
}
.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.input-wrap input, .input-wrap textarea {
  flex: 1; min-width: 0;
  min-height: 50px;
  padding: 12px 14px;
  border: 0; outline: 0;
  background: transparent;
  font-size: 1rem;
}
.input-wrap textarea { resize: vertical; min-height: 96px; line-height: 1.45; }
.input-wrap .icon-btn { margin-right: 4px; color: var(--muted); }
.input-wrap.invalid { border-color: var(--danger); }

input.mono, .mono { font-family: var(--mono); letter-spacing: .02em; }

select.select {
  min-height: 48px; padding: 0 12px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--surface);
}

.checkbox {
  display: flex; gap: 12px; align-items: flex-start;
  font-size: .95rem; cursor: pointer;
}
.checkbox input { width: 22px; height: 22px; margin: 1px 0 0; accent-color: var(--accent); flex: none; }

/* ---------- Écran de déverrouillage ---------- */

.auth {
  flex: 1;
  display: flex; flex-direction: column; justify-content: center;
  width: 100%; max-width: 420px;
  margin: 0 auto;
  padding: 32px 20px calc(32px + var(--safe-bottom));
  gap: 22px;
}
.brand { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.brand .logo { width: 76px; height: 76px; filter: drop-shadow(0 8px 20px rgba(75, 87, 214, .35)); }
.brand h1 { margin: 0; font-size: 1.9rem; font-weight: 700; letter-spacing: -.03em; }
.brand p { margin: 0; color: var(--muted); }
.auth-sub { margin: -8px 0 0; text-align: center; color: var(--muted); font-size: .95rem; }
.auth .actions { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.auth .links { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--muted); font-size: .85rem;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.notice {
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: .92rem;
}
.notice.danger { background: var(--danger-soft); color: var(--danger); font-weight: 500; }
.notice.warning { background: color-mix(in srgb, var(--warning) 14%, transparent); }

/* ---------- Recherche et liste ---------- */

.search {
  position: sticky; top: 64px; z-index: 9;
  padding: 4px 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.search .input-wrap { border-radius: 14px; }
.search .input-wrap > svg { width: 20px; height: 20px; margin-left: 14px; color: var(--muted); flex: none; }
.search input { min-height: 48px; }

.group-letter {
  margin: 14px 4px 6px;
  font-size: .8rem; font-weight: 700; letter-spacing: .06em;
  color: var(--muted);
}

.list {
  margin: 0; padding: 0; list-style: none;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.list li + li { border-top: 1px solid var(--line); }

.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 10px 6px 10px 14px;
  background: none; border: 0; text-align: left;
  cursor: pointer;
}
.row:hover { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: .88rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px;
  border-radius: 12px;
  font-weight: 700; font-size: 1.05rem;
  color: #fff;
}
.avatar.big { width: 64px; height: 64px; border-radius: 18px; font-size: 1.6rem; }
.av0 { background: #5b67e0; } .av1 { background: #2f9c8a; } .av2 { background: #d0694a; }
.av3 { background: #9b59b6; } .av4 { background: #3d8bd9; } .av5 { background: #c74b7a; }
.av6 { background: #6f8f3a; } .av7 { background: #b8862b; }

.empty {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 56px 24px; text-align: center; color: var(--muted);
}
.empty svg { width: 48px; height: 48px; opacity: .6; }
.empty strong { color: var(--text); font-size: 1.1rem; }

/* ---------- État de synchronisation ---------- */

/* Pastille discrète : fond et texte prennent la couleur de l'état. */
.sync {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px;
  padding: 0 11px 0 9px;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, currentColor 11%, transparent);
  color: var(--muted);
  font: 600 .78rem/1 var(--font);
  letter-spacing: .01em;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s, color .15s;
}
.sync:hover { background: color-mix(in srgb, currentColor 18%, transparent); }
.sync:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
.sync svg { width: 14px; height: 14px; stroke-width: 2.5; }
.sync.synced { color: var(--success); }
.sync.pending, .sync.syncing { color: var(--warning); }
.sync.offline { color: var(--muted); }
.sync.error { color: var(--danger); }
.sync.syncing svg { animation: spin 1s linear infinite; }

/* Sur petit écran : seulement l'icône, dans un rond. */
@media (max-width: 420px) {
  .sync { width: 30px; padding: 0; justify-content: center; }
  .sync span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
}

/* ---------- Fiche ---------- */

.detail-head { display: flex; align-items: center; gap: 14px; padding: 8px 4px 18px; }
.detail-head h2 { margin: 0; font-size: 1.4rem; letter-spacing: -.02em; word-break: break-word; }

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card + .card { margin-top: 14px; }

.kv { display: flex; align-items: center; gap: 8px; padding: 12px 8px 12px 16px; min-height: 64px; }
.kv + .kv { border-top: 1px solid var(--line); }
.kv .main { flex: 1; min-width: 0; }
.kv .label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.kv .value { word-break: break-word; }
.kv .value.notes { white-space: pre-wrap; }
.kv .value.empty-value { color: var(--muted); font-style: italic; }
.kv .value.secret { font-family: var(--mono); font-size: 1.05rem; letter-spacing: .04em; }

.meta { padding: 14px 16px; font-size: .85rem; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }

.detail-actions { display: flex; gap: 10px; margin-top: 18px; }
.detail-actions .btn { flex: 1; }

/* Mot de passe affiché : chiffres et symboles colorés pour éviter les confusions */
.pw-digit { color: var(--accent-strong); }
.pw-symbol { color: var(--danger); }

/* ---------- Formulaire d'édition ---------- */

.photo-card {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 14px 16px;
  border: 1.5px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.photo-card svg { width: 28px; height: 28px; color: var(--accent-strong); flex: none; }
.photo-card strong { display: block; }
.photo-card span { font-size: .88rem; color: var(--muted); }

.ocr-lines { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  max-width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-family: var(--mono); font-size: .88rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: pointer;
}
.chip:hover { border-color: var(--accent); }

.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.bottom-bar > div { max-width: 608px; margin: 0 auto; display: flex; gap: 10px; }
.bottom-bar .btn { flex: 1; }

/* ---------- Indicateur de solidité ---------- */

.strength { display: flex; gap: 4px; }
.strength span { flex: 1; height: 5px; border-radius: 3px; background: var(--line); }
.strength.s1 span:nth-child(-n+1) { background: var(--danger); }
.strength.s2 span:nth-child(-n+2) { background: var(--warning); }
.strength.s3 span:nth-child(-n+3) { background: #7aa83a; }
.strength.s4 span:nth-child(-n+4) { background: var(--success); }

/* ---------- Modales ---------- */

dialog.modal {
  width: min(560px, 100%);
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
@media (min-width: 640px) {
  dialog.modal { margin: auto; border-radius: 22px; }
}
dialog.modal::backdrop { background: rgba(10, 12, 20, .5); backdrop-filter: blur(2px); }
dialog.modal[open] { animation: sheet-in .2s ease-out; }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-body { padding: 22px 20px 8px; display: flex; flex-direction: column; gap: 14px; }
.modal-body h2 { margin: 0; font-size: 1.25rem; letter-spacing: -.01em; }
.modal-body p { margin: 0; color: var(--muted); white-space: pre-line; }
.modal-actions {
  display: flex; gap: 10px;
  padding: 14px 20px calc(18px + var(--safe-bottom));
}
.modal-actions .btn { flex: 1; }

.recap { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; }
.recap .kv { min-height: 56px; }
.recap .changed .label::after {
  content: attr(data-changed);
  margin-left: 8px; padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-strong);
  font-size: .72rem;
}

/* ---------- Générateur ---------- */

.gen-output {
  display: flex; align-items: center; gap: 8px;
  padding: 16px;
  border-radius: 12px;
  background: var(--surface-2);
  font-family: var(--mono); font-size: 1.2rem;
  word-break: break-all;
}
.gen-output > span { flex: 1; }
.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--accent); height: 32px; }
.range-row output { min-width: 2.5ch; font-weight: 700; text-align: right; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Réglages ---------- */

.section-title {
  margin: 22px 4px 8px;
  font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted);
}
.setting {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  min-height: 60px;
  padding: 10px 16px;
  background: none; border: 0; text-align: left;
  cursor: pointer;
}
.setting + .setting { border-top: 1px solid var(--line); }
.setting:hover { background: var(--surface-2); }
.setting > svg { width: 22px; height: 22px; color: var(--accent-strong); flex: none; }
.setting .main { flex: 1; min-width: 0; }
.setting .main small { display: block; color: var(--muted); font-size: .85rem; }
.setting.danger > svg, .setting.danger .main { color: var(--danger); }
div.setting { cursor: default; }
div.setting:hover { background: none; }

/* ---------- Kit de secours ---------- */

.recovery-key {
  padding: 18px;
  border: 2px dashed var(--accent);
  border-radius: 14px;
  background: var(--accent-soft);
  font-family: var(--mono); font-size: 1.15rem; font-weight: 600;
  line-height: 1.8;
  text-align: center;
  word-spacing: .3em;
  user-select: all;
}

#print-kit { display: none; }

@media print {
  body { background: #fff; color: #000; }
  #app, .toasts, dialog { display: none !important; }
  #print-kit { display: block; padding: 24px; font-family: var(--font); }
  #print-kit h1 { font-size: 26px; margin: 0 0 8px; }
  #print-kit .recovery-key { background: #fff; border-color: #000; color: #000; font-size: 18px; margin: 18px 0; }
  #print-kit table { border-collapse: collapse; margin: 16px 0; }
  #print-kit td { padding: 6px 16px 6px 0; vertical-align: top; }
  #print-kit .box { border: 1px solid #000; height: 40px; margin-top: 6px; }
}

/* ---------- Notifications et chargement ---------- */

.toasts {
  position: fixed; left: 0; right: 0; bottom: calc(92px + var(--safe-bottom)); z-index: 100;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
  padding: 0 16px;
}
.toast {
  display: flex; align-items: center; gap: 12px;
  max-width: 560px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #1d2030; color: #fff;
  box-shadow: var(--shadow-lg);
  font-size: .95rem;
  pointer-events: auto;
  animation: sheet-in .2s ease-out;
}
.toast.error { background: var(--danger); }
.toast button { background: none; border: 0; color: #aab3ff; font-weight: 700; cursor: pointer; padding: 4px; }

.overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(4px);
  text-align: center; padding: 24px;
}
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.btn .spinner { width: 20px; height: 20px; border-width: 3px; border-color: rgba(255, 255, 255, .35); border-top-color: currentColor; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { width: min(280px, 80vw); height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); transition: width .2s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
