:root {
  --bg:                 #f0eef8;
  --surface:            #ffffff;
  --surface-low:        #f5f4fb;
  --surface-container:  #eceaf5;
  --on-surface:         #1a1b22;
  --on-surface-variant: #5a5470;
  --outline:            #d8d4e8;
  --outline-strong:     #c4bfdb;
  --primary:            #9d4300;
  --on-primary:         #ffffff;
  --primary-container:  #f97316;
  --mono: "JetBrains Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Geist", sans-serif;
  color: var(--on-surface);
  background: var(--bg);
  min-height: 100vh;
  padding: 0;
}

/* ── App Shell ──────────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 200px 1fr;
  min-height: 100vh;
  background: var(--surface);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.side-nav {
  background: var(--surface);
  border-right: 1px solid var(--outline);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
}

.logo-icon {
  width: 26px;
  height: 26px;
  background: linear-gradient(135deg, var(--primary), var(--primary-container));
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.logo-text {
  font-size: 14px;
  font-weight: 700;
  color: var(--on-surface);
  letter-spacing: -0.01em;
}

.nav-groups {
  padding: 8px;
}

.nav-group {
  margin-bottom: 4px;
}

.nav-group-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--on-surface-variant);
  padding: 10px 8px 4px;
  user-select: none;
}

.nav-group-icon {
  font-size: 11px;
  opacity: 0.6;
}

.nav-item {
  display: block;
  text-decoration: none;
  color: var(--on-surface);
  font-family: "Geist", sans-serif;
  font-size: 13.5px;
  font-weight: 500;
  padding: 7px 10px;
  border-radius: 4px;
  margin-bottom: 1px;
  transition: background 0.1s, color 0.1s;
}

.nav-item:hover {
  background: var(--surface-container);
}

.nav-item.active {
  background: #ffedd5;
  color: var(--primary);
  font-weight: 600;
}

/* ── Content Wrap ────────────────────────────────────────────────────────── */
.content-wrap {
  background: var(--surface-low);
  display: flex;
  flex-direction: column;
}

/* ── Content Header ──────────────────────────────────────────────────────── */
.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--outline);
  background: var(--surface);
  gap: 12px;
  flex-shrink: 0;
}

.content-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.tool-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--on-surface);
  line-height: 1.2;
  white-space: nowrap;
}


/* Ghost 按鈕（次要動作，如複製、下載） */
.btn-ghost {
  margin-top: 0;
  background: var(--surface);
  color: var(--on-surface);
  border: 1px solid var(--outline-strong);
  font-weight: 500;
  padding: 4px 10px;
  font-size: 12px;
}

.btn-ghost:hover {
  background: var(--surface-container);
  opacity: 1;
  filter: none;
}

/* 有 data-primary 的按鈕功能已串到 header ▶ 執行，不需顯示 */
[data-primary] { display: none; }

/* .active-badge — 保留備用，可在 app.js 加回 <span class="active-badge"> */
.active-badge {
  background: transparent;
  color: var(--primary);
  border: 1px solid #fed7aa;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.reset-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface);
  color: var(--on-surface);
  border: 1px solid var(--outline-strong);
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  font-family: "Geist", sans-serif;
  cursor: pointer;
  transition: background 0.1s;
  margin-top: 0;
}

.reset-btn:hover {
  background: var(--surface-container);
  filter: none;
}

.run-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: var(--on-primary);
  border: none;
  border-radius: 4px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 700;
  font-family: "Geist", sans-serif;
  cursor: pointer;
  transition: opacity 0.1s;
  flex-shrink: 0;
  margin-top: 0;
}

.run-btn:hover {
  opacity: 0.88;
  background: var(--primary);
  filter: none;
}

/* ── Content Pane ────────────────────────────────────────────────────────── */
.content-pane {
  padding: 24px;
  flex: 1;
}

/* ── Tool ────────────────────────────────────────────────────────────────── */
.tool {
  animation: fadeIn .15s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(3px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Typography ──────────────────────────────────────────────────────────── */
h3 {
  margin: 18px 0 8px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--on-surface-variant);
}

h4 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--on-surface-variant);
}

label {
  display: block;
  margin: 10px 0 5px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--on-surface-variant);
}

