/* Voice Flipper - Main Stylesheet */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

html {
    overflow-x: hidden;
    width: 100%;
}

html, body {
    max-width: 100%;
    overflow-x: hidden;
}

/* Generic ghosted class for disabled buttons */
button.ghosted {
    opacity: 0.5;
    pointer-events: none;
    cursor: not-allowed !important;
}

img {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
    pointer-events: none;
}

body {
    width: 100%;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
}

.container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    padding: 25px;
    max-width: 500px;
    width: 100%;
}

.title-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
    padding: 0px 15px 10px 15px;
    border-bottom: 2px solid #e0e0e0;
    position: relative;
}

.logo-image {
    position: absolute;
    left: 15px;
    height: 48px;
    width: auto;
    display: block;
}

.title-image {
    max-width: 100%;
    height: auto;
    display: block;
}

/* User Management Button */
.usermanage-button {
    position: absolute;
    right: 15px;
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    height: 48px;
    width: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.usermanage-button:hover {
    transform: scale(1.1);
    opacity: 0.8;
}

.usermanage-button:active {
    transform: scale(0.95);
}

.usermanage-icon {
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* User Management Menu */
.usermanage-menu {
    position: fixed;
    /* top and left are set dynamically by JavaScript */
    transform: translateX(-50%); /* Center menu horizontally on button center */
    background: white;
    border: 2px solid #ccc;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 200px;
    z-index: 1000;
    animation: menuSlideIn 0.2s ease;
}

@keyframes menuSlideIn {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.usermanage-menu-header {
    padding: 15px;
    text-align: center;
}

.usermanage-menu-username {
    font-weight: bold;
    font-size: 1.1rem;
    color: #333;
}

.usermanage-menu-divider {
    height: 1px;
    background: #e0e0e0;
    margin: 0 10px;
}

.usermanage-menu-items {
    padding: 10px 0;
}

.usermanage-menu-item {
    padding: 12px 20px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    color: #333;
    font-size: 0.95rem;
    display: none; /* Hidden by default, shown via JavaScript based on roles */
}

.usermanage-menu-item-logout {
    display: block !important; /* Logout is always visible */
    border-bottom: 1px solid #e0e0e0;
    margin-bottom: 5px;
}

.usermanage-menu-item:hover {
    background-color: #f0f0f0;
}

.usermanage-menu-item:active {
    background-color: #e0e0e0;
}

.usermanage-menu-item-disabled {
    color: #999 !important;
    cursor: not-allowed !important;
    opacity: 0.5;
}

.usermanage-menu-item-disabled:hover {
    background-color: transparent !important;
}

.usermanage-menu-item-disabled:active {
    background-color: transparent !important;
}

/* Main Panel */
.main-panel {
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section {
    margin-bottom: 15px;
}

.section-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 10px;
    display: block;
}

.optional {
    font-size: 0.85rem;
    color: #888;
    font-weight: normal;
}

.playback-widget {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-top: 10px;
    transition: opacity 0.3s ease;
    border: 1px solid #e0e0e0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.playback-widget.ghosted {
    opacity: 1;
}

.playback-widget.ghosted > *:not(.waveform-visualization-buttons-container):not(.waveform-controls-row) {
    opacity: 0.3;
}

.playback-controls {
    display: flex;
    flex-direction: row;
    gap: 10px;
    justify-content: center;
    align-items: center;
}

.waveform-container {
    width: 100%;
    height: 100px;
    background: white;
    border-radius: 6px;
    position: relative;
    overflow: hidden;
    border: 2px solid #666;
}

.waveform-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.status {
    margin-top: 15px;
    padding: 12px;
    border-radius: 6px;
    text-align: center;
    font-size: 0.85rem;
}

.status.info {
    background: #e3f2fd;
    color: #1976d2;
}

.status.success {
    background: #e8f5e9;
    color: #388e3c;
}

.status.error {
    background: #ffebee;
    color: #c62828;
}

/* Voice Picker Row with Microphone Button */
.voice-picker-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

/* Microphone Icon Button */
.mic-icon-button {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.mic-icon-button-svg {
    width: 100%;
    height: 100%;
}

.mic-icon-button-icon {
    transition: transform 0.2s ease;
    transform-origin: 18px 18px;
}

.mic-icon-button:hover .mic-icon-button-icon {
    transform: scale(1.1);
}

.mic-icon-button:active .mic-icon-button-icon {
    transform: scale(0.95);
}

/* Voice Picker - Searchable Dropdown */
.voice-picker-container {
    position: relative;
    width: 100%;
    flex: 1;
}

.voice-picker-container::after {
    content: '▼';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #666;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.6s ease;
}

.voice-picker-container.open::after {
    transform: translateY(-50%) rotate(180deg);
}

.voice-picker-input {
    width: 100%;
    padding: 10px 35px 10px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.95rem;
    background: white;
    cursor: text;
    transition: border-color 0.3s ease;
}

.voice-picker-input:focus {
    outline: none;
    border-color: #667eea;
}

.voice-picker-clear {
    position: absolute;
    right: 38px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border: none;
    background: #e0e0e0;
    border-radius: 50%;
    color: #666;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
    line-height: 1;
}

.voice-picker-clear:hover {
    background: #ccc;
    color: #333;
}

.voice-picker-clear.visible {
    display: flex;
}

.voice-picker-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid #e0e0e0;
    border-top: none;
    border-radius: 0 0 6px 6px;
    max-height: 200px;
    overflow-y: auto;
    display: none;
    z-index: 1000;
    margin-top: -2px;
}

.voice-picker-dropdown.open {
    display: block;
}

.voice-picker-option {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.2s ease;
}

.voice-picker-option:hover {
    background: #f5f5f5;
}

.voice-picker-option.selected {
    background: #e3f2fd;
    color: #1976d2;
    font-weight: 600;
}

.voice-picker-option.hidden {
    display: none;
}

.text-input {
    width: 100%;
    min-height: 120px;
    padding: 10px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    resize: vertical;
    transition: border-color 0.3s ease;
}

.text-input:focus {
    outline: none;
    border-color: #667eea;
}

.character-counter {
    text-align: right;
    font-size: 0.8rem;
    color: #888;
    margin-top: 5px;
    margin-bottom: 15px;
}

/* Speech Parameters (Sliders) */
.collapseable-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 15px;
    padding: 8px 0;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s ease;
}

.collapseable-section-header:hover {
    background-color: rgba(102, 126, 234, 0.05);
    border-radius: 4px;
}

.collapseable-section-header .section-label {
    margin-bottom: 0;
    line-height: 1;
    cursor: pointer;
}

.collapse-arrow {
    color: #667eea;
    flex-shrink: 0;
    transition: transform 0.2s ease;
    display: block;
}

.collapseable-section-header.expanded .collapse-arrow {
    transform: rotate(90deg);
}

.speech-parameters {
    margin-top: 15px;
    margin-bottom: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.3s ease, padding 0.3s ease, margin 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}

.speech-parameters.collapsed {
    max-height: 0;
    padding: 0;
    margin: 0;
    border: none;
    opacity: 0;
}

.parameter-group {
    margin-bottom: 12px;
}

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

.parameter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.parameter-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
}

.parameter-value-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.parameter-value {
    font-size: 0.8rem;
    font-weight: 600;
    color: #667eea;
    background: white;
    padding: 2px 8px;
    border-radius: 4px;
    min-width: 40px;
    text-align: center;
}

.parameter-reset {
    padding: 2px 8px;
    font-size: 0.7rem;
    font-weight: 600;
    color: #666;
    background: white;
    border: 1px solid #d0d0d0;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.parameter-reset:hover {
    background: #f5f5f5;
    color: #333;
    border-color: #b0b0b0;
}

.parameter-reset:active {
    background: #e8e8e8;
    transform: scale(0.95);
}

.parameter-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e0e0e0;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

/* Slider track styles */
.parameter-slider::-webkit-slider-track {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e0e0e0;
}

.parameter-slider::-moz-range-track {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e0e0e0;
}

/* Slider thumb styles */
.parameter-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.parameter-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Hover effects */
.parameter-slider::-webkit-slider-thumb:hover {
    background: #5568d3;
    transform: scale(1.1);
}

.parameter-slider::-moz-range-thumb:hover {
    background: #5568d3;
    transform: scale(1.1);
}

/* Active/pressed effects */
.parameter-slider::-webkit-slider-thumb:active {
    background: #4450b8;
    transform: scale(1.05);
}

.parameter-slider::-moz-range-thumb:active {
    background: #4450b8;
    transform: scale(1.05);
}

/* Parameter slider container with chevron buttons */
.parameter-slider-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Chevron buttons for sliders */
.parameter-chevron {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border: none;
    background: transparent;
    color: #667eea;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    user-select: none;
}

.parameter-chevron:hover {
    color: #5568d3;
    transform: scale(1.1);
}

.parameter-chevron:active {
    color: #4450b8;
    transform: scale(0.95);
}

.parameter-chevron.ghosted {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

.parameter-chevron.ghosted:hover {
    transform: scale(1);
    color: #667eea;
}

.flip-button {
    width: 100%;
    padding: 12px 20px;
    border-radius: 6px;
    border: none;
    background: #007bff;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.flip-button:hover {
    background: #0056b3;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 123, 255, 0.3);
}

.flip-button:active {
    transform: translateY(0);
}

.flip-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.flip-button:disabled:hover {
    background: #ccc;
    transform: none;
    box-shadow: none;
}

.flip-button-spinner {
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Flip Progress (Step 2) */
.flip-progress {
    text-align: center;
    padding: 20px;
    margin-top: 15px;
    background: #f5f5f5;
    border-radius: 8px;
}

.flip-progress p {
    font-size: 0.9rem;
    color: #555;
    margin-top: 15px;
    font-weight: 600;
}

/* Loading Message */
.loading-message {
    text-align: center;
    padding: 40px 20px;
    min-height: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.loading-message p {
    font-size: 1.1rem;
    color: #555;
    margin-top: 20px;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #e0e0e0;
    border-top: 5px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Flipped Waveform Visualization Buttons Widget */
.flipped-waveform-visualization-button {
    cursor: pointer;
    width: 40px;
    height: 36px;
    display: inline-block;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
    pointer-events: auto;
    position: relative;
    z-index: 10;
}

.flipped-waveform-visualization-button-svg {
    width: 100%;
    height: 100%;
    display: block;
    margin: 0;
    padding: 0;
    pointer-events: none;
}

.flipped-waveform-visualization-button-svg * {
    pointer-events: none;
}

.flipped-waveform-visualization-button-icon {
    transition: transform 0.2s ease;
}

.flipped-waveform-visualization-button-icon-play {
    transform-origin: 23.5px 18px;
}

.flipped-waveform-visualization-button-icon-pause {
    transform-origin: 23.5px 18px;
}

.flipped-waveform-visualization-button-icon-stop {
    transform-origin: 58px 18px;
}

.flipped-waveform-visualization-button-icon-skipback {
    transform-origin: 92px 18px;
}

.flipped-waveform-visualization-button-icon-skipforward {
    transform-origin: 129px 18px;
}

.flipped-waveform-visualization-button:hover .flipped-waveform-visualization-button-icon {
    transform: scale(1.2);
}

.flipped-waveform-visualization-button:active .flipped-waveform-visualization-button-icon {
    transform: scale(0.9);
}

/* Ghosted state for disabled flipped waveform visualization buttons */
.flipped-waveform-visualization-button-ghosted {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

.flipped-waveform-visualization-button-ghosted:hover .flipped-waveform-visualization-button-icon {
    transform: scale(1);
}

/* Download Button */
.download-button {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.download-button-svg {
    width: 100%;
    height: 100%;
}

.download-button-icon {
    transition: transform 0.2s ease;
    transform-origin: 18px 18px;
}

.download-button:hover .download-button-icon {
    transform: scale(1.1);
}

.download-button:active .download-button-icon {
    transform: scale(0.95);
}

/* Mobile/Phone Responsive Layout */
@media (max-width: 600px) {
    body {
        padding: 0;
        background: white;
        align-items: stretch;
        min-height: 100vh;
    }

    .container {
        padding: 15px;
        max-width: 100%;
        width: 100%;
        border-radius: 0;
        box-shadow: none;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
    }

    h1 {
        font-size: 1.3rem;
        margin-bottom: 15px;
        padding-bottom: 12px;
    }

    /* Hide logo in phone mode to prevent overlap with title and user management button */
    .logo-image {
        display: none;
    }

    /* Left justify title container with professional padding */
    .title-container {
        justify-content: flex-start; /* Left justify title */
        padding: 0px 15px 10px 15px; /* Professional padding */
    }

    /* Right justify user management button with professional padding */
    .usermanage-button {
        right: 15px; /* Professional right padding */
    }

    /* Ensure title has room and doesn't overlap with user management button */
    .title-image {
        max-width: calc(100% - 90px); /* Leave room for user management button (64px + 2*15px padding) */
        padding-left: 0; /* Left aligned, no left padding needed on image itself */
    }

    /* Ensure main panel is 100% width so it doesn't move around */
    .main-panel {
        width: 100%;
    }

    .section {
        margin-bottom: 12px;
    }

    .section-label {
        font-size: 0.9rem;
        margin-bottom: 8px;
    }

    /* Make interactive elements more touch-friendly */
    .voice-picker-input,
    .text-input,
    input[type="text"] {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 12px;
    }

    .flip-button {
        padding: 14px 20px;
        font-size: 1.05rem;
        min-height: 48px; /* Touch-friendly minimum */
    }

    .mic-icon-button {
        width: 48px;
        height: 48px;
    }

    /* Adjust playback controls for touch */
    .playback-widget {
        padding: 12px;
        gap: 10px;
    }

    .waveform-container {
        height: 80px; /* Smaller waveform on mobile */
    }

    /* Voice picker adjustments */
    .voice-picker-dropdown {
        max-height: 150px; /* Smaller dropdown on mobile */
    }

    /* Status and counter adjustments */
    .status {
        font-size: 0.8rem;
        padding: 10px;
        margin-top: 12px;
    }

    .character-counter {
        font-size: 0.75rem;
        margin-top: 4px;
        margin-bottom: 12px;
    }

    /* Download button remains same size */
    .download-button,
    .flipped-waveform-visualization-button {
        /* Keep standard sizes for touch targets */
    }

    /* Speech parameters on mobile */
    .speech-parameters {
        padding: 12px;
        margin-top: 12px;
        margin-bottom: 12px;
    }

    .parameter-group {
        margin-bottom: 10px;
    }

    .parameter-label {
        font-size: 0.8rem;
    }

    .parameter-value-group {
        gap: 4px;
    }

    .parameter-value {
        font-size: 0.75rem;
        padding: 2px 6px;
        min-width: 35px;
    }

    .parameter-reset {
        font-size: 0.65rem;
        padding: 3px 6px;
        min-height: 24px; /* Touch-friendly */
    }

    /* Make sliders more touch-friendly on mobile */
    .parameter-slider {
        height: 8px;
    }

    .parameter-slider::-webkit-slider-track {
        height: 8px;
    }

    .parameter-slider::-moz-range-track {
        height: 8px;
    }

    .parameter-slider::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }

    .parameter-slider::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }

    /* Make chevron buttons more touch-friendly on mobile */
    .parameter-chevron {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        font-size: 2.2rem;
    }

    .parameter-slider-container {
        gap: 6px;
    }
}
