/* =============================================
   UzLM-TTS - Main Stylesheet
   Dark theme, glassmorphism, smooth animations
   ============================================= */

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

:root {
    --bg: #08090d;
    --surface: #10121a;
    --surface2: #181b27;
    --surface3: #1e2235;
    --border: #232738;
    --border-hover: #3a3f5c;
    --text: #e8eaf0;
    --text-dim: #8b8fa3;
    --text-faint: #5a5e74;
    --accent: #6c5ce7;
    --accent-glow: rgba(108, 92, 231, 0.25);
    --accent-light: #a29bfe;
    --accent-subtle: rgba(108, 92, 231, 0.08);
    --success: #51cf66;
    --error: #ff6b6b;
    --warning: #feca57;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ---- Background Effects ---- */
.bg-grid {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(108, 92, 231, 0.02) 1px, transparent 1px),
        linear-gradient(90deg, rgba(108, 92, 231, 0.02) 1px, transparent 1px);
    background-size: 64px 64px;
    pointer-events: none;
    z-index: 0;
}

.bg-orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(140px);
    pointer-events: none;
    z-index: 0;
}
.orb-1 { width: 600px; height: 600px; background: #6c5ce7; top: -250px; left: -200px; opacity: 0.15; }
.orb-2 { width: 500px; height: 500px; background: #0984e3; bottom: -200px; right: -150px; opacity: 0.1; }
.orb-3 { width: 300px; height: 300px; background: #a29bfe; top: 50%; left: 50%; transform: translate(-50%,-50%); opacity: 0.06; }

/* ---- Navbar ---- */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    height: 64px;
    background: rgba(8, 9, 13, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    animation: slideDown 0.4s ease;
}

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

.nav-left { display: flex; align-items: center; gap: 12px; }
.nav-logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { display: flex; }
.logo-text {
    font-size: 20px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.3px;
}

.nav-right { display: flex; align-items: center; gap: 16px; }

.admin-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: rgba(255, 107, 107, 0.08);
    border: 1px solid rgba(255, 107, 107, 0.25);
    border-radius: 100px;
    font-size: 13px;
    font-weight: 600;
    color: #ff6b6b;
    text-decoration: none;
    cursor: pointer;
    transition: var(--transition);
}
.admin-chip:hover {
    background: rgba(255, 107, 107, 0.15);
    border-color: rgba(255, 107, 107, 0.4);
    box-shadow: 0 0 16px rgba(255, 107, 107, 0.15);
}

.balance-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--accent-subtle);
    border: 1px solid rgba(108, 92, 231, 0.2);
    border-radius: 100px;
    font-size: 14px;
    font-weight: 600;
    color: var(--accent-light);
    cursor: default;
    transition: var(--transition);
}
.balance-chip:hover {
    border-color: rgba(108, 92, 231, 0.4);
    box-shadow: 0 0 20px rgba(108, 92, 231, 0.1);
}
.balance-label { color: var(--text-dim); font-weight: 500; font-size: 12px; }

.user-menu { position: relative; }
.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #0984e3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: #fff;
    cursor: pointer;
    transition: var(--transition);
}
.avatar:hover { transform: scale(1.08); box-shadow: 0 0 20px var(--accent-glow); }

.user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 220px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: dropIn 0.2s ease;
    z-index: 200;
}
.user-dropdown.show { display: block; }
@keyframes dropIn {
    from { opacity: 0; transform: translateY(-8px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.dropdown-header { padding: 14px 16px; }
.dropdown-name { font-weight: 700; font-size: 14px; }
.dropdown-email { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.dropdown-divider { height: 1px; background: var(--border); }
.dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: none;
    color: var(--text-dim);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}
.dropdown-item:hover { background: var(--surface3); color: var(--error); }

/* ---- Main ---- */
.main-content {
    position: relative;
    z-index: 1;
    max-width: 800px;
    margin: 0 auto;
    padding: 40px 24px 80px;
}

.hero-section {
    text-align: center;
    margin-bottom: 48px;
    animation: fadeUp 0.6s ease;
}
.hero-title { font-size: 40px; font-weight: 800; line-height: 1.15; letter-spacing: -1px; }
.hero-line { display: block; color: var(--text); }
.hero-accent {
    display: block;
    background: linear-gradient(135deg, var(--accent-light) 0%, var(--accent) 50%, #0984e3 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.hero-sub { color: var(--text-dim); font-size: 16px; margin-top: 12px; max-width: 500px; margin-inline: auto; line-height: 1.6; }

.workspace {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ---- Input Card ---- */
.input-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    animation: fadeUp 0.5s ease 0.1s both;
    transition: border-color var(--transition);
}
.input-card:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 0;
}
.card-header h2 { font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-dim); }
.char-counter { font-size: 13px; color: var(--text-faint); font-family: 'JetBrains Mono', monospace; }
.char-counter strong { color: var(--accent-light); }
.cost-label { color: var(--text-dim); }

.text-area {
    width: 100%;
    min-height: 180px;
    max-height: 400px;
    padding: 16px 20px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 16px;
    font-family: inherit;
    line-height: 1.7;
    resize: vertical;
    outline: none;
}
.text-area::placeholder { color: var(--text-faint); }

.text-limit-bar {
    height: 3px;
    background: var(--surface2);
}
.text-limit-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    border-radius: 0 3px 3px 0;
    transition: width 0.3s ease;
}

/* ---- Controls Row ---- */
.controls-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    animation: fadeUp 0.5s ease 0.2s both;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.control-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-dim);
    padding-left: 4px;
}

