/* JSON Tool Variables */
:root {
    /* Monokai Theme Colors */
    --monokai-bg: #272822;
    --monokai-fg: #f8f8f2;
    --monokai-comment: #75715e;
    --monokai-yellow: #e6db74;
    --monokai-purple: #ae81ff;
    --monokai-red: #f92672;
    --monokai-blue: #66d9ef;
    --monokai-green: #a6e22e;
    --monokai-orange: #fd971f;

    /* Glass Variables */
    --glass-bg: rgba(30, 30, 30, 0.25);
    --glass-border: rgba(255, 255, 255, 0.18);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    --glass-blur: blur(12px) saturate(150%);
}

/* Hide Global Navigation for this tool */
header.navbar-fixed,
#headNav,
#aplayer,
.aplayer {
    display: none !important;
}

/* Base Layout */
body {
    margin: 0;
    padding: 0;
    background-image: linear-gradient(135deg, #1e1e1e 0%, #2d2d2d 100%);
    color: var(--monokai-fg);
    font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
    overflow: hidden;
    height: 100vh;
}

.json-tool-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    position: relative;
    background: var(--monokai-bg);
}

/* Removed overlay - now toolbar shows editor content behind it */

/* Toolbar Styles */
.toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 16px;
    height: 44px;
    box-sizing: border-box;
    
    /* Liquid Glass Effect - shows content behind */
    background: rgba(39, 40, 34, 0.7);
    backdrop-filter: blur(12px) saturate(150%);
    -webkit-backdrop-filter: blur(12px) saturate(150%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.toolbar-left, .toolbar-center, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.tool-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--monokai-fg);
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.back-btn {
    color: var(--monokai-fg);
    font-size: 1.2rem;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateX(-3px);
}

/* Button & Button Groups */
.btn-group {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 2px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.toolbar-btn {
    background: transparent;
    border: none;
    color: rgba(248, 248, 242, 0.7);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.toolbar-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    color: var(--monokai-fg);
}

.toolbar-btn.active {
    background: rgba(255, 255, 255, 0.15);
    color: var(--monokai-green);
    font-weight: 500;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toolbar-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.1);
    margin: 0 5px;
}

/* Search Bar */
.search-bar {
    /* Liquid Glass Effect - shows content behind */
    position: fixed;
    top: 44px; /* Below toolbar */
    left: 0;
    right: 0;
    z-index: 99;
    background: rgba(39, 40, 34, 0.7);
    backdrop-filter: blur(12px) saturate(150%);
    -webkit-backdrop-filter: blur(12px) saturate(150%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    padding: 8px 20px;
    display: none;
    font-size: 0.9rem;
}

.search-bar.active {
    display: block;
    animation: slideDown 0.2s ease-out;
}

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

.search-row {
    display: flex;
    align-items: center; /* Vertically center all items */
    gap: 15px;
}

.search-inputs-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 300px; /* Fixed smaller width */
}

.search-input-group {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    padding: 0 8px;
    height: 28px; /* Compact height */
}

.search-input-group i {
    color: var(--monokai-comment);
    margin-right: 8px;
    font-size: 0.8rem;
}

.search-input-group input {
    background: transparent;
    border: none;
    color: var(--monokai-fg);
    padding: 0;
    padding-top: 8px;
    width: 100%;
    font-family: inherit;
    outline: none;
    font-size: 0.85rem;
    height: 100%;
    line-height: 1;
    box-sizing: border-box;
    vertical-align: bottom;
}

.search-input-group input::placeholder {
    color: rgba(255, 255, 255, 0.35);
    opacity: 1;
    line-height: 1;
}

.search-count {
    font-size: 0.8rem;
    color: var(--monokai-comment);
    white-space: nowrap;
    padding-left: 8px;
}

.search-options {
    display: flex;
    gap: 5px;
}

.search-option-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--monokai-comment);
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.search-option-btn.active {
    background: rgba(166, 226, 46, 0.1);
    color: var(--monokai-green);
    border-color: rgba(166, 226, 46, 0.3);
}

.search-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-btn, .error-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--monokai-fg);
    padding: 0 10px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
}

.search-btn:hover, .error-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.search-close-btn {
    background: transparent;
    border: none;
    color: var(--monokai-comment);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    margin-left: 10px;
}

.search-close-btn:hover {
    background: rgba(249, 38, 114, 0.1);
    color: var(--monokai-red);
}

/* Editor Area */
.editor-container {
    position: absolute;
    top: 0; /* Full height, toolbar overlays it */
    left: 0;
    right: 0;
    bottom: 0; /* Full height */
    z-index: 1;
    overflow: hidden;
    display: flex;
    background: var(--monokai-bg);
    box-sizing: border-box;
}

/* When search bar is active, we DON'T push down anymore, we just add padding to content */

.editor-view {
    display: none;
    width: 100%;
    height: 100%;
    position: relative;
}

.editor-view.active {
    display: flex;
}

