:root {
  --bg: #0b0e14;
  --panel: #0f1420;
  --panel-2: #111a2c;
  --text: #e7eaf0;
  --muted: #9aa4b2;
  --border: #1f2a3b;
  --accent: #36d399;
  --accent-2: #7c5cff;
  --danger: #ff5c7a;
  --shadow: rgba(0, 0, 0, 0.28);

  --radius-control: 12px;
  --radius-surface: 16px;
  --radius-dialog: 16px;

  --control-bg: rgba(255, 255, 255, 0.035);
  --control-bg-hover: rgba(255, 255, 255, 0.055);
  --control-bg-pressed: rgba(255, 255, 255, 0.08);
  --hover-bg: rgba(255, 255, 255, 0.05);

  --focus-border: color-mix(in srgb, var(--accent) 55%, var(--border));
  --focus-ring: color-mix(in srgb, var(--accent) 18%, transparent);

  --selection-bg: color-mix(in srgb, var(--accent) 12%, transparent);
  --selection-border: color-mix(in srgb, var(--accent) 35%, var(--border));
  --active-bg: color-mix(in srgb, var(--accent) 16%, transparent);
  --active-border: color-mix(in srgb, var(--accent) 45%, var(--border));

  --link: color-mix(in srgb, var(--accent) 70%, white 30%);
  --link-underline: color-mix(in srgb, var(--accent) 40%, transparent);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
}

[data-theme="light"] {
  --bg: #f7f8fc;
  --panel: #ffffff;
  --panel-2: #f3f5fb;
  --text: #0b1220;
  --muted: #586174;
  --border: #d6dbea;
  --accent: #169b6b;
  --accent-2: #5a45ff;
  --danger: #d81b60;
  --shadow: rgba(2, 8, 23, 0.09);

  --control-bg: rgba(2, 8, 23, 0.035);
  --control-bg-hover: rgba(2, 8, 23, 0.055);
  --control-bg-pressed: rgba(2, 8, 23, 0.075);
  --hover-bg: rgba(2, 8, 23, 0.04);

  --focus-border: color-mix(in srgb, var(--accent) 55%, var(--border));
  --focus-ring: color-mix(in srgb, var(--accent) 20%, transparent);

  --selection-bg: color-mix(in srgb, var(--accent) 10%, transparent);
  --selection-border: color-mix(in srgb, var(--accent) 32%, var(--border));
  --active-bg: color-mix(in srgb, var(--accent) 14%, transparent);
  --active-border: color-mix(in srgb, var(--accent) 42%, var(--border));

  --link: color-mix(in srgb, var(--accent) 85%, black 15%);
  --link-underline: color-mix(in srgb, var(--accent) 35%, transparent);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon-svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  color: currentColor;
}

.context-menu {
  position: fixed;
  z-index: 1000;
  min-width: 180px;
  border-radius: var(--radius-control);
  border: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  box-shadow: 0 18px 60px var(--shadow);
  padding: 6px;
  backdrop-filter: blur(10px);
}

[data-theme="light"] .context-menu {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
}

.context-item {
  width: 100%;
  text-align: left;
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  padding: 9px 10px;
  border-radius: var(--radius-control);
  cursor: pointer;
  font-size: 13px;
}

.context-item:hover {
  background: var(--hover-bg);
  border-color: color-mix(in srgb, var(--border) 70%, transparent);
}

[data-theme="light"] .context-item:hover {
  background: var(--hover-bg);
  border-color: color-mix(in srgb, var(--border) 70%, transparent);
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
}

[data-theme="light"] body {
  background: var(--bg);
}

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 340px 1fr;
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 8px 0 24px var(--shadow);
  display: flex;
  flex-direction: column;
  min-width: 260px;
}

[data-theme="light"] .sidebar {
  box-shadow: 8px 0 24px var(--shadow);
}

.sidebar-top {
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.brand-logo {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand-subtitle {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.vault-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.vault-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vault-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 4px 6px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--hover-bg);
  border-color: color-mix(in srgb, var(--border) 70%, transparent);
}

.icon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
  border-color: var(--focus-border);
}

.icon-btn-label {
  display: none;
}

@media (min-width: 900px) {
  .icon-btn-label {
    display: inline;
  }
}

