:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --secondary: #8e8e93;
  --separator: rgba(60, 60, 67, 0.12);
  --blue: #007aff;
  --red: #ff3b30;
  --green: #34c759;
  --orange: #ff9500;
  --fill: #f2f2f7;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tab-h: 56px;
  --nav-body-h: 74px;
  --nav-h: calc(var(--safe-t) + var(--nav-body-h));
  --btn-h: 40px;
  --btn-pad-x: 14px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Helvetica Neue", sans-serif;
  --brand: #E60012;
}

html[data-theme="dark"] {
  --bg: #000000;
  --card: #1c1c1e;
  --text: #f5f5f7;
  --secondary: #8e8e93;
  --separator: rgba(84, 84, 88, 0.65);
  --fill: #2c2c2e;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.35;
  min-height: 100%;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
/* Author `display:` rules beat UA [hidden]; force hide for overlays. */
[hidden] { display: none !important; }
#app {
  min-height: 100dvh;
  padding-bottom: calc(var(--tab-h) + var(--safe-b) + 12px);
}

.splash {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  transition: opacity .35s ease;
}
.splash.hide { opacity: 0; pointer-events: none; }
.splash-logo {
  width: 88px;
  height: 88px;
  border-radius: 22px;
  box-shadow: 0 8px 28px rgba(230, 0, 18, 0.18);
}
.splash-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  min-height: var(--nav-h);
  padding: calc(var(--safe-t) + 8px) 16px 12px;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 0.5px solid var(--separator);
}
.nav-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-logo {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  flex: 0 0 auto;
  align-self: center;
  margin-top: -3px;
}
.nav-text { min-width: 0; flex: 1; }
.nav-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-sub {
  margin-top: 2px;
  font-size: 13px;
  color: var(--secondary);
  min-height: 1.2em;
}
.nav-sub:empty {
  display: none;
  min-height: 0;
  margin: 0;
}
.nav-page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.nav-page-actions[hidden] { display: none; }

