/* JSON → Dart：与 ztools-base 配套 */
/* ===== CSS 变量 ===== */

:root {
  --json-dart-error: #b91c1c;
  --json-dart-error-bg: #fef2f2;
  --json-dart-copied-bg: #f0fdf4;
  --json-dart-copied-border: #22c55e;
  --json-dart-code-font: ui-monospace, "Cascadia Code", "SFMono-Regular", Menlo, Consolas, monospace;
}

/* ===== 主布局 ===== */

.json-dart-main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

.json-dart-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: row;
  width: 100%;
  border: 1px solid var(--zt-border);
  border-radius: var(--zt-radius);
  background: var(--zt-surface);
  box-shadow: 0 1px 4px rgba(28, 36, 51, 0.07);
  overflow: hidden;
}

/* ===== 左侧（JSON 输入区） ===== */

/* 错误提示隐藏状态（替代内联 style） */
.json-dart-error--hidden {
  display: none !important;
}

.zbody_left {
  flex: 1 1 50%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--zt-border);
}

.zbody_left form {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* 左侧顶栏标签 */
.left_top-label {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 600;
  color: var(--zt-text);
  white-space: nowrap;
  user-select: none;
}

.left_top,
.right_top {
  flex: 0 0 auto;
  height: 48px;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  align-items: center;
  gap: 8px 12px;
  padding: 0 12px;
  background: var(--zt-surface-muted);
  border-bottom: 1px solid var(--zt-border);
}

.json-dart-input {
  flex: 1 1 10rem;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  font-size: 14px;
  color: var(--zt-text);
  background: var(--zt-surface);
  border: 1px solid var(--zt-border);
  border-radius: var(--zt-radius-sm);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.json-dart-input:focus {
  border-color: var(--zt-accent);
  box-shadow: 0 0 0 3px var(--zt-focus-ring);
}

.json-dart-input::placeholder {
  color: var(--zt-text-muted);
  opacity: 0.75;
}

.json-dart-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 13px;
  color: var(--zt-text);
  user-select: none;
  cursor: pointer;
  white-space: nowrap;
}

.json-dart-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--zt-accent);
  cursor: pointer;
}

.left_bottom {
  flex: 1 1 auto;
  min-height: 200px;
  min-width: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* 左侧编辑区头部 */
.left_bottom-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px 3px;
  gap: 8px;
  background: var(--zt-surface);
  border-bottom: 1px solid var(--zt-border);
}

.left_bottom-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--zt-text);
  user-select: none;
}

.left_bottom-hint {
  font-size: 11px;
  color: var(--zt-text-muted);
  user-select: none;
}

/* 左侧：可视区域为原生 textarea */
.json-dart-left-editor {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

.json-dart-ta {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 200px;
  margin: 0;
  padding: 14px 16px;
  font-family: var(--json-dart-code-font);
  font-size: 13px;
  line-height: 1.6;
  color: var(--zt-text);
  background: var(--zt-surface);
  border: none;
  outline: none;
  resize: none;
  -webkit-overflow-scrolling: touch;
  tab-size: 2;
}

.json-dart-ta::placeholder {
  color: var(--zt-text-muted);
  opacity: 0.85;
}

.json-dart-ta:focus {
  box-shadow: inset 0 0 0 1px var(--zt-accent);
}

/* ===== 右侧（Dart 预览区） ===== */

.zbody_right {
  flex: 1 1 50%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.right_top {
  justify-content: flex-end;
}

/* 复制按钮：与 shell 中 .zbtn 默认（绿色渐变）解耦 */
.json-dart-main .zbtn.zbtn--secondary {
  background: var(--zt-surface);
  background-image: none;
  color: var(--zt-text);
  border: 1px solid var(--zt-border-strong);
  box-shadow: none;
  filter: none;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.json-dart-main .zbtn.zbtn--secondary:hover:not(:disabled) {
  background: var(--zt-surface-muted);
  background-image: none;
  border-color: var(--zt-accent);
  color: var(--zt-text);
  filter: none;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.json-dart-main .zbtn.zbtn--secondary:active:not(:disabled) {
  background: #edf0f4;
  background-image: none;
  border-color: var(--zt-accent);
  color: var(--zt-text);
  filter: none;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08);
  transform: none;
}

.json-dart-main .zbtn.zbtn--secondary:focus-visible:not(:disabled) {
  background: var(--zt-surface-muted);
  background-image: none;
  color: var(--zt-text);
  filter: none;
  outline: 2px solid var(--zt-focus-ring);
  outline-offset: 2px;
}

.json-dart-main .zbtn.zbtn--secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background: var(--zt-surface);
  background-image: none;
  color: var(--zt-text-muted);
  filter: none;
}

/* 复制成功反馈 */
.json-dart-main .zbtn.zbtn--secondary.is-copied {
  background: var(--json-dart-copied-bg);
  border-color: var(--json-dart-copied-border);
  color: var(--zt-accent-active);
  pointer-events: none;
}

.right_bottom {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--zt-surface);
  padding: 12px 14px;
  position: relative;
}

.json-dart-error {
  display: block;
  margin: 0 0 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--json-dart-error);
  background: var(--json-dart-error-bg);
  border: 1px solid rgba(185, 28, 28, 0.2);
  border-radius: var(--zt-radius-sm);
}

.json-dart-pre {
  margin: 0;
  padding: 0;
  background: transparent;
  font-size: 13px;
  line-height: 1.5;
}

.json-dart-pre code {
  display: block;
  min-height: 2em;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
}

