/* ================================================================
   worldbook.css — 世界书管理、Smart Parser、触发沙盒、Kelivo表单
   ================================================================ */

/* ---- 世界书工具栏卡片 ---- */
.wb-toolbar-card {
  padding: 16px 18px;
  margin-bottom: 18px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.wb-toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.wb-select-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 240px;
}

.wb-label {
  font-size: 12px;
  font-weight: 750;
  color: var(--muted);
  white-space: nowrap;
}

.wb-select {
  flex: 1;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  background: #fff;
  font-weight: 600;
  color: var(--ink);
}

.wb-book-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.wb-search-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wb-search-row .search {
  flex: 1;
  height: 40px;
}

.wb-search-sub-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.wb-stats-tag {
  font-size: 12px;
  color: var(--accent-dark);
  background: var(--soft);
  border: 1px solid #dce7df;
  padding: 7px 12px;
  border-radius: 10px;
  white-space: nowrap;
}

/* ---- 搜索框强制规范 ---- */
#page-worlds .wb-search-row input.search,
#page-worlds #wbSearchInput {
  width: 100% !important;
  max-width: none !important;
  height: 44px !important;
  min-height: 44px !important;
  border-radius: 12px !important;
  padding: 0 14px !important;
  font-size: 13px !important;
  line-height: 44px !important;
  background: #ffffff !important;
  border: 1px solid var(--line) !important;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02) !important;
  margin-bottom: 6px !important;
}

#page-worlds .wb-search-row input.search:focus,
#page-worlds #wbSearchInput:focus {
  border-color: #18181b !important;
  box-shadow: 0 0 0 3px rgba(24, 24, 27, 0.06) !important;
}

#page-worlds .dropdown-capsule-btn {
  height: 34px !important;
  padding: 0 14px !important;
  border-radius: 99px !important;
}

/* ---- 条目网格 ---- */
.wb-entries-grid {
  display: grid;
  gap: 12px;
}

/* ---- 分组区块 ---- */
.wb-group-section {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
}

.wb-group-head {
  padding: 14px 18px;
  background: #fafbfa;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.wb-group-title {
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.wb-group-body {
  padding: 12px;
  display: grid;
  gap: 10px;
}

/* ---- 条目卡片 ---- */
.wb-entry-wrap-box {
  background: #fff !important;
  border: 1px solid var(--line) !important;
  border-radius: 16px !important;
  overflow: hidden !important;
  margin-bottom: 12px !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.02) !important;
}

.wb-entry-card {
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  margin: 0 !important;
  background: #fff !important;
  overflow: hidden !important;
  transition: transform .22s ease, box-shadow .22s ease, opacity .22s ease !important;
}

.wb-entry-card:hover {
  border-color: #b9c9bd;
}

.wb-entry-card.dragging-active {
  opacity: 0.95;
  transform: scale(1.025);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.14) !important;
  border-color: #18181b !important;
  z-index: 90;
}

.wb-entry-head {
  padding: 16px 16px 14px !important;
  display: block !important;
  cursor: pointer;
  list-style: none;
  background: #ffffff !important;
  border-bottom: 1px solid transparent;
}

.wb-entry-head::-webkit-details-marker {
  display: none;
}

details[open] > .wb-entry-head {
  background: #f4f4f5;
  border-bottom-color: #e4e4e7;
}

.wb-entry-main {
  flex: 1;
  min-width: 0;
}

.wb-entry-title {
  font-size: 15px;
  font-weight: 750;
  color: #18181b;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-wrap: anywhere;
}

.wb-entry-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 6px;
}

/* ---- 条目徽标 ---- */
.wb-key-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: #f4f4f5;
  color: #18181b;
  border: 1px solid #e4e4e7;
}

.wb-key-sec-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: #f4f4f5;
  color: #71717a;
  border: 1px solid #e4e4e7;
}

.wb-param-badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid #e4e4e7;
  color: #71717a;
}

.wb-param-badge.active {
  background: #18181b;
  color: #ffffff;
  border-color: #18181b;
  font-weight: 600;
}

/* ---- 条目操作栏 ---- */
.wb-entry-actions {
  display: grid !important;
  grid-template-columns: 1.2fr 1fr 44px !important;
  background: #fafafa !important;
  border-top: 1px solid var(--line) !important;
  width: 100% !important;
  height: 42px !important;
}

.wb-entry-actions .btn {
  height: 42px !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 6px !important;
  color: var(--ink) !important;
  border-right: 1px solid var(--line) !important;
  padding: 0 !important;
  box-shadow: none !important;
}

.wb-entry-actions .btn:active {
  background: #f4f4f5 !important;
}

.wb-entry-actions .btn-danger {
  border-right: 0 !important;
  color: #71717a !important;
  display: grid !important;
  place-items: center !important;
}

.wb-entry-actions .btn-danger:active {
  color: var(--danger) !important;
  background: #fef2f2 !important;
}

