* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    color: #17212b;
    background: #eef2f6;
    font-family: "Segoe UI", Arial, sans-serif;
}

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

.topbar {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    color: #fff;
    background: #184d47;
}

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

.userbar {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.userbar a {
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, .35);
    border-radius: 6px;
}

.user-photo {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, .65);
}

.user-photo:not(.initials),
.clickable-photo {
    cursor: pointer;
}

.user-photo.initials {
    display: grid;
    place-items: center;
    color: #184d47;
    background: #fff;
    font-weight: 800;
}

.page {
    max-width: 1180px;
    margin: 24px auto;
    padding: 0 16px;
    height: calc(100vh - 112px);
}

.login-body {
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(135deg, #184d47 0%, #2b6e65 45%, #f0b35b 100%);
}

.login-card {
    width: min(440px, 100%);
    display: grid;
    gap: 12px;
    padding: 32px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 24px 60px rgba(11, 31, 45, .22);
}

.login-card h1,
.login-card p {
    margin: 0;
}

.login-card p {
    margin-bottom: 12px;
    color: #657382;
}

.login-step {
    display: grid;
    gap: 12px;
}

.remember-access {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #394b59;
    font-size: 14px;
    cursor: pointer;
}

.admin-layout {
    display: grid;
    gap: 18px;
}

.admin-card {
    padding: 22px;
    background: #fff;
    border: 1px solid #dbe3ea;
    border-radius: 8px;
}

.admin-card h1,
.admin-card h2,
.admin-card p {
    margin: 0;
}

.admin-card h1,
.admin-card h2 {
    margin-bottom: 10px;
}

.admin-card p {
    margin-bottom: 16px;
    color: #657382;
}

.admin-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 220px auto auto auto;
    gap: 10px;
    align-items: center;
}

.users-table {
    display: grid;
    border: 1px solid #e5ebf0;
    border-radius: 8px;
    overflow: hidden;
}

.users-row {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) 140px 90px 120px minmax(260px, auto);
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid #edf1f4;
}

.users-row:last-child {
    border-bottom: 0;
}

.users-head {
    color: #394b59;
    background: #f7f9fb;
    font-weight: 800;
}

.user-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.password-card {
    max-width: 520px;
    margin: 0 auto;
}

.profile-upload {
    min-height: 62px;
    display: grid;
    gap: 8px;
    place-items: center;
    padding: 10px;
    color: #184d47;
    background: #eef7f5;
    border: 1px dashed #9dbcb5;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
}

.profile-upload input {
    width: 100%;
    font-size: 12px;
}

.profile-box {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid #e5ebf0;
    background: #fbfcfd;
}

.profile-preview {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    object-fit: cover;
    background: #184d47;
}

.profile-preview:hover,
.conversation-avatar:hover,
.message-avatar:hover,
.user-photo:not(.initials):hover {
    box-shadow: 0 0 0 3px rgba(240, 179, 91, .45);
}

.profile-controls {
    display: none;
    gap: 8px;
    min-width: 0;
}

.profile-controls.open {
    display: grid;
}

.profile-upload.compact {
    min-height: 48px;
    padding: 8px;
}

.input {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    color: #17212b;
    background: #fff;
    border: 1px solid #cfd8e3;
    border-radius: 6px;
    font: inherit;
}

.input:focus {
    outline: 3px solid rgba(24, 77, 71, .18);
    border-color: #184d47;
}

.button {
    min-height: 40px;
    padding: 9px 14px;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
}

.button.primary {
    color: #fff;
    background: #184d47;
}

.button.ghost {
    color: #184d47;
    background: #dce9e7;
}

.button.danger {
    color: #fff;
    background: #b42318;
}

.compact-button {
    min-height: 38px;
    padding: 7px 12px;
}

.icon-button {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 1px solid #d8e4e1;
    border-radius: 50%;
    color: #184d47;
    background: #eef7f5;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, transform .15s ease, border-color .15s ease;
}

.icon-button:hover {
    color: #fff;
    background: #184d47;
    border-color: #184d47;
    transform: translateY(-1px);
}

.icon-button svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.danger-icon {
    color: #b42318;
    background: #fff0ed;
    border-color: #ffd1ca;
}

.danger-icon:hover {
    color: #fff;
    background: #b42318;
    border-color: #b42318;
}

