/* ── Custom Properties ─────────────────────────────────────── */
:root {
    --primary:        #4F46E5;
    --primary-dark:   #3730A3;
    --primary-light:  #EEF2FF;
    --primary-hover:  #4338CA;
    --bg:             #F1F5F9;
    --card:           #FFFFFF;
    --border:         #E2E8F0;
    --text:           #0F172A;
    --text-muted:     #64748B;
    --code-bg:        #1E293B;
    --code-text:      #BAE6FD;
    --key-color:      #7C3AED;
    --index-color:    #EA580C;
    --string-color:   #16A34A;
    --number-color:   #D97706;
    --bool-t-color:   #2563EB;
    --bool-f-color:   #DC2626;
    --null-color:     #94A3B8;
    --error:          #DC2626;
    --error-bg:       #FEF2F2;
    --success:        #059669;
    --radius:         12px;
    --radius-sm:      6px;
    --shadow:         0 1px 3px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md:      0 4px 6px -1px rgba(0,0,0,.10), 0 2px 4px -2px rgba(0,0,0,.06);
}

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.5;
}

/* ── Header ────────────────────────────────────────────────── */
.header {
    background: linear-gradient(135deg, #312E81 0%, #4F46E5 60%, #6D28D9 100%);
    color: #fff;
    padding: 20px 32px;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

.header-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 28px;
    flex-wrap: wrap;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.header-icon {
    font-size: 2rem;
    line-height: 1;
    filter: drop-shadow(0 0 8px rgba(255,255,200,.5));
}

.header-title {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.header-subtitle {
    font-size: 0.8rem;
    opacity: .7;
    font-weight: 400;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.header-desc {
    font-size: 0.875rem;
    opacity: .8;
    flex: 1;
    min-width: 200px;
}

.header-desc code {
    background: rgba(255,255,255,.15);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    font-size: .8rem;
}

/* ── Main Layout ───────────────────────────────────────────── */
.main {
    flex: 1;
    padding: 28px 32px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

.layout {
    display: grid;
    grid-template-columns: 420px 1fr;
    gap: 24px;
    height: calc(100vh - 140px);
    min-height: 500px;
}

/* ── Card / Panel ──────────────────────────────────────────── */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0;
}

/* ── Input Panel ───────────────────────────────────────────── */
.input-panel {
    padding: 24px;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group--grow {
    flex: 1;
    min-height: 0;
}

.label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.label-hint {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
}

.input {
    width: 100%;
    padding: 9px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--text);
    background: var(--card);
    transition: border-color .15s, box-shadow .15s;
    outline: none;
}

.input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}

.input::placeholder { color: var(--text-muted); }

.textarea {
    width: 100%;
    flex: 1;
    min-height: 0;
    padding: 11px 13px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    color: var(--text);
    background: #FAFBFC;
    resize: none;
    transition: border-color .15s, box-shadow .15s;
    outline: none;
    line-height: 1.6;
}

.textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
    background: var(--card);
}

.textarea::placeholder { color: var(--text-muted); }

/* ── Parse Button ──────────────────────────────────────────── */
.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 11px 20px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, transform .1s, box-shadow .15s;
    box-shadow: 0 1px 3px rgba(79,70,229,.4);
}

.btn-primary:hover { background: var(--primary-hover); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: translateY(1px); box-shadow: none; }

/* ── Keyboard Hint ─────────────────────────────────────────── */
.keyboard-hint {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
}

kbd {
    display: inline-block;
    padding: 1px 5px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-family: inherit;
    font-size: 0.7rem;
    line-height: 1.4;
}

/* ── Error Message ─────────────────────────────────────────── */
.error-msg {
    display: none;
    padding: 9px 13px;
    background: var(--error-bg);
    border: 1px solid #FECACA;
    border-left: 3px solid var(--error);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    color: var(--error);
    line-height: 1.4;
}

.error-msg.visible { display: block; }

/* ── Output Panel ──────────────────────────────────────────── */
.output-panel {
    position: relative;
}

.output-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}

.output-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
}

/* ── Tree Container ────────────────────────────────────────── */
.tree-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    padding: 16px 20px;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.82rem;
}

/* Custom scrollbar */
.tree-container::-webkit-scrollbar { width: 6px; height: 6px; }
.tree-container::-webkit-scrollbar-track { background: transparent; }
.tree-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.tree-container::-webkit-scrollbar-thumb:hover { background: #CBD5E1; }

/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    height: 100%;
    min-height: 200px;
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
}

.empty-icon {
    font-size: 2.5rem;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-weight: 300;
    color: #CBD5E1;
    letter-spacing: .1em;
}

.empty-state p { font-size: 0.875rem; font-family: -apple-system, sans-serif; line-height: 1.6; }

/* ── Tree Nodes ────────────────────────────────────────────── */
.tree-node { position: relative; }

/* Branch nodes (objects / arrays) */
.branch-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 6px;
    border-radius: 5px;
    cursor: pointer;
    user-select: none;
    transition: background .1s;
    white-space: nowrap;
}

.branch-header:hover { background: var(--primary-light); }

.branch-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    font-size: 9px;
    color: var(--text-muted);
    transition: transform .15s ease;
    flex-shrink: 0;
}

.branch-toggle.expanded { transform: rotate(90deg); }

.tree-children {
    display: none;
    padding-left: 18px;
    border-left: 1.5px solid var(--border);
    margin-left: 7px;
}

