:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2433; --muted: #667085; --line: #e3e6ec;
  --accent: #2459d6; --accent-soft: #e8eefc; --danger: #b42318;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11151c; --panel: #181e28; --text: #e6e9ef; --muted: #98a2b3; --line: #2a3242; --accent: #6b93f2; --accent-soft: #222d47; --danger: #f97066; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, sans-serif; }
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }

#login { height: 100%; display: grid; place-items: center; padding: 16px; }
#loginForm { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: min(360px, 100%); display: grid; gap: 12px; }
#loginForm h1 { margin: 0 0 4px; font-size: 20px; }
input[type=password], input[type=search] { font: inherit; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); width: 100%; }
#loginForm button, .btn { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 9px 14px; text-decoration: none; display: inline-block; }
#loginError { color: var(--danger); margin: 0; min-height: 1.5em; font-size: 14px; }

#app { height: 100%; display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
#crumbs { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; overflow: hidden; }
#crumbs button { background: none; border: 0; color: var(--accent); padding: 2px 6px; border-radius: 6px; }
#crumbs button:hover { background: var(--accent-soft); }
#crumbs .sep { color: var(--muted); }
.toggle { color: var(--muted); font-size: 13px; white-space: nowrap; flex: none; }
#lock { background: var(--accent-soft); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 5px 10px; white-space: nowrap; }
.unlock { display: grid; gap: 10px; max-width: 380px; }
.unlock p { margin: 0; }
#logout { background: none; border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 5px 10px; }

main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(280px, 380px) 1fr; }
#list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.filterbar { display: flex; align-items: center; gap: 10px; padding: 10px; }
#filter { flex: 1; min-width: 0; }
#entries { list-style: none; margin: 0; padding: 0 0 12px; overflow-y: auto; flex: 1; }
#entries li { display: flex; align-items: center; gap: 10px; padding: 7px 14px; cursor: pointer; border-left: 3px solid transparent; }
#entries li:hover { background: var(--accent-soft); }
#entries li.active { background: var(--accent-soft); border-left-color: var(--accent); }
#entries li.sensitive .name { color: var(--muted); }
.ico { width: 22px; text-align: center; flex: none; }
.name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.empty { padding: 20px 14px; color: var(--muted); cursor: default !important; }

#preview { overflow: auto; padding: 20px 24px; min-width: 0; }
.placeholder { color: var(--muted); }
.pv-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.pv-head h2 { margin: 0; font-size: 17px; word-break: break-all; flex: 1; min-width: 160px; }
.pv-head .meta { flex-basis: 100%; }
.notice { background: var(--accent-soft); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; font-size: 13px; }
.error { color: var(--danger); }
.pv-image { max-width: 100%; height: auto; border-radius: 6px; background: repeating-conic-gradient(#8881 0% 25%, transparent 0% 50%) 50% / 16px 16px; }
.pv-pdf { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: 6px; }
pre.pv-text { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px; overflow: auto; font: 13px/1.5 ui-monospace, Menlo, monospace; white-space: pre; margin: 0; }
.rich { max-width: 860px; }
.rich img { max-width: 100%; }
.rich pre, .rich code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: var(--panel); border-radius: 4px; }
.rich pre { padding: 12px; overflow: auto; border: 1px solid var(--line); }
.rich table, .sheet table { border-collapse: collapse; }
.rich td, .rich th, .sheet td, .sheet th { border: 1px solid var(--line); padding: 4px 8px; vertical-align: top; }
.rich blockquote { border-left: 3px solid var(--line); margin-left: 0; padding-left: 14px; color: var(--muted); }
.tabs { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.tabs button { background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 4px 12px; }
.tabs button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.sheet { overflow: auto; max-height: 72vh; border: 1px solid var(--line); border-radius: 6px; }
.sheet td { white-space: nowrap; font-size: 13px; }
.sheet tr:first-child td { font-weight: 600; background: var(--accent-soft); position: sticky; top: 0; }

@media (max-width: 760px) {
  main { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 45%) minmax(0, 1fr); }
  #list { border-right: 0; border-bottom: 1px solid var(--line); }
  #preview { padding: 14px 16px; }
}
