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

body {
    font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    height: 100vh;
    overflow: hidden;
}

/* 화면리더 전용 텍스트 */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* 접근성: 포커스 표시 */
:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

/* 접근성: 터치 타겟 최소 크기 (데스크톱은 작게, 모바일은 44px 유지) */
button, .btn, .more-menu-btn, .narrative-menu-btn, .hamburger-btn {
    min-width: 32px;
    min-height: 32px;
}

/* 비활성/포커스 시각 상태 */
.btn:disabled, button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn:focus-visible, button:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.hidden { display: none !important; }

.screen-root {
    display: none;
    padding: 1rem;
}

.screen-root.active {
    display: block;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    position: relative;
    z-index: 1000;
}

/* 햄버거 메뉴 */
.hamburger-btn {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    z-index: 1000;
}

.hamburger-btn span {
    display: block;
    width: 24px;
    height: 3px;
    background: var(--color-text-muted);
    border-radius: 2px;
    transition: all 0.3s;
}

.hamburger-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.hamburger-btn.active span:nth-child(2) {
    opacity: 0;
}

.hamburger-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* 서사기록 메뉴 버튼 */
.narrative-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    padding: 0.5rem;
    cursor: pointer;
    z-index: 1000;
    transition: transform 0.2s;
}

.narrative-menu-btn:hover {
    transform: scale(1.1);
}

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

/* 더보기 메뉴 버튼 */
.more-menu-btn {
    display: block;
    background: none;
    border: none;
    font-size: 1.5rem;
    font-weight: bold;
    padding: 0.5rem;
    cursor: pointer;
    z-index: 1001;
    transition: transform 0.2s;
    color: var(--color-text-muted);
}

/* 데스크톱: 더보기 메뉴로 이동할 버튼들 숨김 */
#loginBtn, #logoutBtn, #adminBtn, #backupBtn,
#themeToggleBtn, #clearHistoryBtn, #resetSessionsBtn,
#sessionStatusBadge {
    display: none;
}

.more-menu-btn:hover {
    transform: scale(1.1);
}

.more-menu-btn.active {
    background: var(--color-border);
    border-radius: 6px;
}

/* 더보기 메뉴 드롭다운 */
.more-menu-dropdown {
    display: none;
    position: fixed;
    top: 60px;
    right: 10px;
    background: var(--color-surface);
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: 1002;
    min-width: 200px;
    padding: 0.5rem;
}

.more-menu-dropdown.hidden {
    display: none;
}

.more-menu-dropdown.visible {
    display: block;
}

.more-menu-item {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-size: 1rem;
    color: var(--color-text);
    border-radius: 6px;
    transition: background 0.2s;
}

.more-menu-item:hover {
    background: var(--color-muted);
}

.more-menu-item-static {
    padding: 0.75rem 1rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.more-menu-divider {
    height: 1px;
    background: var(--color-border);
    margin: 0.5rem 0;
}

.logout-btn {
    color: var(--color-error) !important;
    font-weight: 600;
}

.logout-btn:hover {
    background: #fef2f2 !important;
}

/* 브랜드 영역 */
header .brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

header .brand-logo {
    height: 36px;
    width: auto;
    display: block;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.current-room-badge {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.6rem;
    background: var(--color-primary);
    color: white;
    border-radius: var(--radius-full);
    font-size: var(--font-sm);
    font-weight: 500;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.current-room-badge:empty {
    display: none;
}

.header-actions {
    display: flex;
    align-items: center;
    margin-left: auto;
    gap: 0.5rem;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: var(--font-sm);
}

.token-info {
    display: flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    background: var(--color-muted);
    border-radius: var(--radius-sm);
    font-size: var(--font-xs);
    font-family: 'Consolas', 'Monaco', monospace;
    color: var(--color-primary);
    border: 1px solid var(--color-border);
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--color-border);
    animation: pulse 2s infinite;
}

.status-indicator.connected {
    background: #48bb78;
    animation: none;
}

.status-indicator.disconnected {
    background: #f56565;
    animation: none;
}

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

/* Main Content - 3 Column Layout */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    gap: 0;
}

/* Left Panel - Context Settings */
.left-panel {
    width: 320px;
    background: var(--color-surface);
    border-right: 2px solid var(--color-border);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease;
}

.left-panel.collapsed {
    width: 0;
    overflow: hidden;
}

/* Center Panel - Main Chat */
.center-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
    min-width: 400px;
}

