:root {
    --viewer-bg: #ffffff;
    --viewer-surface: #f8fafc;
    --viewer-border: #e2e8f0;
    --viewer-border-strong: #cbd5e1;
    --viewer-text: #0f172a;
    --viewer-text-muted: #64748b;
    --viewer-text-soft: #94a3b8;
    --viewer-primary: #2563eb;
    --viewer-primary-hover: #1d4ed8;
    --viewer-primary-light: rgba(37, 99, 235, 0.1);
    --viewer-success: #16a34a;
    --viewer-success-light: rgba(22, 163, 74, 0.1);
    --viewer-error: #dc2626;
    --viewer-error-light: rgba(220, 38, 38, 0.1);
    --viewer-warning: #f59e0b;
    --viewer-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --viewer-shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
    --viewer-radius: 0.75rem;
    --viewer-radius-sm: 0.5rem;
    --viewer-transition: all 0.2s ease;
}

.json-viewer-interface {
    background: var(--viewer-bg);
    border-radius: var(--viewer-radius);
    overflow: hidden;
    box-shadow: var(--viewer-shadow);
    margin-bottom: 2rem;
}

.viewer-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem;
    background: var(--viewer-surface);
    border-bottom: 1px solid var(--viewer-border);
}

.controls-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.control-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: var(--viewer-bg);
    border: 1px solid var(--viewer-border);
    border-radius: var(--viewer-radius-sm);
    color: var(--viewer-text);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--viewer-transition);
}

.control-btn:hover {
    background: var(--viewer-primary-light);
    border-color: var(--viewer-primary);
    color: var(--viewer-primary);
}

.control-btn:active {
    transform: scale(0.98);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-icon {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.view-toggle {
    display: flex;
    gap: 0.5rem;
    background: var(--viewer-bg);
    border: 1px solid var(--viewer-border);
    border-radius: var(--viewer-radius-sm);
    padding: 0.25rem;
}

.toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    border-radius: calc(var(--viewer-radius-sm) - 0.25rem);
    color: var(--viewer-text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--viewer-transition);
}

.toggle-btn:hover {
    color: var(--viewer-text);
    background: var(--viewer-surface);
}

.toggle-btn.active {
    background: var(--viewer-primary);
    color: #ffffff;
}

.toggle-icon {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.viewer-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    min-height: 500px;
    width: 100%;
    overflow: hidden;
}

.panel-input,
.panel-output {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--viewer-border);
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.panel-output {
    border-right: none;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: var(--viewer-surface);
    border-bottom: 1px solid var(--viewer-border);
}

.panel-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--viewer-text);
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.panel-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    background: var(--viewer-surface);
    border: 1px solid var(--viewer-border);
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--viewer-text-muted);
}

.panel-badge.success {
    background: var(--viewer-success-light);
    border-color: var(--viewer-success);
    color: var(--viewer-success);
}

.panel-badge.error {
    background: var(--viewer-error-light);
    border-color: var(--viewer-error);
    color: var(--viewer-error);
}

.editor-wrapper,
.output-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.json-input {
    width: 100%;
    height: 100%;
    min-height: 400px;
    padding: 1.25rem;
    background: var(--viewer-bg);
    border: none;
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--viewer-text);
    resize: none;
    outline: none;
    tab-size: 2;
    box-sizing: border-box;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.json-input::placeholder {
    color: var(--viewer-text-soft);
}

.json-output {
    width: 100%;
    height: 100%;
    min-height: 400px;
    padding: 1.25rem;
    background: var(--viewer-bg);
    font-size: 0.875rem;
    line-height: 1.6;
    color: var(--viewer-text);
    overflow: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    box-sizing: border-box;
}

.json-output .key {
    color: var(--viewer-primary);
    font-weight: 500;
}

.json-output .string {
    color: var(--viewer-success);
}

.json-output .number {
    color: var(--viewer-warning);
}

.json-output .boolean {
    color: #9333ea;
}

.json-output .null {
    color: var(--viewer-text-soft);
}

