:root {
  --bg: #f4f5f9;
  --panel: #ffffff;
  --sidebar: #fbfbfd;
  --border: #e6e8ef;
  --text: #1f2430;
  --text-2: #6b7280;
  --accent: #6366f1;
  --accent-strong: #4f46e5;
  --accent-soft: #eef0ff;
  --danger: #e11d48;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

/* 确保 hidden 属性始终生效（覆盖各组件自身的 display 规则） */
[hidden] { display: none !important; }

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

body {
  display: flex;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 264px;
  flex: 0 0 264px;
  display: flex;
  flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 6px;
}
.brand-logo {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  font-size: 22px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  box-shadow: var(--shadow);
}
.brand-text h1 { margin: 0; font-size: 17px; letter-spacing: .5px; }
.brand-text p { margin: 2px 0 0; font-size: 11px; color: var(--text-2); letter-spacing: 1.5px; text-transform: uppercase; }

.btn-upload {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 12px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform .06s ease, box-shadow .15s ease;
  box-shadow: var(--shadow);
}
.btn-upload:hover { box-shadow: 0 6px 20px rgba(99, 102, 241, .35); }
.btn-upload:active { transform: translateY(1px); }
.btn-icon { font-size: 15px; }

.nav-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 6px 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .8px;
}
.count {
  min-width: 20px;
  text-align: center;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 11px;
}

.tool-nav {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 2px;
}
.tool-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  color: var(--text);
  font-size: 13.5px;
  border: 1px solid transparent;
  transition: background .12s ease, border-color .12s ease;
}
.tool-item:hover { background: #f0f1f7; }
.tool-item.active { background: var(--accent-soft); color: var(--accent-strong); border-color: #dcdfff; font-weight: 600; }
.tool-item-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tool-item-del {
  visibility: hidden;
  border: none;
  background: transparent;
  color: #9ca3af;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 6px;
}
.tool-item:hover .tool-item-del { visibility: visible; }
.tool-item-del:hover { color: var(--danger); background: #fee2e2; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.btn-ghost {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-2);
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 13px;
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.btn-ghost:hover:not(:disabled) { background: #f0f1f7; color: var(--text); }
.btn-ghost:disabled { opacity: .5; cursor: not-allowed; }
.btn-danger-ghost {
  border: 1px solid #fecdd3;
  background: #fff;
  color: var(--danger);
  padding: 8px 12px;
  border-radius: 9px;
  font-size: 13px;
  cursor: pointer;
}
.btn-danger-ghost:hover:not(:disabled) { background: #fff1f2; }
.btn-danger-ghost:disabled { opacity: .5; cursor: not-allowed; }
.storage-note { margin: 0; font-size: 11px; color: #9ca3af; line-height: 1.5; }

/* ---------- 主内容区 ---------- */
.content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  gap: 10px;
}
.empty-icon { font-size: 64px; }
.empty-state h2 { margin: 6px 0 0; font-size: 22px; }
.empty-state p { margin: 0; color: var(--text-2); font-size: 14.5px; max-width: 420px; line-height: 1.7; }
.empty-actions { margin: 14px 0 4px; }
.empty-tip { font-size: 13px; color: #9ca3af; }

.tool-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.tool-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.tool-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.tool-name { font-size: 15px; font-weight: 700; }
.tool-meta { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-actions { display: flex; gap: 8px; }

#toolFrame {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
}

/* ---------- 拖拽遮罩 ---------- */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(79, 70, 229, .12);
  backdrop-filter: blur(2px);
  display: grid;
  place-items: center;
  pointer-events: none;
}
.drop-box {
  padding: 40px 60px;
  background: #fff;
  border: 2px dashed var(--accent);
  border-radius: 16px;
  text-align: center;
  color: var(--accent-strong);
  font-size: 16px;
  font-weight: 600;
}
.drop-icon { font-size: 40px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(12px);
  background: #111827;
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  max-width: 80vw;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 工具市场按钮 ---------- */
.btn-market {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid #dcdfff;
  border-radius: 10px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.btn-market:hover { background: #e2e5ff; }
.btn-market.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- 市场视图 ---------- */
.market-view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 20px 24px;
  gap: 16px;
  overflow: hidden;
}
.market-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.market-heading h2 { margin: 0; font-size: 20px; }
.market-heading p { margin: 4px 0 0; color: var(--text-2); font-size: 13px; }
.market-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.market-controls input {
  padding: 8px 12px;
  font-size: 13.5px;
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
  min-width: 220px;
  background: #fff;
  color: var(--text);
}
.market-controls input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99, 102, 241, .15); }

.market-list {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  align-content: start;
  padding-bottom: 8px;
}
.market-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.market-card h3 { margin: 0; font-size: 15px; }
.market-card .m-desc {
  margin: 0;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.55;
  flex: 1;
}
.market-card .m-meta { font-size: 12px; color: #9ca3af; }
.market-card .m-actions { display: flex; gap: 8px; }

.btn-primary {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }

.market-error {
  grid-column: 1 / -1;
  padding: 40px 20px;
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
  line-height: 1.7;
  background: #fff;
  border: 1px dashed var(--border);
  border-radius: 12px;
}
.market-error small { color: #9ca3af; }

/* ---------- 预览弹窗 ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(15, 18, 30, .45);
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal {
  width: min(960px, 100%);
  height: min(90vh, 100%);
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-actions { display: flex; gap: 8px; }
#previewFrame { flex: 1; width: 100%; border: none; background: #fff; }

/* ---------- 响应式 ---------- */
@media (max-width: 720px) {
  body { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 10px 12px;
  }
  .brand { padding: 0; }
  .brand-text { display: none; }
  .btn-upload { width: auto; }
  .nav-label { display: none; }
  .tool-nav { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding-bottom: 2px; }
  .tool-item { flex: 0 0 auto; }
  .sidebar-footer { border-top: none; flex-direction: row; align-items: center; }
  .storage-note { display: none; }
  .tool-header { flex-wrap: wrap; }
}