/* Right Panel - Narrative */
.right-panel {
    width: 380px;
    background: var(--color-surface);
    border-left: 2px solid var(--color-border);
    display: flex;
    flex-direction: column;
}

/* Panel Headers */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
}

.panel-header h2 {
    font-size: var(--font-base);
    font-weight: 600;
    color: var(--color-text);
}

.narrative-controls {
    background: var(--color-surface);
}

.btn-icon {
    background: none;
    border: none;
    font-size: var(--font-lg);
    cursor: pointer;
    padding: 0.2rem 0.35rem;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    transition: all 0.15s;
}

.btn-icon:hover {
    background: var(--color-border);
    color: var(--color-text);
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
}

.tab-button {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: var(--font-sm);
    font-weight: 500;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
}

.tab-button:hover {
    color: var(--color-text);
    background: var(--color-bg);
}

.tab-button.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
    background: var(--color-bg);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.hint {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
    font-style: italic;
}

/* Panel Content */
.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* Context Settings */
.context-section {
    margin-bottom: 0.75rem;
}

.context-section label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    font-size: var(--font-sm);
    color: var(--color-text);
}

.context-section textarea {
    width: 100%;
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    font-family: inherit;
    font-size: var(--font-base);
    resize: vertical;
    outline: none;
    transition: all 0.15s;
}

.context-section textarea:focus {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-focus);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.35rem;
    cursor: pointer;
    color: var(--color-text-muted);
    font-size: var(--font-sm);
}

.checkbox-label input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--color-primary);
    width: 14px;
    height: 14px;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.slider-row input[type="range"] {
    flex: 1;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: var(--color-border);
    outline: none;
}

.slider-row input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
}

.slider-row input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--color-primary);
    border: none;
    cursor: pointer;
}

.slider-value {
    min-width: 36px;
    text-align: right;
    font-weight: 500;
    font-size: var(--font-sm);
    color: var(--color-primary);
}

.slider-checkbox {
    margin-top: 0.2rem;
    font-size: var(--font-xs);
}

.session-status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 42px;
    padding: 0.3rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--color-border);
    color: var(--color-text-muted);
    border: 2px solid var(--color-border);
}

.session-status-badge.on {
    background: #dcfce7;
    border-color: #86efac;
    color: #16a34a;
}

.checkbox-label.disabled {
    opacity: 0.6;
    pointer-events: none;
}

.context-section.disabled {
    opacity: 0.5;
    pointer-events: none;
}

.select-input {
    width: 100%;
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.6rem;
    font-family: inherit;
    font-size: 1rem;
    margin-bottom: 0.5rem;
    outline: none;
    transition: all 0.2s;
    cursor: pointer;
}

.select-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(92, 135, 255, 0.1);
}

/* Character Items */
.character-item {
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    border-radius: 10px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    transition: all 0.2s;
}

/* stories UI 제거(비활성화) */
#storySelect,
#loadStoryBtn,
#resumeStoryBtn,
#injectStoryBtn,
#deleteStoryBtn,
#saveNarrativeBtn { display: none !important; }

.character-item:hover {
    border-color: var(--color-border);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.character-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.character-item input {
    background: var(--color-surface);
    color: var(--color-text);
    border: 2px solid var(--color-border);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
}

.character-item input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(92, 135, 255, 0.1);
}

.character-item textarea {
    width: 100%;
    background: var(--color-surface);
    color: var(--color-text);
    border: 2px solid var(--color-border);
    border-radius: 6px;
    padding: 0.6rem;
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
    outline: none;
    min-height: 60px;
    transition: all 0.2s;
}

