:root {
    --primary-color: #007bff; /* Blue */
    --primary-color-dark: #0056b3;
    --secondary-color: #6c757d; /* Gray */
    --success-color: #28a745; /* Green */
    --danger-color: #dc3545; /* Red */
    --warning-color: #ffc107; /* Yellow */
    --light-bg: #f8f9fa;
    --dark-text: #212529;
    --medium-text: #495057;
    --light-text: #fff;
    --border-color: #dee2e6;
    --border-radius: 0.375rem; /* 6px */
    --box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.075);
    --font-family-sans-serif: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    --line-height: 1.6;
}

/* --- Basic Reset & Global Styles --- */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: var(--font-family-sans-serif);
    line-height: var(--line-height);
    color: var(--dark-text);
    background-color: #eef2f7; /* Light grayish blue background */
    margin: 0;
    padding: 1.5em;
    font-size: 16px;
}

h1, h2, h3, h4 {
    margin-top: 0;
    margin-bottom: 0.75em;
    font-weight: 500;
}

h1 { font-size: 2.25em; color: var(--primary-color-dark); text-align: center; margin-bottom: 1em; }
h2 { font-size: 1.75em; }
h3 { font-size: 1.4em; }
h4 { font-size: 1.15em; }

p { margin-top: 0; margin-bottom: 1em; }
hr { border: 0; border-top: 1px solid var(--border-color); margin: 2em 0; }

/* --- Utility Classes --- */
.hidden { display: none !important; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* --- Card Component --- */
.card {
    background-color: var(--light-text);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 2em;
    box-shadow: var(--box-shadow);
}

.card-header {
    background-color: var(--light-bg);
    padding: 1em 1.5em;
    border-bottom: 1px solid var(--border-color);
    font-size: 1.25em;
    font-weight: 500;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
    color: var(--primary-color);
}

.card-body { padding: 1.5em; }
.card-footer {
    background-color: #f8f9fa;
    padding: 1em 1.5em;
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 var(--border-radius) var(--border-radius);
    text-align: right;
}
.card-footer > *:not(:last-child) { margin-right: 0.75em; }

/* --- Buttons --- */
.btn {
    display: inline-block;
    font-weight: 400;
    color: var(--dark-text);
    text-align: center;
    vertical-align: middle;
    cursor: pointer;
    user-select: none;
    background-color: #e9ecef; /* Light gray */
    border: 1px solid #ced4da;
    padding: 0.5em 1em;
    font-size: 1rem;
    border-radius: var(--border-radius);
    transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    text-decoration: none;
}
.btn:hover { background-color: #d3d9df; border-color: #b6bfc8; }
.btn:focus {
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25); /* Primary color focus ring */
}
.btn:disabled {
    cursor: not-allowed;
    opacity: 0.65;
    box-shadow: none;
}

.btn-primary { color: var(--light-text); background-color: var(--primary-color); border-color: var(--primary-color); }
.btn-primary:hover { background-color: var(--primary-color-dark); border-color: #0050a2; }

.btn-success { color: var(--light-text); background-color: var(--success-color); border-color: var(--success-color); }
.btn-success:hover { background-color: #1e7e34; border-color: #1c7430; }

.btn-danger { color: var(--light-text); background-color: var(--danger-color); border-color: var(--danger-color); }
.btn-danger:hover { background-color: #b02a37; border-color: #a52834; }

.btn-warning { color: var(--dark-text); background-color: var(--warning-color); border-color: var(--warning-color); }
.btn-warning:hover { background-color: #d39e00; border-color: #c69500; }

.btn-sm { padding: 0.3em 0.75em; font-size: 0.875em; }

/* --- File Input Area --- */
#uploadInstructions { font-size: 0.9em; color: var(--medium-text); margin-top: 0.5em; }

/* --- File List --- */
#fileListContainer { margin-top: 1.5em; }
.file-list-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1em;
    flex-wrap: wrap;
    gap: 0.5em; /* Spacing between items if they wrap */
}
#fileListStatus { font-weight: 500; color: var(--medium-text); }

.file-list {
    list-style: none;
    padding: 0;
    margin-top: 1em;
}
.file-list li {
    background-color: #fff;
    border: 1px solid var(--border-color);
    padding: 0.8em 1.2em;
    margin-bottom: 0.75em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: var(--border-radius);
    transition: box-shadow 0.15s ease-in-out;
    flex-wrap: wrap; /* Allow controls to wrap on small screens */
}
.file-list li:hover { box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,0.075); }

.file-list .file-info {
    flex-grow: 1;
    margin-right: 1em;
    word-break: break-all;
    display: flex;
    align-items: center;
}
.file-list .file-info .file-order-number {
    font-weight: bold;
    color: var(--primary-color);
    margin-right: 0.5em;
    min-width: 1.5em; /* Ensure consistent spacing for numbers */
}
.file-list .file-name {
    color: var(--dark-text);
}

.file-list .file-controls {
    flex-shrink: 0;
    margin-left: auto;
    display: flex;
    gap: 0.4em; /* Spacing between control buttons */
}

#emptyListMessage {
    text-align: center;
    color: var(--medium-text);
    font-style: italic;
    padding: 1.5em;
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    margin-top: 1em;
}

/* --- Preview Player --- */
#previewPlayerContainer {
    margin-top: 1.5em;
    margin-bottom: 1.5em;
    padding: 1.25em;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: #fdfdff; /* Slightly off-white */
}
#previewPlayerContainer h4 {
    margin-bottom: 0.75em;
    font-size: 1.1em;
    color: var(--secondary-color);
}
#previewAudioElementContainer audio { /* If native controls are shown */
    width: 100%;
    margin-bottom: 0.75em;
}
#previewControls {
    display: flex;
    gap: 0.5em;
    align-items: center;
    flex-wrap: wrap; /* Allow buttons to wrap */
}
#previewStatusMessage {
    margin-top: 0.75em;
    font-size: 0.9em;
}