.tree-children.expanded {
    display: block;
    animation: fadeSlide .12s ease-out;
}

@keyframes fadeSlide {
    from { opacity: 0; transform: translateY(-3px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Leaf nodes (primitives) */
.leaf-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 6px;
    border-radius: 5px;
    cursor: pointer;
    transition: background .1s;
    white-space: nowrap;
    border-left: 2px solid transparent;
}

.leaf-row:hover { background: #F8FAFC; }
.leaf-row:hover .btn-use { opacity: 1; }

.leaf-row.selected {
    background: var(--primary-light);
    border-left-color: var(--primary);
}

/* ── Tree Key / Index / Value Labels ───────────────────────── */
.tree-key {
    color: var(--key-color);
    font-weight: 500;
    flex-shrink: 0;
}

.tree-index {
    color: var(--index-color);
    font-weight: 500;
    flex-shrink: 0;
}

.tree-colon { color: var(--text-muted); flex-shrink: 0; }

/* Leaf value type colors */
.leaf-value {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}
.leaf-value.string  { color: var(--string-color); }
.leaf-value.number  { color: var(--number-color); }
.leaf-value.boolean.true-val  { color: var(--bool-t-color); }
.leaf-value.boolean.false-val { color: var(--bool-f-color); }
.leaf-value.null    { color: var(--null-color); font-style: italic; }

/* Type badges on branch nodes */
.type-badge {
    font-size: 0.72rem;
    font-family: -apple-system, sans-serif;
    font-style: italic;
    color: var(--text-muted);
}

/* ── Use Button ────────────────────────────────────────────── */
.btn-use {
    opacity: 0;
    margin-left: auto;
    flex-shrink: 0;
    padding: 2px 9px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.7rem;
    font-family: -apple-system, sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: background .1s, opacity .1s;
    letter-spacing: .03em;
}

.btn-use:hover { background: var(--primary-hover); }
.leaf-row.selected .btn-use { opacity: 1; background: var(--primary-dark); }
.btn-use.use-copied { opacity: 1; background: var(--success); }

/* ── Show More Button ──────────────────────────────────────── */
.btn-show-more {
    display: block;
    width: 100%;
    padding: 4px 8px;
    margin-top: 2px;
    background: none;
    border: 1px dashed var(--border);
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: -apple-system, sans-serif;
    color: var(--text-muted);
    cursor: pointer;
    text-align: left;
    transition: border-color .1s, color .1s;
}

.btn-show-more:hover { border-color: var(--primary); color: var(--primary); }

/* ── Expression Bar ────────────────────────────────────────── */
.expression-bar {
    display: none;
    flex-direction: column;
    gap: 8px;
    padding: 14px 20px;
    background: var(--code-bg);
    border-top: 1px solid #334155;
    border-radius: 0 0 var(--radius) var(--radius);
    flex-shrink: 0;
}

.expression-bar.visible { display: flex; }

.expression-bar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.expression-bar-left {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #7DD3FC;
}

.expression-label {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.expression-code {
    display: block;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.82rem;
    color: var(--code-text);
    word-break: break-all;
    white-space: pre-wrap;
    line-height: 1.6;
    background: rgba(255,255,255,.04);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid #334155;
    user-select: all;
}

/* ── Copy Button ───────────────────────────────────────────── */
.btn-copy {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    font-family: -apple-system, sans-serif;
    cursor: pointer;
    transition: background .15s, transform .1s;
}

.btn-copy:hover { background: var(--primary-hover); }
.btn-copy:active { transform: scale(.97); }
.btn-copy.copied { background: var(--success); }

/* ── How To Use Button ─────────────────────────────────────── */
.btn-how-to-use {
    display: inline-block;
    flex-shrink: 0;
    padding: 8px 18px;
    border: 1.5px solid rgba(255,255,255,.6);
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background .15s, border-color .15s;
}

.btn-how-to-use:hover {
    background: rgba(255,255,255,.15);
    border-color: #fff;
}

/* ── Brand Logo ────────────────────────────────────────────── */
.header-brand-logo {
    height: 54px;
    width: auto;
    /* The SVG is black; invert to white for the dark header */
    filter: invert(1) brightness(2);
    flex-shrink: 0;
}

/* ── Instructions Section ──────────────────────────────────── */
.instructions-section {
    background: var(--card);
    border-top: 1px solid var(--border);
    padding: 32px;
}

.instructions-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.instructions-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
}

.instructions-steps {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-left: 24px;
    max-width: 900px;
    counter-reset: steps;
    list-style: none;
}

.instructions-steps li {
    position: relative;
    padding-left: 36px;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--text);
    counter-increment: steps;
}

.instructions-steps li::before {
    content: counter(steps);
    position: absolute;
    left: 0;
    top: 0;
    width: 24px;
    height: 24px;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.instructions-img {
    width: 100%;
    max-width: 900px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    display: block;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 900px) {
    .main { padding: 16px; }

    .layout {
        grid-template-columns: 1fr;
        height: auto;
        min-height: 0;
    }

    .input-panel {
        height: auto;
    }

    .textarea {
        height: 220px;
    }

    .output-panel {
        min-height: 480px;
        display: flex;
        flex-direction: column;
    }

    .header { padding: 16px; }
    .header-desc { display: none; }
}

@media (max-width: 500px) {
    .header-title { font-size: 1.2rem; }
    .header-icon { font-size: 1.5rem; }
}
