/* ========================================
   Tilqazyna AI — Light Theme (HIG)
   ======================================== */

:root {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --surface-2: #f0f0f3;
    --surface-3: #e8e8ed;
    --border: #d5d5dc;
    --border-hover: #b8b8c4;
    --text: #1d1d2b;
    --text-2: #6e6e80;
    --text-3: #a0a0b0;
    --accent: #d97706;
    --accent-hover: #b45309;
    --accent-bg: #fffbeb;
    --accent-border: #fde68a;
    --accent-light: rgba(217, 119, 6, 0.08);
    --success: #059669;
    --success-bg: #ecfdf5;
    --error: #dc2626;
    --error-bg: #fef2f2;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --font: 'Plus Jakarta Sans', system-ui, sans-serif;
    --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
    --font-mono: 'Fira Code', monospace;
    --topbar-h: 52px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.08);
    --transition: 150ms ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { height: 100%; -webkit-font-smoothing: antialiased; }

body {
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ---- Topbar ---- */
.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    z-index: 100;
    flex-shrink: 0;
    min-width: 0;
}

.topbar-left {
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.02em;
    user-select: none;
    text-decoration: none;
    color: inherit;
    white-space: nowrap;
}
.logo-mark { color: var(--accent); font-size: 12px; }
.logo-text { color: var(--text); }
.logo-sub { color: var(--text-3); font-weight: 400; font-size: 11px; }

.service-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    justify-content: center;
    min-width: 0;
}

.nav-tab {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-2);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
    flex-shrink: 0;
}
.nav-tab:hover { color: var(--text); background: var(--surface-2); }
.nav-tab.active {
    color: var(--accent-hover);
    background: var(--accent-bg);
    border-color: var(--accent-border);
}
.nav-tab.active .tab-icon { stroke: var(--accent-hover); }

.tab-icon { width: 16px; height: 16px; flex-shrink: 0; stroke: var(--text-3); transition: stroke var(--transition); }

.health-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-3);
    transition: background var(--transition);
    flex-shrink: 0;
}
.health-dot.ok { background: var(--success); }
.health-dot.err { background: var(--error); }

.topbar-right {
    margin-left: auto;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-3);
    cursor: pointer;
    transition: all var(--transition);
}
.settings-btn:hover { color: var(--text-2); border-color: var(--border-hover); background: var(--surface-2); }

/* ---- Content ---- */
.content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.panel {
    display: none;
    position: absolute;
    inset: 0;
    overflow-y: auto;
    padding: 24px 24px;
    animation: fadeIn 150ms ease;
}
.panel.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---- Panel Grid ---- */
.panel-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    max-width: 1000px;
    margin: 0 auto;
    height: 100%;
}

.panel-input-area, .panel-output-area {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.section-header h2 {
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ---- Dropzone ---- */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px 20px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    background: var(--surface);
}
.dropzone:hover, .dropzone.drag-over {
    border-color: var(--accent);
    background: var(--accent-bg);
}
.dropzone-icon { color: var(--text-3); margin-bottom: 8px; }
.dropzone:hover .dropzone-icon, .dropzone.drag-over .dropzone-icon { color: var(--accent); }
.dropzone-text { color: var(--text-2); font-size: 14px; margin-bottom: 4px; }
.dropzone-hint { color: var(--text-3); font-size: 12px; }

.file-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.file-name {
    flex: 1;
    font-size: 13px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.divider-with-text {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-3);
    font-size: 12px;
}
.divider-with-text::before, .divider-with-text::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ---- Record ---- */
.record-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-2);
    font-family: var(--font);
    font-size: 13px;
    cursor: pointer;
    transition: all var(--transition);
}
.record-btn:hover { border-color: var(--error); color: var(--error); background: var(--error-bg); }

.record-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--error);
}

.recording-indicator {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    background: var(--error-bg);
    border: 1px solid rgba(220,38,38,0.2);
    border-radius: var(--radius-sm);
}

.recording-bars {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 20px;
}
.recording-bars span {
    width: 3px;
    background: var(--error);
    border-radius: 2px;
    animation: barPulse 0.8s ease-in-out infinite;
}
.recording-bars span:nth-child(1) { height: 8px; animation-delay: 0s; }
.recording-bars span:nth-child(2) { height: 14px; animation-delay: 0.15s; }
.recording-bars span:nth-child(3) { height: 20px; animation-delay: 0.3s; }
.recording-bars span:nth-child(4) { height: 14px; animation-delay: 0.45s; }
.recording-bars span:nth-child(5) { height: 8px; animation-delay: 0.6s; }

