:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --sunk: #efede7;
  --ink: #1c1b19;
  --muted: #6b6862;
  --faint: #9a968e;
  --line: #e4e1da;
  --accent: #1f5f4a;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe9;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --danger: #a1321f;
  --danger-soft: #f8e6e2;
  --shadow: 0 1px 2px rgba(20, 18, 14, 0.05), 0 8px 28px rgba(20, 18, 14, 0.08);
  --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413; --panel: #1d1c1a; --sunk: #191816; --ink: #ecebe7; --muted: #a29e96; --faint: #75716a;
    --line: #2e2d2a; --accent: #6fbf9f; --accent-ink: #0e1a15; --accent-soft: #1d2f28;
    --warn: #e6b45a; --warn-soft: #2e2615; --danger: #ef8a74; --danger-soft: #34201b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--sunk); }
.btn:focus-visible, .icon-btn:focus-visible, .tree-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.55; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 7px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--sunk); color: var(--ink); }
svg.i { width: 16px; height: 16px; flex: none; }

.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink);
}
textarea.input.writing { height: 340px; font: 15px/1.6 var(--font); padding: 12px 14px; }
textarea.input { height: 220px; padding: 10px; font: 12.5px/1.5 var(--mono); resize: vertical; }
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.hint { font-size: 12.5px; color: var(--faint); }
.hint code { font: 11.5px var(--mono); background: var(--sunk); padding: 1px 4px; border-radius: 4px; color: var(--muted); }
.badge.text { background: var(--sunk); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.path-preview { font: 12.5px var(--mono); color: var(--muted); word-break: break-all; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 264px 1fr; height: 100vh; }
.side { border-right: 1px solid var(--line); background: var(--sunk); display: flex; flex-direction: column; min-height: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 16px 14px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center;
  font-weight: 800; font-size: 15px; flex: none; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}
.brand-text { min-width: 0; line-height: 1.25; }
.brand-name { font-weight: 700; letter-spacing: -0.01em; }
.brand-sub { display: block; font-size: 12px; color: var(--faint); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-sub:hover { color: var(--accent); }
.side-scroll { flex: 1; min-height: 0; overflow: auto; padding-bottom: 12px; }
.side-head { display: flex; align-items: center; justify-content: space-between; height: 30px; padding: 10px 10px 0 16px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.07em; color: var(--faint); }
.icon-btn.sm { width: 24px; height: 24px; }
.tree { padding: 4px 8px 6px; }
.tree-item {
  display: flex; align-items: center; gap: 8px; width: 100%; height: 32px; padding: 0 8px; border: 0; border-radius: 7px;
  background: transparent; text-align: left; cursor: pointer; color: var(--ink);
}
.tree-item .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-item .count { font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.tree-item:hover { background: color-mix(in srgb, var(--ink) 6%, transparent); }
.tree-item.active { background: var(--panel); box-shadow: 0 0 0 1px var(--line), 0 1px 2px rgba(20, 18, 14, 0.04); font-weight: 600; }
.tree-item.active .count { color: var(--muted); }
.tree-item.drop-target { background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent); }
.tree-item svg.i { color: var(--faint); }
.tree-item.active svg.i { color: var(--accent); }
.side-foot { border-top: 1px solid var(--line); padding: 10px 10px 10px 12px; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.side-foot .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); font-weight: 500; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 11.5px; font-weight: 700; flex: none; }
.scrim { display: none; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; height: 60px; padding: 0 28px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 85%, transparent); backdrop-filter: blur(8px);
}
.menu-btn { display: none; }
.search-wrap {
  flex: 1; max-width: 460px; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px; border-radius: 9px;
  background: var(--sunk); border: 1px solid transparent; color: var(--faint); cursor: text;
}
.search-wrap:focus-within { background: var(--panel); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-wrap input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--ink); height: 34px; }
.search-wrap input::-webkit-search-cancel-button { cursor: pointer; }
kbd { font: 11px var(--mono); color: var(--faint); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: var(--panel); }
.search-wrap:focus-within kbd { display: none; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.btn .chev { width: 14px; height: 14px; margin-left: -2px; color: var(--faint); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); height: 30px; padding: 0 10px; }
.btn.ghost:hover { background: var(--sunk); color: var(--ink); }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: 250px; padding: 6px; border: 1px solid var(--line);
  border-radius: 11px; background: var(--panel); box-shadow: var(--shadow); display: grid; gap: 2px;
}
.menu button { display: flex; gap: 10px; align-items: flex-start; padding: 9px 10px; border: 0; border-radius: 7px; background: none; text-align: left; cursor: pointer; }
.menu button:hover { background: var(--sunk); }
.menu button svg.i { margin-top: 2px; color: var(--accent); }
.menu b { display: block; font-weight: 600; }
.menu small { color: var(--faint); font-size: 12px; }

