/* ── Anunnaki TTS · Compact Minimal ──────────────────────────────────── */

:root {
    --accent:    #0078d4;
    --accent-h:  #1084e0;
    --danger:    #c42b1c;
    --success:   #107c10;
    --warn:      #9d5d00;

    --bg:        #f5f5f5;
    --surface:   #ffffff;
    --border:    #e0e0e0;
    --text:      #1a1a1a;
    --muted:     #666666;
    --hover:     #f0f0f0;
    --input-bg:  #ffffff;
}

[data-theme="dark"] {
    --bg:        #141414;
    --surface:   #1e1e1e;
    --border:    #333333;
    --text:      #f0f0f0;
    --muted:     #888888;
    --hover:     #2a2a2a;
    --input-bg:  #252525;
    --danger:    #f1707a;
    --success:   #6ccb5f;
    --warn:      #ffd060;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
    line-height: 1.4;
    min-height: 100vh;
    padding-top: 40px;
}

/* ── Header ────────────────────────────────────────────────────────── */
.header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 40px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 14px;
    border-right: 1px solid var(--border);
    height: 100%;
    white-space: nowrap;
    flex-shrink: 0;
}
.logo-icon { font-size: 15px; }
.logo-text  { font-size: 13px; font-weight: 600; color: var(--text); letter-spacing: 0.01em; }

/* ── Tabs (in header) ─────────────────────────────────────────────── */
.tabs {
    display: flex;
    height: 100%;
    flex-shrink: 0;
}
.tab-btn {
    height: 100%;
    padding: 0 16px;
    background: transparent;
    border: none;
    border-right: 1px solid var(--border);
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}
.tab-btn:hover { background: var(--hover); color: var(--text); }
.tab-btn.active {
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
    background: var(--surface);
}

/* ── Header Right ─────────────────────────────────────────────────── */
.header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    margin-left: auto;
}

.gpu-monitor {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 8px;
    height: 26px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 11px;
}
.gpu-label { font-weight: 600; color: var(--muted); }
.gauge-track {
    width: 60px;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}
.gauge-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--success), #f8c100, var(--danger));
    transition: width 0.4s ease;
    border-radius: 3px;
}
.gpu-stats { color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }

.icon-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-size: 15px;
    cursor: pointer;
    border-radius: 3px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* ── Main ─────────────────────────────────────────────────────────── */
.main {
    max-width: 860px;
    margin: 0 auto;
    padding: 16px 16px 32px;
}

/* ── Tabs ─────────────────────────────────────────────────────────── */
.tab { display: none; }
.tab.active { display: flex; flex-direction: column; gap: 10px; }

/* ── Panel ────────────────────────────────────────────────────────── */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 12px 14px;
}
.panel-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 8px;
}
.panel-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    margin-bottom: 0;
}
.panel-toggle:hover { color: var(--fg); }
.panel-chevron {
    margin-left: auto;
    font-size: 11px;
    transition: transform 0.15s;
}
.panel-chevron.open { transform: rotate(90deg); }
.backends-warn {
    font-size: 11px;
    margin-left: 6px;
}
.backends-warn.backends-missing {
    color: #f5a623;
}
.backends-warn.backends-ok {
    color: #4caf50;
}
#backends-list { margin-top: 8px; }

/* ── Form ─────────────────────────────────────────────────────────── */
.row     { display: flex; align-items: flex-end; }
.gap-4   { gap: 4px; }
.gap-8   { gap: 8px; }
.field   { display: flex; flex-direction: column; gap: 3px; }
.field-label { font-size: 11px; font-weight: 600; color: var(--muted); }

label {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
}

select, textarea, input[type="text"] {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text);
    font-size: 12px;
    font-family: inherit;
    padding: 5px 7px;
    width: 100%;
    transition: border-color 0.15s;
}
select:focus, textarea:focus, input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
}
select { height: 28px; padding: 0 7px; cursor: pointer; }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
    height: 28px;
    padding: 0 12px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    white-space: nowrap;
    display: inline-flex; align-items: center; gap: 4px;
    border: 1px solid transparent;
}
.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover  { background: var(--accent-h); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-ghost {
    background: transparent;
    color: var(--text);
    border-color: var(--border);
}
.btn-ghost:hover  { background: var(--hover); }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Status messages ──────────────────────────────────────────────── */
.status-msg {
    font-size: 12px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 20px;
    flex-wrap: wrap;
}
.status-msg.success { color: var(--success); }
.status-msg.error   { color: var(--danger); }
.status-msg.warning { color: var(--warn); }

/* ── Spinner ──────────────────────────────────────────────────────── */
.spin {
    display: inline-block;
    width: 12px; height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Generate layout ──────────────────────────────────────────────── */
.gen-layout {
    display: grid;
    grid-template-columns: 1fr 260px;
    gap: 14px;
}
.gen-left { display: flex; flex-direction: column; gap: 6px; }
.gen-mid  { display: flex; flex-direction: column; }
.gen-left textarea {
    flex: 1;
    min-height: 110px;
    resize: vertical;
    font-family: inherit;
    font-size: 13px;
}

.gen-right { display: flex; flex-direction: column; gap: 10px; }

/* ── Sliders ──────────────────────────────────────────────────────── */
.slider-group { display: flex; flex-direction: column; gap: 8px; }

.seed-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}
.seed-row input[type="number"] {
    width: 80px;
    height: 24px;
    font-size: 11px;
    padding: 0 6px;
    text-align: right;
}
/* hide number input spinners */
.seed-row input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; }
.seed-row input[type="number"] { -moz-appearance: textfield; }