.search {
  width: 100%;
  margin-top: 12px;
  background: var(--control-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 10px 12px;
  color: var(--text);
  outline: none;
}

[data-theme="light"] .search {
  background: var(--control-bg);
}

.search:focus {
  border-color: var(--focus-border);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  appearance: none;
  border: 1px solid var(--border);
  background: var(--control-bg);
  color: var(--text);
  padding: 9px 10px;
  border-radius: var(--radius-control);
  cursor: pointer;
  transition: transform 0.02s ease, background 0.15s ease, border-color 0.15s ease;
  font-size: 13px;
  white-space: nowrap;
}

[data-theme="light"] .btn {
  background: var(--control-bg);
}

.btn:hover {
  background: var(--control-bg-hover);
  border-color: color-mix(in srgb, var(--accent) 22%, var(--border));
}

[data-theme="light"] .btn:hover {
  background: var(--control-bg-hover);
}

.btn:active {
  background: var(--control-bg-pressed);
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  border-color: var(--active-border);
  background: var(--active-bg);
}

.btn-primary:hover {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.btn-secondary {
  background: transparent;
}

.tree {
  padding: 10px 8px 20px 10px;
  overflow: auto;
  flex: 1;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-control);
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
}

.tree-item:hover {
  background: var(--hover-bg);
}

[data-theme="light"] .tree-item:hover {
  background: var(--hover-bg);
}

.tree-item.active {
  background: var(--active-bg);
  border-color: var(--active-border);
}

.tree-item.selected {
  background: var(--selection-bg);
  border-color: var(--selection-border);
}

.tree-item.drop-target {
  background: rgba(54, 211, 153, 0.14);
  border: 1px solid rgba(54, 211, 153, 0.35);
}

.tree-item .icon {
  width: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  line-height: 0;
}

.tree-item[data-type="file"] .icon {
  color: color-mix(in srgb, var(--muted) 78%, var(--text));
}

.tree-item .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-children {
  margin-left: 18px;
  padding-left: 10px;
  border-left: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  backdrop-filter: blur(10px);
}

[data-theme="light"] .topbar {
  background: color-mix(in srgb, var(--panel) 86%, transparent);
}

.path {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.path-label {
  color: var(--muted);
  font-size: 12px;
}

.path-value {
  font-family: var(--mono);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dirty {
  color: var(--danger);
  font-size: 14px;
  margin-left: 2px;
}

.editor {
  flex: 1;
  min-height: 0;
  padding: 14px;
  position: relative;
}

.textarea {
  width: 100%;
  height: 100%;
  resize: none;
  border-radius: var(--radius-surface);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 14px 14px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.45;
  outline: none;
}

[data-theme="light"] .textarea {
  background: var(--panel);
}

.textarea:focus {
  border-color: var(--focus-border);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.preview {
  width: 100%;
  height: 100%;
  overflow: auto;
  border-radius: var(--radius-surface);
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 14px 14px;
  outline: none;
}

[data-theme="light"] .preview {
  background: var(--panel);
}

.preview:focus {
  border-color: var(--focus-border);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.preview .muted {
  color: var(--muted);
}

.preview h1,
.preview h2,
.preview h3,
.preview h4 {
  margin: 0.6em 0 0.35em;
}

.preview h1 {
  font-size: 22px;
}
.preview h2 {
  font-size: 18px;
}
.preview h3 {
  font-size: 15px;
}
.preview h4 {
  font-size: 13px;
  color: var(--muted);
}

.preview p {
  margin: 0.55em 0;
  line-height: 1.55;
}

.preview img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0.8em auto;
  border-radius: var(--radius-surface);
  border: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
}

.preview img[src$="/img/browsidian.png"],
.preview img[src$="browsidian.png"] {
  max-width: 150px;
}

.preview a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px solid var(--link-underline);
}

[data-theme="light"] .preview a {
  color: var(--link);
  border-bottom-color: var(--link-underline);
}

.preview a:hover {
  border-bottom-color: color-mix(in srgb, var(--accent) 55%, transparent);
}

.preview .tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--selection-bg);
  border: 1px solid var(--selection-border);
  color: var(--text);
  cursor: default;
}

.preview code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--control-bg);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  padding: 1px 5px;
  border-radius: 8px;
}

