* {
    box-sizing: border-box;
}

body {
    font-family: 'Roboto', sans-serif;
    margin: 0;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

#container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.header {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    padding: 30px;
    text-align: center;
}

.header h1 {
    margin: 0;
    font-size: 2.5rem;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header p {
    margin: 10px 0 0 0;
    opacity: 0.9;
    font-size: 1.1rem;
}

.main-content {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 0;
    min-height: 600px;
}

.controls-sidebar {
    background: #f8f9fa;
    padding: 25px;
    border-right: 1px solid #e9ecef;
    overflow-y: auto;
    max-height: 90vh;
}

.canvas-area {
    padding: 25px;
    display: flex;
    flex-direction: column;
}

/* Control Groups */
.control-section {
    margin-bottom: 25px;
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    border: 1px solid #e9ecef;
}

.control-section h3 {
    margin: 0 0 15px 0;
    color: #007bff;
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-section h3::before {
    content: '';
    width: 4px;
    height: 20px;
    background: #007bff;
    border-radius: 2px;
}

/* Form Controls */
.form-group {
    margin-bottom: 15px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: #495057;
    font-size: 0.9rem;
}

.form-label .unit {
    color: #6c757d;
    font-weight: 400;
    font-size: 0.85rem;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: all 0.3s ease;
    background: white;
}

.form-control:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

/* Inline Controls */
.inline-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap:10px;
    margin-bottom: 20px;
}

.inline-controls.three-col {
    grid-template-columns: 1fr 2fr 2fr;
}

/* Checkbox Controls */
.checkbox-group {
    display: flex;
    margin-top: -10px;
    margin-bottom:20px;
    gap:8px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.checkbox-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #007bff;
}

.checkbox-item label {
    font-size: 0.9rem;
    color: #495057;
    cursor: pointer;
}

/* Color Picker Styling */
.color-picker-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.color-swatch {
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15), inset 0 0 0 1px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.3s ease;
    overflow: hidden;
}

.color-swatch:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2), inset 0 0 0 1px rgba(0, 0, 0, 0.1);
}

.color-swatch input[type="color"] {
    position: absolute;
    top: -5px;
    left: -5px;
    width: 50px;
    height: 50px;
    border: none;
    outline: none;
    background: none;
    cursor: pointer;
    opacity: 0;
}

.color-preview {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    pointer-events: none;
}

/* Buttons */
.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.btn-danger {
    background: #dc3545;
    color: white;
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-danger:hover {
    background: #c82333;
}

.btn-full {
    width: 100%;
    margin-top: 10px;
}

/* File Upload */
.file-upload {
    position: relative;
    display: inline-block;
    width: 100%;
}

.file-upload input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.file-upload-label {
    display: block;
    padding: 12px;
    background: #f8f9fa;
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    text-align: center;
    color: #6c757d;
    cursor: pointer;
    transition: all 0.3s ease;
}

.file-upload:hover .file-upload-label {
    background: #e9ecef;
    border-color: #007bff;
    color: #007bff;
}

.file-upload-icon {
    font-size: 1.5rem;
    margin-bottom: 5px;
    display: block;
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    background: #000;
    border-radius: 12px;
    overflow: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    margin-bottom: 20px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.canvas-container canvas {
    width: 100%;
    height: auto;
    display: block;
    cursor: grab;
}

.canvas-container canvas:active {
    cursor: grabbing;
}

/* Canvas Size Controls */
.canvas-size-controls {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 15px;
}

.canvas-size-btn {
    width: 20px;
    height: 20px;
    padding: 0;
    font-size: 0.75rem;
    line-height: 10px;
    text-align: center;
    border-radius: 4px;
}

.canvas-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px; /* Matches the original margin-bottom of canvas-size-controls */
}

.api-key-link {
    font-size: 0.85rem;
    color: #495057;
    cursor: pointer;
    text-decoration: none;
    transition: color 0.2s ease;
}

.api-key-link:hover {
    color: #007bff;
}

/* Modal Specifics */
#openai-key-modal .modal-content {
    width: 500px;
    text-align: left;
}

#openai-key-modal .modal-content h2 {
    margin-bottom: 0;
}

#openai-key-modal input {
    margin: 10px 0 20px 0;
}

#openai-key-modal .modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Element Lists */
.element-list {
    max-height: 120px;
    overflow-y: auto;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    background: #f8f9fa;
}

.element-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid #e9ecef;
    font-size: 0.85rem;
    background: white;
}

.element-item:last-child {
    border-bottom: none;
}

.element-item:hover {
    background: #e9ecef;
}

.element-item.selected {
    background: #cce5ff;
    color: #0056b3;
}

.element-item.over {
    border-top: 2px solid #007bff;
}

.element-item .btn-danger {
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px;
    min-width: auto;
}

/* Action Buttons */
.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-top: 20px;
}

/* Progress */
.progress-area {
    text-align: center;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-top: 15px;
}

.progress-text {
    color: #28a745;
    font-style: italic;
    font-size: 0.9rem;
    margin-bottom:10px;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 350px 1fr;
    }
}

