/* ==========================================================================
   JSON Formatter & Interactive Tree Viewer - GitHub Dark Graphite Stylesheet
   ========================================================================== */

:root {
    /* GitHub Primer Dark Canvas & Surfaces */
    --bg-base: #0d1117;
    --bg-surface: #11151c;
    --bg-surface-hover: #181d24;
    --bg-subtle: #090c12;
    --bg-inset: #0d1117;
    --border-color: #262c36;
    --border-muted: #1e242f;
    --border-highlight: #343b46;

    /* Text Colors */
    --text-main: #f0f6fc;
    --text-muted: #8b949e;
    --text-dim: #6e7681;
    --text-faint: #484f58;

    /* JSON Syntax Token Colors (GitHub Primer Dark) */
    --token-key: #79c0ff;       /* Primer key blue */
    --token-string: #a5d6ff;    /* Primer string light blue */
    --token-number: #79c0ff;    /* Primer number/constant blue */
    --token-boolean: #ff7b72;   /* Primer keyword/boolean coral */
    --token-null: #ff7b72;      /* Primer keyword/null coral */
    --token-bracket: #8b949e;   /* Primer punctuation/bracket */
    --token-colon: #8b949e;     /* Primer colon/comma */

    /* Theme Accents & States */
    --accent-blue: #58a6ff;
    --accent-blue-subtle: rgba(56, 139, 253, 0.15);
    --accent-green: #3fb950;
    --accent-green-subtle: rgba(46, 160, 67, 0.15);
    --accent-red: #f85149;
    --accent-red-subtle: rgba(248, 81, 73, 0.15);
    --btn-primary-bg: #238636;
    --btn-primary-hover: #2ea043;
    --focus-ring: 0 0 0 3px rgba(56, 139, 253, 0.3);

    /* Typography */
    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

    /* Transitions & Radii */
    --radius-lg: 6px;
    --radius-md: 6px;
    --radius-sm: 6px;
    --transition: all 0.15s ease;
}

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

body {
    font-family: var(--font-ui);
    background-color: var(--bg-base);
    color: var(--text-main);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Ambient Background Lights - Removed in GitHub Dark Graphite */
.ambient-bg {
    display: none !important;
}

/* Main Application Container */
.app-layout {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    overflow: hidden;
    background-color: var(--bg-base);
}

/* ==========================================================================
   Top Navigation Bar
   ========================================================================== */
.navbar {
    height: 56px;
    min-height: 56px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 0 18px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-self: start;
}

.brand-icon {
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    filter: none;
}

.brand-text h1 {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--text-main);
    line-height: 1.1;
}

/* Center Meta & Live Status */
.nav-center {
    display: flex;
    align-items: center;
    gap: 16px;
    justify-self: center;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    border: 1px solid transparent;
    transition: var(--transition);
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
}

.badge-empty {
    background: #181d24;
    border-color: var(--border-color);
    color: var(--text-muted);
}
.badge-empty .status-dot { 
    background: var(--text-dim); 
    box-shadow: none; 
}

.badge-valid {
    background: var(--accent-green-subtle);
    border-color: rgba(46, 160, 67, 0.35);
    color: var(--accent-green);
    box-shadow: none;
}
.badge-valid .status-dot { 
    background: var(--accent-green); 
    box-shadow: none; 
}

.badge-invalid {
    background: var(--accent-red-subtle);
    border-color: rgba(248, 81, 73, 0.35);
    color: var(--accent-red);
    box-shadow: none;
}
.badge-invalid .status-dot { 
    background: var(--accent-red); 
    box-shadow: none; 
}

.stats-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.76rem;
    color: var(--text-muted);
}

.stat-label {
    color: var(--text-dim);
    margin-right: 2px;
}

.stat-item strong {
    color: var(--text-main);
    font-family: var(--font-mono);
    font-weight: 600;
}

.stat-separator {
    color: var(--border-color);
    font-size: 0.75rem;
}

/* Nav Actions */
.nav-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-self: end;
}

.indent-select-wrapper select {
    background: #181d24;
    border: 1px solid var(--border-color);
    color: var(--text-main);
    font-family: var(--font-ui);
    font-size: 0.78rem;
    font-weight: 500;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    outline: none;
    cursor: pointer;
    transition: var(--transition);
}

.indent-select-wrapper select:hover {
    border-color: var(--border-highlight);
    background: #222832;
}

.indent-select-wrapper select:focus {
    border-color: var(--accent-blue);
    box-shadow: var(--focus-ring);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    font-family: var(--font-ui);
    font-size: 0.78rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    user-select: none;
    outline: none;
    line-height: 1.4;
    white-space: nowrap;
}

.btn:focus-visible {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: var(--focus-ring);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 0.78rem;
}

.btn-primary {
    background: var(--btn-primary-bg);
    border: 1px solid rgba(240, 246, 252, 0.1);
    color: #ffffff;
    box-shadow: 0 1px 0 rgba(27, 31, 36, 0.1);
}

