/* ======= JSON 在线解析格式化工具样式 ======= */
/* 复用 json-viewer.css 的工具主体风格，新增视图切换/树形视图/JSONPath/统计/路径样式 */

/* 覆盖全局 .tool-container 的 900px，本工具含左右双面板+多按钮，需要更宽容器 */
.tool-page .tool-container {
    max-width: 1200px;
}

.tool-title-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--primary-light);
}

.tool-title-wrapper i {
    font-size: 2rem;
    color: var(--primary-color);
}

.tool-title-wrapper .tool-title {
    margin-bottom: 0;
    border-bottom: none;
}

/* 配置区 */
.config-section {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.config-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.config-actions {
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
    margin-left: auto;
}

.form-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.indent-buttons,
.view-switcher {
    display: flex;
    gap: 8px;
}

.indent-btn,
.view-btn {
    padding: 8px 16px;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.indent-btn:hover,
.view-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.indent-btn.active,
.view-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

/* JSONPath 查询区 */
.jsonpath-section {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 16px;
    padding: 12px 14px;
    background: var(--bg-light);
    border-radius: var(--radius-md);
    flex-wrap: wrap;
}

.jsonpath-section .jsonpath-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.jsonpath-input {
    flex: 1;
    min-width: 200px;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-white);
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    color: var(--text-primary);
}

.jsonpath-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.jsonpath-match-count {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.jsonpath-match-count.has-match {
    color: var(--primary-color);
    font-weight: 600;
}

/* JSON 面板（左输入 / 右输出） */
.json-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.json-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.panel-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.panel-header .panel-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.json-input {
    min-height: 320px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    line-height: 1.6;
}

/* 输出区容器（文本视图 + 树形视图切换） */
.json-output-wrapper {
    min-height: 320px;
    max-height: 560px;
    overflow: auto;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    position: relative;
}

.json-output {
    padding: 12px 14px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    line-height: 1.6;
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
}

/* 文本视图语法高亮配色 */
.json-key { color: #d63384; }
.json-string { color: #198754; }
.json-number { color: #0d6efd; }
.json-boolean { color: #fd7e14; }
.json-null { color: #6c757d; }

/* 树形视图 */
.tree-view {
    padding: 8px 6px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    line-height: 1.7;
}

.tree-node {
    padding-left: 20px;
}

.tree-row {
    display: flex;
    align-items: baseline;
    gap: 4px;
    padding: 1px 4px;
    border-radius: 4px;
    cursor: default;
    transition: background 0.15s ease;
}

.tree-row.clickable {
    cursor: pointer;
}

.tree-row.clickable:hover {
    background: var(--primary-light);
}

.tree-row.highlight {
    background: #fff3cd;
    outline: 1px solid #ffc107;
}

.tree-toggle {
    display: inline-block;
    width: 16px;
    text-align: center;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    font-size: 10px;
    transition: transform 0.2s ease;
}

.tree-toggle.collapsed {
    transform: rotate(-90deg);
}

.tree-toggle.leaf {
    cursor: default;
    color: transparent;
}

.tree-key {
    color: #d63384;
    font-weight: 600;
}

.tree-key::after {
    content: ': ';
    color: var(--text-secondary);
    font-weight: normal;
}

.tree-value {
    color: var(--text-primary);
}

.tree-value.string { color: #198754; }
.tree-value.number { color: #0d6efd; }
.tree-value.boolean { color: #fd7e14; }
.tree-value.null { color: #6c757d; font-style: italic; }

.tree-bracket {
    color: var(--text-secondary);
}

.tree-children {
    overflow: hidden;
}

.tree-children.collapsed {
    display: none;
}

.tree-preview {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 12px;
    margin-left: 4px;
}

/* 统计栏 */
.stats-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
    margin-top: 12px;
    padding: 10px 14px;
    background: var(--bg-light);
    border-radius: var(--radius-md);
    font-size: 13px;
}

.stat-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
}

.stat-item .stat-label {
    color: var(--text-secondary);
}

.stat-item .stat-value {
    color: var(--primary-color);
    font-weight: 600;
    font-family: 'Consolas', 'Monaco', monospace;
}

/* 路径显示 */
.path-display {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 8px 12px;
    background: var(--bg-light);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    font-size: 13px;
    min-height: 38px;
}

.path-display .path-label {
    color: var(--text-secondary);
    white-space: nowrap;
    font-weight: 600;
}

.path-display .path-value {
    flex: 1;
    font-family: 'Consolas', 'Monaco', monospace;
    color: var(--primary-color);
    word-break: break-all;
}

.path-display .path-value.empty {
    color: var(--text-secondary);
    font-style: italic;
}

/* 错误提示 */
.error-message {
    margin-top: 10px;
    padding: 10px 14px;
    background: #fff2f0;
    border: 1px solid #ffccc7;
    border-radius: var(--radius-md);
    color: var(--danger-color);
    font-size: 13px;
    display: none;
    align-items: center;
    gap: 8px;
}

.error-message.show {
    display: flex;
}

/* 响应式 */
@media (max-width: 768px) {
    .config-section {
        flex-direction: column;
        align-items: stretch;
    }

    .config-actions {
        margin-left: 0;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .json-panels {
        grid-template-columns: 1fr;
    }

    .json-input,
    .json-output-wrapper {
        min-height: 220px;
    }

    .jsonpath-section {
        flex-direction: column;
        align-items: stretch;
    }

    .jsonpath-input {
        width: 100%;
    }

    .stats-bar {
        gap: 6px 14px;
        font-size: 12px;
    }
}