.character-item textarea:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(92, 135, 255, 0.1);
}

/* 캐릭터 이름 필드 */
.character-name-field {
    background: var(--color-surface);
    color: var(--color-text);
    border: 2px solid var(--color-border);
    border-radius: 8px;
    padding: 0.6rem;
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
}

.character-name-field:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(92, 135, 255, 0.1);
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* 이전 메시지 불러오기 버튼 */
.load-more-btn {
    align-self: center;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    margin-bottom: 0.5rem;
    background: var(--color-surface);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: var(--font-sm);
    transition: background 0.2s, color 0.2s;
}

.load-more-btn:hover:not(:disabled) {
    background: var(--color-bg);
    color: var(--color-text);
}

.load-more-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.load-more-btn.loading {
    pointer-events: none;
}

.load-more-btn.error {
    border-color: var(--color-error, #e53935);
    color: var(--color-error, #e53935);
}

.load-more-btn.error:hover:not(:disabled) {
    background: rgba(229, 57, 53, 0.1);
}

/* 스피너 애니메이션 */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

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

.chat-message {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chat-message.user {
    align-items: flex-end;
}

.chat-message.assistant {
    align-items: flex-start;
}

.chat-message.system {
    align-items: center;
}

.chat-message .message-content {
    max-width: 85%;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 1rem;
}

.chat-message.user .message-content {
    background: var(--color-primary);
    color: var(--color-surface);
}

.chat-message.assistant .message-content {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.chat-message.system .message-content,
.chat-message.system p {
    background: transparent;
    color: var(--color-text-muted);
    font-size: var(--font-sm);
    text-align: center;
}

.chat-message .character-name {
    font-weight: 600;
    margin-bottom: 0.15rem;
    font-size: var(--font-sm);
}

.chat-message .message-time {
    font-size: var(--font-xs);
    color: var(--color-text-muted);
}

/* Character-specific colors */
.chat-message.character-0 .message-content {
    background: #dbeafe;
    border-color: #93c5fd;
    color: #1e40af;
}

.chat-message.character-1 .message-content {
    background: #f3e8ff;
    border-color: #d8b4fe;
    color: #7c3aed;
}

.chat-message.character-2 .message-content {
    background: #d1fae5;
    border-color: #6ee7b7;
    color: #059669;
}

.chat-message.character-3 .message-content {
    background: #fed7aa;
    border-color: #fdba74;
    color: #c2410c;
}

.chat-message.character-4 .message-content {
    background: #fce7f3;
    border-color: #f9a8d4;
    color: #be185d;
}

.chat-message.character-5 .message-content {
    background: #fecaca;
    border-color: #fca5a5;
    color: #dc2626;
}

.chat-message.character-6 .message-content {
    background: #cffafe;
    border-color: #67e8f9;
    color: #0891b2;
}

.chat-message.character-7 .message-content {
    background: #fef3c7;
    border-color: #fcd34d;
    color: #d97706;
}

.chat-message.character-8 .message-content {
    background: #e9d5ff;
    border-color: #c084fc;
    color: #9333ea;
}

.chat-message.character-9 .message-content {
    background: #ccfbf1;
    border-color: #5eead4;
    color: #0f766e;
}

/* Narrator style */
.chat-message.narrator .message-content {
    background: #fffbeb;
    border-left: 4px solid #fbbf24;
    font-style: italic;
    color: #78350f;
    border: 2px solid #fde68a;
}

.chat-message.narrator .character-name {
    color: #d97706;
    font-weight: 700;
}

/* Chat Input */
.chat-input-container {
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.chat-input-container textarea {
    flex: 1;
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    font-family: inherit;
    font-size: 1rem;
    resize: none;
    outline: none;
    min-height: 60px;
    transition: all 0.15s;
}

.chat-input-container textarea:focus {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-focus);
}

/* Narrative Markdown */
.narrative-markdown {
    line-height: 1.5;
    font-size: var(--font-base);
}

.narrative-markdown h1 {
    font-size: var(--font-xl);
    margin-bottom: 0.75rem;
    color: var(--color-primary);
    border-bottom: 2px solid var(--color-border);
    padding-bottom: 0.35rem;
}

.narrative-markdown h2 {
    font-size: var(--font-lg);
    margin-top: 1rem;
    margin-bottom: 0.35rem;
    color: var(--color-text);
    font-weight: 600;
}

.narrative-markdown p {
    margin-bottom: 0.75rem;
    color: var(--color-text-muted);
}

.narrative-markdown hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: 1rem 0;
}

/* 빈 상태 placeholder 공통 */
.placeholder {
    color: var(--color-text-muted);
    font-size: var(--font-sm);
    font-style: italic;
    text-align: center;
}

.narrative-markdown .placeholder {
    color: var(--color-text-muted);
    font-style: italic;
    text-align: center;
    padding: 2rem;
}

/* Buttons */
.btn {
    padding: 0.4rem 0.75rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: var(--font-sm);
    font-weight: 500;
    transition: all 0.15s;
}

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

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.btn-sm {
    padding: 0.2rem 0.4rem;
    font-size: var(--font-xs);
    min-width: auto;
    height: 24px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--color-muted);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
}

.btn-sm:hover:not(:disabled) {
    background: var(--color-border);
    color: var(--color-text);
}

.btn-warning {
    background: #fbbf24;
    color: #78350f;
}

.btn-warning:hover:not(:disabled) {
    background: #f59e0b;
}

.btn-remove {
    background: var(--color-error);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.2rem 0.4rem;
    cursor: pointer;
    font-size: var(--font-xs);
    font-weight: 500;
}

.btn-remove:hover {
    background: #dc2626;
}

/* Footer */
footer {
    background: var(--color-surface);
    border-top: 2px solid var(--color-border);
}

.log-area {
    padding: 0.5rem 1.5rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    max-height: 80px;
    overflow-y: auto;
}

.log-area p {
    margin: 0.25rem 0;
}

.log-error {
    color: var(--color-error);
    font-weight: 500;
}

.log-success {
    color: var(--color-success);
    font-weight: 500;
}

/* Loading animation */
.chat-message.assistant .typing {
    display: inline-flex;
    gap: 4px;
    padding: 0.75rem 1rem;
    background: var(--color-muted);
    border-radius: 12px;
    border: 2px solid var(--color-border);
}

.chat-message.assistant .typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-text-muted);
    animation: typing 1.4s infinite;
}