.select-wrapper {
    position: relative;
}
.custom-select {
    width: 100%;
    padding: 12px 40px 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    font-weight: 500;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    outline: none;
    transition: var(--transition);
}
.custom-select:hover { border-color: var(--border-hover); }
.custom-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.custom-select option { background: var(--surface2); color: var(--text); }
.custom-select option:disabled { color: var(--text-faint); }

.select-arrow {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-dim);
    pointer-events: none;
}

/* ---- Generate Button ---- */
.generate-btn {
    position: relative;
    width: 100%;
    padding: 18px 24px;
    border: none;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--accent), #5b4bd5);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s ease;
    animation: fadeUp 0.5s ease 0.3s both;
}
.generate-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, transparent 30%, rgba(255,255,255,0.1) 50%, transparent 70%);
    transform: translateX(-100%);
    transition: transform 0.6s ease;
}
.generate-btn:hover::before { transform: translateX(100%); }
.generate-btn:hover {
    box-shadow: 0 8px 32px var(--accent-glow);
    transform: translateY(-2px);
}
.generate-btn:active { transform: translateY(0); }
.generate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.gen-content { display: flex; align-items: center; justify-content: center; gap: 10px; }
.gen-loader { display: none; align-items: center; justify-content: center; gap: 12px; }

.generate-btn.loading .gen-content { display: none; }
.generate-btn.loading .gen-loader { display: flex; }

.wave-bars {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 20px;
}
.wave-bars span {
    width: 4px;
    height: 8px;
    background: #fff;
    border-radius: 2px;
    animation: wave 1s ease-in-out infinite;
}
.wave-bars span:nth-child(1) { animation-delay: 0s; }
.wave-bars span:nth-child(2) { animation-delay: 0.1s; }
.wave-bars span:nth-child(3) { animation-delay: 0.2s; }
.wave-bars span:nth-child(4) { animation-delay: 0.3s; }
.wave-bars span:nth-child(5) { animation-delay: 0.4s; }
@keyframes wave {
    0%, 100% { height: 8px; }
    50% { height: 20px; }
}

/* ---- Audio Card ---- */
.audio-card {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    animation: scaleIn 0.4s ease;
}
.audio-card.show { display: block; }

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.audio-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.audio-info h3 { font-size: 16px; font-weight: 700; }
.audio-meta { font-size: 12px; color: var(--text-dim); font-family: 'JetBrains Mono', monospace; }

.download-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 100px;
    background: transparent;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}
.download-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.audio-player {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg);
    border-radius: var(--radius);
    padding: 12px 16px;
}

.play-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}
.play-btn:hover {
    background: #5b4bd5;
    box-shadow: 0 4px 20px var(--accent-glow);
    transform: scale(1.08);
}

.waveform-container {
    flex: 1;
    position: relative;
    height: 48px;
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
}
#waveformCanvas {
    width: 100%;
    height: 100%;
    display: block;
}
.waveform-progress {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 0%;
    background: rgba(108, 92, 231, 0.15);
    border-right: 2px solid var(--accent);
    pointer-events: none;
    transition: width 0.05s linear;
}

.audio-time {
    font-size: 12px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-dim);
    white-space: nowrap;
    min-width: 80px;
    text-align: right;
}

/* ---- Popup ---- */
.popup-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
}
.popup-overlay.show { display: flex; }

.popup-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    animation: popIn 0.3s ease;
}
@keyframes popIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.popup-icon { margin-bottom: 16px; }
.popup-card h3 { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.popup-card p { font-size: 14px; color: var(--text-dim); line-height: 1.6; margin-bottom: 24px; }

.popup-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    border: none;
}
.popup-btn.telegram {
    background: #0088cc;
    color: #fff;
    margin-bottom: 10px;
}
.popup-btn.telegram:hover { background: #006daa; }
.popup-btn.close {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-dim);
}
.popup-btn.close:hover { border-color: var(--border-hover); color: var(--text); }

/* ---- General Animations ---- */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
    .navbar { padding: 0 16px; }
    .main-content { padding: 24px 16px 60px; }
    .hero-title { font-size: 28px; }
    .hero-sub { font-size: 14px; }
    .controls-row { grid-template-columns: 1fr; }
    .card-header { flex-direction: column; align-items: flex-start; gap: 6px; }
    .audio-player { flex-wrap: wrap; }
    .audio-time { width: 100%; text-align: center; }
}
