:root {
    /* Premium Dark Theme */
    --bg-dark: #0f1115;
    --bg-panel: #16181D;
    --bg-input: #0A0C0F;
    --border: #2A2E36;
    --border-focus: #4F46E5;

    --primary: #4F46E5;
    --primary-hover: #4338CA;

    --text-main: #F3F4F6;
    --text-muted: #9CA3AF;

    /* Diff Colors */
    --diff-add-bg: rgba(16, 185, 129, 0.15);
    --diff-add-text: #34D399;

    --diff-rem-bg: rgba(239, 68, 68, 0.15);
    --diff-rem-text: #F87171;

    --diff-mod-bg: rgba(245, 158, 11, 0.15);
    --diff-mod-text: #FBBF24;

    --diff-unchanged: #9CA3AF;

    --radius: 10px;
    --radius-sm: 6px;
    --transition: 200ms ease;
}

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

body {
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.5;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.font-mono {
    font-family: 'JetBrains Mono', monospace;
}

.hidden {
    display: none !important;
}

.mt-1 {
    margin-top: 0.5rem;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 1rem;
    gap: 1rem;
    max-width: 1800px;
    margin: 0 auto;
    width: 100%;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-panel);
    padding: 1rem 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-main);
}

.logo svg {
    color: var(--primary);
}

h1 {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.02em;
}

.app-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-right: auto;
    margin-left: 1rem;
    border-left: 1px solid var(--border);
    padding-left: 1rem;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    position: relative;
}

/* Dropdown Settings */
.settings-dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    right: 0;
    top: 120%;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    width: 280px;
    z-index: 100;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
}

.setting-item:last-child {
    margin-bottom: 0;
}

.setting-item.flex-col {
    flex-direction: column;
    align-items: flex-start;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
    color: var(--text-main);
}

.checkbox-label input {
    display: none;
}

.custom-cb {
    width: 16px;
    height: 16px;
    border: 1px solid var(--border);
    background: var(--bg-input);
    border-radius: 4px;
    position: relative;
    transition: all var(--transition);
    flex-shrink: 0;
}

.checkbox-label input:checked+.custom-cb {
    background: var(--primary);
    border-color: var(--primary);
}

.checkbox-label input:checked+.custom-cb::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.input-field {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: 'JetBrains Mono', monospace;
    outline: none;
    transition: border-color var(--transition);
}

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

/* Workspace */
.workspace {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: 1rem;
}

.divider {
    width: 40px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 50px;
    flex-shrink: 0;
}

.diff-stats {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.stat-badge {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-main);
    font-family: 'JetBrains Mono', monospace;
}

.stat-badge.added {
    background: var(--diff-add-bg);
    border: 1px solid var(--diff-add-text);
    color: var(--diff-add-text);
}

.stat-badge.removed {
    background: var(--diff-rem-bg);
    border: 1px solid var(--diff-rem-text);
    color: var(--diff-rem-text);
}

.stat-badge.changed {
    background: var(--diff-mod-bg);
    border: 1px solid var(--diff-mod-text);
    color: var(--diff-mod-text);
}

/* Panels */
.panel {
    flex: 1;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.panel-header h2 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
}

.input-container,
.diff-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

/* URL Bar */
.url-bar {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--bg-input);
}

.method-select {
    background: transparent;
    border: none;
    color: var(--primary);
    font-weight: 700;
    padding: 0 1rem;
    outline: none;
    border-right: 1px solid var(--border);
    cursor: pointer;
}

.url-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    padding: 0.75rem 1rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    outline: none;
}

#fetch-a,
#fetch-b {
    border-radius: 0;
    border: none;
    border-left: 1px solid var(--border);
}

/* Editor */
.code-editor {
    flex: 1;
    background: var(--bg-input);
    border: none;
    color: var(--text-main);
    padding: 1rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
    resize: none;
    outline: none;
    white-space: pre;
    overflow: auto;
}

.status-bar {
    padding: 0.4rem 1rem;
    font-size: 0.75rem;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

.status-bar.error {
    color: var(--diff-rem-text);
    background: rgba(239, 68, 68, 0.05);
}

/* Tree Diff View */
.diff-container {
    background: var(--bg-input);
    overflow: auto;
    padding: 1rem 0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}

.tree-node {
    display: flex;
    flex-direction: column;
}

.tree-line {
    display: flex;
    padding: 0.15rem 1rem;
    cursor: pointer;
    position: relative;
}

.tree-line:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Line type coloring */
.tree-line.added {
    background: var(--diff-add-bg);
    color: var(--diff-add-text);
}

.tree-line.removed {
    background: var(--diff-rem-bg);
    color: var(--diff-rem-text);
}

.tree-line.changed {
    background: var(--diff-mod-bg);
    color: var(--diff-mod-text);
}

.tree-line.unchanged {
    color: var(--diff-unchanged);
}

.tree-indent {
    display: inline-block;
}

.tree-toggle {
    width: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    user-select: none;
}

.tree-toggle:hover {
    color: var(--text-main);
}

.tree-key {
    color: #A78BFA;
}

.tree-val.string {
    color: #34D399;
}

.tree-val.number {
    color: #F87171;
}

.tree-val.boolean {
    color: #60A5FA;
}

.tree-val.null {
    color: var(--text-muted);
    font-style: italic;
}

.tree-line.changed .tree-val {
    color: var(--diff-mod-text);
    font-weight: 700;
    text-decoration: underline;
}

.tree-children {
    display: flex;
    flex-direction: column;
}

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

/* Connecting hover logic (handled in JS, styled here) */
.tree-line.hover-sync {
    background: rgba(255, 255, 255, 0.08);
}

/* Footer */
.app-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    flex-shrink: 0;
}

.view-toggles {
    display: flex;
    gap: 0.5rem;
}

/* Buttons */
.btn {
    padding: 0.6rem 1rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    border: none;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

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

.btn.primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 0 15px rgba(79, 70, 229, 0.4);
}

.btn.secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.btn.secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn.outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}

.btn.outline:hover {
    border-color: var(--text-muted);
    color: var(--text-main);
}

.btn.outline.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border-color: transparent;
}

.btn.btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
    height: 32px;
}

.icon-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.icon-text-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: color var(--transition);
}

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

/* Toast */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    background: var(--text-main);
    color: var(--bg-dark);
    padding: 0.75rem 1.5rem;
    border-radius: 99px;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    transition: all 0.3s ease;
}

.toast.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
}

.toast.error {
    background: var(--diff-rem-text);
    color: white;
}

/* Scrollbars */
::-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: var(--text-muted);
}

/* Responsive */
@media (max-width: 1024px) {
    .workspace {
        flex-direction: column;
    }

    .divider {
        width: 100%;
        flex-direction: row;
        padding-top: 0;
        justify-content: center;
        padding: 0.5rem;
    }

    .diff-stats {
        flex-direction: row;
    }
}