:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #242424;
    --bg-elevated: #2a2a2a;
    --accent-primary: #3b82f6;
    --accent-primary-hover: #2563eb;
    --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-tertiary: #71717a;
    --border-color: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
    --composer-h: 70px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Header */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
    backdrop-filter: blur(10px);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    height: 100%;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-logo {
    width: 36px;
    height: 36px;
    background: var(--accent-gradient);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.app-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

.app-subtitle {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

/* Main Chat Container */
.chat-container {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: var(--composer-h);
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

/* Channel Info */
.channel-info {
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 10;
    backdrop-filter: blur(10px);
}

.selected-channel-empty {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-tertiary);
}

.selected-channel-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.channel-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg-elevated);
}

.channel-details {
    flex: 1;
    min-width: 0;
}

.channel-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.channel-handle {
    font-size: 12px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.select-channel-btn {
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    flex-shrink: 0;
}

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

/* Chat Messages */
.chat-messages {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px 16px;
    min-height: calc(100% - 60px);
}

.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.welcome-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.welcome-message h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.welcome-message p {
    font-size: 14px;
    color: var(--text-tertiary);
}

.message {
    display: flex;
    margin-bottom: 16px;
    animation: messageSlide 0.3s ease-out;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

.message.user {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.user .message-bubble {
    background: var(--accent-gradient);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message.error .message-bubble {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Cards Container */
.cards-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 16px 20px;
}

.cards-header {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card {
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 12px;
    animation: cardSlide 0.4s ease-out;
}

@keyframes cardSlide {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.card-meta {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-bottom: 10px;
}

.card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 10px;
}

.tag {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 500;
}

.card-evidence {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 10px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-secondary);
    font-family: "Menlo", "Monaco", "Courier New", monospace;
    white-space: pre-wrap;
    overflow-x: auto;
}

/* Input Container */
.input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: auto;
    min-height: 70px;
    align-items: flex-end;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 100;
}

.input-container input {
    flex: 1;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 12px 18px;
    font-size: 15px;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s;
}

.input-container input:focus {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
}

.input-container input::placeholder {
    color: var(--text-tertiary);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.icon-btn:active {
    transform: scale(0.9);
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent-gradient);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

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

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Side Menu */
.side-menu {
    position: fixed;
    top: 0;
    right: -100%;
    width: min(320px, 85vw);
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    transition: right 0.3s ease-out;
    z-index: 200;
    display: flex;
    flex-direction: column;
}

.side-menu.open {
    right: 0;
}

.side-menu-header {
    height: 60px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}

.side-menu-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.side-menu-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.new-session-btn {
    width: 100%;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 16px;
    transition: all 0.2s;
}

.new-session-btn:active {
    transform: scale(0.98);
}

.session-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.session-item {
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.session-item:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
}

.session-item.active {
    border-color: var(--accent-primary);
    background: rgba(59, 130, 246, 0.1);
}

.session-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.session-time {
    font-size: 12px;
    color: var(--text-tertiary);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 20px;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal.open {
    display: flex;
}

.modal-content {
    width: min(500px, 100%);
    max-height: 90vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }

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

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.search-input-wrapper {
    position: relative;
    margin-bottom: 16px;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
}

.search-input-wrapper input {
    width: 100%;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 12px 12px 44px;
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s;
}

.search-input-wrapper input:focus {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
}

.search-results {
    min-height: 200px;
}

.search-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-tertiary);
    font-size: 14px;
}

.channel-result {
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    gap: 12px;
    align-items: center;
}

.channel-result:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.channel-result-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg-tertiary);
}

.channel-result-info {
    flex: 1;
    min-width: 0;
}

.channel-result-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.channel-result-handle {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-bottom: 4px;
}

.channel-result-url {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-footer {
    margin-top: 20px;
}

.footer-divider {
    height: 1px;
    background: var(--border-color);
    margin-bottom: 16px;
}

.footer-text {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-bottom: 12px;
    text-align: center;
}

.add-creator-btn {
    width: 100%;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    border-radius: 12px;
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

.add-creator-btn:hover {
    background: var(--bg-elevated);
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

/* Desktop Responsive */
@media (min-width: 768px) {
    .app-header {
        height: 70px;
    }

    .chat-container {
        top: 70px;
        bottom: 80px;
    }

    .input-container {
        height: 80px;
        padding: 16px 24px;
    }

    .input-container input {
        font-size: 16px;
    }

    .chat-messages,
    .cards-container {
        padding-left: 24px;
        padding-right: 24px;
    }

    .message-bubble {
        max-width: 65%;
    }
}

@media (min-width: 1024px) {
    .side-menu {
        width: 380px;
    }
}

/* Loading State */
.loading-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: bounce 1.4s infinite ease-in-out;
}

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

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

/* Session item with channel info */
.session-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.session-avatar {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    background: var(--bg-tertiary);
    object-fit: cover;
    flex-shrink: 0;
}

.session-info {
    flex: 1;
    min-width: 0;
}

.session-channel-line {
    display: flex;
    gap: 8px;
    align-items: baseline;
    min-width: 0;
}

.session-channel-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex: 1;
}

.session-channel-handle {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
    flex-shrink: 0;
}

.session-chat-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== Evidence Bottom Sheet (Mobile friendly) ===== */
.evidence-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.58);
    z-index: 350;
    display: none;
}

.evidence-backdrop.open {
    display: block;
}