@keyframes barPulse {
    0%, 100% { transform: scaleY(0.4); }
    50% { transform: scaleY(1); }
}

.recording-time {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--error);
    min-width: 42px;
}

.btn-stop {
    margin-left: auto;
    padding: 6px 14px;
    border: 1px solid rgba(220,38,38,0.3);
    border-radius: var(--radius-sm);
    background: white;
    color: var(--error);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
}
.btn-stop:hover { background: var(--error-bg); }

/* ---- Advanced settings ---- */
.advanced-settings {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    overflow: hidden;
}
.advanced-settings summary {
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.advanced-settings summary::before {
    content: '\25B8  ';
    color: var(--text-3);
    display: inline-block;
    transition: transform var(--transition);
}
.advanced-settings[open] summary::before { transform: rotate(90deg); }
.advanced-settings summary::-webkit-details-marker { display: none; }

.settings-grid {
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    border-top: 1px solid var(--border);
}

/* ---- Fields ---- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-2);
    display: flex;
    justify-content: space-between;
}
.field-label output {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--accent);
}

.field-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-2);
    cursor: pointer;
}
.field-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    cursor: pointer;
}

select, input[type="text"], input[type="number"], textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
select:focus, input[type="text"]:focus, input[type="number"]:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}
textarea { resize: vertical; }
select { cursor: pointer; }

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--surface-3);
    outline: none;
}
input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid white;
    box-shadow: var(--shadow);
}

.file-input-styled { font-size: 12px; color: var(--text-2); }
.file-input-styled::file-selector-button {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-2);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    margin-right: 8px;
}

/* ---- Buttons ---- */
.btn-primary {
    padding: 10px 28px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    align-self: stretch;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-primary.loading .btn-label { display: none; }
.btn-primary.loading .btn-loader { display: inline-block; }

.btn-loader {
    width: 18px;
    height: 18px;
    border: 2px solid transparent;
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-sm {
    padding: 5px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-2);
    font-family: var(--font);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn-sm:hover { color: var(--text); border-color: var(--border-hover); }

.btn-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-3);
    font-size: 16px;
    cursor: pointer;
    transition: all var(--transition);
}
.btn-icon:hover { color: var(--text); background: var(--surface-2); }

/* ---- Output ---- */
.output-actions { display: flex; gap: 6px; }

.output-box {
    flex: 1;
    padding: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-y: auto;
    min-height: 200px;
}

.output-meta {
    font-size: 12px;
    color: var(--text-3);
    font-family: var(--font-mono);
    padding: 0 4px;
}

.placeholder {
    color: var(--text-3);
    font-style: italic;
    font-size: 13px;
}

/* ---- TTS ---- */
.tts-textarea {
    padding: 16px;
    min-height: 180px;
    font-size: 15px;
    line-height: 1.7;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.tts-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }

.audio-output {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    min-height: 200px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.audio-output audio {
    width: 100%;
    max-width: 420px;
    border-radius: var(--radius-sm);
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.2);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 120ms ease;
}
.modal-overlay[hidden] { display: none; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    overflow: hidden;
    box-shadow: 0 16px 48px rgba(0,0,0,0.12);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-family: var(--font-display); font-size: 15px; font-weight: 600; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-hint { font-size: 12px; color: var(--text-3); line-height: 1.5; }

/* ---- Toast ---- */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    animation: toastIn 200ms ease;
    max-width: 320px;
}
.toast.success { background: var(--success-bg); border-color: rgba(5,150,105,0.25); color: var(--success); }
.toast.error { background: var(--error-bg); border-color: rgba(220,38,38,0.2); color: var(--error); }

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

/* ---- Responsive ---- */
@media (max-width: 800px) {
    .panel-grid { grid-template-columns: 1fr; }
    .panel { padding: 20px 16px; }
    .tab-label { display: none; }
    .nav-tab { padding: 6px 10px; }
    .topbar { padding: 0 12px; }
}

@media (max-width: 480px) {
    .logo-text, .logo-sub { display: none; }
    .topbar { gap: 8px; }
}