.content { overflow: auto; padding: 28px 28px 56px; flex: 1; }
.content > * { max-width: 1120px; margin-left: auto; margin-right: auto; }
.page-head { margin-bottom: 22px; }
.crumbs { display: flex; align-items: center; gap: 2px; min-height: 20px; font-size: 13px; color: var(--faint); margin-bottom: 2px; }
.crumbs:empty { display: none; }
.crumbs button { border: 0; background: none; padding: 1px 4px; border-radius: 5px; cursor: pointer; color: var(--muted); }
.crumbs button:first-child { padding-left: 0; }
.crumbs button:hover { color: var(--ink); text-decoration: underline; }
.crumbs .sep { color: var(--line); padding: 0 2px; }
.title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.title-row h1 { margin: 0 6px 0 0; font-size: 26px; line-height: 1.2; letter-spacing: -0.02em; font-weight: 700; overflow-wrap: anywhere; }
.page-sub { margin: 6px 0 0; color: var(--muted); font-size: 13.5px; }

/* ---------- empty / drop ---------- */
.dz-icon { width: 44px; height: 44px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.dz-icon svg.i { width: 20px; height: 20px; }
.drop-empty {
  display: grid; justify-items: center; gap: 6px; text-align: center; padding: 48px 20px; border: 1.5px dashed var(--line); border-radius: 14px;
  background: var(--panel); color: var(--muted);
}
.drop-empty strong { color: var(--ink); font-size: 16px; margin-top: 6px; }
.drop-empty p { margin: 0 0 10px; max-width: 420px; }
.drop-empty .row { flex-wrap: wrap; justify-content: center; }
.overlay-drop {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; pointer-events: none;
  background: color-mix(in srgb, var(--accent) 10%, transparent); border: 3px dashed var(--accent);
}
.overlay-drop div { background: var(--panel); padding: 16px 22px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; }

/* ---------- folders ---------- */
.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; margin-bottom: 26px; }
.fcard {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  cursor: pointer; text-align: left; transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s;
}
.fcard:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); box-shadow: 0 4px 14px rgba(20, 18, 14, 0.06); transform: translateY(-1px); }
.fcard.drop-target { box-shadow: 0 0 0 2px var(--accent); background: var(--accent-soft); }
.ficon { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; background: var(--warn-soft); color: var(--warn); flex: none; }
.ftext { min-width: 0; display: grid; }
.ftext b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ftext small { color: var(--faint); font-size: 12px; }

