:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --text: #15181d;
  --muted: #697080;
  --line: #e3e6ea;
  --accent: #1f6f5c;
  --accent-soft: #e3f1ec;
  --accent-ink: #ffffff;
  --danger: #b4372b;
  --danger-soft: #fbe9e7;
  --folder: #c98a12;
  --folder-soft: #fbf1dc;
  --note: #2f66b3;
  --note-soft: #e4ecf8;
  --file: #5b6474;
  --file-soft: #eceef1;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .08);
  --radius: 14px;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1114;
    --surface: #181b20;
    --surface-2: #1e2228;
    --text: #e9ebee;
    --muted: #9aa1ad;
    --line: #2a2f37;
    --accent: #3fb48f;
    --accent-soft: #17312a;
    --accent-ink: #08130f;
    --danger: #f07d70;
    --danger-soft: #3a1d1a;
    --folder: #e2a93a;
    --folder-soft: #33280f;
    --note: #7aa7e8;
    --note-soft: #1a2638;
    --file: #a5adbb;
    --file-soft: #252a31;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
#app { min-height: 100%; }
.boot { padding: 40vh 16px 0; text-align: center; color: var(--muted); }
.hidden { display: none !important; }
svg.i { width: 22px; height: 22px; flex: none; }

/* ---------- вход */
.auth {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--top)) 16px calc(24px + var(--bottom));
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 20px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
}
.auth-logo { width: 64px; height: 64px; border-radius: 16px; display: block; margin: 0 auto 14px; }
.auth h1 { margin: 0 0 4px; font-size: 22px; text-align: center; }
.auth p { margin: 0 0 20px; color: var(--muted); text-align: center; font-size: 14px; }
.auth form { display: grid; gap: 12px; }

/* ---------- поля и кнопки */
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }
.input, textarea.input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  outline: none;
  min-height: 48px;
}
textarea.input { min-height: 140px; resize: vertical; line-height: 1.45; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; min-width: 0; }
.btn {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:disabled { opacity: .6; }
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); font-weight: 500; }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.sq { width: 48px; padding: 0; flex: none; }
.err { color: var(--danger); font-size: 14px; min-height: 1em; }

/* ---------- шапка */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  padding: calc(8px + var(--top)) 16px 8px;
  border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; gap: 6px; max-width: 820px; margin: 0 auto; min-height: 48px; }
.top-title { flex: 1; min-width: 0; font-size: 19px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 0;
  background: transparent;
  display: inline-grid;
  place-items: center;
  color: var(--text);
  flex: none;
}
.icon-btn:active, .icon-btn:hover { background: var(--surface-2); }
.search { max-width: 820px; margin: 6px auto 2px; position: relative; }
.search .input { padding-left: 42px; background: var(--surface); }
.search svg { position: absolute; left: 13px; top: 13px; color: var(--muted); }
.crumbs {
  max-width: 820px;
  margin: 6px auto 0;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
}
.crumbs::-webkit-scrollbar { display: none; }
.crumbs button { border: 0; background: none; color: var(--muted); padding: 4px 6px; border-radius: 8px; }
.crumbs button:last-child { color: var(--text); font-weight: 600; }
.crumbs .sep { padding: 4px 0; opacity: .5; }

