/**
 * Qwen TTS Web Interface - iOS Style
 * Copyright © 2026 L♾️pTech - All rights reserved
 * Licensed under MIT License
 * 
 * Based on Apple Human Interface Guidelines
 * https://developer.apple.com/design/human-interface-guidelines/
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

:root {
    /* iOS System Colors */
    --ios-blue: #007AFF;
    --ios-green: #34C759;
    --ios-red: #FF3B30;
    --ios-orange: #FF9500;
    --ios-yellow: #FFCC00;
    --ios-purple: #AF52DE;
    --ios-pink: #FF2D55;
    --ios-teal: #5AC8FA;
    
    /* iOS Semantic Colors - Light Mode */
    --ios-bg: #F2F2F7;
    --ios-bg-secondary: #FFFFFF;
    --ios-bg-tertiary: #F2F2F7;
    --ios-label: #000000;
    --ios-label-secondary: #3C3C43;
    --ios-label-tertiary: #3C3C4399;
    --ios-separator: #3C3C4349;
    --ios-fill: #78788033;
    --ios-fill-secondary: #78788028;
    
    /* iOS Typography */
    --ios-font: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', sans-serif;
    
    /* iOS Spacing */
    --ios-margin: 16px;
    --ios-padding: 16px;
    --ios-radius: 10px;
    --ios-radius-large: 14px;
    
    /* Safe areas */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --ios-bg: #000000;
        --ios-bg-secondary: #1C1C1E;
        --ios-bg-tertiary: #2C2C2E;
        --ios-label: #FFFFFF;
        --ios-label-secondary: #EBEBF5;
        --ios-label-tertiary: #EBEBF599;
        --ios-separator: #54545899;
        --ios-fill: #7878805C;
        --ios-fill-secondary: #78788052;
    }
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--ios-font);
    background: var(--ios-bg);
    color: var(--ios-label);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    padding: 0;
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
    line-height: 1.47;
    letter-spacing: -0.022em;
}

.container {
    max-width: 100%;
    padding: 0;
}

/* iOS Navigation Bar Style Header */
header {
    background: var(--ios-bg-secondary);
    padding: 12px var(--ios-margin);
    padding-top: calc(12px + var(--safe-area-top));
    text-align: center;
    border-bottom: 0.5px solid var(--ios-separator);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
}

header h1 {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.41px;
    color: var(--ios-label);
    margin: 0;
}

header .subtitle {
    font-size: 13px;
    color: var(--ios-label-tertiary);
    margin-top: 2px;
}

header .status {
    display: inline-block;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 12px;
    margin-top: 6px;
}

header .status.online {
    background: rgba(52, 199, 89, 0.15);
    color: var(--ios-green);
}

header .status.offline {
    background: rgba(255, 59, 48, 0.15);
    color: var(--ios-red);
}

header .status.busy {
    background: rgba(255, 204, 0, 0.15);
    color: var(--ios-orange);
}

/* iOS Segmented Control (Tabs) */
.tabs {
    display: flex;
    background: var(--ios-fill-secondary);
    border-radius: 8px;
    padding: 2px;
    margin: var(--ios-margin);
    gap: 0;
}

.tab-btn {
    flex: 1;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--ios-label);
    background: transparent;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.tab-btn .icon {
    font-size: 14px;
}

.tab-btn.active {
    background: var(--ios-bg-secondary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.12);
}

/* iOS Grouped Table Style Cards */
.tab-content {
    display: none;
    padding: 0 var(--ios-margin);
    padding-bottom: calc(var(--ios-margin) + var(--safe-area-bottom));
}

.tab-content.active {
    display: block;
}

.card {
    background: var(--ios-bg-secondary);
    border-radius: var(--ios-radius-large);
    margin-bottom: var(--ios-margin);
    overflow: hidden;
}

.card h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.35px;
    padding: var(--ios-padding);
    padding-bottom: 8px;
}

.card .description {
    font-size: 15px;
    color: var(--ios-label-secondary);
    padding: 0 var(--ios-padding);
    padding-bottom: var(--ios-padding);
}

/* iOS Form Elements */
.form-group {
    padding: 0 var(--ios-padding);
    margin-bottom: 0;
}

.form-group + .form-group {
    border-top: 0.5px solid var(--ios-separator);
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 400;
    color: var(--ios-label-secondary);
    text-transform: uppercase;
    letter-spacing: -0.08px;
    padding: 12px 0 6px 0;
}

input[type="text"],
textarea,
select {
    width: 100%;
    padding: 11px 0;
    font-size: 17px;
    font-family: var(--ios-font);
    color: var(--ios-label);
    background: transparent;
    border: none;
    border-radius: 0;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

input[type="text"]::placeholder,
textarea::placeholder {
    color: var(--ios-label-tertiary);
}

textarea {
    min-height: 100px;
    resize: none;
    line-height: 1.47;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%233C3C43' fill-opacity='0.6' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0 center;
    padding-right: 20px;
}

.char-count {
    font-size: 13px;
    color: var(--ios-label-tertiary);
    text-align: right;
    padding: 4px 0 12px 0;
}

.help-text {
    font-size: 13px;
    color: var(--ios-label-tertiary);
    padding: 8px 0 12px 0;
    line-height: 1.38;
}

/* iOS Preset Chips */
.voice-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 0 16px 0;
}

.preset-btn {
    padding: 8px 14px;
    font-size: 15px;
    font-weight: 400;
    color: var(--ios-blue);
    background: var(--ios-fill);
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.preset-btn:active {
    background: var(--ios-fill-secondary);
    transform: scale(0.97);
}

/* iOS Style Presets */
.style-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 0 16px 0;
}

