:root {
    --bg-main: #0e1621;
    --bg-sidebar: #17212b;
    --bg-panel: #182533;
    --bg-hover: #22303d;
    --bg-active: #2b5278;
    --out-msg: #2b5278;
    --in-msg: #182533;
    --text: #e8f1f8;
    --muted: #8fa7bd;
    --line: rgba(255, 255, 255, 0.08);
    --accent: #5ca7ff;
    --green: #40d57d;
    --danger: #ff6f7d;
}

* { box-sizing: border-box; }

html, body {
    width: 100%;
    height: 100%;
}

body {
    margin: 0;
    font-family: "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
    color: var(--text);
    background: var(--bg-main);
}

/* ---------- Shared ---------- */
.btn {
    border: 0;
    border-radius: 12px;
    padding: 10px 14px;
    font-weight: 600;
    cursor: pointer;
}

.btn:disabled {
    opacity: .65;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #0a1622;
}

.ghost {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text);
    border-radius: 10px;
    padding: 8px 12px;
    cursor: pointer;
}

.error-box,
.ok-box {
    border-radius: 12px;
    padding: 10px 12px;
    margin: 10px 0;
    font-size: 14px;
}

.error-box {
    border: 1px solid rgba(255, 111, 125, 0.45);
    background: rgba(255, 111, 125, 0.14);
}

.ok-box {
    border: 1px solid rgba(64, 213, 125, 0.45);
    background: rgba(64, 213, 125, 0.14);
}

.link {
    color: #8bc5ff;
    text-decoration: none;
}

.link:hover {
    text-decoration: underline;
}

/* ---------- Auth ---------- */
.auth-page {
    background:
        radial-gradient(600px 360px at 15% 10%, rgba(92, 167, 255, .18), transparent 70%),
        radial-gradient(500px 320px at 85% 90%, rgba(64, 213, 125, .12), transparent 70%),
        var(--bg-main);
}

.auth-center {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-shell.auth-single {
    width: 100%;
    max-width: 520px;
    padding: 18px;
}

.auth-card {
    background: var(--bg-sidebar);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 22px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, .25);
}

.auth-card h1 {
    margin: 0 0 8px;
    font-size: 28px;
}

.auth-logo {
    font-weight: 800;
    letter-spacing: .14em;
    margin-bottom: 10px;
}

.auth-logo-small {
    font-size: 20px;
}

.auth-hint {
    margin: 0 0 16px;
    color: var(--muted);
    font-size: 14px;
}

.field {
    margin-bottom: 12px;
}

.field label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.field input,
.field select,
.tg-form-card input,
.tg-form-card select,
.tg-search,
.tg-create-card input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #1f2c39;
    color: var(--text);
    padding: 10px 12px;
}

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

.auth-main-btn {
    width: 100%;
    margin-top: 4px;
}

.auth-foot {
    margin-top: 14px;
    display: flex;
}

.auth-foot-center {
    justify-content: center;
}

/* ---------- Telegram-like App ---------- */
.app-page {
    background: var(--bg-main);
}

.tg-app {
    height: 100vh;
    display: grid;
    grid-template-columns: 330px 1fr 320px;
}

.tg-sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.tg-sidebar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px;
    border-bottom: 1px solid var(--line);
}

.tg-brand {
    font-size: 18px;
    font-weight: 700;
}

.tg-brand-sub {
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
}

.tg-search-wrap {
    padding: 10px 12px;
}

.tg-search {
    background: #22303d;
}

.tg-chat-list {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 4px;
}

.tg-chat-item {
    width: 100%;
    border: 0;
    background: transparent;
    color: var(--text);
    text-align: left;
    border-radius: 12px;
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.tg-chat-item:hover {
    background: var(--bg-hover);
}

.tg-chat-item.active {
    background: var(--bg-active);
}

.tg-chat-avatar,
.tg-peer-avatar,
.tg-profile-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #58a6ff, #3b82f6);
    flex-shrink: 0;
}

