:root {
    --bg: #f6f7fb;
    --card: #ffffff;
    --primary: #2563eb;
    --danger: #dc2626;
    --secondary: #475569;
    --text: #1e293b;
    --muted: #64748b;
    --border: #e2e8f0;
    --success: #16a34a;
    --warning: #d97706;
    --error: #dc2626;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 16px 40px;
}

header {
    text-align: center;
    margin-bottom: 24px;
}

header h1 { margin: 0 0 8px; font-size: 1.8rem; }
header p { margin: 0; color: var(--muted); }

.status {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    background: #e0f2fe;
    color: #075985;
}
.status.success { background: #dcfce7; color: #166534; }
.status.warning { background: #fef3c7; color: #92400e; }
.status.error { background: #fee2e2; color: #991b1b; }

section {
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    padding: 20px;
    margin-bottom: 20px;
}

section h2 { margin: 0 0 16px; font-size: 1.2rem; }

.audio-controls {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

/* Визуальные состояния кнопок записи */
.audio-controls #btnRecord,
.audio-controls #btnStop {
    transition: opacity 0.2s, background 0.2s, box-shadow 0.2s, transform 0.1s;
}

/* Когда запись НЕ идёт: кнопка «Остановить» выглядит неактивной */
.audio-controls:not(.recording) #btnStop {
    opacity: 0.45;
    cursor: not-allowed;
    background: #94a3b8;
    box-shadow: none;
}

.audio-controls:not(.recording) #btnStop:hover {
    background: #94a3b8;
}

/* Когда запись идёт: кнопка «Записать» выглядит неактивной, «Остановить» — активной */
.audio-controls.recording #btnRecord {
    opacity: 0.5;
    cursor: not-allowed;
}

.audio-controls.recording #btnStop {
    opacity: 1;
    cursor: pointer;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.3);
    animation: pulse-red 1.5s infinite;
}

.btn {
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: #1d4ed8; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover:not(:disabled) { background: #334155; }

.file-input { font-size: 0.95rem; }

.recording-indicator {
    color: var(--danger);
    font-weight: 600;
    animation: pulse 1s infinite;
    margin-top: 8px;
}

audio { width: 100%; margin-top: 12px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.form-grid label {
    display: flex;
    flex-direction: column;
    font-size: 0.9rem;
    color: var(--muted);
}

.form-grid input,
.form-grid select,
textarea {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    margin-top: 4px;
    background: #fff;
    color: var(--text);
}

.form-grid select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 34px;
    cursor: pointer;
}

.form-grid input:focus,
.form-grid select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea { width: 100%; resize: vertical; }

.complaints-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

.complaints-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.complaints-wrapper input {
    border: none;
    padding: 6px 4px;
    margin: 0;
    background: transparent;
    font-size: 1rem;
    outline: none;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #e0f2fe;
    color: #075985;
    border-radius: 12px;
    padding: 4px 10px;
    font-size: 0.9rem;
}

.tag button {
    border: none;
    background: transparent;
    color: #075985;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0 0 0 4px;
}

.actions { display: flex; gap: 12px; flex-wrap: wrap; }

.refine {
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    padding: 20px;
    margin-bottom: 20px;
}

.refine textarea {
    width: 100%;
    margin-bottom: 12px;
}

.refine .hint {
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 12px;
}

.report-version {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0;
    margin-bottom: 20px;
    background: #fff;
    overflow: hidden;
}

.report-version-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: #f8fafc;
    cursor: pointer;
    user-select: none;
    border-bottom: 1px solid var(--border);
}

.report-version-header:hover {
    background: #f1f5f9;
}

.report-version-title {
    margin: 0;
    font-size: 1.2rem;
    color: var(--primary);
}

.report-version-toggle {
    background: var(--secondary);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    flex-shrink: 0;
    margin-left: 12px;
}

.report-version-toggle:hover {
    background: #334155;
}

.report-version-content {
    padding: 16px;
}

.report-version.collapsed .report-version-content {
    display: none;
}

.report { }
.report.hidden, .hidden { display: none; }

.report-block {
    border-bottom: 1px solid var(--border);
    padding: 16px 0;
}
.report-block:last-child { border-bottom: none; }
.report-block h3 { margin: 0 0 8px; font-size: 1.1rem; color: var(--primary); }
.report-block p { margin: 0 0 6px; }
.report-block ul { margin: 6px 0; padding-left: 20px; }

.hypothesis {
    background: #f8fafc;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}
.hypothesis h4 { margin: 0 0 8px; }

.disclaimer {
    text-align: center;
    color: var(--muted);
    font-size: 0.9rem;
    margin-top: 24px;
}

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

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.3); }
    50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0.15); }
    100% { box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.3); }
}

/* Навигация */
.top-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    padding: 12px;
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.nav-link {
    padding: 8px 16px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text);
    font-weight: 500;
    transition: background 0.2s;
}

.nav-link:hover {
    background: #f1f5f9;
}

.nav-link.active {
    background: var(--primary);
    color: white;
}

/* Статистика токенов */
.usage-info {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
    color: #075985;
    font-size: 0.95rem;
}

/* История приёмов */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.history-item:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
}

.history-item-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 8px;
    color: var(--primary);
}

.history-item-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    color: var(--muted);
    font-size: 0.9rem;
}

.history-empty {
    text-align: center;
    color: var(--muted);
    padding: 40px 20px;
}

.history-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.history-detail-header h2 {
    margin: 0 0 6px;
}

.history-detail-meta {
    color: var(--muted);
    font-size: 0.95rem;
}

.history-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 20px;
}

/* Форма редактирования в детализации */
#editFormSection {
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    padding: 20px;
    margin-bottom: 20px;
}

#editFormSection h3 {
    margin: 0 0 16px;
    font-size: 1.1rem;
}

/* Продолжение диалога */
#continueSection {
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    padding: 20px;
    margin-bottom: 20px;
}

#continueSection h3 {
    margin: 0 0 8px;
    font-size: 1.1rem;
}

#continueSection .hint {
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 12px;
}

#continueSection textarea {
    width: 100%;
    margin-bottom: 12px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
}

#continueSection textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
