/* ============================
   CHAT PAGE - Full Screen Chat
   ============================ */

/* --- CSS Variables (Dark Mode - Default) --- */
:root {
    --primary: #c9a84c;
    --primary-dark: #a88a3a;
    --primary-light: #e8d59a;
    --bg-dark: #0a0a0f;
    --bg-card: #12121a;
    --bg-card-hover: #1a1a28;
    --bg-section: #0e0e16;
    --text-primary: #f0ece2;
    --text-secondary: #9a9ab0;
    --text-muted: #5a5a72;
    --border: #1e1e30;
    --gradient-gold: linear-gradient(135deg, #c9a84c 0%, #f0d78c 50%, #c9a84c 100%);
    --shadow-glow: 0 0 40px rgba(201, 168, 76, 0.1);
    --shadow-card: 0 4px 30px rgba(0, 0, 0, 0.4);
    --radius: 16px;
    --radius-sm: 8px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --sidebar-width: 340px;
    --overlay-bg: rgba(0, 0, 0, 0.8);
    --code-bg: #0d0d15;
    --msg-user-bg: rgba(201, 168, 76, 0.1);
    --msg-assistant-bg: rgba(255, 255, 255, 0.04);
    --input-bg: rgba(255, 255, 255, 0.05);
}

/* --- Light Mode --- */
:root.light-mode {
    --primary: #9a7b2d;
    --primary-dark: #7a6020;
    --primary-light: #c9a84c;
    --bg-dark: #f5f3ef;
    --bg-card: #ffffff;
    --bg-card-hover: #f0ede6;
    --bg-section: #faf8f4;
    --text-primary: #1a1a2e;
    --text-secondary: #555566;
    --text-muted: #8888a0;
    --border: #e0ddd4;
    --gradient-gold: linear-gradient(135deg, #9a7b2d 0%, #c9a84c 50%, #9a7b2d 100%);
    --shadow-glow: 0 0 30px rgba(154, 123, 45, 0.06);
    --shadow-card: 0 2px 16px rgba(0, 0, 0, 0.06);
    --overlay-bg: rgba(0, 0, 0, 0.5);
    --code-bg: #f0ede6;
    --msg-user-bg: rgba(154, 123, 45, 0.08);
    --msg-assistant-bg: rgba(0, 0, 0, 0.02);
    --input-bg: rgba(0, 0, 0, 0.03);
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
    overflow-x: hidden;
    max-width: 100%;
    width: 100%;
}

body {
    height: 100%;
    height: 100dvh;
    font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    display: flex;
    overflow: hidden;
    overflow-x: hidden;
    max-width: 100%;
    width: 100%;
    position: relative;
}

/* ============================
   SIDEBAR
   ============================ */

.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    height: 100dvh;
    background: var(--bg-section);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 100;
}

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

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    color: var(--primary);
    font-weight: 700;
    font-size: 0.95rem;
    transition: opacity 0.2s;
}

.sidebar-logo:hover {
    opacity: 0.8;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: var(--transition);
}

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

/* Search */
.sidebar-search {
    padding: 16px 20px;
    position: relative;
}

.search-icon {
    position: absolute;
    left: 34px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.04);
    color: var(--text-primary);
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.08);
}

.search-input::placeholder {
    color: var(--text-muted);
}

/* Guru List */
.guru-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
}

.guru-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    margin-bottom: 4px;
}

.guru-list-item:hover {
    background: rgba(255,255,255,0.04);
}

.guru-list-item.active {
    background: rgba(201, 168, 76, 0.08);
    border-color: rgba(201, 168, 76, 0.2);
}

.guru-list-item.hidden {
    display: none;
}

.guru-list-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
    flex-shrink: 0;
    transition: border-color 0.3s;
}

.guru-list-item.active .guru-list-avatar {
    border-color: var(--primary);
}

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

