/* Reset and base styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --success-color: #10b981;
    --error-color: #ef4444;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --border-radius: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
}

/* Main content */
main {
    flex: 1;
    position: relative;
}

/* Upload section */
.upload-section {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 2rem;
}

.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    padding: 3rem 2rem;
    text-align: center;
    transition: all 0.2s ease;
    cursor: pointer;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--primary-color);
    background-color: #f0f7ff;
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.upload-icon {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
}

.drop-text {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--text-color);
}

.drop-subtext {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.drop-divider {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.file-button {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    background-color: var(--primary-color);
    color: white;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.file-button:hover {
    background-color: var(--primary-hover);
}

/* Preview section */
.preview-section {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.file-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.file-name {
    font-weight: 600;
    color: var(--text-color);
}

.file-type {
    padding: 0.25rem 0.75rem;
    background-color: #e0f2fe;
    color: #0369a1;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
}

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

.preview-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.row-count {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Pagination controls */
.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background-color: var(--bg-color);
    border-radius: 8px;
}

.pagination-btn {
    padding: 0.5rem 1rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.pagination-btn:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.page-info {
    color: var(--text-color);
    font-size: 0.875rem;
    font-weight: 500;
    min-width: 100px;
    text-align: center;
}

/* Table styles */
.table-container {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 60vh;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

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

thead {
    background-color: #f8fafc;
    position: sticky;
    top: 0;
    z-index: 1;
}

th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

th {
    font-weight: 600;
    color: var(--text-color);
}

td {
    color: var(--text-muted);
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background-color: #f8fafc;
}

.table-hint {
    color: var(--text-muted);
    font-size: 0.8125rem;
    text-align: center;
    margin-top: 0.5rem;
    margin-bottom: 1rem;
}

/* Raw Editor Section */
.editor-section {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.editor-error {
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
}

.editor-error p {
    color: #dc2626;
    font-size: 0.875rem;
    margin: 0;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
    word-break: break-word;
}

.editor-container {
    display: flex;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1.5rem;
    height: 50vh;
}

.editor-line-numbers {
    background-color: #f1f5f9;
    padding: 0.75rem 0.5rem;
    text-align: right;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
    font-size: 0.8125rem;
    line-height: 1.5;
    color: var(--text-muted);
    user-select: none;
    overflow-y: hidden;
    min-width: 3rem;
    white-space: pre;
    flex-shrink: 0;
}

.raw-editor {
    flex: 1;
    min-width: 0;
    padding: 0.75rem;
    border: none;
    resize: none;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;
    font-size: 0.8125rem;
    line-height: 1.5;
    color: var(--text-color);
    background-color: var(--card-bg);
    overflow-y: auto;
    white-space: pre;
}

.raw-editor:focus {
    outline: none;
}

.editor-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.retry-btn {
    flex: 1;
    padding: 0.75rem 1.5rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.retry-btn:hover {
    background-color: var(--primary-hover);
}

.retry-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.editor-actions .reset-button {
    flex: 1;
}

/* Export Mode Selection */
.export-mode-section {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.mode-card h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 0.5rem;
}

.complexity-info {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.mode-next-step {
    color: var(--text-color);
    font-size: 0.9375rem;
    margin-bottom: 0.75rem;
    line-height: 1.6;
}

.mode-tip {
    color: var(--text-muted);
    font-size: 0.8125rem;
    margin-bottom: 1.5rem;
    line-height: 1.5;
    padding: 0.5rem 0.75rem;
    background: var(--bg-color);
    border-radius: 6px;
    border-left: 3px solid var(--primary-color);
}

.mode-tip code {
    background: var(--border-color);
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-family: 'SF Mono', Monaco, 'Courier New', monospace;
    font-size: 0.8125rem;
}

.mode-options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.mode-option {
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-option:hover {
    border-color: var(--primary-color);
    background-color: #f8fafc;
}

.mode-option.selected {
    border-color: var(--primary-color);
    background-color: #eff6ff;
}

.mode-option-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.25rem;
}

.mode-radio {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    flex-shrink: 0;
    position: relative;
    transition: all 0.2s ease;
}

.mode-option.selected .mode-radio {
    border-color: var(--primary-color);
}

.mode-option.selected .mode-radio::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 10px;
    height: 10px;
    background-color: var(--primary-color);
    border-radius: 50%;
}

.mode-option strong {
    font-weight: 600;
    color: var(--text-color);
}

.mode-description {
    display: block;
    color: var(--text-color);
    font-size: 0.875rem;
    margin-left: 2.25rem;
}

.mode-note {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-left: 2.25rem;
    margin-top: 0.25rem;
}

.mode-actions {
    display: flex;
    gap: 0.75rem;
}

.proceed-btn {
    flex: 1;
    padding: 0.75rem 1.5rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.proceed-btn:hover {
    background-color: var(--primary-hover);
}

.cancel-btn {
    padding: 0.75rem 1.5rem;
    background-color: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cancel-btn:hover {
    background-color: var(--bg-color);
    color: var(--text-color);
}

/* Convert section */
.convert-section {
    margin-bottom: 1.5rem;
}

.convert-label {
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: var(--text-color);
}

.convert-buttons {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.convert-btn {
    padding: 0.75rem 1.5rem;
    background-color: var(--success-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.convert-btn:hover {
    filter: brightness(0.9);
}

.convert-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.reset-button {
    width: 100%;
    padding: 0.75rem;
    background-color: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.reset-button:hover {
    background-color: var(--bg-color);
    color: var(--text-color);
}

/* Loading overlay */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Error message */
.error-message {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--error-color);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    max-width: 90%;
    text-align: center;
    z-index: 1001;
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Footer */
footer {
    text-align: center;
    padding-top: 2rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Disclaimer */
.disclaimer {
    margin-bottom: 1.5rem;
    padding: 0.75rem 1rem;
    background-color: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    color: #166534;
    font-size: 0.8125rem;
}

.disclaimer p {
    margin: 0;
}

/* Feedback Section */
.feedback-section {
    margin-bottom: 1.5rem;
}

.feedback-toggle {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 0.875rem;
    text-decoration: underline;
    padding: 0;
}

.feedback-toggle:hover {
    color: var(--primary-hover);
}

.feedback-form-container {
    margin-top: 1rem;
}

.feedback-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 400px;
    margin: 0 auto;
}

.feedback-input,
.feedback-textarea {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.875rem;
    font-family: inherit;
    background: var(--card-bg);
}

.feedback-input:focus,
.feedback-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
}

.feedback-textarea {
    min-height: 80px;
    resize: vertical;
}

.feedback-submit {
    padding: 0.75rem 1.5rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.feedback-submit:hover {
    background-color: var(--primary-hover);
}

.feedback-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Feedback success message */
.feedback-success {
    color: var(--success-color);
    font-size: 0.875rem;
    text-align: center;
    padding: 0.75rem;
}

/* Preview Mode Toggle */
.preview-mode-toggle {
    display: flex;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 1rem;
    background: var(--card-bg);
}

.mode-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-btn:first-child {
    border-right: 1px solid var(--border-color);
}

.mode-btn.active {
    background: var(--primary-color);
    color: white;
}

.mode-btn:hover:not(.active) {
    background: #f1f5f9;
    color: var(--text-color);
}

.mode-btn-icon {
    flex-shrink: 0;
}

/* Multi-table Accordion */
.multi-table-accordion {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.accordion-item {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    background: var(--card-bg);
}

.accordion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.875rem 1rem;
    background: #f8fafc;
    cursor: pointer;
    transition: background 0.2s ease;
    user-select: none;
}

.accordion-header:hover {
    background: #f1f5f9;
}

.accordion-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.accordion-header .table-name {
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.9375rem;
}

.accordion-header .row-count {
    color: var(--text-muted);
    font-size: 0.8125rem;
    background: #e2e8f0;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.accordion-header .chevron {
    color: var(--text-muted);
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.accordion-item.expanded .accordion-header .chevron {
    transform: rotate(180deg);
}

.accordion-content {
    display: none;
    border-top: 1px solid var(--border-color);
    max-height: 250px;
    overflow: auto;
}

.accordion-item.expanded .accordion-content {
    display: block;
}

.accordion-content table {
    width: 100%;
    font-size: 0.8125rem;
    border-collapse: collapse;
}

.accordion-content th,
.accordion-content td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.accordion-content th {
    background: #f8fafc;
    font-weight: 600;
    color: var(--text-color);
    position: sticky;
    top: 0;
}

.accordion-content td {
    color: var(--text-muted);
}

.accordion-content tr:last-child td {
    border-bottom: none;
}

/* Responsive */
@media (max-width: 640px) {
    .container {
        padding: 1rem;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .drop-zone {
        padding: 2rem 1rem;
    }

    .upload-icon {
        width: 36px;
        height: 36px;
    }

    .drop-text {
        font-size: 1rem;
    }

    th, td {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }

    .convert-buttons {
        flex-direction: column;
    }

    .convert-btn {
        width: 100%;
        text-align: center;
    }
}