/* ── Form Controls ───────────────────────────────────────────────────────── */
textarea,
input[type="text"],
input[type="url"],
input[type="number"],
select {
  width: 100%;
  border: 1px solid var(--outline-strong);
  border-radius: 4px;
  font-size: 13px;
  padding: 9px 11px;
  color: var(--on-surface);
  background: var(--surface);
  font-family: var(--mono);
  transition: border-color .12s, box-shadow .12s;
}

textarea:focus,
input[type="text"]:focus,
input[type="url"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(157, 67, 0, 0.12);
}

input[type="color"] {
  border: 1px solid var(--outline-strong);
  border-radius: 4px;
  cursor: pointer;
  padding: 3px;
}

input[type="color"]:focus {
  outline: none;
  border-color: var(--primary);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
button {
  margin-top: 10px;
  border: 0;
  border-radius: 4px;
  padding: 8px 14px;
  font-weight: 600;
  font-family: "Geist", sans-serif;
  font-size: 13px;
  cursor: pointer;
  color: var(--on-primary);
  background: var(--primary);
  transition: opacity .15s;
}

button:hover {
  opacity: 0.88;
  background: var(--primary);
  filter: none;
}

.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.button-row button { margin-top: 10px; }

/* ── Pre / Code ──────────────────────────────────────────────────────────── */
pre {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 4px;
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--on-surface);
}

/* ── Drop Zone ───────────────────────────────────────────────────────────── */
.drop-zone {
  border: 1px dashed var(--outline-strong);
  border-radius: 4px;
  padding: 28px;
  text-align: center;
  color: var(--on-surface-variant);
  cursor: pointer;
  margin-bottom: 12px;
  background: var(--surface);
  transition: border-color .15s, background .15s;
  font-size: 13px;
}

.drop-zone.dragover {
  border-color: var(--primary-container);
  background: #fff8f3;
}

/* ── Image Preview ───────────────────────────────────────────────────────── */
img.preview {
  max-width: 100%;
  margin-top: 12px;
  display: block;
  border: 1px solid var(--outline);
  border-radius: 4px;
}

/* ── Grids ───────────────────────────────────────────────────────────────── */
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* ── Muted ───────────────────────────────────────────────────────────────── */
.muted {
  color: var(--on-surface-variant);
  font-size: 13px;
  margin: 0 0 16px;
  line-height: 1.5;
}

/* ── JSON Tool ───────────────────────────────────────────────────────────── */
.json-shell {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  height: 420px;
}

.json-panel {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--outline);
  overflow: hidden;
}

.json-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface-container);
  border-bottom: 1px solid var(--outline);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--on-surface-variant);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.json-panel-header .btn-ghost {
  margin-top: 0;
  padding: 2px 8px;
  font-size: 11px;
}

.json-search-row {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.json-search-row input {
  width: 120px;
  padding: 3px 8px;
  font-size: 12px;
  border-radius: 3px;
  font-family: var(--mono);
  border: 1px solid var(--outline-strong);
}

.json-search-row input:focus {
  box-shadow: none;
  border-color: var(--primary);
}

#jsonSearchCount {
  font-size: 11px;
  color: var(--on-surface-variant);
  font-family: var(--mono);
  white-space: nowrap;
  min-width: 40px;
}

.json-panel textarea {
  flex: 1;
  border: none;
  border-radius: 0;
  resize: none;
  font-size: 13px;
  line-height: 1.6;
  padding: 12px;
  box-shadow: none;
}

.json-panel textarea:focus {
  box-shadow: none;
  border-color: transparent;
}

.json-output-wrap {
  flex: 1;
  overflow: auto;
}

.json-output-wrap pre {
  margin: 0;
  border: none;
  border-radius: 0;
  max-height: none;
  padding: 12px;
  background: var(--surface);
  min-height: 100%;
}

/* ── JSON View Toggle ────────────────────────────────────────────────────── */
.json-view-toggle {
  display: flex;
  border: 1px solid var(--outline-strong);
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
}

.json-view-btn {
  margin: 0;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 0;
  background: var(--surface);
  color: var(--on-surface-variant);
  border: none;
  border-right: 1px solid var(--outline-strong);
  transition: background 0.1s;
}

.json-view-btn:last-child { border-right: none; }

