/* Комната Алексея — тёплая палитра */
:root {
    --bg-warm:        #f5efe6;
    --bg-paper:       #fdf9f1;
    --bg-card:        #ffffff;
    --border-soft:    #e6dfd2;
    --text-strong:    #3e3a36;
    --text:           #52524d;
    --text-muted:     #8a8a82;
    --accent:         #5b8a72;
    --accent-dark:    #3d5644;
    --accent-soft:    #c5d6c8;
    --warm-light:     #fff3d6;
    --error:          #c25a4a;
    --shadow-soft:    0 4px 16px rgba(60, 50, 30, 0.06);
    --shadow-card:    0 8px 32px rgba(60, 50, 30, 0.08);
    --radius:         14px;
    --radius-lg:      18px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    font-family: 'Inter', -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-warm);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
body {
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); }

.muted { color: var(--text-muted); font-size: 14px; }
.error { color: var(--error); }

/* ─── home / login ─── */

.page-home, .page-login {
    background:
        radial-gradient(ellipse at top, var(--warm-light) 0%, transparent 70%),
        var(--bg-warm);
}

.home-wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 80px 32px 32px;
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 64px;
    align-items: center;
}
.home-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 56px 48px;
    box-shadow: var(--shadow-card);
    text-align: center;
}
.home-card.narrow { max-width: 460px; margin: 0 auto; }

.home-card h1 {
    margin: 24px 0 12px;
    font-size: 32px;
    color: var(--text-strong);
    font-weight: 700;
    letter-spacing: -0.02em;
}
.home-card .lead {
    font-size: 17px;
    color: var(--text);
    margin: 0 auto 28px;
    max-width: 380px;
}

.alexey-portrait {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    overflow: hidden;
    margin: 0 auto;
    box-shadow: 0 6px 24px rgba(60, 50, 30, 0.12), inset 0 0 0 4px rgba(255,255,255,0.6);
}
.alexey-portrait.small { width: 72px; height: 72px; }
.alexey-portrait svg { width: 100%; height: 100%; display: block; }

.home-meta {
    display: grid;
    gap: 8px;
    margin: 24px 0 28px;
    text-align: left;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
}
.home-meta > div {
    color: var(--text);
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.home-meta .dot {
    width: 8px; height: 8px;
    background: var(--accent);
    border-radius: 50%;
    flex-shrink: 0;
}

.btn {
    display: inline-block;
    padding: 14px 28px;
    border-radius: 10px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    font-size: 15px;
    font-family: inherit;
    transition: all 0.15s;
}
.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-soft { background: var(--accent-soft); color: var(--accent-dark); }
.btn-soft:hover { background: #b3c8b8; color: var(--accent-dark); }
.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-soft);
}
.btn-ghost:hover { background: var(--bg-paper); color: var(--text); }
.btn-sm { padding: 8px 18px; font-size: 13px; }

.footnote {
    margin-top: 28px;
    color: var(--text-muted);
    font-size: 13px;
}

.home-aside {
    padding: 24px;
}
.signature {
    font-family: 'Caveat', cursive;
    font-size: 26px;
    line-height: 1.4;
    color: var(--accent-dark);
    padding: 24px;
    border-left: 3px solid var(--accent);
}
.signature span {
    display: block;
    margin-top: 12px;
    font-size: 22px;
    color: var(--text-muted);
}

.login-form {
    display: grid;
    gap: 12px;
    margin: 12px auto 0;
    max-width: 320px;
}
.login-form input {
    padding: 14px 16px;
    border-radius: 10px;
    border: 1px solid var(--border-soft);
    background: var(--bg-paper);
    font-size: 15px;
    font-family: inherit;
    color: var(--text-strong);
}
.login-form input:focus {
    outline: 2px solid var(--accent-soft);
    border-color: var(--accent);
}

/* ─── chat ─── */

.page-chat, .page-admin {
    background: var(--bg-warm);
    height: 100vh;
    overflow: hidden;
}

.chat-shell {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: 100vh;
}

.sidebar {
    background: var(--bg-paper);
    border-right: 1px solid var(--border-soft);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
}

.me {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
}
.me-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
}
.me-email { font-size: 13px; color: var(--text-strong); font-weight: 500; word-break: break-all; }
.me-role  { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.new-chat { text-align: center; }

.chat-list {
    flex: 1;
    overflow-y: auto;
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.chat-list-item {
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text);
}
.chat-list-item.active,
.chat-list-item:hover {
    background: var(--bg-card);
    color: var(--text-strong);
}
.chat-list-title {
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-list-date { font-size: 11px; color: var(--text-muted); }

.sidebar-bottom {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 12px;
    border-top: 1px solid var(--border-soft);
}
.sidebar-bottom .btn { padding: 8px 14px; font-size: 13px; }

/* main */

.chat-main {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-card);
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-soft);
    background: var(--bg-paper);
}
.chat-header > * {
    /* центрируем header content в той же колонке */
}
.chat-header-inner {
    display: flex;
    align-items: center;
    gap: 16px;
    max-width: 760px;
    width: 100%;
    margin: 0 auto;
}
.alexey-mini {
    width: 44px; height: 44px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}
