:root {
    --wa-green: #128c7e;
    --wa-green-dark: #075e54;
    --wa-green-soft: #d9fdd3;
    --ink: #111b21;
    --muted: #667781;
    --line: #d5dbdf;
    --paper: #ffffff;
    --sidebar: #f7f8fa;
    --chat-bg: #efeae2;
    --danger: #d64545;
    --shadow-app: 0 10px 38px rgba(17, 27, 33, 0.16);
    --shadow-soft: 0 6px 20px rgba(17, 27, 33, 0.1);
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 10px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: "Manrope", "Segoe UI", Tahoma, sans-serif;
    color: var(--ink);
    background: linear-gradient(180deg, #00a884 0 122px, #e9edef 122px 100%);
    padding: clamp(10px, 1.3vw, 18px);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image: radial-gradient(rgba(17, 27, 33, 0.04) 1px, transparent 1px);
    background-size: 20px 20px;
    opacity: 0.45;
}

.bg-orb {
    display: none;
}

.app-shell {
    position: relative;
    z-index: 1;
    width: min(1420px, 100%);
    margin: 0 auto;
}

h1,
h2,
h3 {
    margin: 0;
    font-weight: 700;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

.topbar {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    min-height: 70px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 14px;
}

.topbar-main {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.kicker {
    margin: 0;
    color: var(--muted);
    font-size: 0.73rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
}

h1 {
    font-size: clamp(1.07rem, 2.1vw, 1.44rem);
    margin-top: 2px;
    color: var(--wa-green-dark);
}

.topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.topbar-user {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 6px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #f7f9fb;
}

.topbar-user-name,
.topbar-user-meta {
    margin: 0;
}

.topbar-user-name {
    font-size: 0.85rem;
    font-weight: 700;
}

.topbar-user-meta {
    font-size: 0.76rem;
    color: var(--muted);
}

.avatar {
    border-radius: 999px;
    object-fit: cover;
    border: 1px solid var(--line);
    background: #ecf0f2;
}

.avatar-sm {
    width: 34px;
    height: 34px;
}

.avatar-lg {
    width: 80px;
    height: 80px;
}

.icon-button,
.primary-button,
.ghost-button,
.text-button,
.tab {
    border-radius: 999px;
    padding: 9px 14px;
    border: 1px solid transparent;
    font-weight: 700;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.icon-button {
    background: var(--wa-green-dark);
    color: #fff;
}

.primary-button {
    background: var(--wa-green);
    border-color: var(--wa-green);
    color: #fff;
}

.primary-button:hover {
    background: #0f7f72;
    border-color: #0f7f72;
}

.ghost-button {
    background: #fff;
    border-color: var(--line);
    color: var(--ink);
}

.ghost-button:hover {
    background: #f5f7f8;
}

.text-button {
    border: 0;
    padding: 2px 0;
    background: transparent;
    color: var(--wa-green-dark);
}

.text-button:hover {
    text-decoration: underline;
}

.auth-panel {
    width: min(520px, 100%);
    margin: clamp(20px, 5vh, 64px) auto;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-app);
    padding: 22px;
    animation: fadeUp 220ms ease;
}

.auth-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 16px;
    padding: 5px;
    border-radius: 999px;
    background: #f2f5f6;
}

.tab {
    background: transparent;
    border-color: transparent;
    color: var(--muted);
}

.tab.active {
    background: #fff;
    color: var(--ink);
    border-color: var(--line);
}

.auth-form {
    display: grid;
    gap: 13px;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.92rem;
}

input,
textarea,
select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--ink);
    padding: 10px 12px;
}

textarea {
    resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #86cfc2;
    box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.15);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 0.9rem;
    color: var(--muted);
}

.checkbox-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
}

.checkbox-row.compact {
    margin-top: 8px;
    font-size: 0.84rem;
}

.tiny-note {
    margin: 0;
    color: var(--muted);
    font-size: 0.83rem;
}

.auth-actions {
    display: flex;
    justify-content: flex-end;
}

.workspace {
    margin-top: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-app);
    background: var(--paper);
    min-height: calc(100vh - 128px);
    overflow: hidden;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 290px;
    position: relative;
    padding-bottom: 84px;
}

.chat-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: min(360px, 92vw);
    height: 100vh;
    z-index: 70;
    transform: translateX(-104%);
    transition: transform 180ms ease;
    box-shadow: 12px 0 36px rgba(0, 0, 0, 0.22);
    background: var(--sidebar);
    border-right: 1px solid var(--line);
    padding: 10px;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
    gap: 10px;
    min-width: 0;
}