.nav-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: var(--fill);
  color: var(--blue);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  cursor: pointer;
}
.nav-project {
  flex: 0 1 auto;
  max-width: min(38vw, 140px);
  min-width: 0;
  height: 32px;
  padding: 0 28px 0 10px;
  border: 0;
  border-radius: 8px;
  background: var(--fill);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.nav-project[hidden] { display: none; }
.nav-btn[hidden] { display: none; }
.nav-btn svg { display: block; flex: 0 0 auto; }
.nav-btn:active { opacity: 0.82; }
.nav-btn:disabled { opacity: 0.55; cursor: default; }
.nav-folder-add {
  font-size: 24px;
  line-height: 1;
}
.nav-folder-add:not([hidden]) { margin-right: auto; }
.nav-page-actions .nav-btn {
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}
.nav-page-actions .nav-page-folder {
  max-width: min(44vw, 180px);
  min-width: 92px;
}
.nav-cognitive-actions {
  flex: 1 1 auto;
  min-width: 0;
  justify-content: space-between;
  gap: clamp(10px, 3vw, 18px);
}
.nav-cognitive-actions .nav-page-folder {
  flex: 1 1 auto;
  max-width: none;
  min-width: 96px;
}
.nav-back {
  font-size: 30px;
  font-weight: 400;
  line-height: 1;
  padding-bottom: 3px;
}
.nav-refresh .refresh-icon {
  width: 20px;
  height: 20px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.nav-refresh.refreshing .refresh-icon {
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

main {
  padding: calc(var(--nav-h) + 12px) 16px 24px;
  overscroll-behavior-y: contain;
}

.group {
  background: var(--card);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
  box-shadow: 0 0.5px 0 var(--separator);
}
.group-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 0 4px 8px;
}
.settings-section {
  margin-bottom: 16px;
}
.settings-section > summary {
  list-style: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 0 4px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.settings-section > summary::-webkit-details-marker { display: none; }
.settings-section > summary::marker { content: ""; }
.settings-section > summary::after {
  content: "›";
  font-size: 18px;
  line-height: 1;
  color: var(--secondary);
  transform: rotate(0deg);
  transition: transform 0.18s ease;
}
.settings-section[open] > summary::after {
  transform: rotate(90deg);
}
.settings-section > .group {
  margin-bottom: 0;
}
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--separator);
  background: var(--card);
}
.row:last-child { border-bottom: 0; }
.row-body { flex: 1; min-width: 0; }
.row-title {
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-meta {
  margin-top: 2px;
  font-size: 13px;
  color: var(--secondary);
}
.chip {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 10px;
  line-height: 1.4;
  background: rgba(148, 163, 184, 0.18);
  color: var(--secondary);
}
.todo-row { cursor: pointer; }
.todo-row.done .row-title {
  color: var(--secondary);
  text-decoration: line-through;
}
.chev { color: var(--secondary); font-size: 18px; }

.field {
  padding: 10px 16px;
  border-bottom: 0.5px solid var(--separator);
}
.field:last-child { border-bottom: 0; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--secondary);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  padding: 0;
  font-size: 16px;
}
.field textarea { min-height: 88px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 10px;
  height: var(--btn-h);
  min-height: var(--btn-h);
  max-height: var(--btn-h);
  padding: 0 var(--btn-pad-x);
  font-weight: 600;
  font-size: 15px;
  line-height: 1.2;
  box-sizing: border-box;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  transition: opacity 0.15s ease;
}
.btn:active:not([disabled]) { opacity: 0.85; transform: none; }
.btn.secondary {
  background: var(--fill);
  color: var(--blue);
}
.btn.danger {
  background: color-mix(in srgb, var(--red) 12%, white);
  color: var(--red);
}
.btn.ghost {
  background: transparent;
  color: var(--blue);
  width: auto;
  padding: 0 10px;
}
.btn.ghost.danger-link,
.danger-link { color: var(--red) !important; }
.btn-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
}
.btn-row.wrap { flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 0; }
/* Keep every action chip the same height as primary buttons. */
.pill-actions .btn,
.path-copy,
.modal-actions .btn,
.selection-bar .btn,
.md-link-copy {
  height: var(--btn-h);
  min-height: var(--btn-h);
  max-height: var(--btn-h);
  padding: 0 12px;
  font-size: 15px;
  line-height: 1.2;
  box-sizing: border-box;
}
.pill-actions .btn {
  width: auto;
  border-radius: 999px;
}
.path-copy {
  width: auto;
  border-radius: 999px;
  font-size: 13px;
}
.modal-actions .btn {
  width: auto;
  min-width: 88px;
}
.selection-bar .btn {
  width: auto;
  min-width: 140px;
}
.md-link-copy {
  width: auto;
  font-size: 12px;
  padding: 0 8px;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--fill);
  color: var(--secondary);
}
.badge.ok { background: #e8f8ee; color: var(--green); }
.badge.run { background: #e8f1ff; color: var(--blue); }
.badge.warn { background: #fff4e5; color: var(--orange); }
.badge.err { background: #ffecec; color: var(--red); }

.banner {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
}
.banner.err { background: #ffecec; color: var(--red); }
.banner.ok { background: #e8f8ee; color: #1f7a3a; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + var(--safe-b) + 16px);
  transform: translateX(-50%) translateY(12px);
  width: max-content;
  max-width: min(88vw, 420px);
  padding: 11px 14px 11px 13px;
  border: 0.5px solid var(--separator);
  border-left: 3px solid var(--blue);
  border-radius: 14px;
  background: color-mix(in srgb, var(--card) 96%, transparent);
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
  z-index: 70;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  box-shadow: 0 14px 34px rgba(0,0,0,0.18);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--orange); }
.toast-title {
  font-weight: 650;
  letter-spacing: -0.01em;
}
.toast-detail {
  margin-top: 3px;
  color: var(--secondary);
  font-size: 12px;
  line-height: 1.35;
  word-break: break-word;
}
.btn[disabled] { opacity: 0.55; }

.md {
  padding: 16px;
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font);
}

.markdown-preview {
  padding: 16px;
  font-size: 15px;
  line-height: 1.7;
  color: var(--text);
  word-break: break-word;
}
.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4 {
  margin: 1.1em 0 0.45em;
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
}
.markdown-preview h1 { font-size: 1.45em; }
.markdown-preview h2 { font-size: 1.25em; }
.markdown-preview h3 { font-size: 1.1em; }
.markdown-preview p { margin: 0.65em 0; }
.markdown-preview ul,
.markdown-preview ol { margin: 0.5em 0; padding-left: 1.4em; }
.markdown-preview li { margin: 0.25em 0; }
.markdown-preview blockquote {
  margin: 0.8em 0;
  padding: 0.2em 0 0.2em 0.9em;
  border-left: 3px solid var(--separator);
  color: var(--secondary);
}
.markdown-preview pre {
  background: #0a0e1a;
  border-radius: 10px;
  padding: 12px;
  overflow: auto;
  margin: 0.8em 0;
}
.markdown-preview code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
}
.markdown-preview :not(pre) > code {
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: 4px;
}
.markdown-preview pre code {
  color: #e5e5ea;
  background: transparent;
  padding: 0;
}
.markdown-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.8em 0;
  font-size: 0.92em;
}
.markdown-preview th,
.markdown-preview td {
  border: 0.5px solid var(--separator);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.markdown-preview th { background: rgba(0,0,0,0.03); }
.markdown-preview a {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.markdown-preview .md-link-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 8px;
  align-items: start;
  margin: 0.55em 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(0, 122, 255, 0.06);
  border: 0.5px solid rgba(0, 122, 255, 0.14);
}
.markdown-preview .md-link-row > a {
  grid-column: 1 / -1;
  font-weight: 600;
}
.markdown-preview .md-link-url {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78em;
  line-height: 1.45;
  color: var(--secondary);
  word-break: break-all;
  user-select: text;
  -webkit-user-select: text;
}
.markdown-preview .md-link-copy {
  flex-shrink: 0;
  border-radius: 999px;
}
.markdown-preview img { max-width: 100%; height: auto; border-radius: 8px; }
.markdown-preview .doc-img { display: block; margin: 8px 0; }
.markdown-preview .doc-img-missing {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--fill);
  color: var(--secondary);
  font-size: 13px;
}
.markdown-preview hr {
  border: 0;
  border-top: 0.5px solid var(--separator);
  margin: 1.2em 0;
}

.log {
  margin: 0;
  padding: 12px 14px;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #1c1c1e;
  color: #e5e5ea;
  max-height: 55vh;
  overflow: auto;
  border-radius: 0 0 var(--radius) var(--radius);
}
.log-head {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--secondary);
  border-bottom: 0.5px solid var(--separator);
}
.log-process {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 60vh;
  overflow: auto;
}
.log-card {
  border: 0.5px solid var(--separator);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--card);
}
.log-card .lc-label {
  font-size: 12px;
  color: var(--secondary);
  margin-bottom: 6px;
}
.log-card .lc-body {
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.log-card.tool { background: var(--fill); }
.log-card.result.ok { border-color: #34c759; background: color-mix(in srgb, #34c759 12%, var(--card)); }
.log-card.result.err { border-color: #ff3b30; background: color-mix(in srgb, #ff3b30 12%, var(--card)); }
.log-line {
  display: grid;
  grid-template-columns: 18px 64px 1fr;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 0.5px solid rgba(255,255,255,0.06);
  font-size: 11px;
  line-height: 1.4;
}
.log-line .icon { color: #8e8e93; }
.log-line .label { color: #64d2ff; }
.log-line .body { color: #e5e5ea; white-space: pre-wrap; word-break: break-word; }
.log-mode {
  display: flex;
  gap: 8px;
  padding: 0 0 10px;
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  font-size: 16px;
}
.check input { width: 18px; height: 18px; accent-color: var(--blue); }

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tab-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  flex-wrap: nowrap;
  z-index: 60;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 0.5px solid var(--separator);
}
.tabbar button {
  position: relative;
  border: 0;
  background: transparent;
  color: var(--secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  font-weight: 500;
  padding: 6px 0 4px;
  flex: 1 1 0;
  min-width: 0;
}
.tabbar button.active { color: var(--blue); }
.tabbar button.is-active-work { color: var(--blue); }
.tabbar .ti {
  width: 22px;
  height: 22px;
  display: block;
  fill: currentColor;
}
.tabbar .ti path[fill="none"] { fill: none; }
.tabbar button.is-active-work .ti {
  animation: tab-work-pulse 1.55s cubic-bezier(.45, 0, .55, 1) infinite;
  filter: drop-shadow(0 0 4px color-mix(in srgb, var(--blue) 58%, transparent));
  transform-origin: 50% 50%;
}
.tabbar button.is-active-work::before {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  margin-top: -16px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--blue) 18%, transparent);
  opacity: 0;
  pointer-events: none;
  animation: tab-work-halo 1.55s ease-out infinite;
}
.tabbar button[data-tab="loops"].is-active-work { color: #63b3ff; }
.tabbar button[data-tab="graph"].is-active-work { color: #0a9eb0; }
.is-page-hidden .tabbar button.is-active-work .ti,
.is-page-hidden .tabbar button.is-active-work::before {
  animation-play-state: paused;
}
@keyframes tab-work-pulse {
  0%, 100% { opacity: .62; transform: scale(.9); }
  48% { opacity: 1; transform: scale(1.09); }
}
@keyframes tab-work-halo {
  0% { opacity: 0; transform: scale(.55); }
  42% { opacity: .72; }
  100% { opacity: 0; transform: scale(1.25); }
}
@media (prefers-reduced-motion: reduce) {
  .tabbar button.is-active-work .ti,
  .tabbar button.is-active-work::before {
    animation: none;
  }
}

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--secondary);
  font-size: 14px;
}

/* 绑定表单：输入下方实时显示解析出的完整入口地址。 */
.url-preview {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--secondary);
  word-break: break-all;
  line-height: 1.5;
}

.stack { display: flex; flex-direction: column; gap: 10px; }
.todo-edit-intro,
.form-hint {
  color: var(--secondary);
  font-size: 14px;
  line-height: 1.45;
  padding: 0 4px 12px;
}
.form-hint { margin: -4px 0 14px; }
.pill-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }

.bind-shell { display: grid; gap: 0; }
.bind-hero {
  margin: 0 0 14px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--brand) 10%, var(--card)) 0%, var(--card) 58%);
  border: 0.5px solid var(--separator);
}
.bind-hero-kicker {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--brand);
  margin-bottom: 4px;
}
.bind-hero-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}
.bind-hero-copy {
  margin: 8px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--secondary);
}
.bind-panel .field { padding-top: 12px; padding-bottom: 12px; }
.bind-select,
.bind-panel .field input,
.bind-panel .field select,
.bind-panel .field textarea {
  width: 100%;
  border: 0;
  outline: none;
  background: var(--fill);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 16px;
}
.bind-panel .field textarea { min-height: 88px; resize: vertical; }
.bind-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
.bind-hint,
.bind-desc,
.bind-warn {
  margin: 0;
  padding: 0 16px 12px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--secondary);
}
.bind-warn { color: var(--orange); }
.bind-meta { padding: 0 16px 12px; display: grid; gap: 8px; }
.bind-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.bind-meta-id {
  font-size: 12px;
  color: var(--secondary);
}
.bind-meta-id code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}
.bind-actions {
  margin-top: 4px;
  padding-bottom: 8px;
}