.chat-message.assistant .typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-message.assistant .typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--color-muted);
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 5px;
    transition: background 0.2s;
}

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

/* Responsive adjustments */
@media (max-width: 1200px) {
    .left-panel {
        width: 280px;
    }

    .right-panel {
        width: 320px;
    }
}

@media (max-width: 900px) {
    /* 모바일: 터치 타겟 44px 유지 */
    button, .btn, .more-menu-btn, .narrative-menu-btn, .hamburger-btn {
        min-width: 44px;
        min-height: 44px;
    }

    /* 햄버거 메뉴 표시 */
    .hamburger-btn {
        display: flex;
    }

    /* 서사기록 메뉴 버튼 표시 */
    .narrative-menu-btn {
        display: block;
    }

    /* 모바일에서 중앙 방 이름 숨김 (로고 가림 방지) */
    .current-room-badge {
        display: none;
    }

    /* 헤더 레이아웃 조정 */
    header {
        padding: 0.75rem 1rem;
    }

    /* 브랜드 영역 중앙 정렬 */
    header .brand {
        flex: 1;
        justify-content: center;
    }

    header .brand h1 {
        font-size: 1.2rem;
    }

    header .brand-logo {
        height: 32px;
    }

    /* 헤더 액션 버튼들 숨기기 (더보기 메뉴로 이동) */
    .header-actions {
        display: none;
    }

    /* 좌측/우측 패널을 오버레이로 표시 */
    .left-panel,
    .right-panel {
        position: fixed;
        top: 60px;
        height: calc(100vh - 60px);
        z-index: 999;
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        width: 85%;
        max-width: 320px;
        box-shadow: 2px 0 12px rgba(0, 0, 0, 0.1);
    }

    .left-panel {
        left: 0;
    }

    .left-panel.mobile-visible {
        transform: translateX(0);
    }

    .right-panel {
        right: 0;
        left: auto;
        transform: translateX(100%);
        border-left: none;
        border-right: 2px solid var(--color-border);
    }

    .right-panel.mobile-visible {
        transform: translateX(0);
    }

    /* 센터 패널을 전체 너비로 */
    .center-panel {
        min-width: unset;
        width: 100%;
    }

    /* 모바일 오버레이 배경 */
    .mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.4);
        z-index: 998;
        backdrop-filter: blur(2px);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1), backdrop-filter 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .mobile-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* 탭 버튼 크기 조정 */
    .tab-button {
        font-size: 0.85rem;
        padding: 0.6rem 0.75rem;
    }

    /* 작은 버튼들 크기 통일 */
    .btn-sm {
        font-size: 0.7rem;
        padding: 0.4rem 0.6rem;
        min-height: 44px;
        min-width: 44px;
    }
}