.guru-list-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.guru-list-role {
    font-size: 0.73rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.guru-list-item.active .guru-list-name {
    color: var(--primary);
}

.guru-list-badge {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.3s;
}

.guru-list-item.has-chat .guru-list-badge {
    opacity: 1;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.sidebar-battle-link {
    display: block;
    text-align: center;
    padding: 10px 16px;
    margin-bottom: 12px;
    background: linear-gradient(135deg, #e74c3c, #c9a84c);
    color: #fff;
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.sidebar-battle-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
}

.provider-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.provider-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.3s;
}

.provider-dot.connected {
    background: #4ade80;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.4);
}

/* ============================
   MOBILE HEADER
   ============================ */

.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: rgba(14, 14, 22, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    z-index: 90;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
    padding-top: env(safe-area-inset-top, 0);
    max-width: 100vw;
    overflow: hidden;
}

.mobile-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.menu-btn, .mobile-back, .mobile-reset-btn, .mobile-action-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    text-decoration: none;
    min-height: 40px;
    min-width: 40px;
}

.menu-btn:hover, .mobile-back:hover, .mobile-reset-btn:hover, .mobile-action-btn:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.05);
}

.mobile-reset-btn:active {
    color: var(--gold);
}

.mobile-share-btn:active {
    color: var(--gold);
}

.mobile-guru-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100% - 160px);
    text-align: center;
    pointer-events: none;
}

/* ============================
   SIDEBAR OVERLAY (Mobile)
   ============================ */

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ============================
   CHAT MAIN AREA
   ============================ */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-width: 0;
    max-width: 100%;
    background: var(--bg-dark);
    overflow: hidden;
    overflow-x: hidden;
}

/* --- Empty State --- */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    gap: 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

.empty-icon {
    font-size: 4rem;
    margin-bottom: 8px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.empty-state h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: 'Noto Sans KR', sans-serif;
}

.empty-state > p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.7;
    max-width: 400px;
}

.quick-picks {
    margin-top: 32px;
    width: 100%;
    max-width: 600px;
}

.quick-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 16px;
}

.quick-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.quick-pick-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 20px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    transition: var(--transition);
}

.quick-pick-card:hover {
    border-color: rgba(201, 168, 76, 0.3);
    background: var(--bg-card-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.quick-pick-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}

.quick-pick-card:hover .quick-pick-avatar {
    border-color: var(--primary);
}

.quick-pick-name {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
}

/* ============================
   ACTIVE CHAT
   ============================ */

.chat-active {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
}

/* Chat Top Bar */
.chat-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
    border-bottom: 1px solid var(--border);
    background: rgba(14, 14, 22, 0.6);
    backdrop-filter: blur(10px);
    flex-shrink: 0;
    max-width: 100%;
    overflow: hidden;
}

.chat-guru-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.chat-guru-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--primary);
    box-shadow: 0 0 12px rgba(201, 168, 76, 0.15);
}

.chat-guru-name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.chat-guru-role {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.chat-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.action-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: rgba(201, 168, 76, 0.05);
}

/* Messages Area */
.chat-messages-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 0;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: none;
    touch-action: pan-y;
}

/* Welcome Message */
.chat-welcome-full {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 48px 20px;
    gap: 20px;
    max-width: 500px;
    margin: auto;
}

.welcome-avatar-lg {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--primary);
    box-shadow: 0 0 30px rgba(201, 168, 76, 0.2);
}

.welcome-name {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-primary);
}

.welcome-quote {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.7;
    font-style: italic;
    position: relative;
    padding: 0 24px;
}

.welcome-quote::before { content: '\201C'; }
.welcome-quote::after { content: '\201D'; }

.welcome-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.welcome-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 12px;
}

.suggestion-chip {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: rgba(255,255,255,0.03);
    color: var(--text-secondary);
    font-size: 0.82rem;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.suggestion-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(201, 168, 76, 0.05);
}