.file-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px dashed var(--separator);
  border-radius: var(--radius);
  background: var(--card);
  cursor: pointer;
  transition: border-color 0.15s ease, opacity 0.15s ease;
}
.file-picker:active { opacity: 0.85; }
.file-picker.has-file { border-style: solid; border-color: var(--blue); }
.file-picker-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}
.file-picker-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  color: var(--secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-picker.has-file .file-picker-name { color: var(--text); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: end center;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
}
.modal-sheet {
  position: relative;
  width: min(100%, 520px);
  max-height: min(82vh, 720px);
  overflow: auto;
  border-radius: 18px;
  background: var(--bg);
  border: 0.5px solid var(--separator);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
  padding: 18px 16px 14px;
}
.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}
.modal-body { display: grid; gap: 12px; }
.modal-copy {
  margin: 0;
  color: var(--secondary);
  font-size: 14px;
  line-height: 1.5;
}
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}

.doc-row-wrap {
  position: relative;
  border-bottom: 0.5px solid var(--separator);
  background: var(--card);
}
.doc-row-wrap:last-child { border-bottom: 0; }
.doc-row-wrap .doc-row {
  border-bottom: 0;
}
.doc-row {
  align-items: center;
  gap: 0;
  padding: 0;
  position: relative;
}
.doc-menu-anchor {
  position: relative;
  flex: 0 0 auto;
}
.doc-menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--secondary);
  padding: 0;
  cursor: pointer;
  border-radius: 10px;
}
.doc-menu-btn:active {
  background: var(--fill);
  color: var(--text);
}
.doc-menu-icon {
  width: 18px;
  height: 18px;
  display: block;
  fill: currentColor;
}
.doc-row-main {
  flex: 1;
  min-width: 0;
  padding: 12px 4px 12px 0;
  cursor: pointer;
}
.doc-row-title {
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-open-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  flex: 0 0 auto;
}
.doc-open-btn .chev {
  font-size: 20px;
}
.doc-menu-popover {
  position: absolute;
  top: calc(100% - 4px);
  left: 8px;
  z-index: 80;
  min-width: 168px;
  padding: 6px 0;
  border-radius: 12px;
  background: var(--card);
  border: 0.5px solid var(--separator);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.14);
}
.doc-menu-item {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 11px 16px;
  font-size: 16px;
  color: var(--text);
  cursor: pointer;
}
.doc-menu-item:active {
  background: var(--fill);
}
.doc-menu-item.danger {
  color: var(--red);
}