@media (max-width: 600px) {
    header .brand h1 {
        font-size: 1rem;
    }

    header .brand-logo {
        height: 28px;
    }

    .chat-input-container textarea {
        min-height: 60px;
        font-size: 1rem;
    }

    .left-panel,
    .right-panel {
        width: 90%;
    }
}

/* 파일 미리보기 */
.file-preview {
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    border-radius: 8px;
    padding: 0.75rem;
    margin-top: 0.5rem;
}

.file-preview-item {
    padding: 0.3rem 0;
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text-muted);
}

.file-preview-item:last-child {
    border-bottom: none;
}

/* 로그인 모달 */
.login-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

.login-modal.hidden {
    display: none;
}

.login-modal-content {
    background: var(--color-surface);
    padding: 2.5rem;
    border-radius: 16px;
    width: min(90%, 400px);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border: 2px solid var(--color-border);
    text-align: center;
}

.login-modal-content h2 {
    color: var(--color-text);
}

.login-logo {
    height: 72px;
    width: auto;
    margin-bottom: 0.5rem;
    display: inline-block;
}

.login-modal-content input {
    width: 100%;
    margin-top: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    color: var(--color-text);
    font-size: 1rem;
    transition: all 0.2s;
}

.login-modal-content input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(92, 135, 255, 0.1);
    background: var(--color-surface);
}

.login-description {
    color: var(--color-text-muted);
    margin-bottom: 0.75rem;
}

.login-error {
    color: var(--color-error);
    margin-top: 0.75rem;
    min-height: 1.2rem;
    font-size: 1rem;
    font-weight: 500;
}

/* 설정 모달 */
.settings-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
}

.settings-modal.hidden {
    display: none;
}

.settings-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.settings-modal-content {
    position: relative;
    width: 90%;
    max-width: 700px;
    height: 85vh;
    margin: 7.5vh auto;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
}

.settings-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    background: var(--color-surface);
    z-index: 1;
}

.settings-modal-header h2 {
    font-size: var(--font-lg);
    font-weight: 600;
    color: var(--color-text);
}

/* Settings tabs */
.settings-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-muted);
    padding: 0 0.75rem;
}
.settings-tab {
    padding: 0.5rem 0.75rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: var(--font-sm);
    color: var(--color-text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.settings-tab:hover {
    color: var(--color-text);
    background: var(--color-surface);
}
.settings-tab.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
    background: var(--color-surface);
    font-weight: 600;
}
.settings-tab-content {
    display: none;
}
.settings-tab-content.active {
    display: block;
}

.settings-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    background: linear-gradient(180deg, rgba(0,0,0,0.0), rgba(0,0,0,0.0));
}

.settings-modal-footer {
    padding: 1rem 1.5rem;
    border-top: 2px solid var(--color-border);
    position: sticky;
    bottom: 0;
    background: var(--color-surface);
}

