/* Психотрекер — оформление кабинета специалиста.
   Никаких внешних шрифтов и библиотек: всё локальное.
   Это и требование приватности (нет обращений к сторонним серверам),
   и гарантия работы в закрытом контуре. */

:root {
    color-scheme: light;
    --bg: #f6f4ee;
    --bg-soft: #f0f2eb;
    --surface: #fffef9;
    --surface-2: #e7ece2;
    --border: #d5dbd0;
    --border-strong: #858f80;
    --text: #303b34;
    --text-muted: #536252;
    --text-dim: #5f695d;
    --accent: #49634f;
    --accent-soft: #e2ebdc;
    --danger: #963e49;
    --warning: #795913;
    --success: #3f664e;
    --info: #42657a;
    --shadow: 0 14px 40px rgba(48, 59, 52, 0.08);
    --radius: 14px;
    --radius-sm: 9px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial,
        "Noto Sans", sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-underline-offset: 3px;
}

button,
input,
textarea,
select {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

.hidden {
    display: none !important;
}

/* --- Кнопки --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    font-weight: 500;
    transition: background 0.15s, border-color 0.15s, transform 0.05s;
    white-space: nowrap;
}

.btn:hover {
    background: #dce5d6;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fffef9;
}

.btn-primary:hover {
    background: #3d5542;
}

.btn-ghost {
    background: transparent;
}

.btn-sm {
    padding: 6px 11px;
    font-size: 13px;
}

.btn[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
}

/* --- Вход и регистрация --- */
.auth-wrap {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
}

.auth-card {
    width: 100%;
    max-width: 460px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 32px;
    box-shadow: var(--shadow);
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.4px;
    margin: 0 0 6px;
}

.auth-sub {
    color: var(--text-muted);
    margin: 0 0 24px;
    font-size: 14px;
}

.tabs {
    display: flex;
    gap: 6px;
    background: var(--bg-soft);
    padding: 5px;
    border-radius: var(--radius-sm);
    margin-bottom: 22px;
}

.tab {
    flex: 1;
    padding: 9px;
    text-align: center;
    border-radius: 7px;
    cursor: pointer;
    color: var(--text-muted);
    border: none;
    background: transparent;
    font-weight: 500;
}

.tab.active {
    background: var(--surface-2);
    color: var(--text);
}

.field {
    margin-bottom: 16px;
}

.field label {
    display: block;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.field input,
.field textarea {
    width: 100%;
    padding: 11px 13px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.15s;
}

.field input:focus,
.field textarea:focus {
    border-color: var(--accent);
}

.field .hint {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 5px;
}

.checkbox-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 18px;
}

.checkbox-row input {
    margin-top: 3px;
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
    flex-shrink: 0;
}

.form-error {
    background: #f7e8e7;
    border: 1px solid #c9989b;
    color: var(--danger);
    padding: 10px 13px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
}

.auth-footer {
    margin-top: 22px;
    font-size: 12px;
    color: var(--text-dim);
    text-align: center;
    line-height: 1.6;
}

/* --- Каркас кабинета --- */
.app {
    display: grid;
    grid-template-rows: auto 1fr;
    height: 100%;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 22px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 254, 249, 0.96);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    object-fit: cover;
    background: var(--accent-soft);
    display: grid;
    place-items: center;
    font-size: 15px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-user {
    font-size: 13px;
    color: var(--text-muted);
    text-align: right;
    line-height: 1.3;
}

.layout {
    display: grid;
    grid-template-columns: 310px 1fr;
    min-height: 0;
    /* Без min-width: 0 колонки грида раздуваются по содержимому
       и на телефоне появляется горизонтальная прокрутка. */
    min-width: 0;
}

.layout > * {
    min-width: 0;
}

/* --- Список клиентов --- */
.sidebar {
    border-right: 1px solid var(--border);
    background: #edf0e7;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sidebar-head {
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.sidebar-title h2 {
    margin: 0;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-dim);
}

.search-input {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
}

.client-list {
    list-style: none;
    margin: 0;
    padding: 8px;
    overflow-y: auto;
    flex: 1;
}

.client-item {
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1px solid transparent;
    margin-bottom: 4px;
    transition: background 0.12s;
}

.client-item:hover {
    background: var(--surface-2);
}

.client-item.active {
    background: var(--accent-soft);
    border-color: var(--accent);
}

.client-item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.client-name {
    font-weight: 600;
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.client-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-dim);
}

.dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--text-dim);
    flex-shrink: 0;
}

.empty-hint {
    padding: 28px 18px;
    text-align: center;
    color: var(--text-dim);
    font-size: 13px;
    line-height: 1.7;
}

/* --- Бейджи --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge-danger {
    background: #f7e8e7;
    color: var(--danger);
    border-color: #c9989b;
}

.badge-warning {
    background: #f5eed8;
    color: var(--warning);
    border-color: #bcaa72;
}

.badge-info {
    background: #e6edf0;
    color: var(--info);
    border-color: #9bafb8;
}

.badge-success {
    background: #e2ebdc;
    color: var(--success);
    border-color: #9aac95;
}

.badge-muted {
    background: var(--bg-soft);
    color: var(--text-muted);
    border-color: var(--border);
}

.trend-up {
    color: var(--danger);
}

.trend-down {
    color: var(--success);
}

.trend-flat {
    color: var(--text-dim);
}

/* --- Основная область --- */
.content {
    padding: 22px;
    overflow-y: auto;
    min-height: 0;
}

.empty-state {
    height: 100%;
    display: grid;
    place-items: center;
    text-align: center;
    color: var(--text-muted);
}

.empty-state-inner {
    max-width: 480px;
}

.empty-state h2 {
    color: var(--text);
    margin-bottom: 10px;
}

.client-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.client-head h1 {
    margin: 0 0 6px;
    font-size: 26px;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.client-head-meta {
    color: var(--text-dim);
    font-size: 13px;
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}

.head-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.period-switch {
    display: flex;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.period-switch button {
    padding: 7px 12px;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 13px;
}

.period-switch button.active {
    background: var(--accent);
    color: #fff;
}

/* --- Карточки --- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.card-head h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.card-sub {
    font-size: 12px;
    color: var(--text-dim);
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.kpi-label {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.kpi-value {
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.6px;
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.kpi-value small {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-dim);
}

.kpi-foot {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 5px;
}

/* --- Сигналы --- */
.alert {
    display: flex;
    gap: 12px;
    padding: 13px 15px;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    border: 1px solid;
    align-items: flex-start;
}

.alert-icon {
    font-size: 17px;
    line-height: 1.2;
}

.alert-title {
    font-weight: 600;
    margin-bottom: 3px;
    font-size: 14px;
}

.alert-detail {
    font-size: 13px;
    color: var(--text-muted);
}

.alert-danger {
    background: #f7e8e7;
    border-color: #c9989b;
}

.alert-warning {
    background: #f5eed8;
    border-color: #bcaa72;
}

.alert-info {
    background: #e6edf0;
    border-color: #9bafb8;
}

/* --- График --- */
.metric-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-bottom: 14px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg-soft);
    cursor: pointer;
    font-size: 12.5px;
    color: var(--text-muted);
    transition: all 0.12s;
}

.chip.on {
    color: var(--text);
    border-color: var(--border-strong);
    background: var(--surface-2);
}

.chip-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.35;
}

.chip.on .chip-dot {
    opacity: 1;
}

.chart-box {
    position: relative;
    width: 100%;
    overflow-x: auto;
}

.chart-box svg {
    display: block;
    width: 100%;
    height: auto;
}

.chart-tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    padding: 9px 11px;
    font-size: 12px;
    box-shadow: var(--shadow);
    z-index: 5;
    min-width: 150px;
}

.chart-tooltip-date {
    color: var(--text-dim);
    margin-bottom: 6px;
    font-size: 11px;
}

.chart-tooltip-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 1px 0;
}

.chart-tooltip-row span:first-child {
    display: flex;
    align-items: center;
    gap: 6px;
}

.two-col {
    display: grid;
    grid-template-columns: 1.25fr 1fr;
    gap: 16px;
    align-items: start;
}

