:root {
  --bg-deep: #050810;
  --bg-panel: rgba(8, 16, 32, 0.85);
  --border: rgba(0, 212, 255, 0.25);
  --border-bright: rgba(0, 212, 255, 0.55);
  --cyan: #00d4ff;
  --cyan-dim: rgba(0, 212, 255, 0.15);
  --purple: #7b61ff;
  --text: #c8e6f5;
  --text-dim: #5a7a8f;
  --danger: #ff4466;
  --glow: 0 0 20px rgba(0, 212, 255, 0.35);
  --font-ui: "JetBrains Mono", "SF Mono", monospace;
  --font-display: "Orbitron", sans-serif;
  --panel-head-height: 44px;
  --toolbar-btn-height: 28px;
  --sidebar-width: 300px;
  --detail-width: 300px;
  --resize-handle-width: 5px;
  --tree-row-pad-x: 8px;
  --tree-toggle-size: 18px;
  --tree-child-gap: 10px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text);
  background: var(--bg-deep);
  line-height: 1.5;
}

.grid-bg {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(0, 212, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 212, 255, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

.scanline {
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
  pointer-events: none;
  z-index: 1;
}

.header {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(0, 212, 255, 0.06) 0%, transparent 100%);
}

.logo {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.logo-icon {
  color: var(--cyan);
  font-size: 20px;
  text-shadow: var(--glow);
}

.logo h1 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--cyan);
}

.logo-sub {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.layout {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns:
    var(--sidebar-width)
    var(--resize-handle-width)
    minmax(240px, 1fr)
    var(--resize-handle-width)
    var(--detail-width);
  height: calc(100vh - 57px);
  gap: 0;
}

.resize-handle {
  position: relative;
  z-index: 15;
  cursor: col-resize;
  background: transparent;
  transition: background 0.15s;
  touch-action: none;
}

.resize-handle::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 1px;
  background: var(--border);
  transition: width 0.15s, background 0.15s;
}

.resize-handle:hover,
.layout.is-resizing .resize-handle {
  background: rgba(0, 212, 255, 0.06);
}

.resize-handle:hover::after,
.layout.is-resizing .resize-handle::after {
  width: 2px;
  background: var(--cyan);
  box-shadow: 0 0 8px rgba(0, 212, 255, 0.4);
}

body.is-resizing-panels {
  cursor: col-resize !important;
  user-select: none;
}

body.is-resizing-panels * {
  cursor: col-resize !important;
}

.panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  overflow: hidden;
}

.sidebar {
  border-right: none;
  border-top: none;
}

.preview {
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-top: none;
  min-width: 0;
}

.detail {
  border-left: none;
  border-top: none;
}

.preview-toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.preview-toolbar .btn-sm {
  height: var(--toolbar-btn-height);
  min-height: var(--toolbar-btn-height);
  max-height: var(--toolbar-btn-height);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  line-height: 1;
}

.btn-sm {
  padding: 0 10px;
  height: var(--toolbar-btn-height);
  min-height: var(--toolbar-btn-height);
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  line-height: 1;
}

.preview-url-bar {
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.preview-url-text {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-body {
  flex: 1;
  position: relative;
  min-height: 0;
  background: rgba(0, 0, 0, 0.45);
}

.preview-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  gap: 10px;
  padding: 24px;
  text-align: center;
}

.preview-hint {
  font-size: 10px;
  opacity: 0.75;
  max-width: 280px;
  line-height: 1.6;
}

.preview-frame-wrap {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.preview-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #0a0e18;
}

.preview-blocked {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg-panel);
  text-align: center;
  padding: 32px;
  z-index: 5;
}

.preview-blocked-icon {
  font-size: 48px;
  color: var(--danger);
  opacity: 0.7;
  line-height: 1;
}

.preview-blocked-title {
  font-size: 14px;
  color: var(--text);
}

.preview-blocked-hint {
  font-size: 11px;
  color: var(--text-dim);
  max-width: 280px;
  line-height: 1.7;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--panel-head-height);
  min-height: var(--panel-head-height);
  max-height: var(--panel-head-height);
  padding: 0 16px;
  box-sizing: border-box;
  flex-shrink: 0;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 212, 255, 0.04);
}

.panel-title {
  font-size: 11px;
  color: var(--cyan);
  letter-spacing: 0.08em;
  line-height: 1;
  white-space: nowrap;
}

.detail-type {
  font-size: 10px;
  height: 22px;
  line-height: 20px;
  padding: 0 8px;
  border: 1px solid var(--border);
  color: var(--purple);
  border-radius: 2px;
  flex-shrink: 0;
  box-sizing: border-box;
}

.search-box {
  padding: 12px 16px 8px;
}

