/* ============================================================================
   p2pfs — gestionnaire de fichiers chiffré. Thème clair (façon Drive/Nextcloud)
   avec barre latérale acier sombre + accent teal "chiffrement" + dossiers ambre.
   Mode sombre automatique via prefers-color-scheme.
   ========================================================================== */
:root {
  --bg:        #f5f7f9;
  --surface:   #ffffff;
  --surface-2: #eef1f5;
  --line:      #e2e7ee;
  --line-2:    #d4dae3;
  --txt:       #1b2330;
  --txt-dim:   #5d6b7e;
  --txt-faint: #8a97a8;

  --sidebar:   #111a24;
  --sidebar-2: #1a2531;
  --sidebar-line: #283645;
  --sidebar-txt:  #cdd6e0;
  --sidebar-dim:  #7f8c9c;

  --accent:    #0e9aa6;   /* teal "secure" */
  --accent-h:  #0b818c;
  --accent-tint:#e0f4f5;
  --folder:    #e0a13b;   /* ambre — chemises kraft */
  --danger:    #d6464a;
  --danger-tint:#fdecec;

  --radius:    11px;
  --radius-sm: 8px;
  --shadow:    0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.14);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:#0c1116; --surface:#141b22; --surface-2:#1b242d; --line:#26313c; --line-2:#33414f;
    --txt:#e6eaef; --txt-dim:#9fadbd; --txt-faint:#6f7d8c;
    --sidebar:#0a0f14; --sidebar-2:#121a22; --sidebar-line:#1f2a35;
    --accent-tint:#0c2c30; --danger-tint:#2a1517; --shadow:none;
    --shadow-lg:0 12px 34px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--txt); font-family: var(--font);
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.ic { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.7;
  fill: none; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---- boutons ---- */
.btn { display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  font: 500 13.5px var(--font); border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 9px 14px; transition: background .14s, border-color .14s, color .14s; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); }
.btn-ghost { background: transparent; border-color: var(--line-2); color: var(--txt); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ---- marque ---- */
.brand-mark { width: 26px; height: 26px; fill: none; stroke: var(--accent);
  stroke-width: 1.6; stroke-linejoin: round; }
.brand-mark .check { stroke: var(--accent); stroke-width: 2; }

/* ============================ CONNEXION ============================ */
.auth-screen { min-height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 22px; padding: 24px; }
.auth-card { width: 100%; max-width: 440px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow-lg); padding: 34px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700;
  font-size: 19px; letter-spacing: -.01em; }
.auth-card h1 { font-size: 23px; letter-spacing: -.02em; margin: 22px 0 8px; }
.auth-card .sub { color: var(--txt-dim); margin: 0 0 18px; font-size: 13px; }
#seed { width: 100%; resize: vertical; padding: 13px; border-radius: var(--radius);
  border: 1px solid var(--line-2); background: var(--bg); color: var(--txt);
  font-family: var(--mono); font-size: 14px; line-height: 1.7; }
#seed:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.auth-actions { display: flex; gap: 10px; margin-top: 16px; }
.auth-actions .btn { flex: 1; justify-content: center; }
.auth-status { min-height: 18px; margin: 14px 0 0; font-size: 13px; color: var(--txt-dim); }
.auth-status.err { color: var(--danger); }
.auth-foot { color: var(--txt-faint); font-size: 12px; text-align: center; }

/* ============================ APP SHELL ============================ */
.app { display: grid; grid-template-columns: 248px 1fr; height: 100vh; }

/* ---- sidebar ---- */
.sidebar { background: var(--sidebar); color: var(--sidebar-txt);
  display: flex; flex-direction: column; padding: 18px 14px; gap: 16px;
  border-right: 1px solid var(--sidebar-line); }
.side-brand { display: flex; align-items: center; gap: 9px; font-weight: 700;
  font-size: 17px; color: #fff; padding: 4px 6px; }
.new-wrap { position: relative; }
.new-btn { width: 100%; justify-content: center; padding: 11px; font-size: 14px; }
.menu { position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 20;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px; display: flex; flex-direction: column; }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; color: var(--txt); padding: 9px 10px; border-radius: 7px;
  font: 500 13.5px var(--font); cursor: pointer; text-align: left; }
.menu button:hover { background: var(--surface-2); color: var(--accent); }
.side-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 11px; background: none; border: 0;
  color: var(--sidebar-dim); padding: 9px 11px; border-radius: 8px; cursor: pointer;
  font: 500 13.5px var(--font); text-align: left; transition: background .14s, color .14s; }
.nav-item:hover { background: var(--sidebar-2); color: var(--sidebar-txt); }
.nav-item.active { background: var(--sidebar-2); color: #fff; }
.nav-item.active .ic { stroke: var(--accent); }
.side-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 14px; }
.vault-meter { background: var(--sidebar-2); border: 1px solid var(--sidebar-line);
  border-radius: var(--radius); padding: 12px 13px; }
