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

:root {
    --bg: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #1c2128;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --green: #3fb950;
    --red: #f85149;
    --orange: #d29922;
    --purple: #bc8cff;
    --cyan: #39d2c0;
    --radius: 8px;
    --radius-sm: 6px;
    --transition: 150ms ease;
    --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', Consolas, monospace;
}

html {
    font-size: 15px;
}

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

/* ===== Header ===== */
header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 1.2rem 1.5rem;
    text-align: center;
}

.header-content h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.logo-brace {
    color: var(--accent);
    font-family: var(--font-mono);
    font-weight: 400;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.2rem;
}

/* ===== Main ===== */
main {
    flex: 1;
    padding: 1rem 1.5rem 1.5rem;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

/* ===== Toolbar ===== */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem 0.8rem;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.toolbar-group:not(:last-child)::after {
    content: '';
    width: 1px;
    height: 24px;
    background: var(--border);
    margin-left: 0.4rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--text);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
    white-space: nowrap;
}

.btn:hover {
    background: #272d36;
    border-color: #444c56;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: #0d1117;
    border-color: var(--accent);
    font-weight: 600;
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.indent-label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.select-indent {
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
    font-family: inherit;
    color: var(--text);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.select-indent option {
    background: var(--bg-secondary);
}

/* ===== Panels ===== */
.panels {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
    min-height: 400px;
}

.panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.8rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.upload-label {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    color: var(--accent);
    cursor: pointer;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
}

.upload-label:hover {
    color: var(--accent-hover);
}

/* Input panel */
.textarea-wrapper {
    flex: 1;
    position: relative;
    display: flex;
}

#json-input {
    flex: 1;
    padding: 0.8rem;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.55;
    color: var(--text);
    background: transparent;
    border: none;
    resize: none;
    outline: none;
    tab-size: 2;
}

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

.drop-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(88, 166, 255, 0.08);
    border: 2px dashed var(--accent);
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent);
    pointer-events: none;
    z-index: 10;
}

.drop-overlay.visible {
    display: flex;
}

/* Output panel */
.output-tabs {
    display: flex;
    gap: 0;
}

.tab-btn {
    padding: 0.35rem 0.7rem;
    font-size: 0.78rem;
    font-family: inherit;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: color var(--transition), background var(--transition);
}

.tab-btn:hover {
    color: var(--text);
}

.tab-btn.active {
    color: var(--accent);
    background: var(--bg-secondary);
    border-color: var(--border);
}

.output-content {
    flex: 1;
    position: relative;
    overflow: auto;
}

.output-pane {
    display: none;
    padding: 0.8rem;
    min-height: 100%;
}

.output-pane.active {
    display: block;
}

/* Formatted output */
#output-formatted {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
    background: transparent;
}

/* Syntax highlighting */
.json-key {
    color: var(--accent);
}

.json-string {
    color: var(--green);
}

.json-number {
    color: var(--orange);
}

.json-boolean {
    color: var(--purple);
}

.json-null {
    color: var(--red);
}

.json-brace,
.json-bracket {
    color: var(--text-muted);
}

.json-comma,
.json-colon {
    color: var(--text-muted);
}

/* Error highlighting */
.error-line {
    background: rgba(248, 81, 73, 0.15);
    display: inline-block;
    width: 100%;
    border-left: 3px solid var(--red);
    padding-left: 0.5rem;
    margin-left: -0.5rem;
}

/* ===== Tree View ===== */
.tree-view {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.6;
    overflow: auto;
}

.tree-node {
    padding-left: 1.2rem;
    position: relative;
}

.tree-node.root {
    padding-left: 0;
}

.tree-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    font-size: 0.65rem;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    border-radius: 3px;
    transition: background var(--transition), color var(--transition);
    vertical-align: middle;
    margin-right: 0.15rem;
    font-family: var(--font-mono);
}

.tree-toggle:hover {
    background: var(--bg-tertiary);
    color: var(--accent);
}

.tree-toggle.collapsed::before {
    content: '\25B6';
}

.tree-toggle:not(.collapsed)::before {
    content: '\25BC';
}

.tree-key {
    color: var(--accent);
}

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

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

.tree-value-boolean {
    color: var(--purple);
}

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

.tree-type-hint {
    color: var(--text-muted);
    font-size: 0.72rem;
    margin-left: 0.3rem;
}

.tree-children {
    overflow: hidden;
}

.tree-children.collapsed {
    display: none;
}

.tree-ellipsis {
    color: var(--text-muted);
    cursor: pointer;
}

/* ===== Status Bar ===== */
.status-bar {
    min-height: 1.8rem;
    padding: 0.35rem 0.8rem;
    font-size: 0.78rem;
    border-radius: var(--radius-sm);
    transition: background var(--transition), color var(--transition);
    display: flex;
    align-items: center;
}

.status-bar.valid {
    background: rgba(63, 185, 80, 0.12);
    color: var(--green);
    border: 1px solid rgba(63, 185, 80, 0.25);
}

.status-bar.invalid {
    background: rgba(248, 81, 73, 0.12);
    color: var(--red);
    border: 1px solid rgba(248, 81, 73, 0.25);
}

.status-bar.info {
    background: rgba(88, 166, 255, 0.1);
    color: var(--accent);
    border: 1px solid rgba(88, 166, 255, 0.2);
}

/* ===== Footer ===== */
footer {
    text-align: center;
    padding: 1rem;
    font-size: 0.78rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

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

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

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    padding: 0.6rem 1rem;
    background: var(--bg-tertiary);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    z-index: 100;
    animation: toastIn 0.25s ease, toastOut 0.25s ease 1.8s forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(10px); }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #444c56;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    header {
        padding: 0.8rem 1rem;
    }

    .header-content h1 {
        font-size: 1.3rem;
    }

    main {
        padding: 0.6rem 0.8rem 1rem;
    }

    .toolbar {
        padding: 0.5rem;
        gap: 0.4rem;
    }

    .toolbar-group:not(:last-child)::after {
        display: none;
    }

    .panels {
        grid-template-columns: 1fr;
        min-height: 600px;
    }

    .panel {
        min-height: 280px;
    }
}

@media (max-width: 480px) {
    .btn svg {
        display: none;
    }

    .toolbar-group {
        flex-wrap: wrap;
    }
}
