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

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

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

/* Header */
.header {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: #4f46e5;
}

.logo i {
    font-size: 2rem;
}

.nav {
    display: flex;
    gap: 2rem;
}

.nav-link {
    text-decoration: none;
    color: #6b7280;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    transition: all 0.2s ease;
}

.nav-link:hover,
.nav-link.active {
    color: #4f46e5;
    background: rgba(79, 70, 229, 0.1);
}

/* Main Content */
.main {
    flex: 1;
    padding: 2rem 0;
}

/* Hero Section */
.hero {
    text-align: center;
    margin-bottom: 3rem;
    color: white;
}

.hero-title {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: 1rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.hero-subtitle {
    font-size: 1.25rem;
    opacity: 0.9;
    max-width: 600px;
    margin: 0 auto;
}

/* Cards */
.card {
    background: white;
    border-radius: 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    margin-bottom: 2rem;
}

.card-header {
    padding: 2rem 2rem 1rem;
    border-bottom: 1px solid #f3f4f6;
}

.card-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: #1f2937;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.card-subtitle {
    color: #6b7280;
    font-size: 0.95rem;
}

/* Forms */
.analysis-form {
    padding: 2rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* Download buttons styling */
.form-row .btn {
    margin: 0;
    flex: 1;
}

#downloadSection .form-row {
    margin-top: 1rem;
}

/* Advanced data grid */
.data-grid-container {
    padding: 1.5rem;
}

.data-grid-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
}

.data-grid-toolbar .toolbar-left span {
    font-size: 0.95rem;
    color: #4b5563;
}

.data-grid-toolbar .toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.data-grid-toolbar .search-input {
    position: relative;
    display: flex;
    align-items: center;
    background: #f3f4f6;
    border-radius: 999px;
    padding: 0.35rem 0.75rem;
}

.data-grid-toolbar .search-input i {
    color: #6b7280;
    margin-right: 0.4rem;
}

.data-grid-toolbar .search-input input {
    border: none;
    background: transparent;
    outline: none;
    font-size: 0.95rem;
    min-width: 220px;
}

.data-grid {
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 1rem;
    overflow: hidden;
    min-height: 420px;
}

.tabulator {
    border: none;
    font-size: 0.9rem;
}

.tabulator .tabulator-header {
    background: #f9fafb;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}

.tabulator .tabulator-row:nth-child(even) {
    background-color: #fcfcfd;
}

.tabulator .tabulator-row:hover {
    background-color: #eef2ff;
}

.tabulator .tabulator-cell {
    border-right: 1px solid rgba(15, 23, 42, 0.04);
}

.table-preview {
    padding: 1.5rem;
}

.table-preview .table-info {
    margin-bottom: 1rem;
    color: #4b5563;
    font-size: 0.95rem;
}

.table-preview .table-wrapper {
    overflow-x: auto;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 0.75rem;
}

.table-preview table {
    width: 100%;
    border-collapse: collapse;
}

.table-preview thead {
    background: #f9fafb;
}

.table-preview th,
.table-preview td {
    padding: 0.75rem;
    border-bottom: 1px solid rgba(15, 23, 42, 0.05);
    font-size: 0.9rem;
    text-align: left;
}

.table-preview tbody tr:hover {
    background: #f5f3ff;
}

.table-preview .preview-actions {
    margin-top: 1.25rem;
    display: flex;
    justify-content: flex-end;
}

.table-preview .preview-actions .btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.data-grid-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    z-index: 200;
}

.data-grid-modal.open {
    display: flex;
}

.data-grid-modal-content {
    background: #fff;
    border-radius: 1.25rem;
    width: min(1400px, 96vw);
    height: min(90vh, 900px);
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 60px rgba(15, 23, 42, 0.25);
    padding: 1.5rem;
}

.data-grid-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.data-grid-modal-header h3 {
    margin-bottom: 0.25rem;
}

.modal-close {
    border: none;
    background: #f3f4f6;
    border-radius: 999px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
}

.modal-close:hover {
    background: #e0e7ff;
}

.data-grid-modal .data-grid {
    flex: 1;
    height: auto;
}

@media (max-width: 768px) {
    .data-grid-modal-content {
        width: 100%;
        height: 100%;
        border-radius: 0;
        padding: 1rem;
    }
}

.form-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.5rem;
}