.json-view-btn.active {
  background: var(--surface-container);
  color: var(--on-surface);
}

.json-view-btn:hover { opacity: 1; filter: none; background: var(--surface-container); }

/* ── JSON Path Bar ───────────────────────────────────────────────────────── */
.json-path-bar {
  padding: 4px 12px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--on-surface-variant);
  background: var(--surface-container);
  border-top: 1px solid var(--outline);
  min-height: 22px;
}

/* ── JSON Tree ───────────────────────────────────────────────────────────── */
pre.jt-root {
  padding: 10px 12px;
  line-height: 1.7;
  font-size: 13px;
}

.jt-node { }

.jt-children { padding-left: 20px; margin: 0; list-style: none; }
.jt-children.jt-hidden { display: none; }

.jt-row {
  display: flex;
  align-items: baseline;
  gap: 2px;
  border-radius: 3px;
  padding: 0 4px;
}

.jt-toggle {
  cursor: pointer;
}

.jt-toggle:hover { color: var(--primary); }

.jt-toggle {
  font-size: 10px;
  width: 14px;
  flex-shrink: 0;
  color: var(--on-surface-variant);
  user-select: none;
  cursor: pointer;
}

.jt-toggle:hover { color: var(--primary); }

.jt-toggle-placeholder { width: 14px; flex-shrink: 0; }

.jt-key {
  color: #9d4300;
  font-weight: 600;
  cursor: pointer;
  border-radius: 2px;
  padding: 0 2px;
}

.jt-key:hover {
  background: #ffedd5;
  text-decoration: underline;
}
.jt-colon  { color: var(--on-surface-variant); }
.jt-bracket { color: var(--on-surface-variant); font-size: 12px; }

.jt-val         { }
.jt-string      { color: #16a34a; }
.jt-number      { color: #2563eb; }
.jt-bool        { color: #7c3aed; }
.jt-null        { color: #9ca3af; font-style: italic; }

mark.json-mark {
  background: #fef08a;
  color: inherit;
  border-radius: 2px;
}

mark.json-mark-cur {
  background: #f97316;
  color: #fff;
  border-radius: 2px;
}

.json-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.json-toolbar .btn-ghost {
  margin-top: 0;
}

.json-status {
  font-size: 12px;
  font-family: var(--mono);
  margin-left: 4px;
}

.json-status-ok    { color: #16a34a; }
.json-status-error { color: var(--primary); }
.json-status-jump  { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }

.json-err-snippet {
  margin: 6px 0 0;
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  background: var(--surface-low);
  border-radius: 6px;
  overflow-x: auto;
  cursor: pointer;
  white-space: pre;
}
.json-err-caret { color: var(--primary); font-weight: 700; }

@media (max-width: 640px) {
  .json-shell { grid-template-columns: 1fr; height: auto; }
  .content-pane:has(#mdShell)        { display: block; }
  .content-pane:has(#mdShell) > .tool { display: block; flex: none; }
  #mdShell { flex: none; height: auto; min-height: 0; }
  .json-panel textarea { min-height: 160px; }
}

/* ── OpenAPI 文件檢視：API 列表面板 ───────────────────────────────────── */
.oa-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.oa-panel {
  position: sticky;
  top: 12px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--outline);
  border-radius: 4px;
  background: var(--surface);
  overflow: hidden;
  margin-top: 10px;
}

.oa-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface-container);
  border-bottom: 1px solid var(--outline);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--on-surface-variant);
}

.oa-count { font-family: var(--mono); text-transform: none; letter-spacing: 0; }
.oa-count b { color: var(--primary); }

.oa-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--outline);
}
.oa-toolbar[hidden] { display: none; }
.oa-toolbar button { margin-top: 0; padding: 6px 12px; font-size: 12px; }
.oa-toolbar button:disabled { opacity: 0.6; cursor: not-allowed; }

/* 面板內的 label 不套全域表單 label（大寫小字） */
.oa-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--on-surface);
  cursor: pointer;
}
.oa-panel input[type="checkbox"] { accent-color: var(--primary); flex-shrink: 0; }

.oa-list { max-height: 62vh; overflow-y: auto; }

.oa-panel .oa-cat {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 7px 12px;
  background: var(--surface-low);
  border-bottom: 1px solid var(--outline);
  font-size: 12px;
  font-weight: 600;
  color: var(--on-surface-variant);
}
.oa-cat-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.oa-cat-count {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 9999px;
  background: var(--surface-container);
}