.workspace .chat-drawer.hidden {
    display: none !important;
}

.workspace.drawer-open .chat-drawer {
    display: grid !important;
    transform: translateX(0);
}

.drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.drawer-head h2 {
    font-size: 1.04rem;
}

.drawer-close {
    padding: 7px 11px;
}

.drawer-user-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 8px;
}

.drawer-user {
    margin: 0;
    color: var(--muted);
    font-size: 0.86rem;
}

.chat-list,
.landing-chat-list,
.pending-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 7px;
}

.chat-list {
    overflow: auto;
    padding-right: 2px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid #e2e7ea;
    border-radius: var(--radius-sm);
    background: #fff;
    padding: 9px;
    cursor: pointer;
}

.chat-item:hover {
    background: #f3f7f7;
}

.chat-item.active {
    border-color: #8fd0c7;
    background: #e8f7f3;
}

.chat-item-main {
    min-width: 0;
}

.chat-item-name {
    display: block;
    font-size: 0.93rem;
    font-weight: 700;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-sub {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.79rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.drawer-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 7px;
}

.drawer-form {
    padding-top: 10px;
    border-top: 1px solid var(--line);
    display: grid;
    gap: 8px;
}

.drawer-form h3 {
    font-size: 0.95rem;
}

.drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.34);
    z-index: 65;
    border: 0;
}

.workspace .drawer-backdrop.hidden {
    display: none !important;
}

.chat-main {
    min-width: 0;
    background: var(--chat-bg);
}

.chat-landing,
.chat-panel {
    height: 100%;
}

.chat-landing {
    display: grid;
    place-items: center;
    padding: 20px;
}

.landing-card {
    width: min(620px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 18px;
}

.landing-card h2 {
    margin-bottom: 8px;
}

.landing-card p {
    margin: 0 0 12px;
    color: var(--muted);
    line-height: 1.45;
}

.chat-panel {
    display: grid;
    grid-template-rows: auto 1fr auto;
}

.chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    background: #f0f2f5;
}

.chat-head-main {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.chat-back {
    padding: 7px 11px;
}

.chat-head h2 {
    font-size: 1.05rem;
}

.chat-head p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 0.86rem;
}

.chat-actions {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
}

.messages {
    overflow: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background-color: var(--chat-bg);
    background-image:
        linear-gradient(45deg, rgba(255, 255, 255, 0.24) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.24) 50%, rgba(255, 255, 255, 0.24) 75%, transparent 75%, transparent),
        radial-gradient(rgba(17, 27, 33, 0.035) 1px, transparent 1px);
    background-size: 16px 16px, 20px 20px;
}

.message {
    align-self: flex-start;
    max-width: min(76%, 740px);
    padding: 8px 10px;
    border-radius: 9px;
    border: 1px solid #e0e6e9;
    background: #fff;
    box-shadow: 0 1px 1px rgba(17, 27, 33, 0.07);
}

.message.mine {
    align-self: flex-end;
    background: var(--wa-green-soft);
    border-color: #cfe9ca;
}

.message.system {
    align-self: center;
    max-width: 90%;
    text-align: center;
    background: #f2fbf8;
    border-color: #d4ebe4;
    color: var(--muted);
}

.message-top {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
}

.message-top .avatar {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
}

.message-sender {
    font-size: 0.8rem;
    font-weight: 700;
    color: #2d3d44;
}

.message-body {
    display: grid;
    gap: 8px;
}

.message-text {
    margin: 0;
    line-height: 1.45;
    word-wrap: break-word;
}

.message-body .message-media {
    width: 100%;
    max-width: min(420px, 100%);
    border-radius: var(--radius-sm);
    border: 1px solid #dbe2e6;
    background: #000;
}

.message-body audio.message-media {
    height: 40px;
    background: #fff;
}

.message-body img.message-media {
    max-height: 420px;
    object-fit: cover;
    background: #fff;
}

.message-body video.message-media {
    max-height: 360px;
}

.message .meta {
    margin-top: 6px;
    font-size: 0.74rem;
    color: var(--muted);
    text-align: right;
}

.message.system .meta {
    text-align: center;
}

.composer {
    border-top: 1px solid var(--line);
    background: #f0f2f5;
    padding: 10px;
    display: grid;
    gap: 8px;
}

.composer textarea {
    min-height: 48px;
    max-height: 148px;
    border-radius: 18px;
    background: #fff;
}