/* 바텀시트: 모바일 친화 + 여백 최소화 */
.evidence-popover {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 400;

    /* iOS safe-area 고려 */
    padding-bottom: env(safe-area-inset-bottom);

    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -12px 28px rgba(0, 0, 0, 0.55);

    max-height: min(78vh, 640px);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    transform: translateY(110%);
    transition: transform 0.22s ease-out;

    max-height: min(70vh, 560px) !important;
}

.evidence-popover.open {
    transform: translateY(0);
}

/* 상단 드래그 핸들 느낌 (JS 수정 없이 CSS로) */
.evidence-popover::before {
    content: "";
    display: block;
    width: 44px;
    height: 5px;
    border-radius: 999px;
    margin: 10px auto 6px;
    background: rgba(255, 255, 255, 0.16);
}

/* 헤더는 작고 sticky하게 */
.evidence-header {
    position: sticky;
    top: 0;
    z-index: 2;

    display: flex;
    align-items: center;
    justify-content: space-between;

    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 8px 10px !important;
}

.evidence-title {
    font-size: 14px;
    font-weight: 800;
    letter-spacing: -0.2px;
    color: var(--text-primary);
}

.evidence-close {
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.evidence-close:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.evidence-body {
    padding: 8px 10px 10px !important;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* 비디오 블록: 카드형, 간격 촘촘 */
.evidence-video {
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    padding: 8px !important;
    margin-bottom: 8px !important;
    border-radius: 12px !important;
}

.evidence-video-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 4px !important;
}

.evidence-video-id {
    font-size: 11px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.evidence-open {
    font-size: 12px;
    color: #60a5fa;
    text-decoration: none;
    white-space: nowrap;
    font-weight: 700;
}

.evidence-open:hover {
    text-decoration: underline;
}

.evidence-card-title {
    font-size: 13px;
    font-weight: 800;
    color: var(--text-primary);
    margin: 4px 0 6px !important;
    letter-spacing: -0.2px;
}

/* quote 박스: 프리뷰처럼 더 촘촘하게 */
.evidence-quote {
    background: rgba(0, 0, 0, .26);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 12px;
    padding: 10px 10px !important;
    margin-top: 6px !important;

    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start !important;
    justify-content: flex-start !important;

    gap: 10px !important;

    /* ✅ 공간낭비/정렬깨짐 방지 */
    min-height: 0 !important;
    height: auto !important;
    text-align: left !important;

    font-size: 12.5px !important;
    line-height: 1.45 !important;

}

/* 타임스탬프 링크를 “칩”처럼 */
.evidence-quote a {
    flex: 0 0 auto !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;

    margin: 2px 0 0 0 !important;
    /* ✅ 텍스트 첫줄과 같은 기준선 */
    padding: 5px 10px !important;

    border-radius: 999px !important;
    white-space: nowrap !important;

    background: rgba(59, 130, 246, .14);
    border: 1px solid rgba(59, 130, 246, .22);
    color: #93c5fd;

    font-size: 11px !important;
    font-weight: 800;
    line-height: 1 !important;
    text-decoration: none;
}

/* ✅ a(타임칩) 외 나머지(대사)는 오른쪽 영역 꽉 채우기 */
.evidence-quote> :not(a) {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    text-align: left !important;
}

/* ✅ 내부 p/div 기본 margin 때문에 라인이 밀리는 것 방지 */
.evidence-quote> :not(a) * {
    margin: 0 !important;
    text-align: left !important;
}

.evidence-quote * {
    margin: 0 !important;
}

.evidence-quote a:hover {
    background: rgba(59, 130, 246, 0.2);
}

/* assistant bubble clickable + subtle hint (여백 최소) */
.message.assistant .message-bubble.evidence-clickable {
    cursor: pointer;
    position: relative;
}

.message.assistant .message-bubble.evidence-clickable::after {
    /* content: "근거"; */
    position: absolute;
    right: 10px;
    bottom: -16px;
    font-size: 10px;
    color: var(--text-tertiary);
    
}

.message.assistant .message-bubble.evidence-active {
    outline: 2px solid rgba(59, 130, 246, 0.55);
    outline-offset: 2px;
}

/* 기존 input 스타일 대신/추가 */
.input-container .message-input{
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 12px 18px;
  font-size: 15px;
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s;
  

  /* ✅ 멀티라인 핵심 */
  resize: none;          /* 사용자가 핸들로 늘리는거 막기(선택) */
  overflow: auto;      /* auto-resize 할 때 스크롤바 숨김 */
  line-height: 1.5;
  max-height: 140px;     /* 너무 커지는거 방지(원하면 조절) */
}

.input-container .message-input:focus{
  border-color: var(--accent-primary);
  background: var(--bg-tertiary);
}

.input-container .message-input::placeholder{
  color: var(--text-tertiary);
}


#messageInput{
  scrollbar-width: none;      /* Firefox */
  -ms-overflow-style: none;   /* IE/Edge(legacy) */
}

.chat-container{
      scrollbar-width: none;      /* Firefox */
  -ms-overflow-style: none;   /* IE/Edge(legacy) */
}
#messageInput::-webkit-scrollbar{
  display: none;              /* Chrome/Safari */
}

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

/* 데스크탑에서는 가운데 떠 있는 모달 느낌으로 */
@media (min-width: 768px) {
    .evidence-popover {
        left: 50%;
        right: auto;
        width: min(560px, 92vw);
        transform: translate(-50%, 110%);
        border-radius: 18px;
        bottom: 16px;
        max-height: 75vh;
        border: 1px solid var(--border-color);
    }

    .evidence-popover.open {
        transform: translate(-50%, 0);
    }
}


@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}