/* Chat page: phone-like layout */
body.chat-page {
    padding: 0;
    height: var(--app-height, 100dvh);
    overflow: hidden;
}

body.chat-page .container {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    height: var(--app-height, 100dvh);
    padding: 0;
    overflow: hidden;
    display: flex;
    justify-content: center;
    z-index: 1;
}

body.chat-page .page-container {
    max-width: 480px;
    width: 100%;
    padding: 16px;
    height: 100%;
    display: flex;
    flex-direction: column;
}

body.chat-page .page-header {
    margin-bottom: 12px;
}

.chat-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    background: #b2c7d9;
    border-radius: 20px;
    overflow: hidden;
}

.character-selection {
    margin-bottom: 0;
    padding: 10px 12px;
    background: #ffffff;
    border-bottom: 2px solid #e0e0e0;
}

.character-selection label {
    display: block;
    margin-bottom: 15px;
    font-size: 1em;
    font-weight: 600;
    color: var(--secondary-color);
}

.character-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.char-btn {
    padding: 8px 16px;
    background: #f5f5f5;
    border: 2px solid #e0e0e0;
    border-radius: 20px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9em;
    font-weight: 500;
}

.char-btn:hover {
    background: #e8e8e8;
    transform: scale(1.05);
}

.char-btn.active {
    background: var(--kakao-yellow);
    border-color: var(--primary-dark);
    color: var(--secondary-color);
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(254, 229, 0, 0.4);
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px;
    padding-bottom: 20px;
    background: #b2c7d9;
    background-image: 
        repeating-linear-gradient(0deg, transparent, transparent 35px, rgba(255,255,255,.03) 35px, rgba(255,255,255,.03) 36px);
}

.message {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    animation: slideIn 0.3s ease;
    align-items: flex-end;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-icon {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.message-icon .avatar {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.user-message .message-icon {
    background: linear-gradient(135deg, #667eea, #764ba2);
    order: 2;
}

.message-content {
    max-width: 60%;
    padding: 12px 16px;
    border-radius: 18px;
    line-height: 1.5;
    font-size: 0.95em;
    position: relative;
    word-wrap: break-word;
}

.user-message {
    flex-direction: row-reverse;
}

.user-message .message-content {
    background: var(--message-sent);
    color: var(--secondary-color);
    border-top-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.ai-message .message-content {
    background: var(--message-received);
    color: var(--text-primary);
    border-top-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.error-message .message-content {
    background: #ffe0e0;
    color: #d32f2f;
    border: 1px solid #ffcdd2;
}

.system-message {
    text-align: center;
    padding: 8px 16px;
    color: #666;
    font-style: normal;
    font-size: 0.85em;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    margin: 12px auto;
    max-width: 80%;
    backdrop-filter: blur(10px);
}

.chat-input-container {
    display: flex;
    gap: 10px;
    padding: 15px 20px;
    background: #ffffff;
    border-top: 1px solid #e0e0e0;
}

body.chat-page .chat-input-container {
    padding-bottom: calc(15px + env(safe-area-inset-bottom));
}

/* Hide bottom options (clear button duplicated in character menu) */
body.chat-page .chat-options {
    display: none;
}

/* Keep rounded bottom corners when options are hidden */
body.chat-page .chat-input-container {
    border-radius: 0 0 20px 20px;
}

.chat-input-container textarea {
    flex: 1;
    resize: none;
    border: 1px solid #e0e0e0;
    background: #f5f5f5;
    color: var(--text-primary);
    border-radius: 20px;
    padding: 12px 18px;
    font-size: 0.95em;
    font-family: inherit;
}

/* Compact input height for chat page */
body.chat-page .chat-input-container textarea {
    padding: 9px 14px;
    font-size: 0.92em;
    line-height: 1.35;
}

.chat-input-container textarea:focus {
    outline: none;
    border-color: var(--primary-dark);
    background: #ffffff;
}

.btn-send {
    padding: 12px 24px;
    background: var(--kakao-yellow);
    border: none;
    border-radius: 20px;
    color: var(--secondary-color);
    font-size: 1em;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 80px;
}

body.chat-page .btn-send {
    padding: 9px 14px;
    min-width: 60px;
}

.btn-send:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(254, 229, 0, 0.4);
}

.btn-send:active {
    transform: translateY(0);
}

.btn-send:disabled {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.chat-options {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: #ffffff;
    border-radius: 0 0 20px 20px;
}

/* Hide model selector UI (keep functionality) */
body.chat-page .model-selector {
    display: none;
}

body.chat-page .chat-options {
    justify-content: flex-end;
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.model-selector label {
    font-size: 0.9em;
    color: var(--text-secondary);
    font-weight: 500;
}

.model-selector select {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    background: #f5f5f5;
    color: var(--text-primary);
    font-size: 0.9em;
    cursor: pointer;
}

.btn-refresh {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    background: #f5f5f5;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-refresh:hover {
    background: #e8e8e8;
    transform: translateY(-1px);
}

/* Mobile tweaks */
@media (max-width: 600px) {
    body.chat-page {
        overflow: hidden;
    }

    body.chat-page .container {
        padding: 0;
    }

    body.chat-page .page-container {
        border-radius: 0;
        padding: 12px;
        height: 100%;
    }

    body.chat-page .page-header h1 {
        font-size: 1.6em;
    }

    .chat-container {
        border-radius: 16px;
    }

    .character-selection {
        padding: 10px 12px;
    }

    .character-buttons {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-top: 10px;
        -webkit-overflow-scrolling: touch;
    }

    .char-btn {
        padding: 7px 12px;
        font-size: 0.85em;
        white-space: nowrap;
        flex: 0 0 auto;
    }

    .chat-input-container {
        padding: 10px 12px;
    }

    body.chat-page .chat-input-container textarea {
        padding: 8px 12px;
        font-size: 0.9em;
    }

    body.chat-page .chat-input-container {
        border-radius: 0 0 16px 16px;
    }

    .btn-send {
        padding: 10px 14px;
        min-width: 64px;
    }

    body.chat-page .btn-send {
        padding: 8px 12px;
        min-width: 56px;
    }

    .chat-options {
        padding: 8px 12px;
    }

    .chat-messages {
        padding: 14px;
    }

    .message-content {
        max-width: 78%;
    }

    .chat-options {
        gap: 10px;
        flex-wrap: wrap;
    }
}

.btn-install {
    padding: 8px 16px;
    background: #51cf66;
    border-radius: 8px;
    color: white;
    text-decoration: none;
    font-size: 0.85em;
    font-weight: 600;
    transition: all 0.2s ease;
    display: inline-block;
}

.btn-install:hover {
    background: #40c057;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(81, 207, 102, 0.3);
}

.btn-clear {
    padding: 8px 16px;
    background: #ff6b6b;
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-clear:hover {
    background: #fa5252;
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(255, 107, 107, 0.3);
}
