:root {
    color-scheme: light;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #172033;
    background: #f5f7fb;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    height: 100vh;
    display: grid;
    grid-template-columns: 340px 1fr;
    overflow: hidden;
}

.sidebar {
    background: #ffffff;
    border-right: 1px solid #dfe5ef;
    height: 100vh;
    overflow: auto;
}

.brand {
    height: 64px;
    padding: 0 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #e7ecf3;
}

.brand a {
    color: #246bfe;
    text-decoration: none;
    font-size: 14px;
}

.brand span {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logout-form {
    margin: 0;
}

.logout-form button {
    padding: 6px 8px;
    border-color: #d8dfeb;
    background: #fff;
    color: #48566f;
    font-size: 13px;
}

.search {
    padding: 14px;
}

input,
select,
textarea,
button {
    width: 100%;
    border: 1px solid #d8dfeb;
    border-radius: 8px;
    padding: 10px 12px;
    font: inherit;
}

button {
    width: auto;
    border-color: #246bfe;
    background: #246bfe;
    color: #fff;
    cursor: pointer;
}

.sidebar-actions {
    padding: 0 14px 12px;
}

.new-contact-btn {
    width: 100%;
    border-color: #246bfe;
    background: #246bfe;
    color: #fff;
    font-weight: 600;
}

.chat-list {
    display: grid;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.55);
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    width: min(520px, 100%);
    max-height: 90vh;
    overflow: auto;
    display: grid;
    gap: 14px;
    padding: 24px;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(2, 6, 23, 0.3);
}

.modal h2 {
    margin: 0;
    font-size: 20px;
}

.modal-hint {
    color: #667085;
    font-size: 13px;
    line-height: 1.45;
}

.modal-check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn-secondary {
    border-color: #d8dfeb;
    background: #eef1f7;
    color: #1f2937;
}

.modal-status {
    min-height: 18px;
    margin: 0;
    color: #246bfe;
    font-size: 13px;
}

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

.lookup-row input {
    flex: 1;
}

.lookup-row button {
    white-space: nowrap;
}

.contact-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid #e4e9f2;
    border-radius: 10px;
    background: #fbfcff;
}

.contact-card[hidden] {
    display: none;
}

.contact-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    background: #edf0f5;
    flex: none;
}

.contact-card strong {
    display: block;
}

.contact-card small {
    display: block;
    color: #67748a;
    font-size: 12px;
}

#ncCompose[hidden],
#ncSendBtn[hidden] {
    display: none;
}

#ncCompose {
    display: grid;
    gap: 14px;
}

.chat-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    color: inherit;
    text-decoration: none;
    border-top: 1px solid #eef2f7;
}

.chat-item.active,
.chat-item:hover {
    background: #f0f5ff;
}

.chat-item strong,
.chat-item small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-item small,
time,
.topbar p,
.empty {
    color: #67748a;
    font-size: 13px;
}

.chat-item em {
    align-self: center;
    min-width: 46px;
    border-radius: 999px;
    background: #edf0f5;
    color: #67748a;
    padding: 4px 8px;
    text-align: center;
    font-size: 12px;
    font-style: normal;
}

.chat-item em.on {
    background: #e7f8ee;
    color: #137a3d;
}

.main {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    background: #fff;
    border-bottom: 1px solid #dfe5ef;
}

h1 {
    margin: 0 0 4px;
    font-size: 22px;
}

p {
    margin: 0;
}

.settings-panel {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    padding: 14px 24px;
    background: #fbfcff;
    border-bottom: 1px solid #dfe5ef;
}

label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    color: #48566f;
}

label:has(input[type="checkbox"]) {
    display: flex;
    align-items: center;
    gap: 8px;
}

input[type="checkbox"] {
    width: auto;
}

.wide {
    grid-column: 1 / -1;
}

.settings-hint {
    color: #667085;
    font-size: 12px;
    line-height: 1.45;
}

.sleep-settings {
    display: grid;
    gap: 12px;
    margin: 16px 0;
}

.sleep-settings h2 {
    margin: 0;
    font-size: 18px;
}

.sleep-grid {
    display: grid;
    gap: 8px;
}

.sleep-row {
    display: grid;
    grid-template-columns: 90px 150px 150px;
    gap: 10px;
    align-items: center;
}

.sleep-row input[type="time"] {
    min-width: 110px;
}

