:root {
    --bg: #0f0f13;
    --bg-card: #18181f;
    --bg-card-hover: #1e1e28;
    --border: #2a2a3a;
    --text: #e4e4ef;
    --text-dim: #8888a0;
    --accent: #7c6ff7;
    --accent-glow: rgba(124, 111, 247, 0.15);
    --accent-light: #a89bfc;
    --green: #4ade80;
    --orange: #fb923c;
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ── Layout ── */

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 32px 24px;
}

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

header h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

header p {
    color: var(--text-dim);
    margin-top: 6px;
    font-size: 0.95rem;
}

/* ── Navigation ── */

nav {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 32px;
}

nav button {
    padding: 8px 20px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: transparent;
    color: var(--text-dim);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

nav button:hover {
    border-color: var(--accent);
    color: var(--text);
}

nav button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* ── Input Screen ── */

.input-area {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

textarea {
    width: 100%;
    min-height: 180px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.6;
    resize: vertical;
    transition: border-color 0.2s;
}

textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea::placeholder {
    color: var(--text-dim);
}

/* ── Field Labels ── */

.field-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: -8px;
}

.field-label .required {
    color: var(--accent-light);
}

.question-textarea {
    min-height: 60px;
}

.auto-grow {
    overflow: hidden;
    max-height: 60vh;
    resize: none;
    transition: height 0.15s ease;
}

.auto-grow.scrollable {
    overflow-y: auto;
}

/* ── Theory section (collapsible) ── */

.theory-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toggle-theory-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 0.9rem;
    font-family: inherit;
    cursor: pointer;
    transition: color 0.2s;
}

.toggle-theory-btn:hover {
    color: var(--text);
}

.toggle-chevron {
    font-size: 0.7rem;
    transition: transform 0.2s;
}

.toggle-theory-btn.open .toggle-chevron {
    transform: rotate(90deg);
}

.theory-collapse {
    display: none;
    flex-direction: column;
    gap: 12px;
}

.theory-collapse.visible {
    display: flex;
}

/* ── Search ── */

.search-row {
    display: flex;
    gap: 8px;
}

.search-input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-input::placeholder {
    color: var(--text-dim);
}

.search-btn {
    padding: 12px 24px;
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    background: transparent;
    color: var(--accent-light);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.search-btn:hover {
    background: var(--accent-glow);
}

.search-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.search-results {
    display: none;
}

.search-results.visible {
    display: block;
}

.search-loading, .search-empty {
    text-align: center;
    color: var(--text-dim);
    padding: 20px;
    font-size: 0.9rem;
}

.search-compiled {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.search-compiled-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.85rem;
}

.search-use-btn {
    padding: 6px 16px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.search-use-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--accent-glow);
}

.search-preview {
    padding: 16px;
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text);
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
}

.examples-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.example-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-dim);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.example-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent);
    color: var(--text);
}

.mode-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

.run-btn {
    padding: 14px 32px;
    border: none;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--accent), #6355e0);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s;
}

.run-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--accent-glow);
}

.run-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.run-btn-secondary {
    padding: 14px 24px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-dim);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s;
}

.run-btn-secondary:hover {
    border-color: var(--accent);
    color: var(--text);
}

.run-btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Progress ── */

.progress-area {
    display: none;
    margin-bottom: 24px;
}

.progress-area.visible {
    display: block;
}

.progress-bar-track {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    border-radius: 2px;
    transition: width 0.6s ease;
    width: 0%;
}

.progress-label {
    font-size: 0.85rem;
    color: var(--text-dim);
}

.progress-label .current-step {
    color: var(--accent-light);
}

/* ── Steps Output ── */

.steps-area {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.step-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    animation: fadeSlideIn 0.4s ease;
}

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

.step-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.step-header:hover {
    background: var(--bg-card-hover);
}

.step-number {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent-glow);
    color: var(--accent-light);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    flex-shrink: 0;
}

.step-title {
    font-weight: 600;
    font-size: 0.95rem;
    flex: 1;
}

.step-chevron {
    color: var(--text-dim);
    transition: transform 0.2s;
    font-size: 0.85rem;
}

.step-card.open .step-chevron {
    transform: rotate(90deg);
}

.step-body {
    display: none;
    padding: 0 18px 18px;
}

.step-card.open .step-body {
    display: block;
}

.step-content {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text);
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Финальная развилка — выделяем */
.step-card.final {
    border-color: var(--accent);
    box-shadow: 0 0 20px var(--accent-glow);
}

.step-card.final .step-number {
    background: var(--accent);
    color: white;
}

/* ── History ── */

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    padding: 16px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
}

.history-item:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent);
}