/* Messages */
.chat-msg {
    display: flex;
    gap: 12px;
    max-width: 75%;
    min-width: 0;
    animation: msgFadeIn 0.3s ease;
}

.chat-msg.msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg.msg-assistant {
    align-self: flex-start;
}

.msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 1.5px solid var(--border);
    margin-top: 2px;
}

.msg-assistant .msg-avatar {
    border-color: var(--primary);
}

.msg-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.msg-sender {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0 4px;
}

.msg-bubble {
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 0.92rem;
    line-height: 1.75;
    word-break: break-word;
    overflow-wrap: break-word;
    overflow-x: hidden;
    max-width: 100%;
}

.msg-user .msg-bubble {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #0a0a0f;
    border-bottom-right-radius: 6px;
    font-weight: 500;
}

.msg-assistant .msg-bubble {
    background: var(--msg-assistant-bg);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 6px;
}

/* Tool status indicator */
.msg-tool-status {
    margin-bottom: 8px;
}

.tool-status-inner {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 16px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    font-size: 0.82rem;
    color: var(--primary);
    animation: toolStatusPulse 2s ease-in-out infinite;
}

.tool-spinner {
    width: 14px;
    height: 14px;
    min-width: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: toolSpin 0.8s linear infinite;
}

.tool-status-text {
    font-weight: 500;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: inherit;
}

.tool-done-icon {
    font-size: 13px;
    line-height: 1;
    min-width: 14px;
    text-align: center;
}

.tool-status-done {
    animation: none !important;
    opacity: 0.55;
    border-color: rgba(var(--primary-rgb, 201, 168, 76), 0.2);
    font-size: 0.82rem;
    padding: 6px 14px;
}

/* tool-status-history removed — 현재 활성 도구만 표시 */

@keyframes toolSpin {
    to { transform: rotate(360deg); }
}

@keyframes toolStatusPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

/* Thinking block */
.msg-thinking-block {
    margin-bottom: 8px;
    border-radius: 14px;
    border: 1px solid rgba(180, 160, 120, 0.25);
    background: rgba(180, 160, 120, 0.06);
    overflow: hidden;
    transition: all 0.3s ease;
}

.thinking-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.thinking-header:hover {
    background: rgba(180, 160, 120, 0.1);
}

.thinking-icon {
    font-size: 0.9rem;
}

.thinking-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
}

.thinking-status {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-left: auto;
}

.thinking-status.thinking-active {
    color: var(--primary);
    animation: thinkingPulse 1.5s ease-in-out infinite;
}

.thinking-status.thinking-done {
    color: var(--text-muted);
}

@keyframes thinkingPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* Streaming thinking — auto-expanded with border glow */
.msg-thinking-block.streaming {
    border-color: rgba(180, 160, 120, 0.35);
    animation: thinkingBorderGlow 2.5s ease-in-out infinite;
}

/* Auto-expand during streaming */
.msg-thinking-block.streaming.expanded .thinking-content {
    max-height: 200px;
    overflow-y: auto;
    padding: 8px 14px 12px 14px;
    border-top: 1px solid rgba(180, 160, 120, 0.15);
}

@keyframes thinkingBorderGlow {
    0%, 100% { border-color: rgba(180, 160, 120, 0.2); box-shadow: none; }
    50% { border-color: rgba(180, 160, 120, 0.45); box-shadow: 0 0 8px rgba(180, 160, 120, 0.08); }
}

.thinking-toggle {
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: transform 0.3s ease;
}

.msg-thinking-block.expanded .thinking-toggle {
    transform: rotate(90deg);
}

.thinking-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, padding 0.3s ease;
    font-size: 0.8rem;
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: keep-all;
    overflow-wrap: break-word;
    font-family: 'Noto Sans KR', sans-serif;
}

.msg-thinking-block.expanded .thinking-content {
    max-height: 500px;
    overflow-y: auto;
    padding: 0 14px 12px 14px;
    border-top: 1px solid rgba(180, 160, 120, 0.15);
}