.search-box input {
  width: 100%;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-box input:focus {
  border-color: var(--border-bright);
  box-shadow: var(--glow);
}

.tag-filter {
  padding: 0 16px 12px;
}

.tag-filter-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.tag-filter-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tag-filter-note {
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.75;
  font-size: 9px;
}

.field-tags-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.field-tags-head label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tag-assign-label {
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.tag-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.2);
}

.tag-picker-empty {
  font-size: 11px;
  color: var(--text-dim);
}

.tag-chip-colored {
  --tag-color: var(--cyan);
  padding: 3px 10px;
  font-size: 11px;
  border: 1px solid color-mix(in srgb, var(--tag-color) 55%, transparent);
  border-radius: 2px;
  background: color-mix(in srgb, var(--tag-color) 18%, transparent);
  color: var(--tag-color);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.tag-chip-colored:hover {
  box-shadow: 0 0 12px color-mix(in srgb, var(--tag-color) 35%, transparent);
}

.tag-chip-colored.active,
.tag-chip-colored.selected {
  background: color-mix(in srgb, var(--tag-color) 35%, transparent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--tag-color) 45%, transparent);
}

.tag-chip-colored.filter-active {
  outline: 1px solid var(--tag-color);
  outline-offset: 1px;
}

.ctx-menu {
  position: fixed;
  z-index: 300;
  min-width: 220px;
  padding: 0;
  background: rgba(8, 16, 32, 0.96);
  border: 1px solid var(--border-bright);
  border-radius: 4px;
  box-shadow:
    0 0 24px rgba(0, 212, 255, 0.15),
    0 12px 40px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
  overflow: hidden;
  animation: ctx-in 0.15s ease;
}

@keyframes ctx-in {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(-4px);
  }
}

.ctx-menu-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px 10px;
  background: rgba(0, 212, 255, 0.05);
}

.ctx-menu-icon {
  color: var(--purple);
  font-size: 14px;
  line-height: 1;
  margin-top: 2px;
}

.ctx-menu-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.ctx-menu-label {
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ctx-menu-folder {
  font-size: 12px;
  color: var(--cyan);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

.ctx-menu-divider {
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--border-bright),
    transparent
  );
}

.ctx-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s;
}

.ctx-menu-item:hover,
.ctx-menu-item:focus {
  background: rgba(0, 212, 255, 0.1);
  outline: none;
}

.ctx-menu-item:focus-visible {
  box-shadow: inset 0 0 0 1px var(--cyan);
}

.ctx-item-icon {
  font-size: 16px;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.ctx-menu-item[data-type="folder"] .ctx-item-icon {
  color: var(--purple);
}

.ctx-menu-item[data-type="link"] .ctx-item-icon {
  color: var(--cyan);
}

.ctx-item-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ctx-item-title {
  font-size: 12px;
  color: var(--text);
}

.ctx-item-desc {
  font-size: 10px;
  color: var(--text-dim);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 4, 12, 0.75);
  backdrop-filter: blur(4px);
  padding: 24px;
}

.modal {
  width: min(480px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.tag-create-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.tag-create-form input[type="text"] {
  flex: 1;
  min-width: 120px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
}

.tag-create-form input[type="color"] {
  width: 40px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: transparent;
  cursor: pointer;
}

.tag-registry-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tag-registry-item {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.25);
}

.tag-registry-item .tag-sample {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.tag-registry-item input[type="text"] {
  padding: 6px 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  width: 100%;
}

.tag-registry-item input[type="color"] {
  width: 36px;
  height: 30px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: transparent;
  cursor: pointer;
}

.tag-registry-meta {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}

.tag-registry-actions {
  display: flex;
  gap: 4px;
}

.tag-registry-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 16px;
}

.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 24px;
}

.tag-chip {
  padding: 3px 10px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
}

.tag-chip:hover {
  border-color: var(--cyan);
  color: var(--cyan);
}

.tag-chip.active {
  background: var(--cyan-dim);
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: var(--glow);
}

.tag-clear {
  margin-top: 8px;
  font-size: 10px;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  text-decoration: underline;
}

.tag-clear:hover {
  color: var(--cyan);
}

.tree-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 16px;
}

.tree {
  list-style: none;
}