.history-time {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.history-preview {
    font-size: 0.9rem;
    color: var(--text);
    line-height: 1.5;
}

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

/* ── History detail ── */

.history-detail {
    display: none;
}

.history-detail.visible {
    display: block;
}

.back-btn {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-dim);
    font-size: 0.85rem;
    cursor: pointer;
    margin-bottom: 20px;
    transition: all 0.2s;
}

.back-btn:hover {
    border-color: var(--accent);
    color: var(--text);
}

.readable-output {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    font-size: 0.9rem;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 80vh;
    overflow-y: auto;
}

/* ── Scrollbar ── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Chat Mode (0.3) ── */

.chat-area {
    display: none;
    margin-top: 24px;
}

.chat-area.visible {
    display: block;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.phase-indicator {
    font-size: 0.85rem;
    font-weight: 600;
    padding: 6px 14px;
    border-radius: 999px;
    transition: all 0.4s;
}

.phase-discovery { background: var(--accent-glow); color: var(--accent-light); }
.phase-probing { background: rgba(251, 146, 60, 0.15); color: var(--orange); }
.phase-resolution { background: rgba(74, 222, 128, 0.15); color: var(--green); }
.phase-complete { background: rgba(74, 222, 128, 0.25); color: var(--green); }

.end-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-dim);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.end-btn:hover { border-color: var(--orange); color: var(--orange); }

.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 4px 0;
    margin-bottom: 16px;
}

.chat-msg {
    animation: fadeSlideIn 0.4s ease;
    max-width: 90%;
}

.system-msg {
    align-self: flex-start;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 0 var(--radius) var(--radius) var(--radius);
    padding: 16px 20px;
}

.user-msg {
    align-self: flex-end;
    background: var(--accent-glow);
    border: 1px solid rgba(124, 111, 247, 0.3);
    border-radius: var(--radius) 0 var(--radius) var(--radius);
    padding: 12px 18px;
}

.msg-body {
    font-size: 0.93rem;
    line-height: 1.75;
    color: var(--text);
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ── Chat Interaction ── */

.chat-interaction {
    display: none;
}

.chat-interaction.visible {
    display: block;
}

.chat-loading {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    color: var(--text-dim);
    font-size: 0.9rem;
}

.chat-loading.visible {
    display: flex;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.reaction-area {
    display: none;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.reaction-area.visible {
    display: flex;
}

.reaction-input {
    width: 100%;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    line-height: 1.5;
    resize: vertical;
}

.reaction-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.next-act-btn {
    padding: 12px 28px;
    border: none;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--accent), #6355e0);
    color: white;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s;
    align-self: flex-end;
}

.next-act-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--accent-glow);
}

.next-act-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ── Choice (A/B) ── */

.choice-area {
    display: none;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
    background: var(--bg-card);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: 0 0 24px var(--accent-glow);
}

.choice-area.visible {
    display: flex;
}

.choice-prompt {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.9rem;
}

.choice-buttons {
    display: flex;
    gap: 12px;
}

.choice-btn {
    flex: 1;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
    line-height: 1.6;
    cursor: pointer;
    transition: all 0.25s;
    text-align: left;
    white-space: pre-wrap;
}

.choice-btn:hover {
    border-color: var(--accent);
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.choice-a::before {
    content: "A";
    display: inline-block;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    text-align: center;
    line-height: 24px;
    font-weight: 700;
    font-size: 0.8rem;
    margin-right: 10px;
    margin-bottom: 8px;
    vertical-align: middle;
}

.choice-b::before {
    content: "B";
    display: inline-block;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--green);
    color: #0f0f13;
    text-align: center;
    line-height: 24px;
    font-weight: 700;
    font-size: 0.8rem;
    margin-right: 10px;
    margin-bottom: 8px;
    vertical-align: middle;
}

/* ── Session Done ── */

.session-done {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 24px;
    text-align: center;
}

.session-done.visible {
    display: flex;
}

.session-done p {
    color: var(--green);
    font-size: 1rem;
    font-weight: 500;
}

/* ── Бейджи типа записи в истории ── */

.history-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    vertical-align: middle;
    margin-left: 8px;
}

.history-badge.dialogue {
    background: rgba(124, 87, 255, 0.2);
    color: var(--accent);
}

.history-badge.stream {
    background: rgba(0, 200, 150, 0.15);
    color: var(--green);
}

.history-phase {
    font-size: 0.75rem;
    color: var(--orange);
    margin-left: 6px;
}

/* ── Responsive ── */

@media (max-width: 640px) {
    .container { padding: 20px 16px; }
    header h1 { font-size: 1.5rem; }
    textarea { min-height: 140px; }
    .mode-row { flex-direction: column; }
    .mode-row .run-btn,
    .mode-row .run-btn-secondary { width: 100%; text-align: center; }
    .choice-buttons { flex-direction: column; }
}