.alexey-mini svg { width: 100%; height: 100%; }
.chat-title { font-weight: 600; color: var(--text-strong); font-size: 15px; }
.chat-sub { font-size: 13px; color: var(--text-muted); }

.chat-feed {
    flex: 1;
    overflow-y: auto;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;     /* центральная колонка */
}

.msg {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 760px;        /* центральная колонка как у Claude */
}
.msg-user { flex-direction: row-reverse; }
.msg-user .msg-bubble { max-width: 80%; }
.msg-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}
.msg-avatar svg { width: 100%; height: 100%; }
.msg-bubble {
    background: var(--bg-paper);
    padding: 14px 18px;
    border-radius: 16px;
    color: var(--text);
}
.msg-user .msg-bubble {
    background: var(--accent);
    color: #fff;
    border-top-right-radius: 4px;
}
.msg-assistant .msg-bubble { border-top-left-radius: 4px; }
.msg-content {
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.55;
}
.msg-media { margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.media-link {
    display: inline-block;
    padding: 6px 12px;
    background: var(--bg-card);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text);
}

.save-block {
    margin-top: 16px;
    padding: 16px;
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px dashed var(--accent);
}
.save-head {
    font-size: 13px;
    color: var(--accent-dark);
    margin-bottom: 8px;
    font-weight: 500;
}
.save-head code {
    background: var(--accent-soft);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
}
.save-block pre {
    background: var(--bg-paper);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 13px;
    color: var(--text-strong);
    margin: 8px 0 12px;
    white-space: pre-wrap;
    font-family: 'SFMono-Regular', Menlo, Consolas, monospace;
}
.save-block.saved { opacity: 0.6; }
.save-block .save-confirm.saved-state { background: var(--text-muted); cursor: default; }

.tool-use-block {
    margin-top: 14px;
    padding: 14px 16px;
    background: #fff7e6;
    border-radius: 12px;
    border: 1px solid #f5c98a;
    color: #6b4a1a;
}
.tool-use-head {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
}
.tool-use-row {
    font-size: 13px;
    margin: 4px 0;
    line-height: 1.4;
}
.tool-use-label {
    color: #8a6a30;
    font-weight: 500;
    margin-right: 4px;
}
.tool-use-row code {
    background: rgba(245, 201, 138, 0.4);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12px;
}
.tool-use-hint {
    font-size: 11px;
    color: #a37e3a;
    margin-top: 6px;
    font-style: italic;
}
.tool-use-deal {
    background: #e8f4ea;
    border-color: #82c596;
    color: #2c5d3c;
}
.tool-use-deal .tool-use-label { color: #4a7e5a; }
.tool-use-deal .tool-use-hint { color: #5e8e6a; }
.tool-use-deal .urgent {
    background: #ff6b3d;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    margin-left: 6px;
}

.empty-feed {
    text-align: center;
    padding: 64px 32px;
    color: var(--text-muted);
}
.empty-feed .alexey-portrait { margin: 0 auto 20px; }
.empty-feed p { font-size: 16px; max-width: 460px; margin: 0 auto 24px; color: var(--text); }
.hints {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}
.hint-btn {
    background: var(--bg-paper);
    border: 1px solid var(--border-soft);
    padding: 10px 18px;
    border-radius: 24px;
    color: var(--text);
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    transition: all 0.15s;
}
.hint-btn:hover {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-dark);
}

.empty-state {
    margin: auto;
    text-align: center;
}
.empty-state h2 { color: var(--text-strong); }

.chat-input {
    border-top: 1px solid var(--border-soft);
    padding: 16px;
    background: var(--bg-paper);
    width: 100%;
    box-sizing: border-box;
}
.composer {
    max-width: 760px;
    margin: 0 auto;
    width: 100%;
}
.attachments {
    display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px;
}
.attachment-chip {
    background: var(--bg-card);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 13px;
    display: flex;
    gap: 6px;
    align-items: center;
    border: 1px solid var(--border-soft);
}
.attachment-chip .x {
    cursor: pointer;
    color: var(--text-muted);
    font-weight: 700;
    margin-left: 4px;
}

/* Единый rounded box ввода — как у Claude/ChatGPT */
.composer-box {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: 24px;
    padding: 6px 6px 6px 8px;
    transition: all 0.15s;
    box-shadow: 0 2px 12px rgba(60, 50, 30, 0.04);
}
.composer-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 2px 16px rgba(91, 138, 114, 0.18);
}

.composer-box textarea {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 6px;
    font-family: inherit;
    font-size: 15px;
    color: var(--text-strong);
    resize: none;
    min-height: 24px;
    max-height: 200px;
    line-height: 1.5;
    outline: none;
}
.composer-box textarea::placeholder { color: var(--text-muted); }

.composer-icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}
.composer-icon-btn:hover {
    background: var(--bg-paper);
    color: var(--text-strong);
}
.composer-icon-btn svg { width: 18px; height: 18px; }
.composer-icon-btn input { display: none; }

