:root {
    --purice-blue: #0f4c81;
    --purice-blue-2: #1e88e5;
    --purice-green: #1fa67a;
    --purice-bg: #f7fbff;
    --purice-panel: rgba(255, 255, 255, 0.9);
    --purice-text: #102033;
    --purice-muted: #64748b;
    --purice-border: rgba(15, 76, 129, 0.16);
    --purice-user: #d8ecff;
    --purice-bot: rgba(255, 255, 255, 0.96);
}

body.purice-dark {
    --purice-bg: #071624;
    --purice-panel: rgba(10, 30, 48, 0.92);
    --purice-text: #e7f3ff;
    --purice-muted: #aac1d6;
    --purice-border: rgba(160, 205, 255, 0.18);
    --purice-user: #0f4c81;
    --purice-bot: rgba(18, 43, 66, 0.96);
    background: #071624;
}

body {
    background:
        radial-gradient(circle at top left, rgba(30, 136, 229, 0.12), transparent 32%),
        var(--purice-bg);
    min-height: 100dvh;
    overflow: hidden;
}

body.purice-dark {
    background:
        radial-gradient(circle at top left, rgba(30, 136, 229, 0.12), transparent 32%),
        var(--purice-bg);
}

.purice-shell {
    width: min(1180px, 94vw);
    height: 100dvh;
    margin: 0 auto;
    padding: 12px 0;
    display: grid;
}

.purice-chat {
    position: relative;
    height: 100%;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    overflow: hidden;
    border: 1px solid var(--purice-border);
    border-radius: 18px;
    background: var(--purice-panel);
    box-shadow: 0 20px 60px rgba(7, 55, 99, 0.14);
    backdrop-filter: blur(18px);
}

.purice-chat::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    background:
        radial-gradient(circle at top left, rgba(30, 136, 229, 0.08), transparent 36%),
        linear-gradient(180deg, rgba(247, 251, 255, 0.9), rgba(238, 248, 255, 0.82));
    pointer-events: none;
}

body.purice-dark .purice-chat::before {
    background:
        radial-gradient(circle at top left, rgba(30, 136, 229, 0.16), transparent 36%),
        linear-gradient(180deg, rgba(7, 22, 36, 0.92), rgba(10, 30, 48, 0.96));
}

.purice-chat > * {
    position: relative;
    z-index: 1;
}

.purice-chat-head {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    background: linear-gradient(115deg, var(--purice-blue), var(--purice-blue-2));
    color: #fff;
}

body.purice-dark .purice-chat-head {
    background: linear-gradient(115deg, var(--purice-blue), var(--purice-blue-2));
}

.purice-avatar {
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: #ffffff;
    color: #ffffff;
    font-weight: 850;
    border: 3px solid rgba(255, 255, 255, 0.86);
    box-shadow: 0 10px 24px rgba(2, 28, 70, 0.26), 0 0 0 3px rgba(32, 199, 216, 0.22);
    overflow: hidden;
}

.purice-avatar {
    width: 58px;
    height: 58px;
    font-size: 22px;
}

.purice-avatar img {
    width: 112%;
    height: 112%;
    display: block;
    object-fit: cover;
    object-position: center 32%;
}

.purice-chat-head h2,
.purice-chat-head p {
    margin: 0;
}

.purice-brand {
    min-width: 0;
}

.purice-chat-head h2 {
    color: #06255e;
    font-size: clamp(1.22rem, 2.1vw, 1.65rem);
    font-weight: 900;
    letter-spacing: 0;
    line-height: 1;
    white-space: nowrap;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.18);
}

.purice-chat-head h2 span {
    display: inline-grid;
    place-items: center;
    min-width: 1.82em;
    min-height: 1.34em;
    margin-left: 4px;
    padding: 0 0.22em;
    border-radius: 0.32em;
    background: linear-gradient(135deg, #17c7dc, #0875b9);
    color: #ffffff;
    font-weight: 950;
}

.purice-chat-head p {
    color: #32d583;
    opacity: 1;
    font-size: 13px;
    font-weight: 750;
}

.purice-tools {
    display: flex;
    align-items: center;
    gap: 8px;
}

.purice-tools button {
    min-height: 34px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
}

.purice-tools button {
    padding: 0 12px;
    cursor: pointer;
}

.purice-messages {
    min-height: 0;
    overflow-y: auto;
    padding: 20px;
    display: grid;
    align-content: start;
    gap: 12px;
    color: var(--purice-text);
    background: transparent;
}

.purice-message-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: min(86%, 780px);
    animation: purice-pop 0.2s ease both;
    transition: transform 0.18s ease, opacity 0.18s ease;
}

