:root {
  --bg: #f4f5f7; --panel: #ffffff; --fg: #1f2328; --muted: #6b7280; --border: #dfe3e8;
  --accent: #2563eb; --accent-fg: #fff; --danger: #dc2626; --ok: #16a34a; --warn: #d97706;
  --sel: #e8efff; --radius: 8px; --shadow: 0 10px 30px rgba(0,0,0,.12);
  --side: #e9ebef; --list: #f3f4f6; --hover: rgba(0,0,0,.05); --pick: #dcdfe5;
  color-scheme: light;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}
/* Dark theme: chosen explicitly, or following the system when no choice was made. */
:root[data-theme="dark"] {
  --bg: #15171b; --panel: #1e2126; --fg: #e6e8eb; --muted: #9aa1ab; --border: #2e333a; --sel: #23324f; --shadow: 0 10px 30px rgba(0,0,0,.5);
  --side: #181a1f; --list: #1b1e23; --hover: rgba(255,255,255,.06); --pick: #2a2f37; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171b; --panel: #1e2126; --fg: #e6e8eb; --muted: #9aa1ab; --border: #2e333a; --sel: #23324f; --shadow: 0 10px 30px rgba(0,0,0,.5);
    --side: #181a1f; --list: #1b1e23; --hover: rgba(255,255,255,.06); --pick: #2a2f37; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font-size: 14px; }
#app { height: 100%; } /* the app fills the window: footer stays at the bottom, columns scroll inside */
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--border); background: var(--panel); border-radius: 6px; padding: 6px 12px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
button.link { border: none; background: none; color: var(--accent); padding: 2px 4px; }
button:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  border: 1px solid var(--border); background: var(--panel); border-radius: 6px; padding: 7px 9px; width: 100%;
}
textarea { min-height: 80px; resize: vertical; }
label { display: block; margin: 10px 0 4px; color: var(--muted); font-size: 12px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; color: var(--fg); font-size: 14px; margin: 6px 12px 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.error { color: var(--danger); margin-top: 8px; min-height: 18px; }
.okmsg { color: var(--ok); margin-top: 8px; }
.warnmsg { color: var(--warn); margin-top: 8px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--sel); color: var(--accent); margin-left: 6px; }
.badge.red { background: #fde2e2; color: var(--danger); }
.badge.green { background: #dcfce7; color: var(--ok); }
.badge.gray { background: var(--bg); color: var(--muted); }
.badge.amber { background: #fef3c7; color: var(--warn); }

/* login */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 28px; width: 380px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card .qr { display: block; margin: 12px auto; width: 200px; height: 200px; image-rendering: pixelated; background: #fff; border-radius: 6px; }
.login-card button.primary { width: 100%; margin-top: 16px; padding: 9px; }

/* layout */
.app { display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.footer { flex: none; }
.topbar { flex: none; }
.topbar { display: flex; align-items: center; gap: 6px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border); min-height: 56px; }
.topbar .brand { font-weight: 700; font-size: 17px; margin-right: 12px; white-space: nowrap; }
.topbar nav button { border: none; background: none; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.topbar nav button:hover { background: var(--hover); }
.topbar nav button.active { background: var(--sel); color: var(--accent); }
.search-wrap { position: relative; flex: 1; max-width: 520px; margin: 0 12px; }
.search-wrap .ic { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.topbar .search { width: 100%; padding: 8px 12px 8px 36px; border-radius: 8px; background: var(--bg); }
.user-btn { display: inline-flex; align-items: center; gap: 8px; border: none; background: none; padding: 4px 8px; border-radius: 8px; }
.user-btn:hover { background: var(--hover); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--sel); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; flex: none; }
.user-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 290px; flex: none; background: var(--side); border-right: 1px solid var(--border); overflow-y: auto; padding: 12px 8px; display: flex; flex-direction: column; }
.col-list { width: 370px; flex: none; background: var(--list); border-right: 1px solid var(--border); overflow-y: auto; padding: 10px 8px; }
.col-detail { flex: 1; min-width: 0; overflow-y: auto; background: var(--panel); padding: 18px 28px; }
.content { flex: 1; overflow-y: auto; padding: 16px 20px; min-width: 0; }
.footer { padding: 4px 14px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--border); background: var(--panel); }
.pad { padding: 0 8px; }
@media (max-width: 1150px) { .sidebar { width: 230px; } .col-list { width: 290px; } .user-name { display: none; } }

/* icons, icon buttons, popup menus */
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.ic.big { width: 40px; height: 40px; stroke-width: 1.2; opacity: .5; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; border: none; background: none; padding: 7px; border-radius: 7px; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.popmenu { position: fixed; z-index: 60; min-width: 230px; max-width: 340px; max-height: 70vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; }
.popmenu-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: none; background: none; padding: 8px 10px; border-radius: 6px; }
.popmenu-item:hover { background: var(--hover); }
.popmenu-item.active { color: var(--accent); font-weight: 600; }
.popmenu-item.danger { color: var(--danger); }
.popmenu-item .pm-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popmenu-head { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px 4px; }
.popmenu-sep { height: 1px; background: var(--border); margin: 5px 4px; }

/* left column: all vaults as one tree, vault actions at the bottom */
.side-title { margin: 2px 8px 8px; }
.side-actions { margin-top: auto; padding: 12px 6px 4px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.side-actions .small { padding: 0 6px 4px; }
.side-btn { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: none; background: none; padding: 8px 8px; border-radius: 7px; color: var(--accent); }
.side-btn:hover { background: var(--hover); }
.tree { margin-bottom: 12px; }
.tree-item.vault { font-weight: 600; }
.tree { display: flex; flex-direction: column; gap: 1px; }
.tree-item { display: flex; align-items: center; gap: 6px; padding: 8px 8px; border-radius: 7px; cursor: pointer; white-space: nowrap; min-height: 38px; }
.tree-item:hover { background: var(--hover); }
.tree-item.sel { background: var(--pick); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.tree-item.transit { color: var(--muted); font-style: italic; }
.tree-item .tw { width: 18px; height: 18px; flex: none; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); border-radius: 4px; }
.tree-item .tw:hover { background: var(--hover); color: var(--fg); }
.tree-item .tw .ic { width: 14px; height: 14px; }
.tree-item .ti { color: var(--muted); }
.tree-item.sel .ti { color: var(--fg); }
.tree-item .tn { overflow: hidden; text-overflow: ellipsis; }

/* middle column: folder contents */
.list-crumbs { font-size: 12px; color: var(--muted); padding: 4px 8px 0; min-height: 18px; }
.list-head { display: flex; align-items: center; gap: 4px; padding: 2px 4px 6px 8px; }
.list-title { flex: 1; font-size: 19px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-acts { display: flex; gap: 2px; }
.list-items { display: flex; flex-direction: column; gap: 1px; margin-top: 8px; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 7px; cursor: pointer; min-height: 46px; }
.list-item:hover { background: var(--hover); }
.list-item.sel { background: var(--pick); box-shadow: inset 3px 0 0 var(--accent); }
.list-item.sel .li-title { font-weight: 600; }
.list-item.transit { color: var(--muted); font-style: italic; }
.list-item .li-ic { color: var(--muted); }
.li-main { flex: 1; min-width: 0; }
.li-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-meta { display: flex; align-items: center; gap: 4px; flex: none; flex-wrap: wrap; justify-content: flex-end; max-width: 50%; }
.li-meta .badge { margin-left: 0; }

/* right column: record */
.detail-empty { display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 80px; }
.rec-head { display: flex; align-items: center; gap: 10px; }
.rec-head .rec-ic { color: var(--muted); width: 22px; height: 22px; }
.rec-title { flex: 1; min-width: 0; font-size: 21px; font-weight: 600; overflow-wrap: anywhere; }
.rec-actions { display: flex; gap: 2px; flex: none; }
.rec .crumbs { margin: 4px 0 0 32px; }
.rec-tabs { margin: 14px 0 6px; }
.rec-tabs button { flex: 1; padding: 10px 8px; }
.rec .fieldrow { display: block; padding: 10px 0; border-bottom: 1px solid var(--border); }
.rec .fieldrow .k { width: auto; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.fv { display: flex; align-items: center; gap: 8px; min-height: 30px; }
.fv .v { flex: 1; min-width: 0; word-break: break-all; }
.fv .fa { display: flex; gap: 2px; flex: none; }
.att-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.att-row .v { flex: 1; min-width: 0; word-break: break-all; }
.rec-meta { margin-top: 14px; }

/* settings: vertical tabs, forms of limited width */
.settings-layout { display: flex; gap: 22px; align-items: flex-start; }
.vtabs { width: 220px; flex: none; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; }
.vtabs button { text-align: left; border: none; background: none; padding: 9px 12px; border-radius: 7px; }
.vtabs button:hover { background: var(--hover); }
.vtabs button.active { background: var(--sel); color: var(--accent); font-weight: 600; }
.vpanes { flex: 1; min-width: 0; max-width: 680px; }
.vpanes .section-title:first-child { margin-top: 4px; }
.card.form .form-field { margin-bottom: 4px; }
input.num { width: 160px; }
.save-row { margin-top: 8px; }
.card.narrow { max-width: 560px; }
@media (max-width: 900px) { .settings-layout { flex-direction: column; } .vtabs { width: 100%; flex-direction: row; flex-wrap: wrap; position: static; } }

/* audit filters */
.filters { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; }
.filters .filter label { margin-top: 0; }
.filters .filter select { width: 230px; }
.filters .filter.date input { width: 160px; }
.u-name { font-weight: 600; }

/* tables */
table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.grid th, table.grid td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.grid th { font-weight: 600; color: var(--muted); font-size: 12px; background: var(--bg); }
table.grid tr:last-child td { border-bottom: none; }
table.grid tr.click { cursor: pointer; }
table.grid tr.click:hover td { background: var(--bg); }
.h2 { font-size: 18px; font-weight: 600; margin: 0 0 12px; }
.section-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 0 8px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.crumbs { color: var(--muted); margin-bottom: 10px; font-size: 12px; }

/* share timer */
.share-ind { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--warn); }
.share-ind .t { font-family: ui-monospace, monospace; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: flex-start; justify-content: center; padding: 50px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); width: 560px; max-width: 100%; }
.modal.wide { width: 860px; }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; display: flex; align-items: center; }
.modal-body { padding: 14px 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }

/* record card */
.fieldrow { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px dashed var(--border); }
.fieldrow .k { width: 140px; color: var(--muted); flex: none; }
.fieldrow .v { flex: 1; min-width: 0; word-break: break-all; }
.fieldrow .v.secret { font-family: ui-monospace, monospace; letter-spacing: .1em; }
.totp-code { font-family: ui-monospace, monospace; font-size: 20px; letter-spacing: .15em; }
.totp-bar { height: 4px; background: var(--border); border-radius: 2px; width: 120px; overflow: hidden; }
.totp-bar > div { height: 100%; background: var(--accent); transition: width 1s linear; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 12px 0; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; }
.tabs button.active { border-bottom-color: var(--accent); color: var(--accent); }
.toast { position: fixed; bottom: 18px; right: 18px; background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 8px; z-index: 100; box-shadow: var(--shadow); }
.change-list { margin: 6px 0 12px 16px; padding: 0; }
.perm-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px 12px; }
.pw-strength { height: 4px; border-radius: 2px; margin-top: 4px; background: var(--border); }
.pw-strength > div { height: 100%; border-radius: 2px; }
.empty { color: var(--muted); padding: 30px; text-align: center; }
.linkbox { font-family: ui-monospace, monospace; background: var(--bg); padding: 8px; border-radius: 6px; word-break: break-all; }

/* public share page */
.share-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 28px; width: 440px; max-width: 100%; box-shadow: var(--shadow); }
/* v2: personal vault, results */
.tree-item.personal { font-weight: 600; }
.personal-note { color: var(--accent); margin: 4px 0 8px; }
.linkbox.big { font-size: 1.25em; letter-spacing: .04em; text-align: center; }
pre.mono { white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow: auto; margin: 6px 0 0; }
.card + .card { margin-top: 8px; }
/* drag-and-drop ordering */
.sortable { -webkit-user-drag: element; }
.dragging { opacity: .45; }
.drop-before { box-shadow: inset 0 2px 0 var(--accent) !important; }
.drop-after { box-shadow: inset 0 -2px 0 var(--accent) !important; }
.order-hint { margin-top: 10px; }
.users-bar { margin-bottom: 10px; }
.users-bar select.user-filter { width: 230px; }
.grant-row { margin-top: 10px; } .grant-row select { flex: 1; min-width: 0; }
.login-alt { text-align: center; margin-top: 10px; }
/* move destination tree */
.dest-tree { max-height: 46vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 4px; background: var(--bg); }
.dest-item { display: flex; align-items: center; gap: 6px; padding: 7px 8px; border-radius: 6px; cursor: pointer; }
.dest-item:hover { background: var(--hover); }
.dest-item.sel { background: var(--sel); color: var(--accent); font-weight: 600; }
.dest-item.disabled { cursor: default; color: var(--muted); }
.dest-item.disabled:hover { background: none; }
.dest-item .ti { color: var(--muted); }
.dest-item .tn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dest-why { font-size: 11px; color: var(--muted); flex: none; }
th.sortable-th { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable-th:hover, th.sorted { color: var(--fg); }
.note-text { white-space: pre-wrap; word-break: break-word; }
.bx-by { width: auto; flex: none; }
.topbar .theme-btn { margin-right: 2px; }

/* Справка (0.4.5) */
.help-layout { display: flex; gap: 18px; align-items: flex-start; }
.help-side { width: 260px; flex: none; position: sticky; top: 0; }
.help-search { margin-bottom: 8px; }
.help-toc { display: flex; flex-direction: column; gap: 2px; }
.help-toc button { text-align: left; border: none; background: none; padding: 7px 10px; border-radius: 6px; }
.help-toc button:hover { background: var(--hover); }
.help-toc button.active { background: var(--sel); color: var(--accent); }
.help-toc button.admin::before { content: '⚙ '; color: var(--muted); }
.help-main { flex: 1; min-width: 0; max-width: 820px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 22px; }
.help-text { line-height: 1.55; }
.help-text h4 { margin: 16px 0 6px; font-size: 14px; }
.help-text p { margin: 6px 0 10px; }
.help-text ul, .help-text ol { margin: 6px 0 10px; padding-left: 22px; }
.help-text li { margin: 3px 0; }
.help-text table.grid { margin: 8px 0 12px; }
.help-modal .modal-body { max-height: 70vh; overflow-y: auto; }
.modal-title { display: inline-flex; align-items: center; gap: 6px; }
.icon-btn.help-inline { width: 26px; height: 26px; padding: 0; color: var(--muted); vertical-align: middle; }
.icon-btn.help-inline:hover { color: var(--accent); }
.h2 .help-inline { margin-left: 6px; }
@media (max-width: 760px) {
  .help-layout { flex-direction: column; }
  .help-side { width: 100%; position: static; }
  .help-main { padding: 14px; }
}
