/**
 * Global Application Styles
 * Modern Premium IDE Design
 */

/* ===== CSS Variables (Dark Mode - Default) ===== */
:root {
    /* Layout */
    --ide-header-height: 60px;
    --ide-statusbar-height: 32px;
    --ide-sidebar-width: 280px;
    --ide-chat-width: 380px;

    /* Transition */
    --transition-fast: 0.15s ease;
    --transition-base: 0.2s ease;
    --transition-slow: 0.3s ease;
}

/* Note: Data-theme colors are dynamically injected from Config\Theme via layout.php */

/* ===== Base Styles ===== */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

/* Smooth transitions for most elements */
button, a, .tree-item, .tab-item, .chat-message {
    transition: background-color var(--transition-base),
                color var(--transition-base),
                transform var(--transition-base),
                box-shadow var(--transition-base);
}

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

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-elevated);
    border-radius: 5px;
    border: 1px solid var(--text-primary);
}

::-webkit-scrollbar-thumb:hover {
    border: 1px solid var(--accent-primary);
}

/* ===== Buttons ===== */
.btn-primary {
    background: var(--accent-gradient) !important;
    border: none !important;
    color: #fff !important;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-base);
}

.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
    background: var(--accent-gradient-hover) !important;
    color: #fff !important;
    transform: translateY(-1px);
    box-shadow: var(--glow-primary) !important;
}

.btn-secondary {
    background: var(--bg-tertiary) !important;
    border: 1px solid var(--border-primary) !important;
    color: var(--text-primary) !important;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: all var(--transition-base);
}

.btn-secondary:hover,
.btn-secondary:focus,
.btn-secondary:active {
    background: var(--bg-elevated) !important;
    border-color: var(--border-highlight) !important;
    color: var(--text-primary) !important;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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

/* ===== File Tree ===== */
.file-tree {
    font-size: 14px;
    padding: 6px 0;
}

.file-tree .tree-item {
    display: flex;
    align-items: center;
    height: 28px;
    padding: 0 8px 0 4px;
    cursor: pointer;
    user-select: none;
    position: relative;
}

.file-tree .tree-item *,
.file-tree .tree-item span,
.file-tree .tree-item i {
    cursor: pointer;
    user-select: none;
}

.file-tree .tree-item:hover {
    background: var(--bg-elevated);
}

.file-tree .tree-item.active {
    background: var(--bg-elevated);
}

/* Tree indent spacer */
.file-tree .tree-indent {
    flex-shrink: 0;
    display: inline-block;
}

/* Chevron icon */
.file-tree .tree-chevron {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: var(--text-tertiary);
    margin-right: 6px;
    transition: transform 0.2s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.file-tree .tree-chevron:hover {
    color: var(--text-secondary);
}

.file-tree .tree-chevron-placeholder {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    display: inline-block;
    margin-right: 6px;
}

/* File/folder icon */
.file-tree .tree-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    margin-right: 10px;
}

/* Item name */
.file-tree .tree-item-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
    line-height: 28px;
    font-size: 14px;
}

/* ===== File Type Icons (Enhanced Colors) ===== */
.folder-icon { 
    color: #f0c674 !important; 
    filter: saturate(1.3) brightness(1.1);
}

.folder-icon-open {
    color: #f0db65 !important;
    filter: saturate(1.3) brightness(1.2);
}

/* ===== Editor Tabs ===== */
.editor-tabs {
    display: flex;
    gap: 0;
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    overflow-x: auto;
    overflow-y: hidden;
    min-height: 35px;
    height: 35px;
    align-items: stretch;
}

.editor-tabs::-webkit-scrollbar {
    height: 0;
}

.tab-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 8px 0 16px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border: none;
    white-space: nowrap;
    transition: all 0.15s ease;
    font-size: 13px;
    position: relative;
}

.tab-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 1px;
    background: rgba(255, 255, 255, 0.06);
}

.tab-item:first-child::before,
.tab-item:only-child::before {
    display: none;
}

.tab-item:hover {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-primary);
}