.oa-panel .oa-row {
  align-items: flex-start;
  padding: 7px 12px 7px 32px;
  border-bottom: 1px solid var(--surface-container);
  transition: background .1s;
}
.oa-row:hover { background: var(--surface-low); }
.oa-row:has(input:checked) { background: #fff8f3; }
.oa-row input { margin-top: 3px; }

.oa-method {
  flex-shrink: 0;
  width: 56px;
  padding: 2px 0;
  border-radius: 3px;
  text-align: center;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: var(--on-surface-variant);
}
.oa-method-get    { background: #006591; }
.oa-method-post   { background: #16a34a; }
.oa-method-put    { background: #f97316; }
.oa-method-patch  { background: #795900; }
.oa-method-delete { background: #ba1a1a; }

.oa-row-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.oa-path { font-family: var(--mono); font-size: 12.5px; word-break: break-all; }
.oa-summary { font-size: 12px; color: var(--on-surface-variant); }

.oa-status {
  padding: 32px 16px;
  text-align: center;
  font-size: 13px;
  color: var(--on-surface-variant);
}
.oa-status:empty { display: none; }
.oa-status.is-error { color: var(--primary); }

.oa-panel-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--outline);
  background: var(--surface-low);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--on-surface-variant);
}

@media (max-width: 900px) {
  .oa-columns { grid-template-columns: 1fr; }
  .oa-panel { position: static; }
}

/* ── Markdown 預覽 ───────────────────────────────────────────────────────── */
/* 頂部工具列：說明文字 + 檢視切換鈕 */
.md-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

/* Markdown 編輯/預覽框填滿容器高度（content-pane 已含 24px padding）；
   限桌面寬度，避免覆蓋上方 max-width:640px 的行動版單欄排版 */
@media (min-width: 641px) {
  /* 根容器鎖在視窗高度，整條 flex 鏈才有界線，內容才會在面板內捲而非撐長整頁。
     用 :has 只在 Markdown 工具生效，其他工具維持 min-height:100vh 可隨內容增長 */
  .app-shell:has(#mdShell) { height: 100vh; grid-template-rows: minmax(0, 1fr); }
  .content-pane:has(#mdShell)        { display: flex; flex-direction: column; min-height: 0; }
  .content-pane:has(#mdShell) > .tool { flex: 1; display: flex; flex-direction: column; min-height: 0; }
  /* grid 列高鎖在容器內（minmax 0），內容改在面板內捲動，整頁不再被撐長 */
  #mdShell { flex: 1; min-height: 240px; height: auto; grid-template-rows: minmax(0, 1fr); }
  /* grid 項目預設 min-height:auto 會被內容撐高，改 0 才能讓 output-wrap 內捲 */
  #mdShell > .json-panel { min-height: 0; }
}

/* 檢視切換：只顯示原始 / 只顯示預覽 */
.json-shell.md-view-left,
.json-shell.md-view-right { grid-template-columns: 1fr; }
.json-shell.md-view-left  .json-panel:last-child  { display: none; }
.json-shell.md-view-right .json-panel:first-child { display: none; }

.json-panel.md-drag {
  outline: 2px dashed var(--primary);
  outline-offset: -2px;
}

.md-preview {
  padding: 16px 20px;
  background: var(--surface);
  min-height: 100%;
  font-size: 14px;
  line-height: 1.7;
  color: var(--on-surface);
  word-wrap: break-word;
}

.md-preview > :first-child { margin-top: 0; }
.md-preview > :last-child { margin-bottom: 0; }

.md-preview h1, .md-preview h2, .md-preview h3,
.md-preview h4, .md-preview h5, .md-preview h6 {
  margin: 1.2em 0 0.5em;
  line-height: 1.3;
  font-weight: 700;
}
.md-preview h1 { font-size: 1.7em; border-bottom: 1px solid var(--outline); padding-bottom: 0.3em; }
.md-preview h2 { font-size: 1.4em; border-bottom: 1px solid var(--outline); padding-bottom: 0.25em; }
.md-preview h3 { font-size: 1.2em; }
.md-preview h4 { font-size: 1.05em; }
.md-preview h5, .md-preview h6 { font-size: 0.95em; color: var(--on-surface-variant); }

.md-preview p { margin: 0.7em 0; }

.md-preview a { color: var(--primary); text-decoration: none; }
.md-preview a:hover { text-decoration: underline; }

.md-preview ul, .md-preview ol { margin: 0.6em 0; padding-left: 1.6em; }
.md-preview li { margin: 0.25em 0; }
.md-preview li > ul, .md-preview li > ol { margin: 0.25em 0; }

.md-preview blockquote {
  margin: 0.8em 0;
  padding: 0.2em 1em;
  border-left: 3px solid var(--outline-strong);
  color: var(--on-surface-variant);
  background: var(--surface-low);
}

.md-preview code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-container);
  padding: 0.15em 0.4em;
  border-radius: 3px;
}

.md-preview pre {
  margin: 0.8em 0;
  padding: 12px 14px;
  background: var(--surface-low);
  border: 1px solid var(--outline);
  border-radius: 4px;
  overflow-x: auto;
}
.md-preview pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
  line-height: 1.5;
}

.md-preview hr {
  border: none;
  border-top: 1px solid var(--outline);
  margin: 1.5em 0;
}

.md-preview img { max-width: 100%; border-radius: 4px; }

.md-preview table {
  border-collapse: collapse;
  margin: 0.8em 0;
  font-size: 0.92em;
  width: 100%;
}
.md-preview th, .md-preview td {
  border: 1px solid var(--outline);
  padding: 6px 10px;
  text-align: left;
}
.md-preview th {
  background: var(--surface-container);
  font-weight: 600;
}
.md-preview del { color: var(--on-surface-variant); }

.md-preview li:has(> input[type="checkbox"]) { list-style: none; margin-left: -1.4em; }
.md-preview li > input[type="checkbox"] { margin-right: 0.5em; }

/* Mermaid 圖表 */
.md-mermaid { margin: 0.9em 0; text-align: center; overflow-x: auto; }
.md-mermaid svg { max-width: 100%; height: auto; }
.md-mermaid-error {
  text-align: left;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
}
.md-mermaid-error pre {
  margin: 6px 0 0;
  padding: 10px 12px;
  font-weight: 400;
  color: var(--on-surface);
  background: var(--surface-low);
  border: 1px solid var(--outline);
  border-radius: 4px;
  white-space: pre-wrap;
  overflow-x: auto;
}

/* KaTeX 數學公式 */
.md-math[data-display="1"] { margin: 0.9em 0; overflow-x: auto; }
.md-math-error { color: var(--primary); font-family: var(--mono); font-size: 0.88em; }

/* highlight.js：維持本工具的 pre 背景與內距（壓過主題注入的 padding/background）*/
.md-preview pre code.hljs { padding: 0; background: none; }

/* 目錄 (TOC) 下拉：目錄鈕在預覽標題列（高度已鎖定，標題列不會被捲走），
   下拉清單以面板為定位基準從右上角展開 */
.json-panel:has(.md-toc-pop) { position: relative; }
.md-toc-pop {
  position: absolute;
  top: 40px;                 /* 標題列高度之下 */
  right: 10px;
  z-index: 6;
  width: min(280px, 70vw);
  max-height: 60vh;
  overflow-y: auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--outline-strong);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}
.md-toc-item {
  padding: 4px 8px;
  font-size: 12px;
  color: var(--on-surface-variant);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.md-toc-item:hover { background: var(--surface-container); color: var(--on-surface); }
.md-toc-l2 { padding-left: 18px; }
.md-toc-l3 { padding-left: 30px; }
.md-toc-l4 { padding-left: 42px; }
/* 由目錄跳轉時，標題不要緊貼視窗頂端（留點空隙，避開浮動鈕）*/
.md-preview :is(h1, h2, h3, h4) { scroll-margin-top: 12px; }

/* ── URL Table ───────────────────────────────────────────────────────────── */
.url-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.url-table tr {
  border-bottom: 1px solid var(--outline);
}

.url-table tr:last-child {
  border-bottom: none;
}

.url-key {
  width: 110px;
  padding: 7px 10px 7px 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--on-surface-variant);
  white-space: nowrap;
  vertical-align: top;
}

.url-val {
  padding: 7px 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--on-surface);
  word-break: break-all;
}

.url-empty {
  padding: 7px 0;
  color: var(--on-surface-variant);
  font-size: 13px;
}

.url-copy-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.url-copy-row input {
  flex: 1;
  min-width: 0;
}

.url-copy-row .btn-ghost {
  flex-shrink: 0;
}

/* ── Image Editor ────────────────────────────────────────────────────────── */
.edit-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
  align-items: stretch;
}