.thinking-content::-webkit-scrollbar {
    width: 4px;
}

.thinking-content::-webkit-scrollbar-thumb {
    background: rgba(180, 160, 120, 0.3);
    border-radius: 2px;
}

.msg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 4px;
    opacity: 0;
    transition: opacity 0.2s;
}

.chat-msg:hover .msg-meta {
    opacity: 1;
}

.msg-time {
    font-size: 0.68rem;
    color: var(--text-muted);
}

.msg-copy-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 0.7;
}

.msg-copy-btn:hover {
    color: var(--gold);
    background: rgba(180, 160, 120, 0.15);
    opacity: 1;
}

.msg-copy-btn.copied {
    color: #4ade80;
    opacity: 1;
}

/* Mobile: always show meta for touch devices */
@media (hover: none) {
    .msg-meta {
        opacity: 1;
    }
}

/* Typing indicator */
.typing-indicator {
    display: inline-flex;
    gap: 5px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    animation: typingBounce 1.4s infinite;
    opacity: 0.4;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

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

/* Error */
.msg-error {
    color: #ff6b6b;
    font-size: 0.85rem;
}

/* ============================
   SCROLL TO BOTTOM BUTTON
   ============================ */

.scroll-to-bottom-btn {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--gold);
    background: rgba(14, 14, 22, 0.9);
    color: var(--gold);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.scroll-to-bottom-btn:hover {
    background: var(--gold);
    color: var(--dark);
    transform: translateX(-50%) scale(1.1);
}

.scroll-to-bottom-btn:active {
    transform: translateX(-50%) scale(0.95);
}

/* ============================
   INPUT BAR
   ============================ */

.chat-input-bar {
    padding: 16px 28px 20px;
    border-top: 1px solid var(--border);
    background: rgba(14, 14, 22, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    flex-shrink: 0;
    max-width: 100%;
    overflow-x: hidden;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 6px 6px 6px 18px;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.08);
}

.chat-textarea {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.92rem;
    font-family: 'Noto Sans KR', sans-serif;
    outline: none;
    resize: none;
    max-height: 150px;
    line-height: 1.6;
    padding: 8px 0;
}

.chat-textarea::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #0a0a0f;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
    flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(201, 168, 76, 0.3);
}

.send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    transform: none;
}

.send-btn.sending {
    animation: pulseSend 1.5s infinite;
}

@keyframes pulseSend {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 0.8; }
}

/* Stop button */
.stop-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: none;
    background: #e74c3c;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    animation: pulseStop 1.5s infinite;
    flex-shrink: 0;
}

.stop-btn:hover {
    background: #c0392b;
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(231, 76, 60, 0.4);
}

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

@keyframes pulseStop {
    0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
    50% { box-shadow: 0 0 12px 4px rgba(231, 76, 60, 0.3); }
}

/* Stopped message style */
.msg-stopped {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9em;
}

.input-hint {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: right;
    margin-top: 6px;
    padding-right: 4px;
}

/* ============================
   SCROLLBAR
   ============================ */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================
   CONFIRM POPUP
   ============================ */

.confirm-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10000;
    align-items: center;
    justify-content: center;
}

.confirm-overlay.active {
    display: flex;
}

.confirm-popup {
    background: var(--card-bg);
    border: 1px solid var(--gold);
    border-radius: 16px;
    padding: 36px 32px;
    max-width: 380px;
    width: 90%;
    text-align: center;
    animation: confirmSlideIn 0.25s ease-out;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 30px rgba(212, 175, 55, 0.15);
}