.tab-item.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    position: relative;
    margin-bottom: -1px;
    padding-bottom: 1px;
}

.tab-item.active::before {
    display: none;
}

.tab-item.active + .tab-item::before {
    display: none;
}

.tab-icon {
    flex-shrink: 0;
    font-size: 14px;
    opacity: 0.9;

    cursor: grab;
}

.tab-name {
    /* 텍스트 드래그(선택) 방지 */
    user-select: none;
    -webkit-user-select: none; /* 크롬, 사파리 등 웹킷 계열 브라우저 호환 */
    -moz-user-select: none;    /* 파이어폭스 호환 */
    -ms-user-select: none;     /* IE/엣지 호환 */

    flex-shrink: 0;
    font-weight: 400;

    cursor: grab;
}

.tab-close {
    flex-shrink: 0;
    margin-left: 8px;
    padding: 3px;
    border-radius: 3px;
    opacity: 0;
    transition: all 0.15s ease;
    font-size: 16px;
    line-height: 1;
}

.tab-item:hover .tab-close,
.tab-item.active .tab-close {
    opacity: 0.5;
}

.tab-close:hover {
    opacity: 1 !important;
    background: rgba(255, 255, 255, 0.08);
}

.tab-placeholder {
    padding: 10px 16px;
    color: var(--text-tertiary);
    font-size: 13px;
}
.file-icon-php {
    color: #a78bfa !important;
    filter: saturate(1.2) brightness(1.1);
}

.file-icon-js {
    color: #f0db4f !important;
    filter: saturate(1.3) brightness(1.1);
}

.file-icon-ts {
    color: #818cf8 !important;
    filter: saturate(1.2) brightness(1.1);
}

.file-icon-css {
    color: #60a5fa !important;
    filter: saturate(1.2) brightness(1.1);
}

.file-icon-html {
    color: #fb923c !important;
    filter: saturate(1.2) brightness(1.1);
}

.file-icon-json {
    color: #4ade80 !important;
    filter: saturate(1.2) brightness(1.1);
}

.file-icon-md {
    color: #38bdf8 !important;
    filter: saturate(1.2) brightness(1.1);
}

.file-icon-sql {
    color: #2dd4bf !important;
    filter: saturate(1.2) brightness(1.1);
}

.file-icon-xml {
    color: #f87171 !important;
    filter: saturate(1.2) brightness(1.1);
}

.file-icon-yml {
    color: #f472b6 !important;
    filter: saturate(1.2) brightness(1.1);
}

.file-icon-py {
    color: #60a5fa !important;
    filter: saturate(1.2) brightness(1.1);
}

.file-icon-java {
    color: #f87171 !important;
    filter: saturate(1.2) brightness(1.1);
}

.file-icon-default {
    color: #9ca3af !important;
    filter: brightness(1.2);
}

.chat-messages {
    overflow-y: auto;
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-message {
    padding: 12px 16px;
    border-radius: 12px;
    max-width: 90%;
    position: relative; 
    animation: messageSlideIn 0.3s ease;
}

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

.chat-message.user {
    background: linear-gradient(135deg, 
        rgba(59, 130, 246, 0.12), 
        rgba(139, 92, 246, 0.08)
    );
    border-left: 3px solid var(--accent-primary);
    margin-left: auto;
    box-shadow: var(--shadow-sm);
}

.chat-message.assistant {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--text-tertiary);
    margin-right: auto;
    box-shadow: var(--shadow-sm);
}

.chat-message.system {
    background: rgba(245, 158, 11, 0.1);
    border-left: 3px solid var(--warning);
    font-style: italic;
    font-size: 12px;
    margin: 0 auto;
    max-width: 80%;
}