/* 隐藏的剪贴板辅助文本框 */
.json-dart-clipboard-helper {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  resize: none;
}

/* ===== highlight.js 配色 ===== */

.hljs {
  display: block;
  overflow-x: auto;
  padding: 14px 16px;
  color: var(--zt-text);
  background: var(--zt-surface-muted);
  border: 1px solid var(--zt-border);
  border-radius: var(--zt-radius-sm);
  font-family: var(--json-dart-code-font);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
}

.hljs-comment,
.hljs-quote {
  color: var(--zt-text-muted);
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag {
  color: #15803d;
  font-weight: 600;
}

.hljs-subst {
  color: #15803d;
  font-weight: normal;
}

.hljs-number,
.hljs-literal,
.hljs-variable,
.hljs-template-variable,
.hljs-tag .hljs-attr {
  color: #0d9488;
}

.hljs-string,
.hljs-doctag {
  color: #b45309;
}

.hljs-title,
.hljs-section,
.hljs-selector-id {
  color: #b91c1c;
  font-weight: bold;
}

.hljs-type,
.hljs-class .hljs-title {
  color: #1d4ed8;
  font-weight: bold;
}

.hljs-tag,
.hljs-name,
.hljs-attribute {
  color: #4338ca;
  font-weight: normal;
}

.hljs-regexp,
.hljs-link {
  color: #15803d;
}

.hljs-symbol,
.hljs-bullet {
  color: #a21caf;
}

.hljs-built_in,
.hljs-builtin-name {
  color: #0369a1;
}

.hljs-meta {
  color: var(--zt-text-muted);
  font-weight: bold;
}

.hljs-deletion {
  background: #fee2e2;
}

.hljs-addition {
  background: #dcfce7;
}

/* ===== 顶栏操作按钮 ===== */

.ztools-page-header__actions .zbtn {
  text-decoration: none;
  color: #fff;
}

.ztools-page-header__actions .zbtn:hover,
.ztools-page-header__actions .zbtn:focus-visible {
  color: #fff;
}

.ztools-page-header__actions .zbtn:focus-visible {
  outline: 2px solid var(--zt-focus-ring);
  outline-offset: 2px;
}

/* ===== 滚动条（覆盖 ztools-base 全局灰色，与本工具绿色主题一致） ===== */

.json-dart-main ::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.json-dart-main ::-webkit-scrollbar-thumb {
  border-radius: var(--zt-radius-sm);
  background: rgba(34, 197, 94, 0.4);
}

.json-dart-main ::-webkit-scrollbar-thumb:hover {
  background: var(--zt-accent);
}

.json-dart-main ::-webkit-scrollbar-track {
  background: var(--zt-surface-muted);
}

/* ===== 黑暗模式 ===== */

@media (prefers-color-scheme: dark) {
  :root {
    --json-dart-error: #f87171;
    --json-dart-error-bg: rgba(248, 113, 113, 0.1);
    --json-dart-copied-bg: rgba(34, 197, 94, 0.12);
    --json-dart-copied-border: #22c55e;
  }

  .json-dart-main .zbtn.zbtn--secondary:active:not(:disabled) {
    background: #1e293b;
  }

  .json-dart-error {
    border-color: rgba(248, 113, 113, 0.25);
  }

  .hljs-keyword,
  .hljs-selector-tag {
    color: #4ade80;
  }

  .hljs-subst {
    color: #4ade80;
  }

  .hljs-number,
  .hljs-literal,
  .hljs-variable,
  .hljs-template-variable,
  .hljs-tag .hljs-attr {
    color: #2dd4bf;
  }

  .hljs-string,
  .hljs-doctag {
    color: #fb923c;
  }

  .hljs-title,
  .hljs-section,
  .hljs-selector-id {
    color: #fca5a5;
  }

  .hljs-type,
  .hljs-class .hljs-title {
    color: #93c5fd;
  }

  .hljs-tag,
  .hljs-name,
  .hljs-attribute {
    color: #a5b4fc;
  }

  .hljs-regexp,
  .hljs-link {
    color: #4ade80;
  }

  .hljs-symbol,
  .hljs-bullet {
    color: #e879f9;
  }

  .hljs-built_in,
  .hljs-builtin-name {
    color: #38bdf8;
  }

  .hljs-deletion {
    background: rgba(248, 113, 113, 0.15);
  }

  .hljs-addition {
    background: rgba(74, 222, 128, 0.15);
  }
}

/* ===== 响应式 ===== */

@media (max-width: 900px) {
  .json-dart-body {
    flex-direction: column;
  }

  .zbody_left {
    flex: 1 1 45vh;
    min-height: 280px;
    border-right: none;
    border-bottom: 1px solid var(--zt-border);
  }

  .zbody_right {
    flex: 1 1 40vh;
    min-height: 220px;
  }

  .left_top {
    justify-content: flex-start;
  }

  .json-dart-ta {
    padding: 12px 14px;
  }

  .hljs {
    padding: 12px 14px;
  }
}

@media (max-width: 480px) {
  .json-dart-main {
    margin: 0;
  }

  .ztools-page-main {
    padding: 10px 12px 16px;
  }

  .left_top,
  .right_top {
    padding: 6px 10px;
    gap: 6px 8px;
  }

  .json-dart-input {
    font-size: 13px;
    height: 34px;
  }

  .json-dart-ta {
    font-size: 12px;
    padding: 10px 12px;
  }

  .hljs {
    font-size: 12px;
    padding: 10px 12px;
  }

  .right_bottom {
    padding: 10px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {

  .json-dart-input,
  .zbtn {
    transition: none;
  }
}