:root {
    --color-primary: #667eea;
    --color-primary-dark: #5568d3;
    --color-primary-purple: #764ba2;
    --color-accent: #5a3e9b;
    --color-surface: #fafafa;
    --color-border: #e0e0e0;
    --radius-sm: 4px;
    --radius-md: 6px;
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --font-mono: ui-monospace, 'Cascadia Code', 'Courier New', monospace;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f5f5;
    color: #333;
    height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

header {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-purple) 100%);
    color: white;
    padding: 1.5rem 2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.subtitle {
    font-size: 0.9rem;
    opacity: 0.9;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 350px 1fr;
    gap: 0;
    flex: 1;
    overflow: hidden;
    background: var(--color-border);
}

.panel {
    background: white;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid #ddd;
}

.panel:last-child {
    border-right: none;
}

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

.panel-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #444;
}

.editor {
    flex: 1;
    overflow: hidden;
    border: none;
}

.editor-results {
    min-height: 200px;
}

/* Screen-reader only utility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

/* Buttons */
.btn {
    padding: 0.5rem 1.2rem;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color var(--transition-base), transform var(--transition-base), box-shadow var(--transition-base);
}

.btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--color-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    background: var(--color-border);
    color: #555;
}

.btn-small:hover {
    background: #d0d0d0;
}

.btn.copied {
    background: #4caf50;
    color: white;
}

.tree-controls,
.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Tree View */
.tree-panel {
    background: var(--color-surface);
}

.tree-view {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    background: white;
    scrollbar-width: thin;
    scrollbar-color: #c1c1c1 #f1f1f1;
}

.tree-view::-webkit-scrollbar {
    width: 8px;
}

.tree-view::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.tree-view::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: var(--radius-sm);
}

.tree-view::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

.empty-state {
    text-align: center;
    color: #999;
    padding: 3rem 2rem;
    font-size: 0.95rem;
}

.tree-node {
    margin-left: 1.2rem;
}

.tree-item {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.5rem;
    margin: 0.15rem 0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
    user-select: none;
}

.tree-item:hover {
    background: #f0f0f0;
}

.tree-item.clickable:hover {
    background: #e3f2fd;
}

.tree-item.flash {
    background: #c5e1a5;
    transition: background 0.3s ease;
}

.tree-toggle {
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-right: 0.3rem;
    font-size: 0.8rem;
    color: #666;
    flex-shrink: 0;
}

.tree-toggle.empty {
    visibility: hidden;
}

.tree-icon {
    margin-right: 0.4rem;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.tree-key {
    font-weight: 500;
    color: #1976d2;
    margin-right: 0.4rem;
}

.tree-type {
    font-size: 0.8rem;
    color: #757575;
    font-style: italic;
}

.tree-value {
    color: #2e7d32;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    margin-left: 0.5rem;
}

.tree-path {
    font-size: 0.75rem;
    color: #999;
    margin-left: auto;
    padding-left: 1rem;
    font-family: var(--font-mono);
    opacity: 0;
    transition: opacity var(--transition-base);
}

.tree-item:hover .tree-path {
    opacity: 1;
}

/* Query Section */
.query-input-wrapper {
    padding: 1rem 1.5rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.query-input {
    flex: 1;
    padding: 0.7rem 1rem;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-family: var(--font-mono);
    transition: border-color var(--transition-base);
}

.query-input:focus {
    border-color: var(--color-primary);
}

.query-input:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

.query-help {
    position: relative;
}

.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--color-primary);
    color: white;
    border-radius: 50%;
    font-size: 0.85rem;
    font-weight: bold;
    cursor: help;
}

.help-tooltip {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 0.5rem;
    background: #333;
    color: white;
    padding: 1rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    line-height: 1.6;
    width: 300px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.help-icon:hover + .help-tooltip,
.help-icon:focus + .help-tooltip {
    display: block;
}

.results-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.results-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #444;
}

.results-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.result-count {
    font-size: 0.85rem;
    color: #666;
    padding: 0.3rem 0.8rem;
    background: #e8f5e9;
    border-radius: 12px;
    font-weight: 500;
}

/* Sample Queries */
.samples-section {
    border-bottom: 1px solid var(--color-border);
}

.samples-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.5rem;
    background: #f5f0ff;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-accent);
    text-align: left;
    transition: background var(--transition-fast);
}

.samples-toggle:hover {
    background: #ede7f6;
}

#samplesToggleIcon {
    font-size: 0.7rem;
    transition: transform var(--transition-base);
}

.docs-link {
    margin-left: auto;
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--color-primary);
    text-decoration: none;
}

.docs-link:hover {
    text-decoration: underline;
}

.samples-panel {
    padding: 0.5rem 1.5rem 0.75rem;
    background: #faf8ff;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
}

.samples-panel.collapsed {
    display: none;
}

.sample-query {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d8ccf0;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
    background: white;
}

.sample-query:hover {
    background: #ede7f6;
    border-color: #9c6fe0;
}

.sample-label {
    font-size: 0.75rem;
    color: #666;
}

.sample-query code {
    font-size: 0.8rem;
    font-family: var(--font-mono);
    color: var(--color-accent);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Error Messages */
.error-message {
    display: none;
    padding: 0.8rem 1.5rem;
    background: #ffebee;
    color: #c62828;
    border-left: 4px solid #c62828;
    font-size: 0.9rem;
    margin: 0.5rem 1rem;
    border-radius: var(--radius-sm);
}

.error-message.show {
    display: block;
}

/* Footer */
footer {
    background: #333;
    color: #999;
    padding: 0.8rem 2rem;
    font-size: 0.85rem;
    text-align: center;
}

footer a {
    color: var(--color-primary);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

/* Responsive adjustments */
@media (max-width: 1400px) {
    .main-content {
        grid-template-columns: 1fr 300px 1fr;
    }
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        grid-template-rows: 300px 250px 1fr;
    }

    .panel {
        border-right: none;
        border-bottom: 1px solid #ddd;
    }

    .tree-path {
        display: none;
    }
}

@media (max-width: 768px) {
    body { overflow: auto; }
    .main-content {
        grid-template-rows: 250px 200px 1fr;
    }
}

/* Animation for tree expand/collapse */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tree-node {
    animation: fadeIn 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
    .tree-node { animation: none; }
}

/* Autocomplete dropdown */
.autocomplete-dropdown {
    position: fixed;
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    z-index: 2000;
    max-height: 220px;
    overflow-y: auto;
    display: none;
    scrollbar-width: thin;
}

.autocomplete-item {
    padding: 0.45rem 0.9rem;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #333;
    transition: background var(--transition-fast);
}

.autocomplete-item strong {
    color: var(--color-primary);
    font-weight: 600;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background: #f0f2ff;
    color: var(--color-primary-dark);
}