.slider-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.slider-row label {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.label-text { display: flex; align-items: center; gap: 3px; }
.slider-val { color: var(--text); font-weight: 700; }

/* ── Tooltip ──────────────────────────────────────────────────────── */
.tip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 12px; height: 12px;
    border-radius: 50%;
    border: 1px solid var(--muted);
    color: var(--muted);
    font-size: 8px;
    font-weight: 700;
    cursor: help;
    position: relative;
    flex-shrink: 0;
    line-height: 1;
}
.tip::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 7px 9px;
    font-size: 11px;
    font-weight: 400;
    color: var(--text);
    white-space: pre-wrap;
    width: max-content;
    max-width: 340px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
    z-index: 200;
    line-height: 1.6;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.tip:hover::after { opacity: 1; }

/* ── Fill-bar range inputs ────────────────────────────────────────── */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(to right, var(--accent) var(--pct, 0%), var(--border) var(--pct, 0%));
    cursor: pointer;
    padding: 0;
    outline: none;
    border: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}
input[type="range"]:hover::-webkit-slider-thumb,
input[type="range"]:focus::-webkit-slider-thumb { opacity: 1; }
input[type="range"]::-moz-range-thumb {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}
input[type="range"]:hover::-moz-range-thumb,
input[type="range"]:focus::-moz-range-thumb { opacity: 1; }
input[type="range"]::-moz-range-progress {
    background: var(--accent);
    height: 4px;
    border-radius: 2px;
}

/* ── Sidebar sections (Generate tab) ──────────────────────────────── */
.sidebar-section {
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 6px;
}
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--muted);
    user-select: none;
}
.sidebar-header:hover { color: var(--fg); }
.sidebar-header .panel-chevron { margin-left: auto; }
.sidebar-body {
    padding: 6px 10px 10px;
    border-top: 1px solid var(--border);
}
.sidebar-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin: 0 0 8px;
    line-height: 1.4;
}
.sidebar-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text);
    display: block;
    margin: 0 0 3px;
}
.badge-ok {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 3px;
    background: var(--accent);
    color: #fff;
}
.model-badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 3px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    white-space: nowrap;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: default;
    user-select: none;
    opacity: 0.7;
}

