/* CSS Variables for theming */
:root {
    --primary-color: #4a90d9;
    --primary-hover: #357abd;
    --danger-color: #e74c3c;
    --danger-hover: #c0392b;
    --secondary-color: #6c757d;
    --secondary-hover: #545b62;
    --success-color: #27ae60;
    --background-color: #f8f9fa;
    --surface-color: #ffffff;
    --text-color: #333333;
    --text-muted: #6c757d;
    --border-color: #dee2e6;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);
    --border-radius: 8px;
    --transition: all 0.2s ease;
}

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

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

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

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color), #6c5ce7);
    color: white;
    padding: 2rem;
    text-align: center;
    box-shadow: var(--shadow-md);
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin: 0;
}

.tagline {
    font-size: 1.1rem;
    opacity: 0.9;
    margin-top: 0.5rem;
}

/* Main Content */
.main-content {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem;
}

/* Toolbar */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
    padding: 1rem;
    background: var(--surface-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
}

.toolbar-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-1px);
}

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

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

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

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

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

.btn-secondary {
    background-color: var(--secondary-color);
    color: white;
}

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

.icon {
    font-size: 1rem;
}

/* Section Styles */
section {
    margin-bottom: 2rem;
}

section h2 {
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-color);
}

/* Table Editor */
.table-editor {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
}

.table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

#editableTable {
    width: 100%;
    border-collapse: collapse;
    min-width: 400px;
}

#editableTable th,
#editableTable td {
    border: 1px solid var(--border-color);
    padding: 0;
    min-width: 120px;
}

#editableTable th {
    background-color: #f1f3f4;
}

.cell-wrapper {
    display: flex;
    flex-direction: column;
}

.cell-input {
    width: 100%;
    padding: 0.75rem;
    border: none;
    font-size: 0.95rem;
    font-family: inherit;
    background: transparent;
    text-align: center;
}

.cell-input:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
    background-color: #fff;
}

.header-cell {
    font-weight: 600;
    background: transparent;
}

/* Alignment Controls */
.alignment-controls {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.25rem;
    background: #e9ecef;
    border-top: 1px solid var(--border-color);
}

.align-btn {
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: var(--transition);
}

.align-btn:hover {
    background: #dee2e6;
    color: var(--text-color);
}

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

/* Markdown Output */
.markdown-output {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
}

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

.output-header h2 {
    margin-bottom: 0;
}

.markdown-preview {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 1.5rem;
    border-radius: var(--border-radius);
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9rem;
    overflow-x: auto;
    white-space: pre;
    line-height: 1.5;
    min-height: 100px;
}

.copy-feedback {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--success-color);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1000;
}

.copy-feedback.show {
    opacity: 1;
}

/* Table Preview */
.table-preview {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
}

.preview-container {
    overflow-x: auto;
}

.preview-container table {
    width: 100%;
    border-collapse: collapse;
    min-width: 300px;
}

.preview-container th,
.preview-container td {
    border: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
}

.preview-container th {
    background: #f1f3f4;
    font-weight: 600;
}

.preview-container tr:nth-child(even) {
    background: #f8f9fa;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

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

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}

.close-btn:hover {
    color: var(--text-color);
}

.modal-body {
    padding: 1.5rem;
}

.modal-body textarea {
    width: 100%;
    min-height: 200px;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9rem;
    resize: vertical;
}

.modal-body textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.1);
}

.csv-options {
    margin-top: 1rem;
}

.csv-options label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.csv-options input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: #f8f9fa;
}

/* Footer */
.footer {
    background: #2c3e50;
    color: white;
    padding: 1.5rem;
    text-align: center;
    margin-top: auto;
}

.footer a {
    color: #74b9ff;
    text-decoration: none;
    font-weight: 500;
}

.footer a:hover {
    text-decoration: underline;
}

/* Responsive Design */
@media (max-width: 768px) {
    .header {
        padding: 1.5rem 1rem;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .logo {
        width: 36px;
        height: 36px;
    }

    .tagline {
        font-size: 0.95rem;
    }

    .main-content {
        padding: 1rem;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .toolbar-group {
        justify-content: center;
    }

    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }

    .table-editor,
    .markdown-output,
    .table-preview {
        padding: 1rem;
    }

    section h2 {
        font-size: 1.1rem;
    }

    .output-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .markdown-preview {
        font-size: 0.8rem;
        padding: 1rem;
    }

    #editableTable th,
    #editableTable td {
        min-width: 100px;
    }

    .cell-input {
        padding: 0.5rem;
        font-size: 0.85rem;
    }

    .alignment-controls {
        padding: 0.2rem;
    }

    .align-btn {
        width: 20px;
        height: 20px;
        font-size: 0.6rem;
    }
}

@media (max-width: 480px) {
    .logo-container {
        flex-direction: column;
        gap: 0.5rem;
    }

    .header h1 {
        font-size: 1.3rem;
    }

    .btn {
        flex: 1;
        justify-content: center;
    }

    .toolbar-group {
        width: 100%;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}

/* Focus visible for keyboard navigation */
.btn:focus-visible,
.cell-input:focus-visible,
.align-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .toolbar,
    .markdown-output,
    .footer {
        display: none;
    }

    .header {
        background: none;
        color: black;
        box-shadow: none;
    }

    .table-editor {
        box-shadow: none;
    }
}