@keyframes confirmSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(10px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.confirm-icon {
    font-size: 2.5rem;
    margin-bottom: 16px;
}

.confirm-message {
    color: var(--text-primary);
    font-size: 1.05rem;
    line-height: 1.6;
    margin-bottom: 28px;
    white-space: pre-line;
    font-weight: 500;
}

.confirm-buttons {
    display: flex;
    gap: 12px;
}

.confirm-btn {
    flex: 1;
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    letter-spacing: 0.5px;
}

.confirm-cancel {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.confirm-cancel:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
}

.confirm-ok {
    background: #fff;
    color: #111;
    font-size: 1.05rem;
    font-weight: 800;
    box-shadow: 0 4px 15px rgba(255, 255, 255, 0.25);
}

.confirm-ok:hover {
    background: #f0f0f0;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 255, 255, 0.35);
}

.confirm-ok:active {
    transform: translateY(0);
    background: #e0e0e0;
    box-shadow: 0 2px 10px rgba(255, 255, 255, 0.15);
}

/* ============================
   LIGHT MODE OVERRIDES
   ============================ */

:root.light-mode .sidebar {
    background: var(--bg-card);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.05);
}

:root.light-mode .sidebar-header {
    border-bottom-color: var(--border);
}

:root.light-mode .guru-item:hover {
    background: rgba(154, 123, 45, 0.06);
}

:root.light-mode .guru-item.active {
    background: rgba(154, 123, 45, 0.08);
    border-left-color: var(--primary);
}

:root.light-mode .search-input {
    background: rgba(0, 0, 0, 0.03);
    color: var(--text-primary);
    border-color: var(--border);
}

:root.light-mode .search-input:focus {
    border-color: var(--primary);
    background: var(--bg-card);
}

