/* ========================================
   Chat Input - Fixed Overlay System
   입력창을 화면 하단에 고정하고 메시지와 충돌 방지

   핵심 원칙:
   1. z-index는 Design Tokens 사용
   2. !important 사용 금지 (Specificity로 해결)
   3. 패딩은 JavaScript 동적 계산
   ======================================== */

/* ========== 입력창 컨테이너 - 최상위 고정 레이어 ========== */
.syncleai-page .chat-input-section {
    /* 위치: 화면 하단 고정 */
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;

    /* z-index: Design Tokens 사용 */
    z-index: var(--syncleai-z-input);

    /* 배경: 투명 (내부 컨테이너에서 관리) */
    background: transparent;

    /* 패딩 */
    padding: var(--space-10) var(--space-5) var(--space-5) var(--space-5);
    padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom));

    /* GPU 가속 */
    transform: translate3d(0, 0, 0);
    will-change: transform;

    /* 독립 stacking context */
    isolation: isolate;

    /* 배경은 클릭 방지 */
    pointer-events: none;
    box-sizing: border-box;
    width: 100%;
}

/* ========== 데스크톱: 사이드바 너비만큼 조정 ========== */
@media (min-width: 1025px) {
    .syncleai-page .chat-input-section {
        left: 240px; /* 왼쪽 사이드바 */
        right: var(--syncleai-sidebar-width); /* 오른쪽 사이드바 */
        padding-left: 60px;
        padding-right: 60px;
        width: calc(100vw - 240px - var(--syncleai-sidebar-width));
    }

    .syncleai-page .chat-input-container {
        max-width: 800px;
        margin-left: auto;
        margin-right: auto;
    }
}

/* ========== 태블릿: 전체 너비 ========== */
@media (max-width: 1024px) {
    .syncleai-page .chat-input-section {
        left: 0;
        right: 0;
        padding: var(--space-10) var(--space-4) var(--space-4) var(--space-4);
        padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
    }
}

/* ========== 모바일: 전체 너비 + 키보드 대응 ========== */
@media (max-width: 767px) {
    .syncleai-page .chat-input-section {
        left: 0;
        right: 0;
        padding: var(--space-10) var(--space-4) var(--space-4) var(--space-4);
        padding-bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
    }
}

/* ========== 입력창 내부 컨테이너 ========== */
.syncleai-page .chat-input-container {
    max-width: 720px;
    margin: 0 auto;
    background: var(--color-bg-primary);
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    padding: var(--space-3) var(--space-3) var(--space-3) var(--space-6);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    position: relative;
    z-index: 1;
    pointer-events: auto; /* 입력창만 클릭 가능 */
    backdrop-filter: blur(10px);
    transition: border-color var(--transition-fast);
}

.syncleai-page .chat-input-container:focus-within {
    border-color: #000000;
}

/* ========== 입력창 (Textarea) ========== */
.syncleai-page .chat-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--color-text-primary);
    background: transparent;
    min-height: 24px;
    max-height: 200px;
    overflow-y: auto;
    padding: 0;
}

.syncleai-page .chat-input::placeholder {
    color: var(--color-text-muted);
}

.syncleai-page .chat-input:focus {
    outline: none;
}

/* ========== 전송 버튼 (chat.html 스타일) ========== */
.syncleai-page .send-button {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    flex-shrink: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #cccccc;
    border: none;
    color: #000000;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 14px;
}

.syncleai-page .send-button:hover:not(:disabled) {
    background: #e0e0e0;
}

.syncleai-page .send-button:active:not(:disabled) {
    background: #cccccc;
}

.syncleai-page .send-button:disabled {
    background: #5e5e5e;
    color: #999999;
    cursor: not-allowed;
    transform: scale(1);
}

.syncleai-page .send-button i {
    font-size: 14px;
}

/* ========== 메시지 컨테이너 - 동적 패딩 (JavaScript 제어) ========== */
/* padding-bottom은 chat-layout.css에서 정의되고 JavaScript가 동적으로 덮어씀 */

/* ========== 스크롤 시 메시지가 입력창에 가려지지 않도록 ========== */
.syncleai-page .chat-messages {
    scroll-padding-bottom: 160px; /* JavaScript 동적 계산과 일치 */
}

/* ========== 메시지 wrapper z-index (입력창보다 낮게) ========== */
.syncleai-page .message-wrapper {
    position: relative;
    z-index: var(--syncleai-z-message); /* 입력창(300)보다 낮음(10) */
}

/* ========== 웰컴 화면 z-index (메시지보다 낮게) ========== */
.syncleai-page .welcome-screen {
    z-index: var(--syncleai-z-welcome); /* 메시지(10)보다 낮음(5) */
}

/* ========== 반응형: 모바일 ========== */
@media (max-width: 767px) {
    .syncleai-page .chat-input-container {
        padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
    }

    .syncleai-page .chat-input {
        font-size: 14px;
    }

    .syncleai-page .send-button {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }

    .syncleai-page .send-button i {
        font-size: 12px;
    }
}
