/*
  ChatUbam Theme
  Cambia estos colores para personalizar el diseno.
*/
:root {
    --brand: #23a55a;
    --brand-dark: #15874c;
    --brand-soft: #d8f3e3;
    --accent: #0f6a39;

    --text-strong: #1b2320;
    --text-muted: #63726c;

    --bg-main: #eef2ef;
    --bg-panel: #ffffff;
    --bg-subtle: #f7faf8;
    --border-soft: #d6dfda;

    --bubble-out: #d7f8c4;
    --bubble-in: #ffffff;

    --danger: #ba3c3c;
    --shadow: 0 18px 45px rgba(15, 37, 26, 0.12);

    --radius-xl: 24px;
    --radius-md: 14px;
    --radius-sm: 10px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    overflow-x: hidden;
    min-height: 100%;
    color: var(--text-strong);
    font-family: "Poppins", "Segoe UI", sans-serif;
    background: var(--bg-main);
}

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

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

a {
    color: var(--accent);
    text-decoration: none;
}

.hidden {
    display: none !important;
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 999;
    min-width: 250px;
    max-width: 400px;
    padding: 12px 16px;
    border-radius: 12px;
    color: #fff;
    background: #1e2f27;
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.success {
    background: #1d7745;
}

.toast.error {
    background: var(--danger);
}

/* ---------- AUTH ---------- */
.auth-body {
    background:
        radial-gradient(circle at top right, rgba(35, 165, 90, 0.22) 0%, transparent 50%),
        radial-gradient(circle at bottom left, rgba(21, 135, 76, 0.2) 0%, transparent 45%),
        var(--bg-main);
}

.auth-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 22px;
    padding: 34px;
}

.welcome-panel,
.auth-panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
}

.welcome-panel {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 44px;
    position: relative;
    overflow: hidden;
}

.welcome-panel::before,
.welcome-panel::after {
    content: "";
    position: absolute;
    border-radius: 50%;
    filter: blur(1px);
}

.welcome-panel::before {
    width: 280px;
    height: 280px;
    background: rgba(35, 165, 90, 0.11);
    top: -90px;
    right: -80px;
}

.welcome-panel::after {
    width: 240px;
    height: 240px;
    background: rgba(21, 135, 76, 0.11);
    bottom: -90px;
    left: -80px;
}

.brand-pill {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-weight: 600;
    background: var(--brand-soft);
    color: var(--accent);
    border: 1px solid rgba(18, 104, 56, 0.28);
    border-radius: 999px;
    padding: 8px 15px;
    margin-bottom: 18px;
}

.brand-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--brand);
    box-shadow: 0 0 0 8px rgba(35, 165, 90, 0.16);
}

.welcome-title {
    position: relative;
    z-index: 1;
    margin: 0;
    font-size: clamp(2rem, 3.5vw, 3.2rem);
    line-height: 1.1;
}

.welcome-copy {
    position: relative;
    z-index: 1;
    max-width: 620px;
    color: var(--text-muted);
    font-size: 1.12rem;
    margin-top: 16px;
    margin-bottom: 30px;
}