.wb-entry-actions svg.ui-icon {
  width: 15px !important;
  height: 15px !important;
  stroke: currentColor !important;
  stroke-width: 1.8 !important;
  fill: none !important;
  stroke-linecap: round !important;
  stroke-linejoin: round !important;
  display: block !important;
  flex-shrink: 0 !important;
}

/* ---- 条目展开体 ---- */
.wb-entry-body {
  padding: 16px;
  background: #fff;
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .28s cubic-bezier(0.16, 1, 0.3, 1), padding .28s ease !important;
}

.wb-entry-card[open] .wb-entry-body {
  grid-template-rows: 1fr;
  padding: 16px !important;
}

.wb-entry-body > * {
  overflow: hidden;
}

.wb-entry-content-box {
  font-size: 13px;
  line-height: 1.85;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--ink);
  user-select: text;
}

.wb-entry-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.wb-meta-item {
  background: #f4f4f5;
  border: 1px solid #e4e4e7;
  border-radius: 8px;
  padding: 8px 10px;
}

.wb-meta-item span {
  display: block;
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 2px;
}

.wb-meta-item strong {
  font-size: 12px;
  color: var(--ink);
}

/* ---- Smart Parser 弹窗 ---- */
.parser-modal-view {
  width: 100%;
  max-width: 860px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-sizing: border-box;
}

.parser-tip {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
  background: #f4f7f4;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #dbe6dc;
}

.parser-textarea {
  width: 100%;
  min-height: 180px;
  max-height: 280px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
  background: #fafbfa;
  color: var(--ink);
  box-sizing: border-box;
}

.parser-actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.parser-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.parser-results-list {
  display: grid;
  gap: 10px;
  max-height: 42dvh;
  overflow-y: auto;
  padding-right: 4px;
  margin-top: 8px;
}

.parser-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  display: grid;
  gap: 8px;
  position: relative;
}

.parser-card.unselected {
  opacity: .55;
  background: #fcfcfc;
}

.parser-card-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.parser-check {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

.parser-title-input {
  flex: 1;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
}

.parser-grid-params {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 6px;
}

.parser-small-input {
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 12px;
}

.parser-content-textarea {
  width: 100%;
  min-height: 75px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  line-height: 1.6;
  box-sizing: border-box;
}

/* ---- 沙盒弹窗 ---- */
.sandbox-modal {
  width: 100%;
  max-width: 720px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #fff;
  border-radius: 20px;
  box-sizing: border-box;
}

.sandbox-textarea {
  width: 100%;
  min-height: 90px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.7;
  outline: none;
  background: #fafbfa;
  color: var(--ink);
  box-sizing: border-box;
}

.sandbox-hit-list {
  display: grid;
  gap: 9px;
  max-height: 40vh;
  overflow-y: auto;
  padding-right: 4px;
}

.sandbox-hit-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sandbox-hit-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sandbox-preview-box {
  background: #f4f5f7;
  border: 1px solid #e4e7ed;
  border-radius: 12px;
  padding: 12px;
  font: 12px/1.7 ui-monospace, monospace;
  white-space: pre-wrap;
  color: #1f2329;
  max-height: 180px;
  overflow-y: auto;
}

/* ---- Kelivo 原生高仿表单系统 ---- */
.klv-modal-container {
  background: #f4f5f7 !important;
  width: 100% !important;
  max-width: 520px !important;
  height: 92dvh !important;
  border-radius: 20px 20px 0 0 !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.2) !important;
  margin: auto auto 0 auto !important;
}

.klv-modal-header {
  padding: 14px 20px 8px;
  text-align: center;
  background: #fff;
  border-bottom: 1px solid #ebedf0;
  position: relative;
  flex: 0 0 auto;
}

.klv-drag-handle {
  width: 40px;
  height: 5px;
  border-radius: 99px;
  background: #d8dadf;
  margin: 0 auto 10px;
}

.klv-modal-title {
  font-size: 17px;
  font-weight: 700;
  color: #1f2329;
}

.klv-modal-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.klv-card {
  background: #fff;
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
}

.klv-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
}

.klv-row-stacked {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.klv-label {
  font-size: 15px;
  font-weight: 600;
  color: #2b303b;
}

.klv-desc {
  font-size: 12px;
  color: #8f959e;
  line-height: 1.5;
  margin-top: -4px;
}

.klv-input-pill {
  background: #f0f2f5;
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 15px;
  color: #1f2329;
  outline: none;
  text-align: right;
  width: 140px;
}

.klv-input-pill.align-left {
  text-align: left;
  width: 100%;
}

.klv-input-pill.small {
  width: 72px;
  text-align: center;
}

.klv-input-pill:focus,
.klv-textarea:focus {
  border-color: #18181b !important;
  box-shadow: 0 0 0 4px rgba(24, 24, 27, 0.08) !important;
}

.klv-textarea {
  background: #f0f2f5;
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.7;
  color: #1f2329;
  resize: vertical;
  min-height: 160px;
  outline: none;
  font-family: inherit;
}

.klv-select-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #646a73;
  font-size: 14px;
  cursor: pointer;
  background: none;
  border: none;
  padding: 4px 0;
}