/* ---------- список */
main { max-width: 820px; margin: 0 auto; padding: 12px 16px calc(110px + var(--bottom)); }
.section-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 4px 8px; }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 6px 10px 12px;
  min-height: 64px;
  border-top: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
}
.row:first-child { border-top: 0; }
.row:active, .row:hover { background: var(--surface-2); }
.tile {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex: none;
  overflow: hidden;
}
.tile.folder { background: var(--folder-soft); color: var(--folder); }
.tile.password { background: var(--accent-soft); color: var(--accent); }
.tile.note { background: var(--note-soft); color: var(--note); }
.tile.file { background: var(--file-soft); color: var(--file); font-size: 10px; font-weight: 700; letter-spacing: .02em; }
.tile.file img { width: 100%; height: 100%; object-fit: cover; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.row .icon-btn { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty svg { width: 48px; height: 48px; opacity: .5; margin-bottom: 8px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

/* ---------- кнопка «+» */
.fab {
  position: fixed;
  right: max(16px, calc(50vw - 410px + 16px));
  bottom: calc(20px + var(--bottom));
  width: 60px;
  height: 60px;
  border-radius: 18px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 6px 20px rgba(31, 111, 92, .4);
  display: grid;
  place-items: center;
  z-index: 6;
}
.fab svg { width: 28px; height: 28px; }

/* ---------- листы и окна */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 14, .45);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade .15s ease-out;
}
@media (min-width: 700px) { .backdrop { align-items: center; } }
.sheet {
  width: 100%;
  max-width: 560px;
  max-height: calc(100% - 40px - var(--top));
  overflow: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 8px 18px calc(18px + var(--bottom));
  animation: up .2s ease-out;
}
@media (min-width: 700px) { .sheet { border-radius: 20px; padding-bottom: 20px; } }
.grip { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 4px auto 12px; }
.sheet h2 { margin: 2px 0 14px; font-size: 19px; display: flex; align-items: center; gap: 10px; }
.sheet h2 .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sheet form, .stack { display: grid; gap: 12px; }
.actions { display: flex; gap: 10px; margin-top: 6px; }
.actions .btn { flex: 1; }
.menu { display: grid; }
.menu button {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 54px;
  border: 0;
  background: none;
  padding: 0 6px;
  border-radius: 12px;
  text-align: left;
  font-size: 16px;
}
.menu button:hover, .menu button:active { background: var(--surface-2); }
.menu button.danger { color: var(--danger); }
.menu .tile { width: 38px; height: 38px; border-radius: 10px; }
.kv { display: grid; gap: 6px; padding: 12px 14px; background: var(--surface-2); border-radius: 12px; border: 1px solid var(--line); }
.kv .k { font-size: 12px; color: var(--muted); }
.kv .v-row { display: flex; align-items: center; gap: 6px; }
.kv .v { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 17px; }
.kv .v.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; letter-spacing: .02em; }
.kv .icon-btn { width: 40px; height: 40px; color: var(--muted); }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.5; padding: 12px 14px; background: var(--surface-2); border-radius: 12px; border: 1px solid var(--line); }
.meta { font-size: 13px; color: var(--muted); }
.tree { display: grid; max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.tree button { border: 0; background: none; text-align: left; padding: 12px 14px; display: flex; gap: 10px; align-items: center; border-top: 1px solid var(--line); }
.tree button:first-child { border-top: 0; }
.tree button.sel { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree button:disabled { opacity: .4; }

/* ---------- просмотр файла */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #0b0c0e;
  color: #eceef1;
  display: flex;
  flex-direction: column;
  animation: fade .15s ease-out;
}
.viewer-bar { display: flex; align-items: center; gap: 4px; padding: calc(6px + var(--top)) 8px 6px; background: rgba(20, 22, 26, .95); }
.viewer-bar .icon-btn { color: #eceef1; }
.viewer-bar .icon-btn:hover { background: rgba(255, 255, 255, .08); }
.viewer-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; align-items: center; padding-bottom: var(--bottom); }
.viewer-body.center { justify-content: center; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; object-fit: contain; margin: auto; }
.viewer-body pre { white-space: pre-wrap; overflow-wrap: anywhere; padding: 16px; margin: 0; width: 100%; max-width: 900px; font-size: 14px; }
.pdf-page { width: 100%; max-width: 1000px; background: #fff; margin: 8px 0; box-shadow: 0 2px 10px rgba(0, 0, 0, .5); }
.pdf-page canvas { width: 100%; height: auto; display: block; }
.viewer .placeholder { text-align: center; color: #9aa1ad; padding: 40px 16px; display: grid; gap: 14px; justify-items: center; }

/* ---------- уведомления */
#toasts { position: fixed; left: 0; right: 0; bottom: calc(92px + var(--bottom)); z-index: 50; display: grid; justify-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: #1d2127; color: #f1f3f5; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); max-width: 480px; font-size: 15px; animation: up .2s ease-out; }
.toast.bad { background: #5a1f19; }
.progress { width: 220px; height: 4px; background: rgba(255, 255, 255, .2); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: #3fb48f; width: 0; transition: width .2s; }
.drop-hint { position: fixed; inset: 0; z-index: 40; background: color-mix(in srgb, var(--accent) 18%, transparent); border: 3px dashed var(--accent); display: grid; place-items: center; font-size: 22px; font-weight: 700; color: var(--accent); pointer-events: none; }

@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(16px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