/* ===== Utilities ===== */
.glass-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.gradient-text {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.skeleton {
    background: linear-gradient(90deg,
        var(--bg-tertiary) 25%,
        var(--bg-elevated) 50%,
        var(--bg-tertiary) 75%
    );
    background-size: 200% 100%;
    animation: skeleton 1.5s ease-in-out infinite;
}

@keyframes skeleton {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ===== Header (Shared) ===== */

/* 헤더가 있는 페이지: body 스크롤바가 헤더 영역을 침범하지 않도록
   body 스크롤을 막고 스크롤 가능한 내부 컨테이너(.has-header-content)를 사용 */
body.has-header {
    overflow: hidden;
}

.has-header-content {
    position: fixed;
    top: var(--ide-header-height);
    left: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.ide-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--ide-header-height);
    background: var(--bg-tertiary);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    padding: 0 20px;
    z-index: 540;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
}

.brand-icon-wrapper {
    width: 36px;
    height: 36px;
    background: var(--accent-gradient);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: var(--glow-primary);
}

.brand-icon-wrapper i {
    font-size: 20px;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    position: relative; /* So absolute children anchor here */
}

.header-nav-links {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-nav-links .nav-link {
    padding: 8px 16px;
    border-radius: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 14px;
    transition: all var(--transition-base);
    display: flex;
    align-items: center;
    gap: 6px;
}

.header-nav-links .nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
}

.mobile-toggle {
    display: none;
}

.nav-divider {
    width: 1px;
    height: 24px;
    background: var(--border-primary);
    margin: 0 8px;
}

.header-nav-links .nav-link.active {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

/* ===== Responsive Header Settings ===== */

/* 중간 해상도: 링크 텍스트 축소 */
@media (max-width: 1100px) and (min-width: 1025px) {
    .header-nav-links {
        gap: 2px;
    }

    .header-nav-links .nav-link {
        padding: 6px 10px;
        font-size: 13px;
    }
}

/* 햄버거 전환 브레이크포인트: 1024px */
@media (max-width: 1024px) {
    .ide-header {
        padding: 0 12px;
        gap: 8px;
    }

    .header-brand .brand-icon-wrapper {
        width: 30px;
        height: 30px;
    }

    .header-brand .brand-icon-wrapper i {
        font-size: 16px;
    }

    .header-brand .brand-text {
        display: none;
    }

    /* 햄버거 버튼 표시 */
    #mobile-menu-toggle {
        display: flex !important;
    }

    /* 구분선 숨김 */
    .nav-divider {
        display: none !important;
    }

    /* 드롭다운 메뉴 */
    .header-nav-links {
        display: none;
        position: absolute;
        top: calc(100% + 12px);
        right: 0;
        left: auto;
        min-width: 200px;
        background: var(--bg-secondary);
        flex-direction: column;
        align-items: stretch;
        padding: 8px;
        gap: 4px;
        border: 1px solid var(--border-primary);
        border-radius: 10px;
        box-shadow: var(--shadow-lg);
        z-index: 520;
    }

    .header-nav-links.show {
        display: flex;
        animation: dropDownFade 0.2s ease;
    }

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

    .header-nav-links .nav-link {
        padding: 10px 14px;
        font-size: 14px;
    }
}

/* ===== Settings Dropdown ===== */
.settings-wrapper { position: relative; }
.settings-dropdown { display: none; position: absolute; top: calc(100% + 8px); right: 0; width: 360px; background: var(--bg-secondary); border: 1px solid var(--border-primary); border-radius: 10px; box-shadow: var(--shadow-lg); z-index: 550; overflow: hidden; max-height: calc(100vh - 80px); overflow-y: auto; }
.settings-dropdown.show { display: block; }
.settings-dropdown-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; background: var(--bg-tertiary); border-bottom: 1px solid var(--border-primary); position: sticky; top: 0; z-index: 1; }
.settings-dropdown-header span { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.btn-settings-close { padding: 2px 4px; font-size: 16px; color: var(--text-tertiary); }
.btn-settings-close:hover { color: var(--text-primary); background: var(--bg-elevated); }
.settings-section { padding: 0; border-bottom: 1px solid var(--border-primary); }
.settings-section:last-child { border-bottom: none; }
.settings-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-tertiary); margin-bottom: 0; padding: 10px 14px; }

