/* ============ 主题变量 ============ */
:root {
  --bg: #f6f7f9;
  --bg-card: #ffffff;
  --bg-side: #ffffff;
  --bg-inset: #f1f3f5;
  --text: #1a2333;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --accent: #4f6ef7;
  --accent-hover: #3d5bf5;
  --accent-soft: #eef1fe;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .05);
  --radius: 12px;
}
[data-theme="dark"] {
  --bg: #0f1420;
  --bg-card: #171e2e;
  --bg-side: #141a28;
  --bg-inset: #1f2739;
  --text: #e2e8f0;
  --text-muted: #8fa0b8;
  --border: #2a3247;
  --accent: #6b85ff;
  --accent-hover: #8298ff;
  --accent-soft: #232d4d;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .35);
}

/* ============ 基础 ============ */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  transition: background .25s, color .25s;
}
button { font-family: inherit; }
.hidden { display: none !important; }

/* ============ 布局 ============ */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.main { flex: 1; min-width: 0; padding: 28px 32px 60px; max-width: 1080px; margin: 0 auto; }

/* 侧边栏 */
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px 14px; }
.brand-icon { font-size: 26px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 11px; color: var(--text-muted); letter-spacing: .04em; }
.nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border: none; border-radius: 10px;
  background: transparent; color: var(--text-muted);
  font-size: 14px; cursor: pointer; text-align: left;
  width: 100%; transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--bg-inset); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ico { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.sidebar-footer { padding: 10px 12px 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.side-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg-card); color: var(--text); font-size: 13px; cursor: pointer;
  transition: border-color .15s;
}
.side-btn:hover { border-color: var(--accent); }
.mode-badge {
  font-size: 10px; padding: 1px 7px; border-radius: 999px;
  background: var(--warn); color: #fff; margin-left: auto; white-space: nowrap;
}
.mode-badge.live { background: var(--ok); }
.version { font-size: 11px; color: var(--text-muted); text-align: center; padding-top: 2px; }
.version a { color: inherit; text-decoration: none; }
.version a:hover { color: var(--accent); text-decoration: underline; }

/* ============ 工具工作区 ============ */
.tool-section { display: none; animation: fadeIn .2s ease; }
.tool-section.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.tool-head { margin-bottom: 18px; }
.tool-title { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.tool-desc { color: var(--text-muted); font-size: 13.5px; margin: 0; }

.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; margin-bottom: 16px;
}
.card-title { font-size: 14px; font-weight: 600; margin: 0 0 12px; color: var(--text); display: flex; align-items: center; gap: 6px; }

/* 表单 */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; margin: 0; }
.field.full { grid-column: 1 / -1; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field-label .req { color: var(--err); margin-left: 2px; }
.radio-group { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.radio-option {
  display: flex; align-items: flex-start; gap: 8px; min-width: 0; min-height: 58px;
  padding: 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-inset); color: var(--text); cursor: pointer;
  font-size: 12.5px; line-height: 1.45; overflow-wrap: anywhere;
}
.radio-option input { flex: none; margin: 2px 0 0; accent-color: var(--accent); }
.radio-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-option:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type="text"], input[type="password"], textarea, select {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg-inset); color: var(--text);
  font-size: 13.5px; font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
textarea { resize: vertical; min-height: 84px; line-height: 1.6; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg-inset); color: var(--text-muted);
  font-size: 12.5px; cursor: pointer; user-select: none;
  transition: all .15s;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* 按钮 */
