:root {
    --bg-dark: #121316;
    --sidebar-bg: #121316;
    --card-bg: #1c1d22;
    --card-bg-hover: #23252a;
    --text-main: #f0f0f4;
    --text-muted: #82838c;
    --accent-blue: #5d9cec;
    --accent-orange: #e07455;
    --accent-green: #3ab07a;
    --border-color: #2a2b32;
    --font-stack: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', sans-serif;
    --transition: all 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-stack);
    height: 100vh;
    overflow: hidden;
    position: relative;
}


.app-container {
    display: flex;
    height: 100vh;
    position: relative;
    z-index: 1;
    max-width: 1440px;
    margin: 0 auto;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    padding: 40px 24px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.logo-container {
    margin-bottom: 48px;
    padding-left: 12px;
}

.logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    object-fit: cover;
}

.main-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
    border-radius: 8px;
    transition: var(--transition);
}

.nav-item i {
    font-size: 18px;
}

.nav-item:hover,
.nav-item.active {
    color: var(--text-main);
}

.nav-item.active {
    background-color: rgba(255, 255, 255, 0.05);
}

.nav-divider {
    height: 1px;
    background-color: rgba(255, 255, 255, 0.05);
    margin: 24px 12px;
}

.bottom-nav {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 40px 60px;
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0;
    height: 100%;
    overflow-y: auto;
}

.main-content.chat-mode {
    overflow-y: hidden;
}

.main-content.space-mode {
    overflow: hidden;
}

/* ================================================================
   Space View — Node Editor Foundation
   ================================================================ */

#space-view {
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Toolbar */
.space-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 48px;
    background: var(--card-bg);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    flex-shrink: 0;
    gap: 12px;
    z-index: 10;
}

.space-toolbar-left,
.space-toolbar-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

.space-toolbar-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.space-workspace-name {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.space-workspace-name i { font-size: 15px; }

.space-tool-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: var(--transition);
}

.space-tool-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-main);
}

.space-tool-btn.active {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
}

.space-toolbar-sep {
    width: 1px;
    height: 20px;
    background: rgba(255, 255, 255, 0.08);
    margin: 0 4px;
}

.space-btn-secondary,
.space-btn-run {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.space-btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
}

.space-btn-run {
    background: rgba(93, 156, 236, 0.12);
    color: var(--accent-blue);
    border-color: rgba(93, 156, 236, 0.2);
}

.space-btn-secondary:disabled,
.space-btn-run:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Canvas */
.space-canvas {
    flex: 1;
    position: relative;
    overflow: hidden;
    background-color: #0d0e11;
    background-image:
        radial-gradient(circle, rgba(255, 255, 255, 0.055) 1px, transparent 1px);
    background-size: 28px 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Empty State */
.space-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
    user-select: none;
    pointer-events: none;
}

.space-empty-icon {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.space-empty-state h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
}

.space-empty-state p {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
    margin: 0;
}

.space-empty-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 8px;
}

.space-tag {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 20px;
    font-size: 11px;
    color: var(--text-muted);
}

/* Status bar */
.space-statusbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    height: 28px;
    background: var(--card-bg);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
    font-size: 11px;
    color: var(--text-muted);
}

.space-status-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.space-status-sep { opacity: 0.3; }