/* Text View */
.text-view {
    font-family: 'Fira Code', monospace;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    overflow: hidden;
    height: 100%;
}

.line-numbers {
    width: 50px;
    background: rgba(0, 0, 0, 0.2);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--monokai-comment);
    text-align: right;
    padding: 54px 5px 40px 5px; /* Top: 44px toolbar + 10px; Bottom: 30px status + 10px */
    box-sizing: border-box;
    overflow-y: auto;
    overflow-x: hidden;
    user-select: none;
    scrollbar-width: none;
    -ms-overflow-style: none;
    height: 100%;
    transition: padding-top 0.2s ease-out;
}

/* Increase padding when search is active so content starts lower */
/* Search bar height: ~78px (2 inputs) + 44px toolbar = ~122px. Use 130px for safe spacing */
.json-tool-container.search-active .line-numbers {
    padding-top: 130px; 
}

.line-numbers::-webkit-scrollbar {
    display: none;
}

.line-number {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    line-height: 21px; /* Match textarea line-height: 14px * 1.5 = 21px */
    height: 21px;
    padding-right: 5px;
    padding-left: 5px;
    box-sizing: border-box;
    gap: 4px;
}

.line-number .line-num-text {
    min-width: 20px;
    text-align: right;
    order: 0; /* Line number comes first */
    transition: all 0.2s;
}

.line-number .fold-icon {
    width: 14px;
    height: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--monokai-comment);
    font-size: 10px;
    transition: color 0.2s;
    flex-shrink: 0;
    order: 1; /* Place after line number */
    visibility: hidden; /* Hidden by default but takes space */
}

.line-number .fold-icon:hover {
    color: var(--monokai-fg);
}

.line-number.foldable .fold-icon {
    visibility: visible; /* Show for foldable lines */
}

.syntax-highlight {
    position: absolute;
    left: 50px;
    top: 0;
    right: 0;
    bottom: 0;
    margin: 0 !important;
    padding: 54px 10px 40px 10px !important; /* Top: 44px + 10px; Bottom: 30px + 10px */
    overflow: auto;
    font-family: 'Fira Code', monospace;
    font-size: 14px;
    line-height: 21px; /* Fixed line height in px for precision */
    white-space: pre;
    word-break: normal;
    overflow-wrap: normal;
    tab-size: 2;
    -moz-tab-size: 2;
    pointer-events: none;
    color: transparent;
    border-radius: 0 !important;
    background: transparent !important;
    z-index: 1;
    scrollbar-width: none;
    -ms-overflow-style: none;
    box-sizing: border-box;
    height: 100%;
    transition: padding-top 0.2s ease-out;
}

.json-tool-container.search-active .syntax-highlight {
    padding-top: 130px !important;
}

.syntax-highlight::-webkit-scrollbar {
    display: none;
}

.syntax-highlight code {
    display: block;
    font-family: inherit;
    font-size: inherit;
    margin: 0;
    padding: 0;
    line-height: inherit;
    white-space: inherit;
    word-break: inherit;
    overflow-wrap: inherit;
    tab-size: inherit;
    -moz-tab-size: inherit;
}

.syntax-highlight .hl-key { color: var(--monokai-blue); }
.syntax-highlight .hl-string { color: var(--monokai-yellow); }
.syntax-highlight .hl-number { color: var(--monokai-purple); }
.syntax-highlight .hl-boolean { color: var(--monokai-purple); }
.syntax-highlight .hl-null { color: var(--monokai-red); }
.syntax-highlight .hl-bracket { color: var(--monokai-fg); }
.syntax-highlight .hl-comma { color: var(--monokai-fg); }
.syntax-highlight .hl-colon { color: var(--monokai-fg); }

/* Rainbow Brackets */
.syntax-highlight .hl-bracket-0 { color: var(--monokai-yellow); }
.syntax-highlight .hl-bracket-1 { color: var(--monokai-purple); }
.syntax-highlight .hl-bracket-2 { color: var(--monokai-blue); }
.syntax-highlight .hl-bracket-3 { color: var(--monokai-green); }

#jsonInput {
    position: absolute;
    left: 50px;
    top: 0;
    right: 0;
    bottom: 0;
    height: 100%;
    width: calc(100% - 50px);
    box-sizing: border-box;
    background: transparent;
    border: none;
    color: var(--monokai-fg);
    -webkit-text-fill-color: transparent;
    padding: 54px 10px 40px 10px; /* Top: 44px + 10px; Bottom: 30px + 10px */
    resize: none;
    outline: none;
    white-space: pre;
    word-break: normal;
    overflow-wrap: normal;
    overflow: auto;
    font-family: 'Fira Code', monospace;
    font-size: 14px;
    line-height: 21px; /* Fixed line height in px for precision */
    tab-size: 2;
    caret-color: var(--monokai-fg);
    z-index: 2;
    transition: padding-top 0.2s ease-out;
}