.json-tree {
    width: 100%;
    height: 100%;
    min-height: 400px;
    padding: 1.25rem;
    background: var(--viewer-bg);
    font-size: 0.875rem;
    line-height: 1.8;
    color: var(--viewer-text);
    overflow: auto;
    word-wrap: break-word;
    overflow-wrap: break-word;
    max-width: 100%;
    box-sizing: border-box;
}

.tree-node {
    margin-left: 1.5rem;
    position: relative;
}

.tree-node::before {
    content: '';
    position: absolute;
    left: -1.5rem;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--viewer-border);
}

.tree-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    margin-right: 0.5rem;
    background: transparent;
    border: 1px solid var(--viewer-border);
    border-radius: 0.25rem;
    cursor: pointer;
    transition: var(--viewer-transition);
    flex-shrink: 0;
}

.tree-toggle:hover {
    background: var(--viewer-primary-light);
    border-color: var(--viewer-primary);
}

.tree-toggle::before {
    content: '−';
    font-size: 0.875rem;
    color: var(--viewer-text-muted);
}

.tree-toggle.collapsed::before {
    content: '+';
}

.tree-key {
    color: var(--viewer-primary);
    font-weight: 500;
}

.tree-value {
    color: var(--viewer-text);
}

.tree-value.string {
    color: var(--viewer-success);
}

.tree-value.number {
    color: var(--viewer-warning);
}

.tree-value.boolean {
    color: #9333ea;
}

.tree-value.null {
    color: var(--viewer-text-soft);
    font-style: italic;
}

.error-message {
    padding: 1.25rem;
    margin: 1.25rem;
    background: var(--viewer-error-light);
    border: 1px solid var(--viewer-error);
    border-radius: var(--viewer-radius-sm);
    color: var(--viewer-error);
    font-size: 0.875rem;
    line-height: 1.6;
}

.error-message::before {
    content: '⚠ ';
    font-weight: 600;
    margin-right: 0.5rem;
}

.viewer-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    padding: 1.25rem;
    background: var(--viewer-surface);
    border-top: 1px solid var(--viewer-border);
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--viewer-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--viewer-text);
}

.viewer-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: var(--viewer-surface);
    border-top: 1px solid var(--viewer-border);
    font-size: 0.875rem;
    color: var(--viewer-text-muted);
}

.meta-author {
    font-weight: 500;
}

.meta-author .author-link {
    color: var(--viewer-primary, #2563eb);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s ease;
}

.meta-author .author-link:hover {
    color: var(--viewer-primary-hover, #1d4ed8);
    text-decoration: underline;
}

.meta-updated {
    font-weight: 400;
}

@media (max-width: 1024px) {
    .viewer-panels {
        grid-template-columns: 1fr;
    }

    .panel-input {
        border-right: none;
        border-bottom: 1px solid var(--viewer-border);
    }

    .panel-output {
        border-top: 1px solid var(--viewer-border);
    }
}

@media (max-width: 768px) {
    .viewer-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .controls-group {
        width: 100%;
        justify-content: stretch;
    }

    .control-btn {
        flex: 1;
        justify-content: center;
        min-width: 0;
    }

    .view-toggle {
        width: 100%;
        justify-content: stretch;
    }

    .toggle-btn {
        flex: 1;
        justify-content: center;
    }

    .json-input,
    .json-output,
    .json-tree {
        min-height: 300px;
        font-size: 0.8125rem;
    }

    .viewer-stats {
        flex-direction: column;
        gap: 1rem;
    }

    .stat-item {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .viewer-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
}

@media (max-width: 480px) {
    .viewer-controls {
        padding: 1rem;
    }

    .controls-group {
        flex-direction: column;
    }

    .control-btn {
        width: 100%;
    }

    .panel-header {
        padding: 0.875rem 1rem;
    }

    .json-input,
    .json-output,
    .json-tree {
        padding: 1rem;
        min-height: 250px;
    }

    .viewer-meta {
        padding: 0.875rem 1rem;
        font-size: 0.8125rem;
    }
}
