/* ============================================
   JSON Editor & Formatter - Styles
   ============================================ */

/* Reset & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

/* Container Layout */
.container {
    max-width: 1600px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 160px 1fr 160px;
    gap: 20px;
    align-items: start;
}

/* Responsive Design for Ads */
@media (max-width: 1200px) {
    .container {
        grid-template-columns: 1fr;
    }
    .ad-space.side {
        display: none;
    }
    /* Show in-content ad on mobile */
    .ad-space.in-content {
        display: block;
    }
}

@media (max-width: 768px) {
    /* Adjust bottom ad for mobile */
    .ad-space.bottom {
        min-height: 50px;
        padding: 10px;
    }
    
    /* Make in-content ad responsive */
    .ad-space.in-content {
        min-height: 50px;
        padding: 10px;
    }
}

/* Advertisement Spaces - Google AdSense Compatible */
.ad-space {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    overflow: hidden;
    position: relative;
    transition: background 0.3s ease;
}

/* When ad is loaded, use white background for ad container */
.ad-space.ad-loaded {
    background: white;
}

/* Fallback for browsers that don't support :has() */
.ad-space:has(.adsbygoogle:not(:empty)) {
    background: white;
}

/* Sidebar Ad Spaces (Skyscraper 160x600) */
.ad-space.side {
    position: sticky;
    top: 20px;
    min-height: 600px;
    width: 160px;
    max-width: 160px;
}

/* Bottom Ad Space (Leaderboard 728x90) */
.ad-space.bottom {
    grid-column: 1 / -1;
    min-height: 90px;
    width: 100%;
    max-width: 728px;
    margin: 20px auto 0;
    padding: 15px;
}

/* In-Content Ad Space (Responsive) */
.ad-space.in-content {
    width: 100%;
    min-height: 100px;
    margin: 20px 0;
    padding: 15px;
}

.ad-space.in-content .ad-placeholder {
    min-height: 100px;
}

/* Google AdSense Ad Container Styling */
.ad-space .adsbygoogle {
    display: block;
    width: 100%;
    height: 100%;
    min-height: inherit;
}

/* Ensure proper ad rendering */
.ad-space.side .adsbygoogle {
    width: 160px;
    min-height: 600px;
}

.ad-space.bottom .adsbygoogle {
    width: 100%;
    min-height: 90px;
}

.ad-space.in-content .adsbygoogle {
    width: 100%;
    min-height: 100px;
}

/* Ad Placeholder Visibility - Controlled by JavaScript */
/* Placeholders are shown by default and hidden when ads load */
.ad-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.7);
    padding: 20px;
    z-index: 1;
}

/* Hide placeholder when ad has loaded (JavaScript will handle this) */
.ad-placeholder.hidden {
    display: none !important;
}

/* Fallback: Hide placeholder if ad container has significant height */
.ad-space .adsbygoogle[style*="height"]:not([style*="height: 0"]) ~ .ad-placeholder {
    display: none;
}

/* Placeholder Icon */
.ad-placeholder-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
    filter: brightness(0) invert(1);
}

/* Placeholder Text */
.ad-placeholder-text {
    font-size: 13px;
    line-height: 1.5;
    text-align: center;
}

.ad-placeholder-text strong {
    color: rgba(255, 255, 255, 0.9);
    font-weight: 600;
    display: block;
    margin-bottom: 4px;
}

.ad-placeholder-size {
    color: rgba(255, 255, 255, 0.6);
    font-size: 11px;
}

/* Bottom ad placeholder - horizontal layout */
.ad-space.bottom .ad-placeholder {
    flex-direction: row;
    gap: 15px;
    min-height: 90px;
}

.ad-space.bottom .ad-placeholder-icon {
    font-size: 32px;
    margin-bottom: 0;
    filter: brightness(0) invert(1);
    opacity: 0.5;
}

/* Main Content Area */
.main-content {
    background: white;
    border-radius: 16px;
    padding: 30px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

/* Header */
header {
    margin-bottom: 30px;
    text-align: center;
}

h1 {
    color: #667eea;
    margin-bottom: 8px;
    font-size: 2.5rem;
    font-weight: 700;
}

.subtitle {
    color: #666;
    font-size: 1.1rem;
}

/* Toolbar */
.toolbar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 2px solid #f0f0f0;
}

