:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --master-gradient: linear-gradient(135deg, #FF8008 0%, #FFC837 100%);
    --accent-color: #764ba2;
    --text-dark: #2d3436;
    --text-light: #636e72;
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --danger-color: #ff7675;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-dark);
    margin: 0;
    padding: 2em 1em;
    line-height: 1.6;
}

#container {
    max-width: 1000px;
    margin: auto;
    background-color: var(--card-bg);
    padding: 3em;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.05);
}

h1 {
    color: var(--text-dark);
    font-weight: 700;
    margin-top: 0;
    text-align: center;
    letter-spacing: -0.5px;
}

p.subtitle {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 2em;
    font-weight: 300;
}

.normalization-badge {
    background-color: #e0f2fe;
    color: #0369a1;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.9em;
    font-weight: 500;
    margin-left: 5px;
}

/* --- Upload Area --- */
.upload-area {
    border: 2px dashed #cbd5e0;
    border-radius: 12px;
    padding: 2.5em;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: #f8fafc;
    position: relative;
    margin-bottom: 1.5em;
}

.upload-area:hover, .upload-area.dragover {
    border-color: var(--accent-color);
    background-color: #f3f0ff;
    transform: scale(1.01);
}

.upload-area input[type="file"] { display: none; }
.upload-icon { font-size: 3em; color: #a0aec0; margin-bottom: 0.5em; }
.upload-btn-text { color: var(--accent-color); font-weight: 600; font-size: 1.1em; }
.upload-subtext { display: block; margin-top: 0.5em; font-size: 0.85em; color: #a0aec0; }

/* Toolbar */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1em;
}
#status { font-size: 0.9em; color: var(--text-light); font-weight: 500; margin: 0; }

/* --- DIALOGUE CARDS --- */
.dialogue-group {
    border: 2px solid #e2e8f0;
    border-radius: 16px;
    margin-bottom: 2em;
    padding: 0;
    background-color: #fff;
    overflow: hidden;
    position: relative; /* For drag handle positioning if needed */
}

/* Header */
.dialogue-header {
    background-color: #f8fafc;
    border-bottom: 2px solid #e2e8f0;
    padding: 1em 1.5em;
    cursor: default; /* Default cursor, specific handle for drag */
}

.header-top-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    gap: 15px;
}

/* Group Drag Handle */
.group-drag-handle {
    cursor: grab;
    color: #cbd5e0;
    font-size: 1.5em;
    margin-right: 10px;
    line-height: 1;
}
.group-drag-handle:hover { color: var(--accent-color); }

/* Editable Title */
.group-title-input {
    font-family: 'Poppins', sans-serif;
    font-weight: 700;
    color: var(--text-dark);
    font-size: 1.1em;
    border: 1px solid transparent;
    background: transparent;
    padding: 2px 5px;
    border-radius: 4px;
    flex-grow: 1;
    transition: all 0.2s;
    width: 100%;
}

.group-title-input:hover {
    border-color: #e2e8f0;
    background-color: #fff;
}

.group-title-input:focus {
    outline: none;
    border-color: var(--accent-color);
    background-color: #fff;
}

.header-left-wrapper {
    display: flex;
    align-items: center;
    flex-grow: 1;
    overflow: hidden;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-shrink: 0;
}

.group-player-row { width: 100%; min-height: 10px; }
.group-audio-player { width: 100%; height: 36px; margin-top: 5px; }

/* --- LIST ITEMS --- */
.file-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
    min-height: 60px; /* Important for dropping into empty groups */
    background-color: #fff; /* Ensure bg is white for drop zone */
}

/* Visual cue for empty list */
.file-list:empty::after {
    content: "Drag audio clips here";
    display: block;
    text-align: center;
    color: #cbd5e0;
    padding: 20px;
    font-size: 0.9em;
    font-style: italic;
}

.file-list li {
    padding: 1em 1.5em;
    border-bottom: 1px solid #f1f5f9;
    display: grid;
    grid-template-columns: auto 1fr auto; 
    gap: 20px;
    background: #fff;
    align-items: center;
}

