:root {
  --green: #07c160;
  --green-dark: #06a050;
  --bg: #f5f7fa;
  --side: #1b2330;
  --side-2: #232d3d;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 6px 20px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 220px;
  background: linear-gradient(180deg, var(--side), var(--side-2));
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--green); color: #fff; font-weight: 800; font-size: 20px;
  display: grid; place-items: center;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 11px; color: #9aa4b2; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  text-align: left; background: transparent; border: none; color: #cbd2dc;
  padding: 11px 12px; border-radius: 9px; cursor: pointer; font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--green); color: #fff; font-weight: 600; }

.sidebar-foot { font-size: 12px; color: #9aa4b2; display: flex; align-items: center; gap: 7px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; display: inline-block; }
.dot.ok { background: var(--green); }

/* Main */
.main { flex: 1; padding: 26px 30px;  }
.view { display: none; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.view-head h1 { margin: 0 0 4px; font-size: 22px; }
.view-head p { margin: 0 0 18px; color: var(--muted); }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 15px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

label { display: block; font-size: 13px; color: #374151; margin-bottom: 12px; font-weight: 500; }
label .req { color: #ef4444; }
input, textarea, select {
  width: 100%; margin-top: 5px; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; font-family: inherit; color: var(--text); background: #fff;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(7,193,96,.12); }
.row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.row label { margin-bottom: 12px; }

.adv { margin: 6px 0 12px; border-top: 1px dashed var(--border); padding-top: 10px; }
.adv summary { cursor: pointer; color: var(--green-dark); font-weight: 600; font-size: 13px; }

.check-line { display: flex; align-items: center; gap: 8px; font-weight: 400; margin-bottom: 10px; }
.check-line input { width: auto; margin: 0; }

.actions { display: flex; gap: 10px; margin-top: 6px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 10px 16px; border-radius: 9px; cursor: pointer; font-size: 13px; font-weight: 600;
  transition: all .15s;
}
.btn:hover { border-color: var(--green); color: var(--green-dark); }
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.primary:hover { background: var(--green-dark); color: #fff; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* Tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.tab { background: none; border: none; padding: 9px 14px; cursor: pointer; color: var(--muted); font-size: 13px; border-bottom: 2px solid transparent; }
.tab.active { color: var(--green-dark); border-bottom-color: var(--green); font-weight: 600; }

.md-view {
  background: #0f172a; color: #e2e8f0; padding: 16px; border-radius: 8px;
  max-height: 460px; overflow: auto; font-size: 12.5px; line-height: 1.7; white-space: pre-wrap; margin: 0;
}
.md-view.md-edit, textarea.md-edit {
  display: block; width: 100%; box-sizing: border-box; border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre; resize: vertical; outline: none; min-height: 320px;
}
.md-view.md-edit:focus, textarea.md-edit:focus { border-color: var(--green); box-shadow: 0 0 0 2px rgba(16,185,129,.15); }
#tpl-edit-wrap { margin-top: 10px; }
.html-view { width: 100%; height: 520px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.hidden { display: none; }

/* MD 模板库 */
.tpl-lib { margin-top: 4px; }
.tpl-lib-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.tpl-lib-head strong { font-size: 14px; }
.tpl-lib-tip { font-size: 12px; color: #6b7280; }
.tpl-lib-head input {
  flex: 1; min-width: 180px; max-width: 280px; padding: 8px 12px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 8px; outline: none;
}
.tpl-lib-head input:focus { border-color: var(--green-dark); }
.tpl-lib-head .btn { margin-left: auto; }
.tpl-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 12px; max-height: 520px; overflow-y: auto; padding: 2px;
}
.tpl-card {
  border: 2px solid var(--border); border-radius: 10px;  cursor: pointer;
  background: #fff; transition: border-color 0.15s, box-shadow 0.15s;
}
.tpl-card:hover { box-shadow: var(--shadow); }
.tpl-card.selected { border-color: #16a34a; box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.15); }
.tpl-cover { height: auto; background: #f3f4f6; }
.tpl-cover img { width: 100%; height: auto; display: block; }
.tpl-name {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 7px 9px; font-size: 12.5px; font-weight: 600;
}
.tpl-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-name em { font-style: normal; font-size: 10.5px; padding: 1px 6px; border-radius: 8px; flex-shrink: 0; }
.tpl-name em.free { background: #dcfce7; color: #15803d; }
.tpl-name em.vip { background: #fef3c7; color: #b45309; }

/* 模板库与预览同界面 */
.tpl-layout { display: flex; gap: 16px; align-items: stretch; margin-top: 12px; }
.tpl-layout .tpl-grid { flex: 0 0 460px; max-height: 560px; }
.tpl-preview { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tpl-preview-head {
  font-size: 13px; font-weight: 600; color: var(--green-dark);
  margin-bottom: 8px; display: flex; align-items: center; gap: 8px;
}
.tpl-preview-bar { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.tpl-preview-bar input { flex: 1; min-width: 160px; }
.tpl-preview .html-view {
  flex: 1; min-height: 520px; width: 100%;
  border: 1px solid var(--border); border-radius: 8px; background: #fff;
}
.tpl-ai-tag {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: #dcfce7; color: #15803d; font-weight: 600;
}
.tpl-ai { margin: 0 4px; }
@media (max-width: 900px) {
  .tpl-layout { flex-direction: column; }
  .tpl-layout .tpl-grid { flex: none; max-height: 300px; }
}
.tpl-empty { grid-column: 1 / -1; color: var(--muted); font-size: 13px; padding: 20px 0; text-align: center; }

/* Check */
.check-empty { color: var(--muted); font-size: 13px; }
.check-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; margin-bottom: 8px; }
.check-badge.ok { background: #dcfce7; color: #15803d; }
.check-badge.warn { background: #fef3c7; color: #b45309; }
.check-meta { font-size: 13px; color: #374151; margin-bottom: 6px; }
.check-warn { font-size: 12.5px; color: #b45309; margin: 2px 0; }

.cover-box { border: 1px dashed var(--border); border-radius: 8px; min-height: 150px; display: grid; place-items: center; color: var(--muted); overflow: hidden; }
.cover-box img { width: 100%; border-radius: 8px; display: block; }

.msg { margin-top: 12px; font-size: 13px; }
.msg.ok { color: var(--green-dark); }
.msg.err { color: #dc2626; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; padding: 11px 18px; border-radius: 10px; font-size: 13px;
  box-shadow: var(--shadow); z-index: 50;
}
.toast.err { background: #dc2626; }
.toast.hidden { display: none; }

code { background: #eef2f7; padding: 1px 6px; border-radius: 5px; font-size: 12px; }

@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
  .sidebar { width: 64px; }
  .brand-text, .sidebar-foot, .nav-item { font-size: 0; }
  .nav-item { text-align: center; }
}

/* 进度遮罩 */
.progress-overlay {
  position: fixed; inset: 0; background: rgba(17, 24, 39, 0.45);
  display: grid; place-items: center; z-index: 100;
}
.progress-overlay.hidden { display: none; }
.progress-box {
  background: #fff; border-radius: 14px; padding: 26px 32px; min-width: 280px;
  box-shadow: var(--shadow); text-align: center;
}
.spinner {
  width: 38px; height: 38px; margin: 0 auto 14px;
  border: 4px solid #e5e7eb; border-top-color: var(--green-dark, #16a34a);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-text { font-size: 14px; color: #374151; margin-bottom: 14px; }
.progress-track { height: 6px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.progress-fill {
  height: 100%; width: 40%; border-radius: 999px;
  background: var(--green-dark, #16a34a); animation: indet 1.1s ease-in-out infinite;
}
@keyframes indet {
  0% { margin-left: -40%; }
  100% { margin-left: 100%; }
}

/* 通用小按钮 / tabs 内操作 */
.btn.small { padding: 6px 12px; font-size: 12.5px; }
.tab-action { margin-left: auto; }

/* 提取页：自定义模板入口 */
.custom-tpl { margin-top: 18px; border-top: 1px dashed var(--border); padding-top: 14px; }
.custom-tpl-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.custom-tpl-head .tpl-lib-tip { font-size: 12px; color: var(--muted); flex: 1; min-width: 160px; }

/* 模板卡片：自定义徽标 / 空封面 / 删除 */
.tpl-name em.custom { background: #ede9fe; color: #6d28d9; }
.tpl-cover-empty {
  height: 90px; display: grid; place-items: center; padding: 6px;
  background: linear-gradient(135deg, #eef2f7, #f8fafc); color: #475569;
  font-size: 12px; text-align: center; line-height: 1.3;
}
.tpl-del {
  cursor: pointer; color: #9ca3af; font-size: 14px; line-height: 1; padding: 2px 4px; border-radius: 6px;
}
.tpl-del:hover { color: #dc2626; background: #fee2e2; }

/* 弹窗 */
.modal {
  position: fixed; inset: 0; background: rgba(17, 24, 39, 0.45);
  display: grid; place-items: center; z-index: 100; padding: 16px;
}
.modal.hidden { display: none; }
.modal-box {
  background: #fff; border-radius: 14px; padding: 22px 24px; width: 100%; max-width: 560px;
  max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-box label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 6px; }
.modal-box input, .modal-box textarea {
  width: 100%; padding: 9px 11px; font-size: 13px; font-weight: 400;
  border: 1px solid var(--border); border-radius: 8px; outline: none; box-sizing: border-box;
}
.modal-box textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-x { border: none; background: transparent; font-size: 24px; line-height: 1; cursor: pointer; color: #9ca3af; }
.modal-x:hover { color: #374151; }
.modal-box .actions { margin-top: 16px; }

/* 登录遮罩 */
.login-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1f2937, #0f172a);
}
.login-overlay.hidden { display: none; }
.login-box {
  width: 320px; max-width: 90vw; background: #fff; border-radius: 14px;
  padding: 28px 26px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-logo {
  width: 44px; height: 44px; border-radius: 12px; margin: 0 auto 12px;
  background: linear-gradient(135deg, #3b82f6, #6366f1); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px;
}
.login-box h2 { text-align: center; margin: 4px 0 2px; font-size: 18px; }
.login-tip { text-align: center; color: #6b7280; font-size: 12px; margin: 0 0 16px; }
.login-box label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 6px; }
.login-box input {
  width: 100%; box-sizing: border-box; padding: 9px 11px; border: 1px solid #d1d5db;
  border-radius: 8px; font-size: 14px; outline: none;
}
.login-box input:focus { border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
.btn.block { width: 100%; margin-top: 16px; }
.link-btn { background: none; border: none; color: #3b82f6; cursor: pointer; font-size: 12px; padding: 0; margin-left: 6px; }
.link-btn:hover { text-decoration: underline; }
.account-bar { width: 100%; margin-top: 6px; display: flex; align-items: center; justify-content: space-between; }
.muted { color: #6b7280; font-size: 12px; margin: 0 0 12px; }