.json-tool-container.search-active #jsonInput {
    padding-top: 130px;
}

#jsonInput::placeholder {
    -webkit-text-fill-color: var(--monokai-comment);
    opacity: 1;
}

#jsonInput::selection {
    background: rgba(102, 217, 239, 0.3);
    -webkit-text-fill-color: var(--monokai-fg);
}

/* Error Markers */
/* Error Line Number Styling */
.line-number.error::after {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--monokai-red);
    border-radius: 50%;
    margin-left: 4px;
    flex-shrink: 0;
    box-shadow: 0 0 4px var(--monokai-red);
    /* order defaults to 0, which places it after text (order 0) but before icon (order 1) if icon exists */
}

/* Tree View Styling */
.tree-view, .table-view {
    padding: 74px 20px 50px 20px; /* Top: 54 + 20, Bottom: 30 + 20 */
    overflow: auto;
    height: 100%;
    box-sizing: border-box;
    transition: padding-top 0.2s ease-out;
}

.json-tool-container.search-active .tree-view,
.json-tool-container.search-active .table-view {
    padding-top: 140px; /* 130 + 10 */
}

.json-tree {
    font-family: 'Fira Code', monospace;
    font-size: 14px;
}

.json-node {
    margin-left: 20px;
    position: relative;
}

.json-key {
    color: var(--monokai-blue);
    cursor: pointer;
}

.json-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-right: 4px;
    color: var(--monokai-comment);
    cursor: pointer;
    transition: transform 0.2s ease;
    font-size: 0.8rem;
}

.json-toggle:hover {
    color: var(--monokai-fg);
}

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

.json-toggle.invisible {
    visibility: hidden;
}

.json-string { color: var(--monokai-yellow); }
.json-number { color: var(--monokai-purple); }
.json-boolean { color: var(--monokai-purple); }
.json-null { color: var(--monokai-red); }

.json-bracket { color: var(--monokai-fg); }
.json-colon { color: var(--monokai-fg); margin-right: 5px; }

/* Status Bar */
.status-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 20; /* Ensure strictly layered */
    height: 30px;
    
    /* Liquid Glass Effect */
    background: rgba(39, 40, 34, 0.7);
    backdrop-filter: blur(12px) saturate(150%);
    -webkit-backdrop-filter: blur(12px) saturate(150%);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.2);
    
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    font-size: 0.85rem;
    color: var(--monokai-comment);
}

.status-left, .status-right {
    display: flex;
    gap: 20px;
}

.cursor-position span {
    margin-right: 10px;
}

.json-status {
    display: flex;
    align-items: center;
    gap: 6px;
}

.json-status.valid { color: var(--monokai-green); }
.json-status.invalid { color: var(--monokai-red); }

/* Error Bar */
.error-bar {
    position: absolute;
    bottom: 30px; /* Directly above status bar */
    left: 0;
    right: 0;
    /* Use a solid but semi-transparent background to ensure readability over code */
    background: rgba(40, 40, 40, 0.95);
    border-top: 1px solid var(--monokai-red);
    padding: 8px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    
    /* Animation: slide up/down + opacity */
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    z-index: 30; /* Above status bar */
}

.error-bar.active {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* Force high z-index to ensure visibility if that was the issue */
.error-bar {
    z-index: 30; 
}

.error-content {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--monokai-red);
    overflow: hidden; /* Prevent text overflow */
    white-space: nowrap;
    text-overflow: ellipsis;
    max-width: 80%;
}

.error-message {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
}

.error-actions {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Responsive */
@media (max-width: 768px) {
    .tool-title { display: none; }
    .toolbar-center { gap: 5px; }
    .toolbar-btn span { display: none; }
    .toolbar-btn { padding: 6px; }
}
/* Liquid Glass Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.glass-modal {
    background: rgba(45, 45, 45, 0.85);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.15);
    box-shadow: 
        0 20px 50px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    width: 320px;
    padding: 24px;
    transform: scale(0.95);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-overlay.active .glass-modal {
    transform: scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--monokai-fg);
}

.modal-header i {
    color: var(--monokai-orange);
    font-size: 1.3rem;
}

.modal-body {
    color: rgba(248, 248, 242, 0.8);
    font-size: 0.95rem;
    line-height: 1.5;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 8px;
}

.modal-btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.modal-btn.cancel {
    background: transparent;
    color: var(--monokai-fg);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-btn.cancel:hover {
    background: rgba(255, 255, 255, 0.1);
}

.modal-btn.confirm {
    background: rgba(249, 38, 114, 0.8);
    color: #fff;
    box-shadow: 0 4px 12px rgba(249, 38, 114, 0.3);
}

.modal-btn.confirm:hover {
    background: var(--monokai-red);
    box-shadow: 0 6px 16px rgba(249, 38, 114, 0.4), 0 0 10px rgba(249, 38, 114, 0.2);
    transform: translateY(-1px);
}