.composer-actions {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
}

.file-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.admin-panel {
    border-left: 1px solid var(--line);
    background: var(--sidebar);
    padding: 12px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px;
    max-height: 100%;
}

.admin-panel h2 {
    font-size: 1.01rem;
}

.pending-list {
    overflow: auto;
    align-content: start;
}

.pending-item {
    border: 1px solid #e2e7ea;
    border-radius: var(--radius-sm);
    background: #fff;
    padding: 9px;
    display: grid;
    gap: 8px;
}

.pending-item .line-1 {
    font-weight: 700;
}

.pending-item .line-2 {
    color: var(--muted);
    font-size: 0.82rem;
    overflow-wrap: anywhere;
}

.settings-modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 12px;
}

.settings-backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(11, 20, 26, 0.54);
}

.settings-card {
    position: relative;
    width: min(1040px, 100%);
    max-height: 94vh;
    overflow: auto;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: #fff;
    box-shadow: var(--shadow-app);
    padding: 16px;
}

.settings-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.settings-body {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 12px;
}

.settings-form {
    background: #fafbfc;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 12px;
    display: grid;
    gap: 10px;
}

.settings-form h3 {
    font-size: 1rem;
}

.settings-avatar-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.push-status {
    border: 1px dashed #b8c4cb;
    border-radius: var(--radius-sm);
    padding: 9px 10px;
    color: var(--muted);
    font-size: 0.84rem;
    background: #fff;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 16px;
    transform: translateX(-50%);
    background: #1f2c34;
    color: #fff;
    padding: 10px 14px;
    border-radius: 999px;
    box-shadow: var(--shadow-soft);
    z-index: 60;
    font-size: 0.9rem;
}

.bottom-nav {
    position: fixed;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    width: min(760px, calc(100% - 18px));
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 999px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.16);
    padding: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 45;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.bottom-nav-btn,
.bottom-nav-profile {
    border: 1px solid transparent;
    border-radius: 999px;
    background: #f3f6f7;
    color: var(--ink);
    padding: 9px 10px;
    font-size: 0.86rem;
    font-weight: 700;
    min-width: 0;
    flex: 1;
}

.bottom-nav-btn:hover,
.bottom-nav-profile:hover {
    background: #eaf1f3;
}

.bottom-nav-profile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex: 1.4;
}

.bottom-nav-profile .avatar {
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
}

.bottom-nav-profile span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.workspace.chat-selected + .bottom-nav {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 120%);
}

.hidden {
    display: none !important;
}

@media (max-width: 1260px) {
    .workspace {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) auto;
    }

    .admin-panel {
        grid-column: 1 / -1;
        border-left: 0;
        border-top: 1px solid var(--line);
        max-height: 220px;
    }
}

@media (max-width: 980px) {
    body {
        padding: 8px;
    }

    .topbar {
        border-radius: 12px;
        min-height: 62px;
        padding: 8px 10px;
    }

    .topbar-user {
        max-width: 100%;
    }

    .topbar-user-meta {
        display: none;
    }

    .workspace {
        display: block;
        min-height: calc(100vh - 90px);
        margin-top: 8px;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
        padding-bottom: 76px;
    }

    .chat-main {
        min-height: calc(100vh - 146px);
        border: 1px solid var(--line);
        border-radius: 12px;
        overflow: hidden;
    }

    .admin-panel {
        margin-top: 8px;
        border: 1px solid var(--line);
        border-radius: 12px;
        max-height: none;
    }

    .chat-drawer {
        width: min(340px, 92vw);
    }

    .chat-head {
        flex-direction: column;
        align-items: flex-start;
    }

    .chat-actions {
        width: 100%;
    }

    .chat-actions button {
        flex: 1;
    }

    .message {
        max-width: 92%;
    }

    .settings-body {
        grid-template-columns: 1fr;
    }

    .bottom-nav {
        width: calc(100% - 12px);
        bottom: 6px;
        gap: 4px;
        padding: 5px;
    }

    .bottom-nav-btn,
    .bottom-nav-profile {
        padding: 9px 6px;
        font-size: 0.8rem;
    }
}

@media (max-width: 620px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .composer-actions {
        width: 100%;
    }

    .composer-actions .ghost-button,
    .composer-actions .primary-button,
    .composer-actions .file-button {
        flex: 1;
        justify-content: center;
    }

    .bottom-nav-profile span {
        display: none;
    }
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}