.btn-primary:hover {
    background: var(--btn-primary-hover);
    border-color: rgba(240, 246, 252, 0.1);
}

.btn-primary:active {
    background: var(--btn-primary-bg);
}

.btn-primary.copied {
    background: var(--btn-primary-bg) !important;
    border-color: var(--accent-green) !important;
    box-shadow: none !important;
}

.btn-secondary {
    background: #181d24;
    border: 1px solid var(--border-color);
    color: #c9d1d9;
}

.btn-secondary:hover {
    background: #222832;
    border-color: var(--border-highlight);
    color: var(--text-main);
}

.btn-icon-text {
    background: #181d24;
    border: 1px solid var(--border-color);
    color: #c9d1d9;
    font-family: var(--font-ui);
    font-size: 0.76rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon-text:hover {
    color: var(--text-main);
    background: #222832;
    border-color: var(--border-highlight);
}

/* ==========================================================================
   Workspace & Panes (Split View)
   ========================================================================== */
.workspace {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 0;
    overflow: hidden;
    background: var(--bg-base);
}

.pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    background: var(--bg-inset);
}

.pane-input {
    border-right: 1px solid var(--border-color);
}

.pane-header {
    height: 44px;
    min-height: 44px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-muted);
    padding: 0 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.pane-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
}

.pane-title h2 {
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.8px;
    color: var(--text-main);
}

.pane-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* View Mode Switcher (Tree vs Raw) */
.view-switch {
    display: inline-flex;
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 2px;
    margin-left: 10px;
    gap: 2px;
}

.tab-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-family: var(--font-ui);
    font-size: 0.74rem;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: var(--transition);
}

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

.tab-btn.active {
    background: #181d24;
    border-color: var(--border-color);
    color: var(--text-main);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    font-weight: 600;
}

/* Search Box */
.search-box {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 3px 8px;
    color: var(--text-muted);
    transition: var(--transition);
}

.search-box:focus-within {
    border-color: var(--accent-blue);
    box-shadow: var(--focus-ring);
}

.search-box input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-main);
    font-family: var(--font-ui);
    font-size: 0.76rem;
    width: 120px;
}

.search-box input::placeholder {
    color: var(--text-dim);
}

.search-counter {
    font-size: 0.7rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
    user-select: none;
    padding: 0 2px;
    white-space: nowrap;
}

.btn-search-nav {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px;
    border-radius: 3px;
    line-height: 1;
    transition: var(--transition);
}

.btn-search-nav:hover {
    color: var(--text-main);
    background: #181d24;
}

.btn-clear-search {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1;
    padding: 0 2px;
}
.btn-clear-search:hover { 
    color: var(--text-main); 
}

/* Display Mode Controls (Expand, Collapse, Minify) */
.display-mode-group {
    display: inline-flex;
    align-items: center;
    background: var(--bg-subtle);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 2px;
    gap: 2px;
}

.btn-mode {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-family: var(--font-ui);
    font-size: 0.74rem;
    font-weight: 500;
    padding: 4px 9px;
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: var(--transition);
    user-select: none;
    outline: none;
}

.btn-mode:hover {
    color: var(--text-main);
    background: transparent;
}

.btn-mode.active {
    background: #181d24;
    border-color: var(--border-color);
    color: var(--text-main);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    font-weight: 600;
}

/* ==========================================================================
   Left Editor (Input Area with Line Numbers)
   ========================================================================== */
.editor-container,
.viewer-layout {
    flex: 1;
    display: flex;
    min-height: 0;
    position: relative;
    overflow: hidden;
    font-family: var(--font-mono);
    font-size: 0.84rem;
    line-height: 24px;
    background: var(--bg-inset);
}

.line-numbers {
    width: 48px;
    min-width: 48px;
    padding: 12px 10px 12px 0;
    text-align: right;
    color: var(--text-dim);
    background: var(--bg-inset);
    border-right: 1px solid var(--border-muted);
    user-select: none;
    overflow: hidden;
    white-space: pre-line;
    line-height: 24px;
    font-size: 0.84rem;
}

.json-textarea {
    flex: 1;
    height: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-main);
    caret-color: var(--accent-blue);
    font-family: inherit;
    font-size: inherit;
    line-height: 24px;
    resize: none;
    tab-size: 2;
    white-space: pre;
    overflow: auto;
    word-break: normal;
    word-wrap: normal;
}

.json-textarea::placeholder {
    color: var(--text-faint);
    font-style: normal;
}

/* Error Banner */
.error-bar {
    background: #161b22;
    border-top: 1px solid #da3633;
    padding: 8px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.78rem;
    color: var(--accent-red);
    animation: slideUp 0.15s ease-out;
}

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

.error-icon {
    color: var(--accent-red);
    display: flex;
    align-items: center;
}

.error-content {
    flex: 1;
    min-width: 0;
}

