/* ============================================
   HATWIN — Layout (grid, sidebar, resizer, responsive, mobile nav)
   ============================================ */

/* ===== App Grid 布局 ===== */
.app-grid {
    --left-width: 220px;
    --resizer-width: 6px;
    display: grid;
    grid-template-columns: var(--left-width) var(--resizer-width) 1fr;
    min-height: 100vh;
    transition: grid-template-columns 0.3s ease;
}
.app-grid.nav-collapsed {
    --left-width: 72px;
}

/* 左栏 */
#sidebar {
    width: auto;
    overflow: hidden;
}
.app-grid.nav-collapsed #sidebar .nav-label,
.app-grid.nav-collapsed #sidebar .nav-text,
.app-grid.nav-collapsed #sidebar .sidebar-section-extra {
    display: none !important;
}
.app-grid.nav-collapsed #sidebar .sidebar-collapse-show {
    display: flex !important;
    justify-content: center;
}
.sidebar-collapse-show { display: none; }

/* nav-label */
.nav-label { display: inline; }

/* ===== 拖拽分隔条 ===== */
.resizer {
    width: var(--resizer-width);
    cursor: col-resize;
    background: transparent;
    position: relative;
    transition: background 0.2s;
    user-select: none;
    -webkit-user-select: none;
    min-width: 0;
}
.resizer:hover,
.resizer.active {
    background: #2563eb;
}
.resizer::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 24px;
    background: var(--muted-2);
    border-radius: 1px;
}
.resizer.right-collapsed,
.resizer.nav-collapsed {
    cursor: default;
    pointer-events: none;
}
.resizer.nav-collapsed::after,
.resizer.right-collapsed::after {
    display: none;
}
.resizer:focus {
    outline: 2px solid #2563eb;
    outline-offset: -2px;
    background: rgba(37, 99, 235, 0.1);
}
body.resizing {
    user-select: none !important;
    -webkit-user-select: none !important;
    cursor: col-resize;
}
body.resizing * {
    pointer-events: none !important;
}
body.resizing .resizer.active {
    pointer-events: auto !important;
}

/* 右分隔条不再使用 */
.resizer-right { display: none !important; }

/* ===== 手机端侧边栏 ===== */
.sidebar-mobile {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 170px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}
.sidebar-mobile.open {
    transform: translateX(0);
    display: flex !important;
}
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.sidebar-overlay.open {
    opacity: 1;
    visibility: visible;
}
.sidebar-toggle {
    display: none;
    position: fixed;
    left: 12px;
    top: 12px;
    z-index: 90;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: white;
    border: 1px solid var(--line);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.sidebar-close-btn {
    display: none;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 10;
    border-radius: 8px;
}
.sidebar-close-btn:hover {
    background: var(--line-soft);
}

/* ===== 底部 Tab 导航（仅手机端） ===== */
.mobile-bottom-tabs {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: white;
    border-top: 1px solid var(--line);
    z-index: 90;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.05);
}
.mobile-bottom-tabs .tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--muted);
    font-size: 0.65rem;
    cursor: pointer;
    min-height: 44px;
    min-width: 44px;
}
.mobile-bottom-tabs .tab-btn .tab-icon {
    font-size: 18px;
}
.mobile-bottom-tabs .tab-btn.active {
    color: var(--navy);
}

/* ===== Responsive Breakpoints ===== */

/* 桌面端（≥1024px） */
@media (min-width: 1024px) {
    #sidebar {
        position: relative !important;
        transform: none !important;
        height: auto !important;
        display: flex !important;
    }
    .sidebar-toggle { display: none !important; }
    .sidebar-overlay { display: none !important; }
}

/* 平板端（768-1023px） */
@media (max-width: 1023px) and (min-width: 768px) {
    .app-grid {
        --left-width: 220px;
    }
    .app-grid.nav-collapsed {
        --left-width: 220px;
    }
    .resizer-left { display: none !important; }
    #sidebar {
        position: relative !important;
        transform: none !important;
        height: auto !important;
        display: flex !important;
    }
    .sidebar-toggle { display: none !important; }
    .sidebar-overlay { display: none !important; }
}

/* 手机端（<768px） */
@media (max-width: 768px) {
    .sidebar-desktop { display: none; }
    .sidebar-toggle { display: flex; }
    .main-content-mobile { margin-left: 0 !important; }
    .header-mobile { padding-left: 60px !important; }
}

@media (max-width: 767px) {
    .app-grid {
        grid-template-columns: 1fr;
        padding-bottom: 56px;
    }
    .resizer { display: none !important; }
    #workspace-stage {
        position: fixed !important;
        left: 0;
        right: 0;
        top: 0;
        bottom: 0;
        height: 100vh !important;
        z-index: 1001;
        background: var(--paper);
    }
    #workspace-stage.active { display: flex; }
    .workspace-stage-header { padding: 12px; }
    .workspace-stage-content { padding: 12px; }
    #sidebar {
        position: fixed !important;
        left: 0;
        top: 0;
        height: 100vh !important;
        width: 280px !important;
        max-width: 85vw;
        z-index: 100;
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease;
        display: flex !important;
    }
    #sidebar.open { transform: translateX(0) !important; }
    .mobile-bottom-tabs { display: flex; }
    .sidebar-close-btn { display: flex; }
    .header-actions {
        flex-direction: row !important;
        flex-wrap: nowrap;
        gap: 6px;
    }
    .header-actions button {
        white-space: nowrap;
        padding: 6px 10px;
        flex-shrink: 0;
    }
    .header-actions button .btn-text { font-size: 0.75rem; }
    #chat-form {
        position: sticky;
        bottom: 0;
        z-index: 50;
    }
}