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

:root {
    --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --header-bg: #fdfbf7;
    --text-primary: #333;
    --text-secondary: #666;
    --editor-bg: white;
    --toolbar-bg: #f8f9fa;
    --border-color: #e9ecef;
    --preview-text: #495057;
    --preview-heading: #212529;
    --code-bg: #f1f3f5;
    --blockquote-bg: #f8f9fa;
    --table-border: #dee2e6;
}

body.dark-mode {
    --bg-gradient: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    --header-bg: #2d2d3a;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --editor-bg: #1e1e2e;
    --toolbar-bg: #2a2a3a;
    --border-color: #3a3a4a;
    --preview-text: #c0c0c0;
    --preview-heading: #e0e0e0;
    --code-bg: #2a2a3a;
    --blockquote-bg: #2a2a3a;
    --table-border: #3a3a4a;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    color: var(--text-primary);
    transition: all 0.3s ease;
}

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

.header {
    background: var(--header-bg);
    backdrop-filter: blur(10px);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
    border-radius: 16px;
    margin-bottom: 1rem;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    background: var(--header-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.action-btn:hover {
    background: var(--toolbar-bg);
    border-color: #667eea;
    color: #667eea;
    transform: translateY(-2px);
}

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

.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--header-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.5rem;
    min-width: 180px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    z-index: 1000;
}

.dropdown-menu.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-primary);
    transition: all 0.2s ease;
    font-size: 0.95rem;
}

.dropdown-item:hover {
    background: var(--toolbar-bg);
    color: #667eea;
}

.dropdown-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.5rem 0;
}

.main-content {
    flex: 1;
}

.editor-container {
    background: var(--editor-bg);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    position: relative;
    min-height: 600px;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.85rem;
    font-weight: 600;
}

.toolbar-btn:hover {
    background: var(--border-color);
    color: #667eea;
}

.toolbar-btn:active {
    background: var(--border-color);
}

.toolbar-btn-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.toolbar-btn-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.toolbar-divider {
    width: 1px;
    height: 48px;
    background: var(--border-color);
    margin: 0 0.5rem;
}

.editor {
    flex: 1;
    width: 100%;
    padding: 1.5rem;
    border: none;
    outline: none;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1rem;
    line-height: 1.8;
    resize: none;
    display: none;
    background: var(--editor-bg);
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.preview {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.preview-content {
    max-width: 100%;
}

.preview-content h1 {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: var(--preview-heading);
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.preview-content h2 {
    font-size: 1.5rem;
    margin: 1.5rem 0 0.75rem;
    color: var(--preview-heading);
}

.preview-content h3 {
    font-size: 1.25rem;
    margin: 1.25rem 0 0.5rem;
    color: var(--preview-text);
}

.preview-content p {
    margin: 1rem 0;
    line-height: 1.8;
    color: var(--preview-text);
}

.preview-content ul, .preview-content ol {
    margin: 1rem 0;
    padding-left: 2rem;
}

.preview-content li {
    margin: 0.5rem 0;
    line-height: 1.7;
    color: var(--preview-text);
}

.preview-content blockquote {
    margin: 1.5rem 0;
    padding: 1rem 1.5rem;
    background: var(--blockquote-bg);
    border-left: 4px solid #667eea;
    color: var(--text-secondary);
    font-style: italic;
}

.preview-content code {
    background: var(--code-bg);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    color: #e83e8c;
}

.preview-content pre {
    margin: 1.5rem 0;
    padding: 1rem;
    background: #1e1e1e;
    border-radius: 8px;
    overflow-x: auto;
}

.preview-content pre code {
    background: transparent;
    padding: 0;
    color: #d4d4d4;
}

.preview-content a {
    color: #667eea;
    text-decoration: none;
    transition: color 0.2s;
}

.preview-content a:hover {
    color: #764ba2;
    text-decoration: underline;
}

.preview-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1rem 0;
}

.preview-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
}

.preview-content th, .preview-content td {
    padding: 0.75rem 1rem;
    border: 1px solid var(--table-border);
    text-align: left;
}

.preview-content th {
    background: var(--blockquote-bg);
    font-weight: 600;
    color: var(--preview-heading);
}

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

.preview-content hr {
    border: none;
    height: 2px;
    background: var(--border-color);
    margin: 2rem 0;
}

.drop-zone {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(102, 126, 234, 0.95);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.drop-zone.active {
    display: flex;
}

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

.drop-content svg {
    margin-bottom: 1rem;
    opacity: 0.9;
}

.drop-content p {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.drop-content span {
    font-size: 0.95rem;
    opacity: 0.8;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 1000;
}

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

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-overlay p {
    color: white;
    margin-top: 1rem;
    font-size: 1rem;
}

.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #333;
    color: white;
    padding: 1rem 2rem;
    border-radius: 8px;
    font-size: 0.95rem;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1001;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.toast.active {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.error {
    background: #dc3545;
}

.toast.success {
    background: #28a745;
}

@media (max-width: 768px) {
    .app-container {
        padding: 0.5rem;
    }
    
    .header {
        padding: 1rem;
        flex-direction: column;
        gap: 1rem;
    }

    .header-right {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.75rem;
    }

    .main-content {
        padding: 0;
    }

    .logo {
        font-size: 1.25rem;
    }

    .toolbar {
        justify-content: center;
    }

    .editor, .preview {
        padding: 1rem;
    }

    .action-btn {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    animation: fadeIn 0.3s ease;
}

.modal-overlay.active {
    display: flex;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal {
    background: var(--header-bg);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 480px;
    animation: slideUp 0.3s ease;
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-close:hover {
    background: var(--toolbar-bg);
    color: var(--text-primary);
}

.modal-body {
    padding: 1.5rem;
}

.modal-input {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 1rem;
    background: var(--editor-bg);
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s ease;
}

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

.modal-footer {
    display: flex;
    gap: 0.75rem;
    padding: 1rem 1.5rem 1.5rem;
    justify-content: flex-end;
}

.modal-btn {
    padding: 0.6rem 1.5rem;
    border: none;
    border-radius: 24px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.modal-btn-cancel {
    background: var(--toolbar-bg);
    color: var(--text-primary);
}

.modal-btn-cancel:hover {
    background: var(--border-color);
}

.modal-btn-confirm {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.modal-btn-confirm:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}
