:root {
    --primary-red: #ff3366;
    --primary-red-hover: #ff1a53;
    --soft-pink: #ffe6ea;
    --bg-pink: #fff5f8;
    --leaf-green: #4caf50;
    --leaf-green-light: #e8f5e9;
    --text-dark: #2d3748;
    --text-gray: #718096;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
    --shadow: 0 8px 32px 0 rgba(255, 51, 102, 0.15);
    --msg-bg-ai: white;
    --input-bg: white;
    --header-bg: rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] {
    --bg-pink: #1a0b12;
    --text-dark: #f7fafc;
    --text-gray: #a0aec0;
    --glass-bg: rgba(30, 20, 25, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.5);
    --msg-bg-ai: #2d1b24;
    --input-bg: #2d1b24;
    --header-bg: rgba(20, 10, 15, 0.4);
    --soft-pink: #3d1a25;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-pink);
    color: var(--text-dark);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    position: relative;
}

/* Dynamic Background Blobs */
.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    z-index: -1;
    opacity: 0.6;
    animation: float 20s infinite ease-in-out alternate;
}

.blob-1 {
    width: 400px;
    height: 400px;
    background: linear-gradient(135deg, #ff9a9e 0%, #fecfef 99%, #fecfef 100%);
    top: -100px;
    left: -100px;
}

.blob-2 {
    width: 300px;
    height: 300px;
    background: linear-gradient(120deg, #f093fb 0%, #f5576c 100%);
    bottom: -50px;
    right: -50px;
    animation-delay: -5s;
}

.blob-3 {
    width: 250px;
    height: 250px;
    background: linear-gradient(to top, #4facfe 0%, #00f2fe 100%);
    opacity: 0.2;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -10s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(30px, -50px) scale(1.1); }
    100% { transform: translate(-20px, 20px) scale(0.9); }
}

.app-container {
    width: 100%;
    max-width: 480px;
    height: 90vh;
    max-height: 850px;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

/* Glassmorphism Panel */
.chat-glass-panel {
    flex: 1;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 30px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 10;
}

/* Header */
.chat-header {
    padding: 24px 24px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    background: var(--header-bg);
}

.ai-profile {
    display: flex;
    align-items: center;
    gap: 16px;
}

.avatar-container {
    position: relative;
    width: 50px;
    height: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.avatar-glow {
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(45deg, var(--primary-red), #ff9a8b);
    border-radius: 50%;
    filter: blur(8px);
    opacity: 0.7;
    animation: pulse 2s infinite alternate;
}

@keyframes pulse {
    0% { transform: scale(0.95); opacity: 0.5; }
    100% { transform: scale(1.1); opacity: 0.8; }
}

.avatar-emoji {
    position: relative;
    font-size: 32px;
    z-index: 2;
    background: var(--msg-bg-ai);
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    user-select: none;
}

.ai-info h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-red);
    margin-bottom: 2px;
}

.status {
    font-size: 0.8rem;
    color: var(--text-gray);
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.status-dot {
    width: 8px;
    height: 8px;
    background-color: var(--leaf-green);
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 8px var(--leaf-green);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-gray);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.icon-btn:hover {
    background: var(--soft-pink);
    color: var(--primary-red);
}

/* Chat Messages Area */
.chat-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 51, 102, 0.2);
    border-radius: 10px;
}

.message {
    max-width: 85%;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    opacity: 0;
    transform: translateY(20px);
}

@keyframes popIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-content {
    padding: 14px 18px;
    border-radius: 20px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
}

.ai-message {
    align-self: flex-start;
}

.ai-message .message-content {
    background: var(--msg-bg-ai);
    color: var(--text-dark);
    border-bottom-left-radius: 4px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.03);
    border: 1px solid rgba(255, 51, 102, 0.1);
}

.user-message {
    align-self: flex-end;
}

.user-message .message-content {
    background: linear-gradient(135deg, var(--primary-red), #ff6b8b);
    color: white;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 15px rgba(255, 51, 102, 0.2);
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-gray);
    margin-top: 6px;
    margin-left: 4px;
    margin-right: 4px;
}

.user-message .message-time {
    text-align: right;
}

/* Typing Indicator */
.typing-indicator {
    padding: 0 24px 10px;
    display: flex;
    gap: 4px;
    align-self: flex-start;
    align-items: center;
    height: 24px;
}

.dot {
    width: 6px;
    height: 6px;
    background-color: var(--primary-red);
    border-radius: 50%;
    opacity: 0.6;
    animation: bounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Input Area */
.chat-input-area {
    padding: 16px 24px 24px;
    background: rgba(255, 255, 255, 0.3);
    border-top: 1px solid rgba(255, 255, 255, 0.5);
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border-radius: 24px;
    padding: 6px 6px 6px 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    border: 1px solid rgba(255, 51, 102, 0.1);
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

.input-wrapper:focus-within {
    box-shadow: 0 4px 15px rgba(255, 51, 102, 0.15);
    border-color: var(--primary-red);
}

#user-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 10px;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-dark);
    background: transparent;
}

#user-input::placeholder {
    color: #a0aec0;
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-red);
    color: white;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.send-btn:hover {
    background: var(--primary-red-hover);
    transform: scale(1.05);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn svg {
    margin-left: -2px;
    margin-top: 2px;
}

#char-count {
    font-size: 0.72rem;
    font-weight: 600;
    color: #a0aec0;
    min-width: 22px;
    text-align: center;
    transition: color 0.2s ease;
    user-select: none;
}

#char-count.warning {
    color: #f59e0b;
}

#char-count.danger {
    color: var(--primary-red);
}

/* ===== Quota Modal ===== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.modal-box {
    background: var(--msg-bg-ai);
    border-radius: 28px;
    padding: 40px 36px;
    max-width: 320px;
    width: 90%;
    text-align: center;
    box-shadow: var(--shadow);
    animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.modal-icon {
    font-size: 3.5rem;
    margin-bottom: 12px;
    animation: wiggle 0.6s ease 0.3s both;
}

@keyframes wiggle {
    0%,100% { transform: rotate(0deg); }
    25%      { transform: rotate(-12deg); }
    75%      { transform: rotate(12deg); }
}

.modal-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary-red);
    margin-bottom: 12px;
}

.modal-desc {
    font-size: 0.95rem;
    color: var(--text-dark);
    line-height: 1.6;
    margin-bottom: 10px;
}

.modal-sub {
    font-size: 0.8rem;
    color: var(--text-gray);
    line-height: 1.5;
    margin-bottom: 28px;
}

.modal-btn {
    background: linear-gradient(135deg, var(--primary-red), #ff6b8b);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 12px 32px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 15px rgba(255, 51, 102, 0.3);
}

.modal-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 51, 102, 0.4);
}

.modal-btn:active {
    transform: translateY(0);
}

.modal-detail-error {
    font-size: 0.7rem;
    color: var(--text-gray);
    margin-bottom: 20px;
    word-break: break-all;
    background: var(--header-bg);
    padding: 8px;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    max-height: 60px;
    overflow-y: auto;
}
