/* ==========================================================================
   Gestionnaire de mots de passe — design system 2026, mobile-first
   ========================================================================== */

:root {
  color-scheme: light;
  --surface-1:   #fcfcfb;
  --surface-2:   #f4f4f2;
  --surface-3:   #ffffff;
  --surface-blur: rgba(255,255,255,0.72);
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --border:      #e7e6e0;
  --border-strong: rgba(11,11,11,0.10);

  --accent:      #2a78d6;
  --accent-2:    #1baf7a;
  --accent-dark: #184f95;
  --accent-bg:   #eaf2fc;
  --accent-grad: linear-gradient(135deg, #2a78d6 0%, #1c5cab 100%);

  --good:        #0ca30c;
  --good-bg:     #e6f6e6;
  --warning:     #b5790f;
  --warning-bg:  #fdf2df;
  --critical:    #d03b3b;
  --critical-bg: #fbe9e9;

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;
  --shadow-xs: 0 1px 2px rgba(11,11,11,0.05);
  --shadow-sm: 0 2px 8px rgba(11,11,11,0.06), 0 1px 2px rgba(11,11,11,0.05);
  --shadow-md: 0 8px 24px rgba(11,11,11,0.10), 0 2px 6px rgba(11,11,11,0.06);
  --shadow-lg: 0 20px 48px rgba(11,11,11,0.20), 0 4px 12px rgba(11,11,11,0.08);
  --shadow-glow: 0 8px 24px rgba(42,120,214,0.25);

  --ease: cubic-bezier(.2,.8,.2,1);
  --font: system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --surface-1: #171716;
    --surface-2: #0d0d0d;
    --surface-3: #212120;
    --surface-blur: rgba(23,23,22,0.72);
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8d86;
    --border: #2c2c2a;
    --border-strong: rgba(255,255,255,0.10);

    --accent: #3987e5;
    --accent-2: #22c98a;
    --accent-dark: #86b6ef;
    --accent-bg: #16283f;
    --accent-grad: linear-gradient(135deg, #3987e5 0%, #2a78d6 100%);

    --good: #22c55e;
    --good-bg: #0f2b14;
    --warning: #fab219;
    --warning-bg: #3a2c0d;
    --critical: #f0625f;
    --critical-bg: #3a1414;

    --shadow-xs: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-sm: 0 2px 10px rgba(0,0,0,0.35);
    --shadow-md: 0 10px 28px rgba(0,0,0,0.45);
    --shadow-lg: 0 24px 56px rgba(0,0,0,0.55);
    --shadow-glow: 0 8px 28px rgba(57,135,229,0.35);
  }
}

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

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--surface-2);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: proportional-nums;
  letter-spacing: -0.01em;
}
h1, h2, h3 { line-height: 1.15; margin: 0 0 8px; letter-spacing: -0.02em; }
p { margin: 0 0 12px; color: var(--text-secondary); }
.muted { color: var(--text-muted); font-size: 14px; }
a { color: var(--accent); }

button, input, select, textarea { font-family: inherit; font-size: 16px; }

/* --- Layout --- */
.container { max-width: 1100px; margin: 0 auto; padding: 16px; padding-bottom: calc(96px + var(--safe-bottom)); }
@media (min-width: 900px) { .container { padding-bottom: 40px; } }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: calc(12px + var(--safe-top)) 20px 12px;
  background: var(--surface-blur);
  backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--border);
}
.topbar .brand {
  font-weight: 800; font-size: 16px; display: flex; align-items: center; gap: 6px;
  white-space: nowrap; flex: 0 0 auto; text-decoration: none; color: var(--text-primary);
}
.topbar-nav { display: none; gap: 2px; align-items: center; }
.topbar-nav a.btn.is-active { background: var(--accent-bg); color: var(--accent); }
@media (min-width: 720px) {
  .topbar-nav { display: flex; }
}

/* --- Bottom tab bar (mobile, app-like) --- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  background: var(--surface-blur);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-top: 1px solid var(--border);
  padding: 6px 6px calc(6px + var(--safe-bottom));
}
.bottom-nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border-radius: var(--radius-sm);
  text-decoration: none; color: var(--text-muted); font-size: 11px; font-weight: 600;
  transition: color .15s var(--ease), background .15s var(--ease);
}
.bottom-nav-item .icon { font-size: 20px; line-height: 1; transition: transform .15s var(--ease); }
.bottom-nav-item.is-active { color: var(--accent); }
.bottom-nav-item.is-active .icon { transform: translateY(-1px) scale(1.08); }
.bottom-nav-item:active .icon { transform: scale(0.9); }
@media (min-width: 720px) { .bottom-nav { display: none; } }

/* --- Auth pages --- */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 16px;
  background:
    radial-gradient(circle at 15% 10%, color-mix(in srgb, var(--accent) 12%, transparent) 0%, transparent 45%),
    radial-gradient(circle at 85% 90%, color-mix(in srgb, var(--accent-2) 10%, transparent) 0%, transparent 45%),
    var(--surface-2);
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 32px 26px;
  animation: rise .35s var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.auth-card h1 { font-size: 24px; margin-bottom: 6px; }