.folder-row-wrap {
  position: relative;
  border-bottom: 0.5px solid var(--separator);
  background: var(--card);
}
.folder-row-wrap:last-child { border-bottom: 0; }
.folder-row {
  align-items: center;
  gap: 0;
  padding: 0;
}
.folder-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 4px 12px 0;
  cursor: pointer;
}
.folder-icon {
  flex: 0 0 auto;
  font-size: 18px;
  line-height: 1;
}
.folder-icon-svg {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  display: block;
  fill: color-mix(in srgb, var(--blue) 72%, var(--secondary));
}
.folder-row-ungrouped .folder-icon-svg {
  fill: color-mix(in srgb, var(--secondary) 85%, var(--blue));
}
.folder-row-title {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.folder-count {
  flex: 0 0 auto;
  font-size: 13px;
  color: var(--secondary);
  min-width: 1.5em;
  text-align: right;
}
.docs-folder-actions {
  padding: 0 16px 8px;
}
.folder-empty {
  padding: 10px 16px 12px 16px;
  font-size: 13px;
  color: var(--secondary);
  background: var(--card);
  border-bottom: 0.5px solid var(--separator);
}
.folder-depth-1 .folder-row,
.folder-depth-1 .doc-row { padding-left: 18px; }
.folder-depth-2 .folder-row,
.folder-depth-2 .doc-row { padding-left: 36px; }
.folder-depth-3 .folder-row,
.folder-depth-3 .doc-row { padding-left: 54px; }
.folder-depth-4 .folder-row,
.folder-depth-4 .doc-row { padding-left: 72px; }
.folder-empty.folder-depth-1 { padding-left: 34px; }
.folder-empty.folder-depth-2 { padding-left: 52px; }
.folder-empty.folder-depth-3 { padding-left: 70px; }
.folder-empty.folder-depth-4 { padding-left: 88px; }
.folder-pick-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 50vh;
  overflow: auto;
}
.folder-pick-item {
  border-radius: 8px;
}

