/* 变量：排版与背景由 JS 注入，此处为默认 */
:root {
  --layout-cols: 3;
  --layout-gap: 16px;
  --layout-align: start;
  --bg-type: color;
  --bg-color: #1a1b26;
  --bg-image: none;
  --bg-gradient: linear-gradient(135deg, #1a1b26 0%, #24283b 100%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #c0caf5;
  background: var(--bg-color);
  background-image: var(--bg-image);
  background-size: cover;
  background-position: center;
  transition: background 0.3s ease;
}

body[data-bg-type="gradient"] {
  background: var(--bg-gradient);
  background-image: none;
}

body[data-bg-type="image"] {
  background-color: #0f0f14;
  background-image: var(--bg-image);
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px;
}

.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  pointer-events: none;
}

.login-overlay-inner {
  pointer-events: auto;
  text-align: center;
  padding: 24px 32px;
  border-radius: 16px;
  background: rgba(15, 16, 24, 0.72);
  border: 1px solid rgba(192, 202, 245, 0.25);
  backdrop-filter: blur(12px);
  color: #c0caf5;
}

.login-overlay-inner h2 {
  margin-top: 0;
  margin-bottom: 8px;
}

.login-overlay-inner p {
  margin: 4px 0;
}

.login-overlay-hint {
  font-size: 0.8rem;
  color: rgba(192, 202, 245, 0.7);
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px;
}

.cloud-sync-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  background: rgba(186, 130, 59, 0.2);
  border: 1px solid rgba(186, 130, 59, 0.5);
  border-radius: 8px;
  color: #e0af68;
}
.cloud-sync-hint .cloud-sync-hint-close {
  flex-shrink: 0;
  padding: 2px 8px;
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
}
.cloud-sync-hint .cloud-sync-hint-close:hover {
  opacity: 0.8;
}
.cloud-sync-hint code {
  font-size: 0.85em;
  padding: 0 4px;
  background: rgba(0,0,0,0.2);
  border-radius: 4px;
}

/* 头部 */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 16px;
  border-bottom: 1px solid rgba(192, 202, 245, 0.15);
}

.title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* 主内容网格：按内容高度排列，不把同行模块拉成等高 */
.main {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(var(--layout-cols), 1fr);
  gap: var(--layout-gap);
  align-content: start;
  align-items: start;
  justify-items: var(--layout-align);
  padding: 20px 0;
}

.main .card {
  justify-self: stretch;
  max-width: 100%;
}

.empty-hint {
  grid-column: 1 / -1;
  text-align: center;
  color: rgba(192, 202, 245, 0.6);
  padding: 2rem;
}

/* 卡片通用 */
.card {
  background: rgba(36, 40, 59, 0.85);
  border-radius: 12px;
  padding: 16px;
  border: 1px solid rgba(192, 202, 245, 0.12);
  backdrop-filter: blur(8px);
  transition: transform 0.2s, box-shadow 0.2s;
  width: 100%;
  min-width: 0;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.card-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.card-actions {
  display: flex;
  gap: 4px;
}

.card-content {
  font-size: 0.9rem;
  line-height: 1.5;
  color: rgba(192, 202, 245, 0.9);
  white-space: pre-wrap;
  word-break: break-word;
}

.card-content a {
  color: #7aa2f7;
  text-decoration: none;
}

.card-content a:hover {
  text-decoration: underline;
}

/* 网页卡片：可点击整块 */
.card.card-link {
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
}

.card.card-link .card-content {
  color: rgba(192, 202, 245, 0.75);
  font-size: 0.85rem;
}

/* 顶栏搜索与用户 */
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.search-input {
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid rgba(192, 202, 245, 0.2);
  background: rgba(36, 40, 59, 0.8);
  color: #c0caf5;
  font-size: 0.9rem;
  min-width: 140px;
}

.search-input::placeholder {
  color: rgba(192, 202, 245, 0.5);
}

.user-area .user-name {
  margin-right: 6px;
  font-size: 0.9rem;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.85rem;
}

/* 模块卡片（模块为基本，网页为模块下数据） */
.module-card {
  display: flex;
  flex-direction: column;
}

.module-card .card-header {
  align-items: center;
  gap: 6px;
}

.drag-handle {
  cursor: grab;
  color: rgba(192, 202, 245, 0.5);
  font-size: 0.9rem;
  user-select: none;
}

.drag-handle.small {
  font-size: 0.75rem;
  margin-right: 4px;
}

.drag-handle:active {
  cursor: grabbing;
}

.module-card.drag-over,
.module-item.drag-over {
  outline: 2px dashed #7aa2f7;
  outline-offset: 2px;
}

.btn-collapse {
  padding: 2px 6px;
  font-size: 0.8rem;
  min-width: 24px;
}

.module-card.collapsed .module-items,
.module-card.collapsed .btn-add-item {
  display: none;
}

.module-items {
  margin: 8px 0;
  padding: 0;
  list-style: none;
}

.module-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  margin-bottom: 0;
  font-size: 0.9rem;
}

