/* Кабинет. Отдельно от style.css: тот собран под мини-приложение телеграма
   и его переменные темы, а кабинет открывается обычным браузером. */

:root {
    --ink: #2b2622;
    --ink-soft: #6d635b;
    --paper: #fbf8f4;
    --card: #ffffff;
    --line: #e7e0d6;
    --accent: #b4643a;
    --accent-soft: #f6ece4;
    --alarm: #a33c2f;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.wrap {
    max-width: 560px;
    margin: 0 auto;
    padding: 40px 20px 64px;
}

.head { position: relative; margin-bottom: 28px; }

/* ---- меню под значком человечка ----------------------------------------- */

.menu-wrap { position: absolute; top: -6px; right: 0; }

.menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    color: var(--accent);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 50%;
    cursor: pointer;
}

.menu {
    position: absolute;
    top: 50px;
    right: 0;
    z-index: 20;
    min-width: 230px;
    padding: 8px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(43, 38, 34, .12);
}

.menu-who {
    margin: 0 0 6px;
    padding: 8px 12px 10px;
    font-size: 14px;
    color: var(--ink-soft);
    border-bottom: 1px solid var(--line);
    overflow-wrap: anywhere;
}

.menu-name {
    display: block;
    font-size: 16px;
    font-weight: 600;
    color: var(--ink);
}

.menu a,
.menu button {
    display: block;
    width: 100%;
    padding: 10px 12px;
    font: inherit;
    text-align: left;
    color: var(--ink);
    text-decoration: none;
    background: none;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.menu a:hover,
.menu button:hover { background: var(--accent-soft); }

.links a {
    display: block;
    padding: 6px 0;
    color: var(--accent);
}

/* `display: block` выше перебивает атрибут hidden — возвращаем его силу,
   иначе видна ссылка на страницу, которой нет. */
.links a[hidden] { display: none; }

.lead.small { font-size: 14px; color: var(--ink-soft); }

.brand {
    margin: 0 0 6px;
    font-size: 13px;
    letter-spacing: .12em;
    color: var(--accent);
}

h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -.01em;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 22px;
    margin-bottom: 16px;
}

.card.accent {
    background: var(--accent-soft);
    border-color: #e6d3c4;
}

.lead {
    margin: 0 0 18px;
    color: var(--ink-soft);
}

.field { display: block; margin-bottom: 16px; }

.field span {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    color: var(--ink-soft);
}

input {
    width: 100%;
    padding: 12px 14px;
    font-size: 16px;
    font-family: inherit;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 10px;
}

input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

#code {
    letter-spacing: .35em;
    font-size: 22px;
    text-align: center;
}

button {
    font: inherit;
    cursor: pointer;
    border-radius: 10px;
}

.primary {
    width: 100%;
    padding: 12px 18px;
    color: #fff;
    background: var(--accent);
    border: 1px solid var(--accent);
    font-weight: 500;
}

.primary:disabled { opacity: .55; cursor: default; }

.quiet {
    padding: 8px 0;
    margin-top: 10px;
    color: var(--ink-soft);
    background: none;
    border: none;
    text-decoration: underline;
}

.row { display: flex; gap: 12px; align-items: center; }
.row .primary { width: auto; }
.row .quiet { margin-top: 0; }

.report {
    display: block;
    padding: 18px 20px;
    margin-bottom: 12px;
    color: inherit;
    text-decoration: none;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
}

.report-name {
    font-size: 18px;
    font-weight: 600;
}

.report-meta {
    margin-top: 4px;
    font-size: 14px;
    color: var(--ink-soft);
}

.tag {
    display: inline-block;
    margin-left: 8px;
    padding: 1px 8px;
    font-size: 12px;
    border-radius: 20px;
    background: var(--accent-soft);
    color: var(--accent);
    vertical-align: 2px;
}

.empty { color: var(--ink-soft); }

.foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 28px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    font-size: 14px;
    color: var(--ink-soft);
}

