:root {
    --bg: #0d1016;
    --bg-soft: #11151d;
    --surface: #151a23;
    --surface-2: #1a202b;
    --surface-3: #202838;
    --line: #2a3342;
    --line-strong: #3a4659;
    --text: #eef2f8;
    --muted: #9aa6b7;
    --muted-2: #748195;
    --accent: #6ea8fe;
    --accent-soft: rgba(110, 168, 254, .14);
    --green: #4fc18b;
    --green-soft: rgba(79, 193, 139, .13);
    --danger: #ef7182;
    --danger-soft: rgba(239, 113, 130, .14);
    --warn: #d7a84b;
    --warn-soft: rgba(215, 168, 75, .14);
    --shadow: 0 14px 36px rgba(0, 0, 0, .24);
    --radius: 12px;
    --radius-lg: 16px;
    --sidebar: 218px;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-width: 0;
    min-height: 100%;
    margin: 0;
}

body {
    overflow-x: hidden;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea,
select {
    font: inherit;
}

button,
a,
input,
textarea,
select {
    -webkit-tap-highlight-color: transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    border: 2px solid transparent;
    border-radius: 999px;
    background: rgba(154, 166, 183, .38);
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(154, 166, 183, .56);
    background-clip: content-box;
}

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar) minmax(0, 1fr);
    width: 100%;
    min-width: 0;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 100vh;
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px;
    border-right: 1px solid var(--line);
    background: #0b0e13;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding: 10px 10px 12px;
}

.brand__dot {
    width: 10px;
    height: 10px;
    flex: 0 0 auto;
    border-radius: 999px;
    background: var(--green);
    box-shadow: 0 0 0 4px var(--green-soft);
}

.brand__text {
    min-width: 0;
}

.brand__title {
    min-width: 0;
    overflow: hidden;
    color: #f7f9fc;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .08em;
    line-height: 1.2;
    text-overflow: ellipsis;
    text-transform: uppercase;
    white-space: nowrap;
}

.nav {
    display: grid;
    gap: 6px;
}

.nav a,
.nav-logout button {
    display: flex;
    align-items: center;
    min-height: 38px;
    width: 100%;
    padding: 9px 10px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: transparent;
    box-shadow: none;
    color: var(--muted);
    cursor: pointer;
    font-weight: 650;
    line-height: 1.2;
    text-align: left;
}

.nav a:hover,
.nav a.active,
.nav-logout button:hover {
    border-color: var(--line);
    background: var(--surface);
    color: var(--text);
    filter: none;
}

.nav-logout {
    margin: auto 0 0;
}

.content {
    width: 100%;
    min-width: 0;
    min-height: 100vh;
    overflow-x: hidden;
    padding: 16px;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
    margin: 0 0 12px;
}

.page-head h1 {
    margin: 0;
    font-size: clamp(22px, 3vw, 30px);
    font-weight: 800;
    letter-spacing: 0;
    line-height: 1.1;
}

.page-head__actions {
    width: min(100%, 340px);
    min-width: 220px;
}

.muted {
    color: var(--muted);
}

.section-title {
    font-weight: 750;
}

input[type="text"],
input[type="password"],
input[type="number"],
textarea,
select,
.search-input {
    width: 100%;
    min-width: 0;
    min-height: 38px;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 10px;
    outline: none;
    background: #0f131a;
    color: var(--text);
}

textarea {
    min-height: 86px;
    resize: vertical;
}

select {
    color-scheme: dark;
}

input:focus,
textarea:focus,
select:focus {
    border-color: rgba(110, 168, 254, .72);
    box-shadow: 0 0 0 3px rgba(110, 168, 254, .14);
}

button,
.btn,
.pager__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 9px 13px;
    border: 1px solid transparent;
    border-radius: 10px;
    background: var(--accent);
    box-shadow: none;
    color: #08111f;
    cursor: pointer;
    font-weight: 750;
    line-height: 1.15;
    white-space: nowrap;
}

button:hover,
.btn:hover,
.pager__btn:hover {
    filter: brightness(1.04);
}

.btn-secondary,
button.btn-secondary,
.ghost-btn {
    border-color: var(--line);
    background: var(--surface-2);
    color: var(--text);
}

.btn-secondary:hover,
button.btn-secondary:hover,
.ghost-btn:hover {
    background: var(--surface-3);
    filter: none;
}

.btn-danger,
button.btn-danger {
    background: var(--danger);
    color: #fff;
}

.form-grid {
    display: grid;
    gap: 10px;
}