.auth-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.auth-card label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }

/* --- Forms --- */
input[type=text], input[type=password], input[type=search], input[type=url],
input[type=email], textarea, select {
  width: 100%;
  padding: 11px 13px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  color: var(--text-primary);
  outline: none;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-bg); }
textarea { resize: vertical; min-height: 60px; }

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text-primary);
  font-weight: 600; font-size: 14px;
  cursor: pointer;
  transition: transform .12s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease), border-color .15s var(--ease);
  text-decoration: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--surface-2); box-shadow: var(--shadow-xs); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent-grad); border-color: transparent; color: #fff; box-shadow: var(--shadow-glow); }
.btn-primary:hover { filter: brightness(1.08); box-shadow: var(--shadow-glow); }
.btn-danger { background: var(--critical-bg); border-color: var(--critical); color: var(--critical); }
.btn-danger:hover { background: var(--critical); color: #fff; }
.btn-success { background: var(--good-bg); border-color: var(--good); color: var(--good); }
.btn-success:hover { background: var(--good); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-icon { width: 42px; height: 42px; padding: 0; border-radius: 50%; }

.icon-btn-row { display: flex; gap: 10px; justify-content: center; }

/* --- Alerts / toasts --- */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 14px; margin-bottom: 4px; }
.alert-error { background: var(--critical-bg); color: var(--critical); }
.alert-success { background: var(--good-bg); color: var(--good); }

#toast-container {
  position: fixed; bottom: calc(90px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: 100%; padding: 0 16px; pointer-events: none;
}
@media (min-width: 720px) { #toast-container { bottom: 24px; } }
.toast {
  background: var(--text-primary); color: var(--surface-1);
  padding: 11px 20px; border-radius: 999px; font-size: 14px;
  box-shadow: var(--shadow-md);
  animation: toast-in .22s var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.96);} to { opacity: 1; transform: translateY(0) scale(1);} }

/* --- Dashboard --- */
h1.page-title { font-size: 26px; font-weight: 800; }

.stats-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px;
  margin: 20px 0;
}
@media (min-width: 640px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }
.stat-tile {
  position: relative; overflow: hidden;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-xs);
  animation: rise .3s var(--ease) backwards;
}
.stats-grid .stat-tile:nth-child(1) { animation-delay: .02s; }
.stats-grid .stat-tile:nth-child(2) { animation-delay: .06s; }
.stats-grid .stat-tile:nth-child(3) { animation-delay: .10s; }
.stats-grid .stat-tile:nth-child(4) { animation-delay: .14s; }
.stat-tile .icon-chip {
  width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 16px; margin-bottom: 10px;
}
.stat-tile .value { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.stat-tile .label { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.stat-tile.accent .icon-chip { background: var(--accent-bg); color: var(--accent); }
.stat-tile.accent .value { color: var(--accent); }
.stat-tile.warn .icon-chip { background: var(--warning-bg); color: var(--warning); }
.stat-tile.warn .value { color: var(--warning); }
.stat-tile.good .icon-chip { background: var(--good-bg); color: var(--good); }
.stat-tile.good .value { color: var(--good); }
.stat-tile.critical .icon-chip { background: var(--critical-bg); color: var(--critical); }
.stat-tile.critical .value { color: var(--critical); }

.actions-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin: 20px 0;
}
@media (min-width: 640px) { .actions-grid { grid-template-columns: repeat(4, 1fr); } }
.action-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 24px 12px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 14px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform .18s var(--ease), box-shadow .18s var(--ease), border-color .18s var(--ease);
}
.action-card:hover { box-shadow: var(--shadow-md); border-color: var(--accent); transform: translateY(-3px); }
.action-card:active { transform: translateY(-1px) scale(0.98); }
.action-card .emoji {
  font-size: 26px; width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-bg);
}

/* --- List page --- */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin: 12px 0;
  position: sticky; top: calc(56px + var(--safe-top)); z-index: 10;
  background: var(--surface-blur);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 10px 0;
  margin-top: 0;
}
.toolbar input[type=search] { flex: 1 1 220px; }
.toolbar select { flex: 0 0 auto; width: auto; }

.account-list { display: flex; flex-direction: column; gap: 8px; }
.account-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow .15s var(--ease), border-color .15s var(--ease);
}
.account-row:hover { box-shadow: var(--shadow-sm); border-color: var(--border-strong); }
.account-row .main { min-width: 0; }
.account-row .name { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-row .meta { font-size: 13px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-row .password-field { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 13px; }
.account-row .password-field code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-1); padding: 3px 7px; border-radius: 7px;
  letter-spacing: 1px;
}
.account-row .row-actions { display: flex; gap: 2px; align-items: flex-start; }
.badge {
  display: inline-block; font-size: 10.5px; font-weight: 700; padding: 3px 9px;
  border-radius: 999px; text-transform: uppercase; letter-spacing: .03em;
}
.badge-review { background: var(--warning-bg); color: var(--warning); }
.badge-kept { background: var(--good-bg); color: var(--good); }
.badge-changed { background: var(--accent-bg); color: var(--accent); }

