:root {
    --brand: #2d5a27;
    --brand-dark: #1e4d1a;
    --line: #e5e7eb;
    --bg: #f7f8f7;
    --bubble-other: #f2f3f5;
    --bubble-own: #e6f4e3;
}
html, body { height: 100%; }
body {
    background: var(--bg);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

/* ---------- top bar: одна строка ---------- */
.topbar {
    flex: 0 0 auto;
    background: #fff;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 5px 16px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
}
.topbar-brand {
    color: var(--brand);
    text-decoration: none;
    font-weight: 700;
    font-size: 1rem;
    white-space: nowrap;
    justify-self: start;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar-brand:hover { color: var(--brand-dark); }
.topbar-title {
    margin: 0;
    font-size: clamp(.7rem, 1.5vw, 1rem);
    font-weight: 600;
    color: #111;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    justify-self: center;
    max-width: 100%;
}
.userbox {
    justify-self: end;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.1;
    min-width: 0;
}
.userbox .user-name {
    font-size: .84rem;
    font-weight: 600;
    color: #111;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.menu-btn {
    border: 0;
    background: none;
    color: #6b7280;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0 6px;
    cursor: pointer;
    border-radius: 6px;
}
.menu-btn:hover { background: #f3f4f6; color: var(--brand-dark); }
.menu-btn::after { display: none; }
@media (max-width: 560px) {
    .brand-text { display: none; }
    .userbox .user-name { max-width: 100px; }
}

.app-main {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
}
.flash-wrap { max-width: 1080px; margin: 10px auto 0; padding: 0 16px; width: 100%; }
.flash-wrap .alert { margin-bottom: 8px; }

/* ---------- обычные страницы ---------- */
.page-wrap { max-width: 1000px; width: 100%; margin: 0 auto; padding: 16px; }

/* ---------- чат ---------- */
.chat-mode { background: #fff; }
.chat-mode .app-main { max-width: 920px; margin: 0 auto; width: 100%; border-left: 1px solid var(--line); border-right: 1px solid var(--line); background: #fff; }
.chat-wrap { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.chat-head { padding: 5px 16px; border-bottom: 1px solid var(--line); background: #fff; }
.chat-sub { font-size: .78rem; color: #6b7280; }
.chat-footer { flex: 0 0 auto; border-top: 1px solid var(--line); padding: 8px 16px; font-size: .8rem; color: #6b7280; background: #fafbfa; }
.chat-footer a { color: var(--brand); font-weight: 600; text-decoration: none; }
.chat-footer a:hover { text-decoration: underline; }
.chat-sub a { color: var(--brand); text-decoration: none; }
.chat-sub a:hover { text-decoration: underline; }

.chat-scroll { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; }
.chat-list { padding: 12px 12px 16px; display: flex; flex-direction: column; gap: 6px; }
.chat-empty { text-align: center; color: #9aa1a9; padding: 40px 0; font-size: .92rem; }

.msg { display: flex; gap: 9px; padding: 3px 4px; }
.msg .ava {
    width: 32px; height: 32px; flex: 0 0 32px;
    border-radius: 50%;
    background: #d9e7d5; color: var(--brand-dark);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .85rem;
    margin-top: 18px;
}
.msg .content { max-width: min(680px, 82%); }
.msg .meta { font-size: .74rem; color: #8b929a; margin: 0 0 3px 4px; }
.msg .meta .who { color: var(--brand-dark); font-weight: 600; }
.msg .pin-flag { color: #b25e00; font-weight: 600; }
.bubble {
    background: var(--bubble-other);
    border-radius: 14px;
    border-top-left-radius: 4px;
    padding: 9px 13px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: .95rem;
    color: #1a1a1a;
}
.msg.own { flex-direction: row-reverse; }
.msg.own .content { display: flex; flex-direction: column; align-items: flex-end; }
.msg.own .meta { margin: 0 4px 3px 0; }
.msg.own .bubble { background: var(--bubble-own); border-top-left-radius: 14px; border-top-right-radius: 4px; }
.msg.pinned .bubble { box-shadow: inset 3px 0 0 #d99a2b; }

.att-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.att-grid a { display: block; line-height: 0; }
.att-grid img { height: 68px; width: auto; max-width: 220px; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); background: #fff; display: block; }
.att-grid-lg img { height: 130px; }
.att-file {
    display: inline-flex; align-items: center; gap: 6px;
    margin-top: 6px; padding: 6px 10px;
    background: #fff; border: 1px solid var(--line); border-radius: 10px;
    text-decoration: none; color: #1a1a1a; font-size: .88rem;
}
.att-file:hover { background: #fafafa; }
.att-file small { color: #8b929a; }

.pin-btn {
    margin-top: 5px;
    background: transparent;
    border: 1px solid var(--line);
    color: #6b7280;
    border-radius: 8px;
    font-size: .74rem;
    padding: 2px 8px;
    cursor: pointer;
}
.pin-btn:hover { border-color: #d99a2b; color: #b25e00; }

/* composer */
.composer { flex: 0 0 auto; border-top: 1px solid var(--line); background: #fff; padding: 8px 12px 12px; }
.composer-inner {
    display: flex; align-items: flex-end; gap: 6px;
    border: 1px solid #d5d9de; border-radius: 16px;
    padding: 5px 6px 5px 8px; background: #fff;
    transition: border-color .15s;
}
.composer-inner:focus-within { border-color: var(--brand); }
#chatInput {
    flex: 1 1 auto; border: 0; outline: none; resize: none;
    font-size: .95rem; line-height: 1.35; max-height: 180px;
    padding: 6px 2px; background: transparent;
}
.icon-btn, .send-btn {
    border: 0; background: transparent; border-radius: 10px;
    width: 34px; height: 34px; flex: 0 0 34px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 1rem;
}
.icon-btn:hover { background: #f3f4f6; }
.send-btn { background: var(--brand); color: #fff; }
.send-btn:hover { background: var(--brand-dark); }
.send-btn:disabled { opacity: .5; cursor: default; }

.att-previews { display: flex; flex-wrap: wrap; gap: 6px; }
.att-previews:not(:empty) { padding-bottom: 8px; }
.att-preview {
    position: relative; width: 64px; height: 64px;
    border-radius: 8px; overflow: hidden; border: 1px solid var(--line); background: #fafafa;
}
.att-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att-preview-doc { display: flex; align-items: center; justify-content: center; font-size: 1.6rem; }
.att-preview-x {
    position: absolute; top: 1px; right: 1px;
    width: 18px; height: 18px; line-height: 16px;
    border: 0; border-radius: 50%;
    background: rgba(0,0,0,.6); color: #fff; font-size: 13px;
    cursor: pointer; padding: 0;
}

/* drop zone (личные) */
.drop-zone { border: 2px dashed var(--brand); background: #fff; cursor: pointer; }
.drop-zone-active { background: #e8f5e0; }

/* общие */
.message-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.btn-success { background: var(--brand); border-color: var(--brand-dark); }
.btn-success:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-outline-success { color: var(--brand); border-color: var(--brand); }
.btn-outline-success:hover { background: var(--brand); color: #fff; }
.card-header { background: #fff; }
.text-muted { color: #6b7280 !important; }