.tg-chat-body {
    min-width: 0;
}

.tg-chat-title {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tg-chat-last {
    margin-top: 2px;
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tg-quick-create {
    padding: 10px;
    border-top: 1px solid var(--line);
}

.tg-create-card {
    background: #1f2c39;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px;
}

.tg-create-card label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 8px;
}

.tg-search-results {
    margin-top: 8px;
    display: grid;
    gap: 6px;
}

.tg-user-result {
    border: 1px solid var(--line);
    background: #22303d;
    color: var(--text);
    border-radius: 10px;
    padding: 8px 10px;
    cursor: pointer;
    text-align: left;
}

.tg-user-result:hover {
    background: #2a3b4b;
}

.tg-main {
    background: #0f1a24;
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-width: 0;
    min-height: 0;
}

.tg-chat-header {
    border-bottom: 1px solid var(--line);
    background: #17212b;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
}

.tg-peer-meta {
    min-width: 0;
}

.tg-peer-name {
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tg-peer-sub {
    margin-top: 2px;
    font-size: 12px;
    color: var(--muted);
}

.tg-messages {
    overflow: auto;
    padding: 14px;
    background:
        radial-gradient(550px 280px at 20% 0%, rgba(58, 109, 165, .22), transparent 65%),
        radial-gradient(500px 300px at 80% 100%, rgba(31, 58, 85, .18), transparent 65%),
        #0f1a24;
}

.tg-msg-row {
    display: flex;
    margin-bottom: 8px;
}

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

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

.tg-msg-bubble {
    max-width: min(72%, 620px);
    border-radius: 14px;
    padding: 8px 10px 6px;
    border: 1px solid var(--line);
}

.tg-msg-row.in .tg-msg-bubble {
    background: var(--in-msg);
}

.tg-msg-row.out .tg-msg-bubble {
    background: var(--out-msg);
}

.tg-msg-text {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.35;
}

.tg-msg-meta {
    margin-top: 4px;
    font-size: 11px;
    color: var(--muted);
    text-align: right;
}

.tg-composer-wrap {
    border-top: 1px solid var(--line);
    background: #17212b;
    padding: 10px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.tg-attach-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--line);
    display: grid;
    place-items: center;
    cursor: pointer;
    background: #22303d;
    color: #fff;
    font-size: 26px;
    line-height: 1;
}

.tg-composer-form {
    flex: 1;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.tg-composer-form textarea {
    flex: 1;
    max-height: 140px;
    min-height: 42px;
    resize: none;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: #22303d;
    color: var(--text);
    padding: 10px 14px;
    font-family: inherit;
    font-size: 14px;
}

.tg-send-btn {
    height: 42px;
    border-radius: 22px;
    padding: 0 16px;
}

.tg-profile {
    background: var(--bg-sidebar);
    border-left: 1px solid var(--line);
    padding: 14px;
    overflow: auto;
}

.tg-side-title {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    margin-bottom: 10px;
}

.tg-profile-card {
    background: #1f2c39;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px;
}

.tg-profile-avatar {
    width: 74px;
    height: 74px;
    margin: 0 auto;
}

.tg-profile-name {
    margin-top: 10px;
    text-align: center;
    font-size: 18px;
    font-weight: 700;
}

.tg-profile-status {
    margin-top: 4px;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
}

.tg-form-card {
    margin-top: 14px;
    display: grid;
    gap: 8px;
}

.tg-form-card label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
}

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
    .tg-app {
        grid-template-columns: 300px 1fr;
    }

    .tg-profile {
        display: none;
    }
}

@media (max-width: 820px) {
    .tg-app {
        grid-template-columns: 1fr;
        grid-template-rows: 44vh 56vh;
    }

    .tg-sidebar {
        display: flex;
        min-height: 0;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .tg-msg-bubble {
        max-width: 88%;
    }

    .auth-shell.auth-single {
        padding: 12px;
    }

    .auth-card {
        padding: 16px;
        border-radius: 14px;
    }
}