.space-status-right {
    margin-left: auto;
    font-size: 10px;
    opacity: 0.4;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* Header */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.breadcrumb {
    font-size: 15px;
    font-weight: 500;
}

.breadcrumb .muted {
    color: var(--text-muted);
}

.breadcrumb .separator {
    color: var(--text-muted);
    margin: 0 8px;
}

.breadcrumb .current {
    color: var(--text-main);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-search {
    display: flex;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    padding: 8px 16px;
    gap: 12px;
    transition: var(--transition);
    border: 1px solid transparent;
}

.header-search:focus-within {
    border-color: rgba(255, 255, 255, 0.1);
    background-color: rgba(255, 255, 255, 0.08);
}

.header-search i.ph-magnifying-glass {
    color: var(--text-muted);
    font-size: 18px;
}

.header-search input {
    background: none;
    border: none;
    color: var(--text-main);
    font-size: 15px;
    width: 140px;
    outline: none;
    font-family: inherit;
}

.header-search input::placeholder {
    color: var(--text-muted);
}

.header-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

.profile-name {
    font-size: 15px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Header auth elements */
.btn-header-login {
    background-color: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    padding: 7px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-header-login:hover {
    background-color: rgba(255, 255, 255, 0.12);
}

.header-user-area {
    display: flex;
    align-items: center;
    gap: 8px;
}

.credit-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    background-color: rgba(224, 116, 85, 0.12);
    border: 1px solid rgba(224, 116, 85, 0.25);
    color: var(--accent-orange);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    padding: 5px 12px;
    border-radius: 20px;
    cursor: pointer;
    transition: var(--transition);
}

.credit-badge:hover {
    background-color: rgba(224, 116, 85, 0.2);
}

.credit-badge i {
    font-size: 15px;
}

.header-profile-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    border-radius: 20px;
    transition: var(--transition);
}

.header-profile-btn:hover .profile-name {
    color: var(--text-main);
}

/* Banner */
.banner-section {
    margin-bottom: 32px;
}

.banner-wrapper {
    width: 100%;
    height: 220px;
    border-radius: 20px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.banner-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Content Grid */
.content-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 60px;
}

/* Left Column - Tabs */
.tabs {
    display: flex;
    gap: 24px;
    margin-bottom: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 12px;
    overflow-x: auto;
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: 20px;
    transition: var(--transition);
    font-family: inherit;
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    background-color: transparent;
    color: var(--text-main);
    border: 1px solid var(--text-main);
}

/* Activity List */
.activity-list {
    display: flex;
    flex-direction: column;
    gap: 24px;
    margin-top: 32px;
}

.activity-item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 16px;
}

.activity-icon {
    font-size: 16px;
}

.icon-white {
    color: var(--text-main);
}

.icon-orange {
    color: var(--accent-orange);
}

.icon-blue {
    color: var(--accent-blue);
}

.activity-content h4 {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-main);
    margin: 0;
}

.activity-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    text-align: right;
    white-space: nowrap;
}

/* Right Column - Info */
.info-column {
    display: flex;
    flex-direction: column;
}

.community-title {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 12px;
}

.community-desc {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-muted);
    margin-bottom: 24px;
    word-break: keep-all;
}

.tag-group {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 32px;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

.badge-gray {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
}

.badge-green {
    background-color: rgba(58, 176, 122, 0.1);
    color: var(--accent-green);
    border: 1px solid rgba(58, 176, 122, 0.2);
}

/* Funds Card */
.funds-card {
    background-color: var(--card-bg);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 32px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.funds-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.funds-header .amount {
    font-size: 24px;
    font-weight: 700;
}

.funds-header .label {
    font-size: 13px;
    color: var(--text-muted);
}

.funds-footer {
    display: flex;
    align-items: center;
    gap: 12px;
}

.mini-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
}

.admin-name {
    font-size: 13px;
    font-weight: 500;
}

.admin-role {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: auto;
}

/* Stats List */
.stats-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 40px;
}

.stats-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.stat-name {
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 10px;
}

.stat-name i {
    font-size: 16px;
}

.stat-val {
    font-weight: 500;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 16px;
}

.btn {
    flex: 1;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: var(--transition);
    border: 1px solid transparent;
}

.btn-secondary {
    background-color: transparent;
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.btn-dark {
    background-color: #1a1b20;
    color: var(--text-muted);
    border-color: rgba(255, 255, 255, 0.05);
}

.btn-dark:hover {
    background-color: #23252a;
    color: var(--text-main);
}

/* Chat View Redesign */
#chat-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    position: relative;
    height: 100%;
    min-height: 0;
}

.chat-history-wrapper {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-bottom: 20px;
}

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 24px 60px;
    /* 전체 채팅 내역 영역의 위아래/좌우 여백 */
    display: flex;
    flex-direction: column;
    gap: 24px;
    /* [여기를 수정하세요] 말풍선 그룹(대화 단위) 사이의 세로 간격을 조절합니다 (예: 16px, 32px) */
}

