:root {
    --bg: #0b1020;
    --panel: #121932;
    --panel2: #18213f;
    --text: #eef2ff;
    --muted: #98a2c4;
    --accent: #6c7cff;
    --accent2: #8b5cf6;
    --danger: #ff5d73;
    --ok: #2dd4bf;
    --border: rgba(255,255,255,.08);
    --shadow: 0 20px 50px rgba(0,0,0,.28);
}
* {
    box-sizing: border-box;
}
html, body {
    height: 100%;
}
body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: linear-gradient(135deg,#090e1b,#101834 55%,#131b37);
    color: var(--text);
}
a {
    color: inherit;
    text-decoration: none;
}
button, input, textarea, select {
    font: inherit;
}
.topbar {
    height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    border-bottom: 1px solid var(--border);
    background: rgba(9,14,27,.86);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand {
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 10px;
}
.brandmark {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    display: inline-grid;
    place-items: center;
    background: linear-gradient(135deg,var(--accent),var(--accent2));
    box-shadow: 0 8px 25px rgba(108,124,255,.3);
}
.brandmark.big {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    font-size: 23px;
}
.top-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.who {
    color: var(--muted);
    font-size: 14px;
}
.ghost-btn, .icon-btn {
    border: 1px solid var(--border);
    background: var(--panel2);
    color: var(--text);
    padding: 9px 12px;
    border-radius: 10px;
    cursor: pointer;
}
.primary-btn {
    border: 0;
    background: linear-gradient(135deg,var(--accent),var(--accent2));
    color: white;
    padding: 10px 15px;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
}
.danger-btn {
    border: 0;
    background: var(--danger);
    color: #fff;
    padding: 9px 12px;
    border-radius: 9px;
    cursor: pointer;
}
.full {
    width: 100%;
}
.login-bg {
    display: grid;
    place-items: center;
    padding: 24px;
}
.login-card {
    width: min(430px,100%);
    background: rgba(18,25,50,.92);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 28px;
    box-shadow: var(--shadow);
}
.login-logo {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
    margin-bottom: 24px;
    text-align: center;
}
.login-logo h1 {
    margin: 0;
}
.login-logo p {
    margin: 10px 0 0;
    color: var(--muted);
}
label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin: 12px 0 6px;
}
input, textarea, select {
    width: 100%;
    border: 1px solid var(--border);
    background: #0d142a;
    color: var(--text);
    border-radius: 10px;
    padding: 11px 12px;
    outline: none;
}
input:focus, textarea:focus, select:focus {
    border-color: #6475ff;
    box-shadow: 0 0 0 3px rgba(100,117,255,.12);
}
.login-note {
    font-size: 12px;
    color: var(--muted);
    margin-top: 16px;
    line-height: 1.5;
}
.alert {
    padding: 11px 13px;
    border-radius: 10px;
    margin-bottom: 14px;
}
.alert.error {
    background: rgba(255,93,115,.12);
    border: 1px solid rgba(255,93,115,.25);
}
.chat-shell {
    height: calc(100vh - 106px);
    display: grid;
    grid-template-columns: 330px 1fr;
    max-width: 1500px;
    margin: auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
}
.sidebar {
    background: rgba(15,22,44,.92);
    border-right: 1px solid var(--border);
    overflow: hidden;
}
.sidebar-head {
    display: flex;
    gap: 8px;
    padding: 14px;
}
.search {
    padding: 10px 12px;
}
.sidebar-tabs {
    display: flex;
    padding: 0 14px 10px;
    gap: 8px;
}
.tab {
    flex: 1;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 8px;
    border-radius: 9px;
    cursor: pointer;
}
.tab.active {
    background: var(--panel2);
    color: var(--text);
}
.list-pane {
    height: calc(100% - 112px);
    overflow: auto;
    padding: 4px 8px 12px;
}
.list-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 11px;
    border-radius: 12px;
    cursor: pointer;
}
.list-item:hover, .list-item.active {
    background: var(--panel2);
}
.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg,#243258,#3c4c85);
    font-weight: 800;
}
.li-main {
    min-width: 0;
    flex: 1;
}
.li-title {
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.li-sub {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 3px;
}
.badge {
    font-size: 10px;
    padding: 3px 7px;
    border-radius: 999px;
    background: rgba(108,124,255,.17);
    color: #bdc5ff;
}
.badge.danger {
    background: rgba(255,93,115,.13);
    color: #ff9aa8;
}
.chat-main {
    position: relative;
    min-width: 0;
    background: rgba(8,13,27,.62);
}
.empty-chat {
    height: 100%;
    display: grid;
    place-content: center;
    text-align: center;
    color: var(--muted);
}
.empty-chat h2 {
    color: var(--text);
    margin-bottom: 4px;
}
.empty-icon {
    font-size: 56px;
}
.active-chat {
    height: 100%;
    display: grid;
    grid-template-rows: auto 1fr auto auto;
}
.chat-head {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.chat-head h2 {
    margin: 0;
    font-size: 18px;
}
.chat-head small {
    color: var(--muted);
}
.messages {
    overflow: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.message {
    max-width: min(72%,680px);
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 10px 12px;
    align-self: flex-start;
}
.message.mine {
    align-self: flex-end;
    background: linear-gradient(135deg,rgba(70,84,164,.8),rgba(91,64,156,.82));
}
.message.deleted {
    opacity: .75;
    font-style: italic;
    color: var(--muted);
}
.msg-top {
    display: flex;
    gap: 10px;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}
.msg-name {
    font-size: 12px;
    font-weight: 800;
}
.msg-time {
    font-size: 10px;
    color: var(--muted);
}
.msg-body {
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.45;
}
.msg-actions {
    margin-top: 7px;
    display: flex;
    justify-content: flex-end;
}
.link-btn {
    border: 0;
    background: transparent;
    color: #c7ceff;
    font-size: 11px;
    cursor: pointer;
    padding: 0;
}
.attachment {
    display: inline-flex;
    gap: 7px;
    align-items: center;
    margin-top: 8px;
    padding: 8px 9px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: rgba(255,255,255,.04);
}
.composer {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 9px;
    padding: 12px;
    border-top: 1px solid var(--border);
    background: rgba(10,15,29,.9);
}
.composer textarea {
    resize: none;
    max-height: 120px;
}
.attach-btn {
    margin: 0;
    align-self: center;
    font-size: 22px;
    cursor: pointer;
    color: var(--text);
}
.file-hint {
    padding: 0 15px 9px;
    font-size: 11px;
    color: var(--muted);
    background: rgba(10,15,29,.9);
}
.hidden {
    display: none!important;
}
.modal {
    position: fixed;
    inset: 0;
    background: rgba(2,5,12,.72);
    display: grid;
    place-items: center;
    z-index: 100;
    padding: 20px;
}
.modal-card {
    width: min(520px,100%);
    max-height: 85vh;
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 18px;
    box-shadow: var(--shadow);
}
.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-head h3 {
    margin: 0;
}
.modal-head button {
    background: transparent;
    border: 0;
    color: white;
    font-size: 24px;
    cursor: pointer;
}
.member-picker {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px;
    max-height: 230px;
    overflow: auto;
}
.member-row {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 7px;
}
.member-row input {
    width: auto;
}
.footer {
    height: 38px;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 11px;
    border-top: 1px solid var(--border);
}
.admin-wrap {
    max-width: 1400px;
    margin: 22px auto;
    padding: 0 18px;
}
.admin-grid {
    display: grid;
    grid-template-columns: repeat(4,1fr);
    gap: 14px;
    margin-bottom: 20px;
}
.stat {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 15px;
    padding: 16px;
}
.stat b {
    font-size: 28px;
}
.stat span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-top: 5px;
}
.admin-nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 15px;
    padding: 16px;
    margin-bottom: 16px;
}
.card h2, .card h3 {
    margin-top: 0;
}
.table-wrap {
    overflow: auto;
}
.table {
    width: 100%;
    border-collapse: collapse;
}
.table th, .table td {
    text-align: left;
    padding: 11px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.table th {
    color: var(--muted);
    font-weight: 600;
}
.inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.inline-form input, .inline-form select {
    width: auto;
    min-width: 130px;
}
.toggle {
    position: relative;
    width: 46px;
    height: 26px;
    display: inline-block;
}
.toggle input {
    display: none;
}
.toggle span {
    position: absolute;
    inset: 0;
    background: #33405f;
    border-radius: 999px;
    cursor: pointer;
}
.toggle span:after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 3px;
    top: 3px;
    border-radius: 50%;
    background: white;
    transition: .2s;
}
.toggle input:checked+span {
    background: var(--ok);
}
.toggle input:checked+span:after {
    transform: translateX(20px);
}
.muted {
    color: var(--muted);
}
.audit-body {
    max-width: 560px;
    white-space: pre-wrap;
    word-break: break-word;
}
.deleted-content {
    background: rgba(255,93,115,.08);
    border: 1px solid rgba(255,93,115,.16);
    padding: 8px;
    border-radius: 8px;
}
.row-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
@media(max-width:900px) {
    .chat-shell {
        grid-template-columns: 280px 1fr;
    }
    .admin-grid {
        grid-template-columns: repeat(2,1fr);
    }
}
@media(max-width:700px) {
    .who {
        display: none;
    }
    .chat-shell {
        height: calc(100vh - 106px);
        grid-template-columns: 1fr;
    }
    .sidebar {
        position: absolute;
        z-index: 8;
        width: 100%;
        height: calc(100vh - 106px);
    }
    .sidebar.mobile-hidden {
        display: none;
    }
    .chat-main {
        height: 100%;
    }
    .message {
        max-width: 88%;
    }
    .admin-grid {
        grid-template-columns: 1fr;
    }
    .table th, .table td {
        white-space: nowrap;
    }
    .topbar {
        padding: 0 12px;
    }
}
.filter-grid, .settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit,minmax(210px,1fr));
    gap: 14px;
    margin: 16px 0;
}
.filter-grid label, .settings-grid label {
    display: flex;
    flex-direction: column;
    gap: 7px;
}
.filter-actions {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
    margin: 18px 0 4px;
}
.page-link, .page-gap {
    padding: 8px 11px;
    border-radius: 9px;
}
.page-link {
    border: 1px solid rgba(148,163,184,.22);
    text-decoration: none;
    color: inherit;
}
.page-link.active {
    background: rgba(59,130,246,.2);
    border-color: rgba(59,130,246,.45);
}
.settings-form hr {
    border: 0;
    border-top: 1px solid rgba(148,163,184,.18);
    margin: 24px 0;
}
.settings-preview {
    display: block;
    max-width: 180px;
    max-height: 80px;
    object-fit: contain;
    padding: 8px;
    border: 1px solid rgba(148,163,184,.2);
    border-radius: 10px;
}
.favicon-preview {
    width: 48px;
    height: 48px;
    object-fit: contain;
    padding: 6px;
    border: 1px solid rgba(148,163,184,.2);
    border-radius: 9px;
}
.audit-body {
    min-width: 260px;
    max-width: 560px;
    white-space: normal;
    word-break: break-word;
}
/* Chat notification badges */
.notification-toggle {
    min-width: 42px;
    padding-left: 9px;
    padding-right: 9px;
}
.notification-toggle.muted-toggle {
    opacity: .55;
}
.sidebar-tabs .tab {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}
.unread-badge, .tab-unread {
    display: inline-grid;
    place-items: center;
    min-width: 21px;
    height: 21px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 4px 12px rgba(255,93,115,.26);
}
.tab-unread {
    min-width: 19px;
    height: 19px;
    font-size: 10px;
}
.list-item .unread-badge {
    flex: 0 0 auto;
}
.list-item:has(.unread-badge) .li-title {
    font-weight: 800;
    color: #fff;
}
/* FIX: keep long conversations inside the chat viewport instead of overflowing past the footer */
.chat-shell {
    min-height: 0;
    overflow: hidden;
}
.chat-main {
    min-height: 0;
    overflow: hidden;
}
.active-chat {
    min-height: 0;
    overflow: hidden;
    grid-template-rows: auto minmax(0,1fr) auto auto;
}
.messages {
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
}
.sidebar {
    min-height: 0;
}
.list-pane {
    min-height: 0;
}
/* CompanyChat professional dialogs */
.cc-dialog-open {
    overflow: hidden;
}
.cc-dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(3,8,24,.72);
    backdrop-filter: blur(7px);
    animation: ccFade .16s ease;
}
.cc-dialog-backdrop.hidden, .cc-toast.hidden {
    display: none!important;
}
.cc-dialog {
    width: min(430px,100%);
    padding: 28px;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 20px;
    background: linear-gradient(145deg,#121a36,#0c1329);
    box-shadow: 0 28px 80px rgba(0,0,0,.48);
    text-align: center;
    animation: ccPop .18s ease;
}
.cc-dialog-icon {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    margin: 0 auto 15px;
    border-radius: 18px;
    background: rgba(124,92,255,.16);
    border: 1px solid rgba(124,92,255,.35);
    font-size: 30px;
    font-weight: 800;
    color: #a999ff;
}
.cc-dialog[data-type="success"] .cc-dialog-icon {
    background: rgba(45,212,191,.13);
    border-color: rgba(45,212,191,.32);
    color: #5eead4;
}
.cc-dialog[data-type="warning"] .cc-dialog-icon {
    background: rgba(251,191,36,.12);
    border-color: rgba(251,191,36,.32);
    color: #fcd34d;
}
.cc-dialog[data-type="error"] .cc-dialog-icon {
    background: rgba(248,113,113,.12);
    border-color: rgba(248,113,113,.32);
    color: #fca5a5;
}
.cc-dialog h3 {
    margin: 0 0 9px;
    font-size: 20px;
}
.cc-dialog p {
    margin: 0;
    color: #aeb9d6;
    line-height: 1.55;
    white-space: pre-wrap;
}
.cc-dialog-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 24px;
}
.cc-dialog-actions button {
    min-width: 110px;
}
.cc-toast {
    position: fixed;
    right: 22px;
    top: 84px;
    z-index: 100000;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: min(390px,calc(100vw - 32px));
    padding: 15px 17px;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 14px;
    background: #111a34;
    box-shadow: 0 18px 50px rgba(0,0,0,.38);
    animation: ccToastIn .22s ease;
}
.cc-toast-icon {
    display: grid;
    place-items: center;
    flex: 0 0 32px;
    height: 32px;
    border-radius: 10px;
    background: rgba(45,212,191,.14);
    color: #5eead4;
    font-weight: 900;
}
.cc-toast strong {
    display: block;
    margin: 1px 0 3px;
}
.cc-toast #ccToastText {
    color: #aeb9d6;
    font-size: 13px;
    line-height: 1.4;
}
.cc-toast[data-type="error"] .cc-toast-icon {
    background: rgba(248,113,113,.12);
    color: #fca5a5;
}
.cc-toast[data-type="warning"] .cc-toast-icon {
    background: rgba(251,191,36,.12);
    color: #fcd34d;
}
@keyframes ccFade {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}
@keyframes ccPop {
    from {
        opacity: 0;
        transform: translateY(8px) scale(.98);
    }
    to {
        opacity: 1;
        transform: none;
    }
}
@keyframes ccToastIn {
    from {
        opacity: 0;
        transform: translateX(16px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}
@media(max-width:600px) {
    .cc-toast {
        top: 72px;
        right: 16px;
    }
    .cc-dialog {
        padding: 23px 18px;
    }
}

/* Message reactions */
.reaction-row {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.reaction-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 28px;
    padding: 0 9px;
    border: 1px solid rgba(255,255,255,.10);
    border-radius: 999px;
    background: rgba(255,255,255,.055);
    color: var(--text);
    cursor: pointer;
    transition: .16s ease;
}
.reaction-pill:hover {
    background: rgba(255,255,255,.10);
    transform: translateY(-1px);
}
.reaction-pill.mine {
    border-color: rgba(108,124,255,.58);
    background: rgba(108,124,255,.20);
    box-shadow: 0 0 0 1px rgba(108,124,255,.08) inset;
}
.reaction-pill span {
    font-size: 15px;
    line-height: 1;
}
.reaction-pill b {
    font-size: 11px;
    font-weight: 800;
    color: #d9defc;
}
.msg-actions {
    position: relative;
    gap: 9px;
    align-items: center;
}
.reaction-control {
    position: relative;
    display: inline-flex;
}
.reaction-add-btn {
    display: grid;
    place-items: center;
    width: 28px;
    height: 26px;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: #c7ceff;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    opacity: .72;
    transition: .16s ease;
    align-items: center;
}
.message:hover .reaction-add-btn, .reaction-add-btn:focus {
    opacity: 1;
    border-color: rgba(255,255,255,.10);
    background: rgba(255,255,255,.055);
}
.reaction-picker {
    position: absolute;
    right: 0;
    bottom: 34px;
    z-index: 30;
    display: flex;
    gap: 3px;
    padding: 7px;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 12px;
    background: #111a34;
    box-shadow: 0 14px 38px rgba(0,0,0,.36);
    white-space: nowrap;
}
.message:not(.mine) .reaction-picker {
    left: 0;
    right: auto;
}
.reaction-picker button {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 9px;
    background: transparent;
    cursor: pointer;
    font-size: 20px;
    transition: .14s ease;
}
.reaction-picker button:hover {
    background: rgba(255,255,255,.09);
    transform: scale(1.12);
}
@media(max-width:600px) {
    .reaction-add-btn {
        opacity: 1;
    }
    .reaction-picker {
        position: fixed;
        left: 50%!important;
        right: auto!important;
        bottom: 78px;
        transform: translateX(-50%);
        padding: 9px;
    }
    .reaction-picker button {
        width: 38px;
        height: 38px;
        font-size: 22px;
    }
}