.preview pre {
  background: var(--control-bg);
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  padding: 10px 12px;
  border-radius: var(--radius-surface);
  overflow: auto;
}

.preview pre code {
  background: transparent;
  border: none;
  padding: 0;
}

.preview blockquote {
  margin: 0.6em 0;
  padding: 0.2em 0 0.2em 12px;
  border-left: 3px solid color-mix(in srgb, var(--accent) 45%, var(--border));
  color: var(--muted);
}

.preview ul,
.preview ol {
  margin: 0.5em 0 0.6em 1.25em;
}

.preview table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 0.8em 0;
  border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  border-radius: var(--radius-surface);
  overflow: hidden;
}

.preview th,
.preview td {
  padding: 8px 10px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  border-right: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  vertical-align: top;
}

.preview th:last-child,
.preview td:last-child {
  border-right: none;
}

.preview tr:last-child td {
  border-bottom: none;
}

.preview th {
  text-align: left;
  font-weight: 650;
  background: var(--control-bg);
}

.preview hr {
  border: 0;
  border-top: 1px solid color-mix(in srgb, var(--border) 65%, transparent);
  margin: 1em 0;
}

.statusbar {
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  color: var(--muted);
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

[data-theme="light"] .statusbar {
  background: color-mix(in srgb, var(--panel) 86%, transparent);
}

.status {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 0 0 auto;
}

.meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.meta-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  text-decoration: none;
}

.meta-item#appVersion {
  font-family: var(--mono);
  color: var(--text);
  opacity: 0.9;
}

.meta-icon {
  width: 15px;
  height: 15px;
}

.meta-item:hover {
  color: var(--text);
}

.accent-heart {
  color: var(--accent);
}

.meta-sep {
  opacity: 0.7;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-track {
  order: 1;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--control-bg);
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.toggle-track::after {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 999px;
  position: absolute;
  top: 1px;
  left: 1px;
  background: color-mix(in srgb, var(--text) 18%, var(--panel));
  box-shadow: 0 6px 18px var(--shadow);
  transition: transform 0.15s ease, background 0.15s ease;
}

[data-theme="light"] .toggle-track {
  background: var(--control-bg);
}

[data-theme="light"] .toggle-track::after {
  background: color-mix(in srgb, var(--text) 18%, var(--panel));
}

.toggle input:checked + .toggle-track {
  background: var(--active-bg);
  border-color: var(--active-border);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(16px);
}

.toggle-side {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.toggle-side-left {
  order: 0;
}

.toggle-side-right {
  order: 2;
}

.toggle input:not(:checked) ~ .toggle-side-left {
  color: var(--text);
}

.toggle input:checked ~ .toggle-side-right {
  color: var(--text);
}

.dialog {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius-dialog);
  padding: 0;
  width: min(560px, 92vw);
  box-shadow: 0 18px 60px var(--shadow);
}

[data-theme="light"] .dialog {
  background: var(--panel);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

[data-theme="light"] .dialog::backdrop {
  background: rgba(2, 8, 23, 0.35);
}

.dialog-form {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dialog-title {
  font-weight: 700;
}

.dialog-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.dialog-input {
  width: 100%;
  background: var(--control-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  padding: 10px 12px;
  color: var(--text);
  outline: none;
  font-family: var(--mono);
}

[data-theme="light"] .dialog-input {
  background: var(--control-bg);
}

.dialog-input:focus {
  border-color: var(--focus-border);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.dialog-help {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.dbx-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.dbx-crumb {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
}

.dbx-crumb:hover {
  color: var(--text);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

.dbx-list {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: auto;
  max-height: 280px;
}

.dbx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border);
}

.dbx-muted {
  cursor: default;
  color: var(--muted);
}

.dbx-item:last-child {
  border-bottom: none;
}

.dbx-item:hover {
  background: color-mix(in srgb, var(--text) 6%, transparent);
}

.dbx-item.selected {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
}

.dbx-item-icon {
  width: 18px;
  text-align: center;
  color: var(--muted);
}

.dbx-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    height: 42vh;
    min-width: 0;
  }
}