.actions { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.btn {
  padding: 9px 20px; border-radius: 10px; border: 1px solid transparent;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all .15s; display: inline-flex; align-items: center; gap: 6px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn.danger { background: transparent; border-color: var(--err); color: var(--err); }
.btn.sm { padding: 5px 12px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.spacer { flex: 1; }
.status { font-size: 12.5px; color: var(--text-muted); }
.status.err { color: var(--err); }

/* 结果区 */
.result-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.state-badge {
  font-size: 11.5px; padding: 2px 10px; border-radius: 999px; font-weight: 600;
  background: var(--bg-inset); color: var(--text-muted);
}
.state-badge.running { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.state-badge.done { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.state-badge.err { background: color-mix(in srgb, var(--err) 15%, transparent); color: var(--err); }
.demo-flag { font-size: 11px; color: var(--warn); }
.output {
  background: var(--bg-inset); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; min-height: 120px; max-height: 640px; overflow-y: auto;
  font-size: 14px;
}
.output.empty { display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 13px; }

/* markdown 排版 */
.output h1, .output h2, .output h3, .output h4 { margin: 1em 0 .45em; line-height: 1.4; }
.output h1 { font-size: 17px; } .output h2 { font-size: 16px; } .output h3 { font-size: 15px; } .output h4 { font-size: 14px; }
.output h1:first-child, .output h2:first-child, .output h3:first-child { margin-top: 0; }
.output p { margin: .5em 0; }
.output ul, .output ol { padding-left: 1.4em; margin: .5em 0; }
.output li { margin: .25em 0; }
.output table { border-collapse: collapse; width: 100%; margin: .8em 0; font-size: 13px; display: block; overflow-x: auto; }
.output th, .output td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.output th { background: var(--bg-card); font-weight: 600; white-space: nowrap; }
.output code { background: var(--bg-card); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; font-size: 12.5px; }
.output pre { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: .6em 0; }
.output pre code { background: none; border: none; padding: 0; font-size: 12.5px; line-height: 1.55; font-family: ui-monospace, SFMono-Regular, Consolas, "Courier New", monospace; }
.output blockquote { margin: .6em 0; padding: 2px 14px; border-left: 3px solid var(--accent); color: var(--text-muted); background: var(--bg-card); border-radius: 0 8px 8px 0; }
.output hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
.cursor-blink { display: inline-block; width: 7px; height: 15px; background: var(--accent); vertical-align: -2px; margin-left: 2px; animation: blink .8s step-end infinite; border-radius: 2px; }
@keyframes blink { 50% { opacity: 0; } }

/* 模型与价格查询 */
.lookup-note { font-size: 12.5px; color: var(--text-muted); margin-bottom: 8px; }
.lookup-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.lookup-bar input { max-width: 320px; }
.lookup-count { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }
.lookup-table { border-collapse: collapse; width: 100%; font-size: 13px; display: block; overflow-x: auto; }
.lookup-table th, .lookup-table td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: middle; }
.lookup-table th { background: var(--bg-card); font-weight: 600; white-space: nowrap; }
.lookup-table tr.mrow { cursor: pointer; }
.lookup-table tr.mrow:hover td { background: var(--accent-soft); }
.lookup-sub { font-size: 11px; color: var(--text-muted); }
.lookup-tip { font-size: 11.5px; color: var(--text-muted); margin-top: 8px; line-height: 1.7; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; background: var(--bg-card); border: 1px solid var(--border); white-space: nowrap; }

.lookup-tools { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.lookup-tools .btn { text-decoration: none; }

/* 内嵌站点（SD-WAN 工具箱）：默认卡片式 */
.embed-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.embed-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); background: #fff; }
.embed-wrap iframe { width: 100%; height: 78vh; min-height: 520px; border: 0; display: block; background: #fff; }

/* 内嵌标签激活时：铺满整个页面区域（去掉居中限宽与内边距） */
body.embed-active .layout { height: 100vh; overflow: hidden; }
body.embed-active .main {
  max-width: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}
body.embed-active .workspace { flex: 1; display: flex; min-height: 0; min-width: 0; }
body.embed-active .tool-section.active { flex: 1; display: flex !important; flex-direction: column; min-height: 0; min-width: 0; }
body.embed-active .tool-head { margin: 0; padding: 12px 16px 4px; }
body.embed-active .tool-head .tool-desc { display: none; }
body.embed-active .embed-bar { margin: 0; padding: 0 16px 10px; }
body.embed-active .embed-wrap { flex: 1; min-height: 0; border: none; border-radius: 0; box-shadow: none; }
body.embed-active .embed-wrap iframe { height: 100%; min-height: 0; }

/* 历史 */
.hist-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg-inset); margin-bottom: 8px; cursor: pointer;
  transition: border-color .15s;
}
.hist-item:hover { border-color: var(--accent); }
.hist-title { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-time { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }
.hist-empty { color: var(--text-muted); font-size: 13px; text-align: center; padding: 8px 0; }

/* 弹窗 */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-mask { position: absolute; inset: 0; background: rgba(5, 10, 20, .55); backdrop-filter: blur(2px); }
.modal-card {
  position: relative; width: min(520px, calc(100vw - 32px));
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow); animation: fadeIn .18s ease;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 10px; }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 4px 20px 20px; display: flex; flex-direction: column; gap: 12px; }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.test-result { font-size: 12.5px; }
.test-result.ok { color: var(--ok); }
.test-result.err { color: var(--err); }
.icon-btn {
  border: none; background: var(--bg-inset); color: var(--text-muted);
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.icon-btn:hover { color: var(--text); }
.hint { font-size: 12.5px; color: var(--text-muted); margin: 0; line-height: 1.6; }
.hint.small { font-size: 11.5px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg-card);
  padding: 9px 20px; border-radius: 999px; font-size: 13.5px;
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 200;
  box-shadow: var(--shadow); max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ 响应式 ============ */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); }
  .nav { flex-direction: row; overflow-x: auto; padding: 4px 10px 8px; }
  .nav-item { white-space: nowrap; width: auto; }
  .sidebar-footer { flex-direction: row; align-items: center; flex-wrap: wrap; border-top: none; padding-top: 0; }
  .version { width: 100%; }
  .main { width: 100%; padding: 18px 14px 50px; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .radio-group { grid-template-columns: 1fr; }
  .radio-option { min-height: 0; }
}