.form-grid--compact {
    gap: 9px;
}

.form-grid label span {
    display: block;
    margin: 0 0 5px;
    color: var(--muted);
    font-size: 12px;
}

.form-grid__full {
    grid-column: 1 / -1;
}

.form-error,
.page-alert {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
}

.form-error,
.page-alert--danger {
    border-color: rgba(239, 113, 130, .42);
    background: var(--danger-soft);
}

.page-alert--ok {
    border-color: rgba(79, 193, 139, .42);
    background: var(--green-soft);
}

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

.check input {
    width: 16px;
    height: 16px;
}

.check--compact {
    min-height: 38px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    max-width: 100%;
    padding: 3px 8px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}

.badge--accent {
    border-color: rgba(110, 168, 254, .42);
    background: var(--accent-soft);
    color: #cfe1ff;
}

.badge--dim {
    opacity: .72;
}

.empty-card,
.side-card,
.dialog-card {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    color: var(--text);
    box-shadow: none;
}

.empty-card {
    padding: 18px;
    color: var(--muted);
}

.side-card {
    padding: 14px;
}

.side-card h3 {
    margin: 0 0 12px;
    font-size: 16px;
    line-height: 1.2;
}

.dialog-list {
    display: grid;
    gap: 10px;
    min-width: 0;
}

.dialog-card {
    display: block;
    padding: 13px;
}

.dialog-card__top,
.dialog-card__bottom {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
}

.dialog-card__identity,
.dialog-card__main {
    min-width: 0;
}

.dialog-card__name {
    min-width: 0;
    overflow: hidden;
    font-size: 15px;
    font-weight: 780;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dialog-card__meta,
.dialog-card__bottom {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.dialog-card__mid {
    margin: 8px 0;
}

.dialog-card__preview {
    color: #d9e2ef;
    font-size: 13px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.dialog-card__status {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.dialog-card:hover {
    border-color: var(--line-strong);
    background: var(--surface-2);
}

.login-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 18px;
}

.login-wrap {
    width: min(100%, 360px);
}

.login-card {
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.login-card h1 {
    margin: 18px 0 14px;
    font-size: 24px;
    line-height: 1.15;
}

.login-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.dash-page {
    display: grid;
    gap: 14px;
}

.dash-hero,
.dash-panel,
.dash-kpi,
.dash-item,
.dash-empty {
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
}

.dash-hero {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 16px;
}

.dash-hero__title {
    margin: 0;
    font-size: 26px;
    line-height: 1.1;
}

.dash-hero__badges {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.dash-badge,
.dash-state {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 4px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.dash-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
}

.dash-kpi {
    min-height: 86px;
    padding: 13px;
}

.dash-kpi__label {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.35;
}

.dash-kpi__value {
    margin-top: 12px;
    font-size: 30px;
    font-weight: 800;
    line-height: 1;
}

.dash-panels {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    align-items: start;
}

.dash-panel {
    min-width: 0;
    padding: 14px;
}

.dash-panel__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.dash-panel__head h3 {
    margin: 0;
    font-size: 16px;
    line-height: 1.25;
}

.dash-link {
    color: #b8d4ff;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.dash-list {
    display: grid;
    gap: 8px;
}

.dash-item {
    display: block;
    padding: 11px;
}

.dash-item:hover {
    border-color: var(--line-strong);
    background: var(--surface-2);
}

.dash-item__top,
.dash-item__meta {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.dash-item__title {
    min-width: 0;
    font-weight: 750;
    overflow-wrap: anywhere;
}

.dash-inline-muted,
.dash-item__meta {
    color: var(--muted);
    font-size: 12px;
}

.dash-item__text {
    margin-top: 8px;
    color: #d8e0ec;
    font-size: 13px;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.dash-item__text--error {
    color: #ffc6ce;
}

.dash-state--open {
    border-color: rgba(79, 193, 139, .35);
    background: var(--green-soft);
    color: #c7f0dc;
}

.dash-state--accent {
    border-color: rgba(110, 168, 254, .4);
    background: var(--accent-soft);
    color: #cfe1ff;
}

.dash-empty {
    display: grid;
    min-height: 118px;
    place-items: center;
    padding: 18px;
    color: var(--muted);
    text-align: center;
}

.bots-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 32px);
    min-height: 0;
    overflow: hidden;
}

.bots-page__head {
    flex: 0 0 auto;
}

.bots-grid {
    display: grid;
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
    gap: 12px;
    min-height: 0;
    align-items: stretch;
}

.bots-grid--compact {
    flex: 1 1 auto;
}

.side-card--sticky {
    position: sticky;
    top: 0;
    align-self: start;
    max-height: 100%;
    overflow: auto;
}

.bots-scroll,
body.page-bots .dialog-list {
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
    scrollbar-width: thin;
}

.bot-card {
    padding: 12px;
}

.bot-card__summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: 10px 0;
}

.bot-stat {
    min-width: 0;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg-soft);
}

.bot-stat--full {
    grid-column: 1 / -1;
}

.bot-stat__label {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 11px;
}

.bot-stat strong {
    display: block;
    font-size: 12px;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.bot-edit-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 180px;
    gap: 9px;
}

.bot-edit-form__title {
    grid-column: 1;
}

.bot-edit-form__mode {
    grid-column: 2;
}

.bot-edit-form__full {
    grid-column: 1 / -1;
}

.bot-edit-form textarea {
    min-height: 74px;
    max-height: 180px;
}

.bot-card__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.bot-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.bot-actions form {
    margin: 0;
}

.chat-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 12px;
    align-items: start;
}

.chat-main,
.chat-side,
.side-card {
    min-width: 0;
}

.chat-main {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: calc(100vh - 32px);
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
}

.chat-header,
.reply-box {
    padding: 12px;
    border-color: var(--line);
    background: var(--surface-2);
}

.chat-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    border-bottom: 1px solid var(--line);
}

.chat-header__title {
    font-size: 18px;
    font-weight: 800;
}

.chat-header__sub {
    color: var(--muted);
    font-size: 12px;
}

.messages-feed {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px;
}

.message-row {
    display: flex;
    width: 100%;
}

.message-row--in {
    justify-content: flex-start;
}

.message-row--out {
    justify-content: flex-end;
}

.message-bubble {
    max-width: min(76%, 760px);
    padding: 10px 11px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-2);
    overflow-wrap: anywhere;
}