.edit-controls {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.edit-controls-bottom {
  margin-top: auto;
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Tabs */
.edit-tabs {
  display: flex;
  border: 1px solid var(--outline-strong);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 14px;
}

.edit-tab, .wm-tab {
  flex: 1;
  margin: 0;
  border-radius: 0;
  border: none;
  border-right: 1px solid var(--outline-strong);
  background: var(--surface);
  color: var(--on-surface-variant);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 4px;
  cursor: pointer;
  transition: background 0.1s;
}

.edit-tab:last-child, .wm-tab:last-child { border-right: none; }

.edit-tab:hover, .wm-tab:hover {
  background: var(--surface-container);
  opacity: 1;
  filter: none;
  color: var(--on-surface);
}

.edit-tab.active, .wm-tab.active {
  background: var(--surface-container);
  color: var(--on-surface);
}

/* Panels */
.edit-panel {
  display: flex;
  flex-direction: column;
}

.edit-panel label { margin-top: 8px; }
.edit-panel .grid-2 { gap: 8px; }
.edit-panel .grid-2 label { margin-top: 4px; }
.edit-panel button { margin-top: 12px; }

/* Watermark position grid */
.wm-pos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin-top: 6px;
}

.wm-pos-btn {
  margin: 0;
  padding: 6px;
  font-size: 14px;
  font-weight: 400;
  background: var(--surface);
  color: var(--on-surface-variant);
  border: 1px solid var(--outline);
  border-radius: 3px;
  transition: background 0.1s;
}

.wm-pos-btn:hover {
  background: var(--surface-container);
  opacity: 1;
  filter: none;
}

.wm-pos-btn.active {
  background: #ffedd5;
  color: var(--primary);
  border-color: #fed7aa;
}

/* Operations row */
.edit-ops {
  display: flex;
  gap: 6px;
  margin-top: 14px;
}

.edit-ops .btn-ghost {
  flex: 1;
  text-align: center;
  margin-top: 0;
}

/* Canvas side */
.edit-canvas-wrap {
  border: 1px solid var(--outline);
  background: var(--surface-container);
  border-radius: 4px;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 300px;
  padding: 8px;
}

#editCanvas {
  display: block;
  max-width: 100%;
  cursor: crosshair;
  image-rendering: pixelated;
}