.style-presets .preset-label {
    display: none;
}

.style-btn {
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 400;
    color: var(--ios-blue);
    background: var(--ios-fill);
    border: none;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.style-btn:active {
    background: var(--ios-fill-secondary);
    transform: scale(0.97);
}

/* iOS Audio Source Tabs */
.audio-source-tabs {
    display: flex;
    background: var(--ios-fill-secondary);
    border-radius: 8px;
    padding: 2px;
    margin: 12px 0;
}

.audio-tab {
    flex: 1;
    padding: 10px 16px;
    font-size: 15px;
    font-weight: 500;
    color: var(--ios-label);
    background: transparent;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.audio-tab.active {
    background: var(--ios-bg-secondary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.12);
}

/* iOS File Upload */
.file-upload {
    position: relative;
    margin: 12px 0;
}

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

.file-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    font-size: 17px;
    font-weight: 400;
    color: var(--ios-blue);
    background: var(--ios-fill);
    border: none;
    border-radius: var(--ios-radius);
    cursor: pointer;
    transition: all 0.15s ease;
}

.file-label:active {
    background: var(--ios-fill-secondary);
}

.file-name {
    display: block;
    font-size: 13px;
    color: var(--ios-green);
    margin-top: 8px;
}

/* iOS Recorder */
.audio-section {
    margin: 12px 0;
}

.recorder-container {
    background: var(--ios-fill);
    border-radius: var(--ios-radius-large);
    padding: 24px 20px;
    text-align: center;
}

.recorder-visualizer {
    margin-bottom: 16px;
}

.recorder-visualizer canvas {
    width: 100%;
    height: 60px;
    background: var(--ios-bg-tertiary);
    border-radius: 8px;
}

.recorder-timer {
    font-size: 56px;
    font-weight: 200;
    font-variant-numeric: tabular-nums;
    color: var(--ios-label);
    margin-bottom: 20px;
    font-family: var(--ios-font);
}

.recorder-controls {
    display: flex;
    justify-content: center;
    gap: 16px;
}

.recorder-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: none;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.15s ease;
}

.recorder-btn span {
    font-size: 24px;
}

.recorder-btn.record {
    background: var(--ios-red);
    color: white;
}

.recorder-btn.record:active {
    transform: scale(0.95);
}

.recorder-btn.record.recording {
    animation: ios-pulse 1.5s infinite;
}

@keyframes ios-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.recorder-btn.stop {
    background: var(--ios-fill);
    color: var(--ios-label);
}

.recorder-btn.stop:active {
    background: var(--ios-fill-secondary);
}

#recorded-audio-container {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 0.5px solid var(--ios-separator);
}

#recorded-audio-container audio {
    width: 100%;
    height: 44px;
    margin-bottom: 16px;
}

#recorded-audio-container .btn-sm {
    width: 100%;
    margin: 8px 0;
}

/* iOS Transcription Progress */
.transcription-progress {
    background: var(--ios-fill);
    border-radius: var(--ios-radius);
    padding: 16px;
    margin: 12px 0;
}

.progress-bar {
    height: 4px;
    background: var(--ios-fill-secondary);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-fill {
    height: 100%;
    background: var(--ios-blue);
    border-radius: 2px;
    animation: ios-progress 2s ease-in-out infinite;
}

@keyframes ios-progress {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 100%; }
}

.progress-text {
    font-size: 13px;
    color: var(--ios-label-secondary);
}

/* iOS Primary Button */
.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 16px 20px;
    font-size: 17px;
    font-weight: 600;
    font-family: var(--ios-font);
    color: white;
    background: var(--ios-blue);
    border: none;
    border-radius: var(--ios-radius);
    cursor: pointer;
    transition: all 0.15s ease;
    margin: var(--ios-padding) 0;
}

.btn:active {
    opacity: 0.8;
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.5;
}

.btn-primary {
    background: var(--ios-blue);
}

.btn-secondary {
    background: var(--ios-fill);
    color: var(--ios-blue);
}

.btn-danger {
    background: var(--ios-red);
}

.btn-sm {
    padding: 12px 16px;
    font-size: 15px;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: ios-spin 0.8s linear infinite;
}

@keyframes ios-spin {
    to { transform: rotate(360deg); }
}

/* iOS Result Card */
.result {
    background: var(--ios-bg-secondary);
    border-radius: var(--ios-radius-large);
    padding: var(--ios-padding);
    margin: var(--ios-margin) 0;
}

.result h3 {
    font-size: 17px;
    font-weight: 600;
    color: var(--ios-green);
    margin-bottom: 12px;
}

.result audio {
    width: 100%;
    height: 44px;
    margin-bottom: 12px;
}

/* iOS Error */
.error {
    background: rgba(255, 59, 48, 0.12);
    color: var(--ios-red);
    padding: 12px 16px;
    border-radius: var(--ios-radius);
    font-size: 15px;
    margin: 12px 0;
}

/* iOS Footer */
footer {
    text-align: center;
    padding: 20px var(--ios-margin);
    padding-bottom: calc(20px + var(--safe-area-bottom));
    font-size: 13px;
    color: var(--ios-label-tertiary);
}

footer p {
    margin: 4px 0;
}

#server_url {
    color: var(--ios-blue);
}

/* Desktop adjustments */
@media (min-width: 768px) {
    body {
        padding: 20px;
    }
    
    .container {
        max-width: 500px;
        margin: 0 auto;
    }
    
    header {
        position: relative;
        border-radius: var(--ios-radius-large);
        margin-bottom: var(--ios-margin);
    }
    
    .tabs {
        margin: 0 0 var(--ios-margin) 0;
    }
    
    .tab-content {
        padding: 0;
    }
}