.error-title {
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-red);
}

.error-message {
    font-family: var(--font-mono);
    font-size: 0.76rem;
    color: #c9d1d9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-jump-error {
    background: #21262d;
    border: 1px solid rgba(248, 81, 73, 0.4);
    color: var(--accent-red);
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    font-family: var(--font-ui);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-jump-error:hover {
    background: #da3633;
    color: #ffffff;
}

/* ==========================================================================
   Right Viewer (Interactive Tree & Raw Code)
   ========================================================================== */
.viewer-container {
    flex: 1;
    overflow: auto;
    padding: 12px 16px;
    min-height: 0;
    font-family: var(--font-mono);
    font-size: 0.84rem;
    line-height: 24px;
    position: relative;
    background: var(--bg-inset);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 250px;
    color: var(--text-muted);
    text-align: center;
    gap: 8px;
}

.empty-icon {
    width: 48px;
    height: 48px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
}

.empty-state h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: #c9d1d9;
}

.empty-state p {
    font-size: 0.8rem;
    max-width: 320px;
    color: var(--text-muted);
}

.empty-state strong {
    color: var(--text-main);
}

/* Tree Structure Elements */
.tree-content {
    user-select: text;
}

.tree-node {
    position: relative;
    padding-left: 20px;
}

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

.tree-line {
    display: flex;
    align-items: center;
    height: 24px;
    line-height: 24px;
    padding: 0 4px;
    border-radius: 4px;
    cursor: default;
    transition: background 0.1s ease;
    white-space: nowrap;
}

.tree-line:hover {
    background: #161b22;
}

.tree-line.selected {
    background: var(--accent-blue-subtle);
}

/* Toggle Arrow Button */
.node-toggle {
    position: absolute;
    left: 2px;
    top: 4px;
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.65rem;
    transition: transform 0.15s ease, color 0.15s ease;
}

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

.node-toggle.collapsed {
    transform: rotate(-90deg);
}

/* Tree Children Block */
.node-children {
    display: block;
    border-left: 1px solid var(--border-muted);
    margin-left: 9px;
    transition: border-color 0.15s ease;
}

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

.node-children:hover {
    border-left-color: var(--accent-blue);
}

/* Primer Dark Tokens Syntax Highlighting */
.key {
    color: var(--token-key);
    font-weight: 500;
}

.colon {
    color: var(--token-colon);
    margin: 0 4px 0 1px;
}

.comma {
    color: var(--token-colon);
}

.val-string {
    color: var(--token-string);
}

.val-number {
    color: var(--token-number);
}

.val-boolean {
    color: var(--token-boolean);
    font-weight: 600;
}

.val-null {
    color: var(--token-null);
    font-weight: 600;
}

.bracket {
    color: var(--token-bracket);
    font-weight: 600;
}

.collapsed-summary {
    background: #181d24;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin: 0 4px;
    font-style: italic;
    cursor: pointer;
    transition: var(--transition);
}

.collapsed-summary:hover {
    background: #222832;
    border-color: var(--border-highlight);
    color: var(--text-main);
}

/* Search Highlights */
.search-highlight {
    background: rgba(242, 204, 96, 0.35);
    color: #ffffff;
    border-radius: 2px;
    box-shadow: none;
    transition: background 0.15s ease, color 0.15s ease;
}

.search-highlight.current {
    background: #e3b341;
    color: #0d1117;
    font-weight: 700;
    box-shadow: none;
    outline: none;
}

/* Raw Code Display */
.raw-view {
    height: 100%;
}

.tree-view:has(#tree-content.hidden):has(#empty-state.hidden) {
    display: none;
}

.raw-code {
    font-family: inherit;
    font-size: inherit;
    line-height: 24px;
    white-space: pre;
    color: var(--text-main);
    overflow: auto;
}

/* Path Bar (Footer) */
.path-bar {
    height: 34px;
    min-height: 34px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-muted);
    padding: 0 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.74rem;
    color: var(--text-muted);
}

.path-label {
    font-weight: 500;
    color: var(--text-dim);
}

.current-path {
    font-family: var(--font-mono);
    color: var(--token-key);
    font-size: 0.74rem;
    background: #181d24;
    border: 1px solid var(--border-color);
    padding: 2px 8px;
    border-radius: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 90%;
    user-select: text;
}

/* ==========================================================================
   Toast Notifications
   ========================================================================== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: #161b22;
    border: 1px solid #30363d;
    color: var(--text-main);
    padding: 9px 16px;
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(1, 4, 9, 0.6);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: toastSlideUp 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.hidden { display: none !important; }

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-inset);
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--border-highlight);
}

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */
@media (max-width: 860px) {
    .workspace {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }
    .pane-input {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    .stats-group {
        display: none;
    }
}

@media (max-width: 640px) {
    .navbar {
        display: flex;
        justify-content: space-between;
        padding: 0 12px;
    }
    .nav-center {
        display: none;
    }
}