.vm-head { display: flex; justify-content: space-between; font-size: 12px;
  color: var(--sidebar-dim); margin-bottom: 8px; }
.vm-head span:last-child { color: var(--sidebar-txt); font-weight: 600; font-variant-numeric: tabular-nums; }
.vm-bar { height: 6px; background: #0a1118; border-radius: 99px; overflow: hidden; }
.vm-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), #2fd0d8);
  border-radius: 99px; transition: width .4s ease; }
.vm-files { margin-top: 8px; font-size: 11.5px; color: var(--sidebar-dim); }
.identity { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.identity .key { stroke: var(--accent); width: 22px; height: 22px; }
.id-label { font-size: 11px; color: var(--sidebar-dim); }
.identity code { font-family: var(--mono); font-size: 12px; color: var(--sidebar-txt); letter-spacing: .02em; }
.lock-btn { justify-content: center; border-color: var(--sidebar-line); color: var(--sidebar-txt); }
.lock-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---- topbar ---- */
.content { display: flex; flex-direction: column; min-width: 0; position: relative; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 24px; height: 62px; border-bottom: 1px solid var(--line);
  background: var(--surface); flex: none; }
.crumbs { display: flex; align-items: center; gap: 4px; font-size: 15px;
  min-width: 0; overflow: hidden; }
.crumbs button { background: none; border: 0; cursor: pointer; color: var(--txt-dim);
  font: 600 15px var(--font); padding: 5px 7px; border-radius: 6px; white-space: nowrap; }
.crumbs button:hover { background: var(--surface-2); color: var(--txt); }
.crumbs button.current { color: var(--txt); cursor: default; }
.crumbs button.current:hover { background: none; }
.crumbs .sep { color: var(--txt-faint); }
.top-tools { display: flex; align-items: center; gap: 12px; flex: none; }
.search { display: flex; align-items: center; gap: 8px; background: var(--surface-2);
  border: 1px solid transparent; border-radius: 9px; padding: 7px 11px; width: 260px; }
.search:focus-within { border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-tint); }
.search .ic { color: var(--txt-faint); width: 16px; height: 16px; }
.search input { border: 0; background: none; outline: none; width: 100%;
  color: var(--txt); font: 13.5px var(--font); }
.view-toggle { display: flex; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.vt { background: none; border: 0; cursor: pointer; color: var(--txt-dim);
  padding: 6px; border-radius: 6px; display: flex; }
.vt.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

/* ---- canvas ---- */
.canvas { flex: 1; overflow-y: auto; padding: 22px 24px 60px; }

/* grille */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 14px; cursor: pointer; position: relative; transition: border-color .14s, box-shadow .14s, transform .05s; }
.tile:hover { border-color: var(--line-2); box-shadow: var(--shadow); }
.tile:active { transform: translateY(1px); }
.tile .ico { width: 42px; height: 42px; margin-bottom: 12px; }
.tile .t-name { font-weight: 550; font-size: 13.5px; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile .t-meta { color: var(--txt-faint); font-size: 12px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .t-more { position: absolute; top: 10px; right: 8px; opacity: 0; }
.tile:hover .t-more { opacity: 1; }

/* liste */
.list { width: 100%; border-collapse: collapse; }
.list thead th { text-align: left; font-weight: 600; font-size: 12px; color: var(--txt-faint);
  padding: 8px 12px; border-bottom: 1px solid var(--line); text-transform: uppercase; letter-spacing: .04em; }
.list .c-size { width: 110px; } .list .c-date { width: 150px; } .list .c-act { width: 132px; }
.list tbody tr { cursor: pointer; }
.list tbody tr:hover { background: var(--surface-2); }
.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.list .l-name { display: flex; align-items: center; gap: 12px; font-weight: 500; }
.list .l-name .ico { width: 26px; height: 26px; flex: none; }
.list .c-size, .list .c-date { color: var(--txt-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.list .c-act { text-align: right; }
.row-actions { display: inline-flex; gap: 2px; opacity: 0; }
tr:hover .row-actions, .tile:hover .t-more .row-actions { opacity: 1; }
.icon-btn { background: none; border: 0; cursor: pointer; color: var(--txt-faint);
  padding: 6px; border-radius: 6px; display: inline-flex; }
.icon-btn:hover { background: var(--line); color: var(--txt); }
.icon-btn.danger:hover { background: var(--danger-tint); color: var(--danger); }

/* état vide */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 70px 20px; color: var(--txt-dim); }
.empty svg { width: 56px; height: 56px; color: var(--line-2); margin-bottom: 16px;
  stroke-width: 1.3; fill: none; stroke: currentColor; }
.empty h2 { margin: 0 0 6px; font-size: 16px; color: var(--txt); }
.empty p { margin: 0; font-size: 13.5px; }

/* drop overlay */
.drop-overlay { position: absolute; inset: 0; z-index: 30; background: rgba(14,154,166,.07);
  backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center; padding: 18px; }
.drop-inner { border: 2px dashed var(--accent); border-radius: 18px; width: 100%; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; color: var(--accent); background: var(--surface); }
.drop-inner svg { width: 46px; height: 46px; }
.drop-inner p { font-weight: 600; font-size: 16px; }

/* modale */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(16,24,40,.45);
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: var(--surface); border-radius: 15px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 400px; padding: 24px; }
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.modal input { width: 100%; padding: 11px 13px; border: 1px solid var(--line-2);
  border-radius: var(--radius); background: var(--bg); color: var(--txt); font: 14px var(--font); }
.modal input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.modal-error { min-height: 16px; margin: 8px 0 0; font-size: 12.5px; color: var(--danger); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* toasts */
.toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--sidebar); color: #fff; padding: 11px 18px; border-radius: 10px;
  box-shadow: var(--shadow-lg); font-size: 13.5px; display: flex; align-items: center; gap: 9px;
  animation: toast-in .18s ease; max-width: 90vw; }
.toast .ic { width: 16px; height: 16px; }
.toast.ok .ic { stroke: #2fd0d8; } .toast.err { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* hamburger + fond de tiroir : cachés sur desktop, révélés en mobile */
.menu-btn { display: none; }
#sidebar-backdrop { display: none; }

/* responsive */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }

  /* la barre latérale devient un TIROIR coulissant (au lieu d'être masquée :
     elle contient Nouveau, la navigation, Verrouiller, Ajouter une clé…). */
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 272px; max-width: 84vw;
    z-index: 45; transform: translateX(-100%); transition: transform .22s ease;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  #sidebar-backdrop {
    display: block; position: fixed; inset: 0; z-index: 40; background: rgba(16,24,40,.5);
    opacity: 0; pointer-events: none; transition: opacity .22s ease;
  }
  #sidebar-backdrop.show { opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-flex; padding: 9px; margin-left: -5px; } /* cible tactile ~40px */

  /* topbar resserrée */
  .topbar { padding: 0 12px; gap: 10px; height: 56px; }
  .crumbs { font-size: 14px; }
  .crumbs button { font-size: 14px; padding: 5px 5px; }
  .top-tools { gap: 8px; }
  .search { width: auto; flex: 1 1 auto; min-width: 0; max-width: 220px; }

  /* canvas + grille plus compacts */
  .canvas { padding: 16px 14px 84px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }

  /* liste : la date est trop large pour un petit écran */
  .list .c-date { display: none; }
  .list .c-size { width: 78px; }
  .list .c-act { width: 124px; }
  .list td, .list thead th { padding: 9px 8px; }

  /* pas de survol au doigt : les actions (… / icônes) restent visibles */
  .tile .t-more, .row-actions { opacity: 1; }
}