/* 每个内容像按键：框起来、明确分割 */
.module-item.item-box {
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid rgba(192, 202, 245, 0.2);
  border-radius: 8px;
  background: rgba(26, 27, 38, 0.5);
  transition: background 0.2s, border-color 0.2s;
}

.module-item.item-box:hover {
  background: rgba(192, 202, 245, 0.06);
  border-color: rgba(192, 202, 245, 0.3);
}

.module-item.item-type-link.item-box { border-left: 3px solid #7aa2f7; }
.module-item.item-type-text.item-box { border-left: 3px solid #9ece6a; }
.module-item.item-type-both.item-box { border-left: 3px solid #bb9af7; }

.item-type-icon {
  font-size: 1rem;
  opacity: 0.9;
  flex-shrink: 0;
}

.module-item.has-link.item-box {
  cursor: pointer;
}

.module-item.has-link.item-box:hover {
  background: rgba(192, 202, 245, 0.08);
}

.module-item .item-title-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.module-item .item-title {
  display: block;
}

.module-item .item-title a {
  color: #7aa2f7;
  text-decoration: none;
}

.module-item .item-title a:hover {
  text-decoration: underline;
}

/* 说明：仅悬停时在下方浮层显示，不在名称旁常驻 */
.module-item .item-desc-tooltip {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 6px;
  padding: 8px 10px;
  background: rgba(36, 40, 59, 0.98);
  border: 1px solid rgba(192, 202, 245, 0.25);
  border-radius: 8px;
  font-size: 0.85rem;
  color: rgba(192, 202, 245, 0.9);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
  z-index: 20;
  display: none;
  pointer-events: auto;
}

.module-item.item-box:hover .item-desc-tooltip {
  display: block;
}

.module-item .item-desc-tooltip a {
  color: #7aa2f7;
  text-decoration: none;
}

.module-item .item-desc-tooltip a:hover {
  text-decoration: underline;
}

.module-item .item-actions {
  display: flex;
  gap: 2px;
  opacity: 0.8;
}

.comment-badge {
  font-size: 0.75rem;
  color: #7aa2f7;
  margin-left: 4px;
}

.btn-add-item {
  margin-top: 6px;
  width: 100%;
}

/* 映射目录树（小模块多级） */
.mapped-tree {
  margin: 8px 0;
  padding: 0;
  list-style: none;
}
.mapped-folder {
  margin-bottom: 4px;
}
.mapped-folder-name {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 6px;
  font-size: 0.9rem;
  user-select: none;
}
.mapped-folder-name:hover {
  background: rgba(192, 202, 245, 0.08);
}
.mapped-folder-name .toggle {
  font-size: 0.75rem;
  opacity: 0.8;
  transition: transform 0.2s;
}
.mapped-folder.collapsed .mapped-folder-name .toggle {
  transform: rotate(-90deg);
}
.mapped-folder-children {
  padding-left: 16px;
  border-left: 1px solid rgba(192, 202, 245, 0.15);
  margin-left: 8px;
}
.mapped-folder.collapsed .mapped-folder-children {
  display: none;
}
.mapped-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin-bottom: 4px;
  border-radius: 6px;
  font-size: 0.88rem;
  cursor: pointer;
  border: 1px solid transparent;
}
.mapped-file:hover {
  background: rgba(192, 202, 245, 0.08);
  border-color: rgba(122, 162, 247, 0.3);
}
.mapped-file .file-icon {
  opacity: 0.85;
}

/* 评论 */
.comment-item {
  padding: 8px 0;
  border-bottom: 1px solid rgba(192, 202, 245, 0.1);
  font-size: 0.9rem;
}

.comment-time {
  font-size: 0.8rem;
  color: rgba(192, 202, 245, 0.5);
  margin-left: 6px;
}

.comment-form {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.comment-form input {
  padding: 8px 12px;
  border: 1px solid rgba(192, 202, 245, 0.2);
  border-radius: 8px;
  background: rgba(36, 40, 59, 0.8);
  color: #c0caf5;
  font-size: 0.9rem;
}

.comment-form input#commentInput {
  flex: 1;
}

.item-content-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.item-attachments {
  margin-top: 10px;
}

.attachment-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 4px;
  font-size: 0.85rem;
}

.attachment-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}


.comment-item .btn-delete-comment {
  margin-left: 8px;
  vertical-align: middle;
}

.view-content-body {
  max-height: 60vh;
  overflow-y: auto;
}

.view-content-text {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  color: rgba(192, 202, 245, 0.9);
}