/* ---------- notes ---------- */
.list-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.section-title { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.07em; color: var(--faint); margin-right: auto; }
.seg { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--sunk); border: 1px solid var(--line); }
.seg button { height: 26px; padding: 0 10px; border: 0; border-radius: 7px; background: none; cursor: pointer; color: var(--muted); font-size: 12.5px; font-weight: 500; display: inline-flex; gap: 6px; align-items: center; }
.seg button span { font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 2px rgba(20, 18, 14, 0.08); }
.sort { height: 30px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 0 8px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.list { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: 0 1px 2px rgba(20, 18, 14, 0.03); }
.note {
  display: grid; grid-template-columns: auto 1fr auto auto; gap: 14px; align-items: center; padding: 12px 12px 12px 14px; border-top: 1px solid var(--line);
}
.note:first-child { border-top: 0; }
.note:hover { background: color-mix(in srgb, var(--ink) 2.5%, transparent); }
.note.dragging { opacity: 0.5; }
.ntype { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.ntype.html { background: color-mix(in srgb, #3b6fd8 13%, transparent); color: #3b6fd8; }
.ntype.bundle { background: color-mix(in srgb, #8a4fd1 13%, transparent); color: #8a4fd1; }
.ntype.text { background: var(--accent-soft); color: var(--accent); }
.nmain { min-width: 0; }
.note .title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.note .title a { color: inherit; text-decoration: none; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note .title a:hover { color: var(--accent); }
.note .sub { display: flex; gap: 8px; align-items: center; color: var(--faint); font-size: 12.5px; margin-top: 3px; min-width: 0; }
.note .sub .p { font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.note .meta { display: grid; justify-items: end; color: var(--muted); font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.note .meta small { color: var(--faint); font-size: 11.5px; }
.note .acts { display: flex; gap: 2px; opacity: 0.35; transition: opacity 0.12s; }
.note:hover .acts, .note:focus-within .acts { opacity: 1; }
@media (hover: none) { .note .acts { opacity: 1; } }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 1px 7px 1px 6px; border-radius: 99px; white-space: nowrap; flex: none; }
.badge svg.i { width: 11px; height: 11px; }
.badge.public { background: var(--accent-soft); color: var(--accent); }
.badge.password { background: var(--warn-soft); color: var(--warn); }
.badge.private { background: var(--sunk); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }

/* ---------- tags ---------- */
.tag-chip {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 99px; border: 0;
  background: var(--sunk); color: var(--muted); font-size: 11.5px; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.tag-chip:hover { color: var(--accent); background: var(--accent-soft); }
.tag-chip.on { background: var(--accent-soft); color: var(--accent); }
.note .tags { display: inline-flex; gap: 4px; flex-wrap: nowrap; overflow: hidden; flex: none; max-width: 50%; }
.tag-input {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 36px; padding: 4px 6px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); cursor: text;
}
.tag-input:focus-within { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.tag-input .tag-chip { height: 24px; font-size: 12.5px; color: var(--ink); cursor: default; box-shadow: inset 0 0 0 1px var(--line); }
.tag-input .tag-chip button { border: 0; background: none; padding: 0; margin-left: 2px; cursor: pointer; color: var(--faint); font-size: 14px; line-height: 1; }
.tag-input .tag-chip button:hover { color: var(--danger); }
.tag-entry { flex: 1; min-width: 140px; border: 0; outline: 0; background: transparent; height: 26px; color: var(--ink); }

/* ---------- dialogs ---------- */
dialog {
  width: min(560px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--ink);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(15, 14, 12, 0.45); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.dlg-head h2 { margin: 0; font-size: 16px; }
.dlg-body { padding: 16px 20px; display: grid; gap: 14px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--sunk); border-radius: 0 0 14px 14px; }
.dlg-foot .left { margin-right: auto; }
.files-box { border: 1px solid var(--line); border-radius: 9px; max-height: 140px; overflow: auto; font: 12px/1.6 var(--mono); padding: 8px 10px; color: var(--muted); background: var(--sunk); }
.notice { padding: 9px 12px; border-radius: 8px; font-size: 13px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.err { background: var(--danger-soft); color: var(--danger); }
.token-box { font: 13px var(--mono); padding: 10px; border-radius: 8px; background: var(--sunk); border: 1px solid var(--line); word-break: break-all; }
.tokens { display: grid; gap: 6px; }
.token-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.token-row .grow span { color: var(--faint); font-size: 12px; }
pre.code { margin: 0; font: 12px/1.6 var(--mono); padding: 10px 12px; border-radius: 8px; background: var(--sunk); border: 1px solid var(--line); overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* ---------- toast ---------- */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 60; width: min(460px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: 10px; background: var(--ink); color: var(--bg);
  box-shadow: var(--shadow); font-size: 13.5px; animation: up 0.18s ease-out;
}
.toast.err { background: var(--danger); color: #fff; }
.toast a { color: inherit; font-weight: 600; }
.toast .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes up { from { transform: translateY(6px); opacity: 0; } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login h1 { margin: 0 0 4px; font-size: 20px; }

/* ---------- small screens ---------- */
@media (max-width: 1000px) {
  .top-actions .btn:not(.primary) .lbl { display: none; }
  .note .tags { display: none; }
}
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 50; transform: translateX(-100%);
    transition: transform 0.2s ease; box-shadow: var(--shadow);
  }
  .app.drawer .side { transform: none; }
  .app.drawer .scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(15, 14, 12, 0.4); }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 0 12px; gap: 8px; height: 56px; }
  .search-wrap kbd { display: none; }
  .top-actions { gap: 6px; }
  .top-actions .btn { padding: 0 9px; }
  .top-actions .btn .lbl, .top-actions .btn .chev { display: none; }
  .content { padding: 20px 14px 40px; }
  .title-row h1 { font-size: 22px; }
  .folder-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .list-bar { flex-wrap: wrap; }
  .note { grid-template-columns: auto 1fr auto; gap: 10px; padding: 10px; }
  .note .meta { display: none; }
  .ntype { width: 32px; height: 32px; }
}