.ingest-result { padding-top: 12px; }
.path-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: start;
  padding: 10px 0;
  border-top: 0.5px solid var(--separator);
}
.path-row:first-of-type { border-top: 0; padding-top: 4px; }
.path-label {
  font-size: 12px;
  color: var(--secondary);
  white-space: nowrap;
}
.path-value {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.45;
  word-break: break-all;
  user-select: text;
  -webkit-user-select: text;
}

.selection-bar {
  position: sticky;
  bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border: 0.5px solid var(--separator);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  justify-content: center;
}

.run-check {
  display: flex;
  align-items: flex-start;
  padding: 14px 0 0 16px;
}
.run-check input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.run-row .run-title-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.run-title {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.run-meta-line {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.run-id-meta {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.loop-row {
  border-bottom: 0.5px solid var(--separator);
}
.loop-row:last-child { border-bottom: 0; }
.loop-log-panel {
  padding: 0 16px 12px;
  background: var(--card);
}
.loop-log-list {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--fill);
}
.loop-log-line {
  display: grid;
  grid-template-columns: 92px 72px 1fr;
  gap: 8px;
  font-size: 12px;
  color: var(--secondary);
  align-items: start;
}
.loop-log-event {
  color: var(--text);
  font-weight: 600;
}
.loop-log-detail {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.loop-log-empty {
  padding: 8px 0 4px;
  font-size: 13px;
  color: var(--secondary);
}

.graph-log-group { padding: 4px 0; }
.graph-log-block + .graph-log-block {
  border-top: 0.5px solid var(--separator);
}
.graph-log-toggle {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  border: 0;
  background: transparent;
  padding: 12px 16px;
  text-align: left;
  cursor: pointer;
}
.graph-log-title {
  font-weight: 650;
  font-size: 15px;
  color: var(--text);
}
.graph-log-hint {
  font-size: 12px;
  color: var(--secondary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.graph-log-panel {
  padding: 0 12px 12px;
}
.graph-log-pre {
  margin: 0;
  max-height: 280px;
  overflow: auto;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--fill);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

/* ── Multi-server management ─────────────────────────────────────────
   One phone can bind several zlnewma instances (home Mac / office PC).
   The nav chip shows the active machine; server lists appear on the
   home page, the pairing page, the switcher sheet, and settings. */
.nav-server {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 1 auto;
  max-width: min(38vw, 150px);
  min-width: 0;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: var(--fill);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
}
.nav-server[hidden] { display: none; }
.nav-server:active { opacity: 0.82; }
.nav-server.conn-down {
  background: color-mix(in srgb, var(--red) 12%, var(--fill));
}
.nav-server-name {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-server-caret {
  color: var(--secondary);
  font-size: 11px;
  flex: 0 0 auto;
}

.server-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--secondary);
  flex: 0 0 auto;
}
.server-dot.on { background: var(--green); }
.server-dot.off { background: var(--red); }

.server-list { display: grid; }
.server-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  border-bottom: 0.5px solid var(--separator);
  background: var(--card);
  color: var(--text);
  padding: 12px 16px;
  text-align: left;
  cursor: pointer;
}
/* 当前活跃服务器：蓝色描边卡片 + 淡蓝底，与普通行一眼区分。 */
.server-row[data-active="1"] {
  border: 1.5px solid var(--blue);
  border-radius: 12px;
  background: color-mix(in srgb, var(--blue) 7%, var(--card));
  margin: 6px 8px;
  padding: 12px 14px;
}
.server-row[data-active="1"] .server-row-title {
  color: var(--blue);
  font-weight: 600;
}
.server-manage-row[data-active="1"] {
  border: 1.5px solid var(--blue);
  border-radius: 12px;
  background: color-mix(in srgb, var(--blue) 7%, var(--card));
}
.server-manage-row[data-active="1"] .server-row-title {
  color: var(--blue);
  font-weight: 600;
}
.server-row:last-child { border-bottom: 0; }
.server-row:active { background: var(--fill); }
.server-row-body {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}
.server-row-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.server-row-meta {
  font-size: 12px;
  color: var(--secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.server-manage-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--separator);
  background: var(--card);
}
.server-manage-info {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 2px;
}
.server-manage-row .btn-row {
  padding: 0;
  flex: 0 1 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}
.server-manage-row .btn {
  padding: 0 10px;
  font-size: 13px;
}
@media (max-width: 480px) {
  .server-manage-row { flex-direction: column; align-items: stretch; }
  .server-manage-row .btn-row { justify-content: flex-end; }
}

/* ── Tablet / wide-screen layout ───────────────────────────────────────
   The phone layout stretches edge-to-edge; on a tablet that makes text
   lines unreadably long and spreads the tab bar into huge empty slots.
   Center a readable content column and cluster the tabs instead. The
   column is fluid (viewport minus margins, capped) so landscape tablets
   actually use their width instead of leaving ~40% empty. */
@media (min-width: 700px) {
  :root { --content-w: min(1080px, calc(100vw - 56px)); }
  .nav-row {
    max-width: var(--content-w);
    margin-inline: auto;
  }
  /* main keeps its 16px side padding inside the box, so add it back. */
  main {
    max-width: calc(var(--content-w) + 32px);
    margin-inline: auto;
  }
  .nav-project { max-width: 260px; }
  .nav-server { max-width: 260px; }
  .tabbar {
    justify-content: center;
    gap: 8px;
  }
  .tabbar button { flex: 0 1 104px; }
  .modal-sheet { width: min(92vw, 640px); }
}
