/* Reset và base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 16px;
    color: white;
}

.header h1 {
    font-size: 3rem;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.header h1 i {
    margin-right: 15px;
    color: #ffd700;
}

.header p {
    font-size: 1.2rem;
    opacity: 0.9;
    font-weight: 300;
}

/* Main content */
.main-content {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    overflow: hidden;
    margin-bottom: 30px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas: 
        "input-header output-header"
        "input-section output-section"
        "controls controls";
    min-height: 600px;
    max-width: 100%;
    box-sizing: border-box;
}

/* Section headers */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0;
    background: transparent;
    border: none;
    height: auto;
    box-sizing: border-box;
    overflow: hidden;
    margin-bottom: 10px;
}

.input-section .section-header {
    grid-area: input-header;
}

.output-section .section-header {
    grid-area: output-header;
}

.section-header h2 {
    font-size: 1.4rem;
    font-weight: 600;
    color: #495057;
    margin: 0;
    flex-shrink: 0;
}

.section-header h2 i {
    margin-right: 10px;
    color: #667eea;
}

.actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    max-width: 100%;
}

.section-header .actions {
    margin-bottom: 0;
}

.actions:not(.section-header .actions) {
    margin-bottom: 24px;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: filter 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn:hover {
    filter: brightness(1.15) saturate(1.1);
    transition: all 0.3s ease;
}

/* Primary - Format JSON (Main action) */
.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

/* Secondary - Clear, Example, Paste (Utility actions) */
.btn-secondary {
    background: linear-gradient(135deg, #6c757d 0%, #495057 100%);
    color: white;
}

/* Success - Copy, Download (Positive actions) */
.btn-success {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    color: white;
}

/* Info - Validate (Information action) */
.btn-info {
    background: linear-gradient(135deg, #17a2b8 0%, #6f42c1 100%);
    color: white;
}

/* Warning - Remove comments (Caution action) */
.btn-warning {
    background: linear-gradient(135deg, #ffc107 0%, #fd7e14 100%);
    color: white;
}

/* Danger - Delete/Remove actions */
.btn-danger {
    background: linear-gradient(135deg, #dc3545 0%, #e83e8c 100%);
    color: white;
}

/* Purple - Special features */
.btn-purple {
    background: linear-gradient(135deg, #6f42c1 0%, #a855f7 100%);
    color: white;
}

/* Orange - Highlight actions */
.btn-orange {
    background: linear-gradient(135deg, #fd7e14 0%, #ff922b 100%);
    color: white;
}

/* Teal - Alternative success */
.btn-teal {
    background: linear-gradient(135deg, #20c997 0%, #12b886 100%);
    color: white;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Input section */
.input-section {
    padding: 30px;
    grid-area: input-section;
    border-right: 1px solid #e9ecef;
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

#input-json {
    max-width: 100%;
    height: 388px;
    padding: 20px;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    transition: border-color 0.3s ease;
    overflow: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    word-break: break-all;
    box-sizing: border-box;
}

#input-json:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Error message */
.error-message {
    margin-top: 15px;
    padding: 15px;
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    border-radius: 8px;
    display: none;
    font-weight: 500;
}

.error-message.show {
    display: block;
}

/* Controls */
.controls {
    padding: 12px 30px 24px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    grid-area: controls;
}

.format-options {
    display: flex;
    gap: 30px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    align-items: center;
}

.indent-options, .validation-options {
    display: flex;
    align-items: center;
    gap: 8px;
}

.indent-options label, .validation-options label {
    font-weight: 500;
    color: #495057;
    white-space: nowrap;
}

.indent-options select, .validation-options select {
    padding: 6px 12px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font-size: 13px;
    background: white;
    color: #495057;
    cursor: pointer;
}

.indent-options select:focus, .validation-options select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.checkbox-container {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-weight: 500;
    color: #495057;
}

.checkbox-container input[type="checkbox"] {
    margin-right: 10px;
    transform: scale(1.2);
}

.format-buttons {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

/* Output section */
.output-section {
    padding: 30px;
    grid-area: output-section;
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

/* Search container */
.search-container {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    align-items: center;
}

.search-input {
    flex: 1;
    padding: 10px 15px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s ease;
}

.search-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#search-btn {
    padding: 12px 16px;
}

/* Stats container */
.stats-container {
    display: flex;
    gap: 20px;
    margin-top: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
    flex-wrap: wrap;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stat-label {
    font-size: 12px;
    color: #6c757d;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 16px;
    font-weight: 600;
    color: #495057;
}

.output-container {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
}

#output-json {
    width: 100%;
    max-width: 100%;
    height: 388px;
    padding: 20px;
    background: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 12px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.5;
    overflow-x: auto;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    word-break: break-all;
    box-sizing: border-box;
}

#output-json code {
    background: none;
    padding: 0;
    color: #495057;
}

/* Syntax highlighting */
.json-key {
    color: #0066cc;
    font-weight: 600;
}

.json-string {
    color: #008000;
}

.json-number {
    color: #ff6600;
}

.json-boolean {
    color: #cc0066;
    font-weight: 600;
}

.json-null {
    color: #999999;
    font-style: italic;
}

/* Footer */
.footer {
    text-align: center;
    color: white;
    padding: 30px 0;
}

.footer p {
    font-size: 1.1rem;
    margin-bottom: 20px;
    opacity: 0.9;
}

.features {
    display: flex;
    justify-content: center;
    gap: 30px;
    flex-wrap: wrap;
}

.features span {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    opacity: 0.8;
}

.features i {
    color: #ffd700;
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .header h1 {
        font-size: 2rem;
    }
    
    .main-content {
        grid-template-columns: 1fr;
        grid-template-areas: 
            "input-header"
            "input-section"
            "output-header"
            "output-section"
            "controls";
    }
    
    .input-section {
        border-right: none;
        border-bottom: 1px solid #e9ecef;
    }
    
    .input-section .section-header {
        border-right: none;
        border-bottom: 1px solid #e9ecef;
    }
    
    .section-header {
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
    }
    
    .actions {
        width: 100%;
        justify-content: flex-start;
    }
    
    .format-options {
        flex-direction: column;
        gap: 15px;
    }
    
    .format-buttons {
        flex-direction: column;
    }
    
    .features {
        flex-direction: column;
        gap: 15px;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.5rem;
    }
    
    .header p {
        font-size: 1rem;
    }
    
    .section-header,
    .input-section,
    .controls,
    .output-section {
        padding: 20px;
    }
    
    .btn {
        padding: 8px 16px;
        font-size: 13px;
    }
    
    #input-json,
    #output-json {
        height: 388px;
    }
}

/* Loading animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Success animation */
.success {
    color: #28a745 !important;
    animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
}

.toast {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    transform: translateX(100%);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-left: 4px solid;
    position: relative;
    overflow: hidden;
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast.success {
    border-left-color: #28a745;
    background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
}

.toast.error {
    border-left-color: #dc3545;
    background: linear-gradient(135deg, #f8d7da 0%, #f5c6cb 100%);
}

.toast.info {
    border-left-color: #17a2b8;
    background: linear-gradient(135deg, #d1ecf1 0%, #bee5eb 100%);
}

.toast.warning {
    border-left-color: #ffc107;
    background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
}

.toast-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.toast.success .toast-icon {
    color: #28a745;
}

.toast.error .toast-icon {
    color: #dc3545;
}

.toast.info .toast-icon {
    color: #17a2b8;
}

.toast.warning .toast-icon {
    color: #e67e22;
}

.toast-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.toast-title {
    font-weight: 600;
    font-size: 14px;
    color: #2c3e50;
    margin: 0;
}

.toast-message {
    font-size: 13px;
    color: #5a6c7d;
    margin: 0;
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    color: #6c757d;
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.toast-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #495057;
}

/* Toast progress bar */
.toast::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: currentColor;
    opacity: 0.3;
    animation: toast-progress 4s linear forwards;
}

.toast.success::after {
    color: #28a745;
}

.toast.error::after {
    color: #dc3545;
}

.toast.info::after {
    color: #17a2b8;
}

.toast.warning::after {
    color: #e67e22;
}

@keyframes toast-progress {
    from {
        width: 100%;
    }
    to {
        width: 0%;
    }
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #e9ecef;
    background: #f8f9fa;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    color: #495057;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 18px;
    color: #6c757d;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #495057;
}

.modal-body {
    padding: 24px;
}

.url-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 20px;
    transition: border-color 0.3s ease;
}

.url-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* Tree view styles */
.tree-view {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 14px;
    line-height: 1.5;
}

.tree-node {
    margin: 2px 0;
    cursor: pointer;
    user-select: none;
}

.tree-toggle {
    display: inline-block;
    width: 20px;
    height: 20px;
    text-align: center;
    margin: 0 4px;
    color: #6c757d;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 18px;
    font-size: 12px;
}

.tree-toggle:hover {
    background: #e9ecef;
    border-color: #adb5bd;
    color: #495057;
}

.tree-toggle i {
    font-size: 10px;
}

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

.tree-value {
    color: #008000;
}

.tree-value.number {
    color: #ff6600;
}

.tree-value.boolean {
    color: #cc0066;
    font-weight: 600;
}

.tree-value.null {
    color: #999999;
    font-style: italic;
}

.tree-children {
    margin-left: 20px;
    display: none;
}

.tree-children.expanded {
    display: block;
}

.tree-ellipsis {
    color: #6c757d;
    font-style: italic;
    margin: 0 4px;
}

/* Search highlighting */
mark {
    background: #ffeb3b;
    color: #333;
    border-radius: 3px;
    font-weight: 600;
}

/* Responsive toast */
@media (max-width: 768px) {
    .toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .toast {
        min-width: auto;
        width: 100%;
    }
    
    .modal-content {
        width: 95%;
        margin: 20px;
    }
    
    .modal-actions {
        flex-direction: column;
    }
}
