/* 全局重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, #f0f7ff, #e3f2fd);
    color: #333;
    min-height: 100vh;
    padding: 20px;
    line-height: 1.5;
}

.container {
    max-width: 2000px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    min-height: 100vh; /* 确保至少占满视口 */
}

/* 头部 */
header {
    text-align: center;
    margin-bottom: 28px;
}

header h1 {
    font-size: 2.2rem;
    color: #3498db;
    margin-bottom: 8px;
}

header p {
    color: #95a5a6;
    font-size: 1rem;
}

/* 主布局 */
.main-content {
    display: flex;
    gap: 28px;
    flex-wrap: wrap;
    flex: 1;
    min-height: 0; /* 关键：允许 flex 子项收缩并滚动 */
    overflow: hidden; /* 防止溢出 */
}

/* 面板通用 */
.panel {
    flex: 1;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    background: white;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid #eef4ff;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.panel-header {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    padding: 12px 25px;
    text-align: center;
    flex-shrink: 0;
}

.panel-header h2 {
    font-size: 1.4rem;
    font-weight: 600;
}

.divider {
    width: 40px;
    height: 3px;
    background: rgba(255, 255, 255, 0.7);
    margin: 4px auto;
    border-radius: 2px;
}

/* 面板内容 */
.panel-content {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 22px;
    overflow: hidden;
}

#jsonInput,
.json-output,
.empty-message {
    flex: 1;
    min-height: 0;
    overflow: auto;
    margin: 0;
}

#jsonInput {
    width: 100%;
    padding: 16px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 14px;
    border: 1px solid #dce9f7;
    border-radius: 12px;
    resize: none;
    background-color: #fafcff;
    color: #2c3e50;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#jsonInput:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
}

.json-output {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.4;
    background: #fafcff;
    padding: 16px;
    border-radius: 12px;
    border: 1px solid #dce9f7;
    white-space: pre-wrap;
}

.empty-message {
    color: #95a5a6;
    font-style: italic;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 1.1rem;
}

/* ========== 按钮统一样式 ========== */
.top-action-bar {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    gap: 8px;
    z-index: 10;
}

.clear-btn {
    position: absolute;
    top: 16px;
    right: 16px; /* ✅ 关键：靠右 */
    z-index: 10;
}

.action-btn {
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
    color: white;
    white-space: nowrap;
}

/* 默认灰色 */
.action-btn {
    background: linear-gradient(to bottom, #95a5a6, #7f8c8d);
}

.action-btn:hover {
    background: linear-gradient(to bottom, #7f8c8d, #6c7a7a);
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

/* 主色：复制（蓝色） */
.action-btn.primary {
    background: linear-gradient(to bottom, #3498db, #2980b9);
}

.action-btn.primary:hover {
    background: linear-gradient(to bottom, #2980b9, #1f618d);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.35);
}

/* 成功状态：绿色 */
.action-btn.success {
    background: linear-gradient(to bottom, #2ecc71, #27ae60) !important;
    box-shadow: 0 3px 10px rgba(46, 204, 113, 0.4) !important;
}

/* ========== 错误提示 ========== */
.error-message {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    background: #fdf2f2;
    color: #e74c3c;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    border: 1px solid #f5c6c6;
    z-index: 20;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.2);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.error-message.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.right-error {
    left: auto;
    right: 50%;
    transform: translateX(50%) translateY(-100%);
}

.right-error.show {
    transform: translateX(50%) translateY(0);
}

.input-error {
    /* ✅ 关键：上移 + 居中（在左侧面板顶部上方） */
    top: 0px;                  /* 向上偏移，避开输入框 */
}

/* ========== JSON 高亮 ========== */
.json-key {
    color: #e74c3c;
    font-weight: bold;
}

.json-string {
    color: #2ecc71;
}

.json-number {
    color: #3498db;
}

.json-boolean {
    color: #9b59b6;
}

.json-null {
    color: #f39c12;
}

/* ========== 折叠控制 ========== */
.toggle-btn {
    cursor: pointer;
    user-select: none;
    display: inline-block;
    margin-right: 1px;
    color: #3498db;
    font-weight: bold;
    width: 14px;
    text-align: center;
}

.toggle-btn:hover {
    color: #2980b9;
}

.collapsed {
    display: none !important;
}

.json-line {
    display: block;
    margin: 0;
    padding: 0;
}

.children {
    display: block;
}

footer {
    text-align: center;
    margin-top: 20px;
    color: #666;
    font-size: 0.9rem;
  }
  
footer a,
footer a:visited,
footer a:hover,
footer a:active {
color: #666;
text-decoration: none;
}

/* ========== 响应式 ========== */
@media (max-width: 768px) {
    .main-content {
        flex-direction: column;
        height: auto;
    }

    .top-action-bar,
    .clear-btn {
        position: relative;
        top: 0;
        right: auto;
        margin-bottom: 12px;
        width: 100%;
        justify-content: center;
    }

    .panel-content {
        padding: 16px;
    }
}