/* --- Записи --- */
.monitoring-entry {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-bottom: 14px;
    overflow-wrap: anywhere;
}
.entry-scores {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.6;
}
.entry-status {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 6px;
}
.client-answer, .quote {
    background: #e2ebdc;
    border-left: 4px solid var(--accent);
}
.client-answer {
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.client-answer .block-label {
    color: var(--accent);
    font-weight: 700;
}
.client-answer-text {
    color: var(--text);
    font-size: 16px;
    line-height: 1.65;
    white-space: pre-wrap;
}
#context-preview {
    max-width: 100%;
    white-space: normal;
}
.log-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.log-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.log-date {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

.score-bars {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 8px 18px;
    margin-bottom: 14px;
}

.score-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
}

.score-name {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
}

.score-track {
    grid-column: 1 / -1;
    height: 5px;
    background: var(--surface-2);
    border-radius: 3px;
    overflow: hidden;
}

.score-fill {
    height: 100%;
    border-radius: 3px;
}

.quote {
    background: #e2ebdc;
    border-left: 4px solid var(--accent);
    color: var(--text);
    font-size: 16px;
    line-height: 1.65;
    padding: 12px 14px;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin-bottom: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

.block-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-dim);
    margin-bottom: 6px;
}

.ai-box {
    background: #eeedf2;
    border: 1px solid #cbc8d6;
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 10px;
}

.focus-box {
    background: var(--accent-soft);
    border: 1px solid #9aac95;
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}

.themes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.theme-tag {
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    font-size: 11.5px;
    color: var(--text-muted);
}

/* --- Заметки --- */
.note {
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 11px 13px;
    margin-bottom: 8px;
    font-size: 14px;
    white-space: pre-wrap;
    position: relative;
}

.note-date {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 5px;
}

.note-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 3px 6px;
    border-radius: 6px;
}

.note-delete:hover {
    color: var(--danger);
    background: #f7e8e7;
}

textarea.note-input {
    width: 100%;
    min-height: 78px;
    resize: vertical;
    padding: 11px 13px;
    background: var(--bg-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    margin-bottom: 10px;
}

/* --- Модальное окно --- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(38, 48, 40, 0.38);
    display: grid;
    place-items: center;
    padding: 20px;
    z-index: 100;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: 18px;
    padding: 26px;
    width: 100%;
    max-width: 480px;
    box-shadow: var(--shadow);
    max-height: 88vh;
    overflow-y: auto;
}

.modal h3 {
    margin: 0 0 8px;
    font-size: 19px;
}

.modal p.modal-sub {
    margin: 0 0 20px;
    color: var(--text-muted);
    font-size: 13.5px;
}

.code-display {
    font-family: var(--mono);
    font-size: 26px;
    letter-spacing: 3px;
    text-align: center;
    padding: 18px;
    background: var(--bg-soft);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    margin-bottom: 12px;
    user-select: all;
}

.invite-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.invite-code {
    font-family: var(--mono);
    letter-spacing: 1px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 18px;
}

.toast {
    position: fixed;
    bottom: 22px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    padding: 11px 18px;
    border-radius: 999px;
    font-size: 13.5px;
    z-index: 200;
    box-shadow: var(--shadow);
}

.disclaimer {
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.6;
    padding: 14px 16px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    margin-top: 6px;
}

/* --- Юридические страницы --- */
.legal-page {
    max-width: 820px;
    margin: 0 auto;
    padding: 48px 22px 80px;
}

.legal-page h1 {
    letter-spacing: -0.6px;
}

.legal-page h2 {
    font-size: 18px;
    margin-top: 32px;
}

.legal-page p,
.legal-page li {
    color: var(--text-muted);
}

/* --- Адаптив --- */
:where(button, a, input, textarea, select, [tabindex]):focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

input::placeholder,
textarea::placeholder {
    color: var(--text-dim);
    opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; }
}

@media (max-width: 1000px) {
    .two-col {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 780px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 42vh;
    }

    .content {
        padding: 16px;
    }

    .topbar {
        padding: 12px 14px;
        flex-wrap: wrap;
    }

    .topbar-user {
        display: none;
    }

    .topbar-actions {
        flex: 1 1 100%;
        justify-content: space-between;
    }

    .client-head h1 {
        font-size: 21px;
    }

    .period-switch button {
        padding: 7px 9px;
        font-size: 12px;
    }
}