.messages {
    flex: none;
    overflow: visible;
    min-height: 0;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    max-width: min(720px, 78%);
    padding: 12px 14px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid #e4e9f2;
}

.message.outgoing {
    align-self: flex-end;
    background: #e9f1ff;
    border-color: #cfe0ff;
}

.message time {
    display: block;
    margin-top: 8px;
}

.ai-meta {
    display: block;
    margin-top: 6px;
    color: #246bfe;
    font-size: 12px;
}

.composer,
.settings-page,
.empty-state {
    padding: 20px 24px;
    background: #fff;
    border-top: 1px solid #dfe5ef;
}

.composer div {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

#replyGuidance {
    margin-bottom: 10px;
    background: #fbfcff;
}

.settings-page {
    max-width: 900px;
    align-self: start;
    margin: 32px;
    border: 1px solid #dfe5ef;
    border-radius: 8px;
    display: grid;
    gap: 16px;
}

.prompt-manager {
    margin-top: 0;
}

.prompt-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding: 16px 0;
    border-top: 1px solid #e7ecf3;
}

.prompt-form h2 {
    grid-column: 1 / -1;
    margin: 0;
    font-size: 18px;
}

.prompt-form button {
    justify-self: start;
}

.empty-state {
    align-self: center;
    justify-self: center;
    border: 1px solid #dfe5ef;
    border-radius: 8px;
}

#status {
    margin-top: 10px;
    color: #67748a;
}

@media (max-width: 860px) {
    body {
        grid-template-columns: 1fr;
    }

    .sidebar {
        min-height: auto;
        max-height: 45vh;
        height: auto;
    }

    .main {
        height: auto;
        min-height: 55vh;
        overflow: visible;
    }

    .settings-panel {
        grid-template-columns: 1fr;
    }
}

.auth-body {
    display: grid;
    grid-template-columns: 1fr;
    place-items: center;
    background: #f5f7fb;
}

.auth-card {
    width: min(420px, calc(100vw - 32px));
    background: #fff;
    border: 1px solid #dfe5ef;
    border-radius: 8px;
    padding: 24px;
}

.auth-card form {
    display: grid;
    gap: 14px;
}

.auth-error {
    margin: 0 0 14px;
    color: #b42318;
}

.hp {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* --- Защита от развода на деньги --- */
.risk-badge { color: #b91c1c; font-weight: 600; }
.risk-panel {
    margin: 12px 0; padding: 12px 14px; border: 1px solid #fca5a5;
    background: #fef2f2; border-radius: 8px; color: #7f1d1d;
}
.risk-panel-neutral {
    border-color: #d0d5dd;
    background: #f8fafc;
    color: #344054;
}
.risk-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.risk-head strong { font-size: 15px; }
.risk-paused {
    background: #b91c1c; color: #fff; padding: 2px 8px; border-radius: 999px;
    font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
}
.risk-muted {
    background: #e0e7ff; color: #3730a3; padding: 2px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 600;
}
.risk-head button {
    margin-left: auto; background: #b91c1c; color: #fff; border: 0;
    padding: 6px 12px; border-radius: 6px; cursor: pointer;
}
.risk-flags { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.risk-flag {
    background: #fee2e2; border: 1px solid #fecaca; color: #991b1b;
    padding: 2px 8px; border-radius: 999px; font-size: 12px;
}
.risk-signals { margin: 10px 0 0; padding-left: 18px; font-size: 13px; }
.risk-signals li { margin: 2px 0; }
.risk-signals small { color: #9ca3af; }
.risk-hint { margin: 8px 0 0; font-size: 12px; color: #9ca3af; }

/* --- AI-оценка риска --- */
.risk-action {
    background: #f59e0b; color: #1f2937; padding: 2px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 600;
}
.risk-reason { margin: 8px 0 0; font-size: 13px; color: #7f1d1d; }
.risk-trend { margin-top: 10px; display: flex; align-items: center; gap: 6px; font-size: 12px; color: #9ca3af; flex-wrap: wrap; }
.risk-dot {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 22px; height: 22px; border-radius: 6px; font-weight: 600; color: #fff;
}
.risk-dot-lo { background: #16a34a; }
.risk-dot-mid { background: #f59e0b; color: #1f2937; }
.risk-dot-hi { background: #b91c1c; }