@media (max-width: 992px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .controls-sidebar {
        border-right: none;
        border-bottom: 1px solid #e9ecef;
        max-height: none;
        padding: 20px;
    }

    .canvas-area {
        padding: 20px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .header {
        padding: 20px;
    }

    .header h1 {
        font-size: 2rem;
    }

    .inline-controls {
        grid-template-columns: 1fr;
    }

    .inline-controls.three-col {
        grid-template-columns: 1fr;
    }

    .action-buttons {
        grid-template-columns: 1fr;
    }

    .canvas-size-controls {
        justify-content: center;
    }
}

/* Aspect Ratio Controls */
.aspect-controls {
    display: flex;
    gap: 10px;
    align-items: end;
}

.aspect-controls select {
    flex: 1;
}

.aspect-controls button {
    padding: 10px 16px;
    white-space: nowrap;
}

.form-group.horizontal-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.form-group.horizontal-group .form-label {
    margin-bottom: 0;
    white-space: nowrap;
}

.form-group.horizontal-group .color-picker-group {
    justify-content: flex-start;
    width: auto;
}

.icons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
    gap: 10px;
    margin-bottom: 15px;
    max-height: 150px; 
    overflow-y: auto; 
}

.icon-item img {
    width: 100%;
    height: auto;
    cursor: pointer;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 5px;
    background: white;
}

p.small-text {
    font-size: 14px;
    font-family:inherit;
    font-weight: bold;
}

.small-text a {
    cursor: pointer;
    color: white;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    width: 600px;
    max-width: 90vw;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
}

.modal-content h2 {
    font-size: 2rem;
    margin: 0 0 20px;
    color: #333;
}

.modal-content input {
    width: 100%;
    padding: 15px;
    margin: 15px 0;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 1.1rem;
}

.modal-content button {
    padding: 15px 30px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1.1rem;
}

.modal-content button:hover {
    background: #0056b3;
}

.modal-content p#email-error {
    color: red;
    display: none;
    font-size: 1rem;
    margin-top: 10px;
}

/* --- Transcription Section --- */
#transcription-results {
    padding-top: 15px;
    max-height: 300px;
    overflow-y: auto;
    border-top: 1px solid #e9ecef;
    margin-top: 15px;
}

#transcription-results h3 {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#open-transcription-modal {
    cursor: pointer;
    font-size: 1.2rem;
    color: #6c757d;
    transition: color 0.2s;
}

#open-transcription-modal:hover {
    color: #007bff;
}

#transcription-list {
    margin-bottom: 15px;
}

.transcription-item-sidebar {
    padding: 8px 4px;
    border-bottom: 1px solid #e9ecef;
    font-size: 0.85rem;
}

.transcription-item-sidebar:last-child {
    border-bottom: none;
}

#manual-transcribe-btn {
    justify-content: center;
    margin-top: 10px;
    margin-bottom: 0;
}

.transcription-item-time {
    font-weight: 500;
    color: #007bff;
    margin-bottom: 4px;
    font-size: 0.8rem;
}

.transcription-item-text {
    color: #495057;
    line-height: 1.4;
    word-wrap: break-word;
}

.transcription-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
}

.transcription-actions .btn {
    flex: 1;
    font-size: 0.75rem;
    padding: 10px 20px;
    max-width: fit-content;
}

/* Transcription Modal */
#transcription-modal .modal-content {
    width: 800px;
    height: auto;
}

#transcription-modal-list {
    flex-grow: 1;
    overflow-y: auto;
    text-align: left;
    margin-bottom: 20px;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 10px;
}

.transcription-modal-item {
    display: grid;
    /* Change this line */
    grid-template-columns: 100px 100px 1fr auto; /* Adds a column for the button */
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.transcription-modal-item input {
    font-size: 0.9rem;
    padding: 8px 10px;
    margin: 0;
}

.transcription-modal-item input.start-time,
.transcription-modal-item input.end-time {
    max-width: fit-content;
}

.transcription-modal-item button {
    padding: 5px 10px;
    font-size: 0.75rem;
}

.alignment-controls {
    display: flex;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #e9ecef;
}

.alignment-controls label {
    margin-bottom: 10px;
}
.alignment-btn {
    flex: 1;
    padding: 8px 10px;
    background-color: #fff;
    color: #495057;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 0.75rem; /* Makes icons/emojis look good */
    line-height: 1;
}

.alignment-btn:not(:last-child) {
    border-right: 2px solid #e9ecef;
}

.alignment-btn:hover {
    background-color: #f8f9fa;
}

.alignment-btn.active {
    background-color: #007bff;
    color: white;
}

footer {
    text-align: center;
    padding: 15px;
    border-top: 1px solid #e9ecef;
    background-color: #f8f9fa;
}

footer p {
    margin: 0;
    font-size: 0.8rem;
    color: #6c757d;
}

#caption-background-options .color-swatch .color-preview {
    background-color: #000000; /* Initial value */
}