.message {
    margin: 16px 0 0;
    padding: 12px 14px;
    font-size: 15px;
    border-radius: 10px;
    background: #fdf1ef;
    color: var(--alarm);
    border: 1px solid #f0d6d1;
}

.message.plain {
    background: var(--accent-soft);
    color: var(--ink-soft);
    border-color: #e6d3c4;
}

/* ---- кнопка «Спросить Ниточку» в карточке ------------------------------ */

.report-link {
    display: block;
    color: inherit;
    text-decoration: none;
}

.report-chat { font-weight: 500; }

/* ---- кнопки карточки: одна главная, остальные тише ----------------------- */

.report-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.report-open,
.report-more {
    display: inline-block;
    padding: 9px 18px;
    font-size: 15px;
    text-decoration: none;
    border-radius: 20px;
}

.report-open {
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: 1px solid var(--accent);
}

.report-more {
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid #e6d3c4;
}

.report-pay { font-weight: 600; }

/* ---- окно чата ------------------------------------------------------------
   Высота — видимая область (--chat-h ставит chat.js по visualViewport,
   100dvh — запасной путь): открытая клавиатура сжимает окно, а поле ввода
   остаётся над ней. */

.chat-body { overflow: hidden; }

.chat {
    display: flex;
    flex-direction: column;
    max-width: 640px;
    height: 100vh;
    height: var(--chat-h, 100dvh);
    margin: 0 auto;
}

.chat-head {
    flex: none;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--line);
}

.chat-back {
    font-size: 14px;
    color: var(--ink-soft);
    text-decoration: none;
}

.chat-head .brand { margin: 8px 0 2px; }

.chat-title { font-size: 20px; }

.chat-sub {
    margin: 2px 0 0;
    font-size: 14px;
    color: var(--ink-soft);
}

.chat-log {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}

.chat-hello { color: var(--ink-soft); }