/* ── Trim Editor Modal ───────────────────────────────────────────── */
.trim-editor {
    background: var(--bg-2, #1e1e2e);
    border-radius: 12px;
    padding: 24px 28px;
    width: min(800px, 92vw);
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.trim-hint {
    font-size: 0.85rem;
    color: var(--fg-2, #aaa);
    margin: 4px 0 12px;
}
.trim-waveform-wrap {
    position: relative;
    background: #111;
    border-radius: 6px;
    overflow: hidden;
    cursor: default;
}
.trim-waveform-wrap canvas {
    display: block;
    width: 100%;
}
.trim-region {
    position: absolute;
    top: 0; bottom: 0;
    background: rgba(0, 120, 212, 0.2);
    border-left: 2px solid var(--accent, #0078d4);
    border-right: 2px solid var(--accent, #0078d4);
    pointer-events: none;
}
.trim-handle {
    position: absolute;
    top: 0; bottom: 0;
    width: 14px;
    cursor: ew-resize;
    pointer-events: all;
    z-index: 2;
}
.trim-handle::after {
    content: "";
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 4px; height: 32px;
    background: var(--accent, #0078d4);
    border-radius: 2px;
}
.trim-handle-left  { left: -8px; }
.trim-handle-right { right: -8px; }
.trim-times {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--fg-2, #aaa);
    margin: 6px 0 12px;
    font-variant-numeric: tabular-nums;
}
.trim-controls {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.trim-processing {
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border, #333);
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 16px;
}
.trim-processing .slider-row { margin-bottom: 4px; }
.trim-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ── Confirm Dialog ──────────────────────────────────────────────── */
.confirm-dialog {
    background: var(--bg-2, #1e1e2e);
    border-radius: 12px;
    padding: 24px 28px;
    width: min(420px, 88vw);
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.confirm-msg {
    font-size: 0.95rem;
    line-height: 1.5;
    white-space: pre-line;
    margin-bottom: 20px;
}
.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ── Recording Modal ──────────────────────────────────────────────── */
.rec-modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
}
.rec-modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 28px 32px;
    width: 520px;
    max-width: 92vw;
    max-height: 90vh;
    overflow-y: auto;
}
.rec-modal-header {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
    text-align: center;
}
.rec-modal-hint {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
    text-align: center;
    margin-bottom: 14px;
}
.rec-modal-text {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 14px 16px;
    font-size: 15px;
    line-height: 1.6;
}
.rec-modal-text p { margin: 4px 0; }
.rec-modal-lang {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}
.rec-modal-countdown-num {
    font-size: 72px;
    font-weight: 700;
    text-align: center;
    color: var(--primary);
    line-height: 1;
    margin: 20px 0;
}
.rec-modal-recording-indicator {
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    color: var(--danger);
    animation: rec-pulse 1s ease-in-out infinite;
}
@keyframes rec-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}
.rec-modal-timer {
    text-align: center;
    font-size: 32px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    margin: 10px 0;
}
.rec-modal-waveform {
    width: 100%;
    height: 80px;
    border-radius: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
}

/* ── Audio output ─────────────────────────────────────────────────── */
.audio-box {
    margin-top: 10px;
    padding: 10px;
    border: 1px dashed var(--accent);
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.audio-box audio { flex: 1; height: 32px; }
.audio-output-actions { display: flex; gap: 6px; align-items: center; }
.audio-box.disabled-audio {
    opacity: 0.35;
    pointer-events: none;
}

/* ── File list ────────────────────────────────────────────────────── */
.outputs-list { display: flex; flex-direction: column; gap: 6px; }

.output-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg);
    transition: border-color 0.15s;
}
.output-item:hover { border-color: var(--accent); }
.output-info { flex: 1; min-width: 0; }
.output-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.output-meta { font-size: 11px; color: var(--muted); }
.output-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.output-actions audio { width: 180px; height: 26px; }

/* ── Status box (GPU page) ────────────────────────────────────────── */
.status-box {
    font-size: 12px;
    color: var(--muted);
    padding: 6px 0;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.status-box.success { color: var(--success); }
.status-box.error   { color: var(--danger); }
.status-box.warning { color: var(--warn); }

/* ── Responsive ───────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .gen-layout { grid-template-columns: 1fr; }
    .gen-left  { order: -1; }
    .gen-mid   { order: 0; }
    .gen-right { order: 1; }
    .logo-text  { display: none; }
}

/* ── Ref Audio Player ─────────────────────────────────────────────── */
.ref-audio-player-wrap {
    margin-top: 10px;
    padding: 8px;
    border: 1px solid var(--accent, #0078d4);
    border-radius: 6px;
    background: rgba(0, 120, 212, 0.06);
}
.ref-audio-player-wrap .sidebar-label {
    margin-bottom: 4px;
}

/* ── Ref Audio / Mic ──────────────────────────────────────────────── */
.ref-sep {
    text-align: center;
    font-size: 11px;
    color: var(--muted);
    margin: 6px 0;
    letter-spacing: 0.04em;
}
.phonetic-box {
    margin-top: 6px;
    padding: 8px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 11px;
    line-height: 1.5;
}
.phonetic-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    margin-bottom: 3px;
}
.phonetic-text {
    color: var(--text);
    margin: 0;
    line-height: 1.55;
    user-select: all;
}
.phonetic-hint {
    margin-top: 8px;
    font-size: 11px;
    color: var(--muted);
    opacity: .7;
}

.rec-waveform {
    display: block;
    width: 100%;
    height: 60px;
    margin-top: 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
}

.pitch-controls {
    margin-top: 6px;
    padding: 8px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
}

/* ── Backends Panel ───────────────────────────────────────────────── */
.backends-list       { display: flex; flex-direction: column; gap: 6px; }
.backend-row         { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.backend-name        { flex: 1; font-size: 13px; }
.backend-status      { font-size: 12px; white-space: nowrap; }
.backend-status.installed { color: var(--success); }
.backend-status.missing   { color: var(--danger); }
.btn-sm              { padding: 2px 8px; font-size: 12px; }
.install-log         { font-size: 11px; font-family: monospace; background: var(--hover);
                       border: 1px solid var(--border); border-radius: 4px; padding: 8px;
                       max-height: 200px; overflow-y: auto; white-space: pre-wrap;
                       word-break: break-all; margin-top: 4px; }