.file-list li:last-child { border-bottom: none; }
.file-list li:hover { background-color: #fafbfc; }

/* Left Column */
.li-left-col {
    display: flex;
    flex-direction: row;
    gap: 15px;
    align-items: center;
    min-width: 120px;
}

.drag-handle {
    cursor: grab;
    color: #cbd5e0;
    font-size: 1.4em;
    line-height: 1;
    display: flex;
    align-items: center;
}
.drag-handle:hover { color: var(--accent-color); }

.timestamp-pill {
    background-color: #fff;
    color: #64748b;
    padding: 4px 10px;
    border-radius: 6px;
    font-family: monospace;
    font-size: 0.9em;
    font-weight: 600;
    border: 1px solid #cbd5e0;
    text-align: center;
    cursor: pointer;
    user-select: none;
    min-width: 80px;
    transition: all 0.2s;
}

.timestamp-pill:hover { background-color: #f1f5f9; border-color: var(--accent-color); transform: scale(1.05); }
.timestamp-pill:active { transform: scale(0.95); }

/* Middle Column */
.li-content-col {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    min-width: 0;
}

.filename-text {
    font-weight: 500;
    font-size: 0.95em;
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    transition: transform 3s linear;
}

.file-list li:hover .filename-text { transform: translateX(-20px); }
.clip-audio-player { width: 100%; height: 32px; }

/* Right Column */
.btn-delete {
    background: none;
    border: none;
    color: #cbd5e0;
    font-size: 1.6em;
    padding: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    height: 100%;
}
.btn-delete:hover { color: var(--danger-color); }

.btn-delete-group {
    background: none;
    border: none;
    color: #cbd5e0;
    font-size: 1.2em;
    cursor: pointer;
    padding: 0 5px;
    display: flex;
    align-items: center;
    transition: color 0.2s;
}
.btn-delete-group:hover { color: var(--danger-color); }

/* --- Buttons --- */
button {
    font-family: 'Poppins', sans-serif;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
}

.btn-sm {
    padding: 0.4em 1.2em;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 500;
    background-color: white;
    border: 1px solid #cbd5e0;
    color: var(--text-dark);
}
.btn-sm:hover { border-color: var(--accent-color); color: var(--accent-color); }

.btn-create {
    background-color: #ebf8ff;
    color: #3182ce;
    border-color: #bee3f8;
    font-weight: 600;
}
.btn-create:hover {
    background-color: #3182ce;
    color: white;
}

.btn-preview { background-color: #f8fafc; border-color: #cbd5e0; }
.btn-preview:hover { background-color: var(--accent-color); color: white; border-color: var(--accent-color); }

.btn-action {
    padding: 0.8em 2em;
    border-radius: 50px;
    font-weight: 600;
    font-size: 0.95em;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.btn-primary { background-image: var(--primary-gradient); color: white; }
.btn-master { background-image: var(--master-gradient); color: white; }
.btn-secondary { background-color: #fff; border: 2px solid #e2e8f0; color: var(--text-dark); }
.btn-secondary:hover:not(:disabled) { border-color: var(--accent-color); color: var(--accent-color); }
button:disabled { opacity: 0.6; cursor: not-allowed; }

/* --- Footer & Master --- */
#grand-total-section {
    margin-top: 3em;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5em;
    display: none; 
}

#master-interface {
    width: 100%;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 16px;
    padding: 2em;
    box-shadow: 0 10px 30px rgba(0,0,0,0.05);
}

.master-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.header-left { display: flex; align-items: center; gap: 10px; }
.master-title { font-weight: 700; font-size: 1.1em; }

.status-badge { font-size: 0.75em; font-weight: 600; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; }
.status-loading { background-color: #fff7ed; color: #c2410c; border: 1px solid #ffedd5; }
.time-display { font-family: monospace; color: var(--text-light); background: #f1f5f9; padding: 4px 8px; border-radius: 6px; }

#waveform {
    width: 100%; height: 128px; background-color: #f8fafc; border-radius: 8px; margin-bottom: 1.5em; position: relative; overflow: hidden;
}

#master-loading-overlay {
    display: flex; position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255,255,255,0.85); z-index: 10; align-items: center; justify-content: center;
    font-weight: 600; color: var(--accent-color); font-size: 1.1em;
}

.master-controls { display: flex; justify-content: center; margin-bottom: 2em; }
.btn-circle {
    width: 50px; height: 50px; border-radius: 50%; background-image: var(--master-gradient);
    color: white; font-size: 1.5em; display: flex; align-items: center; justify-content: center;
    box-shadow: 0 4px 15px rgba(255, 128, 8, 0.3); padding-left: 5px; border: none;
}
.btn-circle:hover { transform: scale(1.1); }

.footer-buttons { display: flex; gap: 1em; flex-wrap: wrap; justify-content: center; }

/* --- Undo Toast --- */
#undo-toast {
    position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
    background-color: #333; color: white; padding: 12px 24px;
    border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    display: flex; align-items: center; gap: 15px; z-index: 1000;
    opacity: 0; visibility: hidden; transition: all 0.3s ease;
}
#undo-toast.show { opacity: 1; visibility: visible; bottom: 40px; }
.undo-text { font-size: 0.9em; font-weight: 500; }
.btn-undo { background: none; border: none; color: #4fd1c5; font-weight: 700; text-transform: uppercase; padding: 0; }
.btn-undo:hover { color: #81e6d9; text-decoration: underline; }
.btn-close-toast { background: none; border: none; color: #aaa; font-size: 1.2em; margin-left: 10px; }
.btn-close-toast:hover { color: white; }

@media (max-width: 800px) {
    #container { padding: 1.5em; max-width: 100%; }
    .file-list li { grid-template-columns: 1fr auto; grid-template-rows: auto auto; row-gap: 10px; }
    .li-left-col { grid-column: 1 / -1; justify-content: flex-start; margin-bottom: 5px; }
    .li-content-col { grid-column: 1; }
    .btn-delete { grid-column: 2; grid-row: 2; align-self: center; }
    .footer-buttons { flex-direction: column; width: 100%; }
    .btn-action { width: 100%; }
}