.purice-message-row.user {
    justify-self: end;
    flex-direction: row-reverse;
}

.purice-message-row.hidden {
    display: none;
}

.purice-message {
    padding: 9px 11px;
    border-radius: 14px;
    line-height: 1.42;
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--purice-text);
    box-shadow: 0 4px 16px rgba(7, 55, 99, 0.08);
}

.purice-message.bot {
    background: var(--purice-bot);
    border-bottom-left-radius: 6px;
    border: 1px solid var(--purice-border);
}

.purice-message.user {
    background: var(--purice-user);
    border-bottom-right-radius: 6px;
}

body.purice-dark .purice-tools button,
body.purice-dark .purice-upload,
body.purice-dark .purice-action {
    background: var(--purice-blue);
    border-color: rgba(160, 205, 255, 0.18);
}

body.purice-dark .purice-upload {
    color: #ffffff;
}

.purice-message time {
    display: block;
    margin-top: 6px;
    color: var(--purice-muted);
    font-size: 11px;
    text-align: right;
}

.purice-attachment {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-top: 6px;
    padding: 7px 9px;
    border-radius: 10px;
    background: rgba(15, 76, 129, 0.08);
    color: var(--purice-text);
    font-size: 12px;
    font-weight: 700;
}

.purice-typing {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 18px;
    color: var(--purice-muted);
    background: rgba(255, 255, 255, 0.72);
}

body.purice-dark .purice-typing {
    background: rgba(10, 30, 48, 0.9);
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: var(--purice-blue-2);
    animation: purice-typing 900ms ease-in-out infinite;
}

.typing-dot:nth-child(3) {
    animation-delay: 120ms;
}

.typing-dot:nth-child(4) {
    animation-delay: 240ms;
}

.purice-suggestions {
    border-top: 1px solid var(--purice-border);
}

.purice-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.76);
}

body.purice-dark .purice-suggestions {
    background: rgba(10, 30, 48, 0.9);
}

.purice-suggestions button {
    border: 1px solid rgba(30, 136, 229, 0.24);
    border-radius: 999px;
    padding: 7px 10px;
    background: rgba(255, 255, 255, 0.86);
    color: var(--purice-blue);
    cursor: pointer;
    font-weight: 700;
    font-size: 12px;
    transition: transform 160ms ease, background 160ms ease;
}

.purice-suggestions button:hover {
    transform: translateY(-1px);
    background: #eef7ff;
}

body.purice-dark .purice-suggestions button {
    background: rgba(255, 255, 255, 0.08);
    color: #e7f3ff;
}

.purice-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 14px max(14px, env(safe-area-inset-bottom));
    background: rgba(244, 249, 252, 0.94);
    border-top: 0;
}

body.purice-dark .purice-form {
    background: rgba(7, 22, 36, 0.96);
}

.purice-input-wrap {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    height: 50px;
    min-height: 50px;
    border: 0;
    border-radius: 9999px;
    padding: 3px 12px 3px 8px;
    background: #ffffff;
    background-clip: padding-box;
    box-shadow: inset 0 0 0 1px rgba(15, 76, 129, 0.08);
    overflow: hidden;
    clip-path: inset(0 round 9999px);
}

.purice-form textarea {
    width: 100%;
    height: 44px;
    min-width: 0;
    border: 0;
    border-radius: 0;
    resize: none;
    padding: 12px 8px 12px 10px;
    font: inherit;
    background: transparent;
    color: #102033;
    outline: none;
    line-height: 1.35;
    max-height: 120px;
    overflow-y: auto;
}

.purice-upload,
.purice-action {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border: 0;
    border-radius: 999px;
    background: var(--purice-blue);
    color: #fff;
    font: inherit;
    font-weight: 750;
    cursor: pointer;
}