.visually-hidden-submit {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
    padding: 0;
    margin: -1px;
}

.message {
    display: block;
    min-height: 18px;
    font-size: 13px;
}

.message.error {
    color: #b42318;
}

.message.success {
    color: #087443;
}

.message.warning {
    color: #9a5b00;
}

.code-input {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0;
    text-align: center;
}

.chat-shell {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 18px;
    overflow: hidden;
}

.sidebar,
.conversation {
    min-height: 0;
    height: 100%;
    background: #fff;
    border: 1px solid #dbe3ea;
    border-radius: 8px;
    overflow: hidden;
}

.sidebar {
    display: flex;
    flex-direction: column;
}

[id$="ConversationsUpdatePanel"] {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #8fb7ad transparent;
}

[id$="ConversationsUpdatePanel"]::-webkit-scrollbar {
    width: 10px;
}

[id$="ConversationsUpdatePanel"]::-webkit-scrollbar-track {
    background: transparent;
}

[id$="ConversationsUpdatePanel"]::-webkit-scrollbar-thumb {
    background: #9dbcb5;
    border: 3px solid #fff;
    border-radius: 999px;
}

.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px;
    border-bottom: 1px solid #e5ebf0;
}

.panel-title h2,
.conversation-header h2,
.empty-state h2 {
    margin: 0;
    font-size: 20px;
}

.new-chat {
    display: grid;
    gap: 10px;
    padding: 16px 18px;
    border-bottom: 1px solid #e5ebf0;
}

.conversation-search {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 12px 22px;
    border-bottom: 1px solid #e5ebf0;
    background: #fbfcfd;
}

.conversation-link {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid #edf1f4;
}

.conversation-link:hover,
.conversation-link.active {
    background: #eef7f5;
}

.conversation-link.unread .conversation-list-text strong,
.conversation-link.unread .conversation-list-text span {
    color: #17212b;
    font-weight: 800;
}

.conversation-avatar-wrap {
    position: relative;
    width: 42px;
    height: 42px;
    display: block;
}

.conversation-list-avatar {
    width: 42px !important;
    height: 42px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    background: #184d47;
}

.presence-dot {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 13px;
    height: 13px;
    border: 2px solid #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(23, 33, 43, 0.08);
}

.presence-dot.online {
    background: #19e05a;
}

.presence-dot.offline {
    background: #ff2d2d;
}

.conversation-list-text {
    min-width: 0;
    display: grid;
    gap: 4px;
}