/* Hide default scrollbar for sleek look */
.chat-history::-webkit-scrollbar {
    width: 6px;
}

.chat-history::-webkit-scrollbar-track {
    background: transparent;
}

.chat-history::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.chat-message {
    display: flex;
    gap: 16px;
    /* AI 프로필 아이콘과 말풍선(텍스트) 사이의 가로 간격을 조절합니다 */
    max-width: 100%;
    /* 말풍선의 최대 너비를 늘려 화면 끝까지 텍스트가 표시되도록 허용 */
    align-items: flex-start;
    animation: message-slide-in 0.4s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    will-change: transform, opacity;
}

@keyframes message-slide-in {
    0% {
        opacity: 0;
        transform: translateY(15px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message.assistant {
    align-self: flex-start;
}

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
    max-width: 80%;
}

.message-content {
    background-color: transparent;
    padding: 6px 0 0 0;
    /* AI 텍스트 상단의 여백 조절 (아이콘과 세로 정렬 맞추기 위함) */
    font-size: 15px;
    /* 채팅 텍스트 크기 */
    line-height: 1.65;
    /* [여기를 수정하세요] 채팅 줄간격을 조절합니다 (예: 1.5는 좁게, 1.8은 넓게) */
    color: var(--text-main);
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-message.user .message-content {
    background-color: #2b2d31;
    color: var(--text-main);
    padding: 12px 20px;
    /* [여기를 수정하세요] 사용자 말풍선 내부의 상하(12px) 좌우(20px) 여백 조절 */
    border-radius: 18px;
    /* 말풍선의 둥근 정도(모서리 굴곡) 조절 */
}

/* Markdown Heading Styles in Chat */
.message-content h1,
.message-content h2,
.message-content h3 {
    margin: 16px 0 8px 0;
    font-weight: 700;
    color: #fff;
}

.message-content h1 {
    font-size: 1.5em;
}

.message-content h2 {
    font-size: 1.3em;
}

.message-content h3 {
    font-size: 1.1em;
}

.message-content h3:first-child {
    margin-top: 0;
}

.message-content h1:last-child,
.message-content h2:last-child,
.message-content h3:last-child {
    margin-bottom: 0px;
}

/* Floating Input Container */
.floating-input-container {
    padding: 0 60px 0px 60px;
    /* [여기를 수정하세요] 입력창의 위치 조절: 0(상) 60px(우) 40px(하: 바닥 여백) 60px(좌) */
    display: flex;
    justify-content: center;
    /* [여기를 수정하세요] 입력창 정렬: center(가운데), flex-start(왼쪽), flex-end(오른쪽) */
}

.chat-input-pill {
    width: 100%;
    max-width: 800px;
    /* [여기를 수정하세요] 입력창의 최대 가로 길이 조절 (예: 1000px, 600px) */
    background-color: #1a1b1e;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    /* Pill shape */
    display: flex;
    align-items: flex-end;
    padding: 8px 8px 8px 20px;
    gap: 12px;
    transition: var(--transition);
}

.chat-input-pill:focus-within {
    border-color: rgba(255, 255, 255, 0.2);
    background-color: #1e2024;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 24px;
    width: 24px;
    transition: var(--transition);
}

.icon-btn:hover {
    color: var(--text-main);
}

#chat-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-main);
    font-family: inherit;
    font-size: 15px;
    outline: none;
    min-height: 24px;
    height: 24px;
    max-height: 144px;
    /* Roughly 6 lines of text */
    line-height: 24px;
    resize: none;
    overflow-y: auto;
    transition: height 0.2s ease;
}

#chat-input::-webkit-scrollbar {
    width: 6px;
}

#chat-input::-webkit-scrollbar-track {
    background: transparent;
}

#chat-input::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

#chat-input::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

#chat-input::placeholder {
    color: var(--text-muted);
}

.input-actions-right {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 24px;
}

/* Model Dropdown */
.model-dropdown {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    height: 24px;
    box-sizing: border-box;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    transition: var(--transition);
}

