:root {
    --bg: #ededed;
    --panel: #f7f7f7;
    --text: #111;
    --muted: rgba(0, 0, 0, 0.55);
    --border: rgba(0, 0, 0, 0.08);
    --bot-bubble: #ffffff;
    --user-bubble: #95ec69;
    --avatar-bot: #4f93ff;
    --avatar-user: #26c281;
    --shadow: 0 6px 18px rgba(0,0,0,0.06);
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.hidden {
    display: none !important;
}

.app {
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding-top: env(safe-area-inset-top);
    background: rgba(247,247,247,0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.topbar__title {
    height: 52px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.topbar__name {
    font-size: 16px;
    font-weight: 600;
}

.topbar__sub {
    font-size: 12px;
    color: var(--muted);
}

.chat {
    flex: 1;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}

.chat::-webkit-scrollbar {
    display: none; /* Chrome, Safari */
}

.chat__list {
    list-style: none;
    padding: 12px 12px calc(12px + 92px + env(safe-area-inset-bottom));
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.msg {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.msg--user {
    flex-direction: row-reverse;
}

.msg__avatar {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    flex: 0 0 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    box-shadow: var(--shadow);
}

.msg--bot .msg__avatar {
    background: var(--avatar-bot);
}

.msg--user .msg__avatar {
    background: var(--avatar-user);
}

.msg__content {
    min-width: 0;
    max-width: min(78%, 520px);
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-start; /* Default align left for bot */
}

.msg--user .msg__content {
    align-items: flex-end; /* Align right for user */
}

.bubble {
    position: relative;
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 15px;
    line-height: 1.5;
    white-space: pre-wrap;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.bubble--bot {
    background: var(--bot-bubble);
    color: var(--text);
    border: 1px solid var(--border);
}

.bubble--user {
    background: var(--user-bubble);
    color: #000;
}

.bubble--bot::before {
    content: "";
    position: absolute;
    left: -6px;
    top: 12px;
    width: 10px;
    height: 10px;
    background: var(--bot-bubble);
    border-left: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    transform: rotate(45deg);
}

.bubble--user::before {
    content: "";
    position: absolute;
    right: -6px;
    top: 12px;
    width: 10px;
    height: 10px;
    background: var(--user-bubble);
    transform: rotate(45deg);
}

.bubble a {
    color: #1b6dd8;
    text-decoration: underline;
    overflow-wrap: anywhere;
    word-break: break-all;
}

.chat-image {
    max-width: 100%;
    border-radius: 10px;
    display: block;
    margin: 6px 0 0;
}

.composer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
    background: rgba(247,247,247,0.96);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--border);
}

.composer__preview {
    position: relative;
    width: 112px;
    margin: 0 0 10px 2px;
}

.composer__preview-img {
    width: 112px;
    height: 112px;
    object-fit: cover;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
}

.composer__preview-remove {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.7);
    color: #fff;
    font-size: 18px;
    line-height: 24px;
    padding: 0;
}

.composer__preview-mask {
    position: absolute;
    inset: 0;
    border-radius: 12px;
    background: rgba(0,0,0,0.45);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.composer__spinner {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.5);
    border-top-color: #fff;
    animation: spin 0.9s linear infinite;
}

.composer__preview-text {
    color: #fff;
    font-size: 12px;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.composer__row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.composer__btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow);
    user-select: none;
}

.composer__btn:active {
    background-color: #f0f0f0;
}

.composer__btn-icon {
    font-size: 22px;
    line-height: 1;
    color: rgba(0,0,0,0.75);
}

.composer__input {
    flex: 1;
    min-width: 0;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: #fff;
    padding: 10px 12px;
    font-size: 15px;
    line-height: 1.4;
    resize: none;
    outline: none;
    max-height: 120px;
}

.composer__send {
    height: 40px;
    padding: 0 14px;
    border-radius: 12px;
    border: none;
    background: #07c160;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    box-shadow: var(--shadow);
}

.composer__send:active {
    background: #06ad56;
}

.composer__send:disabled {
    background: rgba(7,193,96,0.35);
}

.composer__status {
    height: 18px;
    margin-top: 6px;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