.msg {
    max-width: 88%;
    margin-bottom: 10px;
    padding: 10px 14px;
    border-radius: 14px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.msg-user {
    margin-left: auto;
    color: #fff;
    background: var(--accent);
    border-bottom-right-radius: 4px;
}

.msg-assistant {
    background: var(--card);
    border: 1px solid var(--line);
    border-bottom-left-radius: 4px;
}

.msg-thinking {
    color: var(--ink-soft);
    background: var(--accent-soft);
    font-style: italic;
    animation: chat-pulse 1.4s ease-in-out infinite;
}

.msg-system {
    max-width: 100%;
    font-size: 15px;
    color: var(--alarm);
    background: #fdf1ef;
    border: 1px solid #f0d6d1;
}

@keyframes chat-pulse { 50% { opacity: .5; } }

.chat-foot {
    flex: none;
    padding: 8px 12px 10px;
    background: var(--paper);
    border-top: 1px solid var(--line);
}

.chat-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chat-actions:not(:empty) { margin-bottom: 8px; }

.chip {
    padding: 7px 12px;
    font-size: 14px;
    color: var(--accent);
    background: var(--card);
    border: 1px solid #e6d3c4;
    border-radius: 18px;
    text-align: left;
}

.chip-pay {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
}

.chip:disabled { opacity: .55; cursor: default; }

.chat-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.chat-form textarea {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 46px;
    max-height: 140px;
    padding: 11px 14px;
    font-size: 16px;
    line-height: 1.4;
    font-family: inherit;
    color: var(--ink);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    resize: none;
}

.chat-form textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.chat-send {
    flex: none;
    width: auto;
    min-height: 46px;
}

.chat-left {
    margin: 6px 2px 0;
    font-size: 12px;
    color: var(--ink-soft);
}

/* ---- анкета /test ---------------------------------------------------------
   Один экран за раз; кнопки ответов во всю ширину — под большой палец. */

.test .head { margin-bottom: 18px; }
.test .head .brand { margin-top: 10px; }

.progress {
    height: 6px;
    margin-top: 10px;
    background: var(--line);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width .25s ease;
}

.progress-label {
    margin: 6px 0 0;
    font-size: 13px;
    color: var(--ink-soft);
}

.screen-title { margin-bottom: 12px; font-size: 22px; }

.screen-text {
    margin: 0 0 18px;
    white-space: pre-line;
}

.q-number {
    margin: 0 0 8px;
    font-size: 13px;
    color: var(--ink-soft);
}

.q-text {
    margin: 0 0 10px;
    font-size: 19px;
    font-weight: 600;
    line-height: 1.4;
}

.q-hint {
    margin: 0 0 18px;
    font-size: 15px;
    color: var(--ink-soft);
}

.stack { display: flex; flex-direction: column; gap: 10px; }

.option {
    width: 100%;
    padding: 13px 16px;
    font-size: 16px;
    color: var(--ink);
    text-align: left;
    background: var(--paper);
    border: 1px solid var(--line);
}

.option.chosen {
    background: var(--accent-soft);
    border-color: var(--accent);
    font-weight: 600;
}

.row.two > * { flex: 1 1 0; width: auto; }
.row.two .option { text-align: center; }

.grades {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.grades .option { text-align: center; padding: 13px 0; }

.test form input { margin-bottom: 14px; }
.test .stack + .quiet,
.test form + .quiet,
.test .primary + .quiet { display: block; }
.test form + .option { margin-top: 10px; }

.link-button {
    display: block;
    text-align: center;
    text-decoration: none;
    border-radius: 10px;
}

.review { margin: 0 0 18px; }

.review-row {
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.review dt { font-size: 13px; color: var(--ink-soft); }

.review dd {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin: 2px 0 0;
    font-weight: 500;
}

.quiet.inline { margin: 0; padding: 0; font-size: 14px; font-weight: 400; }

.consent {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    margin: 0 0 18px;
    font-size: 15px;
    line-height: 1.45;
}

.consent input {
    flex: none;
    width: 22px;
    height: 22px;
    margin: 1px 0 0;
    accent-color: var(--accent);
}

.consent a { color: var(--accent); }

.report.new-test {
    display: block;
    width: 100%;
    margin-top: 4px;
    text-align: center;
    color: var(--accent);
    font-weight: 500;
    border-style: dashed;
}

.report-note {
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: #F5E9DF;
    color: #5A4A40;
    font-size: 15px;
    line-height: 1.45;
}

/* ---- этапы сборки на экране ожидания ------------------------------------- */

.stages {
    margin: 0 0 18px;
    padding: 0;
    list-style: none;
}

.stages li {
    position: relative;
    padding: 7px 0 7px 30px;
    color: var(--ink-soft);
}

.stages li::before {
    content: "";
    position: absolute;
    left: 4px;
    top: 13px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--line);
    background: var(--card);
}

.stages li.done { color: var(--ink); }
.stages li.done::before { background: var(--accent); border-color: var(--accent); }

.stages li.now { color: var(--ink); font-weight: 600; }
.stages li.now::before {
    border-color: var(--accent);
    animation: stage-pulse 1.4s ease-in-out infinite;
}

@keyframes stage-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(181, 98, 58, .35); }
    50% { box-shadow: 0 0 0 6px rgba(181, 98, 58, 0); }
}


/* ---- маскот в анкете ------------------------------------------------------ */

.mascot { display: block; height: auto; }
.mascot.big { width: 96px; margin: 0 auto 14px; }
.mascot.small { width: 34px; flex: none; }

.q-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.q-head .q-number { margin: 0; }

/* ---- страница входа /start ------------------------------------------------ */

.start-card { text-align: center; padding: 28px 22px; }
.start-card h1 { margin-bottom: 12px; }
.start-go { display: block; margin: 18px 0 16px; font-size: 18px; padding: 15px 18px; }

.start-facts {
    margin: 0 0 14px;
    padding: 0;
    list-style: none;
    font-size: 15px;
    color: var(--ink-soft);
}

.start-facts li { padding: 3px 0; }
.start-author-name { margin: 0 0 4px; font-weight: 600; }
.start-author .lead { margin: 0; }
