/* Flightpath Parser Styles */
:root {
    --primary-color: #3498db;
    --primary-dark: #2980b9;
    --secondary-color: #e74c3c;
    --text-color: #333;
    --light-bg: #f8f9fa;
    --border-color: #ddd;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --error-color: #e74c3c;
    --card-bg: #ffffff;
    --muted-text: #666;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: #f4f7f9;
    padding: 20px;
}

/* Apply theme background color to body */
[data-theme="dark"] body {
    background-color: #000000;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) body {
        background-color: #000000;
    }
}

header {
    text-align: center;
    margin-bottom: 30px;
    padding: 20px;
    background-color: var(--primary-color);
    color: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

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

h2 {
    margin-bottom: 15px;
    color: var(--primary-dark);
}

h3 {
    margin-bottom: 10px;
    color: var(--primary-dark);
}

main {
    display: grid;
    gap: 20px;
    grid-template-columns: 1fr;
}

@media (min-width: 1024px) {
    main {
        grid-template-columns: 1fr 1fr;
    }
}

.input-section, .output-section {
    background-color: var(--card-bg);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    /* Allow grid items to shrink and avoid causing page-wide horizontal overflow */
    min-width: 0;
}

.json-input {
    margin-bottom: 20px;
}

textarea {
    width: 100%;
    height: 200px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-family: monospace;
    resize: vertical;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
}

.functionality-selection {
    margin-bottom: 20px;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.radio-option {
    display: flex;
    align-items: center;
}

.radio-option input[type="radio"] {
    margin-right: 10px;
}

.conditional-input {
    margin-bottom: 20px;
    padding: 15px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: var(--light-bg);
}

.hidden {
    display: none;
}

button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s;
}

button:hover {
    background-color: var(--primary-dark);
}

.results-container {
    margin-top: 20px;
    /* Confine scrolling to this container in both axes */
    overflow: auto;
    overflow-x: auto;
    max-height: 1000px; /* Control max height to enable scrolling */
    position: relative;
    /* Ensure position doesn't interfere with sticky positioning of children */
    overflow-anchor: none;
    /* Ensure container takes full width of parent */
    width: 100%;
}

.results-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 10px;
    /* Prevent overly wide content from forcing table to expand beyond container */
    table-layout: fixed;
}

.results-table th, .results-table td {
    padding: 10px;
    border: 1px solid var(--border-color);
    text-align: left;
    /* Allow long tokens to wrap within the cell to avoid expanding the page */
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.results-table th {
    background-color: var(--card-bg);
    font-weight: 600;
}

.results-table tr:nth-child(even) {
    background-color: var(--light-bg);
}

.error {
    color: var(--error-color);
    background-color: rgba(231, 76, 60, 0.1);
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 15px;
}

#inputs-container {
    margin-top: 15px;
    padding: 10px;
    background-color: var(--light-bg);
    border-radius: 4px;
}

pre {
    background-color: #f5f5f5;
    padding: 10px;
    border-radius: 4px;
    overflow-x: auto;
    white-space: pre-wrap;
    font-family: monospace;
}

footer {
    text-align: center;
    margin-top: 30px;
    padding: 10px;
    color: var(--muted-text);
}

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

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

/* Download button styles */
.download-container {
    margin-top: 15px;
    display: flex;
    justify-content: flex-end;
}

.download-csv-btn {
    background-color: var(--success-color);
    color: white;
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 500;
    transition: background-color 0.2s;
}

.download-csv-btn:hover {
    background-color: #219653;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

@media (max-width: 768px) {
    .radio-group {
        flex-direction: column;
    }
    
    .results-table {
        display: block;
        overflow-x: auto;
    }
}

/* Header actions */
.header-actions {
    margin-top: 8px;
    display: flex;
    justify-content: center;
    gap: 10px;
}

.repo-link {
    color: #fff;
    text-decoration: underline;
}

/* Editor toolbar and dropzone */
.editor-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.editor-toolbar .left-group {
    display: flex;
    align-items: center;
    gap: 10px;
}
.editor-toolbar .right-group {
    display: flex;
    gap: 8px;
}
.file-meta {
    font-size: 0.9rem;
    color: var(--muted-text);
}
.drop-zone {
    border: 2px dashed var(--border-color);
    background-color: var(--light-bg);
    border-radius: 6px;
    padding: 12px;
    text-align: center;
    color: var(--muted-text);
    margin-bottom: 8px;
}
.drop-zone:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}
.drop-zone.drag-over {
    background-color: rgba(52, 152, 219, 0.08);
    border-color: var(--primary-color);
}

/* CodeMirror editor sizing */
.CodeMirror {
    height: auto;
    min-height: 200px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

/* Filters and tools */
.results-tools {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 8px;
}
.results-tools input[type="text"] {
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}
/* Removed conflicting selector */

/* Ensure table headers have proper sticky behavior */
.results-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.results-table thead tr:first-child th {
    position: sticky;
    top: 0;
    z-index: 2;
    background-color: var(--card-bg);
}

.results-table thead tr.filters-row th,
.results-table thead tr:nth-child(2) th {
    background-color: var(--card-bg);
    position: sticky;
    top: 42px; /* height of header row approx */
    z-index: 1;
}
.filters-row input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}
.summary {
    margin: 6px 0;
    color: var(--muted-text);
}

/* Sortable headers */
.results-table th.sortable {
    cursor: pointer;
}
.results-table th.sortable::after {
    content: '';
    margin-left: 6px;
    font-size: 0.8em;
}
.results-table th.sortable[data-sort="asc"]::after { content: '▲'; }
.results-table th.sortable[data-sort="desc"]::after { content: '▼'; }

/* Column resize handle */
.col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    width: 6px;
    height: 100%;
    cursor: col-resize;
    user-select: none;
}

/* Search options */
.search-options {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}
.controls-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.threshold-label {
    margin-left: 8px;
}

/* Dark mode (via data-theme="dark") */
[data-theme="dark"] {
    --primary-color: #4aa3ff;
    --primary-dark: #1c6fbe;
    --secondary-color: #ff6b6b;
    --text-color: #e6e6e6;
    --light-bg: #2b2f36;
    --border-color: #3a3f47;
    --card-bg: #1f2228;
    --muted-text: #a8b0ba;
    --error-color: #ff6b6b;
    background-color: #000000;
}

[data-theme="dark"] header {
    background-color: var(--primary-dark);
}

[data-theme="dark"] pre {
    background-color: #23262b;
}

/* Respect system preference by default; JS toggle will override by setting data-theme */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --primary-color: #4aa3ff;
        --primary-dark: #1c6fbe;
        --secondary-color: #ff6b6b;
        --text-color: #e6e6e6;
        --light-bg: #2b2f36;
        --border-color: #3a3f47;
        --card-bg: #1f2228;
        --muted-text: #a8b0ba;
        --error-color: #ff6b6b;
        background-color: #15181d;
    }
}
