:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #e3e8f0;
  --text: #1f2733;
  --muted: #6b7686;
  --primary: #4f6ef7;
  --primary-d: #3a55d6;
  --primary-soft: #eef1fe;
  --green: #1aa663;
  --red: #e0483a;
  --amber: #d98a00;
  --shadow: 0 6px 24px rgba(31,39,51,.08);
  --radius: 14px;
  --sb-w: 268px;
}
* { box-sizing: border-box; }
/* 始终预留滚动条位置，避免有无滚动条时内容区宽度不一致导致左右偏移 */
html { scrollbar-gutter: stable; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Site header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.site-header .inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 16px;
  min-height: 60px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.site-header .logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
.site-header .back {
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}
.site-header .back:hover { background: #f5f7fb; }

main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 60px; }

.tool-head { margin-bottom: 20px; }
.tool-head h1 { font-size: 24px; margin: 0 0 6px; }
.tool-head p { margin: 0; color: var(--muted); font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}

/* Upload zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 38px 20px;
  text-align: center;
  cursor: pointer;
  transition: .2s;
  background: #fafbff;
}
.drop-zone.drag { border-color: var(--primary); background: var(--primary-soft); }
.drop-zone .ico { font-size: 40px; line-height: 1; }
.drop-zone h3 { margin: 12px 0 4px; font-size: 17px; }
.drop-zone p { margin: 0; color: var(--muted); font-size: 13px; }

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  align-items: end;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); }
.field input[type="text"], .field input[type="number"], .field input[type="color"], .field input[type="range"], .field select, .field textarea {
  padding: 9px 10px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 14px; background: #fff; color: var(--text); width: 100%;
}
.field input[type="range"] { padding: 6px 0; }
.field input[type="color"] { min-height: 38px; padding: 4px; }
.field textarea { min-height: 120px; resize: vertical; }
.range-val { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Buttons */
.btn {
  border: none; border-radius: 10px; padding: 11px 18px; font-size: 14px;
  font-weight: 600; cursor: pointer; transition: .15s; display: inline-flex;
  align-items: center; gap: 7px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-ghost { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover { background: #f3f5fa; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }

/* Preview / result */
.preview-wrap { display: flex; gap: 14px; flex-wrap: wrap; }
.preview-box { flex: 1; min-width: 260px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #f0f2f7; display: flex; flex-direction: column; }
.preview-box .title { font-size: 12px; color: var(--muted); padding: 8px 12px; border-bottom: 1px solid var(--border); background: #fff; }
.preview-box img { max-width: 100%; max-height: 55vh; object-fit: contain; display: block; margin: auto; }
.preview-box canvas { max-width: 100%; max-height: 55vh; display: block; margin: auto; }

.result { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

/* Item list */
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.item { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #fff; }
.item img { width: 100%; height: 180px; object-fit: contain; background: #f0f2f7; }
.item .info { padding: 12px; font-size: 13px; }
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { color: var(--muted); margin-top: 4px; }

/* Home page */
.hero { text-align: center; padding: 40px 16px 20px; }
.hero h1 { font-size: 32px; margin: 0 0 10px; }
.hero p { margin: 0; color: var(--muted); font-size: 15px; }

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  transition: .15s;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tool-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.tool-card .icon { font-size: 32px; }
.tool-card .title { font-size: 16px; font-weight: 700; }
.tool-card .desc { font-size: 13px; color: var(--muted); line-height: 1.5; }
.tool-card .tag { font-size: 11px; color: var(--primary); background: var(--primary-soft); padding: 2px 8px; border-radius: 6px; align-self: flex-start; margin-top: auto; }

footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 16px; }

.hidden { display: none !important; }

/* 内容区顶部栏：面包屑 + 信任标签（填充标题上方空白，固定锁定） */
.content-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  height: 56px;
  margin: -24px -16px 18px -16px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.cb-crumb { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.cb-crumb a { color: var(--primary-d); text-decoration: none; }
.cb-crumb a:hover { text-decoration: underline; }
.cb-current { color: var(--text); font-weight: 600; }
.tool-tags { display: flex; gap: 8px; flex-wrap: wrap; }
.tool-tag {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
}

/* 旧顶部导航改为侧边栏，先隐藏避免加载时闪现 */
.site-header { display: none !important; }

/* ===== 侧边导航栏 ===== */
.sidebar-active { padding-left: var(--sb-w); }

/* SPA 外壳：右侧内容区 iframe（固定左侧栏，右侧无刷新切换） */
body[data-shell] { overflow: hidden; }

/* 外壳层顶部栏：与侧栏 logo 同一层级固定，高度与 sb-brand 一致（56px），白底填充 */
.shell-topbar {
  position: fixed;
  top: 0; left: var(--sb-w); right: 0;
  height: 56px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
#content-frame {
  position: fixed;
  top: 56px; left: var(--sb-w);
  width: calc(100% - var(--sb-w));
  height: calc(100vh - 56px);
  height: calc(100dvh - 56px);
  border: 0;
  background: var(--bg);
}

.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sb-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: 2px 0 14px rgba(31,39,51,.05);
  display: flex;
  flex-direction: column;
  z-index: 30;
}

/* 自定义扁平灰色滚动条（仅侧边栏列表） */
.sb-nav {
  scrollbar-width: thin;
  scrollbar-color: #c4cad6 transparent;
}
.sb-nav::-webkit-scrollbar { width: 8px; }
.sb-nav::-webkit-scrollbar-track { background: transparent; }
.sb-nav::-webkit-scrollbar-thumb {
  background: #c4cad6;
  border-radius: 4px;
}
.sb-nav::-webkit-scrollbar-thumb:hover { background: #aab2c0; }
.sb-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 56px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.sb-brand:hover { color: var(--primary-d); }
.sb-brand .sb-logo {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #7c8cff);
  box-shadow: 0 2px 6px rgba(79,110,247,.3);
  flex: none;
}
.sb-search {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.sb-search-input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  background: #fff url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='15'%20height='15'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='%239aa3b2'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%3E%3Ccircle%20cx='11'%20cy='11'%20r='7'/%3E%3Cline%20x1='21'%20y1='21'%20x2='16.65'%20y2='16.65'/%3E%3C/svg%3E") no-repeat 11px center;
  color: var(--text);
  box-sizing: border-box;
  transition: border-color .15s, box-shadow .15s;
}
.sb-search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.sb-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px 16px;
}
.sb-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  margin-bottom: 3px;
  white-space: nowrap;
  position: relative;
  transition: background .15s, color .15s;
}
.sb-link:hover { background: #f3f5fa; }
.sb-link.active {
  background: var(--primary-soft);
  color: var(--primary-d);
  font-weight: 600;
}
.sb-link.active::before {
  content: "";
  position: absolute;
  left: 4px; top: 9px; bottom: 9px;
  width: 3px;
  border-radius: 3px;
  background: var(--primary);
}
.sb-ico {
  font-size: 16px;
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  background: #f0f2f7;
  border-radius: 8px;
  flex: none;
  transition: background .15s;
}
.sb-link:hover .sb-ico { background: #e7ebf3; }
.sb-link.active .sb-ico { background: #fff; }
.sb-name { overflow: hidden; text-overflow: ellipsis; }

/* 移动端：抽屉式 */
/* 汉堡菜单按钮：放在顶栏内部（flex 第一项），桌面端隐藏，移动端显示，与面包屑对齐 */
.topbar-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  flex: none;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow);
}
/* 侧栏关闭按钮：抽屉打开后显示在侧栏右上角，单独成行，不遮挡左上角 logo */
.sb-close {
  display: none;
  position: absolute;
  top: 10px; right: 12px;
  z-index: 35;
  width: 36px; height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  line-height: 1;
  cursor: pointer;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,20,30,.4);
  z-index: 25;
}
body.sidebar-open .sidebar-overlay { display: block; }
body.sidebar-open .sb-close { display: flex; }

@media (max-width: 820px) {
  .sidebar-active { padding-left: 0; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: var(--shadow);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  /* 汉堡按钮进入顶栏内部，移动端显示 */
  .topbar-menu-btn { display: inline-flex; }
  main { padding: 0 16px; }
  /* 移动端顶栏留一点顶部空隙，避免汉堡按钮贴到屏幕最边缘 */
  .content-topbar { padding-top: 10px; }
  /* SPA 外壳：窄屏下顶部栏与 iframe 均占满剩余宽度，抽屉收起时 sidebar 隐藏 */
  .shell-topbar { left: 0; width: 100%; display: none; }
  body[data-shell] #content-frame {
    left: 0;
    width: 100%;
    top: 0;
    height: 100vh;
    height: 100dvh;
  }
  body[data-shell].sidebar-open #content-frame {
    left: 0;
    width: 100%; /* 抽屉是 overlay 浮层，不挤压内容区 */
  }
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .preview-box { min-width: 100%; }
  .actions { flex-direction: column; }
  .btn { width: 100%; justify-content: center; }
  /* 顶栏允许换行（标签换到第二行），但汉堡按钮与面包屑保持在首行 */
  .content-topbar { flex-wrap: wrap; height: auto; padding-bottom: 10px; }
  .drop-zone h3, .drop-zone p { writing-mode: horizontal-tb; white-space: normal; word-break: normal; }
}
