body {
    font-family: sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 20px;
    background-color: #f4f4f4;
    color: #333;
}

.container {
    width: 100%;
    max-width: none; /* Use full window width */
    margin: 0; /* Align to window edges for maximum space */
    background: #fff;
    padding: 18px 20px 28px 20px;
    border-radius: 6px;
    box-shadow: none;
}


.header-section {
    display: flex;
    align-items: center; /* Vertically align items in the center */
    margin-bottom: 20px; /* Space below the header */
}

#logo {
    height: 100px; /* Adjust as needed */
    width: auto; /* Maintain aspect ratio */
    margin-right: 15px; /* Space between logo and title */
    max-width: 100%; /* Prevent overflow on very small screens */
}

h1, h2, h3 {
    color: #440560;
    margin-top: 0; 
    margin-bottom: 0.5em; /* Added some bottom margin for h2/h3 */
}
h1 {
    margin-bottom: 0;
}


.controls, .search-section, .browse-section, .status, .mode-selection {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
}

label {
    display: block;
    margin-bottom: 5px;
    margin-top: 0px;
    font-size: 14px;
}

input[type="file"], input[type="text"], select {
    padding: 8px;
    margin-right: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 8px;
    font-size: 16px; /* Prevent iOS auto-zoom on input focus */
    min-height: 44px; /* Touch-friendly minimum height */
    display: block;
}

input[type="file"] {
    width: auto; 
}
/* Specific width for dropdowns if needed */
/* Removed empty ruleset for #columnSelect, #browseFileSelect */


#searchResults {
    max-height: calc(100vh - 260px); /* Use more vertical space */
    overflow-y: auto;
    overflow-x: auto;
    margin-top: 10px;
    padding-right: 1px;
    border: 1px solid #ddd;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    scroll-behavior: smooth;
}

button {
    padding: 10px 15px;
    background-color: #440560;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 5px; 
    margin-right: 5px;
    min-height: 44px; /* Minimum touch target size */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background-color 0.2s ease;
}

button:hover {
    background-color: #7a0091; /* Darker hover */
}

#clearButton {
    background-color: #dd8fc7;
}

#clearButton:hover {
    background-color: #c86ba5; /* Darker hover for clear */
}

#loadedFilesList {
    list-style: disc;
    padding-left: 20px;
    max-height: 100px; /* Limit height for loaded files list */
    overflow-y: auto;
    border: 1px solid #eee;
    padding-top: 5px;
    padding-bottom: 5px;
}

#loadedFilesList li {
    margin-bottom: 5px;
}

/* Results item styling - might not be used if table view is primary */
.result-item {
    border: 1px solid #e0e0e0;
    padding: 10px;
    margin-bottom: 10px;
    background-color: #f9f9f9;
    border-radius: 4px;
}

.result-item strong {
    color: #007bff;
}

.result-item pre {
    white-space: pre-wrap; 
    word-wrap: break-word; 
    background-color: #eee;
    padding: 8px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 0.9em;
    overflow-x: auto; 
}

.highlight { /* For search term highlighting if implemented later */
    background-color: yellow;
    font-weight: bold;
}

#resultsCount {
    margin-bottom: 10px;
    font-style: italic;
}

.download-buttons {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

.download-buttons button:disabled {
    background-color: #c7b2ce; /* Adjusted disabled color */
    color: #777;
    cursor: not-allowed;
}

#downloadCsvButton {
    display: none;
}


table {
    width: 100%;
    min-width: 1600px;
    border-collapse: collapse;
    font-size: 0.85em;
    table-layout: fixed; /* Fixed table layout so col widths are respected */
}

th, td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
    white-space: normal; /* Allow wrapping so table adapts to viewport */
    vertical-align: top;
}

td {
    max-width: none;
    overflow-wrap: anywhere;
}

/* Per-column wrapping control */
.col-nowrap {
    white-space: nowrap !important;
    overflow: hidden;
    text-overflow: ellipsis;
}
.col-wrap {
    white-space: normal !important;
    overflow-wrap: anywhere;
}


th {
    background-color: #e9d8ed; /* Lighter purple for headers */
    color: #333;
    position: sticky; /* Make headers sticky */
    top: 0; /* Stick to the top of the scrollable container */
    z-index: 10;
    cursor: pointer; 
}

/* Sort arrow styling */
th .sort-arrow {
    font-size: 0.8em;
    margin-left: 5px;
    color: #555;
}

/* Style for current sort column */
th.sorted-asc, th.sorted-desc {
    background-color: #d5b9dd; /* Slightly darker to indicate active sort */
}

/* Hide all sort arrows by default */
.sort-arrow {
    visibility: hidden; /* Initially hidden, shown by JS */
    display: inline-block; /* Ensure it takes space */
}

/* Show arrow for the currently sorted column */
th.sorted-asc .sort-arrow,
th.sorted-desc .sort-arrow {
    visibility: visible;
}


tr:nth-child(even) {
    background-color: #f9f9f9;
}

tr:hover {
    background-color: #f1e8f3; /* Lighter purple hover for rows */
}
/* =========================
   RESPONSIVE DESIGN BREAKPOINTS
   ========================= */