/* Buttons */
.btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 11px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(102, 126, 234, 0.4);
}

.btn:active {
    transform: translateY(0);
}

.btn-success {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    box-shadow: 0 4px 15px rgba(56, 239, 125, 0.3);
}

.btn-success:hover {
    box-shadow: 0 6px 25px rgba(56, 239, 125, 0.4);
}

.btn-warning {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    box-shadow: 0 4px 15px rgba(245, 87, 108, 0.3);
}

.btn-warning:hover {
    box-shadow: 0 6px 25px rgba(245, 87, 108, 0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    box-shadow: 0 4px 15px rgba(79, 172, 254, 0.3);
}

.btn-secondary:hover {
    box-shadow: 0 6px 25px rgba(79, 172, 254, 0.4);
}

/* Editor Layout */
.editor-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

@media (max-width: 900px) {
    .editor-layout {
        grid-template-columns: 1fr;
    }
}

/* Editor Panels */
.editor-panel {
    display: flex;
    flex-direction: column;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    overflow: hidden;
    background: #fafafa;
}

.panel-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 14px 18px;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.panel-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.panel-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
    font-weight: 600;
}

.panel-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.panel-btn.primary {
    background: rgba(255, 255, 255, 0.95);
    color: #667eea;
    border: 1px solid white;
}

.panel-btn.primary:hover {
    background: white;
}

/* Textarea */
textarea {
    width: 100%;
    height: 500px;
    border: none;
    padding: 20px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    resize: vertical;
    background: white;
    color: #333;
    line-height: 1.6;
}

textarea:focus {
    outline: none;
}

/* Tree View */
.tree-view {
    width: 100%;
    height: 500px;
    overflow: auto;
    padding: 20px;
    background: white;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 14px;
    color: #333;
}

.tree-node {
    margin-left: 20px;
    margin-top: 4px;
}

.tree-item {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 3px 0;
    cursor: pointer;
    user-select: none;
}

.tree-toggle {
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #667eea;
    color: white;
    border-radius: 3px;
    font-size: 11px;
    font-weight: bold;
    flex-shrink: 0;
    margin-top: 2px;
}

.tree-toggle.collapsed::before {
    content: '+';
}

.tree-toggle.expanded::before {
    content: '−';
}

.tree-key {
    color: #881391;
    font-weight: 600;
}

.tree-value {
    color: #1A1AA6;
}

.tree-value.string {
    color: #C41A16;
}

.tree-value.number {
    color: #1C00CF;
}

.tree-value.boolean {
    color: #0C6491;
}

.tree-value.null {
    color: #808080;
}

.tree-bracket {
    color: #666;
    font-weight: bold;
}

.tree-children {
    display: block;
}

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

/* Status Bar */
.status-bar {
    background: #f8f9fa;
    padding: 12px 18px;
    border-radius: 8px;
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: #666;
    flex-wrap: wrap;
    gap: 15px;
}

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

.status-icon {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #38ef7d;
}

.status-icon.error {
    background: #f5576c;
}

/* Messages */
.message {
    padding: 12px 18px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
    display: none;
}

.message.success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
    display: block;
}

.message.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    display: block;
}

/* Share Modal */
.share-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.share-modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 16px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
    font-size: 1.5rem;
    font-weight: 700;
    color: #667eea;
    margin-bottom: 20px;
}

.modal-body {
    margin-bottom: 20px;
}

.share-option {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.3s;
    border: 2px solid transparent;
}

.share-option:hover {
    background: #e9ecef;
    border-color: #667eea;
}

.share-option-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.share-option-desc {
    font-size: 13px;
    color: #666;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.link-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    font-family: monospace;
    margin-top: 10px;
}

/* Footer */
footer {
    text-align: center;
    margin-top: 30px;
    color: white;
    font-size: 14px;
}

footer a {
    color: white;
    text-decoration: underline;
}
