:root {
  --bg: #f5f2ea;
  --surface: #ffffff;
  --surface-hover: #faf8f2;
  --text: #2b2a26;
  --text-secondary: #8a8578;
  --primary: #4f46e5;
  --primary-strong: #4338ca;
  --primary-weak: rgba(79, 70, 229, 0.1);
  --border: #e6e1d5;
  --shadow: 0 2px 12px rgba(43, 42, 38, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --surface: #22242a;
    --surface-hover: #2a2d34;
    --text: #e8e6df;
    --text-secondary: #9a968a;
    --primary: #818cf8;
    --primary-strong: #a5b4fc;
    --primary-weak: rgba(129, 140, 248, 0.14);
    --border: #33363f;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  overflow-x: hidden;
}

.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
}

.app-bar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.net-status {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.net-status.offline {
  color: #d97706;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-strong);
}

.main {
  flex: 1;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px calc(24px + var(--safe-bottom));
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px 20px;
}

.placeholder {
  text-align: center;
  padding: 40px 20px;
}

.placeholder-icon {
  font-size: 52px;
  line-height: 1;
  margin-bottom: 12px;
}

.card-title {
  margin: 0 0 16px;
  font-size: 18px;
  font-weight: 600;
}

.status-list {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: 360px;
  text-align: left;
  font-size: 14px;
  line-height: 2;
  color: var(--text-secondary);
}

.tip {
  margin: 18px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}

.hidden {
  display: none !important;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar-info {
  font-size: 13px;
  color: var(--text-secondary);
  margin-left: auto;
}

.tree {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 200px;
}

.tree.root-hover {
  box-shadow: inset 0 0 0 2px var(--primary), var(--shadow);
  background: var(--surface-hover);
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 10px calc(12px + min(var(--depth, 0), 6) * 20px);
  border-bottom: 1px solid var(--border);
  min-height: 48px;
  user-select: none;
  -webkit-user-select: none;
}

.tree-row:last-child {
  border-bottom: none;
}

.chevron {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  padding: 0;
  border-radius: 6px;
}

.chevron:active {
  background: var(--primary-weak);
}

.chevron-spacer {
  width: 24px;
  flex-shrink: 0;
}

.row-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.row-name-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.row-name {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-sub {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-count {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--primary-weak);
  border-radius: 10px;
  padding: 2px 8px;
}

.row-more {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  border-radius: 8px;
}

.row-more:hover,
.row-more:active {
  background: var(--primary-weak);
  color: var(--text);
}

.book-row {
  cursor: pointer;
}

.book-row:hover {
  background: var(--surface-hover);
}

.book-row.dragging {
  opacity: 0.4;
}

.folder-row.drop-hover {
  background: var(--primary-weak);
  box-shadow: inset 0 0 0 2px var(--primary);
}

.root-divider {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--surface-hover);
  border-bottom: 1px solid var(--border);
}

.empty-state {
  text-align: center;
  padding: 56px 16px;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.8;
  white-space: pre-line;
  margin: 0 0 18px;
}

.menu {
  position: fixed;
  z-index: 100;
  min-width: 160px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.2);
  padding: 6px;
}

.menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 14px;
  border-radius: 8px;
  cursor: pointer;
}

.menu button:hover,
.menu button:active {
  background: var(--surface-hover);
}

.menu button.danger {
  color: #dc2626;
}

.dialog {
  border: none;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  padding: 22px 20px;
  width: min(92vw, 400px);
  max-height: 86dvh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

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

.dialog h3 {
  margin: 0 0 14px;
  font-size: 17px;
  line-height: 1.4;
  word-break: break-all;
}

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

.input:focus {
  border-color: var(--primary);
}

.dialog-message {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-secondary);
  margin: 0;
}

.dialog-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 8px 0 0;
}

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

.btn-danger {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}

.btn-danger:hover {
  background: #b91c1c;
}

.move-list {
  max-height: 50vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.move-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

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

.move-item:hover:enabled {
  background: var(--surface-hover);
}

.move-item.current:disabled {
  color: var(--text-secondary);
  cursor: not-allowed;
  background: var(--surface-hover);
}

.progress-dialog .progress-file {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0 0 10px;
  word-break: break-all;
}

.progress-dialog .dialog-message {
  margin: 0 0 14px;
  font-size: 14px;
}

.progress-track {
  height: 8px;
  background: var(--primary-weak);
  border-radius: 6px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--primary);
  border-radius: 6px;
  transition: width 0.25s ease;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(30px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(28, 28, 32, 0.92);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 12px;
  z-index: 200;
  max-width: 82vw;
  text-align: center;
  pointer-events: none;
}

@media (max-width: 480px) {
  .main {
    padding: 14px 12px calc(20px + var(--safe-bottom));
  }

  .net-status {
    display: none;
  }

  .toolbar-info {
    width: 100%;
    margin-left: 0;
    order: 3;
  }

  .tree-row {
    gap: 6px;
  }

  .row-count {
    display: none;
  }
}