/* Tablet devices (768px and below) */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    .container {
        padding: 12px 15px 20px 15px;
    }
    input[type="text"], select {
        width: 100%; 
        margin-right: 0;
        margin-bottom: 10px;
        font-size: 16px; /* Prevent zoom on iOS */
    }
    button {
        padding: 12px 10px; /* Ensure tappable size (44px min height) */
        font-size: 14px;
        margin-bottom: 10px;
    }
    .header-section {
        flex-direction: column;
        align-items: flex-start;
    }
    #logo {
        height: 70px;
        margin-bottom: 10px;
        margin-right: 0;
    }
    h1 {
        font-size: 1.5em;
    }
    h2 {
        font-size: 1.2em;
    }
    th, td {
        white-space: normal;
        font-size: 0.85em;
        padding: 6px;
    }
    .controls-row {
        flex-direction: column;
        gap: 12px;
    }
    .controls-left, .controls-right {
        width: 100%;
        min-width: auto;
        flex: none;
    }
    .browse-search-inline {
        flex-direction: column;
        gap: 8px;
    }
    .browse-search-inline input[type="text"],
    .browse-search-inline button {
        width: 100%;
        margin: 0;
    }
    .results-top {
        flex-direction: column;
        align-items: flex-start;
    }
    .results-top-right {
        width: 100%;
        flex-wrap: wrap;
    }
    .download-buttons-inline {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .download-buttons-inline button {
        margin: 0;
        width: 100%;
    }
    #columnsToggle {
        margin-left: 0;
    }
    .columns-panel {
        position: fixed;
        left: 10px;
        right: 10px;
        top: auto;
        bottom: auto;
        max-width: none;
        min-width: auto;
    }
    #searchResults {
        max-height: calc(100vh - 400px);
    }
}

/* Small mobile phones (480px and below) */
@media (max-width: 480px) {
    body {
        padding: 8px;
    }
    .container {
        padding: 10px 12px 20px 12px;
        border-radius: 0;
    }
    input[type="text"], select, button {
        font-size: 16px; /* Prevent auto-zoom on iOS */
    }
    button {
        padding: 12px 8px; /* Ensure minimum 44px tap target */
        width: 100%;
        margin: 5px 0;
    }
    #logo {
        height: 50px;
    }
    h1 {
        font-size: 1.3em;
        margin-bottom: 10px;
    }
    h2 {
        font-size: 1.1em;
    }
    h3 {
        font-size: 1em;
    }
    label {
        font-size: 0.95em;
        margin-bottom: 5px;
    }
    .controls, .search-section, .browse-section, .status, .mode-selection {
        margin-bottom: 15px;
        padding-bottom: 12px;
    }
    th, td {
        font-size: 0.75em;
        padding: 4px;
    }
    table {
        font-size: 0.8em;
    }
    .download-buttons-inline {
        grid-template-columns: 1fr;
    }
    #searchResults {
        max-height: calc(100vh - 420px);
        font-size: 14px;
    }
    .columns-panel {
        left: 8px;
        right: 8px;
    }
    .columns-panel-inner {
        max-height: 300px;
    }
    .result-item {
        padding: 8px;
        margin-bottom: 8px;
    }
}

/* Very small devices (320px and below) - edge case */
@media (max-width: 320px) {
    body {
        padding: 5px;
    }
    .container {
        padding: 8px 10px;
    }
    #logo {
        height: 40px;
    }
    h1 {
        font-size: 1.1em;
    }
    th, td {
        font-size: 0.7em;
        padding: 3px;
    }
}

/* Controls row: place organism selector and search inline */
.controls-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    justify-content: flex-start;
    flex-wrap: wrap;
}
.controls-left {
    min-width: 220px;
    flex: 0 0 320px;
}
.controls-right {
    flex: 1 1 480px;
    min-width: 200px; /* Ensure minimum width */
}
.browse-search-inline {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
}
.browse-search-inline input[type="text"] {
    flex: 1 1 auto;
    min-width: 150px;
}
.browse-search-inline button {
    white-space: nowrap;
}

/* Results top area */
.results-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.results-top-left {
    display: flex;
    flex-direction: column;
}
.results-top-right {
    display: flex;
    align-items: center;
}
.download-buttons-inline button {
    margin-left: 8px;
}




/* Columns panel */
.columns-panel {
    position: absolute;
    right: 20px;
    top: 56px;
    background: #fff;
    border: 1px solid #ddd;
    padding: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    border-radius: 4px;
    z-index: 2000;
    min-width: 220px;
    max-height: 70vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.columns-panel-inner {
    max-height: 360px;
    overflow: auto;
}
.columns-panel label {
    display: block;
    font-size: 13px;
    margin: 6px 0;
}

/* Footer Styles */
.footer {
    border-top: 1px solid #ddd;
    margin-top: 30px;
    padding-top: 20px;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #666;
    font-size: 0.9em;
}

.version {
    font-weight: 500;
    color: #440560;
}

.help-link {
    font-weight: 500;
    color: #440560;
    text-decoration: none;
}

.help-link:hover {
    text-decoration: underline;
}

.github-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #333;
    transition: color 0.3s ease;
}

.github-link:hover {
    color: #440560;
}

.github-link svg {
    width: 24px;
    height: 24px;
}

/* Styles for custom header tooltip and info icons */
.custom-tooltip {
    position: fixed;
    background: rgba(0,0,0,0.88);
    color: #fff;
    padding: 6px 8px;
    border-radius: 4px;
    font-size: 12px;
    z-index: 1200;
    max-width: 360px;
    pointer-events: none; /* So it doesn't interfere with hover events */
    opacity: 0;
    transition: opacity 120ms ease-in-out, transform 120ms ease-in-out;
    transform: translateY(4px);
}
.custom-tooltip.visible {
    opacity: 1;
    transform: translateY(0);
}

.info-icon {
    margin-left: 8px;
    font-size: 11px;
    line-height: 12px;
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: inherit;
    border-radius: 50%;
    border: 1px solid rgba(0,0,0,0.15);
    background: #fff;
    margin-right: 4px;
    cursor: pointer;
}

.info-icon:hover {
    background: #f0f0f0;
}
