/* Main Panel */
.main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin-left: 0;
    margin-right: 0;
    transition: margin-left var(--transition), margin-right var(--transition-slow);
    background: var(--color-bg);
    overflow-x: hidden;
}

/* Main Header — 베이스 (모바일 기본): sticky, main-panel 안에서 흐름 */
.main-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 3rem;
    padding: 0 1rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
    position: sticky;
    top: 0;
    z-index: 5;
    flex-shrink: 0;
}

/* ─── Desktop 룰 ────────────────────────────────────────────────────────────
   규칙 1: 우측 패널과 중앙은 유기적으로 움직임. body.right-open 일 때
           main-panel 이 margin-right 만큼 축소 → 안의 채팅 영역 함께 축소.
   규칙 2: 최상단 헤더는 우측 패널과 무관. position:fixed 로 분리해 viewport
           풀폭 (좌측 패널 옆부터 우측 끝까지). main-panel 의 margin-right 가
           바뀌어도 헤더는 영향 없음.
*/
@media (min-width: 768px) {
    .main-panel { margin-left: var(--left-width); }
    .main-panel.no-nav { margin-left: 0; }

    /* 규칙 1: 우측 패널 열림 → main-panel 좁아짐 */
    body.right-open .main-panel {
        margin-right: var(--right-width, 380px);
    }

    /* 규칙 2: 헤더는 main-panel 흐름에서 빠져 viewport 풀폭 fixed.
       (베이스 sticky 룰을 덮기 위해 specificity 를 올린 .main-panel > .main-header 사용) */
    .main-panel > .main-header {
        position: fixed;
        top: 0;
        left: var(--left-width);
        right: 0;
        z-index: 100;
    }
    .main-panel.no-nav > .main-header {
        left: 0;
    }

    /* NOTE: .main-content padding-top 양보 룰은 base .main-content { padding: 1.5rem }
       이 더 *늦은* line 에 정의돼 shorthand 가 padding-top 을 덮어쓰는 문제 때문에
       여기 두지 않고, base rule 뒤쪽 (.main-content.full-page 옆) 에 둠. */
}

.header-left {
    display: flex;
    align-items: center;
    min-width: 2.5rem;
}

.header-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    min-width: 0;
}

.header-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
}

.header-title-icon {
    flex-shrink: 0;
}

.folder-icon {
    color: #e2e8f0;
}

.header-right {
    display: flex;
    align-items: center;
    min-width: 2.5rem;
    justify-content: flex-end;
}

.toggle-left-panel {
    display: none;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.25rem;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 0.375rem;
    color: var(--color-text);
    transition: background var(--transition);
}

.toggle-left-panel:hover {
    background: var(--color-bg-secondary);
}

@media (max-width: 767px) {
    .toggle-left-panel {
        display: flex;
    }
}

/* 헤더 프로필 link/avatar/name 룰은 좌측 사이드바 chip 으로 이전 (left.css 의
   .left-profile-* 참조). 헤더 우측엔 toggle 버튼만 남음. */

.toggle-right-panel {
    display: none;  /* 기본 숨김 — body.has-artifact 일 때만 노출 */
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--color-text-secondary);
    border-radius: 0.375rem;
    transition: all var(--transition);
}

/* 아티팩트가 도착하면 chat.js 가 body.has-artifact 부여 → 토글 버튼 노출 */
body.has-artifact .toggle-right-panel {
    display: inline-flex;
}

.toggle-right-panel:hover {
    background: var(--color-bg-secondary);
    color: var(--color-text);
}

/* 패널 열림 시 chevron 180° 회전 (|<- → ->|) */
.toggle-right-panel svg { transition: transform var(--transition); }
body.right-open .toggle-right-panel svg { transform: rotate(180deg); }