.form-input,
.form-select {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 0.5rem;
    font-size: 1rem;
    transition: all 0.2s ease;
    background: white;
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.form-help {
    font-size: 0.875rem;
    color: #6b7280;
    margin-top: 0.25rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.btn-primary {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: white;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(79, 70, 229, 0.4);
}

.btn-secondary {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.btn-secondary:hover {
    background: #e5e7eb;
}

.btn-success {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

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

.btn-loader {
    display: none;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

.btn.loading .btn-loader {
    display: block;
}

.btn.loading span {
    display: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Summary Cards */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.summary-card {
    background: white;
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform 0.2s ease;
}

.summary-card:hover {
    transform: translateY(-2px);
}

.summary-icon {
    width: 60px;
    height: 60px;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #e0e7ff, #c7d2fe);
    color: #4f46e5;
    font-size: 1.5rem;
}

.summary-icon.active {
    background: linear-gradient(135deg, #dcfce7, #bbf7d0);
    color: #059669;
}

.summary-value {
    font-size: 2rem;
    font-weight: 700;
    color: #1f2937;
}

/* Special styling for page name to handle longer text */
#pageName {
    font-size: 1.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    line-height: 1.2;
}

.summary-label {
    color: #6b7280;
    font-size: 0.875rem;
    font-weight: 500;
}

/* Charts */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.chart-container {
    padding: 2rem;
    height: 300px;
}

/* Export Section */
.export-section {
    padding: 2rem;
}

.selector-header {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.column-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.column-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 0.5rem;
    transition: background 0.2s ease;
}

.column-item:hover {
    background: #f9fafb;
}

.column-checkbox {
    margin-top: 0.25rem;
}

.column-info h4 {
    font-size: 0.95rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.25rem;
}

.column-info p {
    font-size: 0.875rem;
    color: #6b7280;
}

.export-actions {
    display: flex;
    justify-content: center;
}

/* Data Table */
.table-container {
    padding: 2rem;
}

.table-info {
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: #f8fafc;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    color: #64748b;
}

.table-wrapper {
    overflow-x: auto;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    max-height: 500px;
    overflow-y: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th {
    background: #f8fafc;
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    color: #374151;
    border-bottom: 2px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table td {
    padding: 0.75rem;
    border-bottom: 1px solid #f1f5f9;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.data-table tr:hover {
    background: #f8fafc;
}

.data-table td.expandable {
    cursor: pointer;
    position: relative;
}

.data-table td.expandable:hover {
    background: #e2e8f0;
}

/* JSON Viewer with Syntax Highlighting */
.json-viewer {
    padding: 2rem;
    background: #0f172a;
    color: #e2e8f0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    max-height: 500px;
    overflow: auto;
    border-radius: 0.5rem;
}

.json-viewer pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
}

/* JSON Syntax Highlighting */
.json-key {
    color: #7dd3fc;
    font-weight: 500;
}

.json-string {
    color: #86efac;
}

.json-number {
    color: #fbbf24;
}

.json-boolean {
    color: #f472b6;
}

.json-null {
    color: #94a3b8;
}

.json-punctuation {
    color: #cbd5e1;
}

.json-brace {
    color: #e879f9;
    font-weight: bold;
}

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

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-overlay.show {
    display: flex;
}

.loading-content {
    text-align: center;
    color: white;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
    margin: 0 auto 1rem;
}

.loading-content h3 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.loading-content p {
    opacity: 0.8;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1100;
}

.toast {
    background: white;
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    padding: 1rem 1.5rem;
    margin-bottom: 1rem;
    min-width: 300px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transform: translateX(400px);
    transition: transform 0.3s ease;
}

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

.toast.success {
    border-left: 4px solid #10b981;
}

.toast.error {
    border-left: 4px solid #ef4444;
}

.toast.warning {
    border-left: 4px solid #f59e0b;
}

.toast-icon {
    font-size: 1.25rem;
}

.toast.success .toast-icon {
    color: #10b981;
}

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

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

.toast-content h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.toast-content p {
    font-size: 0.875rem;
    color: #6b7280;
}

/* Footer */
.footer {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    text-align: center;
    padding: 2rem 0;
    margin-top: auto;
}

/* Responsive Design */
@media (max-width: 768px) {
    .hero-title {
        font-size: 2rem;
    }
    
    .hero-subtitle {
        font-size: 1rem;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .charts-grid {
        grid-template-columns: 1fr;
    }
    
    .summary-grid {
        grid-template-columns: 1fr;
    }
    
    .header-content {
        flex-direction: column;
        gap: 1rem;
    }
    
    .nav {
        gap: 1rem;
    }
    
    .container {
        padding: 0 15px;
    }
}

@media (max-width: 480px) {
    .card {
        margin: 0 -15px 2rem;
        border-radius: 0;
    }
    
    .analysis-form,
    .card-header,
    .export-section,
    .json-viewer {
        padding: 1.5rem;
    }
    
    .chart-container {
        padding: 1rem;
        height: 250px;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.results-section {
    animation: fadeIn 0.5s ease-out;
}

/* Scrollbar Styling */
.column-list::-webkit-scrollbar,
.json-viewer::-webkit-scrollbar {
    width: 8px;
}

.column-list::-webkit-scrollbar-track,
.json-viewer::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.column-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.json-viewer::-webkit-scrollbar-thumb {
    background: #475569;
    border-radius: 4px;
}

.column-list::-webkit-scrollbar-thumb:hover,
.json-viewer::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}