.message-bubble--in {
    background: #17202d;
}

.message-bubble--out {
    background: #1c2a35;
}

.message-bubble__text,
.system-note__body {
    white-space: pre-wrap;
}

.message-bubble__meta {
    margin-top: 6px;
    color: var(--muted);
    font-size: 11px;
    text-align: right;
}

.message-bubble__media img,
.message-bubble__media video {
    display: block;
    max-width: min(360px, 100%);
    max-height: 360px;
    border-radius: 12px;
}

.message-bubble__media audio {
    width: min(360px, 100%);
}

.reply-box {
    border-top: 1px solid var(--line);
}

.reply-box textarea {
    min-height: 64px;
    max-height: 160px;
    resize: none;
    overflow-y: auto;
}

.reply-box__actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 8px;
}

.file-pill,
.media-file {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 34px;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
}

.file-pill input {
    display: none;
}

.file-pill__name {
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.system-note {
    align-self: center;
    width: min(100%, 720px);
    padding: 9px 11px;
    border: 1px dashed var(--line-strong);
    border-radius: 12px;
    background: var(--bg-soft);
}

.system-note summary {
    color: var(--muted);
    cursor: pointer;
    font-weight: 700;
    list-style: none;
}

.system-note summary::-webkit-details-marker {
    display: none;
}

.side-kv {
    display: grid;
    gap: 8px;
}

.side-kv > div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--line);
}

.side-kv span {
    color: var(--muted);
}

.side-kv strong {
    max-width: 60%;
    text-align: right;
    overflow-wrap: anywhere;
}

.side-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

@media (max-width: 1180px) {
    .dash-panels,
    .chat-layout {
        grid-template-columns: 1fr;
    }

    .bots-grid {
        grid-template-columns: 1fr;
    }

    .side-card--sticky {
        position: static;
    }
}

@media (max-width: 820px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        min-height: 0;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .nav-logout {
        margin-top: 4px;
    }

    .content {
        min-height: 0;
        padding: 12px;
    }

    .page-head {
        flex-direction: column;
        align-items: stretch;
    }

    .page-head__actions {
        width: 100%;
        min-width: 0;
    }

    .dash-hero {
        flex-direction: column;
    }

    .dash-hero__badges {
        justify-content: flex-start;
    }

    .bot-card__summary,
    .bot-edit-form {
        grid-template-columns: 1fr;
    }

    .bot-edit-form__title,
    .bot-edit-form__mode,
    .bot-edit-form__full {
        grid-column: 1;
    }

    .bot-card__footer,
    .reply-box__actions {
        align-items: stretch;
        flex-direction: column;
    }

    .message-bubble {
        max-width: 100%;
    }
}