@media (max-width: 720px) {
  .edit-shell { grid-template-columns: 1fr; }
}

/* ── Mobile Bar ──────────────────────────────────────────────────────────── */
.mobile-bar {
  display: none;
}

.mobile-select {
  flex: 1;
  font-family: "Geist", sans-serif;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 10px;
  border: 1px solid var(--outline-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--on-surface);
  cursor: pointer;
  appearance: auto;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-shell { grid-template-columns: 170px 1fr; }
}

@media (max-width: 640px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: 100vh;
  }

  .side-nav { display: none; }

  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--outline);
    flex-shrink: 0;
  }

  /* 固定 top bar */
  .mobile-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 100;
    border-bottom: 1px solid var(--outline);
  }

  /* 固定 footer */
  .content-header {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 100;
    border-top: 1px solid var(--outline);
    border-bottom: none;
    padding: 10px 14px;
    justify-content: center;
    background: var(--surface);
  }

  /* content-pane 在兩個固定 bar 之間滾動 */
  .content-wrap { display: block; }
  .content-pane {
    padding: calc(50px + 14px) 14px calc(58px + 14px);
    min-height: 100vh;
  }

  /* 隱藏標題，只留按鈕 */
  .content-header-left { display: none; }

  /* 沒有任何按鈕時 footer 不顯示 */
  .content-header:not(:has(button)) { display: none; }

  /* 無 footer 時下方 padding 縮回 */
  .content-header:not(:has(button)) ~ * { padding-bottom: 14px; }

  /* 按鈕橫排填滿 */
  .header-actions { width: 100%; justify-content: center; gap: 12px; }
  .run-btn, .reset-btn { flex: 1; max-width: 160px; justify-content: center; }

  .grid-4, .grid-2 { grid-template-columns: 1fr; }
}