.tree-item {
  user-select: none;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px var(--tree-row-pad-x);
  margin: 2px 0;
  border-radius: 2px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

.tree-row:hover {
  background: var(--cyan-dim);
}

.tree-row.selected {
  background: rgba(0, 212, 255, 0.12);
  border-color: var(--border-bright);
  box-shadow: inset 0 0 12px rgba(0, 212, 255, 0.08);
}

.tree-row.drag-over {
  border-color: var(--cyan);
  background: rgba(0, 212, 255, 0.2);
}

.tree-row.dragging {
  opacity: 0.45;
}

.tree-toggle {
  width: var(--tree-toggle-size);
  height: var(--tree-toggle-size);
  min-width: var(--tree-toggle-size);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: var(--text-dim);
  flex-shrink: 0;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
}

.tree-toggle.empty {
  visibility: hidden;
}

.tree-icon {
  font-size: 12px;
  flex-shrink: 0;
}

.tree-icon.folder {
  color: var(--purple);
}

.tree-icon.link {
  color: var(--cyan);
}

.tree-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.tree-rename-input {
  flex: 1;
  min-width: 0;
  padding: 2px 6px;
  font-family: inherit;
  font-size: 12px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--cyan);
  border-radius: 2px;
  outline: none;
  box-shadow: var(--glow);
}

.tree-tags {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.tree-tags .tag-chip-colored {
  font-size: 9px;
  padding: 1px 6px;
  cursor: default;
}

.tree-children {
  list-style: none;
  /* 虚线对齐父行三角按钮中心：左内边距 + 三角宽度的一半 */
  margin-left: calc(var(--tree-row-pad-x) + var(--tree-toggle-size) / 2);
  padding-left: var(--tree-child-gap);
  border-left: 1px dashed rgba(0, 212, 255, 0.12);
}

.tree-empty {
  text-align: center;
  color: var(--text-dim);
  padding: 32px 16px;
  font-size: 12px;
}

.detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  gap: 12px;
}

.empty-icon {
  font-size: 48px;
  color: var(--border);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.7; }
}

.detail-form {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.field {
  margin-bottom: 18px;
}

.field label {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  margin-bottom: 6px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.field .hint {
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.7;
}

.field input,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border);
  border-radius: 2px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--border-bright);
  box-shadow: var(--glow);
}

.tag-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag-preview .tag-chip {
  cursor: default;
}

.folder-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 2px;
  background: rgba(123, 97, 255, 0.06);
}

.folder-actions-label {
  font-size: 10px;
  color: var(--text-dim);
  margin-right: 4px;
}

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 12px;
  border-radius: 2px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.15s;
  text-decoration: none;
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
}

.btn:hover {
  border-color: var(--border-bright);
}

.btn.btn-sm {
  height: var(--toolbar-btn-height);
  min-height: var(--toolbar-btn-height);
  max-height: var(--toolbar-btn-height);
  padding: 0 12px;
  font-size: 11px;
  line-height: 1;
  gap: 4px;
}

.preview-toolbar .btn.btn-sm {
  min-width: var(--toolbar-btn-height);
}

.btn-primary {
  background: linear-gradient(135deg, rgba(0, 212, 255, 0.25), rgba(123, 97, 255, 0.2));
  border-color: var(--cyan);
  color: var(--cyan);
}

.btn-primary:hover {
  box-shadow: var(--glow);
}

.btn-ghost:hover {
  color: var(--cyan);
}

.btn-danger {
  border-color: rgba(255, 68, 102, 0.5);
  color: var(--danger);
  margin-left: auto;
}

.btn-danger:hover {
  background: rgba(255, 68, 102, 0.15);
  border-color: var(--danger);
}

.btn-icon {
  font-size: 14px;
  line-height: 1;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  padding: 10px 20px;
  background: rgba(0, 212, 255, 0.15);
  border: 1px solid var(--cyan);
  color: var(--cyan);
  font-size: 12px;
  border-radius: 2px;
  box-shadow: var(--glow);
  animation: toast-in 0.25s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 212, 255, 0.25);
  border-radius: 3px;
}

@media (max-width: 1100px) {
  .resize-handle {
    display: none;
  }

  .layout {
    grid-template-columns: minmax(200px, 280px) minmax(0, 1fr);
    grid-template-rows: 1fr auto;
    align-items: stretch;
  }

  .sidebar {
    grid-row: 1;
    grid-column: 1;
    height: 100%;
    min-height: 0;
    max-height: none;
  }

  .preview {
    grid-row: 1;
    grid-column: 2;
    height: 100%;
    min-height: 0;
    border-left: 1px solid var(--border);
    border-right: none;
  }

  .detail {
    grid-row: 2;
    grid-column: 1 / -1;
    max-height: 40vh;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(200px, 35vh) minmax(240px, 45vh) auto;
  }

  .sidebar {
    grid-row: 1;
    grid-column: 1;
    max-height: 35vh;
    border-right: 1px solid var(--border);
  }

  .preview {
    grid-row: 2;
    grid-column: 1;
    border-left: none;
    border-top: 1px solid var(--border);
  }

  .detail {
    grid-row: 3;
    grid-column: 1;
  }
}