/* Accordion */
.settings-accordion .settings-section-title { display: flex; align-items: center; justify-content: space-between; cursor: pointer; user-select: none; transition: background var(--transition-fast); }
.settings-accordion .settings-section-title:hover { background: var(--bg-elevated); color: var(--text-secondary); }
.settings-accordion-icon { font-size: 11px; transition: transform var(--transition-base); }
.settings-accordion-body { padding: 0 14px 12px; }
.settings-accordion.collapsed .settings-accordion-body { display: none; }

/* Hosting switch button */
.btn-settings-hosting-switch { display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 6px; background: var(--bg-elevated); border: 1px solid var(--border-primary); color: var(--text-secondary); font-size: 12px; text-decoration: none; transition: all var(--transition-fast); white-space: nowrap; flex-shrink: 0; }
.btn-settings-hosting-switch:hover { background: var(--bg-tertiary); color: var(--text-primary); border-color: var(--accent-primary); }
.btn-settings-hosting-switch i { font-size: 13px; }

/* Account nav links in settings */
.settings-nav-link { display: flex; align-items: center; gap: 8px; padding: 8px 4px; border-radius: 6px; color: var(--text-secondary); font-size: 13px; text-decoration: none; transition: all var(--transition-fast); }
.settings-nav-link:hover { color: var(--text-primary); background: var(--bg-elevated); padding-left: 8px; }
.settings-nav-link.danger { color: var(--error); }
.settings-nav-link.danger:hover { background: rgba(var(--error-rgb, 239,68,68), 0.08); color: var(--error); }
.settings-row { display: flex; align-items: center; justify-content: space-between; height: 32px; }
.settings-hosting-row { height: auto; padding: 6px 0; align-items: center; gap: 8px; }
.current-hosting-info { flex: 1; min-width: 0; }
.current-hosting-info .d-flex { flex-wrap: nowrap; }
#current-hosting-display { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 500; color: var(--text-primary); max-width: 100%; }
.settings-label { font-size: 13px; color: var(--text-secondary); margin: 0; }
.settings-control { display: flex; align-items: center; gap: 0; background: var(--bg-tertiary); border: 1px solid var(--border-primary); border-radius: 6px; overflow: hidden; }
.btn-settings-step { width: 26px; height: 26px; background: transparent; border: none; color: var(--text-secondary); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 14px; transition: background var(--transition-fast), color var(--transition-fast); }
.btn-settings-step:hover { background: var(--bg-elevated); color: var(--text-primary); }
.settings-value { min-width: 28px; text-align: center; font-size: 13px; font-weight: 600; color: var(--text-primary); background: var(--bg-white); border-left: 1px solid var(--border-primary); border-right: 1px solid var(--border-primary); line-height: 26px; }
.btn-settings-toggle { background: none; border: none; padding: 0; cursor: pointer; }
.settings-toggle-track { display: block; width: 40px; height: 22px; background: var(--bg-tertiary); border: 1px solid var(--border-primary); border-radius: 11px; position: relative; transition: background var(--transition-base), border-color var(--transition-base); }
.btn-settings-toggle.on .settings-toggle-track { background: var(--accent-primary); border-color: var(--accent-primary); }
.settings-toggle-thumb { display: block; width: 16px; height: 16px; background: var(--text-tertiary); border-radius: 50%; position: absolute; top: 2px; left: 2px; transition: left var(--transition-base), background var(--transition-base); }
.btn-settings-toggle.on .settings-toggle-thumb { left: 20px; background: #fff; }

/* ===== Responsive Settings Dropdown ===== */
@media (max-width: 768px) {
    .settings-wrapper { position: static; }
    .settings-dropdown {
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 90vw;
        max-width: 420px;
        max-height: 85vh;
        border-radius: 12px;
        overflow-y: auto;
    }
    .settings-dropdown-header {
        padding: 14px 16px;
    }
    .settings-hosting-row {
        flex-wrap: nowrap;
        padding: 8px 0;
    }
    #current-hosting-display {
        font-size: 12px;
    }
    .settings-dropdown-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: 560;
    }
    .settings-dropdown {
        z-index: 570;
    }
    .settings-dropdown-backdrop.show {
        display: block;
    }
}