.conversation-link .conversation-list-text span {
    max-width: 100%;
    overflow: hidden;
    color: #657382;
    font-size: 13px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.conversation {
    display: flex;
    flex-direction: column;
}

[id$="MessagesUpdatePanel"] {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.conversation-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.conversation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 22px;
    border-bottom: 1px solid #e5ebf0;
}

.conversation-person {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.conversation-avatar {
    width: 44px !important;
    height: 44px !important;
    flex: 0 0 auto;
    display: block;
    border-radius: 50% !important;
    object-fit: cover !important;
    background: #184d47;
}

.conversation-person h2 {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.conversation-tools {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.messages {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 18px 22px;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: auto;
    background: #f7f9fb;
}

.messages::-webkit-scrollbar {
    display: none;
}

.message-bubble {
    width: fit-content;
    max-width: min(620px, 82%);
    padding: 10px 12px;
    border-radius: 8px;
}

.message-bubble small {
    display: block;
    color: #657382;
    font-size: 12px;
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}

.message-sender {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.message-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    background: #184d47;
}

.message-actions {
    display: flex;
    gap: 8px;
    font-size: 12px;
}

.message-action {
    color: #184d47;
    text-decoration: underline;
}

.danger-link {
    color: #b42318;
}

.message-bubble p {
    margin: 0;
    overflow-wrap: anywhere;
    line-height: 1.4;
}

.attachment {
    margin-bottom: 8px;
}

.attachment-image,
.attachment-video {
    display: block;
    max-width: min(360px, 100%);
    max-height: 320px;
    border-radius: 8px;
    object-fit: contain;
    background: #0d171c;
}

.message-bubble.mine {
    align-self: flex-end;
    color: #08231f;
    background: #cce9df;
}

.message-bubble.theirs {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e0e6ed;
}

.composer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 132px 110px;
    gap: 12px;
    padding: 16px 22px;
    border-top: 1px solid #e5ebf0;
}

.message-input {
    min-height: 76px;
    resize: vertical;
}

.emoji-picker {
    display: flex;
    gap: 6px;
    padding: 12px 22px 0;
    overflow-x: auto;
}

.edit-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 22px;
    color: #184d47;
    background: #eef7f5;
    border-top: 1px solid #d8e8e5;
    font-size: 13px;
    font-weight: 700;
}

.emoji-button {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 1px solid #d8e1e8;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    font-size: 18px;
}

.emoji-button:hover {
    background: #eef7f5;
    border-color: #9dbcb5;
}

.file-picker {
    min-height: 76px;
    display: grid;
    place-items: center;
    padding: 10px;
    color: #184d47;
    background: #eef7f5;
    border: 1px dashed #9dbcb5;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    text-align: center;
}

.file-picker input {
    width: 100%;
    margin-top: 6px;
    font-size: 11px;
}

.empty-state {
    flex: 1;
    min-height: 0;
    display: grid;
    place-content: center;
    gap: 8px;
    padding: 24px;
    color: #657382;
    text-align: center;
}

.empty-state p {
    margin: 0;
}

.photo-viewer {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(9, 20, 27, .78);
}

.photo-viewer.open {
    display: flex;
}

.photo-viewer-image {
    max-width: min(92vw, 760px);
    max-height: 82vh;
    border-radius: 8px;
    object-fit: contain;
    background: #0d171c;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .35);
}

.photo-viewer-close {
    position: absolute;
    top: 18px;
    right: 18px;
    min-height: 38px;
    padding: 8px 14px;
    color: #fff;
    background: rgba(255, 255, 255, .14);
    border: 1px solid rgba(255, 255, 255, .3);
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
}

.photo-viewer-close:hover {
    background: rgba(255, 255, 255, .24);
}

.call-modal-content {
    overflow: hidden;
}

.call-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.call-title span {
    display: block;
    color: #657382;
    font-size: 13px;
}

.call-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    background: #184d47;
}

.call-device-settings {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.call-device-settings label {
    min-width: 0;
    display: grid;
    gap: 5px;
    color: #485766;
    font-size: 12px;
    font-weight: 700;
}

.call-device-settings select {
    min-width: 0;
}

.call-stage {
    position: relative;
    min-height: 380px;
    display: grid;
    place-items: center;
    background: #0d171c;
    border-radius: 8px;
    overflow: hidden;
}

.call-video {
    width: 100%;
    height: 380px;
    display: none;
    object-fit: cover;
    background: #0d171c;
}

.local-call-video {
    position: absolute;
    right: 14px;
    bottom: 14px;
    width: 168px;
    height: 112px;
    display: none;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, .82);
    border-radius: 8px;
    background: #0d171c;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .28);
}

.call-audio-placeholder {
    min-height: 380px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 14px;
    color: #fff;
}

.call-audio-avatar {
    width: 132px;
    height: 132px;
    border-radius: 50%;
    object-fit: cover;
    background: #184d47;
    border: 4px solid rgba(255, 255, 255, .2);
}

.call-controls {
    justify-content: center;
}

.incoming-call-body {
    display: flex;
    align-items: center;
    gap: 12px;
}

.incoming-call-body span {
    display: block;
    color: #657382;
    font-size: 13px;
}

@media (max-width: 820px) {
    .topbar {
        padding: 0 16px;
    }

    .chat-shell {
        grid-template-columns: 1fr;
        height: auto;
        min-height: calc(100vh - 96px);
        overflow: visible;
    }

    .sidebar,
    .conversation,
    .conversation-panel,
    .empty-state {
        min-height: 0;
    }

    .sidebar {
        height: 320px;
    }

    .conversation {
        height: 620px;
    }

    .conversation-panel,
    .empty-state {
        height: auto;
    }

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

    .file-picker {
        min-height: 58px;
    }

    .conversation-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .conversation-tools {
        width: 100%;
        justify-content: flex-start;
    }

    .admin-form,
    .users-row {
        grid-template-columns: 1fr;
    }

    .users-head {
        display: none;
    }

    .call-stage,
    .call-video,
    .call-audio-placeholder {
        min-height: 280px;
        height: 280px;
    }

    .local-call-video {
        width: 116px;
        height: 82px;
        right: 10px;
        bottom: 10px;
    }

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