.composer-icon-btn.mic-btn.recording {
    background: var(--error);
    color: #fff;
    animation: mic-pulse 1.4s infinite;
}
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(194, 90, 74, 0.6); }
    50%      { box-shadow: 0 0 0 8px rgba(194, 90, 74, 0); }
}
.composer-icon-btn.mic-btn.unsupported { display: none; }

.composer-send-btn {
    background: var(--accent);
    border: none;
    color: #fff;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}
.composer-send-btn:hover { background: var(--accent-dark); }
.composer-send-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.5;
}
.composer-send-btn svg { width: 18px; height: 18px; }

.composer-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 8px;
}

/* admin */

.admin-main { padding: 32px 40px; overflow-y: auto; background: var(--bg-card); }
.admin-main h1 { color: var(--text-strong); margin: 0 0 8px; }
.admin-main h2 { color: var(--text-strong); margin: 32px 0 12px; font-size: 18px; }

.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin: 24px 0;
}
.kpi {
    background: var(--bg-paper);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
}
.kpi-num { font-size: 24px; font-weight: 700; color: var(--accent-dark); }
.kpi-lbl { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

table.data {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-paper);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 24px;
}
table.data th, table.data td {
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-soft);
}
table.data th {
    background: var(--bg-warm);
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
table.data td { font-size: 14px; color: var(--text); }
table.data tr:last-child td { border-bottom: none; }

table.data .num { text-align: right; font-family: 'SFMono-Regular', Menlo, Consolas, monospace; }
table.data .nowrap { white-space: nowrap; }
table.data .small { font-size: 11px; }
table.data .muted { color: var(--text-muted); }

/* Conversations table */
.convs-table .preview-cell {
    max-width: 360px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    color: var(--text-muted);
}
.convs-table .dir { font-weight: 600; margin-right: 4px; }
.convs-table .dir-in { color: #6a8aa0; }
.convs-table .dir-out { color: #5b8a72; }

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.badge-active { background: #e6f0ff; color: #2563a8; }
.badge-warn { background: #fbeee0; color: #a86530; }
.badge-ok { background: #e8f4ea; color: #2c5d3c; }
.badge-error { background: #fae0e0; color: #a83030; }

/* Conversation view */
.conv-header { padding-bottom: 16px; border-bottom: 1px solid var(--border-soft); margin-bottom: 16px; }
.conv-header h1 { margin: 0 0 6px; }
.conv-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }
.conv-meta code { background: var(--bg-paper); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
.conv-summary {
    background: #fff7e6;
    border-left: 3px solid #f5c98a;
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 20px;
}
.summary-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: #8a6a30; margin-bottom: 4px; }
.conv-thread { display: flex; flex-direction: column; gap: 12px; }
.conv-msg { padding: 10px 14px; border-radius: 8px; max-width: 720px; }
.conv-msg-in { background: var(--bg-paper); border: 1px solid var(--border-soft); align-self: flex-start; }
.conv-msg-out { background: #e8f0ea; border: 1px solid #b9d2c1; align-self: flex-end; }
.conv-msg-system { background: #fff7e6; border: 1px dashed #d9c89a; align-self: center; font-style: italic; }
.conv-msg .msg-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.conv-msg .msg-body { font-size: 14px; color: var(--text); white-space: pre-wrap; word-wrap: break-word; }
.btn.btn-sm { padding: 4px 12px; font-size: 12px; }

/* tool-call карточки в timeline */
.conv-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.conv-tool {
    align-self: center;
    max-width: 720px;
    width: 100%;
    padding: 10px 14px;
    border-radius: 8px;
    background: #fff8e0;
    border: 1px solid #e8d29a;
    font-family: 'Inter', system-ui, sans-serif;
}
.conv-tool-handoff_to_human { background: #f5ecff; border-color: #d2c0e8; }
.conv-tool-create_deal_and_handoff { background: #e8f4ea; border-color: #b9d2c1; }
.tool-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; flex-wrap: wrap; gap: 8px; }
.tool-name { font-weight: 600; font-size: 13px; color: var(--text-strong); }
.tool-meta { font-size: 11px; color: var(--text-muted); }
.tool-error { color: #a83030; font-weight: 600; }
.tool-section { margin-top: 4px; }
.tool-section > summary {
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    user-select: none;
    list-style: revert;
}
.tool-section[open] > summary { margin-bottom: 4px; }
.tool-section pre {
    background: rgba(0,0,0,0.04);
    padding: 8px 10px;
    border-radius: 4px;
    font-size: 12px;
    line-height: 1.4;
    overflow-x: auto;
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.tool-pending { font-size: 12px; color: var(--text-muted); font-style: italic; margin-top: 4px; }

/* responsive */

@media (max-width: 800px) {
    .home-wrap { grid-template-columns: 1fr; padding: 32px 16px; }
    .home-card { padding: 40px 24px; }
    .chat-shell { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .chat-feed { padding: 16px; }
    .chat-header { padding: 12px 16px; }
}