:root.light-mode .msg-user .msg-bubble {
    background: linear-gradient(135deg, #d4a843, #e8c060);
    color: #1a1a2e;
    box-shadow: 0 2px 8px rgba(212, 168, 67, 0.3);
}

:root.light-mode .msg-assistant .msg-bubble {
    background: var(--msg-assistant-bg);
    border-color: var(--border);
}

:root.light-mode .chat-input-bar {
    border-top-color: var(--border);
    background: var(--bg-card);
}

:root.light-mode .chat-input-wrapper {
    background: var(--input-bg);
    border-color: var(--border);
}

:root.light-mode .chat-input-wrapper:focus-within {
    border-color: var(--primary);
    background: var(--bg-card);
}

:root.light-mode textarea.chat-input {
    color: var(--text-primary);
}

:root.light-mode .chat-top-bar {
    border-bottom-color: var(--border);
    background: var(--bg-card);
}

:root.light-mode .mobile-header {
    background: rgba(245, 243, 239, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom-color: var(--border);
}

:root.light-mode .thinking-header {
    background: rgba(154, 123, 45, 0.04);
}

:root.light-mode .thinking-content {
    background: var(--code-bg);
    color: var(--text-secondary);
}

:root.light-mode .tool-status-inner {
    background: rgba(154, 123, 45, 0.06);
    border-color: rgba(154, 123, 45, 0.2);
}

:root.light-mode .sidebar-overlay {
    background: rgba(0, 0, 0, 0.3);
}

:root.light-mode .welcome-quote {
    border-left-color: rgba(154, 123, 45, 0.3);
    background: rgba(154, 123, 45, 0.04);
}

:root.light-mode .suggest-chip {
    background: rgba(154, 123, 45, 0.06);
    border-color: rgba(154, 123, 45, 0.15);
    color: var(--text-primary);
}

:root.light-mode .suggest-chip:hover {
    background: rgba(154, 123, 45, 0.12);
    border-color: var(--primary);
}

:root.light-mode .empty-guru-card {
    background: var(--bg-card);
    border-color: var(--border);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
}

:root.light-mode .empty-guru-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 16px rgba(154, 123, 45, 0.1);
}

:root.light-mode .scroll-to-bottom-btn {
    background: var(--bg-card);
    border-color: var(--border);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

:root.light-mode .confirm-overlay {
    background: rgba(0, 0, 0, 0.4);
}

:root.light-mode .confirm-popup {
    background: var(--bg-card);
    border-color: var(--border);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
}

:root.light-mode .shared-banner {
    background: rgba(154, 123, 45, 0.04);
    border-color: rgba(154, 123, 45, 0.2);
}

/* Chat page theme toggle */
.chat-theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.chat-theme-toggle:hover {
    color: var(--primary);
    border-color: var(--primary);
}

.chat-theme-toggle .icon-sun,
.chat-theme-toggle .icon-moon {
    position: absolute;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.chat-theme-toggle .icon-sun {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.chat-theme-toggle .icon-moon {
    opacity: 1;
    transform: rotate(0) scale(1);
}

:root.light-mode .chat-theme-toggle .icon-sun {
    opacity: 1;
    transform: rotate(0) scale(1);
}

:root.light-mode .chat-theme-toggle .icon-moon {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

/* Mobile theme toggle shares same icon behavior */
.mobile-theme-toggle {
    position: relative;
}

.mobile-theme-toggle .icon-sun,
.mobile-theme-toggle .icon-moon {
    position: absolute;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.mobile-theme-toggle .icon-sun {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.mobile-theme-toggle .icon-moon {
    opacity: 1;
    transform: rotate(0) scale(1);
}

:root.light-mode .mobile-theme-toggle .icon-sun {
    opacity: 1;
    transform: rotate(0) scale(1);
}

:root.light-mode .mobile-theme-toggle .icon-moon {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

/* ============================
   RESPONSIVE
   ============================ */

@media (max-width: 768px) {
    html, body {
        flex-direction: column;
        overflow-x: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        width: min(340px, 85vw);
        height: 100%;
        height: 100dvh;
        transition: left 0.3s ease;
        z-index: 100;
    }

    .sidebar.open {
        left: 0;
    }

    .sidebar-close {
        display: flex;
    }

    .mobile-header {
        display: flex;
        flex-shrink: 0;
    }

    .chat-main {
        padding-top: 56px;
        height: 100%;
        height: 100dvh;
        flex: 1;
        overflow-x: hidden;
        max-width: 100vw;
    }

    .chat-active {
        height: calc(100dvh - 56px);
        height: calc(100vh - 56px);
    }

    /* iOS safe area support */
    @supports (padding-bottom: env(safe-area-inset-bottom)) {
        .chat-active {
            height: calc(100dvh - 56px);
        }

        .chat-input-bar {
            padding-bottom: calc(12px + env(safe-area-inset-bottom));
        }
    }

    .chat-top-bar {
        display: none;
    }

    .chat-messages-area {
        padding: 16px 3px 6px;
        gap: 12px;
        flex: 1;
        min-height: 0;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        overscroll-behavior-x: none;
    }

    .chat-input-bar {
        padding: 6px 3px 10px;
        flex-shrink: 0;
    }

    .input-wrapper {
        padding: 4px 4px 4px 10px;
        border-radius: 14px;
        gap: 6px;
    }

    .chat-textarea {
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: 6px 0;
        max-height: 100px;
    }

    .send-btn, .stop-btn {
        width: 38px;
        height: 38px;
        border-radius: 10px;
    }

    .chat-msg {
        max-width: 95%;
        gap: 5px;
    }

    .msg-avatar {
        width: 26px;
        height: 26px;
    }

    .msg-bubble {
        padding: 10px 10px;
        font-size: 1rem;
        line-height: 1.7;
        border-radius: 14px;
    }

    .msg-user .msg-bubble {
        border-bottom-right-radius: 4px;
    }

    .msg-assistant .msg-bubble {
        border-bottom-left-radius: 4px;
    }

    .msg-meta {
        opacity: 1;
    }

    .msg-time {
        font-size: 0.68rem;
    }

    .msg-thinking-block {
        margin-bottom: 6px;
        border-radius: 10px;
    }

    .thinking-header {
        padding: 8px 10px;
        gap: 6px;
    }

    .thinking-label {
        font-size: 0.82rem;
    }

    .thinking-status {
        font-size: 0.72rem;
    }

    .thinking-content {
        font-size: 0.88rem;
        line-height: 1.6;
    }

    .msg-thinking-block.expanded .thinking-content {
        max-height: 300px;
        padding: 0 10px 10px 10px;
    }

    .tool-status-inner {
        font-size: 0.8rem;
        padding: 5px 12px;
        gap: 6px;
    }

    .tool-status-text {
        max-width: 200px;
    }

    .tool-status-done {
        font-size: 0.8rem;
        padding: 5px 12px;
    }

    .empty-state {
        padding: 20px 10px;
        overflow-y: auto;
    }

    .empty-icon {
        font-size: 3rem;
    }

    .empty-state h2 {
        font-size: 1.2rem;
    }

    .empty-state > p {
        font-size: 0.95rem;
    }

    .quick-picks {
        margin-top: 20px;
    }

    .quick-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
    }

    .quick-pick-card {
        padding: 14px 8px;
    }

    .quick-pick-avatar {
        width: 40px;
        height: 40px;
    }

    .quick-pick-name {
        font-size: 0.75rem;
    }

    .input-hint {
        display: none;
    }

    /* Welcome section mobile */
    .chat-welcome-full {
        padding: 20px 10px;
        gap: 14px;
    }

    .welcome-avatar-lg {
        width: 64px;
        height: 64px;
    }

    .welcome-name {
        font-size: 1.15rem;
    }

    .welcome-quote {
        font-size: 0.95rem;
        padding: 0 4px;
    }

    .welcome-suggestions {
        gap: 6px;
    }

    .suggestion-chip {
        padding: 8px 12px;
        font-size: 0.88rem;
    }

    /* Sidebar overlay */
    .sidebar-overlay {
        -webkit-tap-highlight-color: transparent;
    }

    /* Better touch targets */
    .guru-list-item {
        padding: 14px;
        min-height: 64px;
    }

    .menu-btn, .mobile-back, .mobile-reset-btn, .mobile-action-btn {
        min-width: 44px;
        min-height: 44px;
    }

    .action-btn {
        min-width: 44px;
        min-height: 44px;
    }
}

@media (max-width: 480px) {
    .chat-msg {
        max-width: 97%;
    }

    .chat-messages-area {
        padding: 14px 2px 4px;
        gap: 10px;
    }

    .chat-input-bar {
        padding: 4px 2px 8px;
    }

    .msg-bubble {
        padding: 9px 8px;
        font-size: 0.98rem;
    }

    .msg-avatar {
        width: 24px;
        height: 24px;
    }

    .quick-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .suggestion-chip {
        flex: 1 1 calc(50% - 4px);
        text-align: center;
    }

    .confirm-popup {
        padding: 28px 24px;
        border-radius: 14px;
    }

    .confirm-icon {
        font-size: 2.2rem;
    }

    .confirm-message {
        font-size: 0.95rem;
    }

    .confirm-btn {
        padding: 14px 20px;
        font-size: 1rem;
    }
}

/* Landscape phone fix */
@media (max-height: 500px) and (max-width: 900px) {
    .chat-messages-area {
        padding: 8px 12px;
        gap: 8px;
    }

    .chat-input-bar {
        padding: 6px 12px 8px;
    }

    .empty-state {
        padding: 12px;
        gap: 8px;
    }

    .empty-icon {
        font-size: 2rem;
    }

    .quick-picks {
        margin-top: 8px;
    }

    .chat-welcome-full {
        padding: 12px;
        gap: 8px;
    }

    .welcome-avatar-lg {
        width: 48px;
        height: 48px;
    }
}

/* ============================
   SHARE MODE
   ============================ */

/* Shared Banner */
.shared-banner {
    background: linear-gradient(135deg, rgba(201, 168, 76, 0.08), rgba(201, 168, 76, 0.03));
    border-bottom: 1px solid rgba(201, 168, 76, 0.2);
    padding: 12px 28px;
    flex-shrink: 0;
    animation: bannerSlideIn 0.3s ease;
    overflow-x: hidden;
    max-width: 100%;
}

@keyframes bannerSlideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.shared-banner-content {
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: 900px;
    margin: 0 auto;
}

.shared-banner-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
}

.shared-banner-text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.shared-banner-text strong {
    font-size: 0.85rem;
    color: var(--primary);
    font-weight: 700;
}

.shared-banner-text span {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.shared-truncated {
    color: #ff9f43 !important;
    font-size: 0.72rem !important;
}

.shared-id {
    font-family: 'Courier New', monospace;
    color: var(--gold) !important;
    font-size: 0.7rem !important;
    opacity: 0.7;
}

.shared-banner-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.shared-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 10px;
    font-size: 0.78rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid;
}

.shared-btn-save {
    background: rgba(201, 168, 76, 0.1);
    border-color: rgba(201, 168, 76, 0.3);
    color: var(--primary);
}

.shared-btn-save:hover {
    background: rgba(201, 168, 76, 0.2);
    border-color: var(--primary);
    box-shadow: 0 0 12px rgba(201, 168, 76, 0.15);
}

.shared-btn-close {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--border);
    color: var(--text-muted);
    padding: 8px;
}

.shared-btn-close:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
    background: rgba(255, 255, 255, 0.08);
}

/* Share Toast */
.share-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--primary);
    padding: 14px 24px;
    border-radius: 14px;
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5), 0 0 20px rgba(201, 168, 76, 0.15);
    z-index: 9999;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    white-space: nowrap;
}

.share-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Share mode message separator (between shared and new messages) */
.shared-separator {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 0;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.shared-separator::before,
.shared-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--border), transparent);
}