.purice-upload {
    width: 34px;
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    flex: 0 0 34px;
    background: rgba(15, 76, 129, 0.10);
    color: var(--purice-blue);
    font-size: 22px;
}

.purice-action svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.purice-action .icon-send {
    display: none;
}

.purice-action.has-text .icon-mic {
    display: none;
}

.purice-action.has-text .icon-send {
    display: block;
}

.purice-action.listening {
    background: #d92d20;
}

.hidden {
    display: none !important;
}

@keyframes purice-pop {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes purice-typing {
    0%,
    100% {
        transform: translateY(0);
        opacity: 0.45;
    }
    50% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

@media (max-width: 860px) {
    body {
        min-height: 100svh;
    }

    .purice-shell {
        width: 100%;
        height: 100svh;
        padding: 0;
    }

    .purice-chat {
        grid-template-rows: auto minmax(0, 1fr) auto auto auto;
        height: 100svh;
    }

    .purice-chat {
        border-radius: 0;
        border-left: 0;
        border-right: 0;
    }

    .purice-chat-head {
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 9px;
        padding: 9px 9px;
        align-items: center;
    }

    .purice-avatar {
        width: 54px;
        height: 54px;
        font-size: 19px;
        border-width: 3px;
    }

    .purice-chat-head h2 {
        font-size: 19px;
        font-weight: 900;
    }

    .purice-chat-head p {
        font-size: 10.5px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .purice-tools {
        grid-column: 3;
        justify-self: end;
        width: auto;
        overflow-x: auto;
        padding: 2px 0 1px;
        scrollbar-width: none;
        justify-content: flex-end;
    }

    .purice-tools::-webkit-scrollbar,
    .purice-suggestions::-webkit-scrollbar {
        display: none;
    }

    .purice-tools button {
        flex: 0 0 auto;
        min-height: 30px;
        padding: 0 9px;
        font-size: 10.5px;
    }

    .purice-messages {
        padding: 12px 10px;
        gap: 10px;
    }

    .purice-message-row {
        max-width: 96%;
    }

    .purice-message {
        max-width: 100%;
        padding: 8px 9px;
        font-size: 0.84rem;
        line-height: 1.36;
    }

    .purice-suggestions {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 8px 9px;
        scrollbar-width: none;
    }

    .purice-suggestions button {
        flex: 0 0 auto;
        font-size: 11px;
        padding: 7px 9px;
    }

    .purice-form {
        gap: 7px;
        padding: 8px 8px calc(18px + env(safe-area-inset-bottom));
        align-items: center;
    }

    body.keyboard-active .purice-form {
        padding-bottom: calc(28px + env(safe-area-inset-bottom));
    }

    .purice-action {
        width: 48px;
        height: 48px;
        flex-basis: 48px;
        align-self: center;
        margin-bottom: 0;
    }

    .purice-upload {
        width: 34px;
        height: 34px;
        min-width: 34px;
        min-height: 34px;
        flex-basis: 34px;
    }

    .purice-upload {
        font-size: 20px;
    }

    .purice-input-wrap {
        height: 48px;
        min-height: 48px;
        padding: 3px 10px 3px 7px;
        border-radius: 9999px;
        clip-path: inset(0 round 9999px);
    }

    .purice-form textarea {
        height: 42px;
        min-width: 0;
        padding: 11px 7px 11px 9px;
        font-size: 13px;
        border-radius: 0;
        background: transparent;
    }
}

@media (max-width: 420px) {
    .purice-chat-head {
        grid-template-columns: auto minmax(76px, 1fr) auto;
    }

    .purice-avatar {
        width: 50px;
        height: 50px;
    }

    .purice-chat-head h2 {
        font-size: 17px;
    }

    .purice-chat-head h2 span {
        min-width: 1.72em;
        margin-left: 3px;
        padding: 0 0.18em;
    }

    .purice-action {
        width: 46px;
        height: 46px;
        flex-basis: 46px;
    }

    .purice-upload {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
        flex-basis: 32px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .purice-message-row,
    .typing-dot,
    .purice-suggestions button {
        animation: none;
        transition: none;
    }
}