.pagination { display: flex; justify-content: center; align-items: center; gap: 10px; margin: 20px 0; }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(11,11,11,0.55);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50; padding: 0;
  animation: fade-in .15s var(--ease);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@media (min-width: 640px) { .modal-overlay { align-items: center; padding: 16px; } }
.modal {
  background: var(--surface-3);
  width: 100%; max-width: 480px;
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  max-height: 92vh; overflow-y: auto;
  padding: 22px;
  box-shadow: var(--shadow-lg);
  animation: sheet-up .25s var(--ease);
}
@keyframes sheet-up { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@media (min-width: 640px) { .modal { border-radius: var(--radius-lg); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal .field { margin-bottom: 12px; }
.modal .field label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
.modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

/* --- Swipe interface --- */
.swipe-page {
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 16px calc(96px + var(--safe-bottom));
  min-height: calc(100vh - 56px);
}
@media (min-width: 720px) { .swipe-page { padding-bottom: 40px; } }
.swipe-progress { width: 100%; max-width: 420px; margin-bottom: 8px; }
.swipe-progress .bar { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.swipe-progress .fill { height: 100%; background: var(--accent-grad); transition: width .25s var(--ease); }
.swipe-progress .count { font-size: 13px; color: var(--text-muted); margin-top: 6px; text-align: center; font-weight: 600; }

.card-stack {
  position: relative;
  width: 100%; max-width: 420px;
  height: 60vh; min-height: 380px; max-height: 500px;
  margin: 12px 0;
}
.swipe-card {
  position: absolute; inset: 0;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  padding: 26px 22px;
  display: flex; flex-direction: column;
  justify-content: center; /* évite un grand vide en bas sur les cartes sans note */
  touch-action: pan-y;
  will-change: transform;
  user-select: none;
}
.swipe-card:not(.top) { pointer-events: none; }
.swipe-card .favicon {
  width: 44px; height: 44px; border-radius: 13px;
  background: var(--accent-grad); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800; margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}
.swipe-card .site-name { font-size: 23px; font-weight: 800; word-break: break-word; }
.swipe-card .site-url { font-size: 13px; color: var(--accent); word-break: break-all; margin-bottom: 16px; text-decoration: none; }
.swipe-card .field-block { margin-top: 12px; }
.swipe-card .field-block label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 700; }
.swipe-card .field-value { font-size: 16px; margin-top: 3px; word-break: break-all; display: flex; align-items: center; gap: 8px; }
.swipe-card .note { margin-top: 14px; font-size: 13px; color: var(--text-secondary); background: var(--surface-1); padding: 10px 12px; border-radius: 10px; flex: 1; overflow-y: auto; }
.swipe-card .stamp {
  position: absolute; top: 24px; font-weight: 800; font-size: 22px; padding: 6px 14px;
  border: 3px solid; border-radius: 10px; opacity: 0; transform: rotate(-12deg);
  text-transform: uppercase; letter-spacing: .05em;
}
.swipe-card .stamp.keep { left: 20px; color: var(--good); border-color: var(--good); }
.swipe-card .stamp.reject { right: 20px; color: var(--critical); border-color: var(--critical); transform: rotate(12deg); }
.swipe-card .stamp.review { left: 50%; top: 12px; transform: translateX(-50%) rotate(0deg); color: var(--warning); border-color: var(--warning); }

.swipe-actions { display: flex; gap: 16px; margin-top: 12px; }
.swipe-actions .btn-icon { width: 58px; height: 58px; font-size: 22px; box-shadow: var(--shadow-sm); border-width: 1.5px; }
.swipe-actions .btn-icon:hover { transform: translateY(-2px); }
.swipe-hint { text-align: center; margin-top: 10px; }
.swipe-empty { text-align: center; padding: 60px 20px; animation: rise .3s var(--ease); }
.swipe-empty .emoji {
  font-size: 44px; width: 88px; height: 88px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; margin: 0 auto 16px;
  background: var(--good-bg);
}

.kbd-hint { display: none; }
@media (min-width: 900px) {
  .kbd-hint { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
  .kbd-hint span { background: var(--surface-3); border: 1px solid var(--border); border-radius: 6px; padding: 3px 9px; font-size: 12px; color: var(--text-muted); font-weight: 600; }
}

/* --- Import page --- */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius-lg);
  padding: 44px 20px; text-align: center; color: var(--text-muted);
  cursor: pointer;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.dragover { border-color: var(--accent); background: var(--accent-bg); }
.progress-bar { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; margin: 12px 0; }
.progress-bar .fill { height: 100%; background: var(--accent-grad); width: 0%; transition: width .15s var(--ease); }

/* --- Skeleton loading --- */
.skeleton-row {
  height: 92px; border-radius: var(--radius-md);
  background: linear-gradient(100deg, var(--surface-3) 30%, var(--surface-2) 50%, var(--surface-3) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border: 1px solid var(--border);
}
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }

/* --- Utility --- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-8 { gap: 8px; }
.mt-16 { margin-top: 16px; }
.text-center { text-align: center; }
.empty-state { text-align: center; padding: 48px 16px; color: var(--text-muted); }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .7s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }
