/* Custom CSS for JSON Compare Tool */

/* Base styles and animations */
@keyframes shimmer {
    0% {
        background-position: -1000px 0;
    }
    100% {
        background-position: 1000px 0;
    }
}

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

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

@keyframes fadeInScale {
    from {
        transform: scale(0.95);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    transition: background 0.2s ease;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.5);
}

.dark ::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

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

.dark ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

/* JSON Editor styling */
.json-editor {
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    line-height: 24px;
    tab-size: 2;
    -moz-tab-size: 2;
}

.json-editor:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Diff highlighting styles */
.diff-added {
    background-color: rgba(34, 197, 94, 0.1);
    border-left: 3px solid #22c55e;
    padding-left: 8px;
}

.diff-removed {
    background-color: rgba(239, 68, 68, 0.1);
    border-left: 3px solid #ef4444;
    padding-left: 8px;
    text-decoration: line-through;
}

.diff-modified {
    background-color: rgba(245, 158, 11, 0.1);
    border-left: 3px solid #f59e0b;
    padding-left: 8px;
}

.diff-moved {
    background-color: rgba(59, 130, 246, 0.1);
    border-left: 3px solid #3b82f6;
    padding-left: 8px;
}

.diff-type-changed {
    background-color: rgba(168, 85, 247, 0.1);
    border-left: 3px solid #a855f7;
    padding-left: 8px;
}

/* Loading states */
.loading-shimmer {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 1000px 100%;
    animation: shimmer 2s infinite;
}

.dark .loading-shimmer {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
    background-size: 1000px 100%;
}

/* Drop zone styling */
.drop-zone-active {
    border-color: #3b82f6 !important;
    background-color: rgba(59, 130, 246, 0.05) !important;
    transform: scale(1.02);
    transition: all 0.2s ease;
}

.dark .drop-zone-active {
    background-color: rgba(59, 130, 246, 0.1) !important;
}

/* Toast notification styling */
.toast-notification {
    animation: slideInFromTop 0.3s ease-out;
    transition: all 0.3s ease;
}

.toast-notification.removing {
    animation: slideInFromTop 0.3s ease-out reverse;
}

/* Button hover effects */
.btn-hover-lift {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-hover-lift:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
}

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

/* Panel animations */
.panel-enter {
    animation: fadeInScale 0.3s ease-out;
}

.panel-slide-left {
    animation: slideInFromLeft 0.4s ease-out;
}

.panel-slide-right {
    animation: slideInFromRight 0.4s ease-out;
}

@keyframes slideInFromLeft {
    from {
        transform: translateX(-20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideInFromRight {
    from {
        transform: translateX(20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* JSON syntax highlighting */
.json-key {
    color: #059669;
    font-weight: 500;
}

.dark .json-key {
    color: #34d399;
}

.json-string {
    color: #dc2626;
}

.dark .json-string {
    color: #f87171;
}

.json-number {
    color: #2563eb;
}

.dark .json-number {
    color: #60a5fa;
}

.json-boolean {
    color: #7c3aed;
}

.dark .json-boolean {
    color: #a78bfa;
}

.json-null {
    color: #6b7280;
}

.dark .json-null {
    color: #9ca3af;
}

.json-bracket {
    color: #374151;
    font-weight: bold;
}

.dark .json-bracket {
    color: #d1d5db;
}

/* Diff container styling */
.diff-container {
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.5;
}

.diff-line {
    display: block;
    padding: 2px 8px;
    white-space: pre-wrap;
    word-break: break-all;
}

.diff-line-number {
    display: inline-block;
    width: 40px;
    text-align: right;
    color: #6b7280;
    margin-right: 16px;
    user-select: none;
}

.dark .diff-line-number {
    color: #9ca3af;
}

/* Results table styling */
.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.results-table th,
.results-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

.dark .results-table th,
.dark .results-table td {
    border-bottom-color: #374151;
}

.results-table th {
    background-color: #f9fafb;
    font-weight: 600;
    color: #374151;
}

.dark .results-table th {
    background-color: #1f2937;
    color: #f3f4f6;
}

.results-table tr:hover {
    background-color: #f3f4f6;
}

.dark .results-table tr:hover {
    background-color: #374151;
}

/* Status indicator styling */
.status-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 8px;
}

.status-indicator.success {
    background-color: #22c55e;
}

.status-indicator.error {
    background-color: #ef4444;
}

.status-indicator.warning {
    background-color: #f59e0b;
}

.status-indicator.info {
    background-color: #3b82f6;
}

/* Pulse animation for status indicators */
@keyframes pulse-ring {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    }
    70% {
        transform: scale(1);
        box-shadow: 0 0 0 10px rgba(34, 197, 94, 0);
    }
    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
    }
}

.status-indicator.pulse {
    animation: pulse-ring 2s infinite;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .json-editor {
        font-size: 12px;
    }

    .diff-container {
        font-size: 12px;
    }

    .diff-line-number {
        width: 30px;
        margin-right: 8px;
    }

    /* Mobile menu improvements */
    #mobileMenuPanel {
        width: 100%;
        max-width: 320px;
    }

    /* Stack navigation buttons on very small screens */
    .hidden.md\\:flex .gap-2 {
        flex-direction: column;
        gap: 0.5rem !important;
    }

    .hidden.md\\:flex .text-sm {
        font-size: 0.75rem;
    }

    .hidden.md\\:flex .px-3 {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Ensure header is responsive */
    header .container {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* Tool buttons responsive sizing */
    .btn-hover-lift {
        min-height: 2.5rem;
    }

    /* Mobile-friendly font sizes */
    h1 {
        font-size: 1.875rem;
        line-height: 2.25rem;
    }

    h2 {
        font-size: 1.5rem;
        line-height: 2rem;
    }

    h3 {
        font-size: 1.25rem;
        line-height: 1.75rem;
    }

    /* Improve touch targets */
    button, .btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Mobile card spacing */
    .bg-white, .dark\\:bg-slate-800 {
        margin-bottom: 1rem;
    }

    /* Mobile grid improvements */
    .grid-cols-1 {
        grid-template-columns: repeat(1, minmax(0, 1fr));
    }

    /* Mobile text adjustments */
    .text-lg {
        font-size: 1rem;
        line-height: 1.5rem;
    }

    .text-xl {
        font-size: 1.125rem;
        line-height: 1.75rem;
    }

    /* Mobile form improvements */
    input, textarea, select {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    /* Mobile table improvements */
    .results-table {
        font-size: 12px;
    }

    .results-table th,
    .results-table td {
        padding: 8px 4px;
    }

    /* Mobile scroll improvements */
    .overflow-x-auto {
        -webkit-overflow-scrolling: touch;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    /* Further reduce mobile menu panel width */
    #mobileMenuPanel {
        width: 100%;
    }

    /* Stack header elements */
    header .flex.items-center.justify-between {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Smaller text for very small screens */
    .text-xl {
        font-size: 1rem;
    }

    h1 {
        font-size: 1.5rem;
        line-height: 2rem;
    }

    /* Compact mobile menu buttons */
    #mobileMenuPanel .px-4 {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    #mobileMenuPanel .py-3 {
        padding-top: 0.75rem;
        padding-bottom: 0.75rem;
    }

    /* Ensure buttons stay touchable */
    button, .btn {
        min-height: 48px;
    }

    /* More compact spacing */
    .space-y-2 > * + * {
        margin-top: 0.5rem;
    }

    /* Mobile-friendly panels */
    .p-8 {
        padding: 1rem;
    }

    .p-6 {
        padding: 0.75rem;
    }

    .p-4 {
        padding: 0.5rem;
    }
}

/* Landscape mobile improvements */
@media (max-width: 768px) and (orientation: landscape) {
    /* Reduce header height in landscape */
    header .h-16 {
        height: 3rem;
    }

    /* Compact mobile menu in landscape */
    #mobileMenuPanel {
        width: 280px;
    }
}

/* Touch device improvements */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .hover\\:scale-105:hover {
        transform: none;
    }

    .hover\\:bg-gray-100:hover {
        background-color: inherit;
    }

    /* Ensure buttons have clear press states */
    button:active {
        transform: scale(0.98);
    }
}

/* Print styles */
@media print {
    .no-print {
        display: none !important;
    }

    .diff-container {
        font-size: 10px;
        line-height: 1.2;
    }

    .json-editor {
        font-size: 10px;
    }

    /* Ensure proper colors for printing */
    .diff-added {
        background-color: #e6ffed !important;
        color: #000 !important;
    }

    .diff-removed {
        background-color: #ffebe6 !important;
        color: #000 !important;
    }

    .diff-modified {
        background-color: #fffbeb !important;
        color: #000 !important;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .diff-added {
        background-color: #000 !important;
        color: #0f0 !important;
        border-left-color: #0f0 !important;
    }

    .diff-removed {
        background-color: #000 !important;
        color: #f00 !important;
        border-left-color: #f00 !important;
    }

    .diff-modified {
        background-color: #000 !important;
        color: #ff0 !important;
        border-left-color: #ff0 !important;
    }
}

/* Focus styles for better keyboard navigation */
.json-editor:focus-visible,
.upload-btn:focus-visible,
.format-btn:focus-visible,
button:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Custom selection colors */
::selection {
    background-color: rgba(59, 130, 246, 0.2);
}

.dark ::selection {
    background-color: rgba(59, 130, 246, 0.3);
}

/* Hide scrollbars for line numbers */
.line-numbers::-webkit-scrollbar {
    display: none;
}

.line-numbers {
    -ms-overflow-style: none;
    scrollbar-width: none;
    line-height: 24px;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

/* Ensure line number divs have exact same height */
.line-numbers div {
    height: 24px;
    line-height: 24px;
    display: block;
}

/* Editor lines must match line number height exactly */
.json-editor .editor-line {
    height: 24px;
    line-height: 24px;
    display: block;
    box-sizing: border-box;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    margin: 0;
    padding: 0;
}

/* Ensure editor and line numbers have matching vertical alignment */
.line-numbers {
    padding-top: 8px !important;
    padding-bottom: 8px !important;
}

.json-editor {
    padding-top: 8px !important;
    padding-bottom: 8px !important;
}

/* Synchronized scrolling for line numbers and editors */
.json-editor-container {
    position: relative;
}

/* Ensure both line numbers and editor have synchronized scrolling */
.line-numbers,
.json-editor {
    scroll-behavior: smooth;
}

/* ContentEditable Editor Styling */
.json-editor[contenteditable="true"] {
    cursor: text;
    user-select: text;
    -webkit-user-modify: read-write;
    overflow-wrap: break-word;
    word-wrap: break-word;
    background-image: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent 23px,
        rgba(0, 0, 0, 0.03) 23px,
        rgba(0, 0, 0, 0.03) 24px
    );
    background-size: 100% 24px;
    background-position: 0 8px;
}

.dark .json-editor[contenteditable="true"] {
    background-image: repeating-linear-gradient(
        to bottom,
        transparent,
        transparent 23px,
        rgba(255, 255, 255, 0.05) 23px,
        rgba(255, 255, 255, 0.05) 24px
    );
    background-position: 0 8px;
}

.json-editor[contenteditable="true"]:empty:before {
    content: attr(data-placeholder);
    color: #9ca3af;
    pointer-events: none;
    position: absolute;
}

.dark .json-editor[contenteditable="true"]:empty:before {
    content: attr(data-placeholder);
    color: #6b7280;
}

/* Inline Diff Highlighting for ContentEditable - Fixed Height */
.diff-inline-added,
.diff-inline-removed,
.diff-inline-moved,
.diff-inline-type-changed {
    display: inline;
    background-color: rgba(34, 197, 94, 0.15);
    color: #166534;
    padding: 2px 0;
    margin: 0;
    border-radius: 2px;
    position: relative;
    transition: background-color 0.2s ease;
    line-height: 24px;
    vertical-align: baseline;
    box-sizing: border-box;
}

.dark .diff-inline-added {
    background-color: rgba(34, 197, 94, 0.25);
    color: #86efac;
}

.diff-inline-added::before {
    content: "+";
    color: #22c55e;
    font-weight: bold;
    margin-right: 4px;
    opacity: 0.7;
}

.diff-inline-removed {
    background-color: rgba(239, 68, 68, 0.15);
    color: #991b1b;
    text-decoration: line-through;
}

.dark .diff-inline-removed {
    background-color: rgba(239, 68, 68, 0.25);
    color: #fca5a5;
}

.diff-inline-removed::before {
    content: "-";
    color: #ef4444;
    font-weight: bold;
    margin-right: 4px;
    opacity: 0.7;
}

.diff-inline-moved {
    background-color: rgba(59, 130, 246, 0.15);
    color: #1e40af;
}

.dark .diff-inline-moved {
    background-color: rgba(59, 130, 246, 0.25);
    color: #93c5fd;
}

.diff-inline-moved::before {
    content: "↔";
    color: #3b82f6;
    font-weight: bold;
    margin-right: 4px;
    opacity: 0.7;
}

.diff-inline-type-changed {
    background-color: rgba(168, 85, 247, 0.15);
    color: #6b21a8;
}

.dark .diff-inline-type-changed {
    background-color: rgba(168, 85, 247, 0.25);
    color: #d8b4fe;
}

.diff-inline-type-changed::before {
    content: "⊕";
    color: #a855f7;
    font-weight: bold;
    margin-right: 4px;
    opacity: 0.7;
}

/* Modified lines container - fixed height */
.diff-inline-modified {
    display: inline;
    background: none;
    padding: 2px 0;
    margin: 0;
    line-height: 24px;
    position: relative;
    vertical-align: baseline;
    box-sizing: border-box;
}

.diff-inline-modified::before {
    content: "~";
    color: #f59e0b;
    font-weight: bold;
    margin-right: 4px;
    opacity: 0.7;
}

/* Old and new values inside modified lines - fixed height */
.diff-inline-old,
.diff-inline-new {
    display: inline;
    padding: 2px 0;
    margin: 0;
    line-height: 24px;
    border-radius: 2px;
    box-sizing: border-box;
    vertical-align: baseline;
}

.diff-inline-old {
    background-color: rgba(239, 68, 68, 0.15);
    color: #991b1b;
    text-decoration: line-through;
    margin-right: 2px;
}

.dark .diff-inline-old {
    background-color: rgba(239, 68, 68, 0.25);
    color: #fca5a5;
}

.diff-inline-new {
    background-color: rgba(34, 197, 94, 0.15);
    color: #166534;
    margin-left: 2px;
}

.dark .diff-inline-new {
    background-color: rgba(34, 197, 94, 0.25);
    color: #86efac;
}

/* Hover effects for inline diffs */
.diff-inline-added:hover,
.diff-inline-removed:hover,
.diff-inline-modified:hover,
.diff-inline-moved:hover,
.diff-inline-type-changed:hover {
    filter: brightness(1.1);
    transform: scale(1.01);
}

/* Animation for diff updates */
@keyframes diffHighlight {
    0% {
        background-color: rgba(59, 130, 246, 0.3);
        transform: scale(1.02);
    }
    100% {
        transform: scale(1);
    }
}

.diff-highlight-new {
    animation: diffHighlight 0.3s ease-out;
}

/* Cursor and selection styling for contenteditable */
.json-editor[contenteditable="true"] {
    caret-color: #3b82f6;
}

.dark .json-editor[contenteditable="true"] {
    caret-color: #60a5fa;
}

/* Prevent text selection during drag operations */
.json-editor.dragging {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Improved focus styling */
.json-editor[contenteditable="true"]:focus {
    outline: none;
    box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.1);
    background-color: rgba(255, 255, 255, 0.5);
}

.dark .json-editor[contenteditable="true"]:focus {
    background-color: rgba(30, 41, 59, 0.3);
}

/* Tooltip styling */
.tooltip {
    position: relative;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #1f2937;
    color: #f3f4f6;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1000;
}

.tooltip:hover::after {
    opacity: 1;
}

/* Error message styling */
.error-message {
    background-color: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 6px;
    padding: 8px 12px;
    color: #dc2626;
    font-size: 12px;
    margin-top: 4px;
}

.dark .error-message {
    background-color: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    color: #f87171;
}

/* Success message styling */
.success-message {
    background-color: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 6px;
    padding: 8px 12px;
    color: #16a34a;
    font-size: 12px;
    margin-top: 4px;
}

.dark .success-message {
    background-color: rgba(34, 197, 94, 0.2);
    border-color: rgba(34, 197, 94, 0.4);
    color: #22c55e;
}