@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #8B0000 0%, #5C0029 40%, #3D0020 70%, #1a0010 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 960px;
    margin: 0 auto;
}

/* ======== HEADER ======== */

header {
    text-align: center;
    color: white;
    margin-bottom: 40px;
}

.logo {
    width: 120px;
    height: auto;
    margin-bottom: 15px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    font-weight: 700;
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* ======== MAIN ======== */

main {
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

/* ======== STEP BADGE ======== */

.step-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    font-weight: 600;
    color: #374151;
    font-size: 1.05rem;
}

.step-number {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, #8B0000 0%, #5C0029 100%);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    flex-shrink: 0;
}

/* ======== QUERY SECTION ======== */

.query-section {
    margin-bottom: 30px;
    transition: all 0.3s ease;
}

.query-section.collapsed {
    opacity: 0.5;
    max-height: 70px;
    overflow: hidden;
    pointer-events: none;
}

label {
    display: block;
    font-weight: 500;
    margin-bottom: 10px;
    color: #4b5563;
}

textarea {
    width: 100%;
    padding: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
    resize: vertical;
    transition: border-color 0.3s, box-shadow 0.3s;
}

textarea:focus {
    outline: none;
    border-color: #8B0000;
    box-shadow: 0 0 0 3px rgba(139, 0, 0, 0.1);
}

button {
    width: 100%;
    padding: 15px;
    background: linear-gradient(135deg, #8B0000 0%, #5C0029 100%);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    margin-top: 15px;
    font-family: 'Inter', sans-serif;
}

button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(139, 0, 0, 0.4);
}

button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.loader {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #8B0000;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    display: inline-block;
}

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

    100% {
        transform: rotate(360deg);
    }
}

/* ======== SQL EDITOR SECTION ======== */

.sql-editor-section {
    margin-bottom: 30px;
}

.editor-info {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 1px solid #f59e0b;
    border-radius: 10px;
    padding: 14px 18px;
    margin-bottom: 18px;
    font-size: 0.92rem;
    color: #92400e;
    line-height: 1.5;
}

.info-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
    margin-top: 1px;
}

.editor-wrapper {
    position: relative;
}

.editor-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1e293b;
    border-radius: 10px 10px 0 0;
    padding: 10px 16px;
}

.editor-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
    color: #94a3b8;
    font-weight: 500;
}

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

.toolbar-btn {
    width: auto;
    padding: 5px 12px;
    margin: 0;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: #cbd5e1;
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s;
}

.toolbar-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: none;
    box-shadow: none;
}

#sqlEditor {
    width: 100%;
    min-height: 180px;
    padding: 18px;
    background: #0f172a;
    color: #e2e8f0;
    border: 2px solid #1e293b;
    border-top: none;
    border-radius: 0 0 10px 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.92rem;
    line-height: 1.6;
    resize: vertical;
    transition: border-color 0.3s;
}

#sqlEditor:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

#sqlEditor.edited {
    border-color: #f59e0b;
}

.edit-indicator {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    color: #92400e;
    padding: 10px 16px;
    border-radius: 8px;
    margin-top: 10px;
    font-size: 0.88rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ======== ACTION BUTTONS ======== */

.action-buttons {
    display: flex;
    gap: 12px;
    margin-top: 18px;
}

.execute-btn {
    flex: 2;
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    padding: 15px;
}

.execute-btn:hover:not(:disabled) {
    box-shadow: 0 10px 20px rgba(5, 150, 105, 0.4);
}

.back-btn {
    flex: 1;
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
    padding: 15px;
}

.back-btn:hover:not(:disabled) {
    background: #e5e7eb;
    box-shadow: none;
    transform: none;
}

/* ======== RESULT SECTION ======== */

.result-section,
.error-section {
    margin-top: 30px;
    padding: 20px;
    border-radius: 10px;
}

.result-section {
    background: #f0f9ff;
    border: 2px solid #0ea5e9;
}

.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.result-header h3 {
    color: #0369a1;
}

.correction-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #a855f7, #7c3aed);
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 600;
}

.correction-badge.pulse {
    animation: badgePulse 0.6s ease 3;
}

@keyframes badgePulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

.error-section {
    background: #fef2f2;
    border: 2px solid #ef4444;
}

.error-section h3 {
    color: #dc2626;
    margin-bottom: 10px;
}

.sql-preview {
    margin-bottom: 20px;
}

.sql-preview h4 {
    color: #334155;
    margin-bottom: 10px;
}

.sql-preview pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 15px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.88rem;
    font-family: 'JetBrains Mono', monospace;
    line-height: 1.5;
}

