:root {
    /* Color Palette - Clean & Minimal */
    --bg-color: #f8f9fa;
    --surface-color: #ffffff;
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --code-bg: #f3f4f6;
    
    /* Spacing & Sizing */
    --spacing-xs: 0.5rem;
    --spacing-sm: 0.75rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    /* Typography */
    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "SF Mono", "Menlo", "Monaco", "Consolas", "Liberation Mono", "Courier New", monospace;
    
    /* Effects */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --transition-fast: 150ms ease;
    
    /* State Colors */
    --success-color: #10b981;
}

[data-theme="dark"] {
    --bg-color: #0f172a;
    --surface-color: #1e293b;
    --primary-color: #3b82f6;
    --primary-hover: #60a5fa;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --code-bg: #111827;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font-ui);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    width: 100%;
}

body {
    /* Default (Mobile): Allow full page scroll */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    padding: var(--spacing-sm) var(--spacing-lg);
    flex: 0 0 auto;
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1600px;
    margin: 0 auto;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.app-logo {
    color: var(--primary-color);
}

.header-container h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Main Layout */
.app-main {
    flex: 1 1 auto;
    padding: var(--spacing-lg);
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
}

.parser-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-lg);
    /* Mobile: Default is auto height */
}

/* Panel Styling */
.panel {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.panel-header {
    height: 56px; /* Fixed height for perfect alignment */
    padding: 0 var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-color);
    flex: 0 0 auto;
}

.panel-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.panel-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* Input Area */
.input-panel textarea {
    width: 100%;
    border: none;
    padding: var(--spacing-md);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    outline: none;
    background: var(--surface-color);
    color: var(--text-primary);
    
    /* Mobile: Grow with content */
    min-height: 250px;
    field-sizing: content;
    resize: vertical;
}

.input-panel textarea:focus {
    background: var(--surface-color);
}

/* Controls Area */
.controls-area {
    padding: var(--spacing-md);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: var(--spacing-sm);
    align-items: center;
    background: var(--bg-color);
    flex: 0 0 auto;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition-fast);
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

.btn-icon {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.25rem; /* Reduced padding */
    width: 32px; /* Fixed width small square */
    height: 32px; /* Fixed height small square */
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover, .btn-icon.active {
    background: var(--bg-color);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.text-success {
    color: var(--success-color) !important;
    border-color: var(--success-color) !important;
}

/* Options Drawer */
.options-drawer {
    padding: var(--spacing-md);
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-sm);
    flex: 0 0 auto;
}

.options-drawer.hidden {
    display: none;
}

.option-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.option-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.option-group input {
    padding: 6px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    width: 100%;
    background: var(--surface-color);
    color: var(--text-primary);
}

.option-group input:focus {
    outline: 2px solid var(--primary-color);
    border-color: transparent;
}

/* Output Area */
.output-panel {
    display: flex;
    flex-direction: column;
    /* Important for Desktop Flex */
    overflow: hidden; 
}

.output-container {
    position: relative;
    background: var(--code-bg);
    min-height: 250px;
    /* Mobile: Let it grow */
    flex: 1 1 auto;
    /* Important for scrolling inside */
    display: flex;
    flex-direction: column;
}

pre#output {
    margin: 0;
    padding: var(--spacing-lg);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    white-space: pre-wrap;
    color: var(--text-primary);
    
    /* Mobile: Grow with content */
    height: auto;
    overflow: visible; 
    flex: 1 1 auto;
}

pre#output:empty::before {
    content: attr(placeholder);
    color: var(--text-secondary);
    font-style: italic;
}

/* Footer */
.app-footer {
    border-top: 1px solid var(--border-color);
    padding: var(--spacing-md);
    background: var(--surface-color);
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    flex: 0 0 auto;
}

.app-footer a {
    color: var(--primary-color);
    text-decoration: none;
}

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

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Footer Links */
.link-btn {
    background: none;
    border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-size: inherit;
    font-family: inherit;
    padding: 0;
    text-decoration: underline;
}

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

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-md);
    animation: fadeIn 0.2s ease-out;
}

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

.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-body {
    padding: var(--spacing-lg);
    color: var(--text-primary);
    line-height: 1.6;
}

.modal-body p {
    margin-top: 0;
}

.modal-body p:last-child {
    margin-bottom: 0;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* 
   DESKTOP OVERRIDES 
   Fixed App Layout for Main Content
   Footer pushes below the viewport
*/
@media (min-width: 768px) {
    /* Allow body to scroll so we can reach the footer */
    html, body {
        height: auto;
        overflow-y: auto;
    }

    .app-main {
        /* 
           Set a fixed height that forces panels to scroll internally,
           but large enough that footer is pushed down.
           100vh - 50px creates a Main area that, combined with ~60px Header,
           is slightly taller than 100vh, ensuring Footer is just off-screen.
        */
        height: calc(100vh - 50px);
        min-height: 500px; /* Prevent being too small on short screens */
        overflow: hidden;  /* Contain the panels */
        padding-bottom: var(--spacing-lg);
    }

    .parser-grid {
        grid-template-columns: 400px 1fr;
        align-items: start;
        height: 100%;
        overflow: hidden;
    }
    
    .column {
        height: 100%;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        min-height: 0; /* Crucial for flex child to shrink */
    }

    .panel {
        height: 100%;
        min-height: 0; /* Crucial for flex child to shrink */
    }

    /* Input Panel: Internal scrolling */
    .input-panel textarea {
        field-sizing: fixed;
        flex: 1 1 auto;
        height: 100%;
        min-height: 0;
        resize: none;
        overflow-y: auto;
    }

    /* Output Panel: Internal scrolling */
    .output-panel {
        height: 100%;
        overflow: hidden;
    }

    .output-container {
        flex: 1 1 auto;
        height: 100%;
        min-height: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    pre#output {
        flex: 1 1 auto;
        height: 100%;
        min-height: 0; /* Important! Allows shrinking */
        overflow-y: auto;
        margin: 0;
    }
}