/* --- Status and Error Messages --- */
.status-message { color: var(--medium-text); }
.error-message {
    color: var(--danger-color);
    font-weight: 500;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    padding: 0.75em 1.25em;
    margin-top: 0.5em;
    border-radius: var(--border-radius);
}
#fileTypeError.error-message { margin-bottom: 1em; } /* Specific margin for file type error */

/* --- Merged Result Section --- */
#mergedResultSection .card-body p { margin-bottom: 1.5em; }
#mergedPlayerArea audio {
    max-width: 100%;
    margin-top: 1em;
    display: block;
}
#mergedPlayerArea h3 { color: var(--secondary-color); }

/* --- Responsive Adjustments --- */
@media (max-width: 768px) {
    body { padding: 1em; }
    h1 { font-size: 2em; }
    .card-header { padding: 0.8em 1.2em; font-size: 1.15em; }
    .card-body { padding: 1.2em; }
    .card-footer { padding: 0.8em 1.2em; }

    .file-list li {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5em; /* Spacing between file-info and file-controls when stacked */
    }
    .file-list .file-controls {
        margin-left: 0;
        width: 100%;
        justify-content: flex-end; /* Align buttons to the right */
    }
    .file-list .file-info { margin-right: 0; } /* Remove right margin when stacked */
}

@media (max-width: 600px) {
    h1 { font-size: 1.75em; }
    .btn { font-size: 0.95rem; padding: 0.4em 0.8em; }
    .btn-sm { font-size: 0.8rem; padding: 0.25em 0.6em; }

    .card-footer { text-align: center; }
    .card-footer > * {
        display: block;
        width: calc(100% - 1em); /* Slightly less than full width for better aesthetics */
        margin: 0.5em auto !important; /* Center buttons and override other margins */
    }
    .file-list-actions { flex-direction: column; align-items: stretch; gap: 0.75em;}
    #removeAllBtn { width: 100%; }

    #previewControls {
        flex-direction: column;
        align-items: stretch; /* Make buttons full width */
    }
    #previewControls button {
        width: 100%;
        margin-bottom: 0.3em;
    }
}