/* Main Content */
.main-content {
    flex: 1;
    padding: 1.5rem;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

@media (max-width: 767px) {
    .main-content {
        padding: 1rem;
    }
}

.main-content.full-page {
    padding: 0;
    max-width: none;
}

/* 데스크탑에서 .main-header 가 fixed (3rem 높이) 라 모든 콘텐츠가 그 만큼
   상단 양보. base .main-content { padding: 1.5rem } / .full-page { padding: 0 }
   shorthand 보다 *늦게* 정의해야 padding-top override 가 이김 (specificity 동일
   하면 후순위 win). 이전에 @media block 을 base 앞에 두어 적용 안 되던 버그
   ↑ */
@media (min-width: 768px) {
    .main-content {
        padding-top: calc(3rem + 1.5rem);
    }
    .main-content.full-page {
        padding-top: 3rem;
    }
}

/* Right Panel — 메인 헤더(3rem) 아래에서 시작해 채팅 영역과 유기적으로 작동.
   폭은 --right-width 변수로 (drag handle 로 조절, localStorage 저장). 중앙이
   양보하는 *유기적* 모드라 box-shadow 없이 left border 만으로 구분 — overlay
   모드 시절의 떠있는 패널 느낌 제거. */
.right-panel {
    position: fixed;
    right: 0;
    top: 3rem;
    bottom: 0;
    width: var(--right-width, 380px);
    background: var(--color-bg);
    border-left: 1px solid var(--color-border);
    transform: translateX(100%);
    transition: transform var(--transition-slow);
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

/* 리사이즈 중엔 부드러운 transition 끔 — 마우스 추적이 즉각적이게 */
body.right-resizing .right-panel,
body.right-resizing .main-panel,
body.right-resizing .main-header {
    transition: none !important;
}

/* drag handle — *명확히 보이는* 12px 폭 띠. claude.ai 식. */
.right-panel-resize-handle {
    position: absolute;
    left: -6px;            /* 패널 바깥으로 6px overhang */
    top: 0;
    bottom: 0;
    width: 12px;
    cursor: col-resize;
    z-index: 1001;
    background: rgba(226, 232, 240, 0.5);  /* slate-200 alpha — 평소에도 보임 */
    border-left: 1px solid rgba(148, 163, 184, 0.4);
    border-right: 1px solid rgba(148, 163, 184, 0.4);
    transition: background 0.15s;
}
.right-panel-resize-handle::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 40px;
    background: rgba(100, 116, 139, 0.7);
    border-radius: 2px;
    transition: background 0.15s;
}
.right-panel-resize-handle:hover {
    background: rgba(148, 163, 184, 0.35);
}
.right-panel-resize-handle:hover::after {
    background: rgba(51, 65, 85, 0.95);
}
body.right-resizing .right-panel-resize-handle {
    background: rgba(148, 163, 184, 0.5);
}
body.right-resizing .right-panel-resize-handle::after {
    background: rgba(15, 23, 42, 1);
}

@media (max-width: 767px) {
    /* 모바일은 전폭 패널이라 리사이즈 의미 없음 */
    .right-panel-resize-handle { display: none; }
}

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

.right-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.right-panel-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-text);
}

.right-panel-close {
    background: none;
    border: none;
    font-size: 1.375rem;
    color: var(--color-text-muted);
    cursor: pointer;
    line-height: 1;
    padding: 0.125rem 0.25rem;
    flex-shrink: 0;
    transition: color var(--transition);
}

.right-panel-close:hover {
    color: var(--color-text);
}

.right-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
}

.right-panel-empty {
    color: var(--color-text-muted);
    text-align: center;
    padding: 2rem 0.5rem;
    font-size: 0.875rem;
}

@media (max-width: 767px) {
    .right-panel {
        width: 100%;
    }
    /* 모바일에선 main 패널 margin shift 비활성 (overlay 모드) */
    body.right-open .main-panel {
        margin-right: 0;
    }
}

/* Global setup banner — UserConfigGuard 누락 안내. base.tmpl 이 main-panel 의
   header 와 main-content 사이에 렌더. amber tone — 차단이 아닌 권유 톤.
   클래스 이름이 `setup-banner-global` 인 이유: settings.tmpl 의 in-panel
   `.setup-banner` (settings.css 가 own) 와 분리해 fixed positioning 규칙이
   in-panel 배너로 leak 되지 않게. 이전엔 같은 클래스로 main.css 의 fixed/z-index:99
   가 in-panel 배너에도 적용돼 API 키 입력창 위를 덮어 클릭/포커스가 막혔다. */
.setup-banner-global {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: #fff7ed;
    border-bottom: 1px solid #fed7aa;
    color: #9a3412;
    font-size: 0.85rem;
    line-height: 1.3;
    flex-shrink: 0;
}
.setup-banner-global .setup-banner-icon {
    display: flex;
    align-items: center;
    color: #c2410c;
    flex-shrink: 0;
}
.setup-banner-global .setup-banner-text {
    flex: 1;
    min-width: 0;
}
.setup-banner-global-cta {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.75rem;
    background: #c2410c;
    color: #fff;
    border-radius: 0.375rem;
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: background var(--transition);
}
.setup-banner-global-cta:hover { background: #9a3412; }

:root { --setup-banner-h: 2.5rem; }
@media (min-width: 768px) {
    .setup-banner-global {
        position: fixed;
        top: 3rem;
        left: var(--left-width);
        right: 0;
        z-index: 99;
    }
    .main-panel.no-nav .setup-banner-global { left: 0; }
    body.has-setup-banner .main-content {
        padding-top: calc(3rem + var(--setup-banner-h) + 1.5rem);
    }
    body.has-setup-banner .main-content.full-page {
        padding-top: calc(3rem + var(--setup-banner-h));
    }
}
@media (max-width: 767px) {
    .setup-banner-global {
        position: sticky;
        top: 3rem;
        z-index: 4;
    }
}
