/* ======================================================================
   VibeVoice TTS -- Dark Theme Stylesheet
   ====================================================================== */

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-tertiary: #242835;
    --bg-hover: #2d3245;
    --bg-input: #181b24;

    --text-primary: #e4e6ef;
    --text-secondary: #9499b3;
    --text-muted: #5d6280;

    --accent: #6c5ce7;
    --accent-hover: #7e70f0;
    --accent-dim: rgba(108, 92, 231, 0.15);

    --success: #2ecc71;
    --warning: #f39c12;
    --danger: #e74c3c;
    --info: #3498db;

    --border: #2a2e3e;
    --border-light: #343850;

    --radius: 8px;
    --radius-sm: 4px;
    --radius-lg: 12px;

    --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.4);

    --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;

    --header-height: 56px;
}

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    color: var(--text-primary);
    background: var(--bg-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ======================================================================
   CONNECTION DIALOG
   ====================================================================== */

.dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.dialog-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    width: 400px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
}

.dialog-box h2 {
    margin-bottom: 20px;
    font-size: 18px;
    font-weight: 600;
}

/* ======================================================================
   BUTTONS
   ====================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    text-decoration: none;
    color: var(--text-primary);
    background: var(--bg-tertiary);
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-outline {
    background: transparent;
    border-color: var(--border-light);
}
.btn-outline:hover { background: var(--bg-tertiary); }

.btn-ghost {
    background: transparent;
    border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-tertiary); }

.btn-danger {
    background: transparent;
    color: var(--danger);
    border-color: var(--danger);
}
.btn-danger:hover { background: rgba(231, 76, 60, 0.12); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }

.btn-generate {
    padding: 12px;
    font-size: 15px;
    font-weight: 600;
    margin-top: 8px;
}

/* ======================================================================
   FORM ELEMENTS
   ====================================================================== */

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.hint {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text-muted);
    font-size: 11px;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent);
}

textarea {
    resize: vertical;
    min-height: 80px;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%239499b3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

.error-text {
    color: var(--danger);
    font-size: 12px;
    margin: 8px 0;
}

/* ======================================================================
   HEADER
   ====================================================================== */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    padding: 0 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-left h1 {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.badge {
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 12px;
    background: var(--accent-dim);
    color: var(--accent);
}

.badge-model {
    background: var(--accent-dim);
    color: var(--accent);
}

/* --- Status dot --- */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-ready { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-loading { background: var(--warning); box-shadow: 0 0 6px var(--warning); animation: pulse 1.2s infinite; }
.status-disconnected { background: var(--danger); }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* --- Queue indicator --- */
.queue-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}

.queue-icon {
    font-size: 10px;
    color: var(--accent);
}

/* ======================================================================
   MAIN LAYOUT
   ====================================================================== */

.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    height: calc(100vh - var(--header-height));
    overflow: hidden;
}

.panel {
    padding: 20px;
    overflow-y: auto;
}

.panel h2 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.panel-generation {
    border-right: 1px solid var(--border);
}

/* ======================================================================
   VOICE ROW
   ====================================================================== */

.voice-row {
    display: flex;
    gap: 6px;
}

.voice-row select { flex: 1; }

.upload-btn {
    cursor: pointer;
    font-size: 14px;
    padding: 6px 10px;
}

/* ======================================================================
   CONFIG SECTION
   ====================================================================== */

.config-section {
    margin: 12px 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.config-section summary {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    user-select: none;
}

.config-section summary:hover { background: var(--bg-hover); }

.config-body {
    padding: 12px;
}

/* --- Config tabs --- */
.config-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

.config-tab {
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 500;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
}
.config-tab:hover { background: var(--bg-tertiary); }
.config-tab.active { background: var(--accent-dim); color: var(--accent); }

.config-panel { display: none; }
.config-panel.active { display: block; }

/* --- Config sliders --- */
.config-sliders {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.config-slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.config-slider-row label {
    min-width: 110px;
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: none;
    margin-bottom: 0;
}

.config-slider-row input[type="range"] {
    flex: 1;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.config-slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}

.config-slider-row .slider-value {
    min-width: 45px;
    text-align: right;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-primary);
}

.config-slider-row.toggle-row {
    gap: 10px;
}

.toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(16px);
}

.config-sliders.readonly input,
.config-sliders.readonly .toggle-switch {
    pointer-events: none;
    opacity: 0.7;
}

.config-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    justify-content: flex-end;
}

/* ======================================================================
   GENERATION STATUS
   ====================================================================== */

.generation-status {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
}

.status-text {
    font-size: 13px;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.progress-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

.progress-fill.indeterminate {
    width: 30%;
    animation: indeterminate 1.5s infinite ease-in-out;
}

@keyframes indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

/* ======================================================================
   RESULT PLAYER
   ====================================================================== */

.result-player {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.result-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.result-meta .sep { color: var(--border-light); }

.result-player audio {
    width: 100%;
    height: 36px;
    border-radius: var(--radius-sm);
}

.result-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.generate-hint {
    text-align: center;
    margin-top: 4px;
}

/* ======================================================================
   HISTORY
   ====================================================================== */

.history-filters {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.history-search {
    flex: 1;
}

.history-filters select {
    width: 160px;
    flex-shrink: 0;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: calc(100vh - 300px);
    overflow-y: auto;
    padding-right: 4px;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 13px;
}

/* --- History entry card --- */
.history-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    transition: border-color 0.15s;
}

.history-card:hover {
    border-color: var(--border-light);
}

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

.history-card-voice {
    font-weight: 600;
    font-size: 13px;
    color: var(--accent);
}

.history-card-time {
    font-size: 11px;
    color: var(--text-muted);
}

.history-card-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    line-height: 1.4;
    max-height: 42px;
    overflow: hidden;
    word-break: break-word;
}

.history-card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.history-card-meta .sep { color: var(--border); }

.history-card-audio {
    margin-bottom: 8px;
}

.history-card-audio audio {
    width: 100%;
    height: 32px;
}

.history-card-time-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-top: 4px;
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
}

.history-card-time-display .history-time-current {
    color: var(--text-primary);
}

.history-card-time-display .history-time-sep {
    color: var(--text-muted);
}

.history-card-time-display .history-time-total {
    color: var(--text-muted);
}

.history-card-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* ======================================================================
   PAGINATION
   ====================================================================== */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-secondary);
}

/* ======================================================================
   HISTORY BULK
   ====================================================================== */

.history-bulk {
    margin-top: 12px;
    display: flex;
    justify-content: flex-end;
}

/* ======================================================================
   TOAST NOTIFICATIONS (optional, appended via JS)
   ====================================================================== */

.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 2000;
}

.toast {
    padding: 10px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    animation: toast-in 0.3s ease;
    max-width: 360px;
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error { border-left: 3px solid var(--danger); }
.toast.toast-info { border-left: 3px solid var(--info); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ======================================================================
   RESPONSIVE
   ====================================================================== */

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

    .panel-generation {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .history-list {
        max-height: none;
    }
}

@media (max-width: 480px) {
    .dialog-box {
        padding: 20px;
    }

    .history-filters {
        flex-direction: column;
    }

    .history-filters select {
        width: 100%;
    }
}