.klv-select-btn::after {
  content: '›';
  font-size: 18px;
  line-height: 1;
  color: #8f959e;
}

.klv-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.klv-tag-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #ebedf2;
  border-radius: 8px;
  font-size: 13px;
  color: #2e384d;
}

.klv-tag-del {
  cursor: pointer;
  color: #8f959e;
  font-size: 14px;
}

.klv-tag-del:hover {
  color: #e55353;
}

.klv-add-kw-box {
  display: flex;
  gap: 8px;
  align-items: center;
}

.klv-add-btn {
  width: 40px;
  height: 38px;
  border-radius: 10px;
  background: #f0f2f5;
  border: none;
  font-size: 18px;
  color: #646a73;
  display: grid;
  place-items: center;
}

.klv-modal-footer {
  display: flex;
  gap: 12px;
  padding: 12px 18px calc(14px + env(safe-area-inset-bottom));
  background: #fff;
  border-top: 1px solid #ebedf0;
  flex: 0 0 auto;
}

.klv-btn-cancel {
  flex: 1;
  height: 44px;
  border-radius: 12px;
  border: 1px solid #dcdfe6;
  background: #fff;
  color: #1f2329;
  font-size: 15px;
  font-weight: 600;
}

.klv-btn-save {
  flex: 1;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: #18181b;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

/* ---- BottomSheet Picker ---- */
.klv-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  z-index: 100000;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.klv-sheet-panel {
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 16px 20px calc(20px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: klvSheetIn .2s ease-out;
}

.klv-sheet-title {
  font-size: 16px;
  font-weight: 700;
  text-align: center;
  padding-bottom: 12px;
  color: #1f2329;
  border-bottom: 1px solid #ebedf0;
}

.klv-sheet-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 8px;
  font-size: 15px;
  color: #1f2329;
  cursor: pointer;
  border-bottom: 1px solid #f2f3f5;
}

.klv-sheet-option:last-child {
  border-bottom: none;
}

.klv-sheet-option.active {
  color: #18181b;
  font-weight: 700;
}

.klv-sheet-option.active::after {
  content: '✓';
  color: #18181b;
  font-size: 16px;
}

/* ==================================
   移动端世界书适配
   ================================== */
@media (max-width: 760px) {
  #page-worlds .page-heading {
    margin-bottom: 10px !important;
    gap: 6px !important;
  }

  #page-worlds .page-heading h1 {
    font-size: 20px !important;
    margin: 2px 0 4px !important;
  }

  #page-worlds .page-heading p {
    display: none !important;
  }

  #page-worlds .heading-actions {
    display: grid !important;
    grid-template-columns: 1.2fr 1fr !important;
    gap: 6px !important;
    width: 100% !important;
  }

  #page-worlds .heading-actions .btn,
  #page-worlds .heading-actions .file-trigger {
    min-height: 36px !important;
    height: 36px !important;
    font-size: 11px !important;
    padding: 0 8px !important;
    border-radius: 9px !important;
  }

  .wb-toolbar-card {
    padding: 12px !important;
    margin-bottom: 12px !important;
    border-radius: 14px !important;
  }

  .wb-toolbar-row {
    flex-direction: column;
    align-items: stretch;
    margin-bottom: 8px !important;
    gap: 6px !important;
  }

  .wb-select-wrap {
    width: 100%;
  }

  .wb-select {
    height: 36px !important;
    font-size: 12px !important;
  }

  .wb-book-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }

  .wb-book-actions .btn {
    padding: 7px 4px;
    font-size: 11px;
    min-height: 32px !important;
    height: 32px !important;
  }

  .wb-search-row {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
  }

  .wb-search-row .search {
    width: 100% !important;
    max-width: none !important;
    height: 44px !important;
    border-radius: 12px !important;
    padding: 0 14px !important;
    font-size: 13px !important;
    line-height: 44px !important;
  }

  .dropdown-capsule-btn {
    height: 34px !important;
    padding: 0 14px !important;
    border-radius: 99px !important;
  }

  /* 全屏模态编辑器 */
  #modalRoot .modal-backdrop {
    padding: 0 !important;
    align-items: stretch !important;
    justify-content: stretch !important;
  }

  #modalRoot .modal {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    border: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
  }

  #modalRoot .modalhead {
    padding: 14px 18px !important;
    margin: 0 !important;
    background: #fafbfa !important;
    border-bottom: 1px solid var(--line) !important;
    flex: 0 0 auto !important;
  }

  .wb-fullscreen-body {
    padding: 14px 16px 20px !important;
  }

  .wb-fullscreen-footer {
    padding: 10px 16px calc(12px + env(safe-area-inset-bottom)) !important;
  }

  .wb-fullscreen-footer .btn {
    flex: 1 !important;
  }

  .wb-form-grid {
    grid-template-columns: 1fr !important;
  }
}