.model-dropdown:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.model-dropdown .dropdown-menu {
    position: absolute;
    bottom: calc(100% + 12px);
    right: 0;
    background-color: #1c1d22;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 8px;
    display: none;
    flex-direction: column;
    min-width: 220px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 10;
}

.model-dropdown.open .dropdown-menu {
    display: flex;
}

.dropdown-item {
    background: none;
    border: none;
    color: var(--text-muted);
    padding: 12px 16px;
    text-align: left;
    font-size: 13px;
    font-weight: 500;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dropdown-item i {
    font-size: 16px;
}

.dropdown-item:hover:not(.disabled) {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.dropdown-item.active {
    color: var(--text-main);
}

.dropdown-item.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.model-credit-badge {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-orange);
    background: rgba(224, 116, 85, 0.12);
    padding: 1px 6px;
    border-radius: 10px;
    line-height: 1.4;
}

.item-credit-cost {
    margin-left: auto;
    font-size: 11px;
    font-weight: 600;
    color: var(--accent-orange);
    background: rgba(224, 116, 85, 0.12);
    padding: 2px 8px;
    border-radius: 8px;
}

.send-btn.modern {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: var(--text-main);
    color: #000;
    border: none;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.send-btn.modern:hover:not(:disabled) {
    background-color: #fff;
    transform: scale(1.05);
}

.send-btn.modern:disabled {
    background-color: rgba(255, 255, 255, 0.2);
    color: rgba(0, 0, 0, 0.5);
    cursor: not-allowed;
    transform: scale(1);
}

/* New Thinking Animation */
.typing-indicator-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 25px;
}

.thinking-circles {
    display: flex;
    position: relative;
    width: 44px;
    height: 20px;
}

.think-circle {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--bg-dark);
    animation: pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.think-circle:nth-child(1) {
    left: 0;
    background-color: #d13264;
    z-index: 1;
    animation-delay: 0s;
}

.think-circle:nth-child(2) {
    left: 8px;
    background-color: #8cc63f;
    z-index: 2;
    animation-delay: 0.2s;
}

.think-circle:nth-child(3) {
    left: 16px;
    background-color: #662d91;
    z-index: 3;
    animation-delay: 0.4s;
}

.think-circle:nth-child(4) {
    left: 24px;
    background-color: #a67c00;
    z-index: 4;
    animation-delay: 0.6s;
}

@keyframes pulse-ring {

    0%,
    100% {
        transform: scale(1);
        filter: brightness(1);
    }

    50% {
        transform: scale(1.1);
        filter: brightness(1.2);
    }
}

.thinking-text {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
}

/* Media Queries */
@media (max-width: 1024px) {
    .content-grid {
        grid-template-columns: 1fr;
        gap: 40px;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        padding: 20px;
        flex-direction: row;
        flex-wrap: wrap;
        border-right: none;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        align-items: center;
        justify-content: space-between;
    }

    .nav-divider {
        display: none;
    }

    .main-nav {
        flex-direction: row;
        width: 100%;
        overflow-x: auto;
        margin-top: 16px;
    }

    .bottom-nav {
        flex-direction: row;
        margin-top: 16px;
    }

    .logo-container {
        margin-bottom: 0;
    }

    .main-content {
        padding: 20px;
        max-width: 100vw;
    }

    .top-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .header-right {
        width: 100%;
    }

    .header-search {
        width: 100%;
    }

    .header-search input {
        flex: 1;
    }

    .activity-item {
        grid-template-columns: auto 1fr;
        grid-template-rows: auto auto;
    }

    .activity-icon {
        grid-row: span 2;
    }

    .activity-meta {
        grid-column: 2 / -1;
        text-align: left;
    }
}

/* ================================================================
   Modal Overlay (shared)
   ================================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-card {
    background-color: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 32px;
    position: relative;
    animation: modal-in 0.2s ease;
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    transition: var(--transition);
}

.modal-close:hover {
    background-color: rgba(255, 255, 255, 0.06);
    color: var(--text-main);
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 6px;
}

.modal-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 28px;
}

/* ================================================================
   Auth Modal
   ================================================================ */
.auth-modal-card {
    width: 100%;
    max-width: 400px;
}

.auth-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 28px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding-bottom: 16px;
}