/* Inputs unified */
input.input, .select-input, textarea, input[type="text"], input[type="password"], select {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.5rem;
    font-size: var(--font-base);
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
    color: var(--color-text);
}
input.input:focus, .select-input:focus, textarea:focus, select:focus {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-focus);
}

/* Buttons */
.btn {
    background: var(--color-muted);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    color: var(--color-text);
    padding: 0.45rem 0.7rem;
    cursor: pointer;
    transition: background .15s ease, transform .05s ease;
}
.btn:hover { background: #e9eef5; }
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: linear-gradient(180deg, var(--color-primary), var(--color-primary-700));
    color: #fff;
    border: 1px solid var(--color-primary-700);
}
.btn-warning { background: #fff7ed; border-color: #fed7aa; }
.btn-remove { background: #fef2f2; border-color: #fecaca; }

/* Field labels */
.field-label {
    display: block;
    margin: 0 0 0.25rem 0;
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 0.85rem;
}

/* Context section cards in settings modal */
.settings-modal-body .context-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    box-shadow: var(--shadow-sm);
}
.settings-modal-body .context-section + .context-section { margin-top: 0.75rem; }

/* Participant chips */
.character-chip {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    font-size: 0.875rem; /* ~14px for dense side list */
    line-height: 1.4;
}
/* 입력 플레이스홀더 색상 통일(회색) */
input::placeholder, textarea::placeholder {
    color: var(--color-text-muted);
}
/* 에디터 필드 라벨 */
.field-label {
    display: block;
    margin: 0 0 0.25rem 0;
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 0.85rem;
}
/* ===== SVG Icons ===== */
.icon {
    width: 1em;
    height: 1em;
    vertical-align: -0.125em;
    display: inline-block;
}

[data-icon] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ===== Theme Variables ===== */
:root {
    /* Colors - Light Theme */
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-muted: #f1f5f9;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-muted: #64748b;

    /* Primary - Indigo */
    --color-primary: #6366f1;
    --color-primary-hover: #4f46e5;
    --color-primary-700: #4338ca;

    /* Accent - Violet */
    --color-accent: #8b5cf6;

    /* Semantic */
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-error: #ef4444;

    /* Layout */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 10px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-focus: 0 0 0 2px rgba(99, 102, 241, 0.2);

    /* Transitions */
    --transition-fast: 0.15s ease;

    /* Font Scale (compact) */
    --font-xs: 0.7rem;
    --font-sm: 0.75rem;
    --font-base: 0.8125rem;
    --font-lg: 0.875rem;
    --font-xl: 1rem;
}

/* Dark Theme */
[data-theme="dark"] {
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-muted: #334155;
    --color-border: #475569;
    --color-text: #f1f5f9;
    --color-text-muted: #94a3b8;

    --color-primary: #818cf8;
    --color-primary-hover: #a5b4fc;
    --color-primary-700: #6366f1;

    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
}
/* Dark mode overrides for hardcoded colors */
[data-theme="dark"] .btn:hover { background: #475569; }
[data-theme="dark"] .btn-warning { background: #422006; border-color: #92400e; color: #fbbf24; }
[data-theme="dark"] .btn-remove { background: #450a0a; border-color: #7f1d1d; color: #f87171; }

/* ===== 업데이트 토스트 ===== */
.update-toast {
    /* button 기본 스타일 리셋 */
    border: none;
    font-family: inherit;
    /* 토스트 스타일 */
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--color-primary);
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    cursor: pointer;
    z-index: 10000;
    font-size: 14px;
    font-weight: 500;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}
.update-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}
.update-toast:hover {
    background: var(--color-primary-hover);
}
.update-toast::before {
    content: '🔄';
}
@media (max-width: 480px) {
    .update-toast {
        left: 16px;
        right: 16px;
        transform: translateX(0) translateY(100px);
        text-align: center;
        justify-content: center;
    }
    .update-toast.show {
        transform: translateX(0) translateY(0);
    }
}
