:root {
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --secondary: #818CF8;
    --bg-main: #0F172A;
    --bg-surface: #1E293B;
    --bg-surface-elevated: #334155;
    --border: #334155;
    --border-strong: #475569;
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --danger: #EF4444;
    --danger-hover: #DC2626;
    --radius: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --grid-border: #475569;
    --grid-header: #1E293B;
    --grid-cell-focus: rgba(79, 70, 229, 0.2);
    --grid-cell-focus-border: #818CF8;
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Typography */
h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

h2 {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

/* Layout */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

header {
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: center;
    z-index: 10;
}

.header-content {
    width: 100%;
    max-width: 1600px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary);
}

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

.split-view {
    display: flex;
    flex: 1;
    overflow: hidden;
    width: 100%;
    margin: 0 auto;
}

/* Panes */
.pane {
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: var(--bg-main);
}

.editor-pane {
    flex: 6;
    border-right: 1px solid var(--border);
    min-width: 50%;
}

.output-pane {
    flex: 4;
    min-width: 300px;
    background-color: var(--bg-surface);
}

.pane-header {
    padding: 0.75rem 1rem;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 53px;
}

.pane-actions, .toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Toggle */
.toggle-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

input[type="checkbox"] {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-small {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

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

.btn-secondary {
    background-color: var(--bg-surface-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
}
.btn-secondary:hover { background-color: var(--border-strong); }

.btn-danger {
    background-color: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}
.btn-danger:hover { background-color: rgba(239, 68, 68, 0.1); }

.btn-icon {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid transparent;
    padding: 0.35rem;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-icon:hover {
    color: var(--text-primary);
    background-color: var(--bg-surface-elevated);
    border-color: var(--border-strong);
}

.btn i {
    width: 16px;
    height: 16px;
}
.btn-icon i {
    width: 18px;
    height: 18px;
}

/* Spreadsheet Grid */
.grid-container-wrapper {
    flex: 1;
    overflow: auto;
    padding: 1.5rem;
    background-color: var(--bg-main);
    /* Notion/Airtable style subtle background pattern */
    background-image: 
        linear-gradient(to right, rgba(255,255,255,0.02) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255,255,255,0.02) 1px, transparent 1px);
    background-size: 20px 20px;
}

.grid-container {
    display: inline-block; /* allows it to size to content and scroll */
    min-width: 100%;
}

.spreadsheet-grid {
    border-collapse: collapse;
    width: 100%;
    table-layout: fixed;
    background-color: var(--bg-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.spreadsheet-grid th, 
.spreadsheet-grid td {
    border: 1px solid var(--grid-border);
    position: relative;
    min-width: 120px;
}

/* Header Row setup */
.spreadsheet-grid th {
    background-color: var(--grid-header);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.875rem;
    text-align: left;
}

/* Row wrapper for alignment controls */
.col-header-container {
    display: flex;
    flex-direction: column;
}

.col-align-ctrls {
    display: flex;
    border-bottom: 1px solid var(--grid-border);
}

.align-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.25rem 0;
    cursor: pointer;
    border-right: 1px solid var(--grid-border);
    transition: background 0.2s;
}
.align-btn:last-child {
    border-right: none;
}
.align-btn:hover {
    background: var(--bg-surface-elevated);
    color: var(--text-primary);
}
.align-btn.active {
    background: rgba(79, 70, 229, 0.2);
    color: var(--secondary);
}
.align-btn i {
    width: 14px;
    height: 14px;
}

.cell-content, .header-content-inner {
    padding: 0.75rem;
    outline: none;
    min-height: 40px;
    word-break: break-word;
    font-size: 0.875rem;
    color: var(--text-primary);
    transition: background-color 0.2s;
}

.header-content-inner {
    font-weight: 600;
}

.cell-content:focus, .header-content-inner:focus {
    background-color: var(--grid-cell-focus);
    box-shadow: inset 0 0 0 2px var(--grid-cell-focus-border);
}

/* Remove Row/Col Controls */
.del-btn {
    position: absolute;
    opacity: 0;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 5;
    transition: opacity 0.2s;
}

.spreadsheet-grid tr:hover .del-row-btn {
    opacity: 1;
}

.spreadsheet-grid th:hover .del-col-btn {
    opacity: 1;
}

.del-row-btn {
    left: -24px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
}

.del-col-btn {
    top: -24px;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 20px;
}

div:hover > .del-col-btn {
    opacity: 1;
}

.del-btn i {
    width: 12px;
    height: 12px;
}


/* Markdown Editor */
.code-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background-color: var(--bg-surface);
}

textarea#markdownOutput {
    width: 100%;
    height: 100%;
    background-color: transparent;
    color: var(--text-primary);
    border: none;
    padding: 1.5rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.6;
    resize: none;
    outline: none;
    white-space: pre;
    overflow: auto;
}

/* Toast */
.toast {
    position: absolute;
    top: 1rem;
    right: 50%;
    transform: translateX(50%);
    font-size: 0.75rem;
    color: white;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    background-color: var(--primary);
    box-shadow: var(--shadow);
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 50;
}
.toast.hidden { 
    opacity: 0; 
    pointer-events: none;
    transform: translateX(50%) translateY(-10px);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s;
}
.modal.hidden {
    opacity: 0;
    pointer-events: none;
}
.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 600px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}
.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}
.modal-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.modal-desc {
    color: var(--text-secondary);
    font-size: 0.875rem;
}
#csvInput {
    width: 100%;
    height: 200px;
    background: var(--bg-main);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    padding: 1rem;
    border-radius: var(--radius);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.875rem;
    resize: vertical;
    outline: none;
}
#csvInput:focus {
    border-color: var(--primary);
}
.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

/* Responsive */
@media (max-width: 900px) {
    .split-view {
        flex-direction: column;
        overflow-y: auto;
    }
    .editor-pane, .output-pane {
        width: 100%;
        height: 50vh;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
}