.btn {
    border: 0;
    outline: none;
    border-radius: 999px;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn:active {
    transform: scale(0.99);
}

.btn-primary {
    background: linear-gradient(130deg, var(--brand) 0%, var(--brand-dark) 100%);
    color: #fff;
    padding: 14px 28px;
    min-width: 180px;
    box-shadow: 0 10px 20px rgba(21, 134, 76, 0.28);
}

.btn-primary:hover {
    box-shadow: 0 12px 22px rgba(21, 134, 76, 0.35);
}

.auth-panel {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.tab-switcher {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 6px;
    background: var(--bg-subtle);
    border: 1px solid var(--border-soft);
    border-radius: 14px;
}

.tab-switcher button {
    background: transparent;
    color: var(--text-muted);
    border-radius: 10px;
    padding: 10px 12px;
    border: 0;
    cursor: pointer;
    font-weight: 600;
}

.tab-switcher button.active {
    background: #fff;
    color: var(--accent);
    border: 1px solid rgba(21, 135, 76, 0.22);
}

.form-panel {
    display: none;
    animation: fadeIn 0.22s ease;
}

.form-panel.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.form-grid.two {
    grid-template-columns: 1fr 1fr;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.field label {
    font-size: 0.92rem;
    color: var(--text-muted);
}

.input {
    width: 100%;
    border-radius: 12px;
    border: 1px solid var(--border-soft);
    background: #fff;
    padding: 12px 13px;
    color: var(--text-strong);
    outline: none;
}

.input:focus {
    border-color: rgba(21, 135, 76, 0.6);
    box-shadow: 0 0 0 4px rgba(21, 135, 76, 0.12);
}

.auth-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 14px;
}

.btn-secondary {
    background: #fff;
    color: var(--accent);
    border: 1px solid rgba(21, 135, 76, 0.33);
    padding: 10px 16px;
}

.auth-note {
    border: 1px dashed rgba(21, 135, 76, 0.35);
    border-radius: 12px;
    background: rgba(35, 165, 90, 0.06);
    color: #2b4c3a;
    padding: 10px 12px;
    font-size: 0.92rem;
}

/* ---------- APP ---------- */
.app-body {
    background: linear-gradient(180deg, #dae3dd 0%, #edf2ef 30%, #edf2ef 100%);
}

.chat-app {
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-columns: 390px 1fr;
    background: #fff;
    position: relative;
}

.sidebar {
    border-right: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: #fcfdfd;
}

.sidebar-backdrop {
    display: none;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 18px 10px;
}

.sidebar-title {
    margin: 0;
    font-size: 2rem;
    font-weight: 700;
}

.user-mini {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    border: 1px solid var(--border-soft);
    background: #fff;
    color: #2a2d2c;
    cursor: pointer;
}

.search-wrap {
    padding: 8px 18px 12px;
}

.search-input {
    width: 100%;
    border-radius: 999px;
    border: 1px solid transparent;
    background: #eef1ef;
    padding: 12px 16px;
    outline: none;
}

.search-input:focus {
    background: #fff;
    border-color: rgba(21, 135, 76, 0.3);
}

.filters {
    display: flex;
    gap: 8px;
    padding: 0 18px 12px;
}

.filter-pill {
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 0.95rem;
    color: #45524d;
    background: #fff;
}

.filter-pill.active {
    background: var(--brand-soft);
    border-color: rgba(21, 135, 76, 0.35);
    color: var(--accent);
    font-weight: 600;
}

.contacts-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 10px;
}

.contact-item {
    display: grid;
    grid-template-columns: 52px 1fr auto;
    gap: 10px;
    align-items: center;
    border-radius: 14px;
    padding: 10px 10px;
    cursor: pointer;
    transition: background 0.16s ease;
}

.contact-item:hover {
    background: #f0f4f2;
}

.contact-item.active {
    background: #e8f1ec;
}

.avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: linear-gradient(140deg, #82ab96, #2c7a4f);
    color: #fff;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.avatar.bot {
    background: linear-gradient(140deg, #5ca07d, #265941);
}

.avatar img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.contact-main {
    min-width: 0;
}

.contact-name {
    margin: 0;
    font-size: 1.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-preview {
    margin-top: 4px;
    font-size: 1rem;
    color: #4f5c57;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    color: #5f6f69;
    font-size: 0.94rem;
}

.unread-badge {
    min-width: 24px;
    height: 24px;
    border-radius: 999px;
    background: var(--brand);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    padding: 0 6px;
}

.main-panel {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: #f8faf9;
}

.chat-header {
    height: 78px;
    border-bottom: 1px solid var(--border-soft);
    background: #f9fbfa;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-name {
    margin: 0;
    font-size: clamp(1.1rem, 2vw, 1.7rem);
    line-height: 1.2;
}

.chat-header-sub {
    margin-top: 2px;
    color: #61716a;
    font-size: 0.95rem;
    max-width: 48vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-stage {
    position: relative;
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #ebe6de;
}

.chat-stage::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.36;
    background-image:
        radial-gradient(circle at 20px 20px, #c8c1b8 2px, transparent 2px),
        radial-gradient(circle at 80px 60px, #cec7be 2px, transparent 2px),
        radial-gradient(circle at 150px 120px, #d8d1c8 2px, transparent 2px);
    background-size: 180px 180px;
}

.messages {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    max-width: min(75%, 700px);
    border-radius: 12px;
    padding: 10px 12px 9px;
    box-shadow: 0 5px 12px rgba(10, 24, 17, 0.11);
    position: relative;
}

.message.outgoing {
    margin-left: auto;
    background: var(--bubble-out);
}

.message.incoming {
    margin-right: auto;
    background: var(--bubble-in);
}

.message-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 1.02rem;
}

.message-file {
    margin-top: 8px;
    display: inline-block;
    padding: 7px 10px;
    border-radius: 9px;
    background: rgba(0, 0, 0, 0.07);
    color: #153324;
    font-size: 0.92rem;
}

.message img,
.message video {
    margin-top: 8px;
    max-width: 100%;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.12);
}

.message-meta {
    display: flex;
    justify-content: flex-end;
    margin-top: 5px;
    font-size: 0.8rem;
    color: #4e6058;
}

.empty-panel {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    text-align: center;
    color: #5d6c65;
    z-index: 2;
}

.empty-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(150px, 220px));
    gap: 18px;
    justify-content: center;
    margin-top: 20px;
}

.empty-card {
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(96, 108, 101, 0.2);
    border-radius: 20px;
    padding: 24px 16px;
    font-weight: 500;
}

.chat-composer {
    border-top: 1px solid var(--border-soft);
    background: #f9fbfa;
    padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
}

.composer-row {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    gap: 10px;
    align-items: center;
    background: #fff;
    border: 1px solid #d8e1db;
    border-radius: 999px;
    padding: 7px;
}

.composer-row input[type="text"] {
    border: 0;
    outline: none;
    min-width: 0;
    font-size: 1rem;
    padding: 8px 4px;
}

.send-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 0;
    background: linear-gradient(130deg, var(--brand), var(--brand-dark));
    color: #fff;
    font-size: 1.3rem;
    cursor: pointer;
}

.attach-status {
    margin-top: 8px;
    padding-left: 14px;
    color: #4d5e57;
    font-size: 0.88rem;
}

.profile-panel {
    position: absolute;
    left: 14px;
    top: 84px;
    width: 380px;
    max-width: calc(100vw - 20px);
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 15px;
    z-index: 80;
}

.profile-panel h3 {
    margin: 0 0 6px;
}

.profile-line {
    margin: 0;
    color: #5c6d66;
    font-size: 0.95rem;
}

.profile-avatar-wrap {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
}

.profile-avatar {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    border: 2px solid rgba(21, 135, 76, 0.25);
    background: linear-gradient(140deg, #82ab96, #2c7a4f);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.05rem;
    overflow: hidden;
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.profile-avatar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.profile-form {
    margin-top: 12px;
    display: grid;
    gap: 10px;
}

.profile-form-grid {
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr 1fr;
}

.profile-form .field {
    gap: 4px;
}

.profile-form .field label {
    font-size: 0.82rem;
}

.profile-form .input {
    padding: 9px 10px;
    font-size: 0.92rem;
}

.profile-save-btn {
    width: 100%;
    min-width: 0;
    padding: 10px 14px;
}

.profile-actions {
    margin-top: 12px;
    display: grid;
    gap: 8px;
}

.btn-danger {
    background: #fff;
    color: var(--danger);
    border: 1px solid rgba(186, 60, 60, 0.35);
    padding: 10px 15px;
}

.mobile-toggle {
    display: none;
}

@media (max-width: 1280px) {
    .chat-app {
        grid-template-columns: 340px 1fr;
    }

    .sidebar-title {
        font-size: 1.7rem;
    }

    .contact-name {
        font-size: 1.05rem;
    }

    .contact-preview {
        font-size: 0.92rem;
    }
}

@media (max-width: 1100px) {
    .app-body.sidebar-open {
        overflow: hidden;
    }

    .auth-shell {
        grid-template-columns: 1fr;
        padding: 20px;
    }

    .welcome-panel {
        min-height: 300px;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(390px, 90vw);
        z-index: 80;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: 12px 0 28px rgba(0, 0, 0, 0.18);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        display: block;
        z-index: 70;
        background: rgba(0, 0, 0, 0.32);
        backdrop-filter: blur(1px);
    }

    .mobile-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .chat-header {
        height: 70px;
        padding: 0 12px;
    }

    .message {
        max-width: 92%;
    }

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

    .profile-panel {
        position: fixed;
        top: 74px;
        right: 10px;
        left: 10px;
        width: auto;
        max-width: 460px;
        margin: 0 auto;
    }

    .profile-form-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .toast {
        right: 12px;
        left: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom));
        min-width: 0;
        max-width: none;
    }

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

    .welcome-panel {
        min-height: 220px;
        padding: 22px 18px;
    }

    .welcome-copy {
        font-size: 0.98rem;
        margin-bottom: 20px;
    }

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

    .form-grid.two {
        grid-template-columns: 1fr;
    }

    .auth-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .auth-actions .btn {
        width: 100%;
        min-width: 0;
    }

    .tab-switcher button {
        padding: 9px 8px;
        font-size: 0.92rem;
    }

    .sidebar {
        width: 100vw;
    }

    .sidebar-header {
        padding: 14px 12px 8px;
    }

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

    .filters {
        padding: 0 12px 10px;
        overflow-x: auto;
        scrollbar-width: thin;
    }

    .filter-pill {
        white-space: nowrap;
    }

    .chat-header-name {
        font-size: 1.02rem;
    }

    .chat-header-sub {
        font-size: 0.84rem;
        max-width: 56vw;
    }

    .chat-stage {
        padding: 12px 10px;
    }

    .empty-panel {
        padding: 14px;
    }

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

    .chat-composer {
        padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    }

    .composer-row {
        gap: 8px;
        grid-template-columns: auto auto 1fr auto;
        padding: 5px;
    }

    .icon-btn {
        width: 34px;
        height: 34px;
        border-radius: 10px;
        font-size: 0.82rem;
    }

    .send-btn {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    .composer-row input[type="text"] {
        font-size: 16px;
    }

    .message {
        max-width: 96%;
        border-radius: 10px;
        padding: 9px 10px 8px;
    }

    .message-text {
        font-size: 0.96rem;
    }
}

@media (max-width: 520px) {
    .brand-pill {
        margin-bottom: 10px;
    }

    .welcome-title {
        font-size: clamp(1.5rem, 7vw, 1.9rem);
    }

    .sidebar-title {
        font-size: 1.45rem;
    }

    .user-mini {
        display: none;
    }

    .chat-header {
        height: 64px;
    }

    .chat-header-sub {
        display: none;
    }

    .chat-header-left {
        gap: 8px;
    }

    .profile-avatar-wrap {
        grid-template-columns: 1fr;
        justify-items: center;
        text-align: center;
    }

    .profile-avatar-actions {
        justify-content: center;
    }

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

    .composer-row > .icon-btn:nth-child(2) {
        display: none;
    }

    .attach-status {
        font-size: 0.8rem;
        padding-left: 6px;
    }
}