/* ── Regex 測試器 ─────────────────────────────────────────────────── */
.regex-shell {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.regex-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 10px;
  padding: 8px 12px;
}

.regex-engine-badge {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--on-surface-variant);
  background: var(--surface-container);
  border: 1px solid var(--outline);
  border-radius: 4px;
  padding: 1px 6px;
  cursor: default;
  flex-shrink: 0;
}

.regex-slash {
  font-family: var(--mono);
  font-size: 20px;
  color: var(--primary);
  user-select: none;
}

.regex-input-row input[type="text"] {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--mono);
  font-size: 15px;
  color: var(--on-surface);
  padding: 0;
}

.regex-flags {
  display: flex;
  gap: 16px;
  padding: 4px 2px;
}

.regex-flags label {
  display: flex;
  align-items: center;
  gap: 3px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--on-surface-variant);
  cursor: pointer;
  user-select: none;
}

.regex-error {
  font-size: 12px;
  color: #c0392b;
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* 高亮覆蓋層 */
.regex-test-wrap {
  position: relative;
  background: var(--surface-low);
  border: 1px solid var(--outline);
  border-radius: 10px;
  overflow: hidden;
}

.regex-test-wrap:focus-within {
  border-color: var(--primary);
}

.regex-highlight {
  position: absolute;
  inset: 0;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  overflow: auto;
  color: transparent;
  pointer-events: none;
  background: transparent;
  border: none;
  z-index: 0;
}

.regex-textarea {
  position: relative;
  width: 100%;
  min-height: 160px;
  resize: vertical;
  background: transparent;
  border: none;
  outline: none;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.6;
  color: var(--on-surface);
  caret-color: var(--on-surface);
  z-index: 1;
}

.regex-mark {
  background: #f97316;
  color: #fff;
  border-radius: 3px;
  padding: 0 1px;
}

.regex-result-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}

.regex-matches {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.regex-match-item {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--surface-low);
  border: 1px solid var(--outline);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}

.regex-match-idx {
  font-family: var(--mono);
  color: var(--on-surface-variant);
  font-size: 11px;
  min-width: 24px;
}

.regex-match-val {
  font-family: var(--mono);
  background: #fff3eb;
  border: 1px solid #f9731633;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--primary);
}

.regex-groups {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
  padding-top: 4px;
  border-top: 1px solid var(--outline);
}

.regex-group {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--on-surface-variant);
}

.regex-group code {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: 3px;
  padding: 0 4px;
  color: var(--on-surface);
}

/* ── Google 雲端硬碟 ─────────────────────────────────────────────────────── */
.gd-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.gd-bar select { width: auto; }
.gd-bar .btn-ghost { margin-top: 0; }
.gd-check { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.gd-check input { width: auto; }

.gd-status { margin: 10px 0; min-height: 1em; }
.gd-status-error { color: var(--primary); }

.gd-list { display: flex; flex-direction: column; gap: 8px; }
.gd-item {
  border: 1px solid var(--outline);
  border-radius: 4px;
  padding: 10px 12px;
  background: var(--surface);
}
.gd-item-main { display: flex; align-items: center; gap: 10px; }
.gd-icon { width: 16px; height: 16px; flex-shrink: 0; }
.gd-item-info { flex: 1; min-width: 0; }
.gd-name { font-size: 13px; font-weight: 600; color: var(--on-surface); text-decoration: none; word-break: break-all; }
.gd-name:hover { color: var(--primary); text-decoration: underline; }
.gd-meta { font-family: var(--mono); font-size: 11px; color: var(--on-surface-variant); margin-top: 2px; word-break: break-all; }
.gd-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.gd-actions .btn-ghost { margin-top: 0; }
.gd-preview { display: block; max-width: 100%; max-height: 360px; margin-top: 10px; border-radius: 4px; }

@media (max-width: 640px) {
  .gd-item-main { flex-wrap: wrap; }
  .gd-actions { width: 100%; justify-content: flex-end; }
}