.shared-separator span {
    white-space: nowrap;
    color: var(--primary);
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* Mobile share styles */
@media (max-width: 768px) {
    .shared-banner {
        padding: 10px 12px;
    }

    .shared-banner-content {
        gap: 10px;
    }

    .shared-banner-icon {
        font-size: 1.1rem;
    }

    .shared-banner-text strong {
        font-size: 0.8rem;
    }

    .shared-btn-save span {
        display: none;
    }

    .shared-btn-save {
        padding: 8px;
    }

    .share-toast {
        bottom: 80px;
        font-size: 0.82rem;
        padding: 12px 20px;
        left: 16px;
        right: 16px;
        transform: translateX(0) translateY(20px);
        white-space: normal;
        text-align: center;
    }

    .share-toast.show {
        transform: translateX(0) translateY(0);
    }
}

/* ============================
   SHARE URL POPUP (iOS fallback)
   ============================ */
.share-url-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.share-url-popup {
    background: var(--bg-card);
    border: 1px solid var(--primary);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6), 0 0 30px rgba(201, 168, 76, 0.15);
    text-align: center;
}

.share-url-popup p {
    color: var(--text-primary);
    margin: 0 0 16px;
    font-size: 0.95rem;
    font-weight: 500;
}

.share-url-input {
    width: 100%;
    padding: 12px 14px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--primary);
    font-size: 0.85rem;
    font-family: 'SF Mono', 'Fira Code', monospace;
    text-align: center;
    box-sizing: border-box;
    -webkit-user-select: all;
    user-select: all;
}

.share-url-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(201, 168, 76, 0.2);
}

.share-url-close-btn {
    margin-top: 16px;
    padding: 10px 32px;
    background: var(--primary);
    color: #0a0a0f;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.share-url-close-btn:hover {
    background: var(--primary-light);
}

@media (max-width: 768px) {
    .share-url-popup {
        padding: 20px;
        margin: 0 12px;
    }

    .share-url-input {
        font-size: 0.8rem;
    }
}