.auth-tab {
    background: none;
    border: none;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px 4px;
    transition: var(--transition);
    position: relative;
}

.auth-tab.active {
    color: var(--text-main);
}

.auth-tab.active::after {
    content: '';
    position: absolute;
    bottom: -17px;
    left: 0;
    right: 0;
    height: 2px;
    background-color: var(--text-main);
    border-radius: 2px 2px 0 0;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
}

.form-input {
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 10px 14px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: var(--transition);
}

.form-input:focus {
    border-color: rgba(255, 255, 255, 0.2);
    background-color: rgba(255, 255, 255, 0.08);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.auth-error {
    font-size: 13px;
    color: #e07455;
    min-height: 18px;
}

.btn-auth-primary {
    background-color: var(--text-main);
    color: #111;
    border: none;
    border-radius: 10px;
    padding: 12px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-auth-primary:hover:not(:disabled) {
    background-color: #fff;
}

.btn-auth-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    font-size: 13px;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background-color: rgba(255, 255, 255, 0.08);
}

.btn-auth-google {
    background-color: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 11px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition);
}

.btn-auth-google:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.btn-auth-google i {
    font-size: 18px;
}

/* ================================================================
   Subscription Modal
   ================================================================ */
.subscription-modal-card {
    width: 100%;
    max-width: 560px;
}

.plan-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.plan-card {
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    position: relative;
    transition: var(--transition);
}

.plan-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
    background-color: rgba(255, 255, 255, 0.05);
}

.plan-card.featured {
    border-color: var(--accent-orange);
    background-color: rgba(224, 116, 85, 0.06);
}

.plan-featured-label {
    position: absolute;
    top: -11px;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--accent-orange);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    white-space: nowrap;
}

.plan-icon {
    font-size: 26px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.plan-card.featured .plan-icon {
    color: var(--accent-orange);
}

.plan-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-main);
}

.plan-credits {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent-orange);
}

.plan-desc {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.4;
}

.btn-plan-apply {
    margin-top: 8px;
    background-color: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-main);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
}

.btn-plan-apply:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.12);
}

.btn-plan-apply:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.plan-card.featured .btn-plan-apply {
    background-color: var(--accent-orange);
    border-color: var(--accent-orange);
    color: #fff;
}

.plan-card.featured .btn-plan-apply:hover:not(:disabled) {
    background-color: #e8845f;
}

.plan-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    margin-top: 4px;
}

.plan-badge.current {
    background-color: rgba(58, 176, 122, 0.15);
    color: var(--accent-green);
    border: 1px solid rgba(58, 176, 122, 0.25);
}

.plan-badge.pending {
    background-color: rgba(93, 156, 236, 0.15);
    color: var(--accent-blue);
    border: 1px solid rgba(93, 156, 236, 0.25);
}

.subscription-status {
    font-size: 13px;
    text-align: center;
    min-height: 20px;
    padding: 0 4px;
}

.subscription-status.success {
    color: var(--accent-green);
}

.subscription-status.error {
    color: var(--accent-orange);
}

/* ================================================================
   Credit Warning Banner (in chat view)
   ================================================================ */
.credit-warning-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: rgba(224, 116, 85, 0.1);
    border: 1px solid rgba(224, 116, 85, 0.25);
    border-radius: 12px;
    padding: 10px 20px;
    margin: 0 60px 12px;
    font-size: 14px;
    color: var(--accent-orange);
}

.credit-warning-banner i {
    font-size: 18px;
    flex-shrink: 0;
}

.credit-warning-link {
    background: none;
    border: none;
    color: var(--text-main);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    margin-left: auto;
    padding: 0;
}

.credit-warning-link:hover {
    color: #fff;
}

/* ================================================================
   Responsive adjustments for new elements
   ================================================================ */
@media (max-width: 768px) {
    .plan-cards {
        grid-template-columns: 1fr;
    }

    .credit-warning-banner {
        margin: 0 20px 12px;
    }

    .subscription-modal-card,
    .auth-modal-card {
        margin: 16px;
        max-width: calc(100vw - 32px);
    }
}