/* très petits écrans : libérer la topbar et empiler les boutons d'accueil */
@media (max-width: 400px) {
  .view-toggle { display: none; }       /* la grille par défaut suffit ; évite tout débordement */
  .auth-card { padding: 26px 20px; }
  .auth-actions { flex-direction: column; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* icônes de fichiers/dossiers (couleurs par classe — compatible CSP stricte) */
.ico { fill: none; stroke: var(--accent); stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round; }
.ico.k-folder { stroke: var(--folder); fill: var(--folder); fill-opacity: .16; }

/* petit menu d'actions (grille) */
.sheet-box { display: flex; flex-direction: column; gap: 6px; }
.sheet-box .btn { justify-content: center; }

/* liste des dossiers de destination (déplacement) */
.move-list { display: flex; flex-direction: column; gap: 2px; max-height: 46vh;
  overflow-y: auto; margin: 4px 0; }
.move-item { display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; color: var(--txt); padding: 9px 10px; border-radius: 7px;
  font: 500 13.5px var(--font); cursor: pointer; text-align: left; }
.move-item:hover { background: var(--surface-2); color: var(--accent); }
.move-item .ico { width: 20px; height: 20px; flex: none; }

/* spinner du toast de progression */
.toast .spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* écran d'accueil : bouton « déverrouiller par clé » pleine largeur + séparateur */
.auth-key-btn { width: 100%; justify-content: center; }
.auth-or { display: flex; align-items: center; gap: 10px; margin: 16px 0 12px;
  color: var(--txt-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.auth-or::before, .auth-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* texte explicatif de l'encart d'enrôlement de clé */
.modal-text { color: var(--txt-dim); font-size: 14px; line-height: 1.5; margin: 4px 0 18px; }
.modal-text strong { color: var(--txt); font-weight: 600; }

/* mise en avant temporaire du bouton « Ajouter une clé de sécurité » après
   la création d'un coffre (pour inviter à ne plus saisir la seed). */
.pulse { animation: pulse 1.3s ease-out 4; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(14,154,166,.55); }
  70%  { box-shadow: 0 0 0 10px rgba(14,154,166,0); }
  100% { box-shadow: 0 0 0 0 rgba(14,154,166,0); }
}