.download-btn {
    display: inline-block;
    padding: 12px 30px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    transition: background 0.3s, transform 0.2s;
}

.download-btn:hover {
    background: linear-gradient(135deg, #059669, #047857);
    transform: translateY(-2px);
}

/* ======== CORRECTIONS PANEL ======== */

.corrections-info {
    margin-top: 30px;
    border: 2px solid #a855f7;
    border-radius: 12px;
    overflow: hidden;
}

.corrections-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    background: linear-gradient(135deg, #f3e8ff 0%, #ede9fe 100%);
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    color: #6b21a8;
    transition: background 0.2s;
}

.corrections-header:hover {
    background: linear-gradient(135deg, #ede9fe 0%, #ddd6fe 100%);
}

.correction-count {
    background: #a855f7;
    color: white;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 700;
}

.toggle-arrow {
    margin-left: auto;
    font-size: 0.85rem;
}

.corrections-list {
    padding: 16px;
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.correction-item {
    background: #faf5ff;
    border: 1px solid #e9d5ff;
    border-radius: 10px;
    padding: 14px;
}

.correction-query {
    margin-bottom: 10px;
    font-size: 0.9rem;
    color: #374151;
}

.correction-diff {
    margin-bottom: 8px;
}

.diff-label {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.diff-label.diff-wrong {
    color: #dc2626;
}

.diff-label.diff-correct {
    color: #059669;
}

.diff-code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin-bottom: 8px;
    line-height: 1.5;
}

.diff-code.wrong {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    color: #991b1b;
}

.diff-code.correct {
    background: #f0fdf4;
    border: 1px solid #86efac;
    color: #166534;
}

.correction-time {
    font-size: 0.78rem;
    color: #9ca3af;
    text-align: right;
}

/* ======== HISTORY SECTION ======== */

.history-section {
    margin-top: 40px;
    padding-top: 30px;
    border-top: 2px solid #e5e7eb;
}

.history-section h3 {
    color: #334155;
    margin-bottom: 20px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.history-item {
    background: #f9fafb;
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    transition: border-color 0.2s;
}

.history-item:hover {
    border-color: #d1d5db;
}

.history-item.history-edited {
    border-left: 3px solid #a855f7;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 10px;
}

.history-query {
    font-weight: 500;
    color: #1f2937;
    flex: 1;
}

.history-badges {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-edited {
    background: #f3e8ff;
    color: #7c3aed;
    border: 1px solid #ddd6fe;
}

.history-time {
    font-size: 0.85rem;
    color: #6b7280;
    white-space: nowrap;
}

.history-download {
    display: inline-block;
    padding: 6px 15px;
    background: #8B0000;
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: background 0.3s;
}

.history-download:hover {
    background: #5C0029;
}

.empty-state {
    text-align: center;
    color: #9ca3af;
    font-style: italic;
    padding: 20px;
}

.history-summary {
    font-size: 0.85rem;
    color: #6b7280;
    margin-bottom: 15px;
    text-align: right;
}

.history-sql {
    margin: 10px 0;
}

.history-sql pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.83rem;
    font-family: 'JetBrains Mono', monospace;
    margin: 0;
    line-height: 1.5;
}

.history-diff {
    margin-bottom: 10px;
}

.history-toggle-btn {
    width: auto;
    padding: 6px 15px;
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    margin: 0;
    margin-right: 8px;
    transition: background 0.2s;
}

.history-toggle-btn:hover {
    background: #e5e7eb;
    transform: none;
    box-shadow: none;
}

.history-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ======== PAGINATION ======== */

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #e5e7eb;
}

.page-btn {
    width: auto;
    padding: 6px 12px;
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    margin: 0;
    transition: background 0.2s;
}

.page-btn:hover:not(:disabled) {
    background: #e5e7eb;
    transform: none;
    box-shadow: none;
}

.page-btn.active {
    background: linear-gradient(135deg, #8B0000 0%, #5C0029 100%);
    color: white;
    border-color: transparent;
}

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

/* ======== ANIMATIONS ======== */

.fade-in {
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(15px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.shake {
    animation: shake 0.5s ease;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-8px);
    }

    50% {
        transform: translateX(8px);
    }

    75% {
        transform: translateX(-4px);
    }
}

/* ======== RESPONSIVE ======== */

@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }

    main {
        padding: 25px;
    }

    .history-header {
        flex-direction: column;
        gap: 8px;
    }

    .history-badges {
        order: -1;
    }

    .history-time {
        margin-left: 0;
    }

    .history-actions {
        flex-wrap: wrap;
    }

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

    .editor-toolbar {
        flex-direction: column;
        gap: 8px;
    }
}