.view-content-text a {
  color: #7aa2f7;
}

/* 按钮 */
.btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  border-radius: 8px;
  padding: 8px 14px;
  transition: background 0.2s, color 0.2s;
}

.btn-icon {
  padding: 8px;
  background: rgba(192, 202, 245, 0.1);
  color: #c0caf5;
}

.btn-icon:hover {
  background: rgba(192, 202, 245, 0.2);
}

.btn-close {
  font-size: 1.4rem;
  line-height: 1;
}

.btn-primary {
  background: #7aa2f7;
  color: #1a1b26;
}

.btn-primary:hover {
  background: #89b4fa;
}

.btn-secondary {
  background: rgba(192, 202, 245, 0.15);
  color: #c0caf5;
}

.btn-secondary:hover {
  background: rgba(192, 202, 245, 0.25);
}

.btn-danger {
  background: rgba(248, 108, 108, 0.2);
  color: #f7768e;
}

.btn-danger:hover {
  background: rgba(248, 108, 108, 0.35);
}

/* 页脚 */
.footer {
  display: flex;
  gap: 10px;
  padding: 16px 0;
  border-top: 1px solid rgba(192, 202, 245, 0.1);
  flex-wrap: wrap;
}

/* 设置面板 */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 100%;
  max-width: 320px;
  height: 100vh;
  background: rgba(26, 27, 38, 0.98);
  border-left: 1px solid rgba(192, 202, 245, 0.15);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.3);
}

.panel.open {
  transform: translateX(0);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid rgba(192, 202, 245, 0.1);
}

.panel-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.setting-section {
  margin-bottom: 20px;
}

.setting-section h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: rgba(192, 202, 245, 0.8);
}

.setting-section label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.setting-section input[type="number"],
.setting-section input[type="text"],
.setting-section input[type="url"],
.setting-section input[type="color"],
.setting-section select {
  width: 100%;
  padding: 8px 10px;
  margin-top: 4px;
  border: 1px solid rgba(192, 202, 245, 0.2);
  border-radius: 6px;
  background: rgba(36, 40, 59, 0.8);
  color: #c0caf5;
  font-size: 0.9rem;
}

.setting-section input[type="color"] {
  height: 40px;
  padding: 4px;
  cursor: pointer;
}

.setting-label {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: rgba(192, 202, 245, 0.9);
}

.setting-section .mt {
  margin-top: 12px;
}

.setting-hint {
  margin: 4px 0 0;
  font-size: 0.8rem;
  color: rgba(192, 202, 245, 0.6);
}

.bg-gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 4px;
}

.bg-gallery-item {
  aspect-ratio: 16/10;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid rgba(192, 202, 245, 0.2);
  cursor: pointer;
  background: rgba(36, 40, 59, 0.8);
  transition: border-color 0.2s, transform 0.2s;
}

.bg-gallery-item:hover {
  border-color: #7aa2f7;
  transform: scale(1.02);
}

.bg-gallery-item.active {
  border-color: #7aa2f7;
  box-shadow: 0 0 0 1px #7aa2f7;
}

.bg-gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.bg-gallery-item span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 0.75rem;
  color: rgba(192, 202, 245, 0.7);
  text-align: center;
  padding: 4px;
}

#btnApplySettings {
  width: 100%;
  margin-top: 8px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.hidden {
  display: none !important;
}

/* 弹窗 */
.modal {
  position: fixed;
  inset: 0;
  z-index: 101;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal.show {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: #24283b;
  border-radius: 12px;
  border: 1px solid rgba(192, 202, 245, 0.15);
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(192, 202, 245, 0.1);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
}

.modal-body label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.modal-body input[type="text"],
.modal-body input[type="url"],
.modal-body textarea {
  width: 100%;
  padding: 10px 12px;
  margin-top: 4px;
  border: 1px solid rgba(192, 202, 245, 0.2);
  border-radius: 8px;
  background: rgba(26, 27, 38, 0.8);
  color: #c0caf5;
  font-size: 0.9rem;
  font-family: inherit;
}

.modal-body textarea {
  resize: vertical;
  min-height: 60px;
}

.modal-body input[type="checkbox"] {
  margin-right: 8px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid rgba(192, 202, 245, 0.1);
}

/* 手机端 */
@media (max-width: 600px) {
  .main {
    grid-template-columns: 1fr;
    --layout-cols: 1;
  }

  .header .title {
    font-size: 1.25rem;
  }

  .footer {
    flex-direction: column;
  }

  .footer .btn {
    width: 100%;
  }

  .panel {
    max-width: 100%;
  }
}

@media (min-width: 601px) and (max-width: 900px) {
  .main {
    grid-template-columns: repeat(2, 1fr);
    --layout-cols